n<#secure method=pgpmime mode=sign>
Christian, that’s a lot to digest. You’ve done a lot of thinking, but maybe
too much in my opinion
The cfg_page I built last year uses the kiss-on-every-cheek method, I think.
It uses two pages, with GC occuring occasionally by writing everything from
one page to the other page. The pages start with a 16-byte header that has a
checksum and counter, the page with the higher counter is valid.
It uses a CBOR indetermine sized map, which happens to use 0xff as the
end-of-data entry, which also happens to be what most erased NAND flash shows
up as. So we can append to the map without having to erase the flash.
When we write/update new values, we put them at the end, which means that
when looking for a key we have to search to the end. ENV keys are stored as
CBOR integers (forced to be 2-bytes in size, I think), while data is
arbitrary sized CBOR.
New values are written value first, then key, which means that a crash while
writing keeps the new key from being written, but may require some clean up afterwards.
GC occurs when we get to the end of the flash on a write. In that case, the
other page is erased, and we copy every item to the other page. We can crash
at any point and the other page remains invalid, and we can start again.
I used the mtd interface, which resulted in more ram being used because the
mtd includes support for serial NOR flash. We could do better if we
interfaced to the flash at a lower level (and supported memory mapped flash
only). My method would fail if flash did not erase to 0xff, or did not
support writing 0s in place of 1s. In that case, we’d have to do something else.
One thing that I like about my mechanism is that it can be messed with by a
debugger, or a host-based flash tool. I think that one 4k page may be too
small in the for the number of identities/certificates that we might want to
store, along with the various nonce and lollipop counter updates that we
might need.
We might want to have a generational system where things that do not get
updated often migrate to a superior page, while nonce counter/lollipop
updates populate some page subject to more frequent GC. Wear leveling would
rather that we actually moved it all around regularly though.
–
Michael Richardson mcr+IETF@sandelman.ca, Sandelman Software Works
-= IPv6 IoT consulting =-