-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3833040
Add a CRC32 over progmem and ESP.checkFlashCRC
earlephilhower 79d0197
Add example that currupts itself, comments
earlephilhower 7011265
Merge branch 'master' into crc32
earlephilhower b7e9f01
Merge branch 'master' into crc32
earlephilhower 4a50bab
Merge branch 'master' into crc32
earlephilhower 3fca89e
Update Esp.cpp
earlephilhower fcfa48c
Update Esp.cpp
earlephilhower 00929d1
Fix example astyle problems
earlephilhower 49180aa
Check linker script for CRC space in bootsector
earlephilhower 95e64e4
Merge branch 'master' into crc32
earlephilhower 800ebe5
Fix order of crc/len in linker script
earlephilhower 23ecb8e
Merge branch 'master' into crc32
earlephilhower 77d617a
Add note about what to do if CRC check fails
earlephilhower 985b6c5
Only single, flash/ram friendly crc32() function
earlephilhower 379b167
Combine the CRC calc and bin generation in 1 step
earlephilhower 51fec2c
Merge branch 'master' into crc32
earlephilhower 365a9d0
Merge branch 'master' into crc32
earlephilhower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libraries/esp8266/examples/CheckFlashCRC/CheckFlashCRC.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Demonstrate CRC check passing and failing by simulating a bit flip in flash. | ||
WARNING!!! You would never want to actually do this in a real application! | ||
|
||
Released to the Public Domain by Earle F. Philhower, III <[email protected]> | ||
*/ | ||
|
||
extern "C" { | ||
#include "spi_flash.h" | ||
} | ||
// Artificially create a space in PROGMEM that fills multipe sectors so | ||
// we can corrupt one without crashing the system | ||
const int corruptme[SPI_FLASH_SEC_SIZE * 4] PROGMEM = { 0 }; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.printf("Starting\n"); | ||
Serial.printf("CRC check: %s\n", ESP.checkFlashCRC() ? "OK" : "ERROR"); | ||
Serial.printf("...Corrupting a portion of flash in the array...\n"); | ||
|
||
uint32_t ptr = (uint32_t)corruptme; | ||
// Find a page aligned spot inside the array | ||
ptr += 2 * SPI_FLASH_SEC_SIZE; | ||
ptr &= ~(SPI_FLASH_SEC_SIZE - 1); // Sectoralign | ||
uint32_t sector = ((((uint32_t)ptr - 0x40200000) / SPI_FLASH_SEC_SIZE)); | ||
|
||
// Create a sector with 1 bit set (i.e. fake corruption) | ||
uint32_t *space = (uint32_t*)calloc(SPI_FLASH_SEC_SIZE, 1); | ||
space[42] = 64; | ||
|
||
// Write it into flash at the spot in question | ||
spi_flash_erase_sector(sector); | ||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t*)space, SPI_FLASH_SEC_SIZE); | ||
Serial.printf("CRC check: %s\n", ESP.checkFlashCRC() ? "OK" : "ERROR"); | ||
|
||
Serial.printf("...Correcting the flash...\n"); | ||
memset(space, 0, SPI_FLASH_SEC_SIZE); | ||
spi_flash_erase_sector(sector); | ||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t*)space, SPI_FLASH_SEC_SIZE); | ||
Serial.printf("CRC check: %s\n", ESP.checkFlashCRC() ? "OK" : "ERROR"); | ||
} | ||
|
||
|
||
void loop() { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 :)