-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a CRC32 over progmem and ESP.checkFlashCRC #6566
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
Conversation
Automatically embed a CRC32 of the program memory (including bootloader but excluding any filesystems) in all images in unused space in the bootloader block. Add a call, ESP.checkFlashCRC() which returns false if the calculated CRC doesn't match the one stored in the image (i.e. flash corruption). Fixes esp8266#4165
Show CRC checking catch a 1-bit error in program code by corrupting a large array, and then return it to clean and verify the CRC matches once again. Add comments to the CRC check routine Clean up pylint complaints on crc32bin.py
Add an assertion in the eboot linker file to guarantee that we have at least 8 bytes of unused space at the end of the boot sector to patch in the CRC. If not, the eboot link will fail.
Per discussion with @d-a-v. When the CRC check fails, you could *try* to do certain things (but may not succeed since there is known flash corruption at that point). List a few ideas for application authors.
Per discussion w/@mcspr, combine the CRC calculation with the binary generation, removing the additional build step.
@earlephilhower Is this supposed to work out of the box just yet? Like pulling master, restarting the IDE, rebuilding my sketch. I get on one board:
But, on another board:
Immediately noticeable is the 1 byte difference in compressed size. |
@@ -30,6 +30,9 @@ | |||
ffreqb = { '40': 0, '26': 1, '20': 2, '80': 15 } | |||
fsizeb = { '512K': 0, '256K': 1, '1M': 2, '2M': 3, '4M': 4, '8M': 8, '16M': 9 } | |||
|
|||
crcsize_offset = 4088 | |||
crcval_offset = 4092 |
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.
Hm. I think it is off by one error, starting index should be 4087?
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.
@mcspr Build+upload with crcsize_offset = 4087 crashes on boot.
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.
Right, nvm :)
@earlephilhower Ah, OK, I never knew that I HAVE TO select the precise right board w.r.t. flash size. Building for LOLIN D1 mini Pro (16MB flash settings in config) it's fine:
Please allow one remark: could you be more precise in the readme on the use of |
@dok-net, your comment explains it! If you send the wrong flash size, the Updater will change one byte silently to match what's already set. So the CRC check did succeed and found an error...what was in flash was not what you sent in! :) This was related to another bug (already fixed) where the Updater was always changing 1 byte of an uploaded image, even when it was a FS. Signing guarantees that you created the bin being uploaded, and is a 1-time check on upload only. CRC checks dynamically (when you call it) for changes to the flash vs. when you generated the bitstream. Random bit flips, flash page failures, etc. |
Automatically embed a CRC32 of the program memory (including bootloader
but excluding any filesystems) in all images in unused space in the
bootloader block.
Add a call, ESP.checkFlashCRC() which returns false if the calculated
CRC doesn't match the one stored in the image (i.e. flash corruption).
Fixes #4165