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 }