From nobody Mon Feb 9 17:08:13 2026 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 88420C77B7A for ; Wed, 7 Jun 2023 09:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239712AbjFGJnc (ORCPT ); Wed, 7 Jun 2023 05:43:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239485AbjFGJn1 (ORCPT ); Wed, 7 Jun 2023 05:43:27 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C132EB; Wed, 7 Jun 2023 02:43:24 -0700 (PDT) X-QQ-mid: bizesmtp80t1686130994t5ggma8m Received: from linux-lab-host.localdomain ( [61.141.77.49]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 07 Jun 2023 17:43:13 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: CR3LFp2JE4mfAn2LSTK1xi8qQ4UyRaoYMHxJsMRywKHgdAG3qZj5i/iI8Gq2F qluTGaMPCQg796dEjFelUhz3yE2cRQpMvoRAnhlccXre+mIYL9qQKu4FMQhAgYBJSweglF9 kr/0leOh4j8oBKxFg2gyyU9V4K8lOvNTc9+IyvSJpknvm0Jzi96r0jlC9kGPAKAOg3NKisU cWrZgto44qMqQuSFpnk1OcEj3Tt/+aCPDl2NgC+RN85mQQVMP0ndJNtF9xySZ9dMSJM1XLq byk1dnIYv3TABQOU5bFFTJIe9OxHppx3H3IykqTdkFIjFRI8u00KYm8ryj+Vx4BSU5xFBNZ 6I11YXK6OZjQJ06s26jew+8E/pe+8Dosv1Fu1grJgVykfNd5N/UZrVsKqjH/WsYVgpQ9RTJ r2CCAVQVlBKzO2SjacAyKA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1815332739325030604 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Subject: [PATCH v4 3/3] selftests/nolibc: riscv: customize makefile for rv32 Date: Wed, 7 Jun 2023 17:37:01 +0800 Message-Id: <3698e3629148550146b986cda61539a647ebd589.1686128703.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both riscv64 and riscv32 have: * the same arch/riscv source code tree * the same tools/include/nolibc/arch-riscv.h * the same ARCH=3Driscv value passed to top-level kernel Makefile The only differences are: * riscv64 uses defconfig, riscv32 uses rv32_defconfig * riscv64 uses qemu-system-riscv64, riscv32 uses qemu-system-riscv32 * riscv32 has different compiler options (-march=3D and -mabi=3D) So, riscv32 can share most of the settings with riscv64, add riscv32 support like the original ARCH=3Driscv support. To align with x86, the default riscv is reserved for riscv64 and a new riscv64 is also added to allow users pass ARCH=3Driscv64 directly. Since top-level kernel Makefile only accept ARCH=3Driscv, to make it happy, let's add a KARCH, set it as riscv for riscv32 and riscv64, and set it as original ARCH for the others, at last pass it to kernel targets with ARCH=3D$(KARCH). The same ARCH=3D$(KARCH) passed to tools/include/nolibc/Makefile, for both arch-riscv.h and the headers_standalone target require it too. Usage: $ make defconfig ARCH=3Driscv32 CROSS_COMPILE=3Driscv64-linux-gnu- ... $ make run ARCH=3Driscv32 CROSS_COMPILE=3Driscv64-linux-gnu- ... Suggested-by: Thomas Wei=C3=9Fschuh Link: https://lore.kernel.org/linux-riscv/4a3b1cdf-91d5-4668-925e-21f8f5c64= a92@t-8ch.de/ Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-riscv/d1c83340-af4c-4780-a101-b9d22b473= 79c@app.fastmail.com/ Suggested-by: Willy Tarreau Link: https://lore.kernel.org/lkml/ZIAywHvr6UB1J4of@1wt.eu/ Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/Makefile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 4a3a105e1fdf..48fa22817d90 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -14,6 +14,11 @@ include $(srctree)/scripts/subarch.include ARCH =3D $(SUBARCH) endif =20 +# kernel supported ARCH names by architecture +KARCH_riscv32 =3D riscv +KARCH_riscv64 =3D riscv +KARCH =3D $(or $(KARCH_$(ARCH)),$(ARCH)) + # kernel image names by architecture IMAGE_i386 =3D arch/x86/boot/bzImage IMAGE_x86_64 =3D arch/x86/boot/bzImage @@ -21,6 +26,8 @@ IMAGE_x86 =3D arch/x86/boot/bzImage IMAGE_arm64 =3D arch/arm64/boot/Image IMAGE_arm =3D arch/arm/boot/zImage IMAGE_mips =3D vmlinuz +IMAGE_riscv32 =3D arch/riscv/boot/Image +IMAGE_riscv64 =3D arch/riscv/boot/Image IMAGE_riscv =3D arch/riscv/boot/Image IMAGE_s390 =3D arch/s390/boot/bzImage IMAGE_loongarch =3D arch/loongarch/boot/vmlinuz.efi @@ -34,6 +41,8 @@ DEFCONFIG_x86 =3D defconfig DEFCONFIG_arm64 =3D defconfig DEFCONFIG_arm =3D multi_v7_defconfig DEFCONFIG_mips =3D malta_defconfig +DEFCONFIG_riscv32 =3D rv32_defconfig +DEFCONFIG_riscv64 =3D defconfig DEFCONFIG_riscv =3D defconfig DEFCONFIG_s390 =3D defconfig DEFCONFIG_loongarch =3D defconfig @@ -49,6 +58,8 @@ QEMU_ARCH_x86 =3D x86_64 QEMU_ARCH_arm64 =3D aarch64 QEMU_ARCH_arm =3D arm QEMU_ARCH_mips =3D mipsel # works with malta_defconfig +QEMU_ARCH_riscv32 =3D riscv32 +QEMU_ARCH_riscv64 =3D riscv64 QEMU_ARCH_riscv =3D riscv64 QEMU_ARCH_s390 =3D s390x QEMU_ARCH_loongarch =3D loongarch64 @@ -61,6 +72,8 @@ QEMU_ARGS_x86 =3D -M pc -append "console=3DttyS0,9= 600 i8042.noaux panic=3D-1 $( QEMU_ARGS_arm64 =3D -M virt -cpu cortex-a53 -append "panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_arm =3D -M virt -append "panic=3D-1 $(TEST:%=3DNOLIBC_TES= T=3D%)" QEMU_ARGS_mips =3D -M malta -append "panic=3D-1 $(TEST:%=3DNOLIBC_TE= ST=3D%)" +QEMU_ARGS_riscv32 =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" +QEMU_ARGS_riscv64 =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_riscv =3D -M virt -append "console=3DttyS0 panic=3D-1 $(TES= T:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_s390 =3D -M s390-ccw-virtio -m 1G -append "console=3DttyS0= panic=3D-1 $(TEST:%=3DNOLIBC_TEST=3D%)" QEMU_ARGS_loongarch =3D -M virt -append "console=3DttyS0,115200 panic=3D-= 1 $(TEST:%=3DNOLIBC_TEST=3D%)" @@ -76,6 +89,7 @@ else Q=3D@ endif =20 +CFLAGS_riscv32 =3D -march=3Drv32im -mabi=3Dilp32 CFLAGS_s390 =3D -m64 CFLAGS_STACKPROTECTOR ?=3D $(call cc-option,-mstack-protector-guard=3Dglob= al $(call cc-option,-fstack-protector-all)) CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 \ @@ -117,7 +131,7 @@ sysroot: sysroot/$(ARCH)/include sysroot/$(ARCH)/include: $(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot $(QUIET_MKDIR)mkdir -p sysroot - $(Q)$(MAKE) -C ../../../include/nolibc ARCH=3D$(ARCH) OUTPUT=3D$(CURDIR)/= sysroot/ headers_standalone + $(Q)$(MAKE) -C ../../../include/nolibc ARCH=3D$(KARCH) OUTPUT=3D$(CURDIR)= /sysroot/ headers_standalone $(Q)mv sysroot/sysroot sysroot/$(ARCH) =20 nolibc-test: nolibc-test.c sysroot/$(ARCH)/include @@ -141,10 +155,10 @@ initramfs: nolibc-test $(Q)cp nolibc-test initramfs/init =20 defconfig: - $(Q)$(MAKE) -C $(srctree) ARCH=3D$(ARCH) CC=3D$(CC) CROSS_COMPILE=3D$(CRO= SS_COMPILE) mrproper $(DEFCONFIG) prepare + $(Q)$(MAKE) -C $(srctree) ARCH=3D$(KARCH) CC=3D$(CC) CROSS_COMPILE=3D$(CR= OSS_COMPILE) mrproper $(DEFCONFIG) prepare =20 kernel: initramfs - $(Q)$(MAKE) -C $(srctree) ARCH=3D$(ARCH) CC=3D$(CC) CROSS_COMPILE=3D$(CRO= SS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=3D$(CURDIR)/initramfs + $(Q)$(MAKE) -C $(srctree) ARCH=3D$(KARCH) CC=3D$(CC) CROSS_COMPILE=3D$(CR= OSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=3D$(CURDIR)/initramfs =20 # run the tests after building the kernel run: kernel --=20 2.25.1