11# SPDX-License-Identifier: GPL-2.0
22# Makefile for nolibc tests
33include ../../../scripts/Makefile.include
4+ include ../../../scripts/utilities.mak
45# We need this for the "cc-option" macro.
56include ../../../build/Build.include
67
8+ ifneq ($(O ) ,)
9+ ifneq ($(call is-absolute,$(O ) ) ,y)
10+ $(error Only absolute O= parameters are supported)
11+ endif
12+ endif
13+
714# we're in ".../tools/testing/selftests/nolibc"
815ifeq ($(srctree ) ,)
916srctree := $(patsubst % /tools/testing/selftests/,% ,$(dir $(CURDIR ) ) )
@@ -14,6 +21,8 @@ include $(srctree)/scripts/subarch.include
1421ARCH = $(SUBARCH )
1522endif
1623
24+ objtree ?= $(srctree )
25+
1726# XARCH extends the kernel's ARCH with a few variants of the same
1827# architecture that only differ by the configuration, the toolchain
1928# and the Qemu program used. It is copied as-is into ARCH except for
@@ -31,12 +40,15 @@ endif
3140
3241# configure default variants for target kernel supported architectures
3342XARCH_powerpc = ppc
43+ XARCH_mips = mips32le
3444XARCH = $(or $(XARCH_$(ARCH ) ) ,$(ARCH ) )
3545
3646# map from user input variants to their kernel supported architectures
3747ARCH_ppc = powerpc
3848ARCH_ppc64 = powerpc
3949ARCH_ppc64le = powerpc
50+ ARCH_mips32le = mips
51+ ARCH_mips32be = mips
4052ARCH := $(or $(ARCH_$(XARCH ) ) ,$(XARCH ) )
4153
4254# kernel image names by architecture
@@ -45,14 +57,15 @@ IMAGE_x86_64 = arch/x86/boot/bzImage
4557IMAGE_x86 = arch/x86/boot/bzImage
4658IMAGE_arm64 = arch/arm64/boot/Image
4759IMAGE_arm = arch/arm/boot/zImage
48- IMAGE_mips = vmlinuz
60+ IMAGE_mips32le = vmlinuz
61+ IMAGE_mips32be = vmlinuz
4962IMAGE_ppc = vmlinux
5063IMAGE_ppc64 = vmlinux
5164IMAGE_ppc64le = arch/powerpc/boot/zImage
5265IMAGE_riscv = arch/riscv/boot/Image
5366IMAGE_s390 = arch/s390/boot/bzImage
5467IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
55- IMAGE = $(IMAGE_$(XARCH ) )
68+ IMAGE = $(objtree ) / $( IMAGE_$(XARCH ) )
5669IMAGE_NAME = $(notdir $(IMAGE ) )
5770
5871# default kernel configurations that appear to be usable
@@ -61,7 +74,8 @@ DEFCONFIG_x86_64 = defconfig
6174DEFCONFIG_x86 = defconfig
6275DEFCONFIG_arm64 = defconfig
6376DEFCONFIG_arm = multi_v7_defconfig
64- DEFCONFIG_mips = malta_defconfig
77+ DEFCONFIG_mips32le = malta_defconfig
78+ DEFCONFIG_mips32be = malta_defconfig
6579DEFCONFIG_ppc = pmac32_defconfig
6680DEFCONFIG_ppc64 = powernv_be_defconfig
6781DEFCONFIG_ppc64le = powernv_defconfig
@@ -70,6 +84,9 @@ DEFCONFIG_s390 = defconfig
7084DEFCONFIG_loongarch = defconfig
7185DEFCONFIG = $(DEFCONFIG_$(XARCH ) )
7286
87+ EXTRACONFIG_mips32be = -d CONFIG_CPU_LITTLE_ENDIAN -e CONFIG_CPU_BIG_ENDIAN
88+ EXTRACONFIG = $(EXTRACONFIG_$(XARCH ) )
89+
7390# optional tests to run (default = all)
7491TEST =
7592
@@ -79,7 +96,8 @@ QEMU_ARCH_x86_64 = x86_64
7996QEMU_ARCH_x86 = x86_64
8097QEMU_ARCH_arm64 = aarch64
8198QEMU_ARCH_arm = arm
82- QEMU_ARCH_mips = mipsel # works with malta_defconfig
99+ QEMU_ARCH_mips32le = mipsel # works with malta_defconfig
100+ QEMU_ARCH_mips32be = mips
83101QEMU_ARCH_ppc = ppc
84102QEMU_ARCH_ppc64 = ppc64
85103QEMU_ARCH_ppc64le = ppc64
@@ -88,20 +106,31 @@ QEMU_ARCH_s390 = s390x
88106QEMU_ARCH_loongarch = loongarch64
89107QEMU_ARCH = $(QEMU_ARCH_$(XARCH ) )
90108
109+ QEMU_ARCH_USER_ppc64le = ppc64le
110+ QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH ) ) ,$(QEMU_ARCH_$(XARCH ) ) )
111+
112+ QEMU_BIOS_DIR = /usr/share/edk2/
113+ QEMU_BIOS_loongarch = $(QEMU_BIOS_DIR ) /loongarch64/OVMF_CODE.fd
114+
115+ ifneq ($(QEMU_BIOS_$(XARCH ) ) ,)
116+ QEMU_ARGS_BIOS = -bios $(QEMU_BIOS_$(XARCH ) )
117+ endif
118+
91119# QEMU_ARGS : some arch-specific args to pass to qemu
92120QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
93121QEMU_ARGS_x86_64 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
94122QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
95123QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
96124QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
97- QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
125+ QEMU_ARGS_mips32le = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
126+ QEMU_ARGS_mips32be = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
98127QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
99128QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
100129QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
101130QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
102131QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
103132QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=% ) "
104- QEMU_ARGS = $(QEMU_ARGS_$(XARCH ) ) $(QEMU_ARGS_EXTRA )
133+ QEMU_ARGS = $(QEMU_ARGS_$(XARCH ) ) $(QEMU_ARGS_BIOS ) $( QEMU_ARGS_EXTRA )
105134
106135# OUTPUT is only set when run from the main makefile, otherwise
107136# it defaults to this nolibc directory.
@@ -118,7 +147,8 @@ CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
118147CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
119148CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
120149CFLAGS_s390 = -m64
121- CFLAGS_mips = -EL
150+ CFLAGS_mips32le = -EL -mabi=32 -fPIC
151+ CFLAGS_mips32be = -EB -mabi=32
122152CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all) )
123153CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
124154 $(call cc-option,-fno-stack-protector) \
@@ -167,7 +197,8 @@ sysroot: sysroot/$(ARCH)/include
167197sysroot/$(ARCH ) /include :
168198 $(Q ) rm -rf sysroot/$(ARCH ) sysroot/sysroot
169199 $(QUIET_MKDIR ) mkdir -p sysroot
170- $(Q )$(MAKE ) -C ../../../include/nolibc ARCH=$(ARCH ) OUTPUT=$(CURDIR ) /sysroot/ headers_standalone
200+ $(Q )$(MAKE ) -C $(srctree ) outputmakefile
201+ $(Q )$(MAKE ) -C $(srctree ) /tools/include/nolibc ARCH=$(ARCH ) OUTPUT=$(CURDIR ) /sysroot/ headers_standalone
171202 $(Q ) mv sysroot/sysroot sysroot/$(ARCH )
172203
173204ifneq ($(NOLIBC_SYSROOT ) ,0)
@@ -177,7 +208,7 @@ nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
177208else
178209nolibc-test : nolibc-test.c nolibc-test-linkage.c
179210 $(QUIET_CC )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ \
180- -nostdlib -static -include ../../.. /include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
211+ -nostdlib -static -include $( srctree ) /tools /include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
181212endif
182213
183214libc-test : nolibc-test.c nolibc-test-linkage.c
@@ -195,11 +226,11 @@ run-nolibc-test: nolibc-test
195226
196227# qemu user-land test
197228run-user : nolibc-test
198- $(Q ) qemu-$(QEMU_ARCH ) ./nolibc-test > " $( CURDIR) /run.out" || :
229+ $(Q ) qemu-$(QEMU_ARCH_USER ) ./nolibc-test > " $( CURDIR) /run.out" || :
199230 $(Q )$(REPORT ) $(CURDIR ) /run.out
200231
201232initramfs.cpio : kernel nolibc-test
202- $(QUIET_GEN ) echo ' file /init nolibc-test 755 0 0' | $(srctree ) /usr/gen_init_cpio - > initramfs.cpio
233+ $(QUIET_GEN ) echo ' file /init nolibc-test 755 0 0' | $(objtree ) /usr/gen_init_cpio - > initramfs.cpio
203234
204235initramfs : nolibc-test
205236 $(QUIET_MKDIR ) mkdir -p initramfs
@@ -208,21 +239,25 @@ initramfs: nolibc-test
208239
209240defconfig :
210241 $(Q )$(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) mrproper $(DEFCONFIG ) prepare
242+ $(Q ) if [ -n " $( EXTRACONFIG) " ]; then \
243+ $(srctree ) /scripts/config --file $(objtree ) /.config $(EXTRACONFIG ) ; \
244+ $(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) olddefconfig < /dev/null; \
245+ fi
211246
212247kernel :
213- $(Q )$(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) $(IMAGE_NAME )
248+ $(Q )$(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) $(IMAGE_NAME ) < /dev/null
214249
215250kernel-standalone : initramfs
216- $(Q )$(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) $(IMAGE_NAME ) CONFIG_INITRAMFS_SOURCE=$(CURDIR ) /initramfs
251+ $(Q )$(MAKE ) -C $(srctree ) ARCH=$(ARCH ) CC=$(CC ) CROSS_COMPILE=$(CROSS_COMPILE ) $(IMAGE_NAME ) CONFIG_INITRAMFS_SOURCE=$(CURDIR ) /initramfs < /dev/null
217252
218253# run the tests after building the kernel
219254run : kernel initramfs.cpio
220- $(Q ) qemu-system-$(QEMU_ARCH ) -display none -no-reboot -kernel " $( srctree ) / $( IMAGE) " -initrd initramfs.cpio -serial stdio $(QEMU_ARGS ) > " $( CURDIR) /run.out"
255+ $(Q ) qemu-system-$(QEMU_ARCH ) -display none -no-reboot -kernel " $( IMAGE) " -initrd initramfs.cpio -serial stdio $(QEMU_ARGS ) > " $( CURDIR) /run.out"
221256 $(Q )$(REPORT ) $(CURDIR ) /run.out
222257
223258# re-run the tests from an existing kernel
224259rerun :
225- $(Q ) qemu-system-$(QEMU_ARCH ) -display none -no-reboot -kernel " $( srctree ) / $( IMAGE) " -initrd initramfs.cpio -serial stdio $(QEMU_ARGS ) > " $( CURDIR) /run.out"
260+ $(Q ) qemu-system-$(QEMU_ARCH ) -display none -no-reboot -kernel " $( IMAGE) " -initrd initramfs.cpio -serial stdio $(QEMU_ARGS ) > " $( CURDIR) /run.out"
226261 $(Q )$(REPORT ) $(CURDIR ) /run.out
227262
228263# report with existing test log
0 commit comments