-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcreateMergedFirmware.py
More file actions
76 lines (65 loc) · 3.01 KB
/
Copy pathcreateMergedFirmware.py
File metadata and controls
76 lines (65 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''
Description:
This script merges firmware binaries for ESP32 and ESP8266 chip families using esptool.py.
It reads partition offsets from the partition CSV file and constructs the appropriate merge_bin command.
Usage:
python createMergedFirmware.py -c <ChipFamily> -b <BuildDir> -p <PathOfPartitionsCSV>
Arguments:
-c, --ChipFamily (str): The chip family (e.g., ESP8266, ESP32-S3, etc.). Default is 'ESP32'. Required.
-b, --BuildDir (str): The build directory containing the built firmware binaries. Required.
-p, --PathOfPartitionsCSV (str): The path to the partitions.csv file. Default is 'partitions.csv'. Required.
Functions:
readOffsetFromPartitionCSV(path: str, partitionLabel: str) -> int:
Args:
Returns:
Example:
python createMergedFirmware.py -c ESP32 -b ./build -p ./partitions.csv
'''
from myUtils import *
import argparse
import os
parser = argparse.ArgumentParser()
# erwartete Parameter
parser.add_argument('-c', '--ChipFamily', type=str, help='chipFamily, ESP8266, ESP32-S3, ...', default='ESP32', required=True)
parser.add_argument('-b', '--BuildDir', type=str, help='Build Verzeichnis welches die fertig gebauten Firmwares enthält', required=True)
parser.add_argument('-p', '--PathOfPartitionsCSV', type=str, help='Pfad wo die partitions.csv liegt', default='partitions.csv', required=True)
# Parsen der Argumente
args = parser.parse_args()
result = None
# Bootloader offsets vary by chip
bootloader_offsets = {
"ESP32": "0x1000",
"ESP32-S2": "0x1000",
"ESP32-S3": "0x0",
"ESP32-C2": "0x0",
"ESP32-C3": "0x0",
"ESP32-C5": "0x2000",
"ESP32-C6": "0x0",
"ESP32-H2": "0x0",
"ESP32-P4": "0x2000",
}
if(not os.path.isfile(args.PathOfPartitionsCSV)):
logging.error(f'File {args.PathOfPartitionsCSV} does not exist')
exit(1)
if args.BuildDir and os.path.isdir(args.BuildDir):
if 'ESP32' in args.ChipFamily:
bootloader_offset = bootloader_offsets[args.ChipFamily]
result = f'esptool --chip {args.ChipFamily} merge-bin \
--output {args.BuildDir}/merged-firmware.bin \
--flash-mode dout \
--flash-freq 80m \
--flash-size 4MB \
{bootloader_offset} {args.BuildDir}/bootloader.bin \
0x8000 {args.BuildDir}/partitions.bin \
{readOffsetFromPartitionCSV("partitions.csv", "app0")} {args.BuildDir}/firmware.bin'
if os.path.isfile(f'{args.BuildDir}/littlefs.bin'):
result += f' {readOffsetFromPartitionCSV("partitions.csv", "webdata")} {args.BuildDir}/littlefs.bin'
elif 'ESP8266' in args.ChipFamily and os.path.isfile(f'{args.BuildDir}/littlefs.bin'):
result = f'esptool --chip {args.ChipFamily} merge-bin \
--output {args.BuildDir}/merged-firmware.bin \
--flash-mode dout \
--flash-freq 40m \
--flash-size 4MB \
0x0000 {args.BuildDir}/firmware.bin \
{readOffsetFromPartitionCSV("partitions.csv", "webdata")} {args.BuildDir}/littlefs.bin'
print(f'command={result}')