[Buildroot] [PATCH v2 4/4] configs/qemu_riscv32_nommu_virt_defconfig: New defconfig

Jesse Taube mr.bossman075 at gmail.com
Sat Dec 17 05:13:37 UTC 2022


Add RISC-V 32-bit nommu defconfig for QEMU virt machine with MMU
disabled.

Unlike qemu_riscv32_virt, qemu_riscv32_nommu_virt does not use OpenSBI,
since the kernel is running in machine mode (M-mode).

Signed-off-by: Jesse Taube <Mr.Bossman075 at gmail.com>
Cc: Yimin Gu <ustcymgu at gmail.com>
---
 board/qemu/riscv32-virt/nommu/defconfig       | 16 +++++++
 .../riscv32-virt/nommu/patches/linux-headers  |  1 +
 ...nfig-Allow-RV32-to-build-with-no-MMU.patch | 43 +++++++++++++++++++
 ...le-stat64-and-time32-for-RV32-uclibc.patch | 40 +++++++++++++++++
 board/qemu/riscv32-virt/readme.txt            |  6 ++-
 configs/qemu_riscv32_nommu_virt_defconfig     | 31 +++++++++++++
 6 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 board/qemu/riscv32-virt/nommu/defconfig
 create mode 120000 board/qemu/riscv32-virt/nommu/patches/linux-headers
 create mode 100644 board/qemu/riscv32-virt/nommu/patches/linux/6.0/0001-riscv-Kconfig-Allow-RV32-to-build-with-no-MMU.patch
 create mode 100644 board/qemu/riscv32-virt/nommu/patches/linux/6.0/0002-riscv-Enable-stat64-and-time32-for-RV32-uclibc.patch
 create mode 100644 configs/qemu_riscv32_nommu_virt_defconfig

diff --git a/board/qemu/riscv32-virt/nommu/defconfig b/board/qemu/riscv32-virt/nommu/defconfig
new file mode 100644
index 0000000000..460907253a
--- /dev/null
+++ b/board/qemu/riscv32-virt/nommu/defconfig
@@ -0,0 +1,16 @@
+CONFIG_BLK_DEV_INITRD=y
+# CONFIG_MMU is not set
+CONFIG_COMPAT_32BIT_TIME=y
+CONFIG_SOC_VIRT=y
+CONFIG_NONPORTABLE=y
+CONFIG_ARCH_RV32I=y
+CONFIG_BINFMT_FLAT=y
+CONFIG_SLOB=y
+CONFIG_VIRTIO_BLK=y
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
+CONFIG_EXT2_FS=y
+CONFIG_PRINTK_TIME=y
diff --git a/board/qemu/riscv32-virt/nommu/patches/linux-headers b/board/qemu/riscv32-virt/nommu/patches/linux-headers
new file mode 120000
index 0000000000..ce5e2c77b2
--- /dev/null
+++ b/board/qemu/riscv32-virt/nommu/patches/linux-headers
@@ -0,0 +1 @@
+linux/
\ No newline at end of file
diff --git a/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0001-riscv-Kconfig-Allow-RV32-to-build-with-no-MMU.patch b/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0001-riscv-Kconfig-Allow-RV32-to-build-with-no-MMU.patch
new file mode 100644
index 0000000000..af11ddf953
--- /dev/null
+++ b/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0001-riscv-Kconfig-Allow-RV32-to-build-with-no-MMU.patch
@@ -0,0 +1,43 @@
+From 57800c87e422375ec0df4d5ad7f33659f7b60093 Mon Sep 17 00:00:00 2001
+From: Yimin Gu <ustcymgu at gmail.com>
+Date: Sat, 10 Dec 2022 22:27:47 -0500
+Subject: [PATCH] riscv: Kconfig: Allow RV32 to build with no MMU
+
+Some RISC-V 32bit ores do not have an MMU, and the kernel should be
+able to build for them. This patch enables the RV32 to be built with
+no MMU support.
+
+Signed-off-by: Yimin Gu <ustcymgu at gmail.com>
+CC=c: Jesse Taube <Mr.Bossman075 at gmail.com>
+Tested-By: Waldemar Brodkorb <wbx at openadk.org>
+Signed-off-by: Jesse Taube <Mr.Bossman075 at gmail.com>
+---
+ arch/riscv/Kconfig | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
+index 59d18881f35b..49759dbe6a8f 100644
+--- a/arch/riscv/Kconfig
++++ b/arch/riscv/Kconfig
+@@ -163,8 +163,8 @@ config MMU
+ 
+ config PAGE_OFFSET
+ 	hex
+-	default 0xC0000000 if 32BIT
+-	default 0x80000000 if 64BIT && !MMU
++	default 0xC0000000 if 32BIT && MMU
++	default 0x80000000 if !MMU
+ 	default 0xff60000000000000 if 64BIT
+ 
+ config KASAN_SHADOW_OFFSET
+@@ -262,7 +262,6 @@ config ARCH_RV32I
+ 	select GENERIC_LIB_ASHRDI3
+ 	select GENERIC_LIB_LSHRDI3
+ 	select GENERIC_LIB_UCMPDI2
+-	select MMU
+ 
+ config ARCH_RV64I
+ 	bool "RV64I"
+-- 
+2.38.1
+
diff --git a/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0002-riscv-Enable-stat64-and-time32-for-RV32-uclibc.patch b/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0002-riscv-Enable-stat64-and-time32-for-RV32-uclibc.patch
new file mode 100644
index 0000000000..f654cca7a6
--- /dev/null
+++ b/board/qemu/riscv32-virt/nommu/patches/linux/6.0/0002-riscv-Enable-stat64-and-time32-for-RV32-uclibc.patch
@@ -0,0 +1,40 @@
+From 1d985b3cd0fdb37567b4b8263cae740b49a1f46a Mon Sep 17 00:00:00 2001
+From: Yimin Gu <ustcymgu at gmail.com>
+Date: Sat, 10 Dec 2022 22:31:06 -0500
+Subject: [PATCH] riscv: Enable stat64 and time32 for RV32 uclibc
+
+To comply with current uclibc, macros __ARCH_WANT_STAT64 and
+__ARCH_WANT_TIME32_SYSCALLS are defined. CONFIG_COMPAT_32BIT_TIME also
+has to be turned on.
+
+Tested-By: Waldemar Brodkorb <wbx at openadk.org>
+Signed-off-by: Yimin Gu <ustcymgu at gmail.com>
+Cc: Jesse Taube <Mr.Bossman075 at gmail.com>
+Signed-off-by: Jesse Taube <Mr.Bossman075 at gmail.com>
+---
+ arch/riscv/include/uapi/asm/unistd.h | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/arch/riscv/include/uapi/asm/unistd.h b/arch/riscv/include/uapi/asm/unistd.h
+index 73d7cdd2ec49..3dc774bc201f 100644
+--- a/arch/riscv/include/uapi/asm/unistd.h
++++ b/arch/riscv/include/uapi/asm/unistd.h
+@@ -15,9 +15,14 @@
+  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+  */
+ 
+-#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
++#ifndef __SYSCALL_COMPAT
+ #define __ARCH_WANT_NEW_STAT
+ #define __ARCH_WANT_SET_GET_RLIMIT
++#endif /* __SYSCALL_COMPAT */
++
++#ifndef __LP64__
++#define __ARCH_WANT_STAT64
++#define __ARCH_WANT_TIME32_SYSCALLS
+ #endif /* __LP64__ */
+ 
+ #define __ARCH_WANT_SYS_CLONE3
+-- 
+2.38.1
+
diff --git a/board/qemu/riscv32-virt/readme.txt b/board/qemu/riscv32-virt/readme.txt
index 32b4333512..067bb9f436 100644
--- a/board/qemu/riscv32-virt/readme.txt
+++ b/board/qemu/riscv32-virt/readme.txt
@@ -1,5 +1,9 @@
 Run Linux in emulation with:
 
-  qemu-system-riscv32 -M virt -bios output/images/fw_jump.elf -kernel output/images/Image -append "rootwait root=/dev/vda ro" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic # qemu_riscv32_virt_defconfig
+qemu_riscv32_virt_defconfig:
+  qemu-system-riscv32 -M virt -bios output/images/fw_jump.elf -kernel output/images/Image -append "rootwait root=/dev/vda ro" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic
+  
+qemu_riscv32_nommu_virt_defconfig:
+  qemu-system-riscv32 -M virt -bios none -kernel output/images/Image -append "rootwait root=/dev/vda ro" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -nographic -cpu rv32,mmu=off
 
 The login prompt will appear in the terminal that started Qemu.
diff --git a/configs/qemu_riscv32_nommu_virt_defconfig b/configs/qemu_riscv32_nommu_virt_defconfig
new file mode 100644
index 0000000000..8bfa1f7435
--- /dev/null
+++ b/configs/qemu_riscv32_nommu_virt_defconfig
@@ -0,0 +1,31 @@
+# Architecture
+BR2_riscv=y
+BR2_RISCV_32=y
+# BR2_RISCV_USE_MMU is not set 
+
+# System
+BR2_TARGET_GENERIC_GETTY=y
+BR2_PTHREADS_NONE=y
+
+# Filesystem
+BR2_TARGET_ROOTFS_EXT2=y
+
+# Image
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/qemu/post-image.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_DEFCONFIG)"
+
+# Linux headers same as kernel
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_0=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.0"
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/riscv32-virt/nommu/defconfig"
+BR2_LINUX_KERNEL_IMAGE=y
+BR2_GLOBAL_PATCH_DIR="board/qemu/riscv32-virt/nommu/patches"
+
+# host-qemu for gitlab testing
+BR2_PACKAGE_HOST_QEMU=y
+BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
-- 
2.39.0




More information about the buildroot mailing list