Skip to content

Commit f1fdbc5

Browse files
committed
Allow specifying custom application partition name // Issue #1166
This way developers can select an arbitrary partition which will be used for dynamic memory checks.
1 parent 95e0a73 commit f1fdbc5

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

builder/main.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,27 @@ def _update_max_upload_size(env):
144144
if p["type"] in ("0", "app")
145145
}
146146

147-
# One of the `factory` or `ota_0` partitions is used to determine available memory
148-
# size. If both partitions are set, we should prefer the `factory`, but there are
149-
# cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the `factory`
150-
# partition for their UF2 bootloader. So let's use the first match
147+
partitions = {p["name"]: p for p in _parse_partitions(env)}
148+
149+
# User-specified partition name has the highest priority
150+
custom_app_partition_name = board.get("build.app_partition_name", "")
151+
if custom_app_partition_name:
152+
selected_partition = partitions.get(custom_app_partition_name, {})
153+
if selected_partition:
154+
board.update("upload.maximum_size", _parse_size(selected_partition["size"]))
155+
return
156+
else:
157+
print(
158+
"Warning! Selected partition `%s` is not available in the partition " \
159+
"table! Default partition will be used!" % custom_app_partition_name
160+
)
161+
162+
# Otherwise, one of the `factory` or `ota_0` partitions is used to determine
163+
# available memory size. If both partitions are set, we should prefer the `factory`,
164+
# but there are cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the
165+
# `factory` partition for their UF2 bootloader. So let's use the first match
151166
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype
152-
for p in _parse_partitions(env):
167+
for p in partitions.values():
153168
if p["type"] in ("0", "app") and p["subtype"] in ("factory", "ota_0"):
154169
board.update("upload.maximum_size", _parse_size(p["size"]))
155170
break

0 commit comments

Comments
 (0)