From patchwork Wed Jun 7 09:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 104381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp138324vqr; Wed, 7 Jun 2023 03:01:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45GbaP2oLSU+IaZZDhA3/Axxk9eH9ZyqZfe/Z5Y1n/g0p2Jmx7sO82A0O6vk+CN9yZBDtE X-Received: by 2002:a1f:3d8d:0:b0:460:5f0f:1bf8 with SMTP id k135-20020a1f3d8d000000b004605f0f1bf8mr2241077vka.13.1686132085960; Wed, 07 Jun 2023 03:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686132085; cv=none; d=google.com; s=arc-20160816; b=T/AYmsWr+ab67SDSPIEJkFerMSHRDd5Y0tTTgODcDlzds1PJWA6Lb1ewCwjRDSkPKF pOYBlkcBwqQQUE553kaCAhxA2y8OWbNjj1EZtp9cfMPTAs+J7/wsJPNvoVPYjyE23tJB aCSBtnYQ/f9Cmo18HTzWYiGHxzqq/yToUodriKWSwxR5wqD857N/FEahcu8q5JZcS7F+ L9xB+EYPQwtbKXDWL+FSjvTrezTXkcU3aqqPNhJsYTJjSLLyunBjICbUoElJhYhXW/rP 4RpYI5UsvjqOM8uq03J1FhY0h0/HWDmvHtkFHDozx52DC/NXtxAn6ZeLwoxjelNoKigl YnSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=+ZH1qXvMctNG/OnYhba9uKu+EOOBtoB3RMED9z5/rbA=; b=HRL/Y9LtU6uvU7uCVPUpHAIt4MZfErdkFHpukpsJ4rc1vLwrMq7j0MSHABzWyJMb0Y PwxCPNa9ZL9q1p60D5AsBKNHZB9rZdIzV1FrJsoMfUl2sTyt0SCu8zE2DM8LW0vctOWo UA8IvzbSTCgiFiXq2TCtKcv6hxPlcokaB3hvA5vnHej6SL3VHbb8W+4XbhcbTMsbZVIj x1WU30U+1JQmvEW2cutDThVO7xbtfSdEnws7moxpuV+v6aPqnkrlx8jN7tkwiOWVO9io DdnEFmQ1M8v3Hwclsei4cDmto2mYdV7SvdNqhk2YSV/IKBjDhixB21QTr2jM70Yh4jsW F3zQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170902d50a00b001a9265e6fdasi8810527plg.268.2023.06.07.03.01.10; Wed, 07 Jun 2023 03:01:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239640AbjFGJna (ORCPT + 99 others); Wed, 7 Jun 2023 05:43:30 -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_Wei=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 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768037638210035332?= X-GMAIL-MSGID: =?utf-8?q?1768037638210035332?= Both riscv64 and riscv32 have: * the same arch/riscv source code tree * the same tools/include/nolibc/arch-riscv.h * the same ARCH=riscv 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= and -mabi=) So, riscv32 can share most of the settings with riscv64, add riscv32 support like the original ARCH=riscv support. To align with x86, the default riscv is reserved for riscv64 and a new riscv64 is also added to allow users pass ARCH=riscv64 directly. Since top-level kernel Makefile only accept ARCH=riscv, 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=$(KARCH). The same ARCH=$(KARCH) passed to tools/include/nolibc/Makefile, for both arch-riscv.h and the headers_standalone target require it too. Usage: $ make defconfig ARCH=riscv32 CROSS_COMPILE=riscv64-linux-gnu- ... $ make run ARCH=riscv32 CROSS_COMPILE=riscv64-linux-gnu- ... Suggested-by: Thomas Weißschuh Link: https://lore.kernel.org/linux-riscv/4a3b1cdf-91d5-4668-925e-21f8f5c64a92@t-8ch.de/ Suggested-by: Arnd Bergmann Link: https://lore.kernel.org/linux-riscv/d1c83340-af4c-4780-a101-b9d22b47379c@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/selftests/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 = $(SUBARCH) endif +# kernel supported ARCH names by architecture +KARCH_riscv32 = riscv +KARCH_riscv64 = riscv +KARCH = $(or $(KARCH_$(ARCH)),$(ARCH)) + # kernel image names by architecture IMAGE_i386 = arch/x86/boot/bzImage IMAGE_x86_64 = arch/x86/boot/bzImage @@ -21,6 +26,8 @@ IMAGE_x86 = arch/x86/boot/bzImage IMAGE_arm64 = arch/arm64/boot/Image IMAGE_arm = arch/arm/boot/zImage IMAGE_mips = vmlinuz +IMAGE_riscv32 = arch/riscv/boot/Image +IMAGE_riscv64 = arch/riscv/boot/Image IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi @@ -34,6 +41,8 @@ DEFCONFIG_x86 = defconfig DEFCONFIG_arm64 = defconfig DEFCONFIG_arm = multi_v7_defconfig DEFCONFIG_mips = malta_defconfig +DEFCONFIG_riscv32 = rv32_defconfig +DEFCONFIG_riscv64 = defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig @@ -49,6 +58,8 @@ QEMU_ARCH_x86 = x86_64 QEMU_ARCH_arm64 = aarch64 QEMU_ARCH_arm = arm QEMU_ARCH_mips = mipsel # works with malta_defconfig +QEMU_ARCH_riscv32 = riscv32 +QEMU_ARCH_riscv64 = riscv64 QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x QEMU_ARCH_loongarch = loongarch64 @@ -61,6 +72,8 @@ QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $( QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_riscv32 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_riscv64 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -76,6 +89,7 @@ else Q=@ endif +CFLAGS_riscv32 = -march=rv32im -mabi=ilp32 CFLAGS_s390 = -m64 CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ @@ -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=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone + $(Q)$(MAKE) -C ../../../include/nolibc ARCH=$(KARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone $(Q)mv sysroot/sysroot sysroot/$(ARCH) nolibc-test: nolibc-test.c sysroot/$(ARCH)/include @@ -141,10 +155,10 @@ initramfs: nolibc-test $(Q)cp nolibc-test initramfs/init defconfig: - $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare + $(Q)$(MAKE) -C $(srctree) ARCH=$(KARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare kernel: initramfs - $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs + $(Q)$(MAKE) -C $(srctree) ARCH=$(KARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs # run the tests after building the kernel run: kernel