Skip to content

Commit 2bf8acb

Browse files
Merge patch series "Fix XIP boot and make XIP testable in QEMU"
Frederik Haxel <haxel@fzi.de> says: XIP boot seems to be broken for some time now. A likely reason why no one seems to have noticed this is that XIP is more difficult to test, as it is currently not easily testable with QEMU. These patches fix the XIP boot and allow an XIP build without BUILTIN_DTB, which in turn makes it easier to test an image with the QEMU virt machine. * b4-shazam-merge: riscv: Allow disabling of BUILTIN_DTB for XIP riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro riscv: Make XIP bootable again Link: https://lore.kernel.org/r/20231212130116.848530-1-haxel@fzi.de Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents a7565f4 + 6c4a2f6 commit 2bf8acb

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

arch/riscv/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,13 @@ config RISCV_ISA_FALLBACK
905905
on the replacement properties, "riscv,isa-base" and
906906
"riscv,isa-extensions".
907907

908-
endmenu # "Boot options"
909-
910908
config BUILTIN_DTB
911-
bool
909+
bool "Built-in device tree"
912910
depends on OF && NONPORTABLE
913911
default y if XIP_KERNEL
914912

913+
endmenu # "Boot options"
914+
915915
config PORTABLE
916916
bool
917917
default !NONPORTABLE

arch/riscv/include/asm/xip_fixup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
add \reg, \reg, t0
1414
.endm
1515
.macro XIP_FIXUP_FLASH_OFFSET reg
16-
la t1, __data_loc
16+
la t0, __data_loc
1717
REG_L t1, _xip_phys_offset
1818
sub \reg, \reg, t1
1919
add \reg, \reg, t0

arch/riscv/kernel/head.S

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ relocate_enable_mmu:
8888
/* Compute satp for kernel page tables, but don't load it yet */
8989
srl a2, a0, PAGE_SHIFT
9090
la a1, satp_mode
91+
XIP_FIXUP_OFFSET a1
9192
REG_L a1, 0(a1)
9293
or a2, a2, a1
9394

@@ -264,10 +265,12 @@ SYM_CODE_START(_start_kernel)
264265
la sp, _end + THREAD_SIZE
265266
XIP_FIXUP_OFFSET sp
266267
mv s0, a0
268+
mv s1, a1
267269
call __copy_data
268270

269-
/* Restore a0 copy */
271+
/* Restore a0 & a1 copy */
270272
mv a0, s0
273+
mv a1, s1
271274
#endif
272275

273276
#ifndef CONFIG_XIP_KERNEL

arch/riscv/mm/init.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ void __init mem_init(void)
174174

175175
/* Limit the memory size via mem. */
176176
static phys_addr_t memory_limit;
177+
#ifdef CONFIG_XIP_KERNEL
178+
#define memory_limit (*(phys_addr_t *)XIP_FIXUP(&memory_limit))
179+
#endif /* CONFIG_XIP_KERNEL */
177180

178181
static int __init early_mem(char *p)
179182
{
@@ -952,7 +955,7 @@ static void __init create_fdt_early_page_table(uintptr_t fix_fdt_va,
952955
* setup_vm_final installs the linear mapping. For 32-bit kernel, as the
953956
* kernel is mapped in the linear mapping, that makes no difference.
954957
*/
955-
dtb_early_va = kernel_mapping_pa_to_va(XIP_FIXUP(dtb_pa));
958+
dtb_early_va = kernel_mapping_pa_to_va(dtb_pa);
956959
#endif
957960

958961
dtb_early_pa = dtb_pa;
@@ -1055,9 +1058,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
10551058
#endif
10561059

10571060
kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset;
1058-
kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
10591061

10601062
#ifdef CONFIG_XIP_KERNEL
1063+
kernel_map.page_offset = PAGE_OFFSET_L3;
10611064
kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR;
10621065
kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom);
10631066

@@ -1067,6 +1070,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
10671070

10681071
kernel_map.va_kernel_xip_pa_offset = kernel_map.virt_addr - kernel_map.xiprom;
10691072
#else
1073+
kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
10701074
kernel_map.phys_addr = (uintptr_t)(&_start);
10711075
kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr;
10721076
#endif

0 commit comments

Comments
 (0)