Skip to content

Commit 0f66032

Browse files
authored
fix custom partiton table offset calculation
1 parent 59f5a33 commit 0f66032

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

builder/main.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _parse_partitions(env):
131131

132132
result = []
133133
next_offset = 0
134-
bound = int(board.get("upload.offset_address", "0x10000"), 16) # default 0x10000
134+
app_offset = int(board.get("upload.offset_address", "0x10000"), 16) # default 0x10000
135135
with open(partitions_csv) as fp:
136136
for line in fp.readlines():
137137
line = line.strip()
@@ -140,23 +140,25 @@ def _parse_partitions(env):
140140
tokens = [t.strip() for t in line.split(",")]
141141
if len(tokens) < 5:
142142
continue
143+
bound = 0x10000 if tokens[1] in ("0", "app") else 4
144+
calculated_offset = (next_offset + bound - 1) & ~(bound - 1)
143145
partition = {
144146
"name": tokens[0],
145147
"type": tokens[1],
146148
"subtype": tokens[2],
147-
"offset": tokens[3] or next_offset,
149+
"offset": tokens[3] or calculated_offset,
148150
"size": tokens[4],
149151
"flags": tokens[5] if len(tokens) > 5 else None
150152
}
151153
result.append(partition)
152154
next_offset = _parse_size(partition["offset"])
153155
if (partition["subtype"] == "ota_0"):
154-
bound = next_offset
155-
next_offset = (next_offset + bound - 1) & ~(bound - 1)
156+
app_offset = next_offset
157+
next_offset = next_offset + _parse_size(partition["size"])
156158
# Configure application partition offset
157-
env.Replace(ESP32_APP_OFFSET=str(hex(bound)))
159+
env.Replace(ESP32_APP_OFFSET=str(hex(app_offset)))
158160
# Propagate application offset to debug configurations
159-
env["INTEGRATION_EXTRA_DATA"].update({"application_offset": str(hex(bound))})
161+
env["INTEGRATION_EXTRA_DATA"].update({"application_offset": str(hex(app_offset))})
160162
return result
161163

162164

@@ -253,7 +255,7 @@ def __fetch_fs_size(target, source, env):
253255
GDB=join(
254256
platform.get_package_dir(
255257
"riscv32-esp-elf-gdb"
256-
if mcu in ("esp32c2", "esp32c3", "esp32c6")
258+
if mcu in ("esp32c2", "esp32c3", "esp32c6", "esp32h2")
257259
else "xtensa-esp-elf-gdb"
258260
)
259261
or "",

0 commit comments

Comments
 (0)