How to use NVS in native_posix? #nvs #flash


Jan Van Winkel
 

Hi Lucas,

You can use native_posix with NVS, the NVS sample (samples/subsys/nvs) almost works out of the box.
So I would have a look at the sample code and use it as a base line.

Steps (tested against latest master (b173c177db7f) on a Ubuntu host):
  1. Comment the line CONFIG_MPU_ALLOW_FLASH_WRITE=y in samples/subsys/nvs/prj.conf
  2. west build --board native_posix samples/subsys/nvs
  3. cd build
  4. ./zephyr/zephyr.elf
  5. As reboot is not supported in native_posix hit ctrl-c once you see Failed to reboot: spinning endlessly...
  6. Repeat steps 4 and 5 and observe that the Reboot_counter is incrementing
  7. Optional: to start from scratch rm flash.bin, repeat steps 4 to 5
Best regards,
Jan


zephyr/build$ ./zephyr/zephyr.elf
*** Booting Zephyr OS build zephyr-v2.2.0-829-gb173c177db7f  ***
[00:00:00.000,000] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.000,000] <inf> fs_nvs: alloc wra: 0, ff0
[00:00:00.000,000] <inf> fs_nvs: data wra: 0, 0
No address found, adding 192.168.1.1 at id 1
No key found, adding it at id 2
No Reboot counter found, adding it at id 3
Id: 4 not found, adding it
Longarray not found, adding it as id 5
Reboot counter history: ...0
Oldest reboot counter: 0
Rebooting in ...5...4...3...2...1
Failed to reboot: spinning endlessly...
^C
Stopped at 3.490s

zephyr/build$ ./zephyr/zephyr.elf
*** Booting Zephyr OS build zephyr-v2.2.0-829-gb173c177db7f  ***
[00:00:00.000,000] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.000,000] <inf> fs_nvs: alloc wra: 0, fc0
[00:00:00.000,000] <inf> fs_nvs: data wra: 0, a1
Id: 1, Address: 192.168.1.1
Id: 2, Key: ff fe fd fc fb fa f9 f8
Id: 3, Reboot_counter: 1
Id: 4, Data: DATA
Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
Reboot counter history: ...1...0
Oldest reboot counter: 0
Rebooting in ...5...4...3...2...1
Failed to reboot: spinning endlessly...
^C
Stopped at 1.980s

On Fri, Mar 27, 2020 at 6:29 PM Lucas Peixoto <lucaspeixotoac@...> wrote:
Another option would be to use NVS with QEMU, but I think that in QEMU doesn't work too. What steps I would follow to try to make native_posix or qemu_x86 support nvs?