This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SD_MBR_COMMAND_COPY_SD returns NRF_ERROR_INTERNAL (SDK 14.0)

I'm trying to update my NRF52832 running s332 v5.0.0 and a stock SDK14.0 bootloader to S332 v6.1.1 with an SDK 15.3 bootloader.

I am including the flags  --sd-req  and --sd-id with the value of  0xBA,0x9B

Unfortunately, the update is failing when copying the SD. sd_mbr_command with the command SD_MBR_COMMAND_COPY_SD is returning NRF_ERROR_INTERNAL (0x03). According to the documentation that "indicates that the contents of the memory blocks where not verified correctly after copying. "

What is going wrong here? My debug log is shown below (I'm just showing the last bits). The lines " 0> <debug> app: sd_mbr_command 0x0" are printing out the return of the sd_mbr_command function.  It seems to crash during the second copy operation, then restart and continue from where it left off but the next copy operation returns the error. 

 0> <debug> app: Received calculate CRC
 0> <info> dfq_req_handling: Before OP crc
 0> <debug> app: Sending CRC: [0x60, 0x03, 0x01, 0:x0003379C, CRC:0x5DCE3DE3]
 0> <debug> nrf_dfu_flash: Flash write success: addr=0x00060780, pending 0
 0> <debug> app: Received execute object
 0> <info> dfq_req_handling: Before OP execute
 0> <info> dfq_req_handling: Valid Data Execute
 0> <debug> nrf_dfu_settings: Writing settings...
 0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
 0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
 0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 2
 0> <info> dfq_req_handling: Doing postvalidate
 0> <info> dfq_req_handling: Current bank is bank 0
 0> <info> dfq_req_handling: Running SD version check ==============
 0> <warning> dfq_req_handling: SD major version numbers mismatch. Current app will be invalidated.Current: 5. New: 6.
 0> <info> dfq_req_handling: Successfully ran the postvalidation check!
 0> <debug> nrf_dfu_settings: Writing settings...
 0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
 0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 3
 0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 4
 0> <debug> app: Sending Response: [0x4, 0x1]
 0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 3
 0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 2
 0> <debug> dfq_req_handling: Response sent.
 0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 1
 0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
 0> <debug> nrf_dfu_flash: This operation had a callback, calling back to 0x0007B099.
 0> <debug> dfq_req_handling: All flash operations have completed.
 0> <debug> dfq_req_handling: Starting reset timer.
 0> <debug> dfq_req_handling: Attempting to reset the device.
 0> <debug> app: In nrf_dfu_transports_close
 0> <debug> app: num transports: 1
 0> <debug> app: Shutting down BLE transport.
 0> <debug> app: Disconnecting.
 0> <debug> app: BLE transport shut down.
 0> <debug> app: After nrf_dfu_transports_init
 0> <debug> dfq_req_handling: Reset.
 0>
 0>
 0> NRF52 BLE Bootloader (SDK14)
 0>   Version: 1.7
 0>   Built: 15:27:51, May 28 2019
 0> <debug> app: In nrf_bootloader_init
 0> <debug> app: in weak nrf_dfu_init_user
 0> <debug> app: In real nrf_dfu_init
 0> <debug> nrf_dfu_settings: Running nrf_dfu_settings_init(sd_irq_initialized=false).
 0> <debug> nrf_dfu_flash: Calling nrf_dfu_flash_init(sd_irq_initialized=false)...
 0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
 0> <debug> app: Initializing the clock.
 0> <debug> app: Enter nrf_dfu_continue
 0> <debug> app: Valid SD + BL
 0> <debug> app: Enter nrf_dfu_sd_bl_continue
 0> <debug> app: Enter nrf_bootloader_dfu_sd_continue
 0> <debug> app: Updating SD. Old SD ver: 50, New ver: 60
 0> <debug> app: Copying [0x0002D000-0x00039000] to [0x00001000-0x0000D000]: Len: 0x0000C000
 0> <debug> app: sd_mbr_command 0x0
 0> <debug> app: Finished copying [0x0002D000-0x00039000] to [0x00001000-0x0000D000]: Len: 0x0000C000
 0> <debug> app: Validated 0x0002D000-0x00039000 to 0x00001000-0x0000D000: Size: 0x0000C000
 0> <debug> app: Finished with the SD update.
 0> <debug> nrf_dfu_settings: Writing settings...
 0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
 0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
 0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
 0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 1
 0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
 0> <debug> app: Copying [0x00039000-0x00045000] to [0x0000D000-0x00019000]: Len: 0x0000C000
 0>
 0>
 0> NRF52 BLE Bootloader (SDK14)
 0>   Version: 1.7
 0>   Built: 15:27:51, May 28 2019
 0> <debug> app: In nrf_bootloader_init
 0> <debug> app: in weak nrf_dfu_init_user
 0> <debug> app: In real nrf_dfu_init
 0> <debug> nrf_dfu_settings: Running nrf_dfu_settings_init(sd_irq_initialized=false).
 0> <debug> nrf_dfu_flash: Calling nrf_dfu_flash_init(sd_irq_initialized=false)...
 0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
 0> <debug> app: Initializing the clock.
 0> <debug> app: Enter nrf_dfu_continue
 0> <debug> app: Valid SD + BL
 0> <debug> app: Enter nrf_dfu_sd_bl_continue
 0> <debug> app: Enter nrf_bootloader_dfu_sd_continue
 0> <debug> app: Copying [0x0003BB34-0x00044B34] to [0x0000CB34-0x00015B34]: Len: 0x00009000
 0> <debug> app: sd_mbr_command 0x3
 0> <error> app: Failed to copy SD: target: 0x0000CB34, src: 0x0003BB34, len: 0x00009000
 0> <error> app: SD+BL: SD copy failed
 0> <debug> app: Could not continue DFU operation: 0x00000003
 0> <debug> app: In nrf_dfu_transports_init
 0> <debug> app: num transports: 1
 0> <debug> app: Initializing BLE DFU transport
 0> Hard fault

  • Hi Goldwake, 

    Just checking: Which nrfutil version did you use to generate the image? 

    There is also a known issue with the SDK v14.0.0 bootloader when doing combined BL and SD updates, please see

    https://devzone.nordicsemi.com/f/nordic-q-a/27862/update-sd-bl-app-from-sdk-v13-to-v14-via-dfu-fails

    This has been fixed in SDK v14.1.0, see snippet below

    static uint32_t nrf_dfu_bl_continue(uint32_t src_addr, nrf_dfu_bank_t * p_bank)
    {
        uint32_t        ret_val     = NRF_ERROR_NULL;
        uint32_t const  len         = (p_bank->image_size - s_dfu_settings.sd_size);
    
        NRF_LOG_DEBUG("Verifying BL: Addr: 0x%08x, Src: 0x%08x, Len: 0x%08x", BOOTLOADER_START_ADDR, src_addr, len);
        
    #if NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE    
        // This code is a configurable workaround for updating SD+BL from SDK 12.x.y - 14.1.0
        // SoftDevice size increase would lead to unaligned source address when comparing new BL in SD+BL updates.
        // This workaround is not required once BL is successfully installed with a version that is compiled SDK 14.1.0
    #if defined(NRF52832_XXAA)
        if (p_bank->bank_code == NRF_DFU_BANK_VALID_SD_BL)
        {
            ret_val = nrf_dfu_mbr_compare((uint32_t*)BOOTLOADER_START_ADDR, (uint32_t*)(src_addr - 0x4000), len);
        }
    #endif // defined(NRF52832_XXAA)
    #endif // #if NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE
    
        // Check if the BL has already been copied.
        if (ret_val != NRF_SUCCESS)
        {
            ret_val = nrf_dfu_mbr_compare((uint32_t*)BOOTLOADER_START_ADDR, (uint32_t*)src_addr, len);
        }
        
        // If the bootloader is the same as the banked version, the copy is finished
        if (ret_val == NRF_SUCCESS)
        {
            NRF_LOG_DEBUG("Bootloader was verified");
    
            // Invalidate bank, marking completion
            nrf_dfu_invalidate_bank(p_bank);
    
            // Upon successful completion, the callback function will be called and reset the device. If a valid app is present, it will launch.
            NRF_LOG_DEBUG("Writing settings and reseting device.");
            ret_val = nrf_dfu_settings_write(reset_device_callback);
        }
        else
        {
            NRF_LOG_DEBUG("Bootloader not verified, copying: Src: 0x%08x, Len: 0x%08x", src_addr, len);
            // Bootloader is different than the banked version. Continue copy
            // Note that if the SD and BL was combined, then the split point between them is in s_dfu_settings.sd_size
            ret_val = nrf_dfu_mbr_copy_bl((uint32_t*)src_addr, len);
            if (ret_val != NRF_SUCCESS)
            {
                NRF_LOG_ERROR("Request to copy BL failed");
            }
        }
    
        return ret_val;
    }

    Best regards

    Bjørn

  • Hi Bjorn,

    I used nrfutil v 5.2.0. I've tried updating my bootloader to one using SDK14.2 and with NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE defined before doing the update to S332 v6.1.1 and an sdk 15.3 bootloader.

    I still see the bootloader crash when copying the SD

     0> <debug> app: Received calculate CRC
     0> <info> dfu_req_handling: Before OP crc
     0> <debug> app: Sending CRC: [0x60, 0x03, 0x01, 0:x0003379C, CRC:0x5DCE3DE3]
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x00060780, pending 0
     0> <debug> app: Received execute object
     0> <info> dfu_req_handling: Before OP execute
     0> <info> dfu_req_handling: Valid Data Execute
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 2
     0> <info> dfu_req_handling: Doing postvalidate
     0> <info> dfu_req_handling: Current bank is bank 0
     0> <info> dfu_req_handling: Running SD version check ==============
     0> <warning> dfu_req_handling: SD major version numbers mismatch. Current app will be invalidated.Current: 5. New: 6.
     0> <info> dfu_req_handling: Successfully ran the postvalidation check!
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 3
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 4
     0> <debug> app: Sending Response: [0x4, 0x1]
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 3
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 2
     0> <debug> dfu_req_handling: Response sent.
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: This operation had a callback, calling back to 0x0007B421.
     0> <debug> dfu_req_handling: All flash operations have completed.
     0> <debug> dfu_req_handling: Starting reset timer.
     0> <debug> dfu_req_handling: Attempting to reset the device.
     0> <debug> app: In nrf_dfu_transports_close
     0> <debug> app: num transports: 1
     0> <debug> app: Shutting down BLE transport.
     0> <debug> app: Disconnecting.
     0> <debug> app: BLE transport shut down.
     0> <debug> app: After nrf_dfu_transports_init
     0> <debug> dfu_req_handling: Reset.
     0>
     0>
     0> NRF52 BLE Bootloader (SDK14)
     0>   Version: 1.8
     0>   Built: 12:15:41, May 29 2019
     0> <debug> app: In nrf_bootloader_init
     0> <debug> app: in weak nrf_dfu_init_user
     0> <debug> app: In real nrf_dfu_init
     0> <debug> nrf_dfu_settings: Running nrf_dfu_settings_init(sd_irq_initialized=false).
     0> <debug> nrf_dfu_flash: Calling nrf_dfu_flash_init(sd_irq_initialized=false)...
     0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
     0> <debug> app: Initializing the clock.
     0> <debug> app: Enter nrf_dfu_continue
     0> <debug> app: Valid SD + BL
     0> <debug> app: Enter nrf_dfu_sd_bl_continue
     0> <debug> app: Enter nrf_bootloader_dfu_sd_continue
     0> <debug> app: Updating SD. Old SD ver: 50, New ver: 60
     0> <debug> app: Copying [0x0002D000-0x00039000] to [0x00001000-0x0000D000]: Len: 0x0000C000
     0> <debug> app: Finished copying [0x0002D000-0x00039000] to [0x00001000-0x0000D000]: Len: 0x0000C000
     0> <debug> app: Validated 0x0002D000-0x00039000 to 0x00001000-0x0000D000: Size: 0x0000C000
     0> <debug> app: Finished with the SD update.
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <debug> app: Copying [0x00039000-0x00045000] to [0x0000D000-0x00019000]: Len: 0x0000C000
     0>
     0>
     0> NRF52 BLE Bootloader (SDK14)
     0>   Version: 1.8
     0>   Built: 12:15:41, May 29 2019
     0> <debug> app: In nrf_bootloader_init
     0> <debug> app: in weak nrf_dfu_init_user
     0> <debug> app: In real nrf_dfu_init
     0> <debug> nrf_dfu_settings: Running nrf_dfu_settings_init(sd_irq_initialized=false).
     0> <debug> nrf_dfu_flash: Calling nrf_dfu_flash_init(sd_irq_initialized=false)...
     0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
     0> <debug> app: Initializing the clock.
     0> <debug> app: Enter nrf_dfu_continue
     0> <debug> app: Valid SD + BL
     0> <debug> app: Enter nrf_dfu_sd_bl_continue
     0> <debug> app: Enter nrf_bootloader_dfu_sd_continue
     0> <debug> app: Copying [0x00038B34-0x00041B34] to [0x0000CB34-0x00015B34]: Len: 0x00009000
     0> <debug> app: Finished copying [0x00038B34-0x00041B34] to [0x0000CB34-0x00015B34]: Len: 0x00009000
     0> <debug> app: Validated 0x00038B34-0x00041B34 to 0x0000CB34-0x00015B34: Size: 0x00009000
     0> <debug> app: Finished with the SD update.
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, len=0x1B8 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <debug> app: Copying [0x00041B34-0x0004AB34] to [0x00015B34-0x0001EB34]: Len: 0x00009000
     0> <error> app: Failed to copy SD: target: 0x00015B34, src: 0x00041B34, len: 0x00009000
     0> <error> app: SD+BL: SD copy failed
     0> <debug> app: Could not continue DFU operation: 0x00000003
     0> <debug> app: In nrf_dfu_transports_init
     0> <debug> app: num transports: 1
     0> <debug> app: Initializing BLE DFU transport
     0> Hard fault

  • If you are using SDK 14.x.x then you need to use a nrfutil version between v1.5.0 and v4.0.0 as stated in the Readme on https://github.com/NordicSemiconductor/pc-nrfutil

    The DFU package format transitioned from legacy to modern in SDK 12.0. Depending on the SDK version that you are using you will need to select a release of this tool compatible with it:

    • Version 0.5.2 generates legacy firmware packages compatible with nRF SDK 11.0 and older
    • Versions 1.5.0 and later generate modern firmware packages compatible with nRF SDK 12.0 and newer
    • Versions 4.0.0 and later generate modern firmware packages compatible with nRF SDK 15.1 and newer
    • Versions 5.0.0 and later generate modern firmware packages compatible with nRF SDK 15.3 and newer

    Could you try to generate a firmware image using v3.5.1 of nrfutil? 

  • So i found that i had a bug in my script that builds my initial SDK14.2 SD+APP+BL image (generated using nrfutil 5.2.0) that meant the --no-backup flag wasn't included when making the settings. This probably didn't help but I haven't solved my problem

    Doing a SD+BL update to s332v6.1.1 + SDK 15.3 BL from:

    • S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE not defined in 14.2 BL+ nrfutil v3.5.1 results in a BL too large error (which is caused by using the wrong nrfutil version)
    • S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE not defined in 14.2 BL + nrfutil v5.2.0 results in the crash shown above
    • S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE  defined in 14.2 BL+ nrfutil v3.5.1 results in a BL too large error (which is caused by using the wrong nrfutil version)
    • S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE defined in 14.2 BL + nrfutil v5.2.0 results in the crash shown above
    • Initial image generated with nrfutil 3.5.1 S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE defined in 14.2 BL + nrfutil v5.2.0 results in the crash shown above.
    • Initial image generated with nrfutil 3.5.1 S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE defined in 14.2 BL + nrfutil v3.510 results in BL too large errore.
    • Initial image generated with nrfutil 3.5.1 S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE not defined in 14.2 BL + nrfutil v5.2.0 results in the crash above
    • Initial image generated with nrfutil 3.5.1 S332 v5 + SDK14.2 BL + NRF_DFU_WORKAROUND_PRE_SDK_14_1_0_SD_BL_UPDATE not defined in 14.2 BL + nrfutil v3.5.1 results in BL too large error
  • Are you using the nRF5_SDK_14.0.0_3bcc1f7\examples\dfu\bootloader_secure_ble\pca10040_debug example or the nRF5_SDK_14.0.0_3bcc1f7\examples\dfu\bootloader_secure_ble\pca10040 example when you are generating the bootloader hex file used when creating the .zip with nrfutil?

Related