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

How to make app_valid_setting_apply.hex

I want to create a single hex file that I can use to program the SD, DFU, and my application. I know I can use mergehex.exe to merge these files. To make it so that the bootloader knows that there is a valid application, according to this thread, I also need to include a 4th hex the thread named "app_valid_setting_apply.hex" which tells the DFU that there is a valid application.

How do I create this 4th file, and make sure the addresses and data are correct?

Thanks, Clint

Parents
  • Hi

    As the thread you mention states, you can directly use the "app_valid_setting_apply.hex" file by merging it with your softdevice+bootloader+application hex file and that should make your application valid.

    If you want to figure out how to create it manually, then you would need to look at the basics of the intel hex format. If you open the "app_valid_setting_apply.hex" file in notepad you can see it contains only three lines of code.

    Additionally, this thread explains something about what the "app_valid_setting_apply.hex" file actually does in order make the application valid.

  • Hi c cook,

    First you may need to have a look at the structure of bootloader_settings_t in the bootloader:

    typedef struct
    {
        bootloader_bank_code_t bank_0;          /**< Variable to store if bank 0 contains a valid application. */
        uint16_t               bank_0_crc;      /**< If bank is valid, this field will contain a valid CRC of the total image. */
        bootloader_bank_code_t bank_1;          /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */
        uint32_t               bank_0_size;     /**< Size of active image in bank0 if present, otherwise 0. */
        uint32_t               sd_image_size;   /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               bl_image_size;   /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               app_image_size;  /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               sd_image_start;  /**< Location in flash where SoftDevice image is stored for SoftDevice update. */
    } bootloader_settings_t;
    

    We store the data of an instance of this structure at address BOOTLOADER_SETTINGS_ADDRESS (=0x3FC00) At the beginning the data at this address is all 0xFFFFFFFF. The bootloader when starting up read this address and find bank_0 = 0xFFFFFFF mean app invalid (EMPTY_FLASH_MASK) and won't start the application.

    To force the bootloader to start the application we need to set bank_0 !=0xFFFFFFFF. And maybe CRC to correct CRC of the application firmware (in the example in the thread we left CRC as 0 = no check). Next is to calculate the address. This is not simple, because in earlier bootloader ( SDK v6.x and earlier) we use "Enum Container always int" option in project setting means that bank_0 and bank_0_crc occupies first and second 4 bytes with padding added (from address 0x3FC00) . The recent bootloader, we removed that option and bank_0 only occupies 2 bytes and bank_0_crc occupies the next 2 bytes ( from address 0x3FC00).

    Depends on which SDK you use you need to configure the app_valid_setting_apply.hex accordingly. In our latest bootloader, we coped this issue in bootloader_util_settings_get() function.

    A simple way of checking the address, is to read out the flash memory of the chip after you have done a normal DFU update by the bootloader. Then save that as the app_valid_setting_apply.hex file. Of course you have to update the CRC correctly. Note that by default the bootloader won't calculate and store CRC, please look for m_image_crc. If you want the bootloader to store CRC (so that CRC check will be performed everytime the device boot up) you need to calculate crc and assign it to m_image_crc before storing bootloader setting.

Reply
  • Hi c cook,

    First you may need to have a look at the structure of bootloader_settings_t in the bootloader:

    typedef struct
    {
        bootloader_bank_code_t bank_0;          /**< Variable to store if bank 0 contains a valid application. */
        uint16_t               bank_0_crc;      /**< If bank is valid, this field will contain a valid CRC of the total image. */
        bootloader_bank_code_t bank_1;          /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */
        uint32_t               bank_0_size;     /**< Size of active image in bank0 if present, otherwise 0. */
        uint32_t               sd_image_size;   /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               bl_image_size;   /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               app_image_size;  /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */
        uint32_t               sd_image_start;  /**< Location in flash where SoftDevice image is stored for SoftDevice update. */
    } bootloader_settings_t;
    

    We store the data of an instance of this structure at address BOOTLOADER_SETTINGS_ADDRESS (=0x3FC00) At the beginning the data at this address is all 0xFFFFFFFF. The bootloader when starting up read this address and find bank_0 = 0xFFFFFFF mean app invalid (EMPTY_FLASH_MASK) and won't start the application.

    To force the bootloader to start the application we need to set bank_0 !=0xFFFFFFFF. And maybe CRC to correct CRC of the application firmware (in the example in the thread we left CRC as 0 = no check). Next is to calculate the address. This is not simple, because in earlier bootloader ( SDK v6.x and earlier) we use "Enum Container always int" option in project setting means that bank_0 and bank_0_crc occupies first and second 4 bytes with padding added (from address 0x3FC00) . The recent bootloader, we removed that option and bank_0 only occupies 2 bytes and bank_0_crc occupies the next 2 bytes ( from address 0x3FC00).

    Depends on which SDK you use you need to configure the app_valid_setting_apply.hex accordingly. In our latest bootloader, we coped this issue in bootloader_util_settings_get() function.

    A simple way of checking the address, is to read out the flash memory of the chip after you have done a normal DFU update by the bootloader. Then save that as the app_valid_setting_apply.hex file. Of course you have to update the CRC correctly. Note that by default the bootloader won't calculate and store CRC, please look for m_image_crc. If you want the bootloader to store CRC (so that CRC check will be performed everytime the device boot up) you need to calculate crc and assign it to m_image_crc before storing bootloader setting.

Children
No Data
Related