Skip to content

Commit

Permalink
gen_relocate_app.py: make generated/linker_relocate.ld deterministic
Browse files Browse the repository at this point in the history
Dictionaries are not ordered in Python 3.5 and before, so building twice
${ZEPHYR_BASE}/samples/application_development/code_relocation/
in a row could lead to a different sections order, different
build/zephyr/include/generated/linker_relocate.d and code_relocation.c
and different binaries.

Fix with a minor change to three "for" loops in the output functions:
make them iterate on sorted(list of sections) instead of the raw and
randomly ordered dictionaries of sections.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
  • Loading branch information
marc-hb authored and nashif committed Jun 27, 2019
1 parent 2a63e34 commit 6ccd026
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/gen_relocate_app.py
Expand Up @@ -197,7 +197,7 @@ def assign_to_correct_mem_region(memory_type,


def print_linker_sections(list_sections): def print_linker_sections(list_sections):
print_string = '' print_string = ''
for section in list_sections: for section in sorted(list_sections):
print_string += PRINT_TEMPLATE.format(section) print_string += PRINT_TEMPLATE.format(section)
return print_string return print_string


Expand Down Expand Up @@ -233,7 +233,9 @@ def generate_linker_script(linker_file, sram_data_linker_file,
gen_string = '' gen_string = ''
gen_string_sram_data = '' gen_string_sram_data = ''
gen_string_sram_bss = '' gen_string_sram_bss = ''
for memory_type, full_list_of_sections in complete_list_of_sections.items():
for memory_type, full_list_of_sections in \
sorted(complete_list_of_sections.items()):


if memory_type != "SRAM": if memory_type != "SRAM":
gen_string += MPU_RO_REGION_START.format(memory_type.lower(), gen_string += MPU_RO_REGION_START.format(memory_type.lower(),
Expand Down Expand Up @@ -393,7 +395,6 @@ def main():
# Create/or trucate file contents if it already exists # Create/or trucate file contents if it already exists
# raw = open(linker_file, "w") # raw = open(linker_file, "w")


code_generation = {"copy_code": '', "zero_code":'', "extern":''}
#for each memory_type, create text/rodata/data/bss sections for all obj files #for each memory_type, create text/rodata/data/bss sections for all obj files
for memory_type, files in rel_dict.items(): for memory_type, files in rel_dict.items():
full_list_of_sections = {"text":[], "rodata":[], "data":[], "bss":[]} full_list_of_sections = {"text":[], "rodata":[], "data":[], "bss":[]}
Expand All @@ -413,7 +414,10 @@ def main():


generate_linker_script(linker_file, sram_data_linker_file, generate_linker_script(linker_file, sram_data_linker_file,
sram_bss_linker_file, complete_list_of_sections) sram_bss_linker_file, complete_list_of_sections)
for mem_type, list_of_sections in complete_list_of_sections.items():
code_generation = {"copy_code": '', "zero_code":'', "extern":''}
for mem_type, list_of_sections in \
sorted(complete_list_of_sections.items()):
code_generation = generate_memcpy_code(mem_type, code_generation = generate_memcpy_code(mem_type,
list_of_sections, code_generation) list_of_sections, code_generation)


Expand Down

0 comments on commit 6ccd026

Please sign in to comment.