From a65de0ab1f4f6b21b490ab3ba1c972bd82cd1a1b Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Thu, 14 Oct 2021 12:34:27 +0800 Subject: [PATCH] ldgen: generate ld files with fixed order of entries --- tools/ci/check_copyright_ignore.txt | 3 --- tools/ldgen/generation.py | 17 +++---------- tools/ldgen/linker_script.py | 17 ++----------- tools/ldgen/test/test_generation.py | 39 +++++++---------------------- 4 files changed, 14 insertions(+), 62 deletions(-) diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 7a09bc81fd..a221d98858 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -3952,17 +3952,14 @@ tools/kconfig_new/test/gen_kconfig_doc/test_kconfig_out.py tools/kconfig_new/test/gen_kconfig_doc/test_target_visibility.py tools/ldgen/entity.py tools/ldgen/fragments.py -tools/ldgen/generation.py tools/ldgen/ldgen.py tools/ldgen/ldgen_common.py -tools/ldgen/linker_script.py tools/ldgen/output_commands.py tools/ldgen/samples/template.ld tools/ldgen/sdkconfig.py tools/ldgen/test/data/linker_script.ld tools/ldgen/test/test_entity.py tools/ldgen/test/test_fragments.py -tools/ldgen/test/test_generation.py tools/ldgen/test/test_output_commands.py tools/mass_mfg/mfg_gen.py tools/mkdfu.py diff --git a/tools/ldgen/generation.py b/tools/ldgen/generation.py index 910969dd60..74a6d0ba60 100644 --- a/tools/ldgen/generation.py +++ b/tools/ldgen/generation.py @@ -1,17 +1,6 @@ # -# Copyright 2021 Espressif Systems (Shanghai) CO LTD -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 # import collections @@ -251,7 +240,7 @@ class EntityNode(): self.child_placement(entity, sections, target, flags, sections_db) def get_output_sections(self): - return sorted(self.placements.keys(), key=' '.join) + return sorted(self.placements.keys(), key=lambda x: sorted(x)) # pylint: disable=W0108 class SymbolNode(EntityNode): diff --git a/tools/ldgen/linker_script.py b/tools/ldgen/linker_script.py index c15b397a24..968ac776a5 100644 --- a/tools/ldgen/linker_script.py +++ b/tools/ldgen/linker_script.py @@ -1,17 +1,6 @@ # -# Copyright 2021 Espressif Systems (Shanghai) CO LTD -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 # import collections @@ -69,8 +58,6 @@ class LinkerScript: target = member.target rules = member.rules - del rules[:] - rules.extend(mapping_rules[target]) except KeyError: message = GenerationException.UNDEFINED_REFERENCE + " to target '" + target + "'." diff --git a/tools/ldgen/test/test_generation.py b/tools/ldgen/test/test_generation.py index 28aac1c974..26e038aafe 100755 --- a/tools/ldgen/test/test_generation.py +++ b/tools/ldgen/test/test_generation.py @@ -1,18 +1,7 @@ #!/usr/bin/env python # -# Copyright 2021 Espressif Systems (Shanghai) CO LTD -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 # import collections @@ -102,32 +91,22 @@ class GenerationTest(unittest.TestCase): def generate_default_rules(self): rules = collections.defaultdict(list) - rules['flash_text'].append(InputSectionDesc(ROOT, ['.literal', '.literal.*', '.text', '.text.*'], [])) - rules['flash_rodata'].append(InputSectionDesc(ROOT, ['.rodata', '.rodata.*'], [])) - rules['dram0_data'].append(InputSectionDesc(ROOT, ['.data', '.data.*'], [])) - rules['dram0_data'].append(InputSectionDesc(ROOT, ['.dram', '.dram.*'], [])) rules['dram0_bss'].append(InputSectionDesc(ROOT, ['.bss', '.bss.*'], [])) rules['dram0_bss'].append(InputSectionDesc(ROOT, ['COMMON'], [])) + rules['dram0_data'].append(InputSectionDesc(ROOT, ['.data', '.data.*'], [])) + rules['dram0_data'].append(InputSectionDesc(ROOT, ['.dram', '.dram.*'], [])) + rules['flash_text'].append(InputSectionDesc(ROOT, ['.literal', '.literal.*', '.text', '.text.*'], [])) + rules['flash_rodata'].append(InputSectionDesc(ROOT, ['.rodata', '.rodata.*'], [])) rules['iram0_text'].append(InputSectionDesc(ROOT, ['.iram', '.iram.*'], [])) - rules['rtc_text'].append(InputSectionDesc(ROOT, ['.rtc.text', '.rtc.literal'], [])) + rules['rtc_bss'].append(InputSectionDesc(ROOT, ['.rtc.bss'], [])) rules['rtc_data'].append(InputSectionDesc(ROOT, ['.rtc.data'], [])) rules['rtc_data'].append(InputSectionDesc(ROOT, ['.rtc.rodata'], [])) - rules['rtc_bss'].append(InputSectionDesc(ROOT, ['.rtc.bss'], [])) + rules['rtc_text'].append(InputSectionDesc(ROOT, ['.rtc.text', '.rtc.literal'], [])) return rules def compare_rules(self, expected, actual): - self.assertEqual(set(expected.keys()), set(actual.keys())) - - for target in sorted(actual.keys()): - message = 'failed target %s' % target - a_cmds = actual[target] - e_cmds = expected[target] - - self.assertEqual(len(a_cmds), len(e_cmds), message) - - for a, e in zip(a_cmds, e_cmds): - self.assertEqual(a, e, message) + self.assertEqual(expected, actual) def get_default(self, target, rules): return rules[target][0]