summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/makeimg.py50
-rw-r--r--ports/esp32/partitions-16MiB.csv3
-rw-r--r--ports/esp32/partitions-2MiB.csv3
-rw-r--r--ports/esp32/partitions-ota.csv3
-rw-r--r--ports/esp32/partitions.csv3
5 files changed, 46 insertions, 16 deletions
diff --git a/ports/esp32/makeimg.py b/ports/esp32/makeimg.py
index 9f27ed6ef..fd0458318 100644
--- a/ports/esp32/makeimg.py
+++ b/ports/esp32/makeimg.py
@@ -1,19 +1,44 @@
-import sys
+# Combine bootloader, partition table and application into a final binary.
+
+import os, sys
+
+sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
+
+import gen_esp32part
OFFSET_BOOTLOADER = 0x1000
OFFSET_PARTITIONS = 0x8000
-OFFSET_APPLICATION = 0x10000
+
+
+def load_partition_table(filename):
+ with open(filename, "rb") as f:
+ return gen_esp32part.PartitionTable.from_binary(f.read())
+
+
+partition_table = load_partition_table(sys.argv[2])
+
+max_size_bootloader = OFFSET_PARTITIONS - OFFSET_BOOTLOADER
+max_size_partitions = 0
+offset_application = 0
+max_size_application = 0
+
+for part in partition_table:
+ if part.name == "nvs":
+ max_size_partitions = part.offset - OFFSET_PARTITIONS
+ elif part.type == gen_esp32part.APP_TYPE and offset_application == 0:
+ offset_application = part.offset
+ max_size_application = part.size
files_in = [
- ("bootloader", OFFSET_BOOTLOADER, sys.argv[1]),
- ("partitions", OFFSET_PARTITIONS, sys.argv[2]),
- ("application", OFFSET_APPLICATION, sys.argv[3]),
+ ("bootloader", OFFSET_BOOTLOADER, max_size_bootloader, sys.argv[1]),
+ ("partitions", OFFSET_PARTITIONS, max_size_partitions, sys.argv[2]),
+ ("application", offset_application, max_size_application, sys.argv[3]),
]
file_out = sys.argv[4]
cur_offset = OFFSET_BOOTLOADER
with open(file_out, "wb") as fout:
- for name, offset, file_in in files_in:
+ for name, offset, max_size, file_in in files_in:
assert offset >= cur_offset
fout.write(b"\xff" * (offset - cur_offset))
cur_offset = offset
@@ -21,5 +46,14 @@ with open(file_out, "wb") as fout:
data = fin.read()
fout.write(data)
cur_offset += len(data)
- print("%-12s% 8d" % (name, len(data)))
- print("%-12s% 8d" % ("total", cur_offset))
+ print(
+ "%-12s@0x%06x % 8d (% 8d remaining)"
+ % (name, offset, len(data), max_size - len(data))
+ )
+ if len(data) > max_size:
+ print(
+ "ERROR: %s overflows allocated space of %d bytes by %d bytes"
+ % (name, max_size, len(data) - max_size)
+ )
+ sys.exit(1)
+ print("%-22s% 8d" % ("total", cur_offset))
diff --git a/ports/esp32/partitions-16MiB.csv b/ports/esp32/partitions-16MiB.csv
index 5133185c7..20d06bad4 100644
--- a/ports/esp32/partitions-16MiB.csv
+++ b/ports/esp32/partitions-16MiB.csv
@@ -1,6 +1,5 @@
# Notes: the offset of the partition table itself is set in
-# $ESPIDF/components/partition_table/Kconfig.projbuild and the
-# offset of the factory/ota_0 partition is set in makeimg.py
+# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
diff --git a/ports/esp32/partitions-2MiB.csv b/ports/esp32/partitions-2MiB.csv
index 2d3d4c120..73925a514 100644
--- a/ports/esp32/partitions-2MiB.csv
+++ b/ports/esp32/partitions-2MiB.csv
@@ -1,6 +1,5 @@
# Notes: the offset of the partition table itself is set in
-# $ESPIDF/components/partition_table/Kconfig.projbuild and the
-# offset of the factory/ota_0 partition is set in makeimg.py
+# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
diff --git a/ports/esp32/partitions-ota.csv b/ports/esp32/partitions-ota.csv
index 08576b6a3..094ad7666 100644
--- a/ports/esp32/partitions-ota.csv
+++ b/ports/esp32/partitions-ota.csv
@@ -1,7 +1,6 @@
# Partition table for MicroPython with OTA support using 4MB flash
# Notes: the offset of the partition table itself is set in
-# $ESPIDF/components/partition_table/Kconfig.projbuild and the
-# offset of the factory/ota_0 partition is set in makeimg.py
+# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xd000, 0x2000,
diff --git a/ports/esp32/partitions.csv b/ports/esp32/partitions.csv
index 68ab4b356..d304dccc5 100644
--- a/ports/esp32/partitions.csv
+++ b/ports/esp32/partitions.csv
@@ -1,6 +1,5 @@
# Notes: the offset of the partition table itself is set in
-# $ESPIDF/components/partition_table/Kconfig.projbuild and the
-# offset of the factory/ota_0 partition is set in makeimg.py
+# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,