Skip to content

Commit ee490e2

Browse files
authored
fix function get_app_partition_offset() (#252)
1 parent 8e2cd72 commit ee490e2

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

builder/frameworks/espidf.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ def get_partition_info(pt_path, pt_offset, pt_params):
13491349
"offset",
13501350
]
13511351

1352-
if pt_params["name"] == "boot":
1352+
if pt_params.get("name") == "boot":
13531353
cmd.append("--partition-boot-default")
13541354
else:
13551355
cmd.extend(
@@ -1380,8 +1380,11 @@ def get_partition_info(pt_path, pt_offset, pt_params):
13801380

13811381
def get_app_partition_offset(pt_table, pt_offset):
13821382
# Get the default boot partition offset
1383-
app_params = get_partition_info(pt_table, pt_offset, {"name": "boot"})
1384-
return app_params.get("offset", "0x10000")
1383+
ota_app_params = get_partition_info(pt_table, pt_offset, {"type": "app", "subtype": "ota_0"})
1384+
if ota_app_params.get("offset"):
1385+
return ota_app_params["offset"]
1386+
factory_app_params = get_partition_info(pt_table, pt_offset, {"type": "app", "subtype": "factory"})
1387+
return factory_app_params.get("offset", "0x10000")
13851388

13861389

13871390
def preprocess_linker_file(src_ld_script, target_ld_script):
@@ -2234,33 +2237,12 @@ def _parse_size(value):
22342237
# Configure application partition offset
22352238
#
22362239

2237-
partitions_csv = env.subst("$PARTITIONS_TABLE_CSV")
2238-
result = []
2239-
next_offset = 0
2240-
bound = 0x10000
2241-
with open(partitions_csv) as fp:
2242-
for line in fp.readlines():
2243-
line = line.strip()
2244-
if not line or line.startswith("#"):
2245-
continue
2246-
tokens = [t.strip() for t in line.split(",")]
2247-
if len(tokens) < 5:
2248-
continue
2249-
partition = {
2250-
"name": tokens[0],
2251-
"type": tokens[1],
2252-
"subtype": tokens[2],
2253-
"offset": tokens[3] or next_offset,
2254-
"size": tokens[4],
2255-
"flags": tokens[5] if len(tokens) > 5 else None
2256-
}
2257-
result.append(partition)
2258-
next_offset = _parse_size(partition["offset"])
2259-
if (partition["subtype"] == "ota_0"):
2260-
bound = next_offset
2261-
next_offset = (next_offset + bound - 1) & ~(bound - 1)
2262-
2263-
env.Replace(ESP32_APP_OFFSET=str(hex(bound)))
2240+
app_offset = get_app_partition_offset(
2241+
env.subst("$PARTITIONS_TABLE_CSV"),
2242+
partition_table_offset
2243+
)
2244+
2245+
env.Replace(ESP32_APP_OFFSET=app_offset)
22642246

22652247
#
22662248
# Propagate application offset to debug configurations

0 commit comments

Comments
 (0)