Skip to content

Commit 09af98a

Browse files
wentongwunashif
authored andcommitted
scripts: gen_relocate_app.py: add custom align size for relocation
add custom align size for code relocation to reduce alignment memory wasting. Fixes: #17337. Signed-off-by: Wentong Wu <[email protected]>
1 parent da31c81 commit 09af98a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/gen_relocate_app.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@
8484
{{
8585
__{0}_{1}_start = .;
8686
{4}
87+
#if {6}
88+
. = ALIGN({6});
89+
#else
8790
MPU_ALIGN(__{0}_{1}_size);
91+
#endif
8892
__{0}_{1}_end = .;
8993
}} {5}
9094
__{0}_{1}_size = __{0}_{1}_end - __{0}_{1}_start;
@@ -187,6 +191,12 @@ def assign_to_correct_mem_region(memory_type,
187191
iteration_sections["text"] or iteration_sections["rodata"]):
188192
all_regions = True
189193

194+
pos = memory_type.find('_')
195+
if pos in range(len(memory_type)):
196+
align_size = int(memory_type[pos+1:])
197+
memory_type = memory_type[:pos]
198+
mpu_align[memory_type] = align_size
199+
190200
if memory_type in complete_list_of_sections:
191201
for iter_sec in ["text", "rodata", "data", "bss"]:
192202
if ((iteration_sections[iter_sec] or all_regions) and
@@ -229,8 +239,12 @@ def string_create_helper(region, memory_type,
229239
linker_string += tmp
230240
else:
231241
if memory_type != 'SRAM' and region == 'rodata':
242+
align_size = 0
243+
if memory_type in mpu_align.keys():
244+
align_size = mpu_align[memory_type]
245+
232246
linker_string += LINKER_SECTION_SEQ_MPU.format(memory_type.lower(), region, memory_type.upper(),
233-
region.upper(), tmp, load_address_string)
247+
region.upper(), tmp, load_address_string, align_size)
234248
else:
235249
linker_string += LINKER_SECTION_SEQ.format(memory_type.lower(), region, memory_type.upper(),
236250
region.upper(), tmp, load_address_string)
@@ -389,6 +403,8 @@ def create_dict_wrt_mem():
389403

390404

391405
def main():
406+
global mpu_align
407+
mpu_align = {}
392408
parse_args()
393409
searchpath = args.directory
394410
linker_file = args.output

0 commit comments

Comments
 (0)