From 5ddcd56cda7263b71941a3b3f71751d388a887a7 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 28 Apr 2023 16:10:56 +0800 Subject: [PATCH 01/89] clone: Add tag support Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0f3daaa..b0206c2 100644 --- a/Makefile +++ b/Makefile @@ -1975,7 +1975,7 @@ endef # gencfgs define genclone ifneq ($$($(call _uc,$2)_NEW),) -NEW_$3CFG_FILE := $$(_BSP_CONFIG)/$$($(call _uc,$1)_FORK_)$2_$$($(call _uc,$2)_NEW)_defconfig +NEW_$3CFG_FILE := $$(_BSP_CONFIG)/$$($(call _uc,$1)_FORK_)$2_$$($(call _uc,$2)_NEW)_$$(if $$($3TAG),$$($3TAG)_)defconfig NEW_PREBUILT_$(call _uc,$1)_DIR := $$(subst $$($(call _uc,$2)),$$($(call _uc,$2)_NEW),$$(PREBUILT_$(call _uc,$1)_DIR)) ifeq ($$(wildcard $$(NEW_PREBUILT_$(call _uc,$1)_DIR)),) -- Gitee From 1574717cd83a5e5803864ec32d3c779c6a22b0e7 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 4 May 2023 10:57:50 +0800 Subject: [PATCH 02/89] nommu: Allow run kernel as bios QEMU v8.0.0 not boot nommu kernel with "-bios none -kernel /path/to/kernel/image", like u-boot, let it use "-bios /path/to/kernel/image" instead, with this method, the "-append" not work: $ make boot KERNEL_BIOS=1 v6.2 + QEMU v6.0.0 works well with both "-bios none -kernel /path/to/kernel/image" and "-bios /path/to/kernel/image", but v6.2/v6.3 + QEMU v8.0.0 has many issues, especially for v6.3 + QEMU v8.0.0. some fatal regresstions should be fixed in both QEMU v8.0.0 and Linux v6.3. Signed-off-by: Zhangjin Wu --- Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b0206c2..366f4d4 100644 --- a/Makefile +++ b/Makefile @@ -413,6 +413,10 @@ BOARD_KERNEL ?= $(BOARD_DIR)/kernel$(_KERNEL_FORK) nommu ?= 0 NOMMU ?= $(nommu) +# Allow run Kernel as BIOS +LINUX_BIOS ?= 0 +KERNEL_BIOS ?= $(LINUX_BIOS) + # Nolibc support nolibc ?= $(noroot) NOLIBC ?= $(nolibc) @@ -969,9 +973,11 @@ HOST_CPU_THREADS := $$(nproc) JOBS ?= $(HOST_CPU_THREADS) # Emulator configurations +ifeq ($(KERNEL_BIOS),0) ifneq ($(BIOS),) BIOS_ARG := -bios $(BIOS) endif +endif # Another qemu-system-$(ARCH) QEMU_SYSTEM ?= $(QEMU_BUILD)/$(XARCH)-softmmu/qemu-system-$(XARCH) @@ -3844,9 +3850,9 @@ ifneq ($(PORIIMG),) KERNEL_OPT ?= -kernel $(PKIMAGE) -device loader,file=$(QEMU_KIMAGE),addr=$(KRN_ADDR) else ifeq ($(U),1) - KERNEL_OPT ?= $(if $(UBOOT_BIOS),-bios,-kernel) $(QEMU_KIMAGE) + KERNEL_OPT ?= $(if $(findstring 1,$(UBOOT_BIOS)),-bios,-kernel) $(QEMU_KIMAGE) else - KERNEL_OPT ?= -kernel $(QEMU_KIMAGE) + KERNEL_OPT ?= $(if $(findstring 1,$(KERNEL_BIOS)),-bios,-kernel) $(QEMU_KIMAGE) endif endif @@ -3891,7 +3897,7 @@ ifeq ($(U),1) # Load pflash for booting with uboot every time # pflash is at least used as the env storage # unit=1 means the second pflash, the first one is unit=0 - BOOT_CMD += -drive if=pflash,file=$(PFLASH_IMG),format=raw$(if $(UBOOT_BIOS),$(comma)unit=1) + BOOT_CMD += -drive if=pflash,file=$(PFLASH_IMG),format=raw$(if $(findstring 1,$(UBOOT_BIOS)),$(comma)unit=1) endif else # U != 1 ifneq ($(findstring /dev/ram,$(ROOTDEV)),) @@ -4041,7 +4047,7 @@ endif CMDLINE := $(subst $space$space,$space,$(strip $(CMDLINE))) ifneq ($(U),1) - BOOT_CMD += -append "$(CMDLINE)" + BOOT_CMD += $(if $(findstring -kernel,$(CMDLINE)),-append "$(CMDLINE)") endif ifneq ($(TEST_REBOOT), 0) -- Gitee From 1c2380670f3713932e85ae8c86bc7e2c79898617 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 18 May 2023 14:51:28 +0800 Subject: [PATCH 03/89] riscv32/virt: Add initial nolibc support To let this work: 1. please fix up load/store instructions in tools/include/nolibc/arch-riscv.h * lw/sw for rv32 and ld/sd for rv64 2. revert d4c08b9776b3 3. and use llseek to implement lseek Signed-off-by: Zhangjin Wu --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 366f4d4..040d007 100644 --- a/Makefile +++ b/Makefile @@ -3226,6 +3226,15 @@ else NOLIBC_INC := -I$(NOLIBC_SYSROOT_ARCH)/include endif +ifeq ($(XARCH),riscv32) + # FIXME: need to use lw/sw instead of ld/sd in tools/include/nolibc/arch-riscv.h + NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 + # Linux commit d4c08b9776b3 ("riscv: Use latest system call ABI") removed all of the time32 syscalls + # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls + NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS -D__NR_lseek=__NR_llseek + NOLIBC_LDFLAGS += -melf32lriscv_ilp32 +endif + # nolibc gc sections and debug support nolibc_gc ?= 1 nolibc_gc_debug ?= 1 -- Gitee From 145f34d1c2dababe40c9800dd080bac2eb34e092 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 02:32:56 +0800 Subject: [PATCH 04/89] nolibc: Allow debug syscall usage Signed-off-by: Zhangjin Wu --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 040d007..a5a1226 100644 --- a/Makefile +++ b/Makefile @@ -3270,6 +3270,8 @@ $(NOLIBC_SYSROOT_ARCH): $(NOLIBC_FILES) $(NOLIBC_OBJ): $(NOLIBC_SRC) $(NOLIBC_DEP) $(Q)echo "Building $@" $(Q)mkdir -p $(dir $@) + $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -E -o $@.i \ + -nostdlib -static $(NOLIBC_INC) $< -lgcc $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -c -o $@ \ -nostdlib -static $(NOLIBC_INC) $< -lgcc -- Gitee From 60529ddbaf7bbf39826e0248139e1f04398d1139 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 02:35:28 +0800 Subject: [PATCH 05/89] riscv32/virt: add rv32 nolibc patch url A patchset has been sent out: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t Signed-off-by: Zhangjin Wu --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a5a1226..0dcb7a9 100644 --- a/Makefile +++ b/Makefile @@ -3227,11 +3227,12 @@ else endif ifeq ($(XARCH),riscv32) + # ref: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t # FIXME: need to use lw/sw instead of ld/sd in tools/include/nolibc/arch-riscv.h NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 # Linux commit d4c08b9776b3 ("riscv: Use latest system call ABI") removed all of the time32 syscalls # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls - NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS -D__NR_lseek=__NR_llseek + NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS NOLIBC_LDFLAGS += -melf32lriscv_ilp32 endif -- Gitee From 602efb12c794d6f89b22a12a6e4b8fe99d8e7c72 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 13:15:37 +0800 Subject: [PATCH 06/89] nolibc: Add nolibc-test support $ export nolibc=1 $ make nolibc-clean $ make nolibc nolibc_src=test $ make boot nolibc_test="syscall:6-10,stdlib:1-3" Signed-off-by: Zhangjin Wu --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0dcb7a9..4a43790 100644 --- a/Makefile +++ b/Makefile @@ -1198,7 +1198,9 @@ _PBR := $(PBR) NOLIBC_DIR := $(KERNEL_ABS_SRC)/tools/include/nolibc NOLIBC_H := $(NOLIBC_DIR)/nolibc.h # The 'init' source code for initramfs, customize it for your own project -nolibc_src ?= $(TOP_DIR)/src/examples/nolibc/hello.c +nolibc-hello ?= $(TOP_DIR)/src/examples/nolibc/hello.c +nolibc-test ?= $(KERNEL_ABS_SRC)/tools/testing/selftests/nolibc/nolibc-test.c +nolibc_src ?= $(nolibc-hello) NOLIBC_SRC ?= $(nolibc_src) NOLIBC_BIN := $(KERNEL_BUILD)/nolibc/init NOLIBC_OBJ := $(KERNEL_BUILD)/nolibc/init.o @@ -1210,6 +1212,13 @@ NOLIBC_SYSROOT_ARCH := $(NOLIBC_SYSROOT)/$(ARCH) NOLIBC_INITRAMFS := $(KERNEL_BUILD)/nolibc/initramfs NOLIBC_FILES := $(wildcard $(NOLIBC_DIR)/*.h) +ifeq ($(nolibc_src),test) + override nolibc_src := $(nolibc-test) +endif +ifneq ($(nolibc_test),) + XKCLI += "NOLIBC_TEST=$(nolibc_test)" +endif + ifeq ($(NOMMU),1) _NOLIBC_BIN := $(NOLIBC_FLT) else -- Gitee From bf3ce7012bacc489bbf9f9a6b159ac202433dc23 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 13:20:14 +0800 Subject: [PATCH 07/89] Clean up additional kernel command line setting Allow use KCLI instead of XKCLI, XKCLI is used internally. Signed-off-by: Zhangjin Wu --- Makefile | 1 + README.md | 4 ++-- README_zh.md | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4a43790..17044d9 100644 --- a/Makefile +++ b/Makefile @@ -3768,6 +3768,7 @@ endif # Extra kernel command line CMDLINE += $(call _v,XKCLI,LINUX) +CMDLINE += $(call _v,KCLI,LINUX) # Graphic output? we prefer Serial port ;-) G ?= 0 diff --git a/README.md b/README.md index 4e918e9..5c89132 100644 --- a/README.md +++ b/README.md @@ -999,9 +999,9 @@ Boot with different rootfs (depends on board, check `/dev/` after boot): $ make boot ROOTDEV=mmcblk0 $ make boot ROOTDEV=vda // virtio based block device -Boot with extra kernel command line (XKCLI = eXtra Kernel Command LIne): +Boot with extra kernel command line (KCLI = Additional Kernel Command LIne): - $ make boot ROOTDEV=nfs XKCLI="init=/bin/bash" + $ make boot ROOTDEV=nfs KCLI="init=/bin/bash" List supported options: diff --git a/README_zh.md b/README_zh.md index 797f9f1..fad84b5 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1217,9 +1217,9 @@ v0.3 以及之后的版本默认增加了目标依赖支持,所以,如果想 $ make boot ROOTDEV=mmcblk0 $ make boot ROOTDEV=vda // virtio based block device -使用额外的内核命令行参数启动(格式:`XKCLI = eXtra Kernel Command LIne`): +使用额外的内核命令行参数启动(格式:`KCLI = Additional Kernel Command LIne`): - $ make boot ROOTDEV=nfs XKCLI="init=/bin/bash" + $ make boot ROOTDEV=nfs KCLI="init=/bin/bash" 列出支持的选项: -- Gitee From 5fd346b83d8dcb4520f1813616058207e136b347 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 13:21:23 +0800 Subject: [PATCH 08/89] Clean up additional qemu options setting Use QOPTS instead of XOPTS, it is more meaningful. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- README.md | 4 ++-- README_zh.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 17044d9..35bf0d6 100644 --- a/Makefile +++ b/Makefile @@ -3974,7 +3974,7 @@ else endif # Add extra qemu options -BOOT_CMD += $(XOPTS) $(XQOPT) +BOOT_CMD += $(XOPTS) $(XQOPT) $(QOPTS) # Get DEBUG option if -debug found in goals ifeq (debug,$(firstword $(MAKECMDGOALS))) diff --git a/README.md b/README.md index 5c89132..ba38a83 100644 --- a/README.md +++ b/README.md @@ -966,10 +966,10 @@ Boot with graphic (Exit with `CTRL+ALT+2 quit`): `vexpress-a9` and `virt` has no LCD support by default, but for the latest qemu, it is able to boot with G=1 and switch to serial console via the 'View' menu, this can not be used to test LCD and -keyboard drivers. `XOPTS` specify the eXtra QEMU options. +keyboard drivers. `QOPTS` specify the additional QEMU options. $ make b=vexpress-a9 CONSOLE=ttyAMA0 boot G=1 LINUX=v5.1 - $ make b=raspi3 CONSOLE=ttyAMA0 XOPTS="-serial vc -serial vc" boot G=1 LINUX=v5.1 + $ make b=raspi3 CONSOLE=ttyAMA0 QOPTS="-serial vc -serial vc" boot G=1 LINUX=v5.1 Boot with curses graphic (friendly to bash/ssh login, not work for all boards, exit with `ESC+2 quit` or `ALT+2 quit`): diff --git a/README_zh.md b/README_zh.md index fad84b5..938eef7 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1184,10 +1184,10 @@ v0.3 以及之后的版本默认增加了目标依赖支持,所以,如果想 * 真正的图形化方式启动需要 LCD 和键盘驱动的支持,上述开发板可以完美支持 Linux 内核 5.1 版本的运行,`raspi3` 和 `malta` 两款开发板支持 tty0 终端但不支持键盘输入。 * 新版 `BUILDROOT` 配置文件目前设定了 tty 终端为串口(`BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"`),如需启用图形控制台,请修改目标文件系统 `/etc/inittab` 中对应的 `getty` 代码行,例如,把 `ttyAMA0` 替换为 `console`;也可简单通过 QEMU 的 “View” 菜单切换到串口终端后使用。 -`vexpress-a9` 和 `virt` 缺省情况下不支持 LCD,但对于最新的 QEMU,可以通过在启动时指定 `G=1` 参数然后通过选择 “View” 菜单切换到串口终端,但这么做无法用于测试 LCD 和键盘驱动。我们可以通过 `XOPTS` 选项指定额外的 QEMU 选项参数。 +`vexpress-a9` 和 `virt` 缺省情况下不支持 LCD,但对于最新的 QEMU,可以通过在启动时指定 `G=1` 参数然后通过选择 “View” 菜单切换到串口终端,但这么做无法用于测试 LCD 和键盘驱动。我们可以通过 `QOPTS` 选项指定额外的 QEMU 选项参数。 $ make b=vexpress-a9 CONSOLE=ttyAMA0 boot G=1 LINUX=v5.1 - $ make b=raspi3 CONSOLE=ttyAMA0 XOPTS="-serial vc -serial vc" boot G=1 LINUX=v5.1 + $ make b=raspi3 CONSOLE=ttyAMA0 QOPTS="-serial vc -serial vc" boot G=1 LINUX=v5.1 基于 curses 图形方式启动(这么做适合采用 bash/ssh 的登录方式,但不是对所有开发板都有效,退出时需要使用 `ESC+2 quit` 或 `ALT+2 quit`) -- Gitee From 141b2078d3607b2a1ccaa87fac8dc5c2e2297777 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 18:27:09 +0800 Subject: [PATCH 09/89] nolibc: Add automatic test support Convert nolibc to a feature, let it trigger auto kernel build. $ make test f=nolibc nolibc_test=syscall:1-3 Signed-off-by: Zhangjin Wu --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 35bf0d6..f968891 100644 --- a/Makefile +++ b/Makefile @@ -1212,6 +1212,14 @@ NOLIBC_SYSROOT_ARCH := $(NOLIBC_SYSROOT)/$(ARCH) NOLIBC_INITRAMFS := $(KERNEL_BUILD)/nolibc/initramfs NOLIBC_FILES := $(wildcard $(NOLIBC_DIR)/*.h) +ifneq ($(findstring nolibc,$(FEATURE)),) + ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) + PREPARE += nolibc-clean nolibc + export nolibc=1 + export nolibc_src=test + endif +endif + ifeq ($(nolibc_src),test) override nolibc_src := $(nolibc-test) endif -- Gitee From 1435985ec92d3cafe18aaabed27e21fe24993307 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 18:32:53 +0800 Subject: [PATCH 10/89] nolibc: Allow setting nolibc_src for test target // by default $ make test f=nolibc nolibc_src=test // change it $ make test f=nolibc nolibc_src=hello Signed-off-by: Zhangjin Wu --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f968891..b387e36 100644 --- a/Makefile +++ b/Makefile @@ -1216,13 +1216,19 @@ ifneq ($(findstring nolibc,$(FEATURE)),) ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) PREPARE += nolibc-clean nolibc export nolibc=1 - export nolibc_src=test + # If no nolibc_src manual setting, use nolibc-test by default + ifneq ($(origin nolibc_src),command line) + export nolibc_src=test + endif endif endif ifeq ($(nolibc_src),test) override nolibc_src := $(nolibc-test) endif +ifeq ($(nolibc_src),hello) + override nolibc_src := $(nolibc-hello) +endif ifneq ($(nolibc_test),) XKCLI += "NOLIBC_TEST=$(nolibc_test)" endif -- Gitee From c263fc631f7fc3df40a8466c5865837f452dba4d Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 19 May 2023 22:22:01 +0800 Subject: [PATCH 11/89] nolibc: let nolibc work as a type of root target when nolibc enabled, run nolibc target as root, run nolibc-clean as root-clean and run nolibc-distclean as root-distclean. otherwise, the ROOT* variables will be mixed and broken. Signed-off-by: Zhangjin Wu --- Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile b/Makefile index b387e36..a33dbe8 100644 --- a/Makefile +++ b/Makefile @@ -1836,6 +1836,7 @@ $1-cleanstamp: $$(Q)rm -rvf $$(addprefix $$($(call _uc,$1)_BUILD)/.stamp_$1-,outdir source checkout patch env modules modules-km defconfig olddefconfig menuconfig build bsp license) ## clean up $1 source code +ifneq ($1$(NOLIBC),root1) $1-cleansrc: $1-cleanup $1-cleanup: $1-cleanstamp $$(Q)[ -d $$($(call _uc,$1)_SRC_FULL) -a -e $$($(call _uc,$1)_SRC_FULL)/.git ] \ @@ -1855,6 +1856,7 @@ $1-distclean: $$(call make_$1,distclean); \ rm -rvf $$($(call _uc,$1)_BUILD); \ fi +endif PHONY += $(addprefix $1-,cleanstamp cleanup cleansrc cleanall outdir clean distclean) @@ -2553,6 +2555,9 @@ endif RT ?= $(x) +ifeq ($(NOLIBC),1) +_root: root-nolibc +else # !NOLIBC ifneq ($(RT),) _root: $(Q)$(call make_root,$(RT)) @@ -2560,8 +2565,14 @@ else _root: $(ROOT) $(Q)make $(S) root-rebuild endif +endif # !NOLIBC +ifeq ($(NOLIBC),1) +root-clean: root-nolibc-clean +root-distclean: root-nolibc-distclean +else root-clean: $(addsuffix -clean,$(addprefix root-,dir hd $(if $(UBOOT),ud) rd)) +endif # root directory ifneq ($(FS_TYPE),dir) -- Gitee From 4677652d936b6cea4d4204d09f1be24ab6a7f0c3 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 11:31:07 +0800 Subject: [PATCH 12/89] nolibc: Clean up root targets support Signed-off-by: Zhangjin Wu --- Makefile | 57 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index a33dbe8..f394d51 100644 --- a/Makefile +++ b/Makefile @@ -1214,8 +1214,8 @@ NOLIBC_FILES := $(wildcard $(NOLIBC_DIR)/*.h) ifneq ($(findstring nolibc,$(FEATURE)),) ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) - PREPARE += nolibc-clean nolibc export nolibc=1 + PREPARE += root-rebuild # If no nolibc_src manual setting, use nolibc-test by default ifneq ($(origin nolibc_src),command line) export nolibc_src=test @@ -1836,7 +1836,6 @@ $1-cleanstamp: $$(Q)rm -rvf $$(addprefix $$($(call _uc,$1)_BUILD)/.stamp_$1-,outdir source checkout patch env modules modules-km defconfig olddefconfig menuconfig build bsp license) ## clean up $1 source code -ifneq ($1$(NOLIBC),root1) $1-cleansrc: $1-cleanup $1-cleanup: $1-cleanstamp $$(Q)[ -d $$($(call _uc,$1)_SRC_FULL) -a -e $$($(call _uc,$1)_SRC_FULL)/.git ] \ @@ -1856,7 +1855,6 @@ $1-distclean: $$(call make_$1,distclean); \ rm -rvf $$($(call _uc,$1)_BUILD); \ fi -endif PHONY += $(addprefix $1-,cleanstamp cleanup cleansrc cleanall outdir clean distclean) @@ -2415,6 +2413,32 @@ ifneq ($(findstring root,$(MAKECMDGOALS)),) endif ifeq ($(root_targets),1) +ifeq ($(NOLIBC),1) + +root-nolibc: nolibc-initramfs +root-nolibc-distclean: root-nolibc-clean + $(Q)echo "Cleaning nolibc output" + $(Q)rm -rf $(NOLIBC_SYSROOT) + +root-nolibc-clean: + $(Q)rm -rf $(NOLIBC_BIN) + $(Q)rm -rf $(NOLIBC_OBJ) + $(Q)rm -rf $(NOLIBC_FLT) + $(Q)rm -rf $(NOLIBC_PGC) + $(Q)rm -rf $(NOLIBC_INITRAMFS) + +nolibc: root-nolibc +nolibc-distclean: root-nolibc-distclean +nolibc-clean: root-nolibc-clean + +root: root-nolibc +root-rebuild: root-nolibc-clean root-nolibc +root-clean: root-nolibc-clean +root-distclean: root-nolibc-distclean + +PHONY += root-nolibc root-nolibc-clean nolibc nolibc-clean nolibc-distclean root root-rebuild root-clean root-distclean + +else # !NOLIBC _BUILDROOT ?= $(call _v,BUILDROOT,BUILDROOT) #$(warning $(call gensource,root,BUILDROOT)) @@ -2437,23 +2461,6 @@ $(eval $(call genclone,root,buildroot,R)) #$(warning $(call genenvdeps,root,BUILDROOT) $(eval $(call genenvdeps,root,BUILDROOT,R)) -root-nolibc: nolibc-initramfs -root-nolibc-distclean: root-nolibc-clean - $(Q)echo "Cleaning nolibc output" - $(Q)rm -rf $(NOLIBC_SYSROOT) - -root-nolibc-clean: - $(Q)rm -rf $(NOLIBC_BIN) - $(Q)rm -rf $(NOLIBC_OBJ) - $(Q)rm -rf $(NOLIBC_FLT) - $(Q)rm -rf $(NOLIBC_PGC) - $(Q)rm -rf $(NOLIBC_INITRAMFS) - -nolibc: root-nolibc -nolibc-distclean: root-nolibc-distclean -nolibc-clean: root-nolibc-clean -PHONY += root-nolibc root-nolibc-clean nolibc nolibc-clean nolibc-distclean - # Build Buildroot root-buildroot: $(call make_root,$(RT)) @@ -2555,9 +2562,6 @@ endif RT ?= $(x) -ifeq ($(NOLIBC),1) -_root: root-nolibc -else # !NOLIBC ifneq ($(RT),) _root: $(Q)$(call make_root,$(RT)) @@ -2565,14 +2569,8 @@ else _root: $(ROOT) $(Q)make $(S) root-rebuild endif -endif # !NOLIBC -ifeq ($(NOLIBC),1) -root-clean: root-nolibc-clean -root-distclean: root-nolibc-distclean -else root-clean: $(addsuffix -clean,$(addprefix root-,dir hd $(if $(UBOOT),ud) rd)) -endif # root directory ifneq ($(FS_TYPE),dir) @@ -2658,6 +2656,7 @@ root-hd-clean: PHONY += root-hd root-hd-rebuild root-hd-clean +endif # !NOLIBC endif # Root targets # Linux Kernel targets -- Gitee From 95e3774296008806d8e4139f42de16de120518a2 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 11:42:49 +0800 Subject: [PATCH 13/89] nolibc: merge tagets together Signed-off-by: Zhangjin Wu --- Makefile | 207 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 104 insertions(+), 103 deletions(-) diff --git a/Makefile b/Makefile index f394d51..9ab24c1 100644 --- a/Makefile +++ b/Makefile @@ -2438,6 +2438,110 @@ root-distclean: root-nolibc-distclean PHONY += root-nolibc root-nolibc-clean nolibc nolibc-clean nolibc-distclean root root-rebuild root-clean root-distclean +# Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile +NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL +NOLIBC_LDFLAGS := -s + +ifneq ($(findstring .sx,$(NOLIBC_SRC)x),) + NOLIBC_CFLAGS += -fno-pic +endif + +# nolibc use method: header or sysroot +ifeq ($(nolibc_inc),header) + NOLIBC_INC := -include $(NOLIBC_H) +else + NOLIBC_CFLAGS += -D__NOLIBC__ + NOLIBC_DEP := $(NOLIBC_SYSROOT_ARCH) + NOLIBC_INC := -I$(NOLIBC_SYSROOT_ARCH)/include +endif + +ifeq ($(XARCH),riscv32) + # ref: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t + # FIXME: need to use lw/sw instead of ld/sd in tools/include/nolibc/arch-riscv.h + NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 + # Linux commit d4c08b9776b3 ("riscv: Use latest system call ABI") removed all of the time32 syscalls + # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls + NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS + NOLIBC_LDFLAGS += -melf32lriscv_ilp32 +endif + +# nolibc gc sections and debug support +nolibc_gc ?= 1 +nolibc_gc_debug ?= 1 + +ifeq ($(nolibc_gc),1) + NOLIBC_CFLAGS += -ffunction-sections -fdata-sections + NOLIBC_LDFLAGS += --gc-sections +endif + +ifeq ($(nolibc_gc_debug),1) + NOLIBC_LDFLAGS += --print-gc-sections +endif + +# ref: elf2flt.ld.in from https://github.com/uclinux-dev/elf2flt +NOLIBC_FLT_LDFLAGS := -Ttools/nolibc/elf2flt.ld +ifeq ($(nolibc_gc),1) + NOLIBC_FLT_LDFLAGS += -e _start +endif + +nolibc_comp ?= 0 +ifeq ($(nolibc_comp),1) + NOLIBC_E2FFLAGS := -z +endif + +# Use UAPI headers from kernel source code +$(NOLIBC_SYSROOT_ARCH): $(NOLIBC_FILES) + $(Q)echo "Generating $@" + $(Q)rm -rf $(NOLIBC_SYSROOT) + $(Q)mkdir -p $(NOLIBC_SYSROOT) + $(Q)$(call make_kernel,headers_standalone OUTPUT=$(NOLIBC_SYSROOT)/,tools/include/nolibc) + $(Q)mv $(NOLIBC_SYSROOT)/sysroot $(NOLIBC_SYSROOT_ARCH) + +# With the -include $(NOLIBC_H) option, use UAPI headers provided by the toolchain +$(NOLIBC_OBJ): $(NOLIBC_SRC) $(NOLIBC_DEP) + $(Q)echo "Building $@" + $(Q)mkdir -p $(dir $@) + $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -E -o $@.i \ + -nostdlib -static $(NOLIBC_INC) $< -lgcc + $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -c -o $@ \ + -nostdlib -static $(NOLIBC_INC) $< -lgcc + +$(NOLIBC_BIN): $(NOLIBC_OBJ) + $(Q)echo "Building $@" + $(Q)mkdir -p $(dir $@) + $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) -o $@ $< 2>&1 | tee $(NOLIBC_PGC) + +# ref: ld-elf2flt.in from https://github.com/uclinux-dev/elf2flt +$(NOLIBC_FLT): $(NOLIBC_OBJ) + $(Q)echo "Building $@" + $(Q)mkdir -p $(dir $@) + $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) $(NOLIBC_FLT_LDFLAGS) -r -d -o $@.elf2flt $< 2>&1 | tee $(NOLIBC_PGC) + $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_FLT_LDFLAGS) -Ur -o $@.elf $@.elf2flt + $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_FLT_LDFLAGS) -o $@.gdb $@.elf2flt + $(Q)tools/nolibc/elf2flt.$(XARCH) $(NOLIBC_E2FFLAGS) -a -v -p $@.gdb $@.elf -o $@ + $(Q)rm -rf $@.elf2flt $@.gdb $@.elf + $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) -o $(NOLIBC_BIN) $< >/dev/null + +$(NOLIBC_INITRAMFS)/init: $(_NOLIBC_BIN) + $(Q)echo "Creating $(NOLIBC_INITRAMFS)" + $(Q)mkdir -p $(NOLIBC_INITRAMFS) $(NOLIBC_INITRAMFS)/dev + $(Q)cp $< $@ + $(Q)[ -c $(NOLIBC_INITRAMFS)/dev/console ] || sudo mknod $(NOLIBC_INITRAMFS)/dev/console c 5 1 + $(Q)[ -c $(NOLIBC_INITRAMFS)/dev/null ] || sudo mknod $(NOLIBC_INITRAMFS)/dev/null c 1 3 + +$(NOLIBC_INITRAMFS): $(NOLIBC_INITRAMFS)/init $(NOLIBC_SCALL) + +nolibc-initramfs: $(NOLIBC_INITRAMFS) + +$(NOLIBC_SCALL): $(_NOLIBC_BIN) + $(Q)$(C_PATH) tools/nolibc/dump.sh $(NOLIBC_BIN) $(XARCH) $(KERNEL_ABS_SRC) "$(NOLIBC_INC)" $(CCPRE) | \ + cut -d ' ' -f2 > $(NOLIBC_SCALL) + $(Q)echo "Used system calls: $$(cat $(NOLIBC_SCALL) | tr '\n' ' ')" + +nolibc-syscall: $(NOLIBC_SCALL) + +PHONY += nolibc-initramfs nolibc-syscall + else # !NOLIBC _BUILDROOT ?= $(call _v,BUILDROOT,BUILDROOT) @@ -3242,109 +3346,6 @@ module-setconfig: kernel-setconfig PHONY += module-getconfig module-setconfig modules-config module-config -# Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL -NOLIBC_LDFLAGS := -s - -ifneq ($(findstring .sx,$(NOLIBC_SRC)x),) - NOLIBC_CFLAGS += -fno-pic -endif - -# nolibc use method: header or sysroot -ifeq ($(nolibc_inc),header) - NOLIBC_INC := -include $(NOLIBC_H) -else - NOLIBC_CFLAGS += -D__NOLIBC__ - NOLIBC_DEP := $(NOLIBC_SYSROOT_ARCH) - NOLIBC_INC := -I$(NOLIBC_SYSROOT_ARCH)/include -endif - -ifeq ($(XARCH),riscv32) - # ref: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t - # FIXME: need to use lw/sw instead of ld/sd in tools/include/nolibc/arch-riscv.h - NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 - # Linux commit d4c08b9776b3 ("riscv: Use latest system call ABI") removed all of the time32 syscalls - # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls - NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS - NOLIBC_LDFLAGS += -melf32lriscv_ilp32 -endif - -# nolibc gc sections and debug support -nolibc_gc ?= 1 -nolibc_gc_debug ?= 1 - -ifeq ($(nolibc_gc),1) - NOLIBC_CFLAGS += -ffunction-sections -fdata-sections - NOLIBC_LDFLAGS += --gc-sections -endif - -ifeq ($(nolibc_gc_debug),1) - NOLIBC_LDFLAGS += --print-gc-sections -endif - -# ref: elf2flt.ld.in from https://github.com/uclinux-dev/elf2flt -NOLIBC_FLT_LDFLAGS := -Ttools/nolibc/elf2flt.ld -ifeq ($(nolibc_gc),1) - NOLIBC_FLT_LDFLAGS += -e _start -endif - -ifeq ($(nolibc_comp),1) - NOLIBC_E2FFLAGS := -z -endif - -# Use UAPI headers from kernel source code -$(NOLIBC_SYSROOT_ARCH): $(NOLIBC_FILES) - $(Q)echo "Generating $@" - $(Q)rm -rf $(NOLIBC_SYSROOT) - $(Q)mkdir -p $(NOLIBC_SYSROOT) - $(Q)$(call make_kernel,headers_standalone OUTPUT=$(NOLIBC_SYSROOT)/,tools/include/nolibc) - $(Q)mv $(NOLIBC_SYSROOT)/sysroot $(NOLIBC_SYSROOT_ARCH) - -# With the -include $(NOLIBC_H) option, use UAPI headers provided by the toolchain -$(NOLIBC_OBJ): $(NOLIBC_SRC) $(NOLIBC_DEP) - $(Q)echo "Building $@" - $(Q)mkdir -p $(dir $@) - $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -E -o $@.i \ - -nostdlib -static $(NOLIBC_INC) $< -lgcc - $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -c -o $@ \ - -nostdlib -static $(NOLIBC_INC) $< -lgcc - -$(NOLIBC_BIN): $(NOLIBC_OBJ) - $(Q)echo "Building $@" - $(Q)mkdir -p $(dir $@) - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) -o $@ $< 2>&1 | tee $(NOLIBC_PGC) - -# ref: ld-elf2flt.in from https://github.com/uclinux-dev/elf2flt -$(NOLIBC_FLT): $(NOLIBC_OBJ) - $(Q)echo "Building $@" - $(Q)mkdir -p $(dir $@) - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) $(NOLIBC_FLT_LDFLAGS) -r -d -o $@.elf2flt $< 2>&1 | tee $(NOLIBC_PGC) - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_FLT_LDFLAGS) -Ur -o $@.elf $@.elf2flt - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_FLT_LDFLAGS) -o $@.gdb $@.elf2flt - $(Q)tools/nolibc/elf2flt.$(XARCH) $(NOLIBC_E2FFLAGS) -a -v -p $@.gdb $@.elf -o $@ - $(Q)rm -rf $@.elf2flt $@.gdb $@.elf - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) -o $(NOLIBC_BIN) $< >/dev/null - -$(NOLIBC_INITRAMFS)/init: $(_NOLIBC_BIN) - $(Q)echo "Creating $(NOLIBC_INITRAMFS)" - $(Q)mkdir -p $(NOLIBC_INITRAMFS) $(NOLIBC_INITRAMFS)/dev - $(Q)cp $< $@ - $(Q)[ -c $(NOLIBC_INITRAMFS)/dev/console ] || sudo mknod $(NOLIBC_INITRAMFS)/dev/console c 5 1 - $(Q)[ -c $(NOLIBC_INITRAMFS)/dev/null ] || sudo mknod $(NOLIBC_INITRAMFS)/dev/null c 1 3 - -$(NOLIBC_INITRAMFS): $(NOLIBC_INITRAMFS)/init $(NOLIBC_SCALL) - -nolibc-initramfs: $(NOLIBC_INITRAMFS) - -$(NOLIBC_SCALL): $(_NOLIBC_BIN) - $(Q)$(C_PATH) tools/nolibc/dump.sh $(NOLIBC_BIN) $(XARCH) $(KERNEL_ABS_SRC) "$(NOLIBC_INC)" $(CCPRE) | \ - cut -d ' ' -f2 > $(NOLIBC_SCALL) - $(Q)echo "Used system calls: $$(cat $(NOLIBC_SCALL) | tr '\n' ' ')" - -nolibc-syscall: $(NOLIBC_SCALL) - -PHONY += nolibc-initramfs nolibc-syscall - _kernel: $(KERNEL_DEPS) $(call make_kernel,$(KT)) -- Gitee From ba2b8408b4b2ccaf377a7fd756066e6ed9cc018a Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 12:16:36 +0800 Subject: [PATCH 14/89] clone: Fix up while X_NEW == X If want to clone X_NEW from X, tell users to clean the setting. Signed-off-by: Zhangjin Wu --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 9ab24c1..ba3a325 100644 --- a/Makefile +++ b/Makefile @@ -2004,6 +2004,7 @@ endef # gencfgs define genclone ifneq ($$($(call _uc,$2)_NEW),) +ifneq ($$($(call _uc,$2)_NEW),$$($(call _uc,$2))) NEW_$3CFG_FILE := $$(_BSP_CONFIG)/$$($(call _uc,$1)_FORK_)$2_$$($(call _uc,$2)_NEW)_$$(if $$($3TAG),$$($3TAG)_)defconfig NEW_PREBUILT_$(call _uc,$1)_DIR := $$(subst $$($(call _uc,$2)),$$($(call _uc,$2)_NEW),$$(PREBUILT_$(call _uc,$1)_DIR)) @@ -2034,6 +2035,14 @@ $1-cloneconfig: $1-clonepatch: endif +else # X_NEW = X + +$1-cloneconfig $1-clonepatch: + $(Q)l=$$$$(grep -r $$($(call _uc,$2)) $$(BOARD_LABCONFIG)) && echo "Please remove $$$$l from $$(BOARD_LABCONFIG)" + $(Q)echo "ERR: Not able to clone from $$($(call _uc,$2)) to $$($(call _uc,$2)_NEW)" && false + +endif # X_NEW = X + else $1-cloneconfig $1-clonepatch: -- Gitee From ddcb44177dbb44293e609c5f5744e9fa2f47a059 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 12:22:37 +0800 Subject: [PATCH 15/89] nolibc: wrap all of the nolibc operations Signed-off-by: Zhangjin Wu --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index ba3a325..4ab7147 100644 --- a/Makefile +++ b/Makefile @@ -1194,6 +1194,7 @@ ROOTDEV_TYPE_TOOL := tools/root/rootdev_type.sh PBR ?= 0 _PBR := $(PBR) +ifeq ($(NOLIBC),1) # Allow build and embed minimal initramfs with nolibc from tools/include/nolibc to kernel image NOLIBC_DIR := $(KERNEL_ABS_SRC)/tools/include/nolibc NOLIBC_H := $(NOLIBC_DIR)/nolibc.h @@ -1248,16 +1249,15 @@ else endif # Prefer nolibc initramfs -ifeq ($(NOLIBC),1) - ifneq ($(wildcard $(NOLIBC_SRC)),) - # Override ROOTFS and ROOTDEV setting to embed nolibc initramfs automatically, no extra rootfs required - # Use initramfs generated from nolibc instead of the others - override ROOTFS := $(NOLIBC_INITRAMFS) - # Build initramfs into kernel image with CONFIG_INITRAMFS_SOURCE - override ROOTDEV := /dev/null - endif - # Tag defconfig - KTAG := nolibc$(if $(KTAG),_$(KTAG)) +ifneq ($(wildcard $(NOLIBC_SRC)),) + # Override ROOTFS and ROOTDEV setting to embed nolibc initramfs automatically, no extra rootfs required + # Use initramfs generated from nolibc instead of the others + override ROOTFS := $(NOLIBC_INITRAMFS) + # Build initramfs into kernel image with CONFIG_INITRAMFS_SOURCE + override ROOTDEV := /dev/null +endif +# Tag defconfig +KTAG := nolibc$(if $(KTAG),_$(KTAG)) endif ifeq ($(_PBR), 0) -- Gitee From d0184a4b7c199733a3e4f84863639a966004d111 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 12:57:23 +0800 Subject: [PATCH 16/89] nolibc: Fix up IROOTFS for NOLIBC Signed-off-by: Zhangjin Wu --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4ab7147..7b827cb 100644 --- a/Makefile +++ b/Makefile @@ -1357,7 +1357,11 @@ ifneq ($(ROOTFS), $(BUILDROOT_IROOTFS)) ifeq ($(FS_TYPE),rd) IROOTFS := $(ROOTFS) else - IROOTFS := $(ROOTDIR)$(ROOTFS_INITRD_SUFFIX) + ifeq ($(NOLIBC),1) + IROOTFS := $(ROOTFS) + else + IROOTFS := $(ROOTDIR)$(ROOTFS_INITRD_SUFFIX) + endif endif ifeq ($(FS_TYPE),hd) -- Gitee From 210006040496756ae7311b32e4db5e670ce0c920 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 12:57:47 +0800 Subject: [PATCH 17/89] nolibc: remove root-rd dependency for NOLIBC Signed-off-by: Zhangjin Wu --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 7b827cb..ccbcd89 100644 --- a/Makefile +++ b/Makefile @@ -4319,7 +4319,10 @@ ifneq ($(BOOT_PREPARE),) _BOOT_DEPS += $(BOOT_PREPARE) endif _BOOT_DEPS += $(BOARD_SAVE) +# NOLIBC initramfs must be prepared before building kernel image +ifneq ($(NOLIBC),1) _BOOT_DEPS += root-$(DEV_TYPE) +endif _BOOT_DEPS += $(UBOOT_IMGS) _BOOT_DEPS += $(DEBUG_CLIENT) _BOOT_DEPS += $(BOOT_DTB) -- Gitee From 68a7eb59f74a4432535cb7b5b4267a4c81256f60 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 12:58:12 +0800 Subject: [PATCH 18/89] nolibc: Clean up targets Signed-off-by: Zhangjin Wu --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ccbcd89..c530708 100644 --- a/Makefile +++ b/Makefile @@ -2440,16 +2440,20 @@ root-nolibc-clean: $(Q)rm -rf $(NOLIBC_PGC) $(Q)rm -rf $(NOLIBC_INITRAMFS) +root-nolibc-rebuild: root-nolibc-clean root-nolibc + nolibc: root-nolibc nolibc-distclean: root-nolibc-distclean nolibc-clean: root-nolibc-clean +nolibc-rebuild: root-nolibc-rebuild -root: root-nolibc -root-rebuild: root-nolibc-clean root-nolibc -root-clean: root-nolibc-clean -root-distclean: root-nolibc-distclean +root root-rd: root-nolibc +root-clean root-rd-clean: root-nolibc-clean +root-distclean root-rd-distclean: root-nolibc-distclean +root-rebuild root-rd-rebuild: root-nolibc-rebuild -PHONY += root-nolibc root-nolibc-clean nolibc nolibc-clean nolibc-distclean root root-rebuild root-clean root-distclean +NOLIBC_TARGETS := root-nolibc nolibc root root-rd +PHONY += $(NOLIBC_TARGETS) $(foreach x,clean distclean rebuild,$(addsuffix -$x,$(NOLIBC_TARGETS))) # Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL -- Gitee From 815e7f34877709d26494a4749955395e0bd6991d Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 13:03:13 +0800 Subject: [PATCH 19/89] bsp: Clean up bsp branch setting Signed-off-by: Zhangjin Wu --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c530708..722f234 100644 --- a/Makefile +++ b/Makefile @@ -2108,7 +2108,9 @@ ifeq ($(wildcard $(BSP_SRC)/.git),) BSP ?= FETCH_HEAD else # Already fetched - BSP ?= $(if $(wildcard $(BSP_SRC)/.git/refs/remotes/origin/master),origin/master,FETCH_HEAD) + BSP_MASTER := $(BSP_SRC)/.git/refs/remotes/origin/master + BSP_HEAD := $(if $(wildcard $(BSP_SRC)/.git/HEAD),HEAD,FETCH_HEAD) + BSP ?= $(if $(wildcard $(BSP_MASTER)),origin/master,$(BSP_HEAD)) endif _BSP ?= $(BSP) -- Gitee From a75de15b2020e7c71b6894cbd9e5c58417db2589 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 13:07:01 +0800 Subject: [PATCH 20/89] nolibc: disable root-rd for ROOTDEV=/dev/null Not only NOLIBC requires this, ROOTDEV=/dev/null requires it too. Signed-off-by: Zhangjin Wu --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 722f234..1003a2d 100644 --- a/Makefile +++ b/Makefile @@ -4325,8 +4325,8 @@ ifneq ($(BOOT_PREPARE),) _BOOT_DEPS += $(BOOT_PREPARE) endif _BOOT_DEPS += $(BOARD_SAVE) -# NOLIBC initramfs must be prepared before building kernel image -ifneq ($(NOLIBC),1) +# kernel builtin initramfs must be prepared before building kernel image +ifneq ($(ROOTDEV),/dev/null) _BOOT_DEPS += root-$(DEV_TYPE) endif _BOOT_DEPS += $(UBOOT_IMGS) -- Gitee From d5ff90e32cb8975bdaca47668f49c83267e4cc5f Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 13:15:11 +0800 Subject: [PATCH 21/89] nolibc: Fix up NOLIBC setting for feature=nolibc Signed-off-by: Zhangjin Wu --- Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 1003a2d..b6e8b3c 100644 --- a/Makefile +++ b/Makefile @@ -1194,6 +1194,17 @@ ROOTDEV_TYPE_TOOL := tools/root/rootdev_type.sh PBR ?= 0 _PBR := $(PBR) +ifneq ($(findstring nolibc,$(FEATURE)),) + ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) + export nolibc=1 + PREPARE += root-rebuild + # If no nolibc_src manual setting, use nolibc-test by default + ifneq ($(origin nolibc_src),command line) + export nolibc_src=test + endif + endif +endif + ifeq ($(NOLIBC),1) # Allow build and embed minimal initramfs with nolibc from tools/include/nolibc to kernel image NOLIBC_DIR := $(KERNEL_ABS_SRC)/tools/include/nolibc @@ -1213,17 +1224,6 @@ NOLIBC_SYSROOT_ARCH := $(NOLIBC_SYSROOT)/$(ARCH) NOLIBC_INITRAMFS := $(KERNEL_BUILD)/nolibc/initramfs NOLIBC_FILES := $(wildcard $(NOLIBC_DIR)/*.h) -ifneq ($(findstring nolibc,$(FEATURE)),) - ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) - export nolibc=1 - PREPARE += root-rebuild - # If no nolibc_src manual setting, use nolibc-test by default - ifneq ($(origin nolibc_src),command line) - export nolibc_src=test - endif - endif -endif - ifeq ($(nolibc_src),test) override nolibc_src := $(nolibc-test) endif -- Gitee From 44fc3137aa961038157e8e5010b968c4a1d80047 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 14:52:36 +0800 Subject: [PATCH 22/89] boot: Fix up -append option broken by 1574717cd83a Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b6e8b3c..dc644f6 100644 --- a/Makefile +++ b/Makefile @@ -4113,7 +4113,7 @@ endif CMDLINE := $(subst $space$space,$space,$(strip $(CMDLINE))) ifneq ($(U),1) - BOOT_CMD += $(if $(findstring -kernel,$(CMDLINE)),-append "$(CMDLINE)") + BOOT_CMD += $(if $(findstring -kernel,$(BOOT_CMD)),-append "$(CMDLINE)") endif ifneq ($(TEST_REBOOT), 0) -- Gitee From 137797ff02b4e6c35f449a0f89735dac588eca89 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 16:15:30 +0800 Subject: [PATCH 23/89] nolibc: rv32: Fix up wordsize.h Use a latest wordsize.h from https://gitee.com/mirrors/glibc_source/blob/master/sysdeps/riscv/bits/wordsize.h Signed-off-by: Zhangjin Wu --- Makefile | 4 ++++ tools/nolibc/wordsize.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tools/nolibc/wordsize.h diff --git a/Makefile b/Makefile index dc644f6..0e95c1c 100644 --- a/Makefile +++ b/Makefile @@ -2482,6 +2482,10 @@ ifeq ($(XARCH),riscv32) # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS NOLIBC_LDFLAGS += -melf32lriscv_ilp32 + BITS_WORDSIZE_H := /usr/riscv64-linux-gnu/include/bits/wordsize.h + +$(NOLIBC_SRC): FORCE + $(Q)[ -f $(BITS_WORDSIZE_H) ] && grep -q rv32i $(BITS_WORDSIZE_H) && sudo cp tools/nolibc/wordsize.h $(BITS_WORDSIZE_H) endif # nolibc gc sections and debug support diff --git a/tools/nolibc/wordsize.h b/tools/nolibc/wordsize.h new file mode 100644 index 0000000..43d1893 --- /dev/null +++ b/tools/nolibc/wordsize.h @@ -0,0 +1,30 @@ +/* Determine the wordsize from the preprocessor defines. RISC-V version. + Copyright (C) 2002-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#if __riscv_xlen == (__SIZEOF_POINTER__ * 8) +# define __WORDSIZE __riscv_xlen +#else +# error unsupported ABI +#endif + +# define __WORDSIZE_TIME64_COMPAT32 1 + +#if __WORDSIZE == 32 +# define __WORDSIZE32_SIZE_ULONG 0 +# define __WORDSIZE32_PTRDIFF_LONG 0 +#endif -- Gitee From fe50a32d0056b570e1f99ae6c36966443672253a Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 16:17:07 +0800 Subject: [PATCH 24/89] nolibc: enable root targets for nolibc targets Signed-off-by: Zhangjin Wu --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 0e95c1c..ffde667 100644 --- a/Makefile +++ b/Makefile @@ -2426,6 +2426,9 @@ endif # toolchain targets ifneq ($(findstring root,$(MAKECMDGOALS)),) root_targets ?= 1 endif +ifneq ($(findstring nolibc,$(MAKECMDGOALS)),) + root_targets ?= 1 +endif ifeq ($(root_targets),1) ifeq ($(NOLIBC),1) -- Gitee From 1683991800ac8992cf926905c5414b87a8b55f50 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 16:21:11 +0800 Subject: [PATCH 25/89] nolibc: Fix up NOLIBC_SRC setting Signed-off-by: Zhangjin Wu --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ffde667..c26a8cb 100644 --- a/Makefile +++ b/Makefile @@ -1213,7 +1213,6 @@ NOLIBC_H := $(NOLIBC_DIR)/nolibc.h nolibc-hello ?= $(TOP_DIR)/src/examples/nolibc/hello.c nolibc-test ?= $(KERNEL_ABS_SRC)/tools/testing/selftests/nolibc/nolibc-test.c nolibc_src ?= $(nolibc-hello) -NOLIBC_SRC ?= $(nolibc_src) NOLIBC_BIN := $(KERNEL_BUILD)/nolibc/init NOLIBC_OBJ := $(KERNEL_BUILD)/nolibc/init.o NOLIBC_FLT := $(KERNEL_BUILD)/nolibc/init.flt @@ -1230,6 +1229,8 @@ endif ifeq ($(nolibc_src),hello) override nolibc_src := $(nolibc-hello) endif +NOLIBC_SRC ?= $(nolibc_src) + ifneq ($(nolibc_test),) XKCLI += "NOLIBC_TEST=$(nolibc_test)" endif -- Gitee From 385d41f43a11d014a40f3f14502961ebbdd218e8 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 20 May 2023 16:22:49 +0800 Subject: [PATCH 26/89] nolibc: Fix up for the latest wordsize.h Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c26a8cb..3ddf933 100644 --- a/Makefile +++ b/Makefile @@ -2489,7 +2489,7 @@ ifeq ($(XARCH),riscv32) BITS_WORDSIZE_H := /usr/riscv64-linux-gnu/include/bits/wordsize.h $(NOLIBC_SRC): FORCE - $(Q)[ -f $(BITS_WORDSIZE_H) ] && grep -q rv32i $(BITS_WORDSIZE_H) && sudo cp tools/nolibc/wordsize.h $(BITS_WORDSIZE_H) + $(Q)[ -f $(BITS_WORDSIZE_H) ] && grep -q 'rv32i-based targets are not supported' $(BITS_WORDSIZE_H) && sudo cp tools/nolibc/wordsize.h $(BITS_WORDSIZE_H) || true endif # nolibc gc sections and debug support -- Gitee From 83a530dadb11c17f913ccafb37f2018f91d965b0 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 21 May 2023 01:41:52 +0800 Subject: [PATCH 27/89] nolibc: add stackprotector testing support Signed-off-by: Zhangjin Wu --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 3ddf933..6d0c9ec 100644 --- a/Makefile +++ b/Makefile @@ -2465,6 +2465,10 @@ PHONY += $(NOLIBC_TARGETS) $(foreach x,clean distclean rebuild,$(addsuffix -$x,$ NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL NOLIBC_LDFLAGS := -s +ifeq ($(nolibc_stkp),1) + NOLIBC_CFLAGS += -DNOLIBC_STACKPROTECTOR -fstack-protector-all +endif + ifneq ($(findstring .sx,$(NOLIBC_SRC)x),) NOLIBC_CFLAGS += -fno-pic endif -- Gitee From db973dae6adf055629dff2591b7be70a7410459c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 21 May 2023 14:40:53 +0800 Subject: [PATCH 28/89] phony: add missing phony targets This allows to run a target with -t like this: $ make kernel-checkout -t Without this change, it will create the file named with such targets. Signed-off-by: Zhangjin Wu --- Makefile | 78 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 6d0c9ec..0d49306 100644 --- a/Makefile +++ b/Makefile @@ -1440,7 +1440,7 @@ board-clean: board-cleanstamp board-save: $(Q)echo "$(BOARD)" > .board_config -PHONY += board board-init board-clean board-save board-cleanstamp +PHONY += board $(addprefix board-,init show save clean cleanstamp) board-edit: $(Q)vim $(BOARD_MAKEFILE) @@ -1469,7 +1469,7 @@ default-config: local-config local-config: $(BOARD_GOAL) $(Q)$(foreach vs, $(MAKEOVERRIDES), tools/board/config.sh $(vs) $(BOARD_LABCONFIG) $(LINUX);) -PHONY += board-config board-edit +PHONY += config edit default-config $(addprefix board-,config edit) $(addprefix local-,config edit) # Plugin targets @@ -1498,7 +1498,7 @@ plugin-list: plugin-list-full: $(Q)find $(BOARDS_DIR) -maxdepth 3 -name ".plugin" | xargs -i dirname {} | cat -n -PHONY += plugin-save plugin-clean plugin plugin-list plugin-list-full +PHONY += plugin $(addprefix plugin-,save clean list list-full) ifneq ($(findstring xlist,x$(first_target)),) # all: 0, plugin: 1, noplugin: 2 @@ -1583,8 +1583,10 @@ define gendeps $1-patch: $1-checkout $1-defconfig: $1-patch $1-defconfig: $1-env +ifeq ($1,kernel) $1-modules-install: $1-modules $1-modules-install-km: $1-modules-km +endif $1-help: $1-defconfig $1_defconfig_childs := $(addprefix $1-,config getconfig saveconfig menuconfig oldconfig oldnoconfig olddefconfig build buildroot modules modules-km do) @@ -1652,7 +1654,7 @@ $1-release: $1 $1-save $1-saveconfig $1-new $1-clone: $1-cloneconfig $1-clonepatch -PHONY += $(addprefix $1-,save saveconfig savepatch build release new clone) +PHONY += _$1 $(addprefix $1-,save saveall saveconfig savepatch build release new clone) endef # gendeps @@ -1832,7 +1834,7 @@ $1_source_childs := $1-download download-$1 $$($1_source_childs): $1-source -PHONY += $(addprefix $1-,source download license) download-$1 +PHONY += $(addprefix $1-,license source checkout outdir download) download-$1 $1-%-cleanstamp: $$(Q)rm -vf $$(call _stamp,$1,$$(subst $1-,,$$(subst -cleanstamp,,$$@))) @@ -1861,7 +1863,7 @@ $1-distclean: rm -rvf $$($(call _uc,$1)_BUILD); \ fi -PHONY += $(addprefix $1-,cleanstamp cleanup cleansrc cleanall outdir clean distclean) +PHONY += $(addprefix $1-,cleanstamp cleanup cleansrc clean cleanall rawclean distclean) endef # gensource @@ -1921,7 +1923,7 @@ $1-test: _test $1-test-debug: $$(Q)make _test DEBUG=$1 -PHONY += $(addprefix $1-,list help checkout patch debug boot test) +PHONY += $(addprefix $1-,list help verify patch savepatch debug boot test test-debug) debug-$1 endef # gengoals @@ -2002,7 +2004,7 @@ $$(call _stamp,$1,oldconfig): $$($1_config) $1-menuconfig: $$($1_config) $$(call make_$1,menuconfig $$($(call _uc,$1)_CONFIG_EXTRAFLAG)) -PHONY += $(addprefix $1-,defconfig olddefconfig oldconfig menuconfig) +PHONY += $(addprefix $1-,defconfig olddefconfig oldefconfig oldconfig menuconfig) endef # gencfgs @@ -2091,7 +2093,7 @@ $$(call _stamp,$1,env): $1-deps $1-gcc $1-hostgcc $1-env: $$(call __stamp,$1,env) -PHONY += $1-env +PHONY += $(addprefix $1-,tools deps gcc hostgcc env) endef #genenvdeps @@ -2302,6 +2304,8 @@ _qemu: _qemu_update_submodules ln -sf /etc/qemu-ifdown $(QEMU_BUILD)/qemu-bundle$(PREBUILT_QEMU_DIR)/etc/qemu-ifdown; \ fi +PHONY += _qemu _qemu_update_submodules + endif # Qemu targets # Toolchains targets @@ -2364,7 +2368,7 @@ toolchain-list: gcc-list: toolchain-list -PHONY += toolchain-list gcc-list +PHONY += toolchain-list gcc-list toolchain toolchain-info: @echo @@ -2643,7 +2647,7 @@ root-rd-rebuild: root-dir root-rd-clean $(IROOTFS) FORCE root-rd-clean: $(Q)[ "$(IROOTFS)" != "$(PREBUILT_IROOTFS)" ] && rm -vf $(IROOTFS) || true -PHONY += root-rd root-rd-rebuild root-rd-clean +PHONY += root-rd $(addprefix root-rd-,rebuild clean) ROOT_GENDISK_TOOL := $(TOOL_DIR)/root/dir2$(DEV_TYPE).sh @@ -2686,6 +2690,8 @@ root-rebuild-buildroot: $(Q)chown -R $(USER):$(USER) $(BUILDROOT_ROOTDIR) $(Q)[ $(build_root_uboot) -eq 1 ] && make $(S) $(BUILDROOT_UROOTFS) || true +HONY += root-rebuild $(addprefix root-rebuild-,prebuilt buildroot) + ROOT ?= $(ROOTDIR) ifeq ($(_PBR), 0) ifeq ($(wildcard $(BUILDROOT_IROOTFS)),) @@ -2724,7 +2730,7 @@ endif root-dir rootdir: $(ROOTDIR) root-dir-rebuild rootdir-rebuild: root-dir-clean $(ROOTDIR) FORCE -PHONY += root-dir rootdir root-dir-rebuild rootdir-rebuild +PHONY += root-dir rootdir $(addsuffix -rebuild,root-dir rootdir) # Install src/system @@ -2742,6 +2748,8 @@ root-dir-install-system: src/system root-dir-install-modules: $(KERNEL_BUILD) $(Q)echo "LOG: Install modules" && make $(S) module-install || true +PHONE += root-dir-install $(addprefix root-dir-install-,system modules) + $(ROOTDIR): $(ROOTDIR_GOAL) root-dir-install root-dir-prebuilt: bsp-outdir $(ROOTDIR_DEPS) @@ -2760,11 +2768,13 @@ root-dir-clean rootdir-clean: root-dir-distclean rootdir-distclean: rootdir-clean -PHONY += root-dir-distclean rootdir-distclean root-dir-clean rootdir-clean +PHONY += $(addprefix root-dir-,prebuilt buildroot clean distclean) $(addprefix rootdir-,clean distclean) fullclean: $(call gengoalslist,distclean) $(Q)git clean -fdx +PHONY += fullclean + ifeq ($(FS_TYPE),dir) HROOTFS_DEPS := $(ROOTDIR) endif @@ -2789,7 +2799,7 @@ root-hd-rebuild: root-hd-clean $(HROOTFS) FORCE root-hd-clean: -$(Q)rm -vf $(HROOTFS) -PHONY += root-hd root-hd-rebuild root-hd-clean +PHONY += root-hd $(addprefix root-hd-,rebuild clean) endif # !NOLIBC endif # Root targets @@ -2812,6 +2822,8 @@ KERNEL_CLEAN_DEPS := kernel-modules-clean kernel-oldnoconfig: kernel-olddefconfig +PHONY += kernel-oldnoconfig + # kernel features support KERNEL_FEATURE_ENV_TOOL := tools/kernel/feature-env.sh KERNEL_FEATURE_DOWNLOAD_TOOL := tools/kernel/feature-download.sh @@ -2873,14 +2885,15 @@ kernel-features-list: kernel-feature-list features-list: kernel-feature-list feature-list: kernel-feature-list -PHONY += kernel-feature feature features kernel-features kernel-feature-list kernel-features-list features-list +FEATURES_TARGETS := feature features kernel-feature kernel-features +PHONY += $(addsuffix -list,$(FEATURES_TARGETS)) $(FEATURES_TARGETS) kernel-feature-cleanstamp kernel-feature-test: kernel-test kernel-features-test: kernel-feature-test features-test: kernel-feature-test feature-test: kernel-feature-test -PHONY += kernel-feature-test kernel-features-test features-test feature-test +PHONY += $(addsuffix -test,$(FEATURES_TARGETS)) #$(warning $(call gensource,kernel,LINUX)) $(eval $(call gensource,kernel,LINUX)) @@ -3040,7 +3053,7 @@ KERNEL_MODULES_DEPS := modules-prompt kernel-modules-save export KM endif -PHONY += modules-prompt kernel-modules-save +PHONY += modules-prompt $(addprefix kernel-modules-,save) # Both internal and external modules require modules_prepare (prepare and scripts, such as scripts/mod/modpost) MODULE_PREPARE := modules_prepare @@ -3054,6 +3067,8 @@ kernel-modules-config: $(DEFAULT_KCONFIG) kernel-modules-defconfig: $(DEFAULT_KCONFIG) $(Q)make -s $(NPD) kernel-olddefconfig +PHONY += $(addprefix kernel-modules-,config defconfig) + kernel-modules-km: kernel-modules-config $(if $(m),kernel-config) kernel-modules-defconfig $(KERNEL_MODULES_DEPS) @# M variable can not be set for modules_prepare target $(call make_kernel,$(MODULE_PREPARE) M=) @@ -3089,7 +3104,7 @@ kernel-modules-list-full: $(Q)find $(EXT_MODULE_DIR) -name "Makefile" | $(PF) | xargs -i grep -E -iH "^obj-m[[:space:]]*[+:]*=[[:space:]]*.*($(IMF)).*\.o" {} | sed -e "s%$(PWD)\(.*\)/Makefile:obj-m[[:space:]]*[+:]*=[[:space:]]*\(.*\).o%m=\2 ; M=$$PWD/\1%g" | tr -s '/' | cat -n $(Q)[ "$(internal_search)" = "1" ] && find $(KERNEL_SEARCH_PATH) -name "Makefile" | $(PF) | xargs -i grep -E -iH "^obj-.*_($(IMF))(\)|_).*[[:space:]]*[+:]*=[[:space:]]*($(IMF)).*\.o" {} | sed -e "s%$(KERNEL_MODULE_DIR)/\(.*\)/Makefile:obj-\$$(CONFIG_\(.*\))[[:space:]]*[+:]*=[[:space:]]*\(.*\)\.o%c=\2 ; m=\3 ; M=\1%g" | tr -s '/' | cat -n || true -PHONY += kernel-modules-km kernel-modules kernel-modules-list kernel-modules-list-full +PHONY += kernel-modules $(addprefix kernel-modules-,km list list-full) # From linux-stable/scripts/depmod.sh, v5.1 SCRIPTS_DEPMOD := $(TOP_DIR)/tools/kernel/depmod.sh @@ -3131,7 +3146,7 @@ kernel-modules-clean-km: kernel-modules-clean: $(Q)$(KERNEL_MODULE_CLEAN) $(KERNEL_BUILD) -PHONY += kernel-modules-install-km kernel-modules-install kernel-modules-clean +PHONY += $(addprefix kernel-modules-,install install-km clean clean-km) _module: kernel-modules-km plugin-save module-list: kernel-modules-list plugin-save @@ -3145,7 +3160,7 @@ modules-list-full: module-list-full module-test: kernel-test modules-test: module-test -PHONY += _module module-list module-list-full _module-install _module-clean modules-list modules-list-full +PHONY += _module $(addprefix _module-,install clean) $(addprefix module-,list list-full) $(addprefix modules-,list list-full) kernel-module: module module: FORCE @@ -3168,8 +3183,6 @@ module-clean: FORCE $(Q)$(if $(M), $(foreach _M, $(subst $(comma),$(space),$(M)), \ echo "\nCleaning module: $(_M) ...\n" && make $(NPD) _module-clean M=$(_M);) echo '') -PHONY += kernel-module kernel-module-install kernel-module-clean module-install module-clean - # If no M, m/module/modules, M_PATH specified, compile internel modules by default ifneq ($(firstword $(MAKECMDGOALS)),list) @@ -3185,7 +3198,8 @@ endif endif # skip modules target for list command -PHONY += modules modules-install modules-clean module module-install module-clean +MODULE_TARGETS := kernel-module module modules +PHONY += $(MODULE_TARGETS) $(addsuffix -clean,$(MODULE_TARGETS)) $(addsuffix -install,$(MODULE_TARGETS)) endif # module targets @@ -3367,7 +3381,7 @@ _kernel-setconfig: $(DEFAULT_KCONFIG) $(Q)grep -E -iH "_$(KCONFIG_OPT)(_|=| )" $(DEFAULT_KCONFIG) | sed -e "s%$(TOP_DIR)/%%g" $(Q)echo -PHONY += kernel-getconfig kernel-config kernel-setconfig _kernel-getconfig _kernel-setconfig +PHONY += $(addprefix kernel-,config getconfig setconfig) $(addprefix _kernel-,getconfig setconfig) module-config: module-setconfig modules-config: module-setconfig @@ -3375,7 +3389,7 @@ modules-config: module-setconfig module-getconfig: kernel-getconfig module-setconfig: kernel-setconfig -PHONY += module-getconfig module-setconfig modules-config module-config +PHONY += $(addprefix module-,config getconfig setconfig) modules-config _kernel: $(KERNEL_DEPS) $(call make_kernel,$(KT)) @@ -3495,7 +3509,7 @@ root-ud-rebuild: root-ud-clean $(UROOTFS) FORCE root-ud-clean: $(Q)rm -vf $(UROOTFS) || true -PHONY += root-ud root-ud-rebuild root-ud-clean +PHONY += root-ud $(addprefix root-ud-,rebuild clean) # aarch64 and riscv don't add uboot header for kernel image ifneq ($(UKIMAGE), $(KIMAGE)) @@ -3569,7 +3583,7 @@ uboot-images-distclean: uboot-images-clean UBOOT_IMGS := uboot-images UBOOT_IMGS_DISTCLEAN := uboot-images-distclean -PHONY += _uboot-images uboot-images uboot-images-clean uboot-images-distclean +PHONY += _uboot-images uboot-images $(addprefix uboot-images-,clean distclean) endif # Uboot specific part endif # Uboot targets @@ -3647,6 +3661,8 @@ endif getip: $(Q)if [ -z "$(BOARD_IP)" ]; then echo "$(GETIP_TOOL) timeout, $(BOARD_SERIAL) may be connected by another client." && exit 1; fi +PHONY += getip + # Upload images to remote board ifneq ($(findstring upload,$(MAKECMDGOALS)),) @@ -4421,7 +4437,7 @@ env-save: board-config default-help: $(Q)less README_zh.md -PHONY += env env-list env-prepare env-dump env-save lab-help +PHONY += _env env $(addprefix env-,list prepare dump save) default-help tools-install # memory building support BUILD_CACHE_TOOL := tools/build/cache @@ -4464,7 +4480,7 @@ backup-build: @echo "Backing up Cache ..."; echo; \ sudo $(BUILD_BACKUP_TOOL) || true -PHONY += cache-build uncache-build backup-build +PHONY += $(addsuffix -build,cache status uncache backup) # include $(TOP_DIR)/.labend if exist $(eval $(call _ti,labend)) @@ -4516,8 +4532,8 @@ force-%: $(Q)make $(NPD) $(subst force-,,$@)-cleanstamp $(Q)make $(NPD) $(subst force-,,$@) -PHONY += FORCE - FORCE: +PHONY += FORCE + .PHONY: $(PHONY) -- Gitee From d9266d3aae205d745a89e7c9e24cdb0da87f6987 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 22 May 2023 00:51:04 +0800 Subject: [PATCH 29/89] cleanup: tell users the way to avoid cleanup touch a xxx-checkout target can avoid clean up. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0d49306..ca83ba5 100644 --- a/Makefile +++ b/Makefile @@ -1819,7 +1819,7 @@ $$(call _stamp,$1,checkout): $$(ENV_FILES) && git checkout --progress $$(GIT_CHECKOUT_FORCE) $$(_$2) \ && touch $$@ \ || (echo "ERR: Failed to checkout $$(_$2) of $1 in $$($(call _uc,$1)_SRC_FULL)" \ - && echo "ERR: Please backup important changes on demand and run 'make $1-cleanup'." \ + && echo "ERR: Please backup important changes on demand and run 'make $1-cleanup' or simply do a 'make $1-checkout -t'." \ && exit 1) $1-checkout: $$(call __stamp,$1,checkout) -- Gitee From bc9b5cbd9c87f76e743758b92621a8fdd80704d8 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 22 May 2023 15:01:40 +0800 Subject: [PATCH 30/89] nolibc: -mstack-protector-guard=global is required to stkp old riscv compiler not support -mstack-protector-guard=global, so, no stackprotector feature currently. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca83ba5..f0e184e 100644 --- a/Makefile +++ b/Makefile @@ -2470,7 +2470,7 @@ NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCAL NOLIBC_LDFLAGS := -s ifeq ($(nolibc_stkp),1) - NOLIBC_CFLAGS += -DNOLIBC_STACKPROTECTOR -fstack-protector-all + NOLIBC_CFLAGS += -DNOLIBC_STACKPROTECTOR -mstack-protector-guard=global -fstack-protector-all endif ifneq ($(findstring .sx,$(NOLIBC_SRC)x),) -- Gitee From 2d6a5e868b1236af7f8a0fdab19af76c9363068c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Wed, 24 May 2023 01:11:34 +0800 Subject: [PATCH 31/89] nolibc: clean up the riscv32 support riscv32 support for nolibc is ready for upstream, no -D__ARCH_WANT_TIME32_SYSCALLS required. Signed-off-by: Zhangjin Wu --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f0e184e..93d858e 100644 --- a/Makefile +++ b/Makefile @@ -2487,12 +2487,8 @@ else endif ifeq ($(XARCH),riscv32) - # ref: https://lore.kernel.org/linux-riscv/cover.1684425792.git.falcon@tinylab.org/T/#t - # FIXME: need to use lw/sw instead of ld/sd in tools/include/nolibc/arch-riscv.h + # rv32 support patch is ready for both tools/nolibc and selftests/nolibc, see https://lore.kernel.org/linux-riscv/ NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 - # Linux commit d4c08b9776b3 ("riscv: Use latest system call ABI") removed all of the time32 syscalls - # FIXME: "Cheat" unistd.h to compile without such syscalls, but we can not really use such syscalls - NOLIBC_CFLAGS += -D__ARCH_WANT_TIME32_SYSCALLS NOLIBC_LDFLAGS += -melf32lriscv_ilp32 BITS_WORDSIZE_H := /usr/riscv64-linux-gnu/include/bits/wordsize.h -- Gitee From 820669b9ee83e448ff176e0ec141a4b3b1ca13ae Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 25 May 2023 03:22:25 +0800 Subject: [PATCH 32/89] test: Fix up test log file prompt info Users may want to copy the test.log path, remove the . suffix to avoid copy it. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 93d858e..24749ef 100644 --- a/Makefile +++ b/Makefile @@ -4181,7 +4181,7 @@ endif && $(TEST_LOG_READER) $(TEST_LOG_PIPE) $(TEST_LOG) $(TEST_LOG_PID) 2>&1 \ && sleep 1 && sudo timeout $(TEST_TIMEOUT) TEST_AFTER ?= ; echo $$? > $(TEST_RET); sudo kill -9 $$(cat $(TEST_LOG_PID)); [ $(TIMEOUT_CONTINUE) -eq 1 ] && echo 0 > $(TEST_RET); \ - ret=$$(cat $(TEST_RET)) && [ $$ret -ne 0 ] && echo "ERR: Boot timeout in $(TEST_TIMEOUT)." && echo "ERR: Log saved in $(TEST_LOG)." && exit $$ret; \ + ret=$$(cat $(TEST_RET)) && [ $$ret -ne 0 ] && echo "ERR: Boot timeout in $(TEST_TIMEOUT)." && echo "ERR: Log saved in $(TEST_LOG)" && exit $$ret; \ if [ $(TIMEOUT_CONTINUE) -eq 1 ]; then echo "LOG: Test continue after timeout kill in $(TEST_TIMEOUT)."; else echo "LOG: Boot run successfully."; fi; \ if [ $(TIMEOUT_CONTINUE) -eq 1 ]; then sleep 2; rm -rf $(TEST_LOG_PIPE).in $(TEST_LOG_PIPE).out; fi # If not support netowrk, should use the other root device -- Gitee From d97de35e4c89c179e14d10ad014f14c7895396d8 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 26 May 2023 10:12:32 +0800 Subject: [PATCH 33/89] checkout: show previous HEAD and allow skip it This is important for debug and avoid non necessary switch for the same kernel source code. Signed-off-by: Zhangjin Wu --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 24749ef..18dfe26 100644 --- a/Makefile +++ b/Makefile @@ -1813,14 +1813,19 @@ $1-source: $$(call __stamp,$1,source) $1-checkout: $1-source $$(call _stamp,$1,checkout): $$(ENV_FILES) - $$(Q)[ -d $$($(call _uc,$1)_SRC_FULL) -a -e $$($(call _uc,$1)_SRC_FULL)/.git ] \ + $$(Q)if [ -z "$(SKIP_CHECKOUT)" ]; then \ + [ -d $$($(call _uc,$1)_SRC_FULL) -a -e $$($(call _uc,$1)_SRC_FULL)/.git ] \ && cd $$($(call _uc,$1)_SRC_FULL) \ + && git cat-file -e HEAD 2>/dev/null && git log -1 --oneline HEAD 2>/dev/null || true \ && echo "Checking out $$(_$2) ..." \ && git checkout --progress $$(GIT_CHECKOUT_FORCE) $$(_$2) \ && touch $$@ \ || (echo "ERR: Failed to checkout $$(_$2) of $1 in $$($(call _uc,$1)_SRC_FULL)" \ && echo "ERR: Please backup important changes on demand and run 'make $1-cleanup' or simply do a 'make $1-checkout -t'." \ - && exit 1) + && exit 1); \ + else \ + touch $$@; \ + fi $1-checkout: $$(call __stamp,$1,checkout) -- Gitee From 8533770d6051e4def31629b4fcfb31c1881d8f4e Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 26 May 2023 10:37:50 +0800 Subject: [PATCH 34/89] defconfig: unique the defconfig to avoid wrong dep different machine may have the same defconfig file name, but for makefile, they should be unique, unique them with the machine info to avoid such issue, otherwise, a new 'b' specified board may use another defconfig to build a wrong target image. Signed-off-by: Zhangjin Wu --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 18dfe26..e89f831 100644 --- a/Makefile +++ b/Makefile @@ -1969,7 +1969,8 @@ else endif endif -_$3CFG := $$(notdir $$($3CFG_FILE)) +# different boards should not use the same name of defconfig, add $(XARCH)_$(MACH) as the prefix +_$3CFG := $(XARCH)_$(MACH)_$$(notdir $$($3CFG_FILE)) ifneq ($$($3CFG_BUILTIN),) $$($3CFG_FILE)): $$(call __stamp,$1,source) @@ -1977,7 +1978,7 @@ endif $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG): $$(if $$($3CFG_BUILTIN),,$$($3CFG_FILE)) $$(ENV_FILES) $$(if $$(FORCE_DEFCONFIG),FORCE) $$(Q)$$(if $$($(call _uc,$1)_CONFIG_DIR),mkdir -p $$($(call _uc,$1)_CONFIG_DIR)) - $$(Q)$$(if $$($3CFG_BUILTIN),,cp $$($3CFG_FILE) $$($(call _uc,$1)_CONFIG_DIR)) + $$(Q)$$(if $$($3CFG_BUILTIN),,cp $$($3CFG_FILE) $$($(call _uc,$1)_CONFIG_DIR))/$$(_$3CFG) $$(Q)$$(if $$(CFGS[$3_N]),$$(foreach n,$$(CFGS[$3_N]),$$(SCRIPTS_$3CONFIG) --file $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG) -d $$n;)) $$(Q)$$(if $$(CFGS[$3_Y]),$$(foreach y,$$(CFGS[$3_Y]),$$(SCRIPTS_$3CONFIG) --file $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG) -e $$y;)) -- Gitee From 813285bfc9d6ab9259e8fb2ebd63a5b4279e8bf6 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 26 May 2023 10:58:47 +0800 Subject: [PATCH 35/89] boot-test: make sure test use the same board from command line Without this setting, boot-test may use the board setting in .board_config, but we prefer the one from command line. Signed-off-by: Zhangjin Wu --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e89f831..805a989 100644 --- a/Makefile +++ b/Makefile @@ -4205,11 +4205,11 @@ export BOARD TEST_TIMEOUT TEST_LOGGING TEST_LOG TEST_LOG_PIPE TEST_LOG_PID TEST_ boot-test: bsp-checkout $(Q)echo "Running $@" ; \ if [ "$(BOOT_TEST)" = "default" ]; then \ - $(TEST_BEFORE) make $(NPD) _boot U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ + $(TEST_BEFORE) make $(NPD) _boot board=$(BOARD) U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ else \ for r in $$(seq 0 $(TEST_REBOOT)); do \ echo "\nRebooting test: $$r\n"; \ - $(TEST_BEFORE) make $(NPD) _boot U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ + $(TEST_BEFORE) make $(NPD) _boot board=$(BOARD) U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ done ; \ fi -- Gitee From 26fc68d2e552216d7f3cea144cabf07201feceab Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 26 May 2023 11:18:32 +0800 Subject: [PATCH 36/89] Add a pure kernel develop mode kernel developer can enable this DEVMODE and let Linux Lab not do automatically checkout, this is important to let kernel developer work on kernel source code more freely. to use it, simply export DEVMODE=1 to set it on any targets: $ make kernel DEVMODE=1 Signed-off-by: Zhangjin Wu --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 805a989..52735c0 100644 --- a/Makefile +++ b/Makefile @@ -468,6 +468,12 @@ ifeq ($(CACHE_BUILD)$(CACHE_SRC)$(FAST_FETCH),111) TOP_SRC := $(TOP_BUILD)/src endif +# Don't touch the kernel code, let kernel developer do himself +ifeq ($(DEVMODE),1) + SKIP_VERIFY ?= 1 + SKIP_CHECKOUT ?= 1 +endif + # Allow boards to customize source and repos KERNEL_ABS_SRC := $(TOP_SRC)/$(KERNEL_SRC) ROOT_ABS_SRC := $(TOP_SRC)/$(ROOT_SRC) -- Gitee From 20388d76a10ceb4d71d37f4561cceb7bf11f5a2d Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 28 May 2023 00:52:21 +0800 Subject: [PATCH 37/89] nolibc: Fix up nolibc_test argument passing issue We can not set TEST variable before the _boot target, otherwise, some variables will be overridded before running the _boot target. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52735c0..401d755 100644 --- a/Makefile +++ b/Makefile @@ -1203,7 +1203,7 @@ _PBR := $(PBR) ifneq ($(findstring nolibc,$(FEATURE)),) ifeq ($(findstring nolibc,$(TEST)$(PREPARE)$(TEST_PREPARE)),) export nolibc=1 - PREPARE += root-rebuild + TEST_PREPARE += root-rebuild # If no nolibc_src manual setting, use nolibc-test by default ifneq ($(origin nolibc_src),command line) export nolibc_src=test -- Gitee From cd97d8a597b4a3d6e744bfd9d551f6bf40bb833f Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 28 May 2023 02:09:57 +0800 Subject: [PATCH 38/89] clean up XOPTS and XKCLI statements Signed-off-by: Zhangjin Wu --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 401d755..dc05149 100644 --- a/Makefile +++ b/Makefile @@ -1238,7 +1238,7 @@ endif NOLIBC_SRC ?= $(nolibc_src) ifneq ($(nolibc_test),) - XKCLI += "NOLIBC_TEST=$(nolibc_test)" + XKCLI += NOLIBC_TEST=$(nolibc_test) endif ifeq ($(NOMMU),1) @@ -4180,9 +4180,9 @@ ifneq ($(TEST_TIMEOUT),0) # Ref: /labs/linux-lab/logging/arm64-virt-linux-v5.1/20190520-145101/boot.log ifneq ($(findstring serial,$(XOPTS)),) - XOPTS := $(shell echo "$(XOPTS) " | sed -e "s%-serial [^ ]* %-serial mon:pipe:$(TEST_LOG_PIPE) %g") + XOPTS := $(shell echo "$(XOPTS) " | sed -e "s%-serial [^ ]* %-serial mon:pipe:$(TEST_LOG_PIPE) %g") else - XOPTS += -serial mon:pipe:$(TEST_LOG_PIPE) + XOPTS += -serial mon:pipe:$(TEST_LOG_PIPE) endif # Allow test continue if the board always hang after poweroff, please pass TIMEOUT_CONTINUE=1 -- Gitee From ceb0ae5a615f07df782cf49cc93a30e99f544154 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 28 May 2023 02:16:34 +0800 Subject: [PATCH 39/89] nolibc: reserve environment variables for timeout logic This eventually fixes up the issue that not really fixed up in: 20388d76a10 ("nolibc: Fix up nolibc_test argument passing issue") The root cause is the old timeout support use sudo to run timeout command but not pass the -E option to reserve the environment variable, then, the old environment variables will be lost when the TEST_TIMEOUT variable is specified, add -E to solve it. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dc05149..a3080cd 100644 --- a/Makefile +++ b/Makefile @@ -4191,7 +4191,7 @@ endif TEST_LOGGING ?= TEST_LOGGING=$(TOP_DIR)/logging/$(XARCH)-$(MACH)-linux-$(LINUX)/$$(date +"%Y%m%d-%H%M%S") TEST_BEFORE ?= $(TEST_LOGGING); mkdir -p $$TEST_LOGGING && sync && mkfifo $(TEST_LOG_PIPE).in && mkfifo $(TEST_LOG_PIPE).out && touch $(TEST_LOG_PID) && make env-dump > $(TEST_ENV) \ && $(TEST_LOG_READER) $(TEST_LOG_PIPE) $(TEST_LOG) $(TEST_LOG_PID) 2>&1 \ - && sleep 1 && sudo timeout $(TEST_TIMEOUT) + && sleep 1 && sudo -E timeout $(TEST_TIMEOUT) TEST_AFTER ?= ; echo $$? > $(TEST_RET); sudo kill -9 $$(cat $(TEST_LOG_PID)); [ $(TIMEOUT_CONTINUE) -eq 1 ] && echo 0 > $(TEST_RET); \ ret=$$(cat $(TEST_RET)) && [ $$ret -ne 0 ] && echo "ERR: Boot timeout in $(TEST_TIMEOUT)." && echo "ERR: Log saved in $(TEST_LOG)" && exit $$ret; \ if [ $(TIMEOUT_CONTINUE) -eq 1 ]; then echo "LOG: Test continue after timeout kill in $(TEST_TIMEOUT)."; else echo "LOG: Boot run successfully."; fi; \ -- Gitee From e38b28b99e66b074c8ef1a4046849cf8b506a598 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 28 May 2023 09:49:27 +0800 Subject: [PATCH 40/89] Revert "boot-test: make sure test use the same board from command line" This reverts commit 813285bfc9d6ab9259e8fb2ebd63a5b4279e8bf6. With the commit ("nolibc: reserve environment variables for timeout logic"), the board environment will be passed to _boot target, not need to reset it. Signed-off-by: Zhangjin Wu --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a3080cd..d2626cb 100644 --- a/Makefile +++ b/Makefile @@ -4211,11 +4211,11 @@ export BOARD TEST_TIMEOUT TEST_LOGGING TEST_LOG TEST_LOG_PIPE TEST_LOG_PID TEST_ boot-test: bsp-checkout $(Q)echo "Running $@" ; \ if [ "$(BOOT_TEST)" = "default" ]; then \ - $(TEST_BEFORE) make $(NPD) _boot board=$(BOARD) U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ + $(TEST_BEFORE) make $(NPD) _boot U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ else \ for r in $$(seq 0 $(TEST_REBOOT)); do \ echo "\nRebooting test: $$r\n"; \ - $(TEST_BEFORE) make $(NPD) _boot board=$(BOARD) U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ + $(TEST_BEFORE) make $(NPD) _boot U=$(TEST_UBOOT) XOPTS="$(TEST_XOPTS)" TEST=default ROOTDEV=$(TEST_RD) FEATURE=boot$(if $(FEATURE),$(comma)$(FEATURE)) $(TEST_AFTER); \ done ; \ fi -- Gitee From 60f1e0d077b75c28835907ddad1140ec422a9d33 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 28 May 2023 14:01:17 +0800 Subject: [PATCH 41/89] aarch64/virt: Fix up TEST_TIMEOUT support The TEST_LOG_PIPE is wrongly configured, fix up it. Signed-off-by: Zhangjin Wu --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d2626cb..3262925 100644 --- a/Makefile +++ b/Makefile @@ -4179,11 +4179,11 @@ ifneq ($(TEST_TIMEOUT),0) TEST_RET ?= $$TEST_LOGGING/boot.ret # Ref: /labs/linux-lab/logging/arm64-virt-linux-v5.1/20190520-145101/boot.log -ifneq ($(findstring serial,$(XOPTS)),) - XOPTS := $(shell echo "$(XOPTS) " | sed -e "s%-serial [^ ]* %-serial mon:pipe:$(TEST_LOG_PIPE) %g") -else - XOPTS += -serial mon:pipe:$(TEST_LOG_PIPE) -endif + ifneq ($(findstring serial,$(XOPTS)),) + XOPTS := $$(echo "$(XOPTS) " | sed -e "s%-serial [^ ]* %-serial mon:pipe:$(TEST_LOG_PIPE) %g") + else + XOPTS += -serial mon:pipe:$(TEST_LOG_PIPE) + endif # Allow test continue if the board always hang after poweroff, please pass TIMEOUT_CONTINUE=1 TIMEOUT_CONTINUE ?= 0 -- Gitee From b14d2c212c3d8edcddf95186fd1a13abc211da1b Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Thu, 8 Jun 2023 01:36:42 +0800 Subject: [PATCH 42/89] gcc: install: fix up ppa setting A typo blocks the ppa setting, fix up it. Signed-off-by: Wu Zhangjin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3262925..0ae0b55 100644 --- a/Makefile +++ b/Makefile @@ -2356,7 +2356,7 @@ toolchain-install-internal: $(Q)if ! which $(CCPRE)gcc-$(GCC) >/dev/null; then \ gcc_pkg=$(subst -xyz,,gcc-$(GCC)-$(CCPRE)xyz); \ echo "Installing internal toolchain: $$gcc_pkg ..."; \ - [ "$(XARCH)" = "i386" -o "$(XACH)" = "x86_64" ] && sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; \ + [ "$(XARCH)" = "i386" -o "$(XARCH)" = "x86_64" ] && sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; \ sudo apt-get -y update \ && sudo apt-get install $$gcc_pkg \ && sudo update-alternatives --install /usr/bin/$(CCPRE)gcc $(CCPRE)gcc /usr/bin/$(CCPRE)gcc-$(GCC) $$((50+RANDOM%50)); \ -- Gitee From aa89779a893b704e134091b04a452271866d7d0c Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Thu, 8 Jun 2023 01:39:07 +0800 Subject: [PATCH 43/89] apt: clean up apt usage Use apt instead of apt-get and enable the --yes by default. Signed-off-by: Wu Zhangjin --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0ae0b55..10f449c 100644 --- a/Makefile +++ b/Makefile @@ -2188,7 +2188,7 @@ ifeq ($(qemu_targets),1) # Notes: # # 1. --enable-curses is required for G=2, boot with LCD/keyboard from ssh login -# deps: sudo apt-get install libncursesw5-dev +# deps: sudo apt install -y libncursesw5-dev # 2. --enable-sdl is required for G=1, but from v4.0.0, it requires libsdl2-dev, # 3. --disable-vnc disable vnc graphic support, this is not that friendly because # it requires to install a vnc viewer, such as vinagre. @@ -2358,7 +2358,7 @@ toolchain-install-internal: echo "Installing internal toolchain: $$gcc_pkg ..."; \ [ "$(XARCH)" = "i386" -o "$(XARCH)" = "x86_64" ] && sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; \ sudo apt-get -y update \ - && sudo apt-get install $$gcc_pkg \ + && sudo apt install -y $$gcc_pkg \ && sudo update-alternatives --install /usr/bin/$(CCPRE)gcc $(CCPRE)gcc /usr/bin/$(CCPRE)gcc-$(GCC) $$((50+RANDOM%50)); \ fi @@ -2406,7 +2406,7 @@ toolchain-clean-internal: $(Q)gcc=$$(which $(CCPRE)gcc-$(GCC)) >/dev/null \ && gcc_pkg=$$(dpkg -S $$gcc | cut -d ':' -f1) \ && echo "Removing $$gcc_pkg ..." \ - && sudo apt-get remove --purge $$gcc_pkg \ + && sudo apt remove --purge --yes $$gcc_pkg \ && echo "Update alternativies for $(CCPRE)gcc" \ && update-alternatives --remove $(CCPRE)gcc /usr/bin/$(CCPRE)gcc-$(GCC) \ && update-alternatives --verbose --set $(CCPRE)gcc $$(update-alternatives --list $(CCPRE)gcc | sort -u | tail -1) || true -- Gitee From f15f1a7bf12357259e091d81a3ac68aa19c6b5d7 Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Thu, 8 Jun 2023 01:40:32 +0800 Subject: [PATCH 44/89] qemu: disable docs build by default To speed up qemu build, more not-used features should be disabled by default. More features can be found in the ./configure --help Signed-off-by: Wu Zhangjin --- Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile b/Makefile index 10f449c..5f43366 100644 --- a/Makefile +++ b/Makefile @@ -2195,6 +2195,7 @@ ifeq ($(qemu_targets),1) # TODO: start vnc viewer automatically while qemu boots and listen on vnc port. # 4. --disable-kvm is used to let qemu boot in docker environment which not have kvm. # 5. --enable-virtfs adds 9pnet sharing support, depends on libattr1-dev libcap-dev +# 6. --disable-docs is used to not build the docs # @@ -2249,6 +2250,7 @@ else # (too old ubuntu), use vnc instead QEMU_SDL ?= 1 QEMU_CURSES ?= 1 + QEMU_DOCS ?= 0 ifneq ($(QEMU_SDL),0) QEMU_CONF += --enable-sdl endif @@ -2268,6 +2270,14 @@ else ifeq ($(QEMU_CURSES),1) QEMU_CONF += --enable-curses endif + + ifneq ($(QEMU_DOCS),) + ifeq ($(QEMU_DOCS),1) + QEMU_CONF += --enable-docs + else + QEMU_CONF += --disable-docs + endif + endif endif QEMU_TARGET ?= $(subst $(space),$(comma),$(addsuffix -softmmu,$(QEMU_ARCH))) -- Gitee From 94fe57967a994c49ccce215acd2b6a30b4caa555 Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Thu, 8 Jun 2023 02:08:34 +0800 Subject: [PATCH 45/89] defconfig: fix up wrong config file copying The target config file is put in a wrong position, fix up it. Fixes: 8533770d6051 ("defconfig: unique the defconfig to avoid wrong dep") Signed-off-by: Wu Zhangjin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5f43366..2ea1c4a 100644 --- a/Makefile +++ b/Makefile @@ -1984,7 +1984,7 @@ endif $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG): $$(if $$($3CFG_BUILTIN),,$$($3CFG_FILE)) $$(ENV_FILES) $$(if $$(FORCE_DEFCONFIG),FORCE) $$(Q)$$(if $$($(call _uc,$1)_CONFIG_DIR),mkdir -p $$($(call _uc,$1)_CONFIG_DIR)) - $$(Q)$$(if $$($3CFG_BUILTIN),,cp $$($3CFG_FILE) $$($(call _uc,$1)_CONFIG_DIR))/$$(_$3CFG) + $$(Q)$$(if $$($3CFG_BUILTIN),,cp $$($3CFG_FILE) $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG)) $$(Q)$$(if $$(CFGS[$3_N]),$$(foreach n,$$(CFGS[$3_N]),$$(SCRIPTS_$3CONFIG) --file $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG) -d $$n;)) $$(Q)$$(if $$(CFGS[$3_Y]),$$(foreach y,$$(CFGS[$3_Y]),$$(SCRIPTS_$3CONFIG) --file $$($(call _uc,$1)_CONFIG_DIR)/$$(_$3CFG) -e $$y;)) -- Gitee From db88d255fdb673cfa144c60f5b9c5ab0435f5165 Mon Sep 17 00:00:00 2001 From: Wu Zhangjin Date: Thu, 8 Jun 2023 02:15:34 +0800 Subject: [PATCH 46/89] qemu: add python3-venv package for v8.0.1 Signed-off-by: Wu Zhangjin --- .labbegin | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.labbegin b/.labbegin index 3f5229f..cf295bd 100644 --- a/.labbegin +++ b/.labbegin @@ -21,6 +21,9 @@ ifneq ($(QEMU),) ifeq ($(wildcard /usr/bin/ninja),) PKGS[QEMU_$(call _any,QEMU,>=,v6.0.0)] := ninja;ninja-build endif + ifeq ($(wildcard /usr/bin/pyvenv),) + PKGS[QEMU_$(call _any,QEMU,>=,v8.0.1)] += python3-venv + endif # Install all required libraries if QEMU_FULL=1 specified ifeq ($(QEMU_FULL),1) -- Gitee From d26e37b910b7dbae6fbaad5273df8234e349c996 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 8 Jun 2023 19:52:28 +0800 Subject: [PATCH 47/89] nolibc: add -std=c89 to align with nolibc-test makefile Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2ea1c4a..2df5e4b 100644 --- a/Makefile +++ b/Makefile @@ -2488,7 +2488,7 @@ NOLIBC_TARGETS := root-nolibc nolibc root root-rd PHONY += $(NOLIBC_TARGETS) $(foreach x,clean distclean rebuild,$(addsuffix -$x,$(NOLIBC_TARGETS))) # Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL +NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -DRECORD_SYSCALL NOLIBC_LDFLAGS := -s ifeq ($(nolibc_stkp),1) -- Gitee From b7a5189d0e885ce1cd540c03c15da9ed81bf73cb Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Fri, 9 Jun 2023 22:40:43 +0800 Subject: [PATCH 48/89] feature: nolibc: add default config This adds more required config for tools/testing/selftests/nolibc-test.c To avoid some mixleading, perhaps we should rename the old nolibc default to minimal_defconfig. Signed-off-by: Zhangjin Wu --- src/feature/linux/nolibc/config | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/feature/linux/nolibc/config diff --git a/src/feature/linux/nolibc/config b/src/feature/linux/nolibc/config new file mode 100644 index 0000000..9b6a0eb --- /dev/null +++ b/src/feature/linux/nolibc/config @@ -0,0 +1,8 @@ +CONFIG_NET=y +# CONFIG_WIRELESS is not set +# CONFIG_ETHTOOL_NETLINK is not set +CONFIG_DEVTMPFS=y +CONFIG_DEVTMPFS_MOUNT=y +CONFIG_PROC_FS=y +# CONFIG_PROC_SYSCTL is not set +# CONFIG_PROC_PAGE_MONITOR is not set -- Gitee From 7836e585c5cca1a5fd8ed46b2d3ac3f46ff03438 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 10 Jun 2023 17:47:16 +0800 Subject: [PATCH 49/89] x86_64/pc: upgrade kernel from v5.13 to v6.1.1 Signed-off-by: Zhangjin Wu --- boards/x86_64/pc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/x86_64/pc/Makefile b/boards/x86_64/pc/Makefile index 9a71c21..2a6e09a 100644 --- a/boards/x86_64/pc/Makefile +++ b/boards/x86_64/pc/Makefile @@ -7,7 +7,7 @@ XARCH := x86_64 CPU ?= qemu64 MEM ?= 128M SMP ?= 4 -LINUX ?= v5.13 +LINUX ?= v6.1.1 # git repos for the other kernel forks KERNEL_GIT[KERNEL_FORK_openeuler] := https://gitee.com/openeuler/kernel.git -- Gitee From 36ab376e4d651ab0b0e17864c99ecddf7b4ce3d0 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 10 Jun 2023 17:58:13 +0800 Subject: [PATCH 50/89] arm/vexpress-a9: upgrade kernel from v6.1.1 to v6.3 Signed-off-by: Zhangjin Wu --- boards/arm/vexpress-a9/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/vexpress-a9/Makefile b/boards/arm/vexpress-a9/Makefile index 511bd01..acc7cb4 100644 --- a/boards/arm/vexpress-a9/Makefile +++ b/boards/arm/vexpress-a9/Makefile @@ -10,7 +10,7 @@ QEMU ?= v4.1.1 QEMU_US ?= 0 UBOOT ?= v2020.04 -LINUX ?= v6.1.1 +LINUX ?= v6.3 # Uboot breaks 9pnet sharing, disable uboot if 9pnet share used UBOOT[SHARE_1] := disabled -- Gitee From e3b30b19c0ee87d43943e00997612754b99bbf4c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 10 Jun 2023 18:05:18 +0800 Subject: [PATCH 51/89] mipsel/malta: upgrade kernel from v5.13 to v6.2 Signed-off-by: Zhangjin Wu --- boards/mipsel/malta/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/mipsel/malta/Makefile b/boards/mipsel/malta/Makefile index 7ddf36c..a58bf26 100644 --- a/boards/mipsel/malta/Makefile +++ b/boards/mipsel/malta/Makefile @@ -4,7 +4,7 @@ ARCH := mips XARCH := mipsel # Not sure, use the default one CPU ?= -LINUX ?= v5.13 +LINUX ?= v6.2 # NOTE: need to update docker image to get 4.3 gcc GCC[LINUX_v2.6.36] := 4.3 -- Gitee From d4d86cf5fc7b4cc57a9add8bea945ce4e7ba419c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 10 Jun 2023 18:23:20 +0800 Subject: [PATCH 52/89] i386/pc: upgrade kernel from v5.13 to v6.1.1 Signed-off-by: Zhangjin Wu --- boards/i386/pc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/i386/pc/Makefile b/boards/i386/pc/Makefile index 51b50d0..45e73e3 100644 --- a/boards/i386/pc/Makefile +++ b/boards/i386/pc/Makefile @@ -7,7 +7,7 @@ XARCH := i386 CPU ?= qemu32 MEM ?= 128M SMP ?= 4 -LINUX ?= v5.13 +LINUX ?= v6.1.1 # This is for old linux 0.11 floppy support QEMU ?= v0.10.6 -- Gitee From 22380cedab719061cb225b7ff6dced383bc9c24e Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sat, 10 Jun 2023 19:37:17 +0800 Subject: [PATCH 53/89] nolibc: add i386/pc support Signed-off-by: Zhangjin Wu --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 2df5e4b..68d2f00 100644 --- a/Makefile +++ b/Makefile @@ -2518,6 +2518,11 @@ $(NOLIBC_SRC): FORCE $(Q)[ -f $(BITS_WORDSIZE_H) ] && grep -q 'rv32i-based targets are not supported' $(BITS_WORDSIZE_H) && sudo cp tools/nolibc/wordsize.h $(BITS_WORDSIZE_H) || true endif +ifeq ($(XARCH),i386) + NOLIBC_CFLAGS += -m32 + NOLIBC_LDFLAGS += -melf_i386 +endif + # nolibc gc sections and debug support nolibc_gc ?= 1 nolibc_gc_debug ?= 1 -- Gitee From 36ecafb2e4486c3ebe630cbf35f58242f207ee1b Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 11 Jun 2023 11:00:02 +0800 Subject: [PATCH 54/89] aarch64/virt: upgrade kernel from v5.13 to v6.1.1 Signed-off-by: Zhangjin Wu --- boards/aarch64/virt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/aarch64/virt/Makefile b/boards/aarch64/virt/Makefile index 9cba12a..f3d3911 100644 --- a/boards/aarch64/virt/Makefile +++ b/boards/aarch64/virt/Makefile @@ -16,7 +16,7 @@ UBOOT ?= v2019.10 CCORI[UBOOT_v2019.10,OS_trusty]:= linaro CCORI[UBOOT_v2019.10,OS_focal] := internal -LINUX ?= v5.13 +LINUX ?= v6.1.1 BUILDROOT?= 2019.11.1 # git repos for the other kernel forks -- Gitee From 35a22b1e4e508262f8f7e25eb029ca4b050c3a4a Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 11 Jun 2023 11:58:33 +0800 Subject: [PATCH 55/89] riscv32/virt: upgrade kernel from v5.17 to v6.1.1 Signed-off-by: Zhangjin Wu --- boards/riscv32/virt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/riscv32/virt/Makefile b/boards/riscv32/virt/Makefile index 39377f9..d4a68f7 100644 --- a/boards/riscv32/virt/Makefile +++ b/boards/riscv32/virt/Makefile @@ -10,7 +10,7 @@ QEMU ?= v6.0.0 HOST_GCC[QEMU_v4.0.0] := 4.8 # Enable QEMU_US=1 for qemu-user-static QEMU_US ?= 0 -LINUX ?= v5.17 +LINUX ?= v6.1.1 BUILDROOT[LINUX_v5.0.13] ?= 2019.05 BUILDROOT ?= 2021.08 NETDEV_LIST := virtio -- Gitee From 4da240737ed9f47adbb6c46f16115ba4925422da Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 11 Jun 2023 12:29:55 +0800 Subject: [PATCH 56/89] ppc/g3beige: upgrade kernel from v5.13 to v6.3.6 Signed-off-by: Zhangjin Wu --- boards/ppc/g3beige/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/ppc/g3beige/Makefile b/boards/ppc/g3beige/Makefile index 9005929..2ebfaa0 100644 --- a/boards/ppc/g3beige/Makefile +++ b/boards/ppc/g3beige/Makefile @@ -5,7 +5,7 @@ XARCH := ppc # Not sure, use the default setting CPU ?= # Note: <2.6.37 kernel don't have __NR_socket implementation -LINUX ?= v5.13 +LINUX ?= v6.3.6 GCC[LINUX_v2.6.36] := 4.3 -- Gitee From 363d08d34fbb61b080d76d2a92c30fa82636f8ab Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 11 Jun 2023 17:29:29 +0800 Subject: [PATCH 57/89] nolibc: use gcc instead of ld to add missing -lgcc It is not that easy to add the right '-L /path/to/' for 'ld -lgcc', use gcc instead. Reserve the LDFLAGS setting for future re-working. Signed-off-by: Zhangjin Wu --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 68d2f00..8cfac47 100644 --- a/Makefile +++ b/Makefile @@ -2488,7 +2488,7 @@ NOLIBC_TARGETS := root-nolibc nolibc root root-rd PHONY += $(NOLIBC_TARGETS) $(foreach x,clean distclean rebuild,$(addsuffix -$x,$(NOLIBC_TARGETS))) # Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -DRECORD_SYSCALL +NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -DRECORD_SYSCALL -Wl,-s NOLIBC_LDFLAGS := -s ifeq ($(nolibc_stkp),1) @@ -2510,7 +2510,7 @@ endif ifeq ($(XARCH),riscv32) # rv32 support patch is ready for both tools/nolibc and selftests/nolibc, see https://lore.kernel.org/linux-riscv/ - NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 + NOLIBC_CFLAGS += -march=rv32im -mabi=ilp32 -Wl,-melf32lriscv_ilp32 NOLIBC_LDFLAGS += -melf32lriscv_ilp32 BITS_WORDSIZE_H := /usr/riscv64-linux-gnu/include/bits/wordsize.h @@ -2519,7 +2519,7 @@ $(NOLIBC_SRC): FORCE endif ifeq ($(XARCH),i386) - NOLIBC_CFLAGS += -m32 + NOLIBC_CFLAGS += -m32 -Wl,-melf_i386 NOLIBC_LDFLAGS += -melf_i386 endif @@ -2528,11 +2528,12 @@ nolibc_gc ?= 1 nolibc_gc_debug ?= 1 ifeq ($(nolibc_gc),1) - NOLIBC_CFLAGS += -ffunction-sections -fdata-sections + NOLIBC_CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections NOLIBC_LDFLAGS += --gc-sections endif ifeq ($(nolibc_gc_debug),1) + NOLIBC_CFLAGS += -Wl,--print-gc-sections NOLIBC_LDFLAGS += --print-gc-sections endif @@ -2567,7 +2568,8 @@ $(NOLIBC_OBJ): $(NOLIBC_SRC) $(NOLIBC_DEP) $(NOLIBC_BIN): $(NOLIBC_OBJ) $(Q)echo "Building $@" $(Q)mkdir -p $(dir $@) - $(Q)$(C_PATH) $(CCPRE)ld $(NOLIBC_LDFLAGS) -o $@ $< 2>&1 | tee $(NOLIBC_PGC) + $(Q)$(C_PATH) $(CCPRE)gcc $(NOLIBC_CFLAGS) -o $@ \ + -nostdlib -static $< -lgcc 2>&1 | tee $(NOLIBC_PGC) # ref: ld-elf2flt.in from https://github.com/uclinux-dev/elf2flt $(NOLIBC_FLT): $(NOLIBC_OBJ) -- Gitee From e201497eae13b49112188e6c1cb435365a1ccf56 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Sun, 11 Jun 2023 17:55:13 +0800 Subject: [PATCH 58/89] nolibc: add missing SHMEM and TMPFS for MEMFD_CREATE MEMFD_CREATE is required for vfprintf test cases. Signed-off-by: Zhangjin Wu --- src/feature/linux/nolibc/config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/feature/linux/nolibc/config b/src/feature/linux/nolibc/config index 9b6a0eb..aa1773c 100644 --- a/src/feature/linux/nolibc/config +++ b/src/feature/linux/nolibc/config @@ -6,3 +6,5 @@ CONFIG_DEVTMPFS_MOUNT=y CONFIG_PROC_FS=y # CONFIG_PROC_SYSCTL is not set # CONFIG_PROC_PAGE_MONITOR is not set +CONFIG_SHMEM=y +CONFIG_TMPFS=y -- Gitee From daa60b7e7698e05494e98c1a79c4fe855ec850bc Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 01:53:52 +0800 Subject: [PATCH 59/89] nolibc: only enable -std=c89 for v6.4+ The nolibc code can not be compiled with -std=c89 for Linux <= v6.3 Signed-off-by: Zhangjin Wu --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8cfac47..2e73017 100644 --- a/Makefile +++ b/Makefile @@ -2488,9 +2488,13 @@ NOLIBC_TARGETS := root-nolibc nolibc root root-rd PHONY += $(NOLIBC_TARGETS) $(foreach x,clean distclean rebuild,$(addsuffix -$x,$(NOLIBC_TARGETS))) # Nolibc build support, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -DRECORD_SYSCALL -Wl,-s +NOLIBC_CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -DRECORD_SYSCALL -Wl,-s NOLIBC_LDFLAGS := -s +# Apply -std=c89 when LINUX >= v6.4 +NOLIBC_CFLAGS[LINUX_$(call _any,LINUX,>=,v6.4)] += -std=c89 +$(eval $(call __vs,NOLIBC_CFLAGS,LINUX)) + ifeq ($(nolibc_stkp),1) NOLIBC_CFLAGS += -DNOLIBC_STACKPROTECTOR -mstack-protector-guard=global -fstack-protector-all endif -- Gitee From 53ff4ec6fc49232e51e2dcb2ecd9f88a5ed2b8b2 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 03:30:06 +0800 Subject: [PATCH 60/89] loongarch/virt: init loongarch support v6.3.6 is builtable, but there is no buildroot currently, we use nolibc initrd by default. to really use nolibc, we must wait for v6.4 (>= v6.4-rc1) $ pushd src/linux-stable $ git checkout v6.4-rc5 $ popd $ make BOARD=loongarch/virt $ make kernel $ make boot Signed-off-by: Zhangjin Wu --- boards/loongarch/virt/Makefile | 26 ++++++++++++++++++++++++++ boards/loongarch/virt/README.md | 25 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 boards/loongarch/virt/Makefile create mode 100644 boards/loongarch/virt/README.md diff --git a/boards/loongarch/virt/Makefile b/boards/loongarch/virt/Makefile new file mode 100644 index 0000000..28eeff8 --- /dev/null +++ b/boards/loongarch/virt/Makefile @@ -0,0 +1,26 @@ +# Copyright (C) 2016-2021 Wu Zhangjin +_BASE := 1 +ARCH := loongarch +XARCH := loongarch64 +CPU ?= la464-loongarch-cpu +MEM ?= 1024M +SERIAL ?= ttyS0,115200 + +QEMU ?= v8.0.2 + +LINUX ?= v6.3.6 + +HOST_GCC := 9 + +# no buildroot support for loongarch currently, use nolibc initrd by default +NOLIBC ?= 1 + +# download from https://github.com/loongson/Firmware/tree/main/LoongArchVirtMachine +BIOS ?= $(BSP_BIOS)/edk2/edk2-loongarch64-code.fd + +ORIIMG ?= arch/$(ARCH)/boot/vmlinux.efi +KIMAGE ?= $(BSP_KERNEL)/$(LINUX)/vmlinux.efi + +QTOOL ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) + +CCORI ?= mirrors.edge.kernel.org diff --git a/boards/loongarch/virt/README.md b/boards/loongarch/virt/README.md new file mode 100644 index 0000000..1054636 --- /dev/null +++ b/boards/loongarch/virt/README.md @@ -0,0 +1,25 @@ + +# loongarch/virt board Usage + +## Select me + + $ make B=loongarch/virt + +## Boot me with initrd + + $ make boot + +## Debug with qemu + + Debug interactively: + + $ make debug + + Debug automatically: + + $ make test DEBUG=1 + +## References + +* src/qemu/docs/system/loongarch/virt.rst +* https://github.com/foxsen/qemu-loongarch-runenv -- Gitee From 1b230280d62c8516eb67c4ca5eab8b1ec4df785f Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 03:47:57 +0800 Subject: [PATCH 61/89] loongarch/virt: add a default ROOTDEV Signed-off-by: Zhangjin Wu --- boards/loongarch/virt/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/loongarch/virt/Makefile b/boards/loongarch/virt/Makefile index 28eeff8..23e1d8e 100644 --- a/boards/loongarch/virt/Makefile +++ b/boards/loongarch/virt/Makefile @@ -15,6 +15,9 @@ HOST_GCC := 9 # no buildroot support for loongarch currently, use nolibc initrd by default NOLIBC ?= 1 +ROOTDEV_LIST := /dev/ram0 +ROOTDEV ?= /dev/ram0 + # download from https://github.com/loongson/Firmware/tree/main/LoongArchVirtMachine BIOS ?= $(BSP_BIOS)/edk2/edk2-loongarch64-code.fd -- Gitee From 0de461d0117975fa58d8eb0358f44aa390674cd5 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 03:58:59 +0800 Subject: [PATCH 62/89] loongarch/virt: add bsp support Signed-off-by: Zhangjin Wu --- .gitmodules | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitmodules b/.gitmodules index 47c8805..45abafe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -82,3 +82,7 @@ ignore = all path = boards/arm/ebf-imx6ull/bsp url = https://gitee.com/tinylab/ebf-imx6ull.git +[submodule "boards/loongarch/virt/bsp"] + ignore = all + path = boards/loongarch/virt/bsp + url = https://gitee.com/tinylab/qemu-loongarch-virt.git -- Gitee From c2807b6cf3a03e60ba24169e858566b8df9b3bdc Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:07:02 +0800 Subject: [PATCH 63/89] loongarch/virt: add missing NETDEV Signed-off-by: Zhangjin Wu --- boards/loongarch/virt/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/loongarch/virt/Makefile b/boards/loongarch/virt/Makefile index 23e1d8e..64a44f1 100644 --- a/boards/loongarch/virt/Makefile +++ b/boards/loongarch/virt/Makefile @@ -8,6 +8,9 @@ SERIAL ?= ttyS0,115200 QEMU ?= v8.0.2 +NETDEV_LIST ?= e1000 +NETDEV ?= e1000 + LINUX ?= v6.3.6 HOST_GCC := 9 -- Gitee From 31de7ca3ed4004dd10b2e47f04efeb9f252a7919 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:10:33 +0800 Subject: [PATCH 64/89] loongarch/virt: add missing /dev/nfs Signed-off-by: Zhangjin Wu --- boards/loongarch/virt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/loongarch/virt/Makefile b/boards/loongarch/virt/Makefile index 64a44f1..d96e0eb 100644 --- a/boards/loongarch/virt/Makefile +++ b/boards/loongarch/virt/Makefile @@ -18,7 +18,7 @@ HOST_GCC := 9 # no buildroot support for loongarch currently, use nolibc initrd by default NOLIBC ?= 1 -ROOTDEV_LIST := /dev/ram0 +ROOTDEV_LIST := /dev/ram0 /dev/nfs ROOTDEV ?= /dev/ram0 # download from https://github.com/loongson/Firmware/tree/main/LoongArchVirtMachine -- Gitee From 150efdcc7549b8a34a68d455ff0352be2c4479f6 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:13:57 +0800 Subject: [PATCH 65/89] nolibc: must use /dev/null as TEST_ROOTDEV Signed-off-by: Zhangjin Wu --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 2e73017..e85eb43 100644 --- a/Makefile +++ b/Makefile @@ -1263,8 +1263,12 @@ ifneq ($(wildcard $(NOLIBC_SRC)),) # Build initramfs into kernel image with CONFIG_INITRAMFS_SOURCE override ROOTDEV := /dev/null endif + # Tag defconfig KTAG := nolibc$(if $(KTAG),_$(KTAG)) + +# Set TEST_ROOTDEV +TEST_ROOTDEV ?= $(ROOTDEV) endif ifeq ($(_PBR), 0) -- Gitee From afa4b36f0d6d070ed675c4005237b71a182795ab Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:32:04 +0800 Subject: [PATCH 66/89] bsp: don't check bsp root for board download for nolibc, there may be no root, check bsp configs instead. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e85eb43..8a74c00 100644 --- a/Makefile +++ b/Makefile @@ -1407,7 +1407,7 @@ echo [ $(BOARD) ]:"\n" $(foreach v,$(or $(VAR),$(or $1,$(shell $(call getboardva endef BSP_CHECKOUT ?= bsp-checkout -ifeq ($(wildcard $(BSP_ROOT)),) +ifeq ($(wildcard $(_BSP_CONFIG)),) ifneq ($(app),default) BOARD_DOWNLOAD := $(BSP_CHECKOUT) endif -- Gitee From c5f832379a1b76e53db4aecf5a591f2ac07ff498 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:33:09 +0800 Subject: [PATCH 67/89] targets: disable directory print instead of hide all output While the output is hidden, it is very hard to check the status. Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8a74c00..d85125e 100644 --- a/Makefile +++ b/Makefile @@ -4550,7 +4550,7 @@ endef ifneq ($(BOARD_DOWNLOAD),) $(APP_TARGETS): $(BOARD_DOWNLOAD) - $(Q)make $(S) $(foreach a,$(app),$(call real_target,$(first_target),$(a)) ) + $(Q)make $(NPD) $(foreach a,$(app),$(call real_target,$(first_target),$(a)) ) else $(APP_TARGETS): $(foreach a,$(app),$(call real_target,$(first_target),$(a)) ) endif -- Gitee From 9efafff0b61242a1391bdd67097d3d994d517489 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:47:25 +0800 Subject: [PATCH 68/89] loongarch/virt: rename to loongarch64/virt Signed-off-by: Zhangjin Wu --- .gitmodules | 6 +++--- boards/{loongarch => loongarch64}/virt/Makefile | 0 boards/{loongarch => loongarch64}/virt/README.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename boards/{loongarch => loongarch64}/virt/Makefile (100%) rename boards/{loongarch => loongarch64}/virt/README.md (81%) diff --git a/.gitmodules b/.gitmodules index 45abafe..8caf47b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -82,7 +82,7 @@ ignore = all path = boards/arm/ebf-imx6ull/bsp url = https://gitee.com/tinylab/ebf-imx6ull.git -[submodule "boards/loongarch/virt/bsp"] +[submodule "boards/loongarch64/virt/bsp"] ignore = all - path = boards/loongarch/virt/bsp - url = https://gitee.com/tinylab/qemu-loongarch-virt.git + path = boards/loongarch64/virt/bsp + url = https://gitee.com/tinylab/qemu-loongarch64-virt.git diff --git a/boards/loongarch/virt/Makefile b/boards/loongarch64/virt/Makefile similarity index 100% rename from boards/loongarch/virt/Makefile rename to boards/loongarch64/virt/Makefile diff --git a/boards/loongarch/virt/README.md b/boards/loongarch64/virt/README.md similarity index 81% rename from boards/loongarch/virt/README.md rename to boards/loongarch64/virt/README.md index 1054636..16795e7 100644 --- a/boards/loongarch/virt/README.md +++ b/boards/loongarch64/virt/README.md @@ -1,9 +1,9 @@ -# loongarch/virt board Usage +# loongarch64/virt board Usage ## Select me - $ make B=loongarch/virt + $ make B=loongarch64/virt ## Boot me with initrd -- Gitee From bcbb08d3d267ee4bb2e063a506ad6562b5ece146 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 04:52:40 +0800 Subject: [PATCH 69/89] loongarch64/virt: update copyright year Signed-off-by: Zhangjin Wu --- boards/loongarch64/virt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/loongarch64/virt/Makefile b/boards/loongarch64/virt/Makefile index d96e0eb..658c02c 100644 --- a/boards/loongarch64/virt/Makefile +++ b/boards/loongarch64/virt/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2021 Wu Zhangjin +# Copyright (C) 2023 Wu Zhangjin _BASE := 1 ARCH := loongarch XARCH := loongarch64 -- Gitee From da02c15330b20b8b0c386f25d3edbef76c37e108 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 05:01:22 +0800 Subject: [PATCH 70/89] loongarch64/virt: configure external crosstool Signed-off-by: Zhangjin Wu --- prebuilt/toolchains/loongarch64/Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prebuilt/toolchains/loongarch64/Makefile diff --git a/prebuilt/toolchains/loongarch64/Makefile b/prebuilt/toolchains/loongarch64/Makefile new file mode 100644 index 0000000..d5fbc1a --- /dev/null +++ b/prebuilt/toolchains/loongarch64/Makefile @@ -0,0 +1,14 @@ +# Makefile + +CCORI ?= mirrors.edge.kernel.org +CCORI_LIST ?= mirrors.edge.kernel.org +TOOLCHAIN ?= $(PREBUILT_TOOLCHAINS)/loongarch64 + +ifeq ($(CCORI), mirrors.edge.kernel.org) + CCPRE ?= loongarch64-linux- + CCVER ?= 13.1.0 + CCBASE := gcc-$(CCVER)-nolibc/$(subst -x,,$(CCPRE)x) + CCPATH ?= $(TOOLCHAIN)/$(CCBASE)/bin + _CCBASE := x86_64-$(subst /,-,$(CCBASE)) + CCURL := https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/$(CCVER)/$(_CCBASE).tar.gz +endif -- Gitee From 913f0c896a5b4b35cb6f66fcd28e9dd19790037a Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 05:45:46 +0800 Subject: [PATCH 71/89] s390x/s390-ccw-virtio: init a new s390 board Signed-off-by: Zhangjin Wu --- .gitmodules | 4 ++++ Makefile | 7 +++++- boards/s390x/s390-ccw-virtio/Makefile | 31 ++++++++++++++++++++++++++ boards/s390x/s390-ccw-virtio/README.md | 24 ++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 boards/s390x/s390-ccw-virtio/Makefile create mode 100644 boards/s390x/s390-ccw-virtio/README.md diff --git a/.gitmodules b/.gitmodules index 8caf47b..22d7f07 100644 --- a/.gitmodules +++ b/.gitmodules @@ -86,3 +86,7 @@ ignore = all path = boards/loongarch64/virt/bsp url = https://gitee.com/tinylab/qemu-loongarch64-virt.git +[submodule "boards/s390x/s390-ccw-virtio/bsp"] + ignore = all + path = boards/s390x/s390-ccw-virtio/bsp + url = https://gitee.com/tinylab/qemu-s390x-s390-ccw-virtio.git diff --git a/Makefile b/Makefile index d85125e..20ab7e2 100644 --- a/Makefile +++ b/Makefile @@ -2531,6 +2531,10 @@ ifeq ($(XARCH),i386) NOLIBC_LDFLAGS += -melf_i386 endif +ifeq ($(XARCH),s390x) + NOLIBC_CFLAGS += -m64 +endif + # nolibc gc sections and debug support nolibc_gc ?= 1 nolibc_gc_debug ?= 1 @@ -3818,7 +3822,8 @@ NET ?= -net nic,model=$(call _v,NETDEV,LINUX) -net tap,script=/etc/qemu-ifup,do ifeq ($(NETDEV), virtio) MACADDR_TOOL := tools/qemu/macaddr.sh RANDOM_MACADDR := $$($(MACADDR_TOOL)) - NET += -device virtio-net-device,netdev=net0,mac=$(RANDOM_MACADDR) -netdev tap,id=net0 + VIRTIO_NET_DEVICE ?= virtio-net-device + NET += -device $(VIRTIO_NET_DEVICE),netdev=net0,mac=$(RANDOM_MACADDR) -netdev tap,id=net0 endif # Kernel command line configuration diff --git a/boards/s390x/s390-ccw-virtio/Makefile b/boards/s390x/s390-ccw-virtio/Makefile new file mode 100644 index 0000000..fc07fb1 --- /dev/null +++ b/boards/s390x/s390-ccw-virtio/Makefile @@ -0,0 +1,31 @@ +# Copyright (C) 2023 Wu Zhangjin +_BASE := 1 +ARCH := s390 +XARCH := s390x +CPU ?= max,zpci=on,aen=on,ais=on +MEM ?= 1024M +SERIAL ?= ttyS0 + +QEMU ?= v8.0.2 + +NETDEV_LIST ?= virtio +NETDEV ?= virtio + +VIRTIO_NET_DEVICE ?= virtio-net-pci + +LINUX ?= v6.3.6 + +HOST_GCC := 9 + +# no buildroot support for loongarch currently, use nolibc initrd by default +NOLIBC ?= 1 + +ROOTDEV_LIST := /dev/ram0 /dev/nfs +ROOTDEV ?= /dev/ram0 + +ORIIMG ?= arch/$(ARCH)/boot/bzImage +KIMAGE ?= $(BSP_KERNEL)/$(LINUX)/bzImage + +QTOOL ?= $(BSP_QEMU)/$(QEMU)/bin/qemu-system-$(XARCH) + +CCORI ?= mirrors.edge.kernel.org diff --git a/boards/s390x/s390-ccw-virtio/README.md b/boards/s390x/s390-ccw-virtio/README.md new file mode 100644 index 0000000..4afc5f0 --- /dev/null +++ b/boards/s390x/s390-ccw-virtio/README.md @@ -0,0 +1,24 @@ + +# s390x/s390-ccw-virtio board Usage + +## Select me + + $ make B=s390x/s390-ccw-virtio + +## Boot me with initrd + + $ make boot + +## Debug with qemu + + Debug interactively: + + $ make debug + + Debug automatically: + + $ make test DEBUG=1 + +## References + +* tools/testing/selftests/nolibc/Makefile -- Gitee From bb7374408cd38d27d0d52cdfc05c4c1af42c9993 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 06:20:17 +0800 Subject: [PATCH 72/89] s390x/s390-ccw-virtio: configure external crosstool Signed-off-by: Zhangjin Wu --- prebuilt/toolchains/s390x/Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prebuilt/toolchains/s390x/Makefile diff --git a/prebuilt/toolchains/s390x/Makefile b/prebuilt/toolchains/s390x/Makefile new file mode 100644 index 0000000..21375df --- /dev/null +++ b/prebuilt/toolchains/s390x/Makefile @@ -0,0 +1,14 @@ +# Makefile + +CCORI ?= mirrors.edge.kernel.org +CCORI_LIST ?= mirrors.edge.kernel.org +TOOLCHAIN ?= $(PREBUILT_TOOLCHAINS)/s390x + +ifeq ($(CCORI), mirrors.edge.kernel.org) + CCPRE ?= s390-linux- + CCVER ?= 13.1.0 + CCBASE := gcc-$(CCVER)-nolibc/$(subst -x,,$(CCPRE)x) + CCPATH ?= $(TOOLCHAIN)/$(CCBASE)/bin + _CCBASE := x86_64-$(subst /,-,$(CCBASE)) + CCURL := https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/$(CCVER)/$(_CCBASE).tar.gz +endif -- Gitee From f0d5125bc5140ebbaa313efd67717d6c66f0ca52 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 14:26:15 +0800 Subject: [PATCH 73/89] nolibc: fix up NOLIBC setting in board's Makefile NOLIBC has been set before board's Makefile, we can only check its value instead of check whether it is defined. Signed-off-by: Zhangjin Wu --- boards/loongarch64/virt/Makefile | 2 +- boards/s390x/s390-ccw-virtio/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/loongarch64/virt/Makefile b/boards/loongarch64/virt/Makefile index 658c02c..0c508fe 100644 --- a/boards/loongarch64/virt/Makefile +++ b/boards/loongarch64/virt/Makefile @@ -16,7 +16,7 @@ LINUX ?= v6.3.6 HOST_GCC := 9 # no buildroot support for loongarch currently, use nolibc initrd by default -NOLIBC ?= 1 +NOLIBC := $(or $(NOLIBC),1) ROOTDEV_LIST := /dev/ram0 /dev/nfs ROOTDEV ?= /dev/ram0 diff --git a/boards/s390x/s390-ccw-virtio/Makefile b/boards/s390x/s390-ccw-virtio/Makefile index fc07fb1..47734ca 100644 --- a/boards/s390x/s390-ccw-virtio/Makefile +++ b/boards/s390x/s390-ccw-virtio/Makefile @@ -18,7 +18,7 @@ LINUX ?= v6.3.6 HOST_GCC := 9 # no buildroot support for loongarch currently, use nolibc initrd by default -NOLIBC ?= 1 +NOLIBC := $(or $(NOLIBC),1) ROOTDEV_LIST := /dev/ram0 /dev/nfs ROOTDEV ?= /dev/ram0 -- Gitee From 300049917f0f8eecd15d2d5d0b7e79dea1524443 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Mon, 12 Jun 2023 14:27:37 +0800 Subject: [PATCH 74/89] board: add more architectures in the BASE_ARCHS Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 20ab7e2..8629b49 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ FEATURE_DIR := $(TOP_SRC)/feature/linux # Search board in basic arch list while board name given without arch specified ifneq ($(BOARD),) - BASE_ARCHS := arm aarch64 mipsel mips64el ppc i386 x86_64 riscv32 riscv64 csky + BASE_ARCHS := arm aarch64 mipsel mips64el ppc i386 x86_64 riscv32 riscv64 csky s390x s390 loongarch64 loongarch alpha parisc sparc ifeq ($(wildcard $(BOARD_DIR)/Makefile),) ARCH := $(strip $(firstword $(foreach arch,$(BASE_ARCHS),$(if $(wildcard $(TOP_DIR)/$(BOARDS_DIR)/$(arch)/$(BOARD)),$(arch) )))) ifneq ($(ARCH),) -- Gitee From 5110cb8cb62598da9df19c5a371f17c1eb3987f9 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Tue, 13 Jun 2023 15:22:07 +0800 Subject: [PATCH 75/89] loongarch64/virt: add firmware doc Signed-off-by: Zhangjin Wu --- boards/loongarch64/virt/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/loongarch64/virt/README.md b/boards/loongarch64/virt/README.md index 16795e7..03d988c 100644 --- a/boards/loongarch64/virt/README.md +++ b/boards/loongarch64/virt/README.md @@ -23,3 +23,4 @@ * src/qemu/docs/system/loongarch/virt.rst * https://github.com/foxsen/qemu-loongarch-runenv +* https://github.com/loongson/Firmware/blob/main/LoongArchVirtMachine/ -- Gitee From d9a29871a8c12e4a4fcebdb7d8b112f6966fc41b Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Tue, 13 Jun 2023 15:33:31 +0800 Subject: [PATCH 76/89] net: fix up default path of qemu-ifup and qemu-ifdown Signed-off-by: Zhangjin Wu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8629b49..ac35286 100644 --- a/Makefile +++ b/Makefile @@ -3823,7 +3823,7 @@ ifeq ($(NETDEV), virtio) MACADDR_TOOL := tools/qemu/macaddr.sh RANDOM_MACADDR := $$($(MACADDR_TOOL)) VIRTIO_NET_DEVICE ?= virtio-net-device - NET += -device $(VIRTIO_NET_DEVICE),netdev=net0,mac=$(RANDOM_MACADDR) -netdev tap,id=net0 + NET += -device $(VIRTIO_NET_DEVICE),netdev=net0,mac=$(RANDOM_MACADDR) -netdev tap,id=net0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown endif # Kernel command line configuration -- Gitee From 56fc446fafb0503b91a3ad6546dfb7ba16c1b24e Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Wed, 14 Jun 2023 01:03:00 +0800 Subject: [PATCH 77/89] tools: import merge_config.sh from linux source It is used to apply the config fragments. Current version is from v6.4. Signed-off-by: Zhangjin Wu --- tools/kernel/merge_config.sh | 211 +++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100755 tools/kernel/merge_config.sh diff --git a/tools/kernel/merge_config.sh b/tools/kernel/merge_config.sh new file mode 100755 index 0000000..902eb42 --- /dev/null +++ b/tools/kernel/merge_config.sh @@ -0,0 +1,211 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# merge_config.sh - Takes a list of config fragment values, and merges +# them one by one. Provides warnings on overridden values, and specified +# values that did not make it to the resulting .config file (due to missed +# dependencies or config symbol removal). +# +# Portions reused from kconf_check and generate_cfg: +# http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check +# http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg +# +# Copyright (c) 2009-2010 Wind River Systems, Inc. +# Copyright 2011 Linaro + +set -e + +clean_up() { + rm -f $TMP_FILE + rm -f $MERGE_FILE +} + +usage() { + echo "Usage: $0 [OPTIONS] [CONFIG [...]]" + echo " -h display this help text" + echo " -m only merge the fragments, do not execute the make command" + echo " -n use allnoconfig instead of alldefconfig" + echo " -r list redundant entries when merging fragments" + echo " -y make builtin have precedence over modules" + echo " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead." + echo " -s strict mode. Fail if the fragment redefines any value." + echo " -Q disable warning messages for overridden options." + echo + echo "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_ environment variable." +} + +RUNMAKE=true +ALLTARGET=alldefconfig +WARNREDUN=false +BUILTIN=false +OUTPUT=. +STRICT=false +CONFIG_PREFIX=${CONFIG_-CONFIG_} +WARNOVERRIDE=echo + +while true; do + case $1 in + "-n") + ALLTARGET=allnoconfig + shift + continue + ;; + "-m") + RUNMAKE=false + shift + continue + ;; + "-h") + usage + exit + ;; + "-r") + WARNREDUN=true + shift + continue + ;; + "-y") + BUILTIN=true + shift + continue + ;; + "-O") + if [ -d $2 ];then + OUTPUT=$(echo $2 | sed 's/\/*$//') + else + echo "output directory $2 does not exist" 1>&2 + exit 1 + fi + shift 2 + continue + ;; + "-s") + STRICT=true + shift + continue + ;; + "-Q") + WARNOVERRIDE=true + shift + continue + ;; + *) + break + ;; + esac +done + +if [ "$#" -lt 1 ] ; then + usage + exit +fi + +if [ -z "$KCONFIG_CONFIG" ]; then + if [ "$OUTPUT" != . ]; then + KCONFIG_CONFIG=$(readlink -m -- "$OUTPUT/.config") + else + KCONFIG_CONFIG=.config + fi +fi + +INITFILE=$1 +shift; + +if [ ! -r "$INITFILE" ]; then + echo "The base file '$INITFILE' does not exist. Exit." >&2 + exit 1 +fi + +MERGE_LIST=$* +SED_CONFIG_EXP1="s/^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)=.*/\1/p" +SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p" + +TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX) +MERGE_FILE=$(mktemp ./.merge_tmp.config.XXXXXXXXXX) + +echo "Using $INITFILE as base" + +trap clean_up EXIT + +cat $INITFILE > $TMP_FILE + +# Merge files, printing warnings on overridden values +for ORIG_MERGE_FILE in $MERGE_LIST ; do + echo "Merging $ORIG_MERGE_FILE" + if [ ! -r "$ORIG_MERGE_FILE" ]; then + echo "The merge file '$ORIG_MERGE_FILE' does not exist. Exit." >&2 + exit 1 + fi + cat $ORIG_MERGE_FILE > $MERGE_FILE + CFG_LIST=$(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE) + + for CFG in $CFG_LIST ; do + grep -q -w $CFG $TMP_FILE || continue + PREV_VAL=$(grep -w $CFG $TMP_FILE) + NEW_VAL=$(grep -w $CFG $MERGE_FILE) + BUILTIN_FLAG=false + if [ "$BUILTIN" = "true" ] && [ "${NEW_VAL#CONFIG_*=}" = "m" ] && [ "${PREV_VAL#CONFIG_*=}" = "y" ]; then + ${WARNOVERRIDE} Previous value: $PREV_VAL + ${WARNOVERRIDE} New value: $NEW_VAL + ${WARNOVERRIDE} -y passed, will not demote y to m + ${WARNOVERRIDE} + BUILTIN_FLAG=true + elif [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then + ${WARNOVERRIDE} Value of $CFG is redefined by fragment $ORIG_MERGE_FILE: + ${WARNOVERRIDE} Previous value: $PREV_VAL + ${WARNOVERRIDE} New value: $NEW_VAL + ${WARNOVERRIDE} + if [ "$STRICT" = "true" ]; then + STRICT_MODE_VIOLATED=true + fi + elif [ "$WARNREDUN" = "true" ]; then + ${WARNOVERRIDE} Value of $CFG is redundant by fragment $ORIG_MERGE_FILE: + fi + if [ "$BUILTIN_FLAG" = "false" ]; then + sed -i "/$CFG[ =]/d" $TMP_FILE + else + sed -i "/$CFG[ =]/d" $MERGE_FILE + fi + done + cat $MERGE_FILE >> $TMP_FILE +done + +if [ "$STRICT_MODE_VIOLATED" = "true" ]; then + echo "The fragment redefined a value and strict mode had been passed." + exit 1 +fi + +if [ "$RUNMAKE" = "false" ]; then + cp -T -- "$TMP_FILE" "$KCONFIG_CONFIG" + echo "#" + echo "# merged configuration written to $KCONFIG_CONFIG (needs make)" + echo "#" + exit +fi + +# If we have an output dir, setup the O= argument, otherwise leave +# it blank, since O=. will create an unnecessary ./source softlink +OUTPUT_ARG="" +if [ "$OUTPUT" != "." ] ; then + OUTPUT_ARG="O=$OUTPUT" +fi + + +# Use the merged file as the starting point for: +# alldefconfig: Fills in any missing symbols with Kconfig default +# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set +make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET + + +# Check all specified config values took (might have missed-dependency issues) +for CFG in $(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $TMP_FILE); do + + REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE) + ACTUAL_VAL=$(grep -w -e "$CFG" "$KCONFIG_CONFIG" || true) + if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then + echo "Value requested for $CFG not in final .config" + echo "Requested value: $REQUESTED_VAL" + echo "Actual value: $ACTUAL_VAL" + echo "" + fi +done -- Gitee From 6639f25eb009c8a43eb4abd5a2a385b8160a28d5 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Wed, 14 Jun 2023 01:42:26 +0800 Subject: [PATCH 78/89] feature: call merge_config.sh to apply config fragments merge_config.sh is better than simple append, it can report and fix up redefine, override builtin than modules and so forth. Signed-off-by: Zhangjin Wu --- tools/kernel/feature-config.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/kernel/feature-config.sh b/tools/kernel/feature-config.sh index b451b20..8953759 100755 --- a/tools/kernel/feature-config.sh +++ b/tools/kernel/feature-config.sh @@ -27,6 +27,8 @@ KFD_BSP=${TOP_DIR}/boards/${BOARD}/bsp/feature/linux KFD=${TOP_SRC}/feature/linux FEATURE="$(echo $FEATURE | tr ',' ' ')" +MT="${TOP_DIR}/tools/kernel/merge_config.sh -m -y -O ${KERNEL_OUTPUT} ${KERNEL_OUTPUT}/.config" + for d in $KFD_CORE do for f in $FEATURE @@ -40,9 +42,13 @@ do echo "Applying feature: $f" - [ -f "$path/config" ] && cat $path/config >> ${KERNEL_OUTPUT}/.config - [ -f "$path/config.$XARCH.$MACH" ] && cat $path/config.$XARCH.$MACH >> ${KERNEL_OUTPUT}/.config - [ -f "$path/config.$MACH" ] && cat $path/config.$MACH >> ${KERNEL_OUTPUT}/.config + configfiles="" + for c in $path/config $path/config.$XARCH.$MACH $path/config.$MACH + do + [ -f "$c" ] && configfiles="$configfiles $c" + done + + [ -n "$configfiles" ] && $MT $configfiles done #f done #d @@ -60,9 +66,13 @@ do echo "Applying feature: $f" - [ -f "$path/config" ] && cat $path/config >> ${KERNEL_OUTPUT}/.config - [ -f "$path/config.$XARCH.$MACH" ] && cat $path/config.$XARCH.$MACH >> ${KERNEL_OUTPUT}/.config - [ -f "$path/config.$MACH" ] && cat $path/config.$MACH >> ${KERNEL_OUTPUT}/.config + configfiles="" + for c in $path/config $path/config.$XARCH.$MACH $path/config.$MACH + do + [ -f "$c" ] && configfiles="$configfiles $c" + done + + [ -n "$configfiles" ] && $MT $configfiles done #path done #d done #f -- Gitee From f8d4146a729fe0a36a0823b375d0890139877995 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 08:45:40 +0800 Subject: [PATCH 79/89] feature: enable the new additional configs after merge Signed-off-by: Zhangjin Wu --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ac35286..ed97894 100644 --- a/Makefile +++ b/Makefile @@ -2889,6 +2889,7 @@ kernel-olddefconfig kernel-menuconfig: $(call __stamp,kernel,defconfig) $(call _ $(call __stamp,kernel,defconfig.feature): $(ENV_FILES) $(Q)echo "Appling kernel feature configs: $(FEATURE)" $(Q)$(KERNEL_FEATURE_CONFIG_TOOL) $(ARCH) $(XARCH) $(BOARD) $(LINUX) $(KERNEL_ABS_SRC) $(KERNEL_BUILD) "$(FEATURE)" || true + $(Q)$(call make_kernel,$(or $(KERNEL_OLDDEFCONFIG),olddefconfig)) $(Q)touch $@ endif -- Gitee From f3f8506642b2529cf511c8fbf4ff558622c47a37 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 09:39:24 +0800 Subject: [PATCH 80/89] nolibc: add testing script This allows to run nolibc test for a target architecture or more than one at the same time. Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 tools/testing/nolibc.sh diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh new file mode 100755 index 0000000..5fa19a8 --- /dev/null +++ b/tools/testing/nolibc.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# nolibc.sh -- test nolibc for all of the supported boards +# +# Usage: nolibc.sh [board] +# + +TOP_DIR=$(cd $(dirname $0)/../../ && pwd) + +def_boards="arm/vexpress-a9 \ + aarch64/virt \ + ppc/g3beige \ + i386/pc \ + x86_64/pc \ + mipsel/malta \ + riscv64/virt \ + riscv32/virt \ + s390x/s390-ccw-virtio" + +# Allow user test a target board +boards=$1 + +while [ -z "$boards" ] +do + echo "LOG: Available boards for nolibc testing:" + echo + echo $def_boards | tr ' ' '\n' | cat -n + echo + + read -p "LOG: Choose one or more for nolibc test? " boardnumbers + + boardnumbers="$(echo $boardnumbers | tr ',' ' ' | tr ';' ' ')" + for n in $boardnumbers + do + sednp="${n}p;$sednp" + done + boards=$(echo $def_boards | tr ' ' '\n' | sed -n "$sednp") + [ -z "$boards" ] && echo "Please choose a valid board number in the list." +done + +[ "$boards" == "all" ] && boards="$def_boards" + +TEST_LOGDIR=${TOP_DIR}/logging +TEST_LOGFILE=${TEST_LOGDIR}/nolibc.log +mkdir -p $TEST_LOGDIR + +rm -rf $TEST_LOGFILE + +for b in $boards +do + arch=$(echo $b | cut -d'/' -f1 | sed -e 's/mips.*/mips/g;s/s390.*/s390/g;s/riscv.*/riscv/g;s/ppc.*/powerpc/g') + arch_file=${TOP_DIR}/src/linux-stable/tools/include/nolibc/arch-$arch.h + + echo "=====================================================================" | tee -a $TEST_LOGFILE + if [ -f "$arch_file" ]; then + echo "LOG: running nolibc test for $b" | tee -a $TEST_LOGFILE + echo "=====================================================================" | tee -a $TEST_LOGFILE + + ARCH_LOGFILE=$TEST_LOGDIR/$arch-nolibc.log + rm -rf $ARCH_LOGFILE + time make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | col -bp | tee -a $ARCH_LOGFILE + cat $ARCH_LOGFILE >> $TEST_LOGFILE + + # Parse and report it, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile + echo "=====================================================================" | tee -a $TEST_LOGFILE + echo "LOG: testing report for $b:" | tee -a $TEST_LOGFILE + echo + awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++;print} /\[SKIPPED\][\r]*$$/{s++;print} \ + END{ printf("\n%d test(s) passed, %d skipped, %d failed.\n", p, s, f); \ + printf("See all results in %s\n", ARGV[1]) }' $ARCH_LOGFILE | tee -a $TEST_LOGFILE + + else + echo "LOG: current nolibc doesn't support $b" | tee -a $TEST_LOGFILE + fi +done + +echo +echo "LOG: see all results for all boards in $TEST_LOGFILE" +echo -- Gitee From b91a781ecf1b56c0934bfbfcf4dfd7e23538bae5 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 10:50:19 +0800 Subject: [PATCH 81/89] nolibc: clean up testing report Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 63 +++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index 5fa19a8..dec3c1b 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -40,29 +40,52 @@ done [ "$boards" == "all" ] && boards="$def_boards" -TEST_LOGDIR=${TOP_DIR}/logging -TEST_LOGFILE=${TEST_LOGDIR}/nolibc.log +TEST_LOGDIR=${TOP_DIR}/logging/nolibc +TEST_LOGFILE=${TEST_LOGDIR}/nolibc-test.log mkdir -p $TEST_LOGDIR rm -rf $TEST_LOGFILE +function get_arch +{ + local board="$1" + echo $board | cut -d'/' -f1 | sed -e 's/mips.*/mips/g;s/s390.*/s390/g;s/riscv.*/riscv/g;s/ppc.*/powerpc/g' +} + +function get_arch_file +{ + local arch="$1" + echo ${TOP_DIR}/src/linux-stable/tools/include/nolibc/arch-$arch.h +} + +function get_arch_logfile +{ + local arch="$1" + echo $TEST_LOGDIR/$arch-nolibc-test.log +} + +function print_line +{ + echo "=====================================================================" | tee -a $TEST_LOGFILE +} + for b in $boards do - arch=$(echo $b | cut -d'/' -f1 | sed -e 's/mips.*/mips/g;s/s390.*/s390/g;s/riscv.*/riscv/g;s/ppc.*/powerpc/g') - arch_file=${TOP_DIR}/src/linux-stable/tools/include/nolibc/arch-$arch.h + arch=$(get_arch $b) + arch_file=$(get_arch_file $arch) - echo "=====================================================================" | tee -a $TEST_LOGFILE + print_line if [ -f "$arch_file" ]; then echo "LOG: running nolibc test for $b" | tee -a $TEST_LOGFILE - echo "=====================================================================" | tee -a $TEST_LOGFILE + print_line - ARCH_LOGFILE=$TEST_LOGDIR/$arch-nolibc.log + ARCH_LOGFILE=$(get_arch_logfile $arch) rm -rf $ARCH_LOGFILE - time make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | col -bp | tee -a $ARCH_LOGFILE + make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $ARCH_LOGFILE cat $ARCH_LOGFILE >> $TEST_LOGFILE # Parse and report it, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile - echo "=====================================================================" | tee -a $TEST_LOGFILE + print_line echo "LOG: testing report for $b:" | tee -a $TEST_LOGFILE echo awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++;print} /\[SKIPPED\][\r]*$$/{s++;print} \ @@ -74,6 +97,28 @@ do fi done +echo +echo "LOG: testing summary:" +echo + +echo -e "arch/board\tresult" + +for b in $boards +do + arch=$(get_arch $b) + arch_file=$(get_arch_file $arch) + + if [ -f "$arch_file" ]; then + ARCH_LOGFILE=$(get_arch_logfile $arch) + printf "%-8s\t" $b + awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/{s++} \ + END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \ + printf(" See all results in %s\n", ARGV[1]) }' $ARCH_LOGFILE + else + echo "$b\tnot supported" + fi +done + echo echo "LOG: see all results for all boards in $TEST_LOGFILE" echo -- Gitee From 6cfc2b89191ddb3d1da32f7a01e0c9b42f1023fd Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 10:57:16 +0800 Subject: [PATCH 82/89] nolibc: all choose all boards Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index dec3c1b..bc1a4ac 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -24,11 +24,13 @@ while [ -z "$boards" ] do echo "LOG: Available boards for nolibc testing:" echo - echo $def_boards | tr ' ' '\n' | cat -n + echo all $def_boards | tr ' ' '\n' | cat -n echo read -p "LOG: Choose one or more for nolibc test? " boardnumbers + [ "$boardnumbers" == "1" ] && boards=all && break + boardnumbers="$(echo $boardnumbers | tr ',' ' ' | tr ';' ' ')" for n in $boardnumbers do -- Gitee From 70ef40b2a8acd464931ccf3bc44a29cbb4aabca2 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 11:03:06 +0800 Subject: [PATCH 83/89] nolibc: fix up board log file different boards share the same arch, use board instead of arch to specify the log file name. Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index bc1a4ac..20b0807 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -60,10 +60,10 @@ function get_arch_file echo ${TOP_DIR}/src/linux-stable/tools/include/nolibc/arch-$arch.h } -function get_arch_logfile +function get_board_logfile { - local arch="$1" - echo $TEST_LOGDIR/$arch-nolibc-test.log + local board="$(echo $1 | tr '/' '-')" + echo $TEST_LOGDIR/$board-nolibc-test.log } function print_line @@ -81,18 +81,18 @@ do echo "LOG: running nolibc test for $b" | tee -a $TEST_LOGFILE print_line - ARCH_LOGFILE=$(get_arch_logfile $arch) - rm -rf $ARCH_LOGFILE - make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $ARCH_LOGFILE - cat $ARCH_LOGFILE >> $TEST_LOGFILE + BOARD_LOGFILE=$(get_board_logfile $b) + rm -rf $BOARD_LOGFILE + make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $BOARD_LOGFILE + cat $BOARD_LOGFILE | col -bp >> $TEST_LOGFILE # Parse and report it, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile print_line echo "LOG: testing report for $b:" | tee -a $TEST_LOGFILE - echo + echo awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++;print} /\[SKIPPED\][\r]*$$/{s++;print} \ END{ printf("\n%d test(s) passed, %d skipped, %d failed.\n", p, s, f); \ - printf("See all results in %s\n", ARGV[1]) }' $ARCH_LOGFILE | tee -a $TEST_LOGFILE + printf("See all results in %s\n", ARGV[1]) }' $BOARD_LOGFILE | tee -a $TEST_LOGFILE else echo "LOG: current nolibc doesn't support $b" | tee -a $TEST_LOGFILE @@ -111,11 +111,11 @@ do arch_file=$(get_arch_file $arch) if [ -f "$arch_file" ]; then - ARCH_LOGFILE=$(get_arch_logfile $arch) + BOARD_LOGFILE=$(get_board_logfile $b) printf "%-8s\t" $b awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/{s++} \ END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \ - printf(" See all results in %s\n", ARGV[1]) }' $ARCH_LOGFILE + printf(" See all results in %s\n", ARGV[1]) }' $BOARD_LOGFILE else echo "$b\tnot supported" fi -- Gitee From 0415bdf88872855bdb81b6959cb62493162b2e8b Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 11:16:09 +0800 Subject: [PATCH 84/89] nolibc: allow build nolibc-test with header Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index 20b0807..1c10ba0 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -20,6 +20,9 @@ def_boards="arm/vexpress-a9 \ # Allow user test a target board boards=$1 +# Allow pass nolibc_inc via environment +[ -z "$nolibc_inc" ] && nolibc_inc=sysroot + while [ -z "$boards" ] do echo "LOG: Available boards for nolibc testing:" @@ -83,7 +86,7 @@ do BOARD_LOGFILE=$(get_board_logfile $b) rm -rf $BOARD_LOGFILE - make test f=nolibc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $BOARD_LOGFILE + make test f=nolibc nolibc_inc=$nolibc_inc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $BOARD_LOGFILE cat $BOARD_LOGFILE | col -bp >> $TEST_LOGFILE # Parse and report it, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -- Gitee From 826ac1fb78f3fa0fb0d499f3d56cf73d92ad0f69 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 11:27:25 +0800 Subject: [PATCH 85/89] nolibc: add loongarch64/virt test support Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index 1c10ba0..c6abfb8 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -13,6 +13,7 @@ def_boards="arm/vexpress-a9 \ i386/pc \ x86_64/pc \ mipsel/malta \ + loongarch64/virt \ riscv64/virt \ riscv32/virt \ s390x/s390-ccw-virtio" @@ -54,7 +55,7 @@ rm -rf $TEST_LOGFILE function get_arch { local board="$1" - echo $board | cut -d'/' -f1 | sed -e 's/mips.*/mips/g;s/s390.*/s390/g;s/riscv.*/riscv/g;s/ppc.*/powerpc/g' + echo $board | cut -d'/' -f1 | sed -e 's/mips.*/mips/g;s/s390.*/s390/g;s/riscv.*/riscv/g;s/ppc.*/powerpc/g;s/loongarch.*/loongarch/g' } function get_arch_file -- Gitee From f7d0941dfbff00bc7a6664da06342621b998c6eb Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Thu, 15 Jun 2023 11:27:46 +0800 Subject: [PATCH 86/89] nolibc: fix up boards selection Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index c6abfb8..9c35bd0 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -40,7 +40,7 @@ do do sednp="${n}p;$sednp" done - boards=$(echo $def_boards | tr ' ' '\n' | sed -n "$sednp") + boards=$(echo all $def_boards | tr ' ' '\n' | sed -n "$sednp") [ -z "$boards" ] && echo "Please choose a valid board number in the list." done -- Gitee From bde96e2723dc6bd7353840f7df1bcecea468cfd3 Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Tue, 20 Jun 2023 01:40:13 +0800 Subject: [PATCH 87/89] nolibc: fix up not supported prompt print Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index 9c35bd0..3f64122 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -121,7 +121,7 @@ do END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \ printf(" See all results in %s\n", ARGV[1]) }' $BOARD_LOGFILE else - echo "$b\tnot supported" + echo -e "$b\tnot supported" fi done -- Gitee From 64c82ddc21c6f4945498a8b7398666f18a43e63c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Tue, 20 Jun 2023 01:52:31 +0800 Subject: [PATCH 88/89] x86_64/pc: add noapic for nolibc boot Fix up such error: APIC: Switch to symmetric I/O mode setup ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1 ..MP-BIOS bug: 8254 timer not connected to IO-APIC ...trying to set up timer (IRQ0) through the 8259A ... ..... (found apic 0 pin 2) ... ....... failed. ...trying to set up timer as Virtual Wire IRQ... ..... failed. ...trying to set up timer as ExtINT IRQ... ..... failed :(. Kernel panic - not syncing: IO-APIC + timer doesn't work! Boot with apic=debug and send a report. Then try booting with the 'noapic' option. This may due to missing some config options in nolibc config. Signed-off-by: Zhangjin Wu --- boards/x86_64/pc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/x86_64/pc/Makefile b/boards/x86_64/pc/Makefile index 2a6e09a..a10264b 100644 --- a/boards/x86_64/pc/Makefile +++ b/boards/x86_64/pc/Makefile @@ -46,4 +46,4 @@ KIMAGE ?= $(BSP_KERNEL)/$(LINUX)/bzImage ROOTFS ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs.cpio.gz ROOTFS[LINUX_v2.6.12.6] ?= $(BSP_ROOT)/$(BUILDROOT)/rootfs32.cpio.gz # Workaround boot issue -XKCLI := lpj=246205838 raid=noautodetect +XKCLI := noapic lpj=246205838 raid=noautodetect -- Gitee From 4ef679aa4c41536f2c418de59b19e4ec8336372c Mon Sep 17 00:00:00 2001 From: Zhangjin Wu Date: Tue, 20 Jun 2023 08:07:54 +0800 Subject: [PATCH 89/89] nolibc: allow set nolibc test timeout It is mainly for auto detection of the kernel shutdown failure. Signed-off-by: Zhangjin Wu --- tools/testing/nolibc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh index 3f64122..2b3d066 100755 --- a/tools/testing/nolibc.sh +++ b/tools/testing/nolibc.sh @@ -23,6 +23,7 @@ boards=$1 # Allow pass nolibc_inc via environment [ -z "$nolibc_inc" ] && nolibc_inc=sysroot +[ -z "$nolibc_timeout" ] && nolibc_timeout=10 while [ -z "$boards" ] do @@ -87,7 +88,7 @@ do BOARD_LOGFILE=$(get_board_logfile $b) rm -rf $BOARD_LOGFILE - make test f=nolibc nolibc_inc=$nolibc_inc DEVMODE=1 TEST_TIMEOUT=10 b=$b | tee -a $BOARD_LOGFILE + make test f=nolibc nolibc_inc=$nolibc_inc DEVMODE=1 TEST_TIMEOUT=$nolibc_timeout b=$b | tee -a $BOARD_LOGFILE cat $BOARD_LOGFILE | col -bp >> $TEST_LOGFILE # Parse and report it, based on src/linux-stable/tools/testing/selftests/nolibc/Makefile -- Gitee