Skip to content

Commit

Permalink
Allow specifying custom application partition name // Issue #1166
Browse files Browse the repository at this point in the history
This way developers can select an arbitrary partition which will be used
for dynamic memory checks.
  • Loading branch information
valeros committed Aug 7, 2023
1 parent 95e0a73 commit f1fdbc5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,27 @@ def _update_max_upload_size(env):
if p["type"] in ("0", "app")
}

# One of the `factory` or `ota_0` partitions is used to determine available memory
# size. If both partitions are set, we should prefer the `factory`, but there are
# cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the `factory`
# partition for their UF2 bootloader. So let's use the first match
partitions = {p["name"]: p for p in _parse_partitions(env)}

# User-specified partition name has the highest priority
custom_app_partition_name = board.get("build.app_partition_name", "")
if custom_app_partition_name:
selected_partition = partitions.get(custom_app_partition_name, {})
if selected_partition:
board.update("upload.maximum_size", _parse_size(selected_partition["size"]))
return
else:
print(
"Warning! Selected partition `%s` is not available in the partition " \
"table! Default partition will be used!" % custom_app_partition_name
)

# Otherwise, one of the `factory` or `ota_0` partitions is used to determine
# available memory size. If both partitions are set, we should prefer the `factory`,
# but there are cases (e.g. Adafruit's `partitions-4MB-tinyuf2.csv`) that uses the
# `factory` partition for their UF2 bootloader. So let's use the first match
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype
for p in _parse_partitions(env):
for p in partitions.values():
if p["type"] in ("0", "app") and p["subtype"] in ("factory", "ota_0"):
board.update("upload.maximum_size", _parse_size(p["size"]))
break
Expand Down

0 comments on commit f1fdbc5

Please sign in to comment.