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

  • Hello Andy,

    I will have to get back to you on this next week.

    Regards,

    Elfving

  • 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

  • Hmm 

    Very odd. I don't see this behavior any more. Tried to save flash several times and reboot - all works . Let's close for now. Thank you for help

  • 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
Related