Skip to content

Commit 23311f5

Browse files
covanampalmer-dabbelt
authored andcommitted
riscv: drop the use of XIP_OFFSET in XIP_FIXUP_FLASH_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_FLASH_OFFSET. Instead, use __data_loc and _sdata to do the same thing. While at it, also add a description for XIP_FIXUP_FLASH_OFFSET. Signed-off-by: Nam Cao <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/7b3319657edd1822f3457e7e7c07aaa326cc2f87.1717789719.git.namcao@linutronix.de Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent e4eac34 commit 23311f5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

arch/riscv/include/asm/xip_fixup.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@
2424
sub \reg, \reg, t0
2525
.endm
2626
.macro XIP_FIXUP_FLASH_OFFSET reg
27+
/* In linker script, at the transition from read-only section to
28+
* writable section, the VMA is increased while LMA remains the same.
29+
* (See in linker script how _sdata, __data_loc and LOAD_OFFSET is
30+
* changed)
31+
*
32+
* Consequently, early during boot before MMU is up, the generated code
33+
* reads the "writable" section at wrong addresses, because VMA is used
34+
* by compiler to generate code, but the data is located in Flash using
35+
* LMA.
36+
*/
37+
la t0, _sdata
38+
sub \reg, \reg, t0
2739
la t0, __data_loc
28-
REG_L t1, _xip_phys_offset
29-
sub \reg, \reg, t1
3040
add \reg, \reg, t0
3141
.endm
32-
33-
_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
3442
#else
3543
.macro XIP_FIXUP_OFFSET reg
3644
.endm

0 commit comments

Comments
 (0)