diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-04-20 13:48:33 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-04-20 18:07:34 +0300 |
commit | cc1ef76f887f8f56363e3e431ba17320cf99a533 (patch) | |
tree | 49231f7dd5678b29536e7cb07c46067b56e90e66 /esp8266/scripts | |
parent | 584406880c8354d87a714f934e1984393ec76c3b (diff) | |
download | micropython-cc1ef76f887f8f56363e3e431ba17320cf99a533.tar.gz micropython-cc1ef76f887f8f56363e3e431ba17320cf99a533.zip |
esp8266/scripts/flashbdev: Correct bootloader flash size to match real size.
Flash size as seen by vendor SDK doesn't depend on real size, but rather on
a particular value in firmware header, as put there by flash tool. That means
it's user responsibility to know what flash size a particular device has, and
specify correct parameters during flashing. That's not end user friendly
however, so we try to make it "flash and play" by detecting real size vs
from-header size mismatch, and correct the header accordingly.
Diffstat (limited to 'esp8266/scripts')
-rw-r--r-- | esp8266/scripts/flashbdev.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/esp8266/scripts/flashbdev.py b/esp8266/scripts/flashbdev.py index a46d60be58..1427d9c427 100644 --- a/esp8266/scripts/flashbdev.py +++ b/esp8266/scripts/flashbdev.py @@ -26,6 +26,40 @@ class FlashBdev: if op == 5: # BP_IOCTL_SEC_SIZE return self.SEC_SIZE +def set_bl_flash_size(real_size): + if real_size == 256*1024: + code = 1 + elif real_size == 512*1024: + code = 0 + elif real_size == 1024*1024: + code = 2 + elif real_size == 2048*1024: + code = 3 + elif real_size == 4096*1024: + code = 4 + else: + code = 2 + buf = bytearray(4096) + esp.flash_read(0, buf) + buf[3] = (buf[3] & 0xf) | (code << 4) + esp.flash_erase(0) + esp.flash_write(0, buf) + +# If bootloader size ID doesn't correspond to real Flash size, +# fix bootloader value and reboot. +size = esp.flash_id() >> 16 +# Check that it looks like realistic power of 2 for flash sizes +# commonly used with esp8266 +if 22 >= size >= 18: + size = 1 << size + if size != esp.flash_size(): + import machine + import time + print("Bootloader Flash size appear to have been set incorrectly, trying to fix") + set_bl_flash_size(size) + machine.reset() + while 1: time.sleep(1) + if esp.flash_size() < 1024*1024: bdev = None else: |