Skip to content

Commit

Permalink
max_upload_size
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 committed Aug 3, 2023
1 parent 616509a commit 2a00a29
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,41 +159,23 @@ def _parse_partitions(env):
return result


def _parse_partitions(env):
partitions_csv = env.subst("$PARTITIONS_TABLE_CSV")
if not isfile(partitions_csv):
sys.stderr.write("Could not find the file %s with partitions "
"table.\n" % partitions_csv)
env.Exit(1)
def _update_max_upload_size(env):
if not env.get("PARTITIONS_TABLE_CSV"):
return

result = []
next_offset = 0
with open(partitions_csv) as fp:
for line in fp.readlines():
line = line.strip()
if not line or line.startswith("#"):
continue
tokens = [t.strip() for t in line.split(",")]
if len(tokens) < 5:
continue
partition = {
"name": tokens[0],
"type": tokens[1],
"subtype": tokens[2],
"offset": tokens[3] or next_offset,
"size": tokens[4],
"flags": tokens[5] if len(tokens) > 5 else None
}
result.append(partition)
next_offset = _parse_size(partition["offset"]) + _parse_size(
partition["size"]
)

bound = 0x10000 if partition["type"] in ("0", "app") else 4
next_offset = (next_offset + bound - 1) & ~(bound - 1)

return result
sizes = {
p["subtype"]: _parse_size(p["size"]) for p in _parse_partitions(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
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#subtype
for p in _parse_partitions(env):
if p["type"] in ("0", "app") and p["subtype"] in ("factory", "ota_0"):
board.update("upload.maximum_size", _parse_size(p["size"]))
break


def _to_unix_slashes(path):
Expand Down

0 comments on commit 2a00a29

Please sign in to comment.