Skip to content

Commit f9ace4e

Browse files
vwoolpalmer-dabbelt
authored andcommitted
riscv: remove .text section size limitation for XIP
Currently there's a limit of 8MB for the .text section of a RISC-V image in the XIP case. This breaks compilation of many automatic builds and is generally inconvenient. This patch removes that limitation and optimizes XIP image file size at the same time. Signed-off-by: Vitaly Wool <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 241527b commit f9ace4e

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
#endif
7676

7777
#ifdef CONFIG_XIP_KERNEL
78-
#define XIP_OFFSET SZ_8M
78+
#define XIP_OFFSET SZ_32M
79+
#define XIP_OFFSET_MASK (SZ_32M - 1)
7980
#else
8081
#define XIP_OFFSET 0
8182
#endif
@@ -97,7 +98,8 @@
9798
#ifdef CONFIG_XIP_KERNEL
9899
#define XIP_FIXUP(addr) ({ \
99100
uintptr_t __a = (uintptr_t)(addr); \
100-
(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ? \
101+
(__a >= CONFIG_XIP_PHYS_ADDR && \
102+
__a < CONFIG_XIP_PHYS_ADDR + XIP_OFFSET * 2) ? \
101103
__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
102104
__a; \
103105
})

arch/riscv/kernel/head.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
REG_L t0, _xip_fixup
2121
add \reg, \reg, t0
2222
.endm
23+
.macro XIP_FIXUP_FLASH_OFFSET reg
24+
la t1, __data_loc
25+
li t0, XIP_OFFSET_MASK
26+
and t1, t1, t0
27+
li t1, XIP_OFFSET
28+
sub t0, t0, t1
29+
sub \reg, \reg, t0
30+
.endm
2331
_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
2432
#else
2533
.macro XIP_FIXUP_OFFSET reg
2634
.endm
35+
.macro XIP_FIXUP_FLASH_OFFSET reg
36+
.endm
2737
#endif /* CONFIG_XIP_KERNEL */
2838

2939
__HEAD
@@ -266,6 +276,7 @@ pmp_done:
266276
la a3, hart_lottery
267277
mv a2, a3
268278
XIP_FIXUP_OFFSET a2
279+
XIP_FIXUP_FLASH_OFFSET a3
269280
lw t1, (a3)
270281
amoswap.w t0, t1, (a2)
271282
/* first time here if hart_lottery in RAM is not set */
@@ -304,6 +315,7 @@ clear_bss_done:
304315
XIP_FIXUP_OFFSET sp
305316
#ifdef CONFIG_BUILTIN_DTB
306317
la a0, __dtb_start
318+
XIP_FIXUP_OFFSET a0
307319
#else
308320
mv a0, s1
309321
#endif /* CONFIG_BUILTIN_DTB */

arch/riscv/kernel/vmlinux-xip.lds.S

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ SECTIONS
6464
/*
6565
* From this point, stuff is considered writable and will be copied to RAM
6666
*/
67-
__data_loc = ALIGN(16); /* location in file */
68-
. = LOAD_OFFSET + XIP_OFFSET; /* location in memory */
67+
__data_loc = ALIGN(PAGE_SIZE); /* location in file */
68+
. = KERNEL_LINK_ADDR + XIP_OFFSET; /* location in memory */
69+
70+
#undef LOAD_OFFSET
71+
#define LOAD_OFFSET (KERNEL_LINK_ADDR + XIP_OFFSET - (__data_loc & XIP_OFFSET_MASK))
6972

7073
_sdata = .; /* Start of data section */
7174
_data = .;
@@ -96,7 +99,6 @@ SECTIONS
9699
KEEP(*(__soc_builtin_dtb_table))
97100
__soc_builtin_dtb_table_end = .;
98101
}
99-
PERCPU_SECTION(L1_CACHE_BYTES)
100102

101103
. = ALIGN(8);
102104
.alternative : {
@@ -122,6 +124,8 @@ SECTIONS
122124

123125
BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
124126

127+
PERCPU_SECTION(L1_CACHE_BYTES)
128+
125129
.rel.dyn : AT(ADDR(.rel.dyn) - LOAD_OFFSET) {
126130
*(.rel.dyn*)
127131
}

arch/riscv/mm/init.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ phys_addr_t phys_ram_base __ro_after_init;
4141
EXPORT_SYMBOL(phys_ram_base);
4242

4343
#ifdef CONFIG_XIP_KERNEL
44-
extern char _xiprom[], _exiprom[];
44+
extern char _xiprom[], _exiprom[], __data_loc;
4545
#endif
4646

4747
unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
@@ -454,10 +454,9 @@ static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size)
454454
/* called from head.S with MMU off */
455455
asmlinkage void __init __copy_data(void)
456456
{
457-
void *from = (void *)(&_sdata);
458-
void *end = (void *)(&_end);
457+
void *from = (void *)(&__data_loc);
459458
void *to = (void *)CONFIG_PHYS_RAM_BASE;
460-
size_t sz = (size_t)(end - from + 1);
459+
size_t sz = (size_t)((uintptr_t)(&_end) - (uintptr_t)(&_sdata));
461460

462461
memcpy(to, from, sz);
463462
}

0 commit comments

Comments
 (0)