This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to reliably save data using pstorage?

Hello,

I have quite a few of setting on my nodes and I want to save some of these permanently. Currently I am using the pstorage module and everything works as expected. There are quite some limitations:

  • Pstorage does not perform wear leveling,so I cannot save new data very often.
  • Flash operations take some time, so I probably can't do anything when the power drops off.

If the pstorage library works as documented, I assume the following: Updating a small block that shares a page with other blocks will:

  • Erase the swap area page

  • copy the contents of all other blocks to the swap area (why not the affected block as well?)

  • erase the page where the block was stored

  • => at this point, if the device is reset, it will irreversably loose the saved data from our block?

  • write the other blocks from flash and the one block from RAM

  • I don't think that the pstorage library will recover a lost page if it was not written back?

So does that mean that I have to implement the swapping, etc... myself if I want a reliable library that can guarantee me consistent data at all times? E.g. by adding a flag or a crc checksum to pages that is checked during boot and reading from a different page when this checksum is incorrect?

Thanks, Marius

Related