nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

drivers/mtd:init commit of power-loss resilient cfg

Open XinStellaris opened this issue 3 years ago • 6 comments

Signed-off-by: 田昕 [email protected]

Summary

MTD non-volatile storage was originally implemented in Zephyr by Laczen. We made several modification to the original design. The main purpose of those modification was:

  1. support C-string key in nvs API(Original design only support uint16_t as key)
  2. Meanwhile achieve better performance by limiting flash read times(Theoratically better than Zephyr subsys/settings, which is based on original NVS).

This is the initial commit, I have tested its set/unset/get/list/erase with https://github.com/apache/incubator-nuttx-apps/tree/master/system/cfgdata, the result shows no obvious bug.

More tests on power-loss behavior are needed, and I plan to add those test cases into apps/testing in the next patch

Impact

config data only.

Testing

set/unset/get/list/erase tested on ESP32C3.

XinStellaris avatar Aug 10 '22 14:08 XinStellaris

In general I'm a bit lost in architecture here. The MTD layer is designed to provide unified "continuous" access across the underlying physical layer, so I expect that all alignment or any other hardware related stuff is hidden "under" MTD device, but here I observe an opposite when the MTD caller handle alignment and other stuff. I mean that if MTD is implemented on top of flash that is what I expect, but not implementing a flash on top of MTD what I see here. I will submit a negative feedback until all design points are not clarified

Basically, MTD like a block device(but need erase before write, wear leveling and ECC), which is hard to use from user application. To fix this problem, we normally have two approach:

  1. Build a complex filesystem on top of MTD to support a tree like structure(e.g. spiffs, smartfs and littlefs).
  2. Build a simple key value storage on top of MTD

NVS(and cfgdata) is the second approach. @pkarashchenko do you get the idea?

xiaoxiang781216 avatar Aug 10 '22 18:08 xiaoxiang781216

In general I'm a bit lost in architecture here. The MTD layer is designed to provide unified "continuous" access across the underlying physical layer, so I expect that all alignment or any other hardware related stuff is hidden "under" MTD device, but here I observe an opposite when the MTD caller handle alignment and other stuff. I mean that if MTD is implemented on top of flash that is what I expect, but not implementing a flash on top of MTD what I see here. I will submit a negative feedback until all design points are not clarified

Basically, MTD like a block device(but need erase before write, wear leveling and ECC), which is hard to use from user application. To fix this problem, we normally have two approach:

1. Build a complex filesystem on top of MTD to support a tree like structure(e.g. spiffs, smartfs and littlefs).

2. Build a simple key value storage on top of MTD

NVS(and cfgdata) is the second approach. @pkarashchenko do you get the idea?

@xiaoxiang781216 we already have KVS on top of MTD and that is mtdconfig. Could you please bring some more light on key differences between mtdconfig and NVS?

pkarashchenko avatar Aug 11 '22 07:08 pkarashchenko

The major difference is power failure safe, it's very hard to support this feature on mtdconfig without breaking the binary combability. Since NVS share the same external interface with mtdconfig, the user could select which one to use.

xiaoxiang781216 avatar Aug 11 '22 09:08 xiaoxiang781216

I have found a few bugs, and will keep on fixing. So I convert this to draft.

XinStellaris avatar Aug 12 '22 14:08 XinStellaris

Though this is a draft, please review it. Much appreciation to anyone helps to review it.

XinStellaris avatar Aug 12 '22 14:08 XinStellaris

I will review in the weekend.

xiaoxiang781216 avatar Aug 12 '22 14:08 xiaoxiang781216

Alright, I have fixed the bugs and passed zephyr test cases. Please review.

XinStellaris avatar Aug 19 '22 19:08 XinStellaris

I have rebased it

XinStellaris avatar Aug 22 '22 02:08 XinStellaris

test cases are here:https://github.com/apache/incubator-nuttx-apps/pull/1288

XinStellaris avatar Aug 22 '22 04:08 XinStellaris

@pkarashchenko could you review again?

xiaoxiang781216 avatar Aug 22 '22 15:08 xiaoxiang781216

Yes, I will review

pkarashchenko avatar Aug 22 '22 15:08 pkarashchenko