Skip to content

Commit f1fce6c

Browse files
authored
Improve dynamic memory size calculation // Resolves platformio#1159
For better results a partition with either `factory` or `ota_0` subtype should be used instead of selecting the biggest partition size with the type `app`. If both partitions are set, then the partition with the `factory` subtype is used by default.
1 parent 26aa55a commit f1fce6c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

builder/main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,17 @@ def _parse_partitions(env):
139139
def _update_max_upload_size(env):
140140
if not env.get("PARTITIONS_TABLE_CSV"):
141141
return
142-
sizes = [
143-
_parse_size(p["size"]) for p in _parse_partitions(env)
142+
sizes = {
143+
p["subtype"]: _parse_size(p["size"]) for p in _parse_partitions(env)
144144
if p["type"] in ("0", "app")
145-
]
146-
if sizes:
147-
board.update("upload.maximum_size", max(sizes))
145+
}
146+
147+
# One of the `factory` or `ota_0` partitions is used to determine available memory
148+
# size. If both partitions are set, then the `factory` partition is used by default
149+
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype
150+
max_upload_size = sizes.get("factory", sizes.get("ota_0", 0))
151+
if max_upload_size:
152+
board.update("upload.maximum_size", max_upload_size)
148153

149154

150155
def _to_unix_slashes(path):

0 commit comments

Comments
 (0)