From nobody Sun Dec 28 04:49:02 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D516C4332F for ; Tue, 12 Dec 2023 13:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376631AbjLLNRM (ORCPT ); Tue, 12 Dec 2023 08:17:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376548AbjLLNRK (ORCPT ); Tue, 12 Dec 2023 08:17:10 -0500 Received: from fzi-msx-e-03.fzi.de (fzi-msx-e-03.fzi.de [141.21.8.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 391E1EB for ; Tue, 12 Dec 2023 05:17:15 -0800 (PST) From: Frederik Haxel CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Conor Dooley , "Greentime Hu" , Heiko Stuebner , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Sami Tolvanen , Nam Cao , Guo Ren , Alexandre Ghiti , Anup Patel , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Baoquan He , Chen Jiahao , , Subject: [PATCH 1/3] riscv: Make XIP bootable again Date: Tue, 12 Dec 2023 14:01:12 +0100 Message-ID: <20231212130116.848530-2-haxel@fzi.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212130116.848530-1-haxel@fzi.de> References: <20231212130116.848530-1-haxel@fzi.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [141.21.46.139] X-ClientProxiedBy: fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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 =20 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) =20 /* 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 */ =20 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 =3D kernel_mapping_pa_to_va(XIP_FIXUP(dtb_pa)); + dtb_early_va =3D kernel_mapping_pa_to_va(dtb_pa); #endif =20 dtb_early_pa =3D dtb_pa; @@ -1055,9 +1058,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) #endif =20 kernel_map.virt_addr =3D KERNEL_LINK_ADDR + kernel_map.virt_offset; - kernel_map.page_offset =3D _AC(CONFIG_PAGE_OFFSET, UL); =20 #ifdef CONFIG_XIP_KERNEL + kernel_map.page_offset =3D PAGE_OFFSET_L3; kernel_map.xiprom =3D (uintptr_t)CONFIG_XIP_PHYS_ADDR; kernel_map.xiprom_sz =3D (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom); =20 @@ -1067,6 +1070,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) =20 kernel_map.va_kernel_xip_pa_offset =3D kernel_map.virt_addr - kernel_map.= xiprom; #else + kernel_map.page_offset =3D _AC(CONFIG_PAGE_OFFSET, UL); kernel_map.phys_addr =3D (uintptr_t)(&_start); kernel_map.size =3D (uintptr_t)(&_end) - kernel_map.phys_addr; #endif --=20 2.34.1 From nobody Sun Dec 28 04:49:02 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 965DEC4332F for ; Tue, 12 Dec 2023 13:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376590AbjLLNRX (ORCPT ); Tue, 12 Dec 2023 08:17:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376616AbjLLNRS (ORCPT ); Tue, 12 Dec 2023 08:17:18 -0500 Received: from fzi-msx-e-02.fzi.de (fzi-msx-e-02.fzi.de [141.21.8.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2A710D for ; Tue, 12 Dec 2023 05:17:18 -0800 (PST) From: Frederik Haxel CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Heiko Stuebner , Greentime Hu , Conor Dooley , "Sami Tolvanen" , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Nam Cao , Guo Ren , Alexandre Ghiti , Andrew Jones , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Baoquan He , Chen Jiahao , , Subject: [PATCH 2/3] riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro Date: Tue, 12 Dec 2023 14:01:13 +0100 Message-ID: <20231212130116.848530-3-haxel@fzi.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212130116.848530-1-haxel@fzi.de> References: <20231212130116.848530-1-haxel@fzi.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [141.21.46.139] X-ClientProxiedBy: fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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/xi= p_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 --=20 2.34.1 From nobody Sun Dec 28 04:49:02 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F5F9C4332F for ; Tue, 12 Dec 2023 13:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376727AbjLLNR3 (ORCPT ); Tue, 12 Dec 2023 08:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376673AbjLLNRU (ORCPT ); Tue, 12 Dec 2023 08:17:20 -0500 Received: from fzi-msx-e-01.fzi.de (fzi-msx-e-01.fzi.de [141.21.8.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992E6123 for ; Tue, 12 Dec 2023 05:17:21 -0800 (PST) From: Frederik Haxel CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Stuebner , Greentime Hu , Conor Dooley , Andy Chiu , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Sami Tolvanen , Guo Ren , Nam Cao , Alexandre Ghiti , Baoquan He , Andrew Jones , Chen Jiahao , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , , Subject: [PATCH 3/3] riscv: Allow disabling of BUILTIN_DTB for XIP Date: Tue, 12 Dec 2023 14:01:14 +0100 Message-ID: <20231212130116.848530-4-haxel@fzi.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212130116.848530-1-haxel@fzi.de> References: <20231212130116.848530-1-haxel@fzi.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [141.21.46.139] X-ClientProxiedBy: fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To fzi-msx-05.fzi.de (2001:67c:2acc:8:141:21:17:45) To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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=3Dy CONFIG_XIP_KERNEL=3Dy CONFIG_XIP_PHYS_ADDR=3D0x20000000 CONFIG_PHYS_RAM_BASE=3D0x80200000 CONFIG_BUILTIN_DTB=3Dn ``` 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=3Dpflash0 \ -blockdev node-name=3Dpflash0,driver=3Dfile,read-only=3Don,\ filename=3Darch/riscv/boot/xipImage ``` Signed-off-by: Frederik Haxel --- 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". =20 -endmenu # "Boot options" - config BUILTIN_DTB - bool + bool "Built-in device tree" depends on OF && NONPORTABLE default y if XIP_KERNEL =20 +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 =20 - /* Restore a0 copy */ + /* Restore a0 & a1 copy */ mv a0, s0 + mv a1, s1 #endif =20 #ifndef CONFIG_XIP_KERNEL --=20 2.34.1