|
6 | 6 |
|
7 | 7 | import gen_esp32part
|
8 | 8 |
|
9 |
| -OFFSET_BOOTLOADER = 0x1000 |
10 |
| -OFFSET_PARTITIONS = 0x8000 |
| 9 | +OFFSET_BOOTLOADER_DEFAULT = 0x1000 |
| 10 | +OFFSET_PARTITIONS_DEFAULT = 0x8000 |
| 11 | + |
| 12 | + |
| 13 | +def load_sdkconfig_hex_value(filename, value, default): |
| 14 | + value = "CONFIG_" + value + "=" |
| 15 | + with open(filename, "r") as f: |
| 16 | + for line in f: |
| 17 | + if line.startswith(value): |
| 18 | + return int(line.split("=", 1)[1], 16) |
| 19 | + return default |
11 | 20 |
|
12 | 21 |
|
13 | 22 | def load_partition_table(filename):
|
14 | 23 | with open(filename, "rb") as f:
|
15 | 24 | return gen_esp32part.PartitionTable.from_binary(f.read())
|
16 | 25 |
|
17 | 26 |
|
18 |
| -partition_table = load_partition_table(sys.argv[2]) |
| 27 | +# Extract command-line arguments. |
| 28 | +arg_sdkconfig = sys.argv[1] |
| 29 | +arg_bootloader_bin = sys.argv[2] |
| 30 | +arg_partitions_bin = sys.argv[3] |
| 31 | +arg_application_bin = sys.argv[4] |
| 32 | +arg_output_bin = sys.argv[5] |
| 33 | + |
| 34 | +# Load required sdkconfig values. |
| 35 | +offset_bootloader = load_sdkconfig_hex_value( |
| 36 | + arg_sdkconfig, "BOOTLOADER_OFFSET_IN_FLASH", OFFSET_BOOTLOADER_DEFAULT |
| 37 | +) |
| 38 | +offset_partitions = load_sdkconfig_hex_value( |
| 39 | + arg_sdkconfig, "PARTITION_TABLE_OFFSET", OFFSET_PARTITIONS_DEFAULT |
| 40 | +) |
| 41 | + |
| 42 | +# Load the partition table. |
| 43 | +partition_table = load_partition_table(arg_partitions_bin) |
19 | 44 |
|
20 |
| -max_size_bootloader = OFFSET_PARTITIONS - OFFSET_BOOTLOADER |
| 45 | +max_size_bootloader = offset_partitions - offset_bootloader |
21 | 46 | max_size_partitions = 0
|
22 | 47 | offset_application = 0
|
23 | 48 | max_size_application = 0
|
24 | 49 |
|
| 50 | +# Inspect the partition table to find offsets and maximum sizes. |
25 | 51 | for part in partition_table:
|
26 | 52 | if part.name == "nvs":
|
27 |
| - max_size_partitions = part.offset - OFFSET_PARTITIONS |
| 53 | + max_size_partitions = part.offset - offset_partitions |
28 | 54 | elif part.type == gen_esp32part.APP_TYPE and offset_application == 0:
|
29 | 55 | offset_application = part.offset
|
30 | 56 | max_size_application = part.size
|
31 | 57 |
|
| 58 | +# Define the input files, their location and maximum size. |
32 | 59 | files_in = [
|
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]), |
| 60 | + ("bootloader", offset_bootloader, max_size_bootloader, arg_bootloader_bin), |
| 61 | + ("partitions", offset_partitions, max_size_partitions, arg_partitions_bin), |
| 62 | + ("application", offset_application, max_size_application, arg_application_bin), |
36 | 63 | ]
|
37 |
| -file_out = sys.argv[4] |
| 64 | +file_out = arg_output_bin |
38 | 65 |
|
39 |
| -cur_offset = OFFSET_BOOTLOADER |
| 66 | +# Write output file with combined firmware. |
| 67 | +cur_offset = offset_bootloader |
40 | 68 | with open(file_out, "wb") as fout:
|
41 | 69 | for name, offset, max_size, file_in in files_in:
|
42 | 70 | assert offset >= cur_offset
|
|
0 commit comments