From patchwork Tue Dec 12 13:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederik Haxel X-Patchwork-Id: 13489253 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5115AC4167D for ; Tue, 12 Dec 2023 13:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IxTM6WUfoy4zb2q3Of2IAVUf8UmhClcv6Y4AZAuK7hM=; b=YuI2LZZuYEFe7J 3BaZll85HUVYyVUuRohlgdui/wzrZZDSaXyku9e0+t4IHPgzpjuZhYRVUhE5TKQu8KpYvxKSEYmbR AbMH90wTG6kyjxunVjOziq/0osUvaJuAapAJog/NQ3Q8usQz2jSkf9setuG2l2leV5BdIiRq5++Kv 8Mto4BE09QtqraE2FBG3wO3Tr0XSI/pe5Z5rCCj7FdUEwZGzJvbyuFkNTYFVWTlwnHXS/z+QfbyNw BVX5D3cjUIKIp6K0kyDwj8hP4Gy2b5EV95N5JW9uBzhkWdlpCr9G9aGdZpUdDGLpMoaocGqAlysgY BABUfmb30GoGQJkRBVDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rD2P4-00BkKj-1Y; Tue, 12 Dec 2023 13:02:26 +0000 Received: from fzi-msx-e-03.fzi.de ([141.21.8.252]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rD2Oz-00BkHr-1s for linux-riscv@lists.infradead.org; Tue, 12 Dec 2023 13:02:24 +0000 From: Frederik Haxel To: CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Conor Dooley , "Greentime Hu" , Heiko Stuebner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Sami Tolvanen , Nam Cao , Guo Ren , Alexandre Ghiti , Anup Patel , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_050221_639742_C4768978 X-CRM114-Status: GOOD ( 12.10 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 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 From patchwork Tue Dec 12 13:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederik Haxel X-Patchwork-Id: 13489252 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E544FC4332F for ; Tue, 12 Dec 2023 13:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Yit9SGWyg9SmRhTvNHxvs6rZHvB49Atg+iRyONpYFqk=; b=F0KRnlfb7d3Use 9Zdbyp1yu8ic2xCxR7qduKVJ55pevGpms09DuGb+fPeCxGshdQ7zaVnkhpLIwbvffX5UWey1ABnsf YXB1Tg3AMN+AkTb7p4uTjZtdtzGeDzSJLiCPrxxlnM1ejxdaUke726KKYdYD/zsm0LIehsQ6UQ8f2 bJWFo4mEldIpLGwfZi3s4hfc1kqosrXIeKLHGMCtal8e1QZO+/9a8rkn9yOm7FtII47UZNkNVtHky cJnNcg+56cIV6AYnN3Ck1x9HEuOAKcWFdlKMOjT5XRGpksUmN378brjLZaIyubs1bw4wmt9K+OqTN d13PRyvNGFG4uZmrKiGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rD2P2-00BkKF-2p; Tue, 12 Dec 2023 13:02:24 +0000 Received: from fzi-msx-e-02.fzi.de ([141.21.8.250]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rD2Oz-00BkHx-1w for linux-riscv@lists.infradead.org; Tue, 12 Dec 2023 13:02:23 +0000 From: Frederik Haxel To: CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andy Chiu , Heiko Stuebner , Greentime Hu , Conor Dooley , "Sami Tolvanen" , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Nam Cao , Guo Ren , Alexandre Ghiti , Andrew Jones , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_050221_639681_DA4BACF2 X-CRM114-Status: UNSURE ( 7.94 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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/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 From patchwork Tue Dec 12 13:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederik Haxel X-Patchwork-Id: 13489254 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C5CAC41535 for ; Tue, 12 Dec 2023 13:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d3NC8FR4uW8M4HqWc7RV4+oDT0wL2l4TzjiYAYcxqg0=; b=KU7EiWZwSi5l5H y9TqPG0MH3tdPkz1vHjg/a5k8hik2TWWTnGVijVpATAwf7JLlV1o47kH1utvnQRPGvNI7Hw+0Q4/W IZkAYvnnd3GIiFqII346aAZckT33gBGpxhC+No2VBHvW0XJ+pWSHGzHvT7zthf/BlCp6yA3RMP5LA v0rIAf8qbvrWEFmbLR+QjiuUsev/HasUTdz4ve7cM1bNbwtnCOAvXEbuxJZbHvHh31w/XqySD+AaX nRYutMyNm+Lj6QN5W7ROpupaBMEiN0JQWezOyCurK2J2WhiZWCfpsqSMdrQBuTYIw2io1Y1znKac7 Xyx0KnDGtaLpIPMXXjBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rD2P7-00BkLd-2R; Tue, 12 Dec 2023 13:02:29 +0000 Received: from fzi-msx-e-01.fzi.de ([141.21.8.251]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rD2P2-00BkHq-2T for linux-riscv@lists.infradead.org; Tue, 12 Dec 2023 13:02:26 +0000 From: Frederik Haxel To: CC: Vitaly Wool , Frederik Haxel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Stuebner , Greentime Hu , Conor Dooley , Andy Chiu , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Sami Tolvanen , Guo Ren , Nam Cao , Alexandre Ghiti , Baoquan He , Andrew Jones , Chen Jiahao , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , , 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 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_050224_805377_1CC33150 X-CRM114-Status: UNSURE ( 9.45 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 ``` 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". -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