* [PATCH 1/3] riscv: Make XIP bootable again
2023-12-12 13:01 [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Frederik Haxel
@ 2023-12-12 13:01 ` Frederik Haxel
2023-12-12 13:01 ` [PATCH 2/3] riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro Frederik Haxel
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Frederik Haxel @ 2023-12-12 13:01 UTC (permalink / raw)
Cc: Vitaly Wool, Frederik Haxel, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Andy Chiu, Conor Dooley, Greentime Hu, Heiko Stuebner,
Clément Léger, Sami Tolvanen, Nam Cao, Guo Ren,
Alexandre Ghiti, Anup Patel, Björn Töpel, Baoquan He,
Chen Jiahao, linux-riscv, linux-kernel
Currently, the XIP kernel seems to fail to boot due to missing
XIP_FIXUP and a wrong page_offset value. A superfluous XIP_FIXUP
has also been removed.
Signed-off-by: Frederik Haxel <haxel@fzi.de>
---
arch/riscv/kernel/head.S | 1 +
arch/riscv/mm/init.c | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index b77397432403..a2e2f0dd3899 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -89,6 +89,7 @@ relocate_enable_mmu:
/* Compute satp for kernel page tables, but don't load it yet */
srl a2, a0, PAGE_SHIFT
la a1, satp_mode
+ XIP_FIXUP_OFFSET a1
REG_L a1, 0(a1)
or a2, a2, a1
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 2e011cbddf3a..a65937336cdc 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -174,6 +174,9 @@ void __init mem_init(void)
/* Limit the memory size via mem. */
static phys_addr_t memory_limit;
+#ifdef CONFIG_XIP_KERNEL
+#define memory_limit (*(phys_addr_t *)XIP_FIXUP(&memory_limit))
+#endif /* CONFIG_XIP_KERNEL */
static int __init early_mem(char *p)
{
@@ -952,7 +955,7 @@ static void __init create_fdt_early_page_table(uintptr_t fix_fdt_va,
* setup_vm_final installs the linear mapping. For 32-bit kernel, as the
* kernel is mapped in the linear mapping, that makes no difference.
*/
- dtb_early_va = kernel_mapping_pa_to_va(XIP_FIXUP(dtb_pa));
+ dtb_early_va = kernel_mapping_pa_to_va(dtb_pa);
#endif
dtb_early_pa = dtb_pa;
@@ -1055,9 +1058,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
#endif
kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset;
- kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
#ifdef CONFIG_XIP_KERNEL
+ kernel_map.page_offset = PAGE_OFFSET_L3;
kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR;
kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom);
@@ -1067,6 +1070,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
kernel_map.va_kernel_xip_pa_offset = kernel_map.virt_addr - kernel_map.xiprom;
#else
+ kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
kernel_map.phys_addr = (uintptr_t)(&_start);
kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr;
#endif
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/3] riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro
2023-12-12 13:01 [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Frederik Haxel
2023-12-12 13:01 ` [PATCH 1/3] riscv: Make XIP bootable again Frederik Haxel
@ 2023-12-12 13:01 ` Frederik Haxel
2023-12-12 13:01 ` [PATCH 3/3] riscv: Allow disabling of BUILTIN_DTB for XIP Frederik Haxel
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Frederik Haxel @ 2023-12-12 13:01 UTC (permalink / raw)
Cc: Vitaly Wool, Frederik Haxel, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Andy Chiu, Heiko Stuebner, Greentime Hu, Conor Dooley,
Sami Tolvanen, Clément Léger, Nam Cao, Guo Ren,
Alexandre Ghiti, Andrew Jones, Björn Töpel, Baoquan He,
Chen Jiahao, linux-riscv, linux-kernel
During the refactoring, a bug was introduced in the rarly used
XIP_FIXUP_FLASH_OFFSET macro.
Fixes: bee7fbc38579 ("RISC-V CPU Idle Support")
Fixes: e7681beba992 ("RISC-V: Split out the XIP fixups into their own file")
Signed-off-by: Frederik Haxel <haxel@fzi.de>
---
arch/riscv/include/asm/xip_fixup.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/include/asm/xip_fixup.h b/arch/riscv/include/asm/xip_fixup.h
index d4ffc3c37649..b65bf6306f69 100644
--- a/arch/riscv/include/asm/xip_fixup.h
+++ b/arch/riscv/include/asm/xip_fixup.h
@@ -13,7 +13,7 @@
add \reg, \reg, t0
.endm
.macro XIP_FIXUP_FLASH_OFFSET reg
- la t1, __data_loc
+ la t0, __data_loc
REG_L t1, _xip_phys_offset
sub \reg, \reg, t1
add \reg, \reg, t0
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/3] riscv: Allow disabling of BUILTIN_DTB for XIP
2023-12-12 13:01 [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Frederik Haxel
2023-12-12 13:01 ` [PATCH 1/3] riscv: Make XIP bootable again Frederik Haxel
2023-12-12 13:01 ` [PATCH 2/3] riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro Frederik Haxel
@ 2023-12-12 13:01 ` Frederik Haxel
2023-12-12 13:22 ` [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Conor Dooley
2024-01-11 14:50 ` patchwork-bot+linux-riscv
4 siblings, 0 replies; 8+ messages in thread
From: Frederik Haxel @ 2023-12-12 13:01 UTC (permalink / raw)
Cc: Vitaly Wool, Frederik Haxel, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Heiko Stuebner, Greentime Hu, Conor Dooley, Andy Chiu,
Clément Léger, Sami Tolvanen, Guo Ren, Nam Cao,
Alexandre Ghiti, Baoquan He, Andrew Jones, Chen Jiahao,
Björn Töpel, linux-riscv, linux-kernel
This enables, among other things, testing with the QEMU virt machine.
To build an XIP kernel for the QEMU virt machine, configure the
the kernel as desired and apply the following configuration
```
CONFIG_NONPORTABLE=y
CONFIG_XIP_KERNEL=y
CONFIG_XIP_PHYS_ADDR=0x20000000
CONFIG_PHYS_RAM_BASE=0x80200000
CONFIG_BUILTIN_DTB=n
```
Since the QEMU virt flash memory expects a 32 MB file, the built image
must be padded. For example, with
`truncate -s 32M arch/riscv/boot/xipImage`
The kernel can be started using the following command in QEMU (v8+)
```
qemu-system-riscv64 -M virt,pflash0=pflash0 \
-blockdev node-name=pflash0,driver=file,read-only=on,\
filename=arch/riscv/boot/xipImage <optional parameters>
```
Signed-off-by: Frederik Haxel <haxel@fzi.de>
---
arch/riscv/Kconfig | 6 +++---
arch/riscv/kernel/head.S | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 95a2a06acc6a..72bc31b6eeb9 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -904,13 +904,13 @@ config RISCV_ISA_FALLBACK
on the replacement properties, "riscv,isa-base" and
"riscv,isa-extensions".
-endmenu # "Boot options"
-
config BUILTIN_DTB
- bool
+ bool "Built-in device tree"
depends on OF && NONPORTABLE
default y if XIP_KERNEL
+endmenu # "Boot options"
+
config PORTABLE
bool
default !NONPORTABLE
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index a2e2f0dd3899..a8939558702c 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -266,10 +266,12 @@ SYM_CODE_START(_start_kernel)
la sp, _end + THREAD_SIZE
XIP_FIXUP_OFFSET sp
mv s0, a0
+ mv s1, a1
call __copy_data
- /* Restore a0 copy */
+ /* Restore a0 & a1 copy */
mv a0, s0
+ mv a1, s1
#endif
#ifndef CONFIG_XIP_KERNEL
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU
2023-12-12 13:01 [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Frederik Haxel
` (2 preceding siblings ...)
2023-12-12 13:01 ` [PATCH 3/3] riscv: Allow disabling of BUILTIN_DTB for XIP Frederik Haxel
@ 2023-12-12 13:22 ` Conor Dooley
[not found] ` <CAM4kBBKBC=ZSQPzAq5MFQvd1g9=Up_oRAK5CV74oJHt=SbcPqg@mail.gmail.com>
2024-01-11 14:50 ` patchwork-bot+linux-riscv
4 siblings, 1 reply; 8+ messages in thread
From: Conor Dooley @ 2023-12-12 13:22 UTC (permalink / raw)
To: Frederik Haxel
Cc: Vitaly Wool, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Greentime Hu, Andy Chiu, Heiko Stuebner, Clément Léger,
Sami Tolvanen, Masahiro Yamada, Guo Ren, Nam Cao, Alexandre Ghiti,
Andrew Morton, Anup Patel, Baoquan He, Chen Jiahao,
Björn Töpel, linux-riscv, linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 746 bytes --]
On Tue, Dec 12, 2023 at 02:01:11PM +0100, Frederik Haxel wrote:
> 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.
Are you actually using XIP in something other than QEMU? The fact that
some of the blamed fixes are over 18 months old suggests that you are
not actively using XIP builds of the mainline kernel.
There is a desire to remove XIP support (among other things), so if you
do actually have a use case for it, speak up.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU
2023-12-12 13:01 [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Frederik Haxel
` (3 preceding siblings ...)
2023-12-12 13:22 ` [PATCH 0/3] Fix XIP boot and make XIP testable in QEMU Conor Dooley
@ 2024-01-11 14:50 ` patchwork-bot+linux-riscv
4 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-01-11 14:50 UTC (permalink / raw)
To: Frederik Haxel
Cc: linux-riscv, vitaly.wool, paul.walmsley, palmer, aou,
greentime.hu, andy.chiu, heiko, conor.dooley, cleger,
samitolvanen, masahiroy, guoren, namcaov, alexghiti, akpm, anup,
bhe, chenjiahao16, bjorn, linux-kernel
Hello:
This series was applied to riscv/linux.git (for-next)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Tue, 12 Dec 2023 14:01:11 +0100 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [1/3] riscv: Make XIP bootable again
https://git.kernel.org/riscv/c/66f1e6809397
- [2/3] riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro
https://git.kernel.org/riscv/c/5daa37264102
- [3/3] riscv: Allow disabling of BUILTIN_DTB for XIP
https://git.kernel.org/riscv/c/6c4a2f6329f0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread