|
1 |
| -import sys |
| 1 | +# Combine bootloader, partition table and application into a final binary. |
| 2 | + |
| 3 | +import os, sys |
| 4 | + |
| 5 | +sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table") |
| 6 | + |
| 7 | +import gen_esp32part |
2 | 8 |
|
3 | 9 | OFFSET_BOOTLOADER = 0x1000
|
4 | 10 | OFFSET_PARTITIONS = 0x8000
|
5 |
| -OFFSET_APPLICATION = 0x10000 |
| 11 | + |
| 12 | + |
| 13 | +def load_partition_table(filename): |
| 14 | + with open(filename, "rb") as f: |
| 15 | + return gen_esp32part.PartitionTable.from_binary(f.read()) |
| 16 | + |
| 17 | + |
| 18 | +partition_table = load_partition_table(sys.argv[2]) |
| 19 | + |
| 20 | +max_size_bootloader = OFFSET_PARTITIONS - OFFSET_BOOTLOADER |
| 21 | +max_size_partitions = 0 |
| 22 | +offset_application = 0 |
| 23 | +max_size_application = 0 |
| 24 | + |
| 25 | +for part in partition_table: |
| 26 | + if part.name == "nvs": |
| 27 | + max_size_partitions = part.offset - OFFSET_PARTITIONS |
| 28 | + elif part.type == gen_esp32part.APP_TYPE and offset_application == 0: |
| 29 | + offset_application = part.offset |
| 30 | + max_size_application = part.size |
6 | 31 |
|
7 | 32 | files_in = [
|
8 |
| - ("bootloader", OFFSET_BOOTLOADER, sys.argv[1]), |
9 |
| - ("partitions", OFFSET_PARTITIONS, sys.argv[2]), |
10 |
| - ("application", OFFSET_APPLICATION, sys.argv[3]), |
| 33 | + ("bootloader", OFFSET_BOOTLOADER, max_size_bootloader, sys.argv[1]), |
| 34 | + ("partitions", OFFSET_PARTITIONS, max_size_partitions, sys.argv[2]), |
| 35 | + ("application", offset_application, max_size_application, sys.argv[3]), |
11 | 36 | ]
|
12 | 37 | file_out = sys.argv[4]
|
13 | 38 |
|
14 | 39 | cur_offset = OFFSET_BOOTLOADER
|
15 | 40 | with open(file_out, "wb") as fout:
|
16 |
| - for name, offset, file_in in files_in: |
| 41 | + for name, offset, max_size, file_in in files_in: |
17 | 42 | assert offset >= cur_offset
|
18 | 43 | fout.write(b"\xff" * (offset - cur_offset))
|
19 | 44 | cur_offset = offset
|
20 | 45 | with open(file_in, "rb") as fin:
|
21 | 46 | data = fin.read()
|
22 | 47 | fout.write(data)
|
23 | 48 | cur_offset += len(data)
|
24 |
| - print("%-12s% 8d" % (name, len(data))) |
25 |
| - print("%-12s% 8d" % ("total", cur_offset)) |
| 49 | + print( |
| 50 | + "%-12s@0x%06x % 8d (% 8d remaining)" |
| 51 | + % (name, offset, len(data), max_size - len(data)) |
| 52 | + ) |
| 53 | + if len(data) > max_size: |
| 54 | + print( |
| 55 | + "ERROR: %s overflows allocated space of %d bytes by %d bytes" |
| 56 | + % (name, max_size, len(data) - max_size) |
| 57 | + ) |
| 58 | + sys.exit(1) |
| 59 | + print("%-22s% 8d" % ("total", cur_offset)) |
0 commit comments