Zephyr shell "kernel reboot" command and persistent storage

My application uses NVS to store data and it works just fine - no errors reading or writing ,  and saved data persists between device power cycles.

My application also has the Zephyr shell integrated, and if after writing my data  I send "kernel reboot cold" (or warm) command, my data does not persist after device reboots.

Any ideas why and how to fix?
Thank you

Parents
  • Hello Andy,

    That is odd. Are you seeing the same thing with eg. the zephyr NVS sample, along with the zephyr shell? I just tried that without seeing an issue.

    If not, could you tell me more about your application?

    Regards,

    Elfving

  • Actually I have to reopen it since it reappeared again

    My application uses the nvs sample to read and write flash. It saves 24 byte record to flash

    Here is the initialization code - pretty much lifted from the nvs sample

    ssize_t flash_data_init(void)
    {
        int rc = 0;
        struct flash_pages_info info;
        const struct device *flash_dev;
       
        /* define the nvs file system by settings with:
         *  sector_size equal to the pagesize,
         *  3 sectors
         *  starting at FLASH_AREA_OFFSET(storage)
         */
        flash_dev = FLASH_AREA_DEVICE(STORAGE_NODE_LABEL);
        if (!device_is_ready(flash_dev)) {
            LOG_WRN("Flash device %s is not ready", flash_dev->name);
            return rc;
        }
        fs.offset = FLASH_AREA_OFFSET(storage);
        rc = flash_get_page_info_by_offs(flash_dev, fs.offset, &info);
        if (rc) {
            LOG_ERR("Unable to get page info:%d",rc);
            return 0;
        }
        fs.sector_size = info.size;
        // this is from the sample that used 3 sectors to store 3 types of data
        // we only use one. Leave just in cas
        fs.sector_count = 3U;

        rc = nvs_init(&fs, flash_dev->name);
        if (rc) {
            LOG_ERR("Flash Init failed:%d",rc);
            return 0;
        }
        LOG_DBG("Configured flash");
        rc =  flash_data_read();
        // _flash_ready flag
        _flash_ready = true;
        return rc;
    }
    There are no errors on init or when reading and writing. 
    If I write the record and power cycle - the record is read back without problems
    If I write the record and send kernel reboot (soft or hard - doesn't matter) - the record is gone
    Again, no errors
    Perhaps this is important
    The problem reappeared when I erased the card in vscode
  • Sorry about the delay,

    I don't see any obvious issues, though I see you've modified this line:

       rc = nvs_init(&fs, flash_dev->name);

    Can you see if you are getting the same issue without a card? 

    And are you getting the same issue with the default sample? You are using the nRF52840 right?

    Regards,

    Elfving

  • No problem

    I do not have an dev board, only the custom board.

    The nvs sample code has a config option

    CONFIG_MPU_ALLOW_FLASH_WRITE=y

    I did not have that in my project
    After I added it the problem <seems> to've gone away. I can save data to flash, then use kernel reboot command (cold or warm) and the data persists
     
    I'm still cautious not to say it's completely gone - will need to do more testing, will update you here.
    What does this config option do? I could not find much documentation on it
    Thank you
Reply
  • No problem

    I do not have an dev board, only the custom board.

    The nvs sample code has a config option

    CONFIG_MPU_ALLOW_FLASH_WRITE=y

    I did not have that in my project
    After I added it the problem <seems> to've gone away. I can save data to flash, then use kernel reboot command (cold or warm) and the data persists
     
    I'm still cautious not to say it's completely gone - will need to do more testing, will update you here.
    What does this config option do? I could not find much documentation on it
    Thank you
Children
No Data
Related