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

Lack of scratch page may result in lost data at power loss #1

Open
Wassasin opened this issue May 27, 2022 · 3 comments
Open

Lack of scratch page may result in lost data at power loss #1

Wassasin opened this issue May 27, 2022 · 3 comments

Comments

@Wassasin
Copy link

During the exchange of pages a page may be lost at brownout because it only exists in RAM. This can happen during or shortly after this statement:

moonboot/src/boot/mod.rs

Lines 252 to 254 in efadc79

self.internal_memory
.write(a_location + offset, &page_b_buf)
.map_err(|_| MemoryError::WriteFailure)?;

Fixing this would require an intermediate scratch page to write each page to, as well as an appropriate representation of this intermediate state in the State page.

@Wassasin
Copy link
Author

This is referred to in

* Implement power-interrupt safe exchange operation with a temporary flash page sdtorage

@jhbruhn
Copy link
Owner

jhbruhn commented May 27, 2022

Yes, I can confirm this is a problem, which is why I didn't advertise the stateful exchange as a feature (yet).

The scratchpad would need to have a size of PAGE_SIZE. This would obviously reduce the usable size for the firmware, but IMO that is a very good tradeoff to make it an always included feature.

Could this be realised as part of the bootloader via some macro/linker magic, without modifying the linker script?

We could get into problems if this ever supports different memory devices (e.g. external flash/EEPROM). Where will the scratchpad be stored then?

@Wassasin
Copy link
Author

Wassasin commented Jul 3, 2022

See #2 for a proposal on how to get the bootloader power-interrupt safe. As for external flash, perhaps we should change internal_memory to be an abstraction over all types of memory, internal, external and RAM, and use a reference to Bank to make it select the right kind of memory.

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

No branches or pull requests

2 participants