-
Notifications
You must be signed in to change notification settings - Fork 2k
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
mtd_spi_nor | littlefs: improve reliability with corrupted flash #14908
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the deal with the Security register and will it be available on all flash devices?
drivers/mtd_spi_nor/mtd_spi_nor.c
Outdated
/* Read security register */ | ||
uint8_t rdscur; | ||
mtd_spi_cmd_read(dev, dev->params->opcode->rdscur, &rdscur, sizeof(rdscur)); | ||
if (rdscur & SECURITY_PFAIL) { | ||
DEBUG("mtd_spi_nor_write: ERR: page program failed!\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the relationship between the two.
On macronix flashes (at least, I haven't check other vendors actually :/ ), security register contains some flags: |
d'oh! I'll revisit the patch to enable this with a compile flag |
Is there some way to detect this at run-time? |
I guess it could be possible to read the jedec ID. But I'm not sure it's worth it. |
faba5b6
to
26ac8e7
Compare
ping @benpicco |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for letting this slip through the cracks!
This actually looks really good, would merge after giving it a quick test.
Can you rebase this?
#define STATUS_WIP 0x01u | ||
#define STATUS_WEL 0x02u | ||
#define STATUS_BP0 0x04u | ||
#define STATUS_BP1 0x08u | ||
#define STATUS_BP2 0x10u | ||
#define STATUS_BP3 0x20u | ||
#define STATUS_QE 0x40u | ||
#define STATUS_SRWD 0x80u | ||
|
||
#define SECURITY_SOTP 0x01u | ||
#define SECURITY_LDSO 0x02u | ||
#define SECURITY_PSB 0x04u | ||
#define SECURITY_ESB 0x08u | ||
#define SECURITY_XXXXX 0x10u | ||
#define SECURITY_PFAIL 0x20u | ||
#define SECURITY_EFAIL 0x40u | ||
#define SECURITY_WPSEL 0x80u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just move those to the .c
file, no need to define them globally - then you can also get away without a prefix 😉
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
@benpicco Can we get this reactivated? The project I'm currently working on uses an ISSI flash which has the same security features (however the bit positions in the registers are different and the OpCodes are different as well). This PR would be a good base and reduce the amount of work significantly. Given the age of the PR, it probably has merge conflicts now. Unfortunately it looks like @vincent-d is not active anymore, his last GitHub activity was in 2022 and there is not much to find about OTAkeys anymore either. On a different note: I checked the code and there is no timeout for the added functions wait_for_write_enable_cleared and wait_for_write_enable_set, which would get the thread stuck if the chip does not answer. I don't know how this is handled generally in other modules? |
Sure, feel free to take over the PR. |
Contribution description
This PR improves the reliability of
mtd_spi_nor
andlittlefs
:mtd_spi_nor
: properly checks forWEL
enabling/disabling, check for errors when writing/erasing and return a dedicated error code (-EIO
).littlefs
: catch-EIO
and translate it intoLFS_ERR_CORRUPT
that is internally used to realloc sectors if neededTesting procedure
Check that littlefs(2) still works (
examples/filesystem
).This has been tested with flash that had dead sectors. littlefs could detect them and recover.