Best way to write persistent data in factory

Hi, team.

I am trying to find a way to write some persistent data in factory.

The data is a couple of certificates and should be written differently for each devices.

What is the best way to achieve this?

I am considering to use NVS and zephyr settings libraries to save certificates, but want to know whether the better/recommended way exists.

And also, let me know some guideline how to make suitable format (like .hex, maybe?) for writing to flash with well-known flash writing tools like nrfprog or Programmer.

I tried to make my own CLI interface via UART, etc., but currently, target device is lack of resources, and can't afford for it.

Parents Reply Children
  • Hi Håkon,

    OK, I added the following line to my CMakeLists.txt

    if (CONFIG_SETTINGS_FCB OR CONFIG_SETTINGS_NVS)
      ncs_add_partition_manager_config(pm.yml.settings)
    endif()

    And copied pm.yml.settings from Partition Manager to my project directory.

    And also, I added some codes for settings module in my code, and confirmed values are properly loaded from flash.

    Project was built successfully.

    Now what should I do? How can I create hex or binaries to write to settings partition?

  • Hi,

     

    choehyunho said:
    Now what should I do? How can I create hex or binaries to write to settings partition?

    We do not have any examples for the PC platform that conforms to the NVS/"settings" format. This is why I proposed a solution for writing your data directly to the nRF flash, by reserving the space you need for writing your data.

     

    If you only read the data from the nRF-side, having it in NVS or any other filesystem-like architecture does not make that much sense.

    Again, it depends on what you need in this scenario, ie. if you're ever going to update these certs from the nRF etc.

     

    Kind regards,

    Håkon

  • I am considering two scenarios for this.

    1. Writing certs in NCS CLI via UART. With this way, I can easily adapt my settings code and just implement proper shell command. But I am not sure current CONFIG_SHELL feature in zephyr is properly handling thousands of bytes certificates or not.

    2. Writing small PC utility for making HEX fitted in settings partition. I found https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/matter/nrfconnect_factory_data_configuration.html document and looking into settings_ncs.c in NCS. It is quite a large work and I am still suspicious it is worthy.

    I need some insight for this. Any advice will be appreciated.

  • Hi,

     

    choehyunho said:
    1. Writing certs in NCS CLI via UART. With this way, I can easily adapt my settings code and just implement proper shell command. But I am not sure current CONFIG_SHELL feature in zephyr is properly handling thousands of bytes certificates or not.

    This is one way of doing it. It is very similar to the "at_client", where we have the option to write certificates to the nRF9160 modem.

    choehyunho said:
    2. Writing small PC utility for making HEX fitted in settings partition. I found https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/matter/nrfconnect_factory_data_configuration.html document and looking into settings_ncs.c in NCS. It is quite a large work and I am still suspicious it is worthy.

    A solution similar to this will probably be the quickest way, as you're writing the data directly into flash.

    This is a solution that is tailored towards matter applications. You can try to adjust the parameters to make it match your setup, but this will require tuning on your side.

     

    I would recommend that you test this to see if it can be used for your exact use-case.

     

    Kind regards,

    Håkon

  • This is one way of doing it. It is very similar to the "at_client", where we have the option to write certificates to the nRF9160 modem.

    I tried this, and basically confirmed it possible. But, my current board is almost out of memory (it occupies 120KB out of 128KB), and I determined to use the second way.

    A solution similar to this will probably be the quickest way, as you're writing the data directly into flash.

    This is a solution that is tailored towards matter applications. You can try to adjust the parameters to make it match your setup, but this will require tuning on your side.

     

    I would recommend that you test this to see if it can be used for your exact use-case.

    I spent some times to review the structure of Zephyr settings module, but eventually it seems to be to redundant and waste of flash space for my specific usage.

    Currently, I am tied to another urgent work and need some more time to solve this issue.

    So, I will update my experience after a while.

    BTW, I found some interesting document (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_partition_gen.html) in ESP32.

    Is it related to zephyr? It looks quite similar.

Related