Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Best practice for storage of bootloader and application version

I am implementing the Device Information Service, and want to include the bootloader version as "Firmware revision" in DIS and the application version as "Software revision".

I am wondering where the best place is to store this information. Some places it is mentioned to use a fixed offset from the application start address. In other places it is mentioned that it is stored in the bootloader settings. However, I can not find anything authoritative on this.

How is it typically done?

Parents
  • This is how I load versions info into DIS:

    #include <ble_dis.h>
    #include <nrf_dfu_settings.h>
    #include <nrf_sdm.h>
    #include <sdk_errors.h>
    #include <stdlib.h>
    
    #define MANUFACTURER_NAME "..."
    
    uint8_t m_dfu_settings_buffer[BOOTLOADER_SETTINGS_PAGE_SIZE];
    nrf_dfu_settings_t s_dfu_settings;
    
    ret_code_t dis_init() {
        ble_dis_init_t dis_init = {0};
        dis_init.dis_char_rd_sec = SEC_OPEN;
        memcpy(&m_dfu_settings_buffer, (void *)BOOTLOADER_SETTINGS_ADDRESS, BOOTLOADER_SETTINGS_PAGE_SIZE);
        memcpy(&s_dfu_settings, m_dfu_settings_buffer, sizeof(nrf_dfu_settings_t));
    
        // Manufacturer
        ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
        // Firmware (Soft Device)
        char sd[20];
        sprintf(sd, "S%d %d.%d.%d", SD_VARIANT_ID, SD_MAJOR_VERSION, SD_MINOR_VERSION, SD_BUGFIX_VERSION);
        ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, sd);
        // Application
        char app[3];
        itoa(s_dfu_settings.app_version, app, 10);
        ble_srv_ascii_to_utf8(&dis_init.sw_rev_str, app);
        // Hardware (Bootloader)
        char bl[30];
        sprintf(bl, "Bootloader %d\nSettings %d", s_dfu_settings.bootloader_version, s_dfu_settings.settings_version);
        ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, bl);
    
        ret_code_t err = ble_dis_init(&dis_init);
        return err;
    }

Reply
  • This is how I load versions info into DIS:

    #include <ble_dis.h>
    #include <nrf_dfu_settings.h>
    #include <nrf_sdm.h>
    #include <sdk_errors.h>
    #include <stdlib.h>
    
    #define MANUFACTURER_NAME "..."
    
    uint8_t m_dfu_settings_buffer[BOOTLOADER_SETTINGS_PAGE_SIZE];
    nrf_dfu_settings_t s_dfu_settings;
    
    ret_code_t dis_init() {
        ble_dis_init_t dis_init = {0};
        dis_init.dis_char_rd_sec = SEC_OPEN;
        memcpy(&m_dfu_settings_buffer, (void *)BOOTLOADER_SETTINGS_ADDRESS, BOOTLOADER_SETTINGS_PAGE_SIZE);
        memcpy(&s_dfu_settings, m_dfu_settings_buffer, sizeof(nrf_dfu_settings_t));
    
        // Manufacturer
        ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
        // Firmware (Soft Device)
        char sd[20];
        sprintf(sd, "S%d %d.%d.%d", SD_VARIANT_ID, SD_MAJOR_VERSION, SD_MINOR_VERSION, SD_BUGFIX_VERSION);
        ble_srv_ascii_to_utf8(&dis_init.fw_rev_str, sd);
        // Application
        char app[3];
        itoa(s_dfu_settings.app_version, app, 10);
        ble_srv_ascii_to_utf8(&dis_init.sw_rev_str, app);
        // Hardware (Bootloader)
        char bl[30];
        sprintf(bl, "Bootloader %d\nSettings %d", s_dfu_settings.bootloader_version, s_dfu_settings.settings_version);
        ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, bl);
    
        ret_code_t err = ble_dis_init(&dis_init);
        return err;
    }

Children
  • Thanks for the tip. You don't actually need to copy the bootloader settings to RAM, they can be used directly from flash, like this:

        nrf_dfu_settings_t  *p_dfu_settings = (nrf_dfu_settings_t *) BOOTLOADER_SETTINGS_ADDRESS;
        char bl[30];
        sprintf(bl, "Bootloader %d\nSettings %d", p_dfu_settings->bootloader_version, p_dfu_settings->settings_version);
        ble_srv_ascii_to_utf8(&dis_init.hw_rev_str, bl);
Related