diff --git a/.gitmodules b/.gitmodules index 47c8805e00ec56a459a6bc2ecd16af63a101bedf..22d7f07e7e9764d73125c40bf4805d933d263899 100644 --- a/.gitmodules +++ b/.gitmodules @@ -82,3 +82,11 @@ ignore = all path = boards/arm/ebf-imx6ull/bsp url = https://gitee.com/tinylab/ebf-imx6ull.git +[submodule "boards/loongarch64/virt/bsp"] + 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/.labbegin b/.labbegin index 3f5229f7b7af3b3ff3a902a61453b6261c1f72d2..cf295bdc52b390917b9527482021c8c88e5503f9 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) diff --git a/Makefile b/Makefile index 0f3daaa057cd737b349bc3e6408ae72b1b5f062c..ed9789402ebec2b4e9dd49ea26de0afaed20a563 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),) @@ -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) @@ -464,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) @@ -969,9 +979,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) @@ -1188,12 +1200,25 @@ 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 + 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 + 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 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_SRC ?= $(nolibc_src) +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_BIN := $(KERNEL_BUILD)/nolibc/init NOLIBC_OBJ := $(KERNEL_BUILD)/nolibc/init.o NOLIBC_FLT := $(KERNEL_BUILD)/nolibc/init.flt @@ -1204,6 +1229,18 @@ 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 +ifeq ($(nolibc_src),hello) + override nolibc_src := $(nolibc-hello) +endif +NOLIBC_SRC ?= $(nolibc_src) + +ifneq ($(nolibc_test),) + XKCLI += NOLIBC_TEST=$(nolibc_test) +endif + ifeq ($(NOMMU),1) _NOLIBC_BIN := $(NOLIBC_FLT) else @@ -1219,16 +1256,19 @@ 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)) + +# Set TEST_ROOTDEV +TEST_ROOTDEV ?= $(ROOTDEV) endif ifeq ($(_PBR), 0) @@ -1328,7 +1368,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) @@ -1363,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 @@ -1406,7 +1450,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) @@ -1435,7 +1479,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 @@ -1464,7 +1508,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 @@ -1549,8 +1593,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) @@ -1618,7 +1664,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 @@ -1777,14 +1823,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'." \ - && exit 1) + && echo "ERR: Please backup important changes on demand and run 'make $1-cleanup' or simply do a 'make $1-checkout -t'." \ + && exit 1); \ + else \ + touch $$@; \ + fi $1-checkout: $$(call __stamp,$1,checkout) @@ -1798,7 +1849,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,,$$@))) @@ -1827,7 +1878,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 @@ -1887,7 +1938,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 @@ -1928,7 +1979,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) @@ -1936,7 +1988,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;)) @@ -1968,14 +2020,15 @@ $$(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 define genclone ifneq ($$($(call _uc,$2)_NEW),) -NEW_$3CFG_FILE := $$(_BSP_CONFIG)/$$($(call _uc,$1)_FORK_)$2_$$($(call _uc,$2)_NEW)_defconfig +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)) ifeq ($$(wildcard $$(NEW_PREBUILT_$(call _uc,$1)_DIR)),) @@ -2005,6 +2058,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: @@ -2048,7 +2109,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 @@ -2066,7 +2127,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) @@ -2129,13 +2192,14 @@ 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. # 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 # @@ -2190,6 +2254,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 @@ -2209,6 +2274,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))) @@ -2257,6 +2330,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 @@ -2295,9 +2370,9 @@ 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 apt install -y $$gcc_pkg \ && sudo update-alternatives --install /usr/bin/$(CCPRE)gcc $(CCPRE)gcc /usr/bin/$(CCPRE)gcc-$(GCC) $$((50+RANDOM%50)); \ fi @@ -2319,7 +2394,7 @@ toolchain-list: gcc-list: toolchain-list -PHONY += toolchain-list gcc-list +PHONY += toolchain-list gcc-list toolchain toolchain-info: @echo @@ -2345,7 +2420,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 @@ -2382,8 +2457,164 @@ 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) + +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) + +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-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 + +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 -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 + +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) + # 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 -Wl,-melf32lriscv_ilp32 + 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-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 -Wl,-melf_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 + +ifeq ($(nolibc_gc),1) + 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 + +# 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)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) + $(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) #$(warning $(call gensource,root,BUILDROOT)) @@ -2406,23 +2637,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)) @@ -2470,7 +2684,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 @@ -2513,6 +2727,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)),) @@ -2551,7 +2767,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 @@ -2569,6 +2785,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) @@ -2587,11 +2805,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 @@ -2616,8 +2836,9 @@ 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 # Linux Kernel targets @@ -2638,6 +2859,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 @@ -2666,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 @@ -2699,14 +2923,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)) @@ -2866,7 +3091,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 @@ -2880,6 +3105,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=) @@ -2915,7 +3142,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 @@ -2957,7 +3184,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 @@ -2971,7 +3198,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 @@ -2994,8 +3221,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) @@ -3011,7 +3236,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 @@ -3193,7 +3419,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 @@ -3201,98 +3427,7 @@ modules-config: module-setconfig module-getconfig: kernel-getconfig 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 - -# 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) -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 +PHONY += $(addprefix module-,config getconfig setconfig) modules-config _kernel: $(KERNEL_DEPS) $(call make_kernel,$(KT)) @@ -3412,7 +3547,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)) @@ -3486,7 +3621,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 @@ -3564,6 +3699,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)),) @@ -3686,7 +3823,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,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown endif # Kernel command line configuration @@ -3741,6 +3879,7 @@ endif # Extra kernel command line CMDLINE += $(call _v,XKCLI,LINUX) +CMDLINE += $(call _v,KCLI,LINUX) # Graphic output? we prefer Serial port ;-) G ?= 0 @@ -3844,9 +3983,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 +4030,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)),) @@ -3946,7 +4085,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))) @@ -4041,7 +4180,7 @@ endif CMDLINE := $(subst $space$space,$space,$(strip $(CMDLINE))) ifneq ($(U),1) - BOOT_CMD += -append "$(CMDLINE)" + BOOT_CMD += $(if $(findstring -kernel,$(BOOT_CMD)),-append "$(CMDLINE)") endif ifneq ($(TEST_REBOOT), 0) @@ -4071,11 +4210,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 @@ -4083,9 +4222,9 @@ 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; \ + 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 @@ -4253,7 +4392,10 @@ ifneq ($(BOOT_PREPARE),) _BOOT_DEPS += $(BOOT_PREPARE) endif _BOOT_DEPS += $(BOARD_SAVE) +# kernel builtin initramfs must be prepared before building kernel image +ifneq ($(ROOTDEV),/dev/null) _BOOT_DEPS += root-$(DEV_TYPE) +endif _BOOT_DEPS += $(UBOOT_IMGS) _BOOT_DEPS += $(DEBUG_CLIENT) _BOOT_DEPS += $(BOOT_DTB) @@ -4334,7 +4476,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 @@ -4377,7 +4519,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)) @@ -4414,7 +4556,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 @@ -4429,8 +4571,8 @@ force-%: $(Q)make $(NPD) $(subst force-,,$@)-cleanstamp $(Q)make $(NPD) $(subst force-,,$@) -PHONY += FORCE - FORCE: +PHONY += FORCE + .PHONY: $(PHONY) diff --git a/README.md b/README.md index 4e918e950f23b16f6ecabe306aad30ac5dfa39ec..ba38a8340b23548312fdee5065c744ec2a6d347e 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`): @@ -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 797f9f1d2935eb4e9eb2a51e46bda99405ef347a..938eef7541510894ca632df15f96471e38bfe1d1 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`) @@ -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" 列出支持的选项: diff --git a/boards/aarch64/virt/Makefile b/boards/aarch64/virt/Makefile index 9cba12a38a19c9c1e019cc2ca41fa7d24ed92788..f3d3911cd68010ea5c7af3d240aa548ed967b1f7 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 diff --git a/boards/arm/vexpress-a9/Makefile b/boards/arm/vexpress-a9/Makefile index 511bd01cd5cc46cb5cc11e531443fd0437c13f7b..acc7cb428b8faeb5b85d64e57e7304f372bc8cf1 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 diff --git a/boards/i386/pc/Makefile b/boards/i386/pc/Makefile index 51b50d0505995810c6ae023a58fe96af506ae999..45e73e30e6b9cd90493723fdb288c5224fdf9ac2 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 diff --git a/boards/loongarch64/virt/Makefile b/boards/loongarch64/virt/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0c508feb5cd8cd21360783f552b48d0d2d881a51 --- /dev/null +++ b/boards/loongarch64/virt/Makefile @@ -0,0 +1,32 @@ +# Copyright (C) 2023 Wu Zhangjin +_BASE := 1 +ARCH := loongarch +XARCH := loongarch64 +CPU ?= la464-loongarch-cpu +MEM ?= 1024M +SERIAL ?= ttyS0,115200 + +QEMU ?= v8.0.2 + +NETDEV_LIST ?= e1000 +NETDEV ?= e1000 + +LINUX ?= v6.3.6 + +HOST_GCC := 9 + +# no buildroot support for loongarch currently, use nolibc initrd by default +NOLIBC := $(or $(NOLIBC),1) + +ROOTDEV_LIST := /dev/ram0 /dev/nfs +ROOTDEV ?= /dev/ram0 + +# 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/loongarch64/virt/README.md b/boards/loongarch64/virt/README.md new file mode 100644 index 0000000000000000000000000000000000000000..03d988cd85b57d3bc93df87ba2aaf67c1142a27d --- /dev/null +++ b/boards/loongarch64/virt/README.md @@ -0,0 +1,26 @@ + +# loongarch64/virt board Usage + +## Select me + + $ make B=loongarch64/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 +* https://github.com/loongson/Firmware/blob/main/LoongArchVirtMachine/ diff --git a/boards/mipsel/malta/Makefile b/boards/mipsel/malta/Makefile index 7ddf36c0d86545c3d2d3f47fc089fa0abb17b6c0..a58bf262b9f2a3524a180739fa77bf9cc7ac7fd6 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 diff --git a/boards/ppc/g3beige/Makefile b/boards/ppc/g3beige/Makefile index 9005929e930557c780b479e5be2fb8a18c3958d2..2ebfaa0f51e20cf412fd0b41df88f643b82e9433 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 diff --git a/boards/riscv32/virt/Makefile b/boards/riscv32/virt/Makefile index 39377f9e4394420600606b60766b9c47fd0e2df8..d4a68f7940ee91b8291a64719f578034cbb57b38 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 diff --git a/boards/s390x/s390-ccw-virtio/Makefile b/boards/s390x/s390-ccw-virtio/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..47734ca8cf12abd8b7682c42ff5038e9bc193562 --- /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 := $(or $(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 0000000000000000000000000000000000000000..4afc5f0888c8e977aa9abec4ff69203861665be0 --- /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 diff --git a/boards/x86_64/pc/Makefile b/boards/x86_64/pc/Makefile index 9a71c21e966dd070681e21717e690103a1245803..a10264b93f4496a6338e86c29e06ea5772106ed5 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 @@ -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 diff --git a/prebuilt/toolchains/loongarch64/Makefile b/prebuilt/toolchains/loongarch64/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d5fbc1a405edeaacbf2124cd0dc0d256cc6d0878 --- /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 diff --git a/prebuilt/toolchains/s390x/Makefile b/prebuilt/toolchains/s390x/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..21375dfb52bab2f012b0d42206526aab30b62bf6 --- /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 diff --git a/src/feature/linux/nolibc/config b/src/feature/linux/nolibc/config new file mode 100644 index 0000000000000000000000000000000000000000..aa1773c92985bd945fcecbba1faf420eace9e470 --- /dev/null +++ b/src/feature/linux/nolibc/config @@ -0,0 +1,10 @@ +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 +CONFIG_SHMEM=y +CONFIG_TMPFS=y diff --git a/tools/kernel/feature-config.sh b/tools/kernel/feature-config.sh index b451b2036433b7a4b35f595d183184efd6ae6c70..8953759d68fa52b17b146b06de2cad02acd03008 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 diff --git a/tools/kernel/merge_config.sh b/tools/kernel/merge_config.sh new file mode 100755 index 0000000000000000000000000000000000000000..902eb429b9dbd92e060925fdefd06bf2fdd45b4b --- /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 diff --git a/tools/nolibc/wordsize.h b/tools/nolibc/wordsize.h new file mode 100644 index 0000000000000000000000000000000000000000..43d1893eda8147915e909e180822208789b00c62 --- /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 diff --git a/tools/testing/nolibc.sh b/tools/testing/nolibc.sh new file mode 100755 index 0000000000000000000000000000000000000000..2b3d066d3e0208807f7459a0bbb968846a5d394a --- /dev/null +++ b/tools/testing/nolibc.sh @@ -0,0 +1,131 @@ +#!/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 \ + loongarch64/virt \ + riscv64/virt \ + riscv32/virt \ + s390x/s390-ccw-virtio" + +# Allow user test a target board +boards=$1 + +# Allow pass nolibc_inc via environment +[ -z "$nolibc_inc" ] && nolibc_inc=sysroot +[ -z "$nolibc_timeout" ] && nolibc_timeout=10 + +while [ -z "$boards" ] +do + echo "LOG: Available boards for nolibc testing:" + echo + 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 + sednp="${n}p;$sednp" + done + boards=$(echo all $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/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;s/loongarch.*/loongarch/g' +} + +function get_arch_file +{ + local arch="$1" + echo ${TOP_DIR}/src/linux-stable/tools/include/nolibc/arch-$arch.h +} + +function get_board_logfile +{ + local board="$(echo $1 | tr '/' '-')" + echo $TEST_LOGDIR/$board-nolibc-test.log +} + +function print_line +{ + echo "=====================================================================" | tee -a $TEST_LOGFILE +} + +for b in $boards +do + arch=$(get_arch $b) + arch_file=$(get_arch_file $arch) + + print_line + if [ -f "$arch_file" ]; then + echo "LOG: running nolibc test for $b" | tee -a $TEST_LOGFILE + print_line + + BOARD_LOGFILE=$(get_board_logfile $b) + rm -rf $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 + 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} \ + END{ printf("\n%d test(s) passed, %d skipped, %d failed.\n", p, s, f); \ + 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 + 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 + 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]) }' $BOARD_LOGFILE + else + echo -e "$b\tnot supported" + fi +done + +echo +echo "LOG: see all results for all boards in $TEST_LOGFILE" +echo