Skip to content

Commit 0aa4e7b

Browse files
committed
Merge branch 'develop' into feature/stage
* develop: Custom Partition Tables // Resolve #58
2 parents 44f431e + fd9ed71 commit 0aa4e7b

File tree

5 files changed

+95
-45
lines changed

5 files changed

+95
-45
lines changed

boards/nina_w10.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"flash_mode": "dio",
88
"ldscript": "esp32_out.ld",
99
"mcu": "esp32",
10-
"partitions": "minimal",
10+
"partitions": "minimal.csv",
1111
"variant": "nina_w10"
1212
},
1313
"connectivity": [

builder/frameworks/espidf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def build_espidf_bootloader():
302302

303303
FLASH_EXTRA_IMAGES=[
304304
("0x1000", join("$BUILD_DIR", "bootloader.bin")),
305-
("0x8000", join("$BUILD_DIR", "partitions_table.bin"))
305+
("0x8000", join("$BUILD_DIR", "partitions.bin"))
306306
]
307307
)
308308

@@ -339,17 +339,16 @@ def build_espidf_bootloader():
339339
# Generate partition table
340340
#
341341

342-
# Export path to the partitions table
342+
fwpartitions_dir = join(FRAMEWORK_DIR, "components", "partition_table")
343+
partitions_csv = env.BoardConfig().get("build.partitions",
344+
"partitions_singleapp.csv")
343345
env.Replace(
344-
PARTITION_TABLE_CSV=join(
345-
FRAMEWORK_DIR, "components", "partition_table",
346-
"%s.csv" % env.BoardConfig().get("build.partitions", "partitions_singleapp")
347-
)
348-
)
346+
PARTITIONS_TABLE_CSV=join(fwpartitions_dir, partitions_csv) if isfile(
347+
join(fwpartitions_dir, partitions_csv)) else partitions_csv)
349348

350349
partition_table = env.Command(
351-
join("$BUILD_DIR", "partitions_table.bin"),
352-
"$PARTITION_TABLE_CSV",
350+
join("$BUILD_DIR", "partitions.bin"),
351+
"$PARTITIONS_TABLE_CSV",
353352
env.VerboseAction('"$PYTHONEXE" "%s" -q $SOURCE $TARGET' % join(
354353
FRAMEWORK_DIR, "components", "partition_table", "gen_esp32part.py"),
355354
"Generating partitions $TARGET"))

builder/frameworks/pumbaa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def VariantDirWrap(env, variant_dir, src_dir, duplicate=False):
5454

5555
env.Replace(
5656
PLATFORMFW_DIR=env.PioPlatform().get_package_dir("framework-pumbaa"),
57-
UPLOADERFLAGS=[], # Backward compatibility for obsolete build script
57+
UPLOADERFLAGS=[] # Backward compatibility for obsolete build script
5858
)
5959

6060
SConscript(

builder/frameworks/simba.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ def VariantDirWrap(env, variant_dir, src_dir, duplicate=False):
5151
env.AddMethod(VariantDirWrap)
5252

5353
env.Replace(
54-
PLATFORMFW_DIR=env.PioPlatform().get_package_dir("framework-simba")
55-
)
56-
57-
env.Append(
58-
UPLOADERFLAGS=[
59-
"0x1000", join("$PLATFORMFW_DIR", "3pp", "esp32",
60-
"bin", "bootloader.bin"),
61-
"0x4000", join("$PLATFORMFW_DIR", "3pp", "esp32",
62-
"bin", "partitions_singleapp.bin"),
63-
"0x10000"
64-
]
54+
PLATFORMFW_DIR=env.PioPlatform().get_package_dir("framework-simba"),
55+
UPLOADERFLAGS=[] # Backward compatibility for obsolete build script
6556
)
6657

6758
SConscript(
6859
[env.subst(join("$PLATFORMFW_DIR", "make", "platformio.sconscript"))])
60+
61+
env.Replace(
62+
FLASH_EXTRA_IMAGES=[
63+
("0x1000", join("$PLATFORMFW_DIR", "3pp", "esp32",
64+
"bin", "bootloader.bin")),
65+
("0x8000", join("$PLATFORMFW_DIR", "3pp", "esp32",
66+
"bin", "partitions_singleapp.bin"))
67+
]
68+
)

builder/main.py

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
DefaultEnvironment)
2121

2222

23+
#
24+
# Helpers
25+
#
26+
2327
def _get_board_f_flash(env):
2428
frequency = env.subst("$BOARD_F_FLASH")
2529
frequency = str(frequency).replace("L", "")
@@ -34,30 +38,73 @@ def _get_board_flash_mode(env):
3438
return "dout"
3539
return mode
3640

41+
42+
def _parse_size(value):
43+
if value.isdigit():
44+
return int(value)
45+
elif value.startswith("0x"):
46+
return int(value, 16)
47+
elif value[-1] in ("K", "M"):
48+
base = 1024 if value[-1] == "K" else 1024 * 1024
49+
return int(value[:-1]) * base
50+
return value
51+
52+
53+
def _parse_partitions(env):
54+
partitions_csv = env.subst("$PARTITIONS_TABLE_CSV")
55+
if not isfile(partitions_csv):
56+
sys.stderr.write("Could not find the file %s with partitions "
57+
"table.\n" % partitions_csv)
58+
env.Exit(1)
59+
60+
result = []
61+
with open(partitions_csv) as fp:
62+
for line in fp.readlines():
63+
line = line.strip()
64+
if not line or line.startswith("#"):
65+
continue
66+
tokens = [t.strip() for t in line.split(",") if t.strip()]
67+
if len(tokens) < 5:
68+
continue
69+
result.append({
70+
"name": tokens[0],
71+
"type": tokens[1],
72+
"subtype": tokens[2],
73+
"offset": tokens[3],
74+
"size": tokens[4],
75+
"flags": tokens[5] if len(tokens) > 5 else None
76+
})
77+
return result
78+
79+
80+
def _update_max_upload_size(env):
81+
if not env.get("PARTITIONS_TABLE_CSV"):
82+
return
83+
sizes = [
84+
_parse_size(p['size']) for p in _parse_partitions(env)
85+
if p['type'] in ("0", "app")
86+
]
87+
if sizes:
88+
env.BoardConfig().update("upload.maximum_size", max(sizes))
89+
90+
3791
#
3892
# SPIFFS helpers
3993
#
4094

4195
def fetch_spiffs_size(env):
42-
path_to_patition_table = env.get("PARTITION_TABLE_CSV")
43-
if not isfile(path_to_patition_table):
44-
sys.stderr.write("Could not find the file %s with paritions table." %
45-
path_to_patition_table)
46-
env.Exit(1)
47-
48-
with open(path_to_patition_table) as fp:
49-
for l in fp.readlines():
50-
if l.startswith("spiffs"):
51-
spiffs_config = [s.strip() for s in l.split(",")]
52-
env["SPIFFS_START"] = spiffs_config[3]
53-
env["SPIFFS_SIZE"] = spiffs_config[4]
54-
env["SPIFFS_PAGE"] = "0x100"
55-
env["SPIFFS_BLOCK"] = "0x1000"
56-
return
57-
58-
sys.stderr.write("Could not find the spiffs section in the paritions "
59-
"file %s" % path_to_patition_table)
60-
env.Exit(1)
96+
spiffs = None
97+
for p in _parse_partitions(env):
98+
if p['type'] == "data" and p['subtype'] == "spiffs":
99+
spiffs = p
100+
if not spiffs:
101+
sys.stderr.write(
102+
env.subst("Could not find the `spiffs` section in the partitions "
103+
"table $PARTITIONS_TABLE_CSV\n"))
104+
env["SPIFFS_START"] = _parse_size(spiffs['offset'])
105+
env["SPIFFS_SIZE"] = _parse_size(spiffs['size'])
106+
env["SPIFFS_PAGE"] = int("0x100", 16)
107+
env["SPIFFS_BLOCK"] = int("0x1000", 16)
61108

62109

63110
def __fetch_spiffs_size(target, source, env):
@@ -157,9 +204,9 @@ def __fetch_spiffs_size(target, source, env):
157204
action=env.VerboseAction(" ".join([
158205
'"$MKSPIFFSTOOL"',
159206
"-c", "$SOURCES",
160-
"-p", "${int(SPIFFS_PAGE, 16)}",
161-
"-b", "${int(SPIFFS_BLOCK, 16)}",
162-
"-s", "${int(SPIFFS_SIZE, 16)}",
207+
"-p", "$SPIFFS_PAGE",
208+
"-b", "$SPIFFS_BLOCK",
209+
"-s", "$SPIFFS_SIZE",
163210
"$TARGET"
164211
]), "Building SPIFFS image from '$SOURCES' directory to $TARGET"),
165212
emitter=__fetch_spiffs_size,
@@ -194,6 +241,10 @@ def __fetch_spiffs_size(target, source, env):
194241
AlwaysBuild(env.Alias("nobuild", target_firm))
195242
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
196243

244+
# update max upload size based on CSV file
245+
if "upload" in COMMAND_LINE_TARGETS:
246+
_update_max_upload_size(env)
247+
197248
#
198249
# Target: Print binary size
199250
#
@@ -263,7 +314,7 @@ def __fetch_spiffs_size(target, source, env):
263314
"write_flash", "-z",
264315
"--flash_mode", "$BOARD_FLASH_MODE",
265316
"--flash_size", "detect",
266-
"${int(SPIFFS_START, 16)}"
317+
"$SPIFFS_START"
267318
],
268319
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE',
269320
)

0 commit comments

Comments
 (0)