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

DFU

Hi,

I use a custom board, softdevice and boot loader.

I use DFU to update a slave chip firmware. Everything goes right until we invalidate and write flash :   

        // Invalidate bank, marking completion.
        nrf_dfu_bank_invalidate(&s_dfu_settings.bank_1);

        uint32_t ret_val = nrf_dfu_settings_write_and_backup(NULL);

the nrf_dfu_settings_write_and_backup lead to a HARDFAULT handler because of accessing flash :

Parents
  • Is it your main application that calls nrf_dfu_settings_write_and_backup(), and not the bootloader? In that case, make sure the app is compiled with the NRF_DFU_IN_APP flag enabled.  This will prevent the nrf_dfu_settings module from attempting to erase the flash page protected by the BPROT — Block protection peripheral. And note that BPROT protection is automatically disabled in debug interface mode.

  • I will try this

    NRF_BL_DFU_ALLOW_UPDATE_FROM_APP set to 1 in bootloader

    and

    NRF_DFU_IN_APP set to 1 in our app.

    Is that correct?

  • Hi Vidar,

    maybe i found out why setting NRF_BL_DFU_ALLOW_UPDATE_FROM_APP is not enough in our case.

    actually I look in details the bootloader and found this :

        area_size = BOOTLOADER_SIZE + NRF_MBR_PARAMS_PAGE_SIZE;

        if (!NRF_BL_DFU_ALLOW_UPDATE_FROM_APP && !NRF_BL_DFU_ENTER_METHOD_BUTTONLESS && !NRF_DFU_TRANSPORT_BLE)
        {
            area_size += BOOTLOADER_SETTINGS_PAGE_SIZE;
        }

        ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, area_size);

    in my case BOOTLOADER_SIZE is

    #define BOOTLOADER_SIZE (NRF_MBR_PARAMS_PAGE_ADDRESS - BOOTLOADER_START_ADDR)

    What I found is the following :

    actually it BOOTLOADER_START_ADDR  is 0x00078000 (in debug mode I look at nrf_bootloader_flash_protect() function)

    area_size is 0x7000.

    and so all the end of flash is then protected and then the bootloader settings as well.

    Maybe we have miss something here.

    Could you tell us more on this?

    Thanks



  • one more things

    in nrf_dfu_types.h i found this:

    #elif defined( NRF52832_XXAA )
        #define BOOTLOADER_SETTINGS_ADDRESS     (0x0007F000UL) 

    and

    #elif defined(NRF52832_XXAA)
        #define NRF_MBR_PARAMS_PAGE_ADDRESS         (0x0007E000UL)

    so area_size = BOOTLOADER_SIZE + NRF_MBR_PARAMS_PAGE_SIZE

    BOOTLOADER_SIZE = (NRF_MBR_PARAMS_PAGE_ADDRESS - BOOTLOADER_START_ADDR)

    NRF_MBR_PARAMS_PAGE_ADDRESS = 0x7e000

    BOOTLOADER_START_ADDR = 0x78000

    so BOOTLOADER_SIZE  = 0x6000

    NRF_MBR_PARAMS_PAGE_SIZE = CODE_PAGE_SIZE

    CODE_PAGE_SIZE = 1024 * sizeof( uint32) == 1000

    area_size= 0x7000

    so evrything should work fine as the MBR settings start at 0x7f000.

    so why the nrf_dfu_settings_write_and_backup() function lead to hardfault handler ?

    maybe it try to access something that is not in BOOTLOADER settings but in MBR params?

  • yes I confirm my feeling.

    hardfault arrive in nrf_dfu_settings_write_and_backup()  because it try to erase at adress 0x7e000.

    question : why?

  • The hardfault happens because the app is not intented to have access the backup page (i.e, MBR param page), see my first post to see which fields the it's permitted to change by default. But, if you want to give you give your app full write access, you can do so by disabling the flash protection in your bootloader as you already suggested.

  • yes understood the reason of hardfault.

    What I don't understand is :

    why the function invalidate is not sufficient ?

    after loading zip file, bootloader call my app

    then we do this :

      ret_code_t ret_val = nrf_dfu_settings_init(false);
      if (ret_val != NRF_SUCCESS)
      {
        //return NRF_ERROR_INTERNAL;
        NRF_LOG_ERROR("Impossible d'init nrf_dfu_settings_init");
      }
      else
      {
        NRF_LOG_DEBUG("s_dfu_settings bank 1 : 0x%02x", s_dfu_settings.bank_1.bank_code);
        if (s_dfu_settings.bank_1.bank_code == NRF_DFU_BANK_VALID_EXT_APP)
        {

    else the s_dfu_settings.bank_1.bank_code is never valid.

    but if I do this the s_dfu_settings.bank_1.bank_code is ALWAYS valide except if we wrote in MBR param.
    just want to understand why i need to erase MBR param.

    seems data are written by bootloader to inform data available but then restore at each reboot except if I wrote it back in MBR param

Reply
  • yes understood the reason of hardfault.

    What I don't understand is :

    why the function invalidate is not sufficient ?

    after loading zip file, bootloader call my app

    then we do this :

      ret_code_t ret_val = nrf_dfu_settings_init(false);
      if (ret_val != NRF_SUCCESS)
      {
        //return NRF_ERROR_INTERNAL;
        NRF_LOG_ERROR("Impossible d'init nrf_dfu_settings_init");
      }
      else
      {
        NRF_LOG_DEBUG("s_dfu_settings bank 1 : 0x%02x", s_dfu_settings.bank_1.bank_code);
        if (s_dfu_settings.bank_1.bank_code == NRF_DFU_BANK_VALID_EXT_APP)
        {

    else the s_dfu_settings.bank_1.bank_code is never valid.

    but if I do this the s_dfu_settings.bank_1.bank_code is ALWAYS valide except if we wrote in MBR param.
    just want to understand why i need to erase MBR param.

    seems data are written by bootloader to inform data available but then restore at each reboot except if I wrote it back in MBR param

Children
Related