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

Application does not start after custom DFU (hardfault_handler)

Hi,

We are using a bootloader/DFU based on the secure_bootloader example with USB transport from SDK15 and It works fine.

Now, we are trying to add the possibility to do an OTA update of our device by GSM. (first ticket here)

For this we do the “DFU” part in the app. The app is therefore responsible for:

  • download by GSM the .bin and .dat files,
  • write them in flash (bank1)
  • configure s_dfu_settings
  • write s_dfu_settings at BOOTLOADER_SETTINGS_ADDRESS
  • reset the device.

When the device restarts, the bootloader check if a new app is available and copies contents of bank1 to bank0 with app_activate()

nrf_bootloader_init() -> nrf_bootloader_fw_activate() -> app_activate()

after the copy, the bootloader performs a reset and start the application with nrf_bootloader_app_start()

 

but the application does not start and if we go in debug in bootloader we can see that the device goes into the hardfault_handler after calling jump_to_addr(new_msp, new_lr, reset_handler) in function app_start().

nrf_bootloader_app_start() -> nrf_bootloader_app_start_final() -> app_start() -> jump_to_addr()

 

Are we missing a step during the update ?

Do you have any idea what we can check/debug to find the problem ?

 

.bin file generated by nrfutil is signed for the DFU by USB.

But it is not signed for our custom DFU by GSM. So what we have to do with the .dat file ?

Configuration of s_dfu_settings in app

#define BIN_FILE_START_ADDRESS 0x000A0000UL

s_dfu_settings.bank_1.image_size = device->ota_data.fileBin.size; // size of .bin file
s_dfu_settings.bank_1.image_crc  = crc32_compute((uint8_t*)(BIN_FILE_START_ADDRESS), device->ota_data.fileBin.size, NULL);

s_dfu_settings.bank_1.bank_code = NRF_DFU_BANK_VALID_APP;
s_dfu_settings.bank_0.bank_code = NRF_DFU_BANK_INVALID;
s_dfu_settings.bank_current     = NRF_DFU_CURRENT_BANK_1;

s_dfu_settings.write_offset = 0;
s_dfu_settings.progress.update_start_address = (BIN_FILE_START_ADDRESS);

s_dfu_settings.crc = crc32_compute((uint8_t*)&s_dfu_settings + 4, DFU_SETTINGS_INIT_COMMAND_OFFSET  - 4, NULL);

Before update :

After update :


same address in bank0


Thanks for your help.

  • Hi, 

    Sorry for the delay. 

    I would suggest you use the usb secure DFU debug version as the base to get the log to help debug. 

    -Amanda H.

  • Hi Amanda,

    Sorry for the delay, I had to work on another project and had difficulty to implement the "usb secure DFU debug" example...

    Here are the logs.

    Normal DFU by USB:

    00> <info> app: Inside main
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return false in valid app check
    00> <debug> app: In nrf_bootloader_init
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00> <debug> app: Valid App
    00> <debug> app: Enter nrf_dfu_app_continue
    00> <info> nrf_bootloader_wdt: WDT enabled CRV:10240 ms
    00> <info> nrf_bootloader_wdt: Starting a timer (7680 ms) for feeding watchdog.
    00> <info> app_timer: RTC: initialized.
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x00026000, len=8 pages), queue usage: 0
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x00026000, pending 0
    00> <debug> app: Copying 0x3E000 to 0x26000, size: 0x8000
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00026000, src=0x0003E000, len=32768 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x00026000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0002E000, len=8 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x0002E000, pending 0
    00> <debug> app: Copying 0x46000 to 0x2E000, size: 0x8000
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0002E000, src=0x00046000, len=32768 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x0002E000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x00036000, len=8 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x00036000, pending 0
    00> <debug> app: Copying 0x4E000 to 0x36000, size: 0x7AF0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00036000, src=0x0004E000, len=31472 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x00036000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> app: Setting app as valid
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> app: Resetting bootloader.
    
    00> <info> app: --- OTA ---
    00> <info> app: Inside main
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return false in valid app check
    00> <debug> app: In nrf_bootloader_init
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00> <info> app: No firmware to activate.
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return true. App was valid
    00> <warning> nrf_dfu_settings: No additional data erased
    00> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
    00> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
    00> <debug> app: running irq table set
    00> <debug> app: After running irq table set

    After that the app is running fine.

    Custom DFU from the app:

    00> <info> app: Inside main
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return false in valid app check
    00> <debug> app: In nrf_bootloader_init
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00> <debug> app: Valid App
    00> <debug> app: Enter nrf_dfu_app_continue
    00> <info> nrf_bootloader_wdt: WDT is not enabled
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x00026000, len=8 pages), queue usage: 0
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x00026000, pending 0
    00> <debug> app: Copying 0xA1000 to 0x26000, size: 0x8000
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00026000, src=0x000A1000, len=32768 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x00026000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0002E000, len=8 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x0002E000, pending 0
    00> <debug> app: Copying 0xA9000 to 0x2E000, size: 0x8000
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0002E000, src=0x000A9000, len=32768 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x0002E000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x00036000, len=8 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x00036000, pending 0
    00> <debug> app: Copying 0xB1000 to 0x36000, size: 0x7AF0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00036000, src=0x000B1000, len=31472 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x00036000, pending 0
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> app: Setting app as valid
    00> <debug> nrf_dfu_settings: Writing settings...
    00> <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    00> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash erase success: addr=0x000FF000, pending 0
    00> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000165C, len=348 bytes), queue usage: 1
    00> <debug> nrf_dfu_flash: Flash write success: addr=0x000FF000, pending 0
    00> <debug> app: Resetting bootloader.
    00> <info> app: --- OTA ---
    00> <info> app: Inside main
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return false in valid app check
    00> <debug> app: In nrf_bootloader_init
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00> <info> app: No firmware to activate.
    00> <debug> app: Enter nrf_dfu_app_is_valid
    00> <debug> app: Return true. App was valid
    00> <warning> nrf_dfu_settings: No additional data erased
    00> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
    00> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
    00> <debug> app: running irq table set
    00> <debug> app: After running irq table set

    Nothing relevant, the bootloader seems to correctly write the new app after the custom DFU but after the update the application is going in hardfault...

    Best regards

  • Hi, 

    Could the new app run without the issue with the Normal DFU by USB? (Does the issue only happen to your custom DFU?)

    Is the app run able to run without DFU?

    -Amanda H.

Related