Skip to content

Commit e4eac34

Browse files
covanampalmer-dabbelt
authored andcommitted
riscv: drop the use of XIP_OFFSET in XIP_FIXUP_OFFSET
XIP_OFFSET is the hard-coded offset of writable data section within the kernel. By hard-coding this value, the read-only section of the kernel (which is placed before the writable data section) is restricted in size. As a preparation to remove this hard-coded macro XIP_OFFSET entirely, stop using XIP_OFFSET in XIP_FIXUP_OFFSET. Instead, use CONFIG_PHYS_RAM_BASE and _sdata to do the same thing. While at it, also add a description for XIP_FIXUP_OFFSET. Signed-off-by: Nam Cao <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/dba0409518b14ee83b346e099b1f7f934daf7b74.1717789719.git.namcao@linutronix.de Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 5cf0896 commit e4eac34

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/riscv/include/asm/xip_fixup.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99

1010
#ifdef CONFIG_XIP_KERNEL
1111
.macro XIP_FIXUP_OFFSET reg
12-
REG_L t0, _xip_fixup
12+
/* Fix-up address in Flash into address in RAM early during boot before
13+
* MMU is up. Because generated code "thinks" data is in Flash, but it
14+
* is actually in RAM (actually data is also in Flash, but Flash is
15+
* read-only, thus we need to use the data residing in RAM).
16+
*
17+
* The start of data in Flash is _sdata and the start of data in RAM is
18+
* CONFIG_PHYS_RAM_BASE. So this fix-up essentially does this:
19+
* reg += CONFIG_PHYS_RAM_BASE - _start
20+
*/
21+
li t0, CONFIG_PHYS_RAM_BASE
1322
add \reg, \reg, t0
23+
la t0, _sdata
24+
sub \reg, \reg, t0
1425
.endm
1526
.macro XIP_FIXUP_FLASH_OFFSET reg
1627
la t0, __data_loc
@@ -19,7 +30,6 @@
1930
add \reg, \reg, t0
2031
.endm
2132

22-
_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
2333
_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
2434
#else
2535
.macro XIP_FIXUP_OFFSET reg

0 commit comments

Comments
 (0)