summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2022-07-29 15:25:10 -0500
committerDamien George <damien@micropython.org>2022-08-06 00:01:10 +1000
commit9a51273d96405527e3950441cfebc6c7314a6bcf (patch)
tree2af074c631e0467e22733767e6e762e8fd9217db
parent7cc6df3303f467e218a6ac4f12924eac0ed15045 (diff)
stm32/boards/LEGO_HUB_NO6/appupdate: Detect filesystem size at runtime.
This changes appupdate.py to get the filesystem size at runtime. This will allow the code to be shared with LEGO_HUB_NO7 which has a similar flash chip with a different size. Signed-off-by: David Lechner <david@pybricks.com>
-rw-r--r--ports/stm32/boards/LEGO_HUB_NO6/appupdate.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py
index 0927f1611..57b24d3f2 100644
--- a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py
+++ b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py
@@ -2,13 +2,20 @@
# MIT license; Copyright (c) 2022 Damien P. George
from micropython import const
-import struct, machine, fwupdate, spiflash
+import struct, machine, fwupdate, spiflash, pyb
+
+_IOCTL_BLOCK_COUNT = const(4)
+_IOCTL_BLOCK_SIZE = const(5)
_SPIFLASH_UPDATE_KEY_ADDR = const(1020 * 1024)
_SPIFLASH_UPDATE_KEY_VALUE = const(0x12345678)
_FILESYSTEM_ADDR = const(0x8000_0000 + 1024 * 1024)
-_FILESYSTEM_LEN = const(31 * 1024 * 1024)
+
+# Roundabout way to get actual filesystem size from config.
+# This takes into account the 1M "reserved" section of the flash memory.
+flash = pyb.Flash(start=0)
+_FILESYSTEM_LEN = flash.ioctl(_IOCTL_BLOCK_COUNT, None) * flash.ioctl(_IOCTL_BLOCK_SIZE, None)
def update_app(filename):
@@ -30,6 +37,8 @@ def update_app(filename):
baudrate=50_000_000,
)
cs = machine.Pin(machine.Pin.board.FLASH_NSS, machine.Pin.OUT, value=1)
+
+ # We can't use pyb.Flash() because we need to write to the "reserved" 1M area.
flash = spiflash.SPIFlash(spi, cs)
# Write the update key and elements to the SPI flash.