Skip to content

Commit aa3457f

Browse files
covanampalmer-dabbelt
authored andcommitted
riscv: cleanup XIP_FIXUP macro
The XIP_FIXUP macro is used to fix addresses early during boot before MMU: generated code "thinks" the data section is in ROM while it is actually in RAM. So this macro corrects the addresses in the data section. This macro determines if the address needs to be fixed by checking if it is within the range starting from ROM address up to the size of (2 * XIP_OFFSET). This means if the kernel size is bigger than (2 * XIP_OFFSET), some addresses would not be fixed up. XIP kernel can still work if the above scenario does not happen. But this macro is obviously incorrect. Rewrite this macro to only fix up addresses within the data section. Signed-off-by: Nam Cao <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/95f50a4ec8204ec4fcbf2a80c9addea0e0609e3b.1717789719.git.namcao@linutronix.de Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 57d76bc commit aa3457f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@
142142

143143
#ifdef CONFIG_XIP_KERNEL
144144
#define XIP_FIXUP(addr) ({ \
145+
extern char _sdata[], _start[], _end[]; \
146+
uintptr_t __rom_start_data = CONFIG_XIP_PHYS_ADDR \
147+
+ (uintptr_t)&_sdata - (uintptr_t)&_start; \
148+
uintptr_t __rom_end_data = CONFIG_XIP_PHYS_ADDR \
149+
+ (uintptr_t)&_end - (uintptr_t)&_start; \
145150
uintptr_t __a = (uintptr_t)(addr); \
146-
(__a >= CONFIG_XIP_PHYS_ADDR && \
147-
__a < CONFIG_XIP_PHYS_ADDR + XIP_OFFSET * 2) ? \
148-
__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
149-
__a; \
151+
(__a >= __rom_start_data && __a < __rom_end_data) ? \
152+
__a - __rom_start_data + CONFIG_PHYS_RAM_BASE : __a; \
150153
})
151154
#else
152155
#define XIP_FIXUP(addr) (addr)

0 commit comments

Comments
 (0)