From 725abdf4304d8aec843ff5be3bb577835b74d239 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 21 Jun 2019 15:06:39 -0700 Subject: [PATCH] gen_app_partitions.py: make generated/app_smem_*.ld files deterministic Dictionaries are not ordered in Python 3.5 and before, so building twice in a row could lead to a different partition order, different build/zephyr/include/generated/app_smem_*.ld files and different binaries. Fix with a minor change to the "for" loop in the output function: make it iterate on sorted(partitions.items()) instead of the raw and randomly ordered partitions dictionary. It is easy to reproduce the issue even without downgrading to an obsolete Python version; pick a test like samples/userspace/shared_mem/ and simply change the code to this: --- a/scripts/gen_app_partitions.py +++ b/scripts/gen_app_partitions.py @@ -159,10 +159,12 @@ def parse_elf_file(partitions): partitions[partition_name][SZ] += size +import random def generate_final_linker(linker_file, partitions): string = linker_start_seq size_string = '' - for partition, item in sorted(partitions.items()): + for partition, item in sorted(partitions.items(), + key=lambda x: random.random()): string += data_template.format(partition) if LIB in item: for lib in item[LIB]: Signed-off-by: Marc Herbert --- scripts/gen_app_partitions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gen_app_partitions.py b/scripts/gen_app_partitions.py index 3b6ff4751b5..616fb533d51 100644 --- a/scripts/gen_app_partitions.py +++ b/scripts/gen_app_partitions.py @@ -162,7 +162,7 @@ def parse_elf_file(partitions): def generate_final_linker(linker_file, partitions): string = linker_start_seq size_string = '' - for partition, item in partitions.items(): + for partition, item in sorted(partitions.items()): string += data_template.format(partition) if LIB in item: for lib in item[LIB]: