Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating sequential-storage, adding flash erase support #884

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ryan-summers
Copy link
Member

Fixes #861 by updating clear <setting> to actually erase the requested setting from flash memory instead of overwriting it with the current default value.

This PR also updates to sequential-storage v1.0 by using embassy-futures to complete the async operations in a blocking manner. This shouldn't matter at all because the underlying impl is blocking anyways. However, the version bump may cause users to lose their flash settings.

To test this, I cleared flash settings and rebooted the device. I then reprogrammed it with a new default broker of "mqtt2" and verified that the device used the new default of mqtt2 after reprogramming, which indicated that nothing was loaded from flash.

@ryan-summers ryan-summers marked this pull request as ready for review April 22, 2024 14:42
serial-settings/src/lib.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated
} else {
// Erase the whole flash range.
embassy_futures::block_on(
self.storage.erase(range.start, range.end),
Copy link
Member

@jordens jordens Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a multi page erase? Wouldn't it be better to have sequential-storage do it "smart"?
I suspect sequential-storage should provide a (much more efficient than multiple remove_item) way to clear (distinct from flash erase) its storage. Maybe they have an idea on what's best here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this erases 1MB of flash and takes quite a while to do (several seconds).

I definitely think this could be done more efficiently on the sequential-storage side of things (i.e. scan the device, look for used pages, erase those pages only). I'll take a look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also reduce the flash range for sequential storage. We don't need to allocate 1 MB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we don't need 1MB, I think we have to allocate at least 128KB * 3 based on the design of sequential-storage and the layout of flash pages in the device unfortunately.

Sequential storage requires at least 3 pages from what I remember.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can do with 2 right now. But your effective storage size page_size * (num_pages - 1) for map, because it needs to keep one page as a buffer page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Nice work on sequential-storage!
Let's just take current sequential storage master, wait for release, and 2 pages (three breaking changes in one ;). It'll be a while in practice until it needs to erase pages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm currently testing, but hitting HardFault exceptions after erasing and then re-reading flash sections. I believe it's due to flash ECC code failures, but what we're doing should be supported (since we're only clearing bits). I'll dig into what's going wrong here over the next day or two

serial-settings/src/lib.rs Outdated Show resolved Hide resolved
@diondokter
Copy link

However, the version bump may cause users to lose their flash settings.

There was a breaking change to the on-disk data format in 0.7, so yes this will break things.

Also, I'm very close to releasing v2.0 with some API changes that make dealing with the keys and values easier (and more straightforward).
v1.0 is fine and without known bugs, so you can upgrade to that just fine if you don't want to do the refactoring. Going from v1 to v2 won't have changes on-disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USB/flash clear/save behavior w.r.t. default changes
3 participants