-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added option to check for possible overlapping during write_flash
o…
#174
Conversation
3786f3f
to
dfabf6f
Compare
dfabf6f
to
e3c749f
Compare
Hi @slaff, Thanks for submitting this. This seems like a good thing to check for. Is there a use case for writing overlapping data in a single write_flash command? I'd be happy to have this check always fail write_flash, no additional command line option required. If people really need to flash overlapping data, they can do it by running |
Probably not. I added it as an option to not break immediately the build of projects using esptool. If you want I can change the PR to enforce overlap detection? |
16d0fd0
to
fb3d69c
Compare
@projectgus Check the latest version of this PR. |
If people really need to flash overlapping data, they can do it by running esptool.py write_flash multiple times.
fb3d69c
to
9757948
Compare
end = 0 | ||
for address, argfile in sorted(pairs): | ||
argfile.seek(0,2) # seek to end | ||
size = argfile.tell() |
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.
Because esptool erases entire sectors, the address & size can be aligned to 4096-byte boundaries when checking for overlaps - even regions which don't obviously overlap can cause data loss if they land on the same sector.
Something like:
next_end = (address + size + FLASH_SECTOR_SIZE-1) & ~(FLASH_SECTOR_SIZE-1)
address = address & ~(FLASH_SECTOR_SIZE-1)
... # if end > address, etc.
end = next_end
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, my bad. The calculation should be better now and there are two small unit tests related to overlapping.
Looks good to me. Just have the one addition above about sector alignment. Also, could you please write a couple of tests for these in tests/test_esptool.py? A test case for the correct error directly overlapping images, and maybe one where they don't overlap but land in the same sector, would be fantastic. |
I am not sure that this should be the case. Look at the following example: AI-Thinker are suggesting in their AT software (http://bbs.espressif.com/download/file.php?id=1470) to initialize the flash memory with the following setup for 4MB flash 0x3fc000 esp_init_data_default.bin The second address is in the same sector as the first address.
and
|
Sector size is 4096 bytes (hex 0x1000), so 0x3fe000 and 0x3fc000 are two sectors apart. (There is also a larger block erase command, but the minimum erase size is one sector ie 0x1000 bytes.) |
Added unit tests for write_flash overlapping.
690681b
to
2830559
Compare
@projectgus Angus, did you have to look over the changes? It there something more that is needed for the PR to be merged? |
@projectgus Great, thanks! |
…peration.