From c1dc4a6f6104817f88cfeb316fbccd6c3bd3ceef Mon Sep 17 00:00:00 2001 From: Jim Shu Date: Wed, 1 Sep 2021 17:30:43 +0800 Subject: [PATCH] riscv: linker: fix __rom_region_end in non-XIP system In non-XIP system, because ROMABLE_REGION == RAMABLE_REGION, setting __rom_region_size/end symbol at linker script end will mistakely contain RAMABLE_REGION in it. Move __rom_region_end symbol to end of common ROMABLE_REGION (text and rodata) instead in non-XIP system. Signed-off-by: Jim Shu --- include/arch/riscv/common/linker.ld | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/arch/riscv/common/linker.ld b/include/arch/riscv/common/linker.ld index 6d932cafbf9..baed73aa628 100644 --- a/include/arch/riscv/common/linker.ld +++ b/include/arch/riscv/common/linker.ld @@ -188,6 +188,16 @@ SECTIONS #include __rodata_region_end = .; MPU_ALIGN(__rodata_region_end - __rom_region_start); + + /* For non-XIP system, __rom_region_end symbol should be set to + * the end of common ROMABLE_REGIONs (text and rodata) instead of + * the linker script end, so it wouldn't mistakely contain + * RAMABLE_REGION in it. + */ +#ifndef CONFIG_XIP + __rom_region_end = .; + __rom_region_size = __rom_region_end - __rom_region_start; +#endif /* CONFIG_XIP */ GROUP_END(ROMABLE_REGION) GROUP_START(RAMABLE_REGION) @@ -361,6 +371,11 @@ GROUP_END(DTCM) KEEP(*(.gnu.attributes)) } +/* Because ROMABLE_REGION != RAMABLE_REGION in XIP-system, it is valid + * to set __rom_region_end symbol at the end of linker script and + * doesn't mistakely contain the RAMABLE_REGION in it. + */ +#ifdef CONFIG_XIP /* Must be last in romable region */ SECTION_PROLOGUE(.last_section,(NOLOAD),) { @@ -370,5 +385,6 @@ SECTION_PROLOGUE(.last_section,(NOLOAD),) * calculate this value here. */ __rom_region_end = LOADADDR(.last_section); __rom_region_size = __rom_region_end - __rom_region_start; +#endif }