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

Storing Device Serial/Identifier

We'd like to be able to store a few items including mutable keys, and unique identifier in each device that is generated on initial boot of the product. I'm just starting out with research but I'm wondering if there is any documentation/guidance from Nordic regarding how/where to store this kind of information?

Parents
  • Take a look at the NVS driver that Zephyr provides.  There is a sample application over in zephyr/samples/subsys/nvs.

    The only issue I bumped into was the flash offset you pass into nvs_init().  The Zephyr sample uses DT_FLASH_AREA_STORAGE_OFFSET, which should work in most cases.  Howeverif you are using mcuboot for FOTA updating, that value needs to be PM_MCUBOOT_STORAGE_ADDRESS.

  • I am trying to use PM_MCUBOOT_STORAGE_ADDRESS in our project instead of DT_FLASH_AREA_STORAGE_OFFSET so that we can retain NVS storage after a FOTA update.  However, when building, I get the following error:

    'PM_MCUBOOT_STORAGE_ADDRESS' undeclared (first use in this function); did you mean 'PWM_0_BASE_ADDRESS'?

    I am setting CONFIG_BOOTLOADER_MCUBOOT=y in the prj.conf, and we are able to do a FOTA.

    Here is the init code... this works fine when using DT_FLASH_AREA_STORAGE_OFFSET.

    int tk_nv_init(void){
      int err = 0;
      struct flash_pages_info info;
        /* define the nvs file system by settings with:
       *  sector_size equal to the pagesize,
       *  3 sectors
       *  starting at DT_FLASH_AREA_STORAGE_OFFSET
       */
      fs.offset = PM_MCUBOOT_STORAGE_ADDRESS; // was DT_FLASH_AREA_STORAGE_OFFSET (should be PM_MCUBOOT_STORAGE_ADDRESS)
      err = flash_get_page_info_by_offs(device_get_binding(DT_FLASH_DEV_NAME), fs.offset, &info); // previous NVS space
      if (err) {
        printk("Unable to get page info");
        return err;
      }
      fs.sector_size = info.size;
      fs.sector_count = 3U;

      err = nvs_init(&fs, DT_FLASH_DEV_NAME);   // previous NVS space
      if (err) {
        printk("Flash Init failed\n");
        return err;
      }

      TK_NV_INCR_M(REBOOT_CNT_ID);  // Increment the reboot counter

      return 0;
    }
Reply Children
Related