diff --git a/.gitattributes b/.gitattributes
index 89c411b5c..5aa29e952 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,3 @@
*.c diff=cpp
*.h diff=cpp
+dist/ export-ignore
diff --git a/.gitignore b/.gitignore
index 70580bdd3..f39c82316 100644
--- a/.gitignore
+++ b/.gitignore
@@ -146,3 +146,7 @@ x509.genkey
# Clang's compilation database file
/compile_commands.json
+
+# Tencent dist files
+/dist/rpm
+/dist/workdir
diff --git a/Makefile b/Makefile
index 19ade6503..d51ceb701 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# dist_make: Tencent Dist Makefile, which contains dist-* make targets
+ifneq ($(shell echo $(MAKECMDGOALS) | grep "^dist-"),)
+include dist/Makefile
+else
+
# SPDX-License-Identifier: GPL-2.0
VERSION = 5
PATCHLEVEL = 4
SUBLEVEL = 119
-EXTRAVERSION = -1
+EXTRAVERSION = -19
NAME = Kleptomaniac Octopus
# *DOCUMENTATION*
@@ -1881,3 +1888,5 @@ FORCE:
# Declare the contents of the PHONY variable as phony. We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
+
+endif # dist_make
diff --git a/arch/x86/include/asm/msr-trace.h b/arch/x86/include/asm/msr-trace.h
index f6adbe968..788f23789 100644
--- a/arch/x86/include/asm/msr-trace.h
+++ b/arch/x86/include/asm/msr-trace.h
@@ -6,7 +6,7 @@
#define TRACE_INCLUDE_FILE msr-trace
#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH asm/
+#define TRACE_INCLUDE_PATH asm
#if !defined(_TRACE_MSR_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_MSR_H
diff --git a/arch/x86/include/asm/trace/fpu.h b/arch/x86/include/asm/trace/fpu.h
index 879b77792..fd86d4bd2 100644
--- a/arch/x86/include/asm/trace/fpu.h
+++ b/arch/x86/include/asm/trace/fpu.h
@@ -90,7 +90,7 @@ DEFINE_EVENT(x86_fpu, x86_fpu_xstate_check_failed,
);
#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH asm/trace/
+#define TRACE_INCLUDE_PATH asm/trace
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE fpu
#endif /* _TRACE_FPU_H */
diff --git a/arch/x86/include/asm/trace/hyperv.h b/arch/x86/include/asm/trace/hyperv.h
index ace464f09..8fecd21c6 100644
--- a/arch/x86/include/asm/trace/hyperv.h
+++ b/arch/x86/include/asm/trace/hyperv.h
@@ -74,7 +74,7 @@ TRACE_EVENT(hyperv_send_ipi_mask,
#endif /* CONFIG_HYPERV */
#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH asm/trace/
+#define TRACE_INCLUDE_PATH asm/trace
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE hyperv
#endif /* _TRACE_HYPERV_H */
diff --git a/arch/x86/include/asm/trace/mpx.h b/arch/x86/include/asm/trace/mpx.h
index 541330172..43b8e9ba4 100644
--- a/arch/x86/include/asm/trace/mpx.h
+++ b/arch/x86/include/asm/trace/mpx.h
@@ -125,7 +125,7 @@ void trace_bounds_exception_mpx(const struct mpx_bndcsr *bndcsr)
#endif /* CONFIG_X86_INTEL_MPX */
#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH asm/trace/
+#define TRACE_INCLUDE_PATH asm/trace
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE mpx
#endif /* _TRACE_MPX_H */
diff --git a/dist/Makefile b/dist/Makefile
new file mode 100644
index 000000000..3e931eee7
--- /dev/null
+++ b/dist/Makefile
@@ -0,0 +1,387 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# A simple and clean build system initially inspired by Fedora ARK Kernel and Tencent Linux Kernel public.
+#
+
+TOPDIR := $(shell git rev-parse --show-toplevel)
+ifeq ("$(TOPDIR)", "")
+ TOPDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..)
+endif
+
+DISTPATH = dist
+DISTDIR := $(TOPDIR)/$(DISTPATH)
+ifeq ("$(abspath $(DISTDIR)/Makefile)", "$(lastword $(MAKEFILE_LIST))")
+$(error Can't detect Makefile, aborting)
+endif
+
+### Downstream marker, update this when forking to another downstream
+KDIST =
+
+### Vendor mark
+VENDOR = tencent
+VENDOR_CAPITALIZED = Tencent
+URL = https://github.com/Tencent/TencentOS-kernel
+
+### Get native arch for binary build by default
+NATIVE_ARCH := $(shell uname -m | sed -e 's/amd64/x86_64/;s/arm64/aarch64/;s/*86$$/x86/')
+
+###### Build parameters, change them with `make =` ######
+# When building binary package, which arch to build against
+ARCH := $(NATIVE_ARCH)
+# ARCH to be covered by spec file
+SPEC_ARCH := x86_64 aarch64 riscv64
+# Kernel variant, will be appended to kernel release string as suffix
+# to indicate this is a variant kernel (eg. debug; minimal;)
+VARIANT :=
+# Which kernel config to use, this build system supports multiple config targets,
+# Get the available config by scripts/ls-config.sh
+CONFIG := generic-release
+# Build a specific tag/commit with `make TAG=` or `make COMMIT=`
+TAG := $(COMMIT)
+# Extra RPM flags
+RPMFLAGS :=
+####### Build parameters end ######
+
+### Basic variables
+DISTCONFIGDIR = $(DISTDIR)/configs
+DISTWORKDIR = $(DISTDIR)/workdir
+
+DISTTEMPLATES = $(wildcard $(DISTDIR)/templates/*)
+DISTCONFIGS = $(shell find $(DISTDIR)/configs -type f)
+DISTSCRIPTS = $(wildcard $(DISTDIR)/scripts/*)
+DISTSOURCES = $(wildcard $(DISTDIR)/sources/*)
+DISTKABIS = $(wildcard $(DISTDIR)/kabi/*)
+DISTFILES = $(DISTDIR) $(DISTTEMPLATES) $(DISTCONFIGS) $(DISTSCRIPTS) $(DISTSOURCES) $(DISTKABIS)
+
+### Force unify arch name, so Kbuild, and other Makefiles can work seamlessly
+# BUILD_ARCH is for RPM, Dist make
+BUILD_ARCH := $(ARCH)
+override BUILD_ARCH := $(shell echo $(BUILD_ARCH) | sed -e 's/amd64/x86_64/;s/arm64/aarch64/;s/*86$$/x86/')
+# ARCH is for Kbuild
+override ARCH := $(shell echo $(BUILD_ARCH) | sed -e 's/amd64/x86_64/;s/aarch64/arm64/;s/*86$$/x86/')
+
+### Check if TAG is valid
+TAG := HEAD
+COMMIT := $(shell git rev-parse --verify --quiet $(TAG))
+ifeq ($(COMMIT),)
+$(error Invalid git reference, tag '$(TAG)' commit '$(COMMIT)', aborting)
+endif
+
+### Build files
+KFULLVER := $(shell $(DISTDIR)/scripts/get-version.sh $(COMMIT))
+CONFIGFILE := $(shell $(DISTDIR)/scripts/ls-config-files.sh $(CONFIG))
+WORKDIRS = $(DISTWORKDIR) $(RPM_TOPDIR) $(RPM_BUILDDIR) $(RPM_RPMDIR) $(RPM_SOURCEDIR) $(RPM_SPECDIR) $(RPM_SRCRPMDIR) $(RPM_BUILDROOTDIR)
+SPECFILE = $(RPM_SOURCEDIR)/kernel.spec
+TARFILE = $(RPM_SOURCEDIR)/kernel-$(KFULLVER).tar
+TESTPATCH = $(RPM_SOURCEDIR)/linux-kernel-test.patch
+ifeq ($(CONFIGFILE),)
+$(error Invalid CONFIG value '$(CONFIG)', no matching config target found)
+endif
+
+### RPM files
+RPM_TOPDIR := $(DISTDIR)/rpm
+RPM_BUILDDIR := $(RPM_TOPDIR)/BUILD
+RPM_RPMDIR := $(RPM_TOPDIR)/RPMS
+RPM_SOURCEDIR := $(RPM_TOPDIR)/SOURCES
+RPM_SPECDIR := $(RPM_TOPDIR)/SPECS
+RPM_SRCRPMDIR := $(RPM_TOPDIR)/SRPMS
+RPM_BUILDROOTDIR := $(RPM_TOPDIR)/BUILDROOT
+
+### RPM build options
+# All params enabled by default (except kABI check, see below), DEFAULT_ENABLED overrides DEFAULT_DISABLE.
+DEFAULT_DISABLED=
+DEFAULT_ENABLED=
+
+## A few shortcut for commonly used params:
+# Disable KABI check by default
+KABI=0
+ifeq ($(KABI), 0)
+override DEFAULT_DISABLED := kabichk $(DEFAULT_DISABLED)
+endif
+
+# Enabled module sign by default
+MODSIGN=1
+ifeq ($(MODSIGN), 0)
+override DEFAULT_DISABLED := modsign $(DEFAULT_DISABLED)
+endif
+
+# Allow to skip RPM dependency check
+NODEP=0
+ifeq ($(NODEP), 1)
+override RPMFLAGS := --nodeps $(RPMFLAGS)
+endif
+
+# Crossbuild
+ifneq ($(BUILD_ARCH),$(NATIVE_ARCH))
+RPMCROSSFLAGS = --with crossbuild --target $(BUILD_ARCH) --define "_cross_compile $(BUILD_ARCH)-linux-gnu-"
+else
+RPMCROSSFLAGS = --without crossbuild
+endif
+
+# For re-distribute to another distro
+ifneq ($(DISTRO),)
+override RPMFLAGS := --define "dist .$(DISTRO)" $(RPMFLAGS)
+$(info "NOTE: DISTRO is set, building for another distro $(DISTRO)")
+$(info " You shoudn't do this unless you know what you are doing.")
+endif
+
+# Always make sure workdir exists
+$(shell mkdir -p $(WORKDIRS))
+
+default: dist-help
+
+$(TARFILE):
+ @echo "Generating kernel source tar: $(TARFILE)"
+ @cd $(TOPDIR); git archive $(COMMIT) $(TOPDIR) --format=tar --prefix=kernel-$(KFULLVER)/ --output $(TARFILE)
+
+dist-tarball: $(TARFILE)
+ @echo "$(TARFILE)"
+
+$(CONFIGFILE): $(DISTFILES)
+ @echo "Generating kernel config style '$(CONFIG)'"
+ @$(DISTDIR)/scripts/gen-configs.sh $(CONFIG)
+
+dist-configs: $(CONFIGFILE)
+dist-config: dist-configs
+ rm -f $(TOPDIR)/.config
+ cp $(RPM_SOURCEDIR)/$(CONFIG).$(BUILD_ARCH).config $(TOPDIR)/.config
+ @printf "\033[0;32mDefault kernel config copied as $(TOPDIR)/.config\033[0m\n"
+
+# TODO: Build from a unclean tree is not working yet
+# which can't be detected by make.
+# $(TESTPATCH): always-rebuild
+# @git diff --no-renames HEAD -- ":(exclude)$(DISTDIR)" > $(TESTPATCH)
+# @[ -s "$(TESTPATCH)" ] && echo "Building from a unclean tree" || :
+
+# TODO: Remove always-rebuild - currently these targets depend on git worktree or variables,
+.PHONY: always-rebuild
+$(SPECFILE): always-rebuild
+ @echo "Generating kernel RPM spec: $(SPECFILE)"
+ @$(DISTDIR)/scripts/gen-spec.sh \
+ --commit "$(COMMIT)" \
+ --build-arch "$(SRPM_ARCH)" \
+ --kernel-config "$(CONFIG)" \
+ --kernel-variant "$(VARIANT)" \
+ --set-default-disabled "$(DEFAULT_DISABLED)" \
+ --set-default-enabled "$(DEFAULT_ENABLED)" \
+ > $(SPECFILE)
+ @grep -A2 "# == Package options ==" $(SPECFILE) | cut -c3-
+
+dist-specfile: $(SPECFILE) $(TOPDIR)/.config
+ @echo "$(SPECFILE)"
+
+dist-sources: dist-configs $(TARFILE) $(DISTSOURCES) $(DISTKABIS) $(SPECFILE)
+ @cp $(DISTSOURCES) $(DISTKABIS) $(RPM_SOURCEDIR)
+
+define DO_RPMBUILD
+@echo "=== DISTBUILD ==="
+@echo "Building kernel: $(KFULLVER)"
+@echo "Config style: $(CONFIG)"
+@echo "RPM build flags: $(1)"
+@echo "=== RPMBULID ==="
+rpmbuild \
+ --define '_topdir $(RPM_TOPDIR)' \
+ --define '_builddir $(RPM_BUILDDIR)' \
+ --define '_rpmdir $(RPM_RPMDIR)' \
+ --define '_sourcedir $(RPM_SOURCEDIR)' \
+ --define '_specdir $(RPM_SPECDIR)' \
+ --define '_srcrpmdir $(RPM_SRCRPMDIR)' \
+ --define '_buildrootdir $(RPM_BUILDROOTDIR)' \
+ $(SPECFILE) $(1)
+endef
+
+dist-srpm: dist-sources
+ $(call DO_RPMBUILD,-bs --nodeps --rmsource --rmspec $(RPMFLAGS))
+
+dist: dist-rpm
+dist-rpms: dist-rpm
+dist-rpm: dist-sources
+ $(call DO_RPMBUILD,-bb $(RPMCROSSFLAGS) --rmsource --rmspec $(RPMFLAGS))
+
+dist-prep: dist-sources
+ $(call DO_RPMBUILD,-bp --nodeps $(RPMCROSSFLAGS) $(RPMFLAGS))
+
+dist-new-release:
+ @$(DISTDIR)/scripts/make-release.sh
+
+dist-new-sub-release:
+ @$(DISTDIR)/scripts/make-release.sh --sub-release
+
+dist-clean:
+ @for i in $(RPM_TOPDIR)/* $(DISTWORKDIR); do \
+ echo Cleaning up $$i; \
+ rm -rf $$i/*; \
+ rm -rf $$i/.* 2>/dev/null; \
+ done; :;
+
+BUILDDEPS=$(shell rpmspec -q --buildrequires $(SPECFILE) | cut -d ' ' -f 1)
+MISSINGDEPS=$(shell echo "$(BUILDDEPS)" | xargs -n1 echo | while read -r _d; do rpm -q --whatprovides "$$_d" >/dev/null || echo "$$_d"; done)
+dist-check-buildrequires: $(SPECFILE)
+ @if [ -n "$(MISSINGDEPS)" ]; then \
+ echo "Error: Build dependency packages missing, please install: $(MISSINGDEPS)"; \
+ echo "Hint: You can try run \`make dist-install-buildrequires\` to fix this."; \
+ exit 1; \
+ fi;
+
+dist-install-buildrequires: $(SPECFILE)
+ @if [ -n "$(MISSINGDEPS)" ]; then \
+ echo "Installing kernel build dependency "$(MISSINGDEPS)" using yum..." \
+ echo "Missing dependency packages: $(MISSINGDEPS)..."; \
+ if [ -x /usr/bin/yum ]; then \
+ echo "Trying to install..."; \
+ echo "$(MISSINGDEPS)" | sudo xargs yum install -y && exit 0; \
+ else \
+ echo "Yum is not available for current user."; \
+ fi; \
+ echo "Error: Intallation failed."; \
+ exit 1; \
+ fi
+
+dist-check-requires: dist-check-buildrequires
+ @if [ ! -x /usr/bin/python3 ]; then \
+ echo "ERROR: Python 3 is required." ; \
+ exit 1; \
+ fi
+ @if [ ! -x /usr/bin/git ]; then \
+ echo "ERROR: Git is required." ; \
+ exit 1; \
+ fi
+
+dist-format-config:
+ @$(DISTDIR)/scripts/format-configs.sh
+dist-format-configs: dist-format-config
+
+dist-check-new-config:
+ @echo "Checking for unset Kconfig..."
+ @$(DISTDIR)/scripts/check-configs.sh check-new-configs $(CONFIG)
+dist-check-new-configs: dist-check-new-config
+
+dist-fix-new-config:
+ @echo "Fixing unset Kconfig issue..."
+ @$(DISTDIR)/scripts/check-configs.sh check-new-configs --autofix $(CONFIG)
+dist-fix-new-configs: dist-fix-new-config
+
+dist-check-dup-config:
+ @echo "Checking for duplicated Kconfig..."
+ @$(DISTDIR)/scripts/check-configs.sh check-dup-configs $(CONFIG)
+dist-check-dup-configs: dist-check-dup-config
+
+dist-fix-dup-config:
+ @echo "Fixing duplicated Kconfig issue..."
+ @$(DISTDIR)/scripts/check-configs.sh check-dup-configs --autofix $(CONFIG)
+dist-fix-dup-configs: dist-fix-dup-config
+
+dist-check-diff-config:
+ @echo "Checking for duplicated Kconfig..."
+ @$(DISTDIR)/scripts/check-configs.sh check-diff-configs $(CONFIG)
+dist-check-diff-configs: dist-check-diff-config
+
+dist-check-config: dist-check-new-config dist-check-dup-config dist-check-diff-config
+dist-check-configs: dist-check-config
+
+dist-check-commit:
+ @echo "Checking for new commits..."
+ @$(DISTDIR)/scripts/check-commits.sh
+dist-check-commits: dist-check-commit
+
+dist-check-tag:
+ @echo "Checking tag of '$(TAG)' ..."
+ @$(DISTDIR)/scripts/check-tag.sh '$(TAG)'
+
+dist-check-kabi: dist-sources
+ @echo "Checking kABI for $(BUILD_ARCH)..."
+ $(call DO_RPMBUILD,-bi $(RPMCROSSFLAGS) \
+ --without doc --without headers --without perf --without tools --without bpftool \
+ --without debuginfo --without selftest --without modsign \
+ --with kabichk \
+ )
+
+dist-update-kabi: KABI_WORKDIR:=$(shell mktemp -d $(DISTWORKDIR)/kabi.XXXX)
+dist-update-kabi: RPM_BUILDDIR:=$(KABI_WORKDIR)
+dist-update-kabi: dist-sources dist-check-buildrequires
+ @echo "Updating kABI for $(BUILD_ARCH)..."
+ $(call DO_RPMBUILD,-bc $(RPMCROSSFLAGS) \
+ --without doc --without headers --without perf --without tools --without bpftool \
+ --without debuginfo --without selftest --without modsign --without kabichk \
+ )
+ MODSYM=$$(find $(KABI_WORKDIR) -maxdepth 3 -type f -name 'Module.symvers'); \
+ if [ -f "$$MODSYM" ]; then \
+ echo "Using $$MODSYM as kABI reference file."; \
+ $(DISTDIR)/scripts/helper/update-kabi.sh \
+ $(DISTDIR)/kabi/Module.kabi_$(BUILD_ARCH) $$MODSYM > $(KABI_WORKDIR)/Module.kabi.updated; \
+ cp $(KABI_WORKDIR)/Module.kabi.updated $(DISTDIR)/kabi/Module.kabi_$(BUILD_ARCH); \
+ else \
+ echo "Failed to find Module.symvers."; \
+ exit 1; \
+ fi
+
+# Do a fast check
+dist-check: dist-check-commit dist-check-new-config
+dist-help:
+ @echo 'This helps you to manage, release, and develop $(VENDOR_CAPITALIZED) Linux kernel.'
+ @echo 'Use below make targets as sub-command:'
+ @echo
+ @echo 'NOTE: Before you submit any patch, please see the "Sanity check" targets and at lease run:'
+ @echo '`make dist-check`'
+ @echo 'And ensure there is no error.'
+ @echo
+ @echo 'For building a kernel RPM distrobution package:'
+ @echo ' dist, dist-rpms - Alias to dist-rpm.'
+ @echo ' dist-rpm - Create the binary RPMS for the kernel and put it under:'
+ @echo ' $(RPM_RPMDIR)'
+ @echo ' dist-srpm - Create a source RPM and put it under:'
+ @echo ' $(RPM_SRCRPMDIR)'
+ @echo ' dist-prep - Prep the kernel dist build source code under:'
+ @echo ' $(RPM_BUILDDIR)'
+ @echo
+ @echo 'Available params (most of these params are usable for all sub-commands besides dist-rpm/dist-srpm):'
+ @echo ' ARCH="$(ARCH)"'
+ @echo ' Target ARCH used for binary/RPM build.'
+ @echo ' SPEC_ARCH="$(SPEC_ARCH)"'
+ @echo ' Targer ARCH coverted by spec/SRPM build.'
+ @echo ' TAG="$(TAG)" (or COMMIT="$(COMMIT)")'
+ @echo ' Specify a git tag or commit, and this Makefile will build the kernel from that version.'
+ @echo ' VARIANT="$(VARIANT)"'
+ @echo ' Kernel variant, will be appended to kernel release string as suffix'
+ @echo ' to indicate this is a variant kernel (eg. debug; minimal;), especially'
+ @echo ' useful when combined with CONFIG='
+ @echo ' RPMFLAGS="$(RPMFLAGS)"'
+ @echo ' Extra RPM flags to be passed to rpmbuild for RPM bulding related commands.'
+ @echo ' CONFIG="$(CONFIG)"'
+ @echo ' Which kernel config to use, $(VENDOR_CAPITALIZED) build system supports multiple config targets,'
+ @echo ' Avaiable targets:'
+ @$(DISTDIR)/scripts/ls-config-targets.sh | xargs -n3 printf " %s %s %s\n"
+ @echo
+ @echo 'To make a new kernel version release:'
+ @echo ' dist-new-release - Update changelog, increase release number and tag a new commit properly.'
+ @echo ' dist-new-sub-release - Same as dist-new-release but increase the sub release number (eg. 5.18.0-1, 5.18.0-1.1, 5.18.0-1.2, ...).'
+ @echo
+ @echo 'Build prepare:'
+ @echo ' dist-check-requires - Check build time and dist targets package dependency.'
+ @echo ' dist-check-buildrequires - Check build time package dependency.'
+ @echo ' dist-install-buildrequires - Check and automatically install build time dependency, requires root.'
+ @echo
+ @echo 'Sanity check:'
+ @echo ' dist-check-commit - Check commit message and patch.'
+ @printf " \033[1;33m* Please at least ensure this check doesn't raise any error before submitting a patch.\033[0m\n"
+ @echo ' dist-check-diff-config - Check for invalid configs. If a CONFIG_XXX=y is set in config file but gone after make oldconfig,'
+ @echo ' it it considered a invalid config. There are many potential resons causing this, changed or missing'
+ @echo ' config dependency, deprecated config, auto-select configs, this tool will also provide some hint.'
+ @echo ' dist-check-dup-config - Check for duplicated configs, '
+ @echo ' dist-check-new-config - Check for unset configs. If any config is not set, kbuild will prompt during built time.'
+ @echo ' This helper will check for unset configs so you can set them properly in predefined config file.'
+ @echo 'Code clean up:'
+ @echo ' dist-fix-new-config - Same as dist-check-new-configs but automatically set unset configs to its default value and'
+ @echo ' update config files.'
+ @echo ' dist-fix-dup-config - Automatically remove duplicated configs.'
+ @echo " dist-format-config - Sort and simplify the base config files, won\'t change the final config output."
+ @printf ' \033[1;33m* Please run this before submitting any config change.\033[0m\n'
+ @echo ' dist-clean - Clean up directories under:'
+ @echo ' $(DISTDIR)'
+ @echo
+ @echo 'Configuration targets:'
+ @echo ' dist-configs - Generate dist config files, using config matrix in:'
+ @echo ' $(DISTDIR)/config/'
+ @echo ' dist-config - Generate config, and override .config file with the config corresponding'
+ @echo ' to arch $(BUILD_ARCH)'
+ @echo
diff --git a/dist/README b/dist/README
new file mode 100644
index 000000000..a171f5f91
--- /dev/null
+++ b/dist/README
@@ -0,0 +1,10 @@
+RPM based dist Makefile and build system for the Linux kernel.
+
+Run `make dist-help` to see the usage.
+
+Authors:
+Kairui Song
+Katrin Zhou
+Kaixu Xia
+
+Bundle with the Linux Kernel, licensed under the GPLv2
diff --git a/dist/configs/00base/defconfig/aarch64.config b/dist/configs/00base/defconfig/aarch64.config
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/configs/00base/defconfig/default.config b/dist/configs/00base/defconfig/default.config
new file mode 100644
index 000000000..2c8761954
--- /dev/null
+++ b/dist/configs/00base/defconfig/default.config
@@ -0,0 +1,8 @@
+CONFIG_BPF_SYSCALL=y
+CONFIG_DEBUG_INFO_BTF=y
+CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_IKCONFIG=m
+CONFIG_IKCONFIG_PROC=y
+CONFIG_MODULES=y
+CONFIG_MODVERSIONS=y
diff --git a/dist/configs/00base/defconfig/x86_64.config b/dist/configs/00base/defconfig/x86_64.config
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/configs/00base/generic/aarch64.config b/dist/configs/00base/generic/aarch64.config
new file mode 120000
index 000000000..742284636
--- /dev/null
+++ b/dist/configs/00base/generic/aarch64.config
@@ -0,0 +1 @@
+../../../../package/arm/config.default
\ No newline at end of file
diff --git a/dist/configs/00base/generic/default.config b/dist/configs/00base/generic/default.config
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/configs/00base/generic/x86_64.config b/dist/configs/00base/generic/x86_64.config
new file mode 120000
index 000000000..909e521f4
--- /dev/null
+++ b/dist/configs/00base/generic/x86_64.config
@@ -0,0 +1 @@
+../../../../package/default/config.default
\ No newline at end of file
diff --git a/dist/configs/50variant/debug/aarch64.config b/dist/configs/50variant/debug/aarch64.config
new file mode 100644
index 000000000..88c8ed1ce
--- /dev/null
+++ b/dist/configs/50variant/debug/aarch64.config
@@ -0,0 +1,17 @@
+CONFIG_DEBUG_PERF_USE_VMALLOC=y
+# CONFIG_DEBUG_VM is not set
+CONFIG_DEVMEM=y
+# CONFIG_IP_VS_DEBUG is not set
+CONFIG_KASAN=y
+CONFIG_KASAN_GENERIC=y
+# CONFIG_KASAN_HW_TAGS is not set
+CONFIG_KASAN_INLINE=y
+CONFIG_KDB_DEFAULT_ENABLE=0x1
+# CONFIG_LOCK_STAT is not set
+CONFIG_MAILBOX_TEST=m
+CONFIG_PANIC_ON_OOPS=y
+CONFIG_PANIC_ON_OOPS_VALUE=1
+CONFIG_PERCPU_TEST=m
+# CONFIG_RANDOM32_SELFTEST is not set
+CONFIG_SPI_DEBUG=y
+CONFIG_WQ_WATCHDOG=y
diff --git a/dist/configs/50variant/debug/default.config b/dist/configs/50variant/debug/default.config
new file mode 100644
index 000000000..c6fd43402
--- /dev/null
+++ b/dist/configs/50variant/debug/default.config
@@ -0,0 +1,127 @@
+CONFIG_ACPI_APEI_ERST_DEBUG=m
+CONFIG_ACPI_CONFIGFS=m
+CONFIG_ACPI_CUSTOM_METHOD=m
+CONFIG_ACPI_DEBUG=y
+CONFIG_ACPI_DEBUGGER=y
+CONFIG_ACPI_DEBUGGER_USER=m
+CONFIG_ACPI_EC_DEBUGFS=m
+CONFIG_ATH10K_DEBUG=y
+CONFIG_ATH10K_TRACING=y
+CONFIG_ATH_DEBUG=y
+# CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION is not set
+CONFIG_CAN_DEBUG_DEVICES=y
+CONFIG_CEPH_LIB_PRETTYDEBUG=y
+CONFIG_CFG80211_DEBUGFS=y
+CONFIG_CGROUP_DEBUG=y
+CONFIG_CPUMASK_OFFSTACK=y
+CONFIG_CRYPTO_DEV_CCP_DEBUGFS=y
+CONFIG_CSD_LOCK_WAIT_DEBUG=y
+CONFIG_DEBUG_ATOMIC_SLEEP=y
+CONFIG_DEBUG_CREDENTIALS=y
+CONFIG_DEBUG_IRQFLAGS=y
+CONFIG_DEBUG_KMEMLEAK=y
+CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y
+CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y
+CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE=40000
+CONFIG_DEBUG_LOCK_ALLOC=y
+CONFIG_DEBUG_MUTEXES=y
+CONFIG_DEBUG_NOTIFIERS=y
+CONFIG_DEBUG_OBJECTS=y
+CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1
+CONFIG_DEBUG_OBJECTS_FREE=y
+CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
+CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
+CONFIG_DEBUG_OBJECTS_TIMERS=y
+CONFIG_DEBUG_OBJECTS_WORK=y
+CONFIG_DEBUG_PAGEALLOC=y
+# CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT is not set
+CONFIG_DEBUG_PAGE_REF=y
+CONFIG_DEBUG_PER_CPU_MAPS=y
+CONFIG_DEBUG_PREEMPT=y
+CONFIG_DEBUG_RT_MUTEXES=y
+CONFIG_DEBUG_RWSEMS=y
+CONFIG_DEBUG_SG=y
+CONFIG_DEBUG_SPINLOCK=y
+CONFIG_DEBUG_STACK_USAGE=y
+CONFIG_DEBUG_VM=y
+CONFIG_DEBUG_VM_PGTABLE=y
+CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y
+CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=120
+CONFIG_DMABUF_DEBUG=y
+CONFIG_DMADEVICES_DEBUG=y
+CONFIG_DMADEVICES_VDEBUG=y
+CONFIG_DMA_API_DEBUG=y
+CONFIG_DMA_API_DEBUG_SG=y
+CONFIG_EDAC_DEBUG=y
+CONFIG_EXT4_DEBUG=y
+CONFIG_FAILSLAB=y
+# CONFIG_FAIL_FUNCTION is not set
+CONFIG_FAIL_IO_TIMEOUT=y
+CONFIG_FAIL_MAKE_REQUEST=y
+CONFIG_FAIL_MMC_REQUEST=y
+CONFIG_FAIL_PAGE_ALLOC=y
+CONFIG_FAIL_SUNRPC=y
+CONFIG_FAULT_INJECTION=y
+CONFIG_FAULT_INJECTION_DEBUG_FS=y
+CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y
+CONFIG_FSCACHE_OBJECT_LIST=y
+CONFIG_GENERIC_IRQ_DEBUGFS=y
+CONFIG_I2C_GPIO_FAULT_INJECTOR=y
+CONFIG_IOMMU_DEBUGFS=y
+CONFIG_IP_VS_DEBUG=y
+CONFIG_IWLWIFI_DEBUG=y
+CONFIG_IWLWIFI_DEVICE_TRACING=y
+CONFIG_KASAN_KUNIT_TEST=m
+# CONFIG_KASAN_OUTLINE is not set
+CONFIG_KASAN_VMALLOC=y
+CONFIG_KDB_CONTINUE_CATASTROPHIC=0
+CONFIG_KPROBE_EVENT_GEN_TEST=m
+CONFIG_LATENCYTOP=y
+CONFIG_LOCKDEP_BITS=16
+CONFIG_LOCKDEP_CHAINS_BITS=17
+CONFIG_LOCKDEP_CIRCULAR_QUEUE_BITS=12
+CONFIG_LOCKDEP_STACK_TRACE_BITS=19
+CONFIG_LOCKDEP_STACK_TRACE_HASH_BITS=14
+CONFIG_LOCK_EVENT_COUNTS=y
+CONFIG_LOCK_STAT=y
+CONFIG_MAC80211_DEBUGFS=y
+CONFIG_MAC80211_MESSAGE_TRACING=y
+CONFIG_MMIOTRACE=y
+CONFIG_NET_DEV_REFCNT_TRACKER=y
+CONFIG_NET_NS_REFCNT_TRACKER=y
+CONFIG_NFP_DEBUG=y
+CONFIG_NOUVEAU_DEBUG_MMU=y
+CONFIG_NOUVEAU_DEBUG_PUSH=y
+CONFIG_PAGE_TABLE_CHECK=y
+CONFIG_PAGE_TABLE_CHECK_ENFORCED=y
+# CONFIG_PANIC_ON_OOPS is not set
+CONFIG_PERCPU_STATS=y
+CONFIG_PM_ADVANCED_DEBUG=y
+CONFIG_PM_TEST_SUSPEND=y
+CONFIG_PM_TRACE_RTC=y
+CONFIG_PROVE_LOCKING=y
+CONFIG_PTDUMP_DEBUGFS=y
+CONFIG_QUOTA_DEBUG=y
+CONFIG_RANDOM32_SELFTEST=y
+CONFIG_RC_LOOPBACK=m
+CONFIG_RTLWIFI_DEBUG=y
+CONFIG_RTW88_DEBUG=y
+CONFIG_RTW88_DEBUGFS=y
+CONFIG_RTW89_DEBUGFS=y
+CONFIG_RTW89_DEBUGMSG=y
+CONFIG_SCF_TORTURE_TEST=m
+CONFIG_SND_CTL_VALIDATION=y
+CONFIG_SND_DEBUG=y
+CONFIG_SND_JACK_INJECTION_DEBUG=y
+CONFIG_SND_PCM_XRUN_DEBUG=y
+CONFIG_SND_SOC_SOF_DEBUG_PROBES=y
+CONFIG_SND_SOC_SOF_HDA_PROBES=y
+CONFIG_SND_VERBOSE_PRINTK=y
+CONFIG_SYNTH_EVENT_GEN_TEST=m
+CONFIG_TEST_FPU=m
+CONFIG_TEST_LIST_SORT=m
+CONFIG_TEST_MIN_HEAP=m
+CONFIG_TEST_STRING_HELPERS=m
+# CONFIG_USB_XHCI_DBGCAP is not set
+CONFIG_XFS_WARN=y
+CONFIG_ZRAM_MEMORY_TRACKING=y
diff --git a/dist/configs/50variant/debug/x86_64.config b/dist/configs/50variant/debug/x86_64.config
new file mode 100644
index 000000000..f981bef20
--- /dev/null
+++ b/dist/configs/50variant/debug/x86_64.config
@@ -0,0 +1,9 @@
+CONFIG_HYPERV_TESTING=y
+CONFIG_KASAN=y
+CONFIG_KASAN_GENERIC=y
+CONFIG_KASAN_INLINE=y
+CONFIG_PM_SLEEP_DEBUG=y
+# CONFIG_PM_TEST_SUSPEND is not set
+CONFIG_USB_XHCI_DBGCAP=y
+CONFIG_X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK=y
+CONFIG_X86_DEBUG_FPU=y
diff --git a/dist/configs/50variant/release/default.config b/dist/configs/50variant/release/default.config
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/kabi/Module.kabi_aarch64 b/dist/kabi/Module.kabi_aarch64
new file mode 120000
index 000000000..97f2669b5
--- /dev/null
+++ b/dist/kabi/Module.kabi_aarch64
@@ -0,0 +1 @@
+../../package/arm/Module.kabi_aarch64
\ No newline at end of file
diff --git a/dist/kabi/Module.kabi_riscv64 b/dist/kabi/Module.kabi_riscv64
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/kabi/Module.kabi_x86_64 b/dist/kabi/Module.kabi_x86_64
new file mode 120000
index 000000000..407d6f410
--- /dev/null
+++ b/dist/kabi/Module.kabi_x86_64
@@ -0,0 +1 @@
+../../package/default/Module.kabi_x86_64
\ No newline at end of file
diff --git a/dist/scripts/check-commits.sh b/dist/scripts/check-commits.sh
new file mode 100755
index 000000000..77edada62
--- /dev/null
+++ b/dist/scripts/check-commits.sh
@@ -0,0 +1,323 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check kernel commit messages
+
+# shellcheck source=./lib.sh
+. "$(dirname "$(realpath "$0")")/lib.sh"
+
+usage()
+{
+ cat << EOF
+check-commit-msg.sh ...
+
+ --extra-author Who is triggering this check, check for corresponding signed-off-by in commit body
+ For example, if this script is triggered by a Merge Request, the one who submitted
+ the Merge Request should also sign all commits within the MR.
+
+ Can be also enabled by setting EXTRA_AUTHOR= in environmental variable.
+
+ --gen-report Generate error report under corrent directory for each commit being checked
+ in current directory.
+
+ Can be also enabled by setting GEN_REPORT=1 in environmental variable.
+
+ --output-dir Specify where the report should be put if '--gen-report' is used
+ An directory path is expected.
+
+ Defaults to current directory.
+
+ --vendor-only Author should be limited to vendor only.
+ (Git commit email address must end with @$VENDOR.com).
+EOF
+}
+
+if ! [[ -x "$TOPDIR/scripts/checkpatch.pl" ]]; then
+ die "This command requires scripts/checkpatch.pl"
+fi
+
+COMMITS=()
+HEAD_COMMIT=
+OUTPUT_DIR=$(pwd)
+VENDOR_ONLY=
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ --extra-author )
+ EXTRA_AUTHOR=$2
+ shift 2
+ ;;
+ --output-dir )
+ OUTPUT_DIR=$2
+ shift 2
+ ;;
+ --gen-report )
+ GEN_REPORT=1
+ shift
+ ;;
+ --vendor-only )
+ VENDOR_ONLY=1
+ shift
+ ;;
+ -* )
+ usage
+ exit 1
+ ;;
+ * )
+ COMMITS+=( "$1" )
+ shift
+ esac
+done
+
+if [[ -z "${COMMITS[*]}" ]]; then
+ echo "Checking all commits that are ahead of remote tracking branch."
+
+ if ! UPSTREAM_BASE=$(git -C "$repo" merge-base HEAD "@{u}" 2>/dev/null); then
+ warn "Can't find a valid upstream, will only check HEAD commit."
+ COMMITS=HEAD
+ else
+ if [[ $(git rev-list "$UPSTREAM_BASE..HEAD" --count) -eq 0 ]]; then
+ COMMITS="HEAD"
+ else
+ COMMITS="$UPSTREAM_BASE..HEAD"
+ fi
+ fi
+fi
+
+is_valid_commit() {
+ case $1 in
+ *[!0-9A-Fa-f]* | "" )
+ return 1
+ ;;
+ * )
+ if [ "${#1}" -lt 12 ] || [ "${#1}" -gt 41 ]; then
+ return 1
+ fi
+ ;;
+ esac
+
+ return 0
+}
+
+# Check if a commit id is valid upstream commit id
+# $1: commit id to check
+is_valid_upstream_commit() {
+ local commit=$1
+ local upstream_repo=(
+ "torvalds https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=<>"
+ "stable https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/patch/?id=<>"
+ "tip https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/patch/?id=<>"
+ )
+ local repo repo_name repo_url commit_url
+
+ for repo in "${upstream_repo[@]}"; do
+ repo_name=${repo%% *}
+ repo_url=${repo#* }
+ commit_url=${repo_url/<>/$commit}
+ if curl --fail --silent --output /dev/null "$commit_url"; then
+ echo "$commit_url"
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+# TODO(katinzhou): 需要测试。且能支持本地调用检查commit msg是否合规
+# Check a commit for all potential issues
+# returns number of issues found
+check_commit() {
+ local ret=0
+ local commit=$1
+ local commit_msg=$2
+
+ local author=$(git log --pretty=format:"%an" "$commit" -1)
+ local author_email=$(git log --pretty=format:"%ae" "$commit" -1)
+ local committer=$(git log --pretty=format:"%cn" "$commit" -1)
+ local committer_email=$(git log --pretty=format:"%ce" "$commit" -1)
+ local commit_body=$(git log --pretty=format:"%b" "$commit" -1)
+ local commit_summary=$(git log --pretty=format:"%s" "$commit" -1)
+
+ # Ignore merge commit
+ if [ "$(git show --no-patch --format="%P" "$commit" | wc -w)" -ne 1 ]; then
+ echo "Found merge commit $commit"
+ echo "NOTICE: This checking routine only follows one parent commit."
+ return 0
+ fi
+
+ local ignore_line="ERROR: Please use git commit description style 'commit <12+ chars of sha1> (\"\")'"
+
+ local patch_content
+ if ! patch_content=$(git format-patch --stdout -1 "$commit"); then
+ echo "ERROR: FATAL: Failed to format $commit into a patch"
+ echo
+ return 1
+ fi
+
+ if ! echo "$commit_body" | grep -iq "^checkpatch:.*\bno\b"; then
+ local patch_err
+ patch_err=$(echo "$patch_content" | "$TOPDIR/scripts/checkpatch.pl" --terse | grep -v "$ignore_line" | grep "ERROR: ")
+
+ if [[ -n "$patch_err" ]]; then
+ echo "ERROR: scripts/checkpatch.pl reported following error:"
+ echo " $patch_err"
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ fi
+
+ if ! echo "$commit_body" | grep -q "Signed-off-by: .*\b$author\b"; then
+ echo "ERROR: Commit author ($author) need to sign the commit, so a Signed-off-by: <$author's sign> is needed"
+ echo
+ ret=$(( ret + 1 ))
+ fi
+
+ if [[ $EXTRA_AUTHOR ]]; then
+ if ! echo "$commit_body" | grep -q "Signed-off-by: .*\b$EXTRA_AUTHOR\b"; then
+ echo "ERROR: Commit co-author (eg. MR author) need to sign the commit, so a Signed-off-by: <$EXTRA_AUTHOR's sign> is needed"
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ fi
+
+ upstream_commit=$(echo "$commit_body" | sed -nE "s/^(Upstream commit:|Upstream: commit) (\S+)/\2/pg")
+ upstream_status=$(echo "$commit_body" | sed -nE "s/^(Upstream status:|Upstream:) (\S+)/\2/pg")
+ commits_cnt=$(echo "$upstream_commit" | wc -w)
+
+ if [[ $commit_summary == $VENDOR:* ]]; then
+ if [[ -z "$upstream_status" ]]; then
+ echo "ERROR: It seems this is a downstream commit."
+ echo " Please add following mark in the commit message:"
+ echo ' ```'
+ echo ' Upstream status: '
+ echo ' ```'
+ echo " to explain this is a downstream commit."
+ echo
+ ret=$(( ret + 1 ))
+ fi
+
+ if [[ $commits_cnt -ne 0 ]]; then
+ echo "ERROR: It seems this is a downstream commit, but a Upstream commit mark is provided."
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ fi
+
+ # This is an upstream commit
+ if [[ $commits_cnt -eq 0 ]]; then
+ if [[ $VENDOR_ONLY ]] && [[ $commit_summary != $VENDOR:* ]]; then
+ echo "ERROR: '$VENDOR:' is missing in the commit summary, and no 'Upstream commit:' mark is found."
+ echo " If this is a downstream commit, please add '$VENDOR': in commit summary, and add this mark in commit message:"
+ echo
+ ret=$(( ret + 1 ))
+ fi
+
+ if [[ -z "$upstream_status" ]]; then
+ echo "ERROR: No upstream mark found."
+ echo " If this is a downstream commit, please add this mark:"
+ echo ' ```'
+ echo ' Upstream status: '
+ echo ' ```'
+ echo " to explain this is a downstream commit."
+ echo
+ echo " If this is a backported upstream commit, please add one and only one mark:"
+ echo ' ```'
+ echo " Upstream commit: "
+ echo ' ```'
+ echo " to indicate which commit is being backported."
+ echo
+ ret=$(( ret + 1 ))
+ elif [[ "$upstream_status" =~ ^[a-f0-9]{7,}$ ]]; then
+ echo "ERROR: It seems you pasted a plain commit id after 'Upstream:' or 'Upstream status:' mark."
+ echo " Please use this format instead:"
+ echo ' ```'
+ echo " Upstream commit: "
+ echo ' ```'
+ echo " If this is a actually downstream commit, please use less confusing words"
+ echo " for the 'Upstream status:' mark."
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ else
+ if [[ $commits_cnt -ne 1 ]]; then
+ echo "ERROR: It seems this is a upstream commit, please add one *and only one* upstream commit indicator per commit, in following format:"
+ echo ' ```'
+ echo " Upstream commit: "
+ echo ' ```'
+ echo " If this is a downstream commit, please add \"$VENDOR:\" header in commit summary."
+ echo
+ ret=$(( ret + 1 ))
+ else
+ if ! is_valid_commit "$upstream_commit"; then
+ echo "ERROR: $upstream_commit is not an valid commit!"
+ echo
+ ret=$(( ret + 1 ))
+ else
+ if ! is_valid_upstream_commit "$upstream_commit" > /dev/null; then
+ echo "ERROR: $upstream_commit is not an valid upstream commit!"
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ fi
+ fi
+
+ conflict_cnt=$(echo "$commit_body" | grep -c "^Conflict: ")
+ if [ "$conflict_cnt" -ne 1 ]; then
+ echo "ERROR: This is an upstream commit, please add one (and only one) conflict indicator in following format:"
+ echo ' ```'
+ echo " Conflict: "
+ echo ' ```'
+ echo
+ ret=$(( ret + 1 ))
+ fi
+ fi
+
+ if [[ $VENDOR_ONLY ]] && [[ $author_email != *@$VENDOR.com ]]; then
+ echo "ERROR: The author of this commit is not from $VENDOR.com, did you forget to reset author?"
+ echo " You can reset author to your self for better backports commits tracking, use:"
+ echo " > git commit --amend --reset-author"
+ echo " Or:"
+ echo " > git commit --amend --author=\"yourname \""
+ echo " If there are many commits to be modified, use:"
+ echo " > git filter-branch."
+ echo
+ ret=$(( ret + 1 ))
+ fi
+
+ return $ret
+}
+
+if ! git_logs=$(git log --no-walk=sorted --no-decorate --pretty=oneline --first-parent "${COMMITS[*]}"); then
+ die "Failed to parse git references '${COMMITS[*]}'"
+ exit 1
+fi
+
+IDX=0
+ERROR_MSG=""
+echo "$git_logs" | while read -r commit_id commit_msg; do
+ echo "=== Checking $commit_id ('$commit_msg') ..."
+
+ IDX=$(( IDX + 1 ))
+ ERROR_MSG=$(check_commit "$commit_id")
+ RET=$?
+ OUTFILE=$(printf "$OUTPUT_DIR/%04d-%s.err" $IDX "$commit_id")
+
+ if [[ $RET -ne 0 ]]; then
+ echo_yellow "Found following issues with $commit_id ('$commit_msg'):"
+ echo_red "$ERROR_MSG"
+ if [[ "$GEN_REPORT" ]] && [[ "$GEN_REPORT" != "0" ]]; then
+ {
+ echo "$ERROR_MSG"
+ } > "$OUTFILE"
+ fi
+ else
+ if [[ -n "$ERROR_MSG" ]]; then
+ echo_yellow "$commit_id have some warnings:"
+ echo_red "$ERROR_MSG"
+ else
+ echo_green "$commit_id looks OK"
+ fi
+ fi
+
+ # Newline as seperator
+ echo
+done
diff --git a/dist/scripts/check-configs.sh b/dist/scripts/check-configs.sh
new file mode 100755
index 000000000..6fc453147
--- /dev/null
+++ b/dist/scripts/check-configs.sh
@@ -0,0 +1,215 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# This script takes the merged config files and processes them through listnewconfig
+# then append the new options to pending config
+
+# shellcheck source=./lib-config.sh
+. "$(dirname "$(realpath "$0")")/lib-config.sh"
+
+# shellcheck disable=SC2164
+export CONFIG_OUTDIR=$DISTDIR/workdir
+AUTOFIX=0
+
+usage()
+{
+ cat << EOF
+check-configs.sh [sub command] [--autofix] [ ... ]
+ Available sub command:
+
+ check-new-configs Check for new unset kernel options.
+ If --autofix (or env var AUTOFIX) is enabled,
+ will append to pending configs
+
+ check-dup-configs Check for kernel configs of the same value in different archs.
+ If --autofix (or env var AUTOFIX) is enabled,
+ will move these configs from arch
+ specific config to the default base config.
+
+ check-diff-configs Check for kernel configs that failed to enabled,
+ which means, they are set =y/=m in config matrix,
+ but end up disabled in the final .config file.
+ Doesn't support AUTOFIX since issues caused by
+ Kconfig dependency is complex and always need manual fix.
+EOF
+}
+
+# Use make listnewconfig to check new Kconfigs
+check_new_configs() {
+ # First generate plain concated config files
+ populate_configs "$@"
+
+ # Check if there are unset config
+ _check_new_kconfigs() {
+ local arch=$1 config_file=$2 base_file=$3 base_configs new_configs
+
+ echo_green "=== Checking $config_file..."
+ new_configs=$(config_make "$arch" KCONFIG_CONFIG="$config_file" --no-print-directory listnewconfig)
+
+ if [ -n "$new_configs" ]; then
+ echo_yellow "=== Following configs are not set properly:"
+ echo "$new_configs"
+
+ if [[ $AUTOFIX -eq 1 ]]; then
+ echo_green "=== Appending these new configs to the base config file: '$base_file'"
+ echo "$new_configs" >> "$base_file"
+
+ base_configs=$(<"$base_file")
+ {
+ echo "$base_configs"
+ echo "$new_configs"
+ } | config_sanitizer > "$base_file"
+ fi
+ else
+ echo_green "=== Config is all clear"
+ fi
+
+ # Add a newline as seperator
+ echo
+ }
+
+ for_each_config_product _check_new_kconfigs "$@"
+}
+
+check_dup_configs() {
+ # Merge common config items among different archs with same value into base default config.
+ _dedup_single_dir() {
+ local dir=$1
+ local common_conf base_conf
+
+ echo_green "=== Checking config dir '$dir'"
+ for arch in "${CONFIG_ARCH[@]}"; do
+ [[ -e "$dir/$arch.config" ]] || continue
+
+ if [[ -z "$common_conf" ]]; then
+ # Read-in first arch specific config
+ common_conf=$(config_sanitizer < "$dir/$arch.config")
+ else
+ # Keep the common config items of differnt archs
+ # The content is filtered with config_sanitizer so `comm` is enough
+ common_conf=$(comm -12 \
+ <(echo "$common_conf") \
+ <(config_sanitizer < "$dir/$arch.config")
+ )
+ fi
+ done
+
+ if [[ "$common_conf" ]]; then
+ echo_yellow "=== Common configs shared by all sub arch:"
+ echo "$common_conf"
+
+ if [[ $AUTOFIX -eq 1 ]]; then
+ base_conf=$(<"$dir/default.config")
+ {
+ echo "$base_conf"
+ echo "$common_conf"
+ } | config_sanitizer > "$dir/default.config"
+ fi
+ else
+ echo_green "=== Config is all clear"
+ fi
+ }
+
+ _get_config_dirs() {
+ shift; printf "%s\n" "$@"
+ }
+
+ for dir in $(for_each_config_target _get_config_dirs "$@" | sort -u); do
+ _dedup_single_dir "$dir"
+ done
+}
+
+# generate diff file using kernel script diffconfig after make olddefconfig
+# param: config.file.old config.file
+check_diff_configs() {
+ local ALL_CONFIGS
+
+ [[ -x "$TOPDIR"/scripts/diffconfig ]] || die "This command rely on linux's in-tree diffconfig script"
+
+ ALL_CONFIGS=$(find "$TOPDIR" -name "Kconfig*" -exec grep -h "^config .*" {} + | sed "s/^config //")
+
+ # First generate plain concated config files
+ populate_configs "$@"
+
+ _make_a_copy() {
+ cp "$2" "$2.orig"
+ }
+ for_each_config_product _make_a_copy "$@"
+
+ makedef_configs "$@"
+
+ # Check why a config is not enabled
+ _check_config_issue() {
+ local _config=$1 _config_file=$2
+
+ if ! echo "$ALL_CONFIGS" | grep -q "\b$_config\b"; then
+ echo "$_config no longer exists, maybe it's deprecated or renamed."
+ return
+ fi
+
+ echo "$_config have following depends:"
+ get_all_depends "$_config" "$_config_file" || echo "No dependency found, likely not available on this arch."
+ echo
+ }
+
+ _check_diff_configs() {
+ local arch=$1 config_file=$2 diff_configs
+
+ echo "=== Checking config $config_file"
+
+ echo "= Parsing Kconfig ..."
+ kconfig_parser "$arch" "$TOPDIR/Kconfig" "$config_file"
+
+ echo "= Checking configs ..."
+ diff_configs=$("$TOPDIR"/scripts/diffconfig "$config_file.orig" "$config_file" |
+ # Ignore new added config, they should be covered by check_new_configs
+ # If kernel didn't ask us to fill one config, then it's an auto-selected config
+ grep -v "^+" | \
+ # Ignore disappeared configs that were unset
+ grep -v "^\-.*n$" \
+ )
+
+ if [[ -z "$diff_configs" ]]; then
+ echo_green "=== Config is all clear"
+ return
+ fi
+
+ echo "$diff_configs" | while read -r _line; do
+ local config config_hint=""
+ case $_line in
+ -*" m" | -*" y" )
+ config=${_line% *}
+ config=${config#-}
+ config_hint=$(_check_config_issue "$config" "$config_file")
+ ;;
+ esac
+
+ echo_yellow "$_line"
+ if [[ "$config_hint" ]]; then
+ echo_yellow "$config_hint" | sed "s/^/ /"
+ fi
+ echo
+ done
+ echo
+ }
+
+ for_each_config_product _check_diff_configs "$@"
+}
+
+CMD=$1; shift
+[[ $1 == '--autofix' ]] && AUTOFIX=1
+case "$CMD" in
+ check-new-configs )
+ check_new_configs "$@"
+ ;;
+ check-dup-configs )
+ check_dup_configs "$@"
+ ;;
+ check-diff-configs )
+ check_diff_configs "$@"
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+esac
diff --git a/dist/scripts/check-tag.sh b/dist/scripts/check-tag.sh
new file mode 100755
index 000000000..5d7220641
--- /dev/null
+++ b/dist/scripts/check-tag.sh
@@ -0,0 +1,19 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# $1: tag
+# $2: (opt) git repo
+
+# shellcheck source=./lib-version.sh
+. "$(dirname "$(realpath "$0")")/lib-version.sh"
+
+prepare_kernel_ver "$@"
+
+# If tag is not recognized, prepare_kernel_ver will version it as snapshot
+# use this as an indicator of invalid tag
+if ! [[ $KTAGRELEASE ]]; then
+ error "Invalid tag '$1'"
+ exit 1
+else
+ info "Tag '$KTAGRELEASE' OK, Kernel version '$KERNEL_UNAMER', RPM version '${KERNEL_MAJVER//-/.}-${KERNEL_RELVER//-/.}'"
+fi
diff --git a/dist/scripts/dummy-tools/gcc b/dist/scripts/dummy-tools/gcc
new file mode 100755
index 000000000..b2483149b
--- /dev/null
+++ b/dist/scripts/dummy-tools/gcc
@@ -0,0 +1,111 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG
+# options your compiler does not support. This works well if you configure and
+# build the kernel on the same host machine.
+#
+# It is inconvenient if you prepare the .config that is carried to a different
+# build environment (typically this happens when you package the kernel for
+# distros) because using a different compiler potentially produces different
+# CONFIG options than the real build environment. So, you probably want to make
+# as many options visible as possible. In other words, you need to create a
+# super-set of CONFIG options that cover any build environment. If some of the
+# CONFIG options turned out to be unsupported on the build machine, they are
+# automatically disabled by the nature of Kconfig.
+#
+# However, it is not feasible to get a full-featured compiler for every arch.
+# Hence these dummy toolchains to make all compiler tests pass.
+#
+# Usage:
+#
+# From the top directory of the source tree, run
+#
+# $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig
+#
+# Most of compiler features are tested by cc-option, which simply checks the
+# exit code of $(CC). This script does nothing and just exits with 0 in most
+# cases. So, $(cc-option, ...) is evaluated as 'y'.
+#
+# This scripts caters to more checks; handle --version and pre-process __GNUC__
+# etc. to pretend to be GCC, and also do right things to satisfy some scripts.
+
+# Check if the first parameter appears in the rest. Succeeds if found.
+# This helper is useful if a particular option was passed to this script.
+# Typically used like this:
+# arg_contain "$@"
+arg_contain ()
+{
+ search="$1"
+ shift
+
+ while [ $# -gt 0 ]
+ do
+ if [ "$search" = "$1" ]; then
+ return 0
+ fi
+ shift
+ done
+
+ return 1
+}
+
+# To set CONFIG_CC_IS_GCC=y
+if arg_contain --version "$@"; then
+ echo "gcc (scripts/dummy-tools/gcc)"
+ exit 0
+fi
+
+if arg_contain -E "$@"; then
+ # For scripts/cc-version.sh; This emulates GCC 20.0.0
+ if arg_contain - "$@"; then
+ sed -n '/^GCC/{s/__GNUC__/20/; s/__GNUC_MINOR__/0/; s/__GNUC_PATCHLEVEL__/0/; p;}'
+ exit 0
+ else
+ echo "no input files" >&2
+ exit 1
+ fi
+fi
+
+# To set CONFIG_AS_IS_GNU
+if arg_contain -Wa,--version "$@"; then
+ echo "GNU assembler (scripts/dummy-tools) 2.50"
+ exit 0
+fi
+
+if arg_contain -S "$@"; then
+ # For scripts/gcc-x86-*-has-stack-protector.sh
+ if arg_contain -fstack-protector "$@"; then
+ if arg_contain -mstack-protector-guard-reg=fs "$@"; then
+ echo "%fs"
+ else
+ echo "%gs"
+ fi
+ exit 0
+ fi
+
+ # For arch/powerpc/tools/gcc-check-mprofile-kernel.sh
+ if arg_contain -m64 "$@" && arg_contain -mlittle-endian "$@" &&
+ arg_contain -mprofile-kernel "$@"; then
+ if ! test -t 0 && ! grep -q notrace; then
+ echo "_mcount"
+ fi
+ exit 0
+ fi
+fi
+
+# To set GCC_PLUGINS
+if arg_contain -print-file-name=plugin "$@"; then
+ plugin_dir=$(mktemp -d)
+
+ mkdir -p $plugin_dir/include
+ touch $plugin_dir/include/plugin-version.h
+
+ echo $plugin_dir
+ exit 0
+fi
+
+# inverted return value
+if arg_contain -D__SIZEOF_INT128__=0 "$@"; then
+ exit 1
+fi
diff --git a/dist/scripts/dummy-tools/ld b/dist/scripts/dummy-tools/ld
new file mode 100755
index 000000000..f68233050
--- /dev/null
+++ b/dist/scripts/dummy-tools/ld
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Dummy script that always succeeds.
+
+# Check if the first parameter appears in the rest. Succeeds if found.
+# This helper is useful if a particular option was passed to this script.
+# Typically used like this:
+# arg_contain "$@"
+arg_contain ()
+{
+ search="$1"
+ shift
+
+ while [ $# -gt 0 ]
+ do
+ if [ "$search" = "$1" ]; then
+ return 0
+ fi
+ shift
+ done
+
+ return 1
+}
+
+if arg_contain --version "$@" || arg_contain -v "$@"; then
+ progname=$(basename $0)
+ echo "GNU $progname (scripts/dummy-tools/$progname) 2.50"
+ exit 0
+fi
diff --git a/dist/scripts/dummy-tools/nm b/dist/scripts/dummy-tools/nm
new file mode 120000
index 000000000..c0648b38d
--- /dev/null
+++ b/dist/scripts/dummy-tools/nm
@@ -0,0 +1 @@
+ld
\ No newline at end of file
diff --git a/dist/scripts/dummy-tools/objcopy b/dist/scripts/dummy-tools/objcopy
new file mode 120000
index 000000000..c0648b38d
--- /dev/null
+++ b/dist/scripts/dummy-tools/objcopy
@@ -0,0 +1 @@
+ld
\ No newline at end of file
diff --git a/dist/scripts/format-configs.sh b/dist/scripts/format-configs.sh
new file mode 100755
index 000000000..2abe34df4
--- /dev/null
+++ b/dist/scripts/format-configs.sh
@@ -0,0 +1,14 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# Generate kernel config according to config matrix
+
+# shellcheck source=./lib-config.sh
+. "/$(dirname "$(realpath "$0")")/lib-config.sh"
+
+# Sort and remove duplicated items in each config base file
+for file in "$CONFIG_PATH"/*/*/*.config; do
+ config_sanitizer < "$file" > "$file.fmt.tmp"
+
+ mv "$file.fmt.tmp" "$file"
+done
diff --git a/dist/scripts/gen-configs.sh b/dist/scripts/gen-configs.sh
new file mode 100755
index 000000000..385f83901
--- /dev/null
+++ b/dist/scripts/gen-configs.sh
@@ -0,0 +1,16 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# Generate kernel config according to config matrix
+#
+# Params:
+# $@: [ ... ] When non-empty, only generate kernel configs style matching
+
+# shellcheck source=./lib-config.sh
+. "$(dirname "$(realpath "$0")")/lib-config.sh"
+
+# Populate basic config entries based on our config file tree
+populate_configs "$@"
+
+# Process the config files with make olddefconfig
+makedef_configs "$@"
diff --git a/dist/scripts/gen-spec.sh b/dist/scripts/gen-spec.sh
new file mode 100755
index 000000000..86262a836
--- /dev/null
+++ b/dist/scripts/gen-spec.sh
@@ -0,0 +1,250 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+
+# shellcheck source=./lib-version.sh
+. "/$(dirname "$(realpath "$0")")/lib-version.sh"
+
+usage()
+{
+ cat << EOF
+gen-spec.sh [OPTION]
+
+ --kernel-dist Kernel distribution marker, eg. tks/tlinux4/tlinux3
+ --kernel-config Kernel config base name, will look for the corresponding kernel config under $DISTDIR/configs
+ --kernel-variant Kernel variant, eg. debug, gcov, kdb
+ --build-arch What arch's are supported, defaults to '$SPEC_ARCH'"
+EOF
+}
+
+DEFAULT_DISALBED=" kabichk "
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ --kernel-config )
+ KERNEL_CONFIG=$2
+ shift 2
+ ;;
+ --kernel-variant )
+ KERNEL_VARIANT=$2
+ shift 2
+ ;;
+ --build-arch )
+ BUILD_ARCH=$2
+ shift 2
+ ;;
+ --commit )
+ COMMIT=$2
+ shift 2
+ ;;
+ --set-default-disabled )
+ for param in $2; do
+ DEFAULT_DISALBED=" $param $DEFAULT_DISALBED"
+ done
+ shift 2
+ ;;
+ --set-default-enabled )
+ for param in $2; do
+ DEFAULT_DISALBED="${DEFAULT_DISALBED/ $param /}"
+ done
+ shift 2
+ ;;
+ * )
+ die "Unrecognized parameter $1"
+ ;;
+ esac
+done
+
+# This function will prepare $KERNEL_MAJVER, $KERNEL_RELVER
+prepare_kernel_ver "${COMMIT:-HEAD}"
+
+BUILD_ARCH="${BUILD_ARCH:-$SPEC_ARCH}"
+
+RPM_NAME="kernel${KERNEL_VARIANT:+-$KERNEL_VARIANT}${KERNEL_DIST:+-$KERNEL_DIST}"
+RPM_VERSION=${KERNEL_MAJVER//-/.}
+RPM_RELEASE=${KERNEL_RELVER//-/.}
+RPM_RELEASE=${RPM_RELEASE%".$KERNEL_DIST"}
+RPM_VENDOR=$(get_dist_makefile_var VENDOR_CAPITALIZED)
+RPM_URL=$(get_dist_makefile_var URL)
+
+if [ -z "$KERNEL_CONFIG" ]; then
+ for config in "$TOPDIR/configs/"*.config; do
+ # "..config" -> ""
+ KERNEL_CONFIG=$(basename "$config")
+ KERNEL_CONFIG=${config%.config}
+ KERNEL_CONFIG=${config%.*}
+ break
+ done
+
+ if [ -z "$KERNEL_CONFIG" ]; then
+ die "There is no valid kernel config."
+ fi
+fi
+
+_gen_arch_spec() {
+ local arch kernel_arch
+ cat << EOF
+ExclusiveArch: $BUILD_ARCH
+EOF
+ for arch in $BUILD_ARCH; do
+ if ! kernel_arch=$(get_kernel_arch "$arch"); then
+ die "Unsupported arch '$arch'"
+ fi
+ cat << EOF
+%ifarch $arch
+%define kernel_arch $kernel_arch
+%endif
+EOF
+ done
+}
+
+_gen_kerver_spec() {
+ cat << EOF
+%define rpm_name $RPM_NAME
+%define rpm_version $RPM_VERSION
+%define rpm_release $RPM_RELEASE
+%define rpm_vendor $RPM_VENDOR
+%define rpm_url $RPM_URL
+%define kernel_majver $KERNEL_MAJVER
+%define kernel_relver $KERNEL_RELVER
+EOF
+[ "$KERNEL_VARIANT" ] && cat << EOF
+%define kernel_variant $KERNEL_VARIANT
+EOF
+}
+
+_gen_arch_source() {
+ # Source1000 - Source1199 for kernel config
+ local config_source_num=1000 arch
+ for arch in $BUILD_ARCH; do
+ echo "Source$config_source_num: $KERNEL_CONFIG.$arch.config"
+ config_source_num=$((config_source_num + 1))
+ done
+
+ # Source1200 - Source1399 for kabi source
+ local kabi_source_num=1200 arch
+ for arch in $BUILD_ARCH; do
+ echo "Source$kabi_source_num: Module.kabi_$arch"
+ kabi_source_num=$((kabi_source_num + 1))
+ done
+
+ # Source1400 - Source1599 for module filter
+ local filter_source_num=1400 arch
+ for arch in $BUILD_ARCH; do
+ echo "Source$filter_source_num: filter-$arch.sh"
+ filter_source_num=$((filter_source_num + 1))
+ done
+}
+
+_gen_config_build() {
+ cat << EOF
+%ifnarch $BUILD_ARCH
+{error:unsupported arch}
+%endif
+EOF
+ local config_source_num=1000 arch
+ for arch in $BUILD_ARCH; do
+ cat << EOF
+%ifarch $arch
+BuildConfig %{SOURCE$config_source_num}
+%endif
+EOF
+ config_source_num=$((config_source_num + 1))
+ done
+}
+
+_gen_kabi_check() {
+ cat << EOF
+%ifnarch $BUILD_ARCH
+{error:unsupported arch}
+%endif
+EOF
+ local kabi_source_num=1200 arch
+ for arch in $BUILD_ARCH; do
+ cat << EOF
+%ifarch $arch
+CheckKernelABI %{SOURCE$kabi_source_num}
+%endif
+EOF
+ kabi_source_num=$((kabi_source_num + 1))
+ done
+}
+
+_gen_changelog_spec() {
+ cat "$DISTDIR/templates/changelog"
+}
+
+_gen_pkgopt_spec() {
+ local enabled_opts disabled_opts opts_output
+ for opt in \
+ core \
+ doc \
+ headers \
+ perf \
+ tools \
+ bpftool \
+ debuginfo \
+ modsign \
+ kabichk
+ do
+ case $DEFAULT_DISALBED in
+ *" $opt "* )
+ disabled_opts="$disabled_opts $opt"
+ opts_output="$opts_output
+%define with_$opt %{?_with_$opt: 1} %{?!_with_$opt: 0}"
+ ;;
+ * )
+ enabled_opts="$enabled_opts $opt"
+ opts_output="$opts_output
+%define with_$opt %{?_without_$opt: 0} %{?!_without_$opt: 1}"
+ esac
+ done
+
+ # Marker for dist build system, a little bit ugly, maybe find a better way to present this info later
+ echo ""
+ echo "# === Package options ==="
+ echo "# Eanbled by default: $enabled_opts"
+ echo "# Disabled by default: $disabled_opts"
+ echo "$opts_output"
+}
+
+gen_spec() {
+ local _line
+ local _spec
+
+ while IFS='' read -r _line; do
+ case $_line in
+ "{{PKGPARAMSPEC}}"* )
+ _spec+="$(_gen_pkgopt_spec)"
+ ;;
+ "{{ARCHSPEC}}"* )
+ _spec+="$(_gen_arch_spec)"
+ ;;
+ "{{VERSIONSPEC}}"* )
+ _spec+="$(_gen_kerver_spec)"
+ ;;
+ "{{ARCHSOURCESPEC}}"* )
+ _spec+="$(_gen_arch_source)"
+ ;;
+ "{{CONFBUILDSPEC}}"* )
+ _spec+="$(_gen_config_build)"
+ ;;
+ "{{KABICHECKSPEC}}"* )
+ _spec+="$(_gen_kabi_check)"
+ ;;
+ "{{CHANGELOGSPEC}}"* )
+ _spec+="$(_gen_changelog_spec)"
+ ;;
+ "{{"*"}}"*)
+ die "Unrecognized template keywork $_line"
+ ;;
+ * )
+ _spec+="$_line"
+ ;;
+ esac
+ _spec+="
+"
+ done
+
+ echo "$_spec"
+}
+
+gen_spec < "$DISTDIR/templates/kernel.template.spec"
diff --git a/dist/scripts/get-next-sub-version.sh b/dist/scripts/get-next-sub-version.sh
new file mode 100755
index 000000000..f328d3087
--- /dev/null
+++ b/dist/scripts/get-next-sub-version.sh
@@ -0,0 +1,9 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+
+# shellcheck source=./lib-version.sh
+. "$(dirname "$(realpath "$0")")/lib-version.sh"
+
+prepare_next_sub_kernel_ver "$@"
+
+echo "$KERNEL_UNAMER"
diff --git a/dist/scripts/get-next-version.sh b/dist/scripts/get-next-version.sh
new file mode 100755
index 000000000..07b5c5760
--- /dev/null
+++ b/dist/scripts/get-next-version.sh
@@ -0,0 +1,9 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+
+# shellcheck source=./lib-version.sh
+. "$(dirname "$(realpath "$0")")/lib-version.sh"
+
+prepare_next_kernel_ver "$@"
+
+echo "$KERNEL_UNAMER"
diff --git a/dist/scripts/get-version.sh b/dist/scripts/get-version.sh
new file mode 100755
index 000000000..047c0db79
--- /dev/null
+++ b/dist/scripts/get-version.sh
@@ -0,0 +1,11 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# Print out the tkernel version based on git commit and work tree.
+
+# shellcheck source=./lib-version.sh
+. "$(dirname "$(realpath "$0")")/lib-version.sh"
+
+prepare_kernel_ver "$@"
+
+echo "$KERNEL_UNAMER"
diff --git a/dist/scripts/helper/backporter.sh b/dist/scripts/helper/backporter.sh
new file mode 100755
index 000000000..8da635148
--- /dev/null
+++ b/dist/scripts/helper/backporter.sh
@@ -0,0 +1,91 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+
+# shellcheck source=../lib.sh
+. "/$(dirname "$(realpath "$0")")/../lib.sh"
+
+AUTHOR="$(git config user.name) <$(git config user.email)>"
+COMMIT=$1
+
+[ -z "$COMMIT" ] && die "Usage: $0 "
+
+_resolve_conflict_shell() {
+ error "Failed to backport, please fix the problem, then commit it."
+ error "then exit the shell with \`exit 0\`."
+ error "To abort the backport, exited with a dirty worktree or exit with non-zero."
+
+ export PS1="RESOLVING CONFLICT"
+
+ $SHELL || {
+ RET=$?
+ error "Shell exited with non-zero, aborting backport"
+ git reset --hard HEAD
+ exit $RET
+ }
+
+ git diff-index --quiet HEAD || {
+ RET=$?
+ error "Dirty worktree, aborting backport"
+ git reset --hard HEAD
+ exit $RET
+ }
+}
+
+_fetch_upstream() {
+ # Try to fetch from well-known upstream
+ local commit=$1
+ local upstream_repos=(
+ "torvalds https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=<> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git"
+ "tip https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/patch/?id=<> git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git"
+ "mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/patch/?id=<> git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git"
+ "stable https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/patch/?id=<> git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
+ )
+
+ for repo in "${upstream_repos[@]}"; do
+ repo_http_git=${repo#* }
+ repo_name=${repo%% *}
+ repo_http=${repo_http_git% *}
+ repo_git=${repo_http_git#* }
+ commit_url=${repo_http/<>/$commit}
+ echo curl --fail --silent --output /dev/null "$commit_url"
+ if curl --fail --silent --output /dev/null "$commit_url"; then
+ echo "Found commit '$commit' in '$repo_name' repo"
+ echo git fetch "$repo_git" "$commit"
+ git fetch "$repo_git" "$commit"
+ return
+ fi
+ done
+
+ echo "Can't find commit $commit in upstream."
+ return 1
+}
+
+if ! git cat-file -e "$COMMIT"; then
+ # Available locally, just cherry-pick
+ _fetch_upstream "$COMMIT"
+fi
+
+if ! git cherry-pick "$COMMIT"; then
+ _resolve_conflict_shell
+ CONFLICT=Resolved
+else
+ CONFLICT=None
+fi
+
+git commit \
+ --am \
+ --author="$AUTHOR" \
+ --date=now \
+ --message \
+ "$(git log -1 --format=%s "$COMMIT")
+
+$MSG
+
+Upstream commit: $COMMIT
+Conflict: $CONFLICT
+
+Backport of following upstream commit:
+
+$(git log -1 "$COMMIT")
+
+Signed-off-by: $AUTHOR"
diff --git a/dist/scripts/helper/dist-repo-init.sh b/dist/scripts/helper/dist-repo-init.sh
new file mode 100755
index 000000000..3e1d5bbd2
--- /dev/null
+++ b/dist/scripts/helper/dist-repo-init.sh
@@ -0,0 +1,66 @@
+#!/bin/bash --norc
+# SPDX-License-Identifier: GPL-2.0
+#
+# After dropping the dist build system into a upstream kernel repo,
+# use this to hook the dist build system into Kbuild Makefile.
+
+# shellcheck source=../lib.sh
+. "/$(dirname "$(realpath "$0")")/../lib.sh"
+
+VENDOR_CAPITALIZED=$(get_dist_makefile_var VENDOR_CAPITALIZED)
+KMAKEFILE_CONTENT=""
+
+[ -d "$TOPDIR" ] || {
+ die "Not a valid git repo."
+}
+
+[ -e "$TOPDIR/Kbuild" ] && [ -e "$TOPDIR/Kconfig" ] && [ -e "$TOPDIR/Makefile" ] || {
+ die "Not a valid kernel repo."
+}
+
+[ -e "$DISTDIR/Makefile" ] || {
+ die "Dist files are not properly configured, aborting."
+}
+
+[[ "$DISTDIR" == "$TOPDIR"/* ]] || {
+ die "Dist files are not properly configured, aborting."
+}
+
+
+### Patch .gitignore
+grep -qF "# ${VENDOR_CAPITALIZED:+${VENDOR_CAPITALIZED} }dist files" "$TOPDIR/.gitignore" || {
+ echo "Updating Kernel .gitignore to ignore dist files..."
+ cat >> "$TOPDIR/.gitignore" << EOF
+
+# ${VENDOR_CAPITALIZED:+${VENDOR_CAPITALIZED} }dist files
+/$DISTPATH/rpm
+/$DISTPATH/workdir
+EOF
+}
+
+### Patch .gitattributes
+for i in ".ci" "$DISTPATH"; do \
+ [[ -d $TOPDIR/$i ]] || continue
+ grep -qF "$i/" $TOPDIR/.gitattributes 2>/dev/null || {
+ echo "Updating .gitattributes to exclude $i/..."
+ echo "$i/ export-ignore" >> $TOPDIR/.gitattributes
+ }
+done;
+
+### Patch kernel Makefile
+grep -qF "# dist_make: ${VENDOR_CAPITALIZED:+${VENDOR_CAPITALIZED} }" "$TOPDIR/Makefile" || {
+ echo "Updating Kenrel Makefile..."
+ KMAKEFILE_CONTENT=$(<"$TOPDIR/Makefile")
+ cat > "$TOPDIR/Makefile" << EOF
+# SPDX-License-Identifier: GPL-2.0
+
+# dist_make: ${VENDOR_CAPITALIZED:+${VENDOR_CAPITALIZED} }Dist Makefile, which contains dist-* make targets
+ifneq (\$(shell echo \$(MAKECMDGOALS) | grep "^dist-"),)
+include $DISTPATH/Makefile
+else
+
+$KMAKEFILE_CONTENT
+
+endif # dist_make
+EOF
+}
diff --git a/dist/scripts/helper/gen-module-kabi.sh b/dist/scripts/helper/gen-module-kabi.sh
new file mode 100755
index 000000000..e91ff6a9e
--- /dev/null
+++ b/dist/scripts/helper/gen-module-kabi.sh
@@ -0,0 +1,116 @@
+#!/usr/bin/env sh
+#
+
+KERNEL=
+SYMVER=
+TMPDIR=
+
+error() {
+ echo "error: $*" > /dev/stderr
+}
+
+usage() {
+ cat << EOF
+Provide a list of modules, this script will print the SYMBOLS used by these modules
+
+gen-module-kabi.sh: [--kernel ] [--symver ] [, ...]
+
+: default to \$(uname -r), or specify a installed kernel
+: default to /usr/lib//symvers.gz, or specify a symver file
+: module name
+EOF
+}
+
+while true; do
+ case $1 in
+ --symver )
+ SYMVER=$2
+ shift 2
+ ;;
+ --kernel )
+ KERNEL=$2
+ shift 2
+ ;;
+ --usage|--help|-h )
+ usage
+ exit 0
+ ;;
+ * )
+ break
+ ;;
+ esac
+done
+
+if ! TMPDIR="$(mktemp -d -t gen-module-kabi.XXXXXX)"; then
+ error "mktemp failed"
+ exit 1
+fi
+
+trap 'ret=$?;
+[[ -d $TMPDIR ]] && rm --one-file-system -rf -- "$TMPDIR";
+exit $ret;
+' EXIT
+
+[ "$KERNEL" ] || KERNEL=$(uname -r)
+[ -f "$SYMVER" ] || SYMVER=/lib/modules/$KERNEL/symvers.gz
+[ -f "$SYMVER" ] || SYMVER=/boot/symvers-$KERNEL.gz
+[ -f "$SYMVER" ] || SYMVER=./Module.symvers
+
+if [[ "$#" -eq 0 ]]; then
+ usage
+fi
+
+case $SYMVER in *.gz )
+ gzip < "$SYMVER" -d > "$TMPDIR/symver"
+ SYMVER=$TMPDIR/symver
+ ;;
+esac
+
+_get_export_syms() {
+ _temp_extract=$TMPDIR/extracted.ko
+ case $1 in
+ *.ko )
+ modfile=$1
+ ;;
+ *.xz )
+ modfile=$_temp_extract
+ xz -c -d "$1" > "$_temp_extract"
+ ;;
+ * )
+ error "unsupported file format of file: $1"
+ esac
+
+ nm -uAg "$modfile"
+}
+
+for mod in "$@"; do
+ if [[ $mod == *.ko ]] && [[ -f $mod ]]; then
+ mods=$mod
+ elif [[ $mod == *.ko.* ]] && [[ -f $mod ]]; then
+ mods=$mod
+ elif ! mods="$(modinfo --set-version "$KERNEL" --filename "$mod" 2> /dev/null)"; then
+ error "'$mod' is not a valid module name"
+ fi
+
+ for m in $mods; do
+ _get_export_syms "$m"
+ done
+done | sort | while read -r file_path type sym_name; do
+ in_symver=0
+ in_vmlinux=0
+ sym_line=$(grep "\s$sym_name\s" "$SYMVER") && in_symver=1
+ case $sym_line in
+ # print only symbol in vmlinux
+ *vmlinux*EXPORT_SYMBOL* )
+ in_vmlinux=1
+ ;;
+ esac
+ echo -n "$file_path $type $sym_name"
+ if [[ $in_symver -eq 0 ]]; then
+ echo -n " (NO-KABI: NOT IN SYMVER)"
+ fi
+ if [[ $in_vmlinux -eq 0 ]]; then
+ echo -n " (NO-KABI: NOT IN VMLINUX)"
+ fi
+ echo
+done
diff --git a/dist/scripts/helper/update-kabi.sh b/dist/scripts/helper/update-kabi.sh
new file mode 100755
index 000000000..b8fa69db7
--- /dev/null
+++ b/dist/scripts/helper/update-kabi.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env sh
+#
+
+error() {
+ echo "error: $*" > /dev/stderr
+}
+
+usage() {
+ cat << EOF
+update-kabi.sh:
+
+Take kABI Module.symvers as reference and generate a new kABI symvers file.
+EOF
+}
+
+KABI=$1
+SYMVER=$2
+
+if ! [ -s "$KABI" ] || ! [ -s "$SYMVER" ]; then
+ error "Invalid params."
+ usage
+ exit 1
+fi
+
+cat "$KABI" | while read -r _crc _symbol _vmlinux _gpl; do
+ grep "\b$_symbol\b.*vmlinux" "$SYMVER"
+done | sed -e "s/\t$//"
diff --git a/dist/scripts/lib-config.sh b/dist/scripts/lib-config.sh
new file mode 100755
index 000000000..8615de922
--- /dev/null
+++ b/dist/scripts/lib-config.sh
@@ -0,0 +1,384 @@
+#!/bin/bash --norc
+#
+# To support different arches, compile options, and distributions,
+# Kernel configs are managed with a hierarchy matrix.
+#
+# This script is the helper for parsing and updating the config matrix
+#
+# shellcheck source=./lib.sh
+. "$(dirname "$(realpath "$0")")/lib.sh"
+
+CONFIG_PATH=${CONFIG_PATH:-$DISTDIR/configs}
+# shellcheck disable=SC2206
+CONFIG_ARCH=( $SPEC_ARCH )
+CONFIG_SPECS=( "$CONFIG_PATH"/[0-9][0-9]* )
+CONFIG_OUTDIR=$SOURCEDIR
+CONFIG_CACHE=$DISTDIR/workdir/config_cache
+
+
+_get_config_cross_compiler () {
+ if [[ "$1" == $(get_native_arch) ]]; then
+ :
+ elif [[ -d "$TOPDIR/scripts/dummy-tools/" ]]; then
+ echo "scripts/dummy-tools/"
+ else
+ echo "$DISTDIR/scripts/dummy-tools/"
+ fi
+}
+
+get_config_val() {
+ # If it's y/m/n/0-9, return plain text, else get from .config
+ #
+ # To be more accurate, maybe we need to check right/left-value?
+ case $1 in
+ n )
+ ;;
+ y|m|[0-9] )
+ echo "$1" ;;
+ * )
+ local _val
+ _val=$(grep "^CONFIG_$1=" "$2")
+ _val=${_val#*=}
+ echo "${_val:-not set}"
+ ;;
+ esac
+}
+
+# Eval a Kconfig condition statement
+kconfig_eval() {
+ local _line=$1
+
+ local _if
+ # Convert Kconfig cond statement to bash syntax then eval it
+ _if=$(echo "$_line" | sed -E \
+ -e "s/(\|\||&&|=|!=|<|<=|>|>=|!|\(|\))/ \1 /g" \
+ -e "s/([[:alnum:]_-]+)/ \"\$(get_kconf_val \'\1\')\" /g")
+ eval "[[ $_if ]]"
+}
+
+get_depends() {
+ local _conf=$1
+ local _deps _line
+
+ sed -nE "s/^[[:space:]]*depends on //p;" "$CONFIG_CACHE/$_conf"
+}
+
+# $1: Parsed Kconfig file
+get_all_depends() {
+ local _dep
+ local _deps=( )
+
+ [[ ! -e "$CONFIG_CACHE/$1" ]] && return 1
+
+ # shellcheck disable=SC2207
+ while read -r _dep; do
+ if ! [[ "$_dep" ]]; then
+ continue
+ elif [[ "$_dep" =~ y|n|m ]]; then
+ _deps+=( "$_dep" )
+ elif [[ "$_dep" =~ [a-zA-Z0-9] ]]; then
+ _deps+=( "$_dep[=$(get_config_val "$_dep" "$2")]" )
+ else
+ _deps+=( "$_dep" )
+ fi
+ done <<< "$(get_depends "$1" | sed -E \
+ -e 's/^([^\(])/(\1/' \
+ -e 's/([^\)])$/\1)/' \
+ -e '2,$s/^/\&\&/' \
+ -e 's/(\|\||&&|=|!=|<|<=|>|>=|!|\(|\)|([[:alnum:]_-]+))/\n\1\n/g')"
+ # The regex above simply tokenize the Kconfig expression
+
+ echo "${_deps[@]}"
+
+ return 0
+}
+
+kconfig_parser() {
+ local _arch=$1 _kconfig=$2 _config=$3
+
+ [[ -s $_kconfig ]] || error "Invalid Kconfig '$_kconfig'"
+ [[ -s $_config ]] || error "Invalid config file '$_kconfig'"
+
+ rm -r "${CONFIG_CACHE:?}" 2>/dev/null
+ mkdir -p "$CONFIG_CACHE"
+
+ local _CONFIG_FILE=$CONFIG_CACHE/_invalid
+ local _PARSE_DEPS=()
+
+ _reader() {
+ local _f=$1
+
+ if [[ $_f == *"\$(SRCARCH)"* ]]; then
+ _f=${_f/\$(SRCARCH)/$(get_kernel_src_arch "$_arch")}
+ fi
+
+ local _line
+ while :; do
+ _line=${_line%%#*}
+ case $_line in
+ "config "* | "menuconfig "* )
+ _CONFIG_FILE=${_line#* }
+ _CONFIG_FILE=${_CONFIG_FILE## }
+ _CONFIG_FILE=$CONFIG_CACHE/$_CONFIG_FILE
+ for _dep in "${_PARSE_DEPS[@]}"; do [[ $_dep ]] && echo "depends on $_dep"; done >> "$_CONFIG_FILE"
+ ;;
+ "source "* )
+ _line=${_line#* }
+ _line=${_line#\"}
+ _line=${_line%\"}
+ _reader "$_line"
+ ;;
+ "if "* )
+ _line=${_line#if }
+ _PARSE_DEPS+=( "${_line}" )
+ ;;
+ "menu "* | "choice" )
+ local _sub_dep=""
+ while read -r _line; do
+ case $_line in
+ if*|menu*|config*|end*|source*|choice* ) break ;;
+ "depends on"* )
+ _line="${_line#depends on}"
+ _sub_dep="${_sub_dep:+$_sub_dep && }(${_line## })"
+ ;;
+ "visible if"* )
+ _line="${_line#visible if}"
+ _sub_dep="${_sub_dep:+$_sub_dep && }(${_line## })"
+ ;;
+ esac
+ done
+ _PARSE_DEPS+=( "${_sub_dep## }" )
+ continue
+ ;;
+ "end"* )
+ # We don't care about correctness,
+ # it's always paired with previous if/menu/choice
+ unset '_PARSE_DEPS[${#_PARSE_DEPS[@]}-1]'
+ ;;
+ '' | ' ' )
+ ;;
+ * )
+ echo "$_line" >> "$_CONFIG_FILE"
+ esac
+ IFS='' read -r _line || break
+ done <<< "$(<"$_f")"
+ }
+
+ pushd "$(dirname "$_kconfig")" > /dev/null || die "Failed pushd to '$TOPDIR'"
+
+ _reader "$_kconfig"
+
+ popd || die
+}
+
+# Call make for config related make target. Will set proper cross compiler and kernel arch name.
+# $1: Target arch.
+config_make() {
+ local arch=$1; shift
+ local config_cross_compiler config_arch
+
+ pushd "$TOPDIR" >/dev/null || die "Not in a valid git repo."
+
+ config_cross_compiler=$(_get_config_cross_compiler "$arch")
+ config_arch=$(get_kernel_arch "$arch")
+
+ if [[ -z "$config_arch" ]]; then
+ die "Unsupported arch $arch"
+ fi
+
+ make ARCH="$config_arch" CROSS_COMPILE="$config_cross_compiler" "$@"
+
+ popd >/dev/null || die "Failed popd"
+}
+
+# Dedup, and filter valid config lines, print the sanitized content sorted by config name.
+config_sanitizer() {
+ # AWK will add an extra column of CONFIG_NAME for sort to work properly
+ LC_ALL=C
+ awk '
+ /is not set/ {
+ split($0, val, "#");
+ split(val[2], val);
+ configs[val[1]]=$0
+ }
+ /^CONFIG.*=/ {
+ split($0, val, "=");
+ if (val[2] == "n")
+ configs[val[1]]="# "val[1]" is not set"
+ else
+ configs[val[1]]=$0
+ }
+ END {
+ for (config in configs) {
+ print config " " configs[config]
+ }
+ }' \
+ | LC_ALL=C sort -k 1 \
+ | cut -d ' ' -f 2-
+}
+
+# Iterate the dot product of all config options
+# param: [... ]
+# [... ]: Filters config targets to use. eg. kernel-default-*, kernel-minimal-debug
+# : A callback function, see below for params.
+#
+# Will generate a matrix, and call like this:
+# [ ... ]
+#
+# eg.
+# "kernel-generic-release" "$TOPDIR/00pending/kernel" "$TOPDIR/20preset/generic" "$TOPDIR/50variant/release"
+# "kernel-generic-debug" "$TOPDIR/00pending/kernel" "$TOPDIR/20preset/generic" "$TOPDIR/50variant/debug"
+# ...
+#
+for_each_config_target () {
+ local filters callback
+ local target cur_target i j
+
+ callback=$1; shift
+ filters=("$@")
+
+ _match () {
+ [[ ${#filters[@]} -eq 0 ]] && return 0
+
+ for _f in "${filters[@]}"; do
+ # shellcheck disable=SC2053
+ [[ $1 == $_f ]] && return 0
+ done
+
+ return 1
+ }
+
+ # The '_' is used to bootstrap the file loop
+ local -a hierarchy=( _ ) prev_hierarchy target_conf prev_target_conf
+
+ for folder in "${CONFIG_SPECS[@]}"; do
+ prev_hierarchy=( "${hierarchy[@]}" )
+ prev_target_conf=( "${target_conf[@]}" )
+
+ hierarchy=( )
+ target_conf=( )
+
+ i=0
+ for config in "$folder"/*; do
+ if ! [[ -e "$config/default.config" ]]; then
+ error "Invalid config folder $config"
+ return 1
+ fi
+
+ j=0
+ for target in "${prev_hierarchy[@]}"; do
+ cur_target=$target-$(basename "$config")
+ hierarchy+=( "$cur_target" )
+ # config files can't have spece in their path since the
+ # list is split by space, seems no better way
+ target_conf[$i]="${prev_target_conf[$j]} $config"
+ i=$(( i + 1 ))
+ j=$(( j + 1 ))
+ done
+ done
+ done
+
+ i=0
+ for target in "${hierarchy[@]}"; do
+ # split target_conf by space is what we want here
+ target="${target#_-}"
+ # shellcheck disable=SC2086
+ _match $target && "$callback" "${target#_-}" ${target_conf[$i]}
+ i=$(( i + 1 ))
+ done
+}
+
+# Iterate populated config files
+# param: [... ]
+# [... ]: Filters config targets to use. eg. kernel-default-*, kernel-minimal-debug
+# : A callback function, see below for params.
+#
+# Will generate a matrix, and call like this:
+# [ ... ]
+#
+# eg.
+# "x86_64" "kernel-generic-release" \
+# "$TOPDIR/00pending/kernel/default.config" "$TOPDIR/00pending/kernel/x86_64.config" \
+# "$TOPDIR/20preset/generic/default.config" "$TOPDIR/20preset/generic/x86_64.config" \
+# "$TOPDIR/50variant/release/default.config" "$TOPDIR/50variant/release/x86_64.config"
+# "aarch64" "kernel-generic-release" \
+# "$TOPDIR/00pending/kernel/default.config" "$TOPDIR/00pending/kernel/aarch64.config" \
+# "$TOPDIR/20preset/generic/default.config" "$TOPDIR/20preset/generic/aarch64.config" \
+# "$TOPDIR/50variant/release/default.config" "$TOPDIR/50variant/release/aarch64.config"
+# ...
+#
+for_each_config_product () {
+ local _wrapper_cb=$1; shift
+
+ _wrapper () {
+ local target=$1; shift
+ local files=( "$@" )
+
+ for arch in "${CONFIG_ARCH[@]}"; do
+ local config_basename="$target.$arch.config"
+ local config_product="$CONFIG_OUTDIR/$config_basename"
+ local config_files=( )
+
+ for _conf in "${files[@]}"; do
+ config_files+=( "$_conf/default.config" )
+ if [[ -e "$_conf/$arch.config" ]]; then
+ config_files+=( "$_conf/$arch.config" )
+ fi
+ done
+
+ $_wrapper_cb "$arch" "$config_product" "${config_files[@]}"
+ done
+ }
+
+ for_each_config_target _wrapper "$@"
+}
+
+# Simply concat the backing config files in order into a single files for each config target
+populate_configs () {
+ _merge_config () {
+ local target=$1; shift
+ local config_basename output_config
+ for arch in "${CONFIG_ARCH[@]}"; do
+ config_basename="$target.$arch.config"
+ output_config="$CONFIG_OUTDIR/$config_basename"
+
+ echo "Populating $config_basename from base configs..."
+
+ for conf in "$@"; do
+ cat "$conf/default.config"
+ if [[ -e "$conf/$arch.config" ]]; then
+ cat "$conf/$arch.config"
+ fi
+ done | config_sanitizer > "$output_config"
+ done
+ }
+
+ for_each_config_target _merge_config "$@"
+}
+
+makedef_configs () {
+ _makedef_config() {
+ local target=$1; shift
+ local populated_config
+
+ for arch in "${CONFIG_ARCH[@]}"; do
+ populated_config="$CONFIG_OUTDIR/$target.$arch.config"
+
+ # config base name is always in this format: ..config
+ echo "Processing $(basename "$populated_config") with make olddefconfig..."
+
+ if ! [ -f "$populated_config" ]; then
+ error "Config not found: '$populated_config'"
+ continue
+ fi
+
+ pushd "$TOPDIR" > /dev/null || exit 1
+
+ config_make "$arch" KCONFIG_CONFIG="$populated_config" olddefconfig
+
+ popd > /dev/null || return
+ done
+ }
+
+ for_each_config_target _makedef_config "$@"
+}
diff --git a/dist/scripts/lib-version.sh b/dist/scripts/lib-version.sh
new file mode 100755
index 000000000..ecc0a41e2
--- /dev/null
+++ b/dist/scripts/lib-version.sh
@@ -0,0 +1,496 @@
+#!/bin/bash
+#
+# Version conversion helpers for building a TK kernel.
+#
+# shellcheck source=./lib.sh
+. "$(dirname "$(realpath "$0")")/lib.sh"
+
+## Autogenerated version pattern:
+# -.
+
+# KERNEL_MAJVER's format: ..
+# It's the standdard upstream linux kernel release version,
+# eg. 3.10.0; 5.4.119; 5.16.0
+#
+# KERNEL_RELVER's format: [.].
+# If is 0, indicates it's a snapshot, unofficial release.
+# If is >=1, indicates it the n'th release of that kernel version.
+#
+# KERNEL_DIST: /tks/tlinux4/...
+# Indicates this is a special build kernel.
+
+# NOTE: This versioning script fully respects the git tag if tag's
+# major kernel version matches the version numbers in kernel Makefile
+
+# This naming style is compatible with Tencent Kernel public naming style.
+# Take TK4 for example:
+#
+# Merge base: git describe --tag make install version Generate version:
+# 5.4.119 (master) 5.4.119-1-tlinux4-0007 5.4.119-1 5.4.119-1-tlinux4-0007
+# 5.4.119 (master) 5.4.119-1-tlinux4-0007-2-g884a77bf0ba6 5.4.119-1 5.4.119-0.20211115git1135ec008ef3.1-tlinux4-0007
+# 5.4.119 (master) 5.4.119-1-tlinux4-0007.subrelease 5.4.119-1 5.4.119-1-tlinux4-0007.subrelease
+# 5.4.119 (master) 5.4.119-1-tlinux4-0007~rc1 5.4.119-1 5.4.119-1-tlinux4-0007~rc1 (*)
+#
+# NOTE: Sometime TK4's release version may go backwards, it's a known issue we have to live with.
+# TK4 used tag like 5.4.119-1-tlinux4-0007.prerelease to indicate a release candidate.
+# You can check this with `rpmdev-vercmp`:
+# $ rpmdev-vercmp 5.4.119-1-tlinux4-0007.prerelease 5.4.119-1-tlinux4-0007
+# $ 5.4.119-1-tlinux4-0007.prerelease > 5.4.119-1-tlinux4-0007
+# This means RPM thinks the release candidate is higher than the real release, to fix that,
+# try use tilde symbol to indicate it's a RC.
+
+## Macros and values:
+# Standard four-part linux kernel version from kernel's Makefile
+KVERSION=
+KPATCHLEVEL=
+KSUBLEVEL=
+KEXTRAVERSION=
+
+# Kernel dist release (eg. /tks/tlinux4)
+KDIST=
+
+# KPREMERGEWINDOW: If we are building a commit in the first merge window
+# In the first merge time window, after a formal kernel release, and before rc1 release of next kernel,
+# the KPATCHLEVEL will be stuck in lower value, which confuses RPM in many ways. So just bump
+# KSUBLEVEL upon build in such case.
+#
+# For example, after 5.15 release, and before 5.16, upstream will start merging features for 5.16
+# without bumping KPATCHLEVEL, which is stuck in 15.
+# As now our build will be newer than 5.15 build, we have to make the version higher than 5.15
+# To avoid conflict with 5.15 stable build like 5.15.Y-Z, we can't bump the Y part or Z part.
+# So instead bump to 5.16 and mark it rc0 as 5.16.0-0.rc0. (Just as what Fedora does).
+KPREMERGEWINDOW=
+
+# KRCRELEASE: If we are building a rc-release
+# KSNAPRELEASE: If we are building a snapshot-release
+# Pre-release means we are building from an RC release
+# Snap-release means we are building from an git commit without tag
+export KRCRELEASE=
+export KSNAPRELEASE=
+export KTAGRELEASE=
+
+# git snapshot versioning
+KGIT_SNAPSHOT=
+# Set if current commit is tagged with valid release info, force use it.
+KGIT_FORCE_RELEAE=
+# Set if current commit is tagged with a valid test tag name
+KGIT_TESTBUILD_TAG=
+# Release: Start from 1.0, indicate the release version, info embedded in git tag
+KGIT_RELEASE=
+KGIT_RELEASE_NUM=
+KGIT_SUB_RELEASE_NUM=
+
+### The formal kernel version and release
+
+# Simulate `uname -r` output, which is always "$KVERSION.$KPATCHLEVEL.$KSUBLEVEL$KEXTRAVERSION"
+export KERNEL_UNAMER=
+# Basically: $KVERSION.$KPATCHLEVEL.$KSUBLEVEL (eg. 5.17.0, 5.16.3)
+export KERNEL_MAJVER=
+# Release version, may contain $KEXTRAVERSION (eg. 1, 0.rc0, 0.20220329gita11bf64a6e8f)
+export KERNEL_RELVER=
+# Kernel distro variable (eg. tks, tlinux4, ), with any leading "." or "-" removed
+export KERNEL_DIST=
+# Only used for make-release
+export KERNEL_PREV_RELREASE_TAG=
+
+# $1: git tag or git commit, defaults to HEAD
+# $2: kernel source tree, should be a git repo
+get_kernel_code_version() {
+ local gitref=${1:-HEAD}
+ local repo=${2:-$TOPDIR}
+ local makefile dist_makefile
+
+ makefile=$(git -C "$repo" show "$gitref:Makefile" 2>/dev/null || cat "$repo/Makefile")
+ dist_makefile=$(git -C "$repo" show "$gitref:$DISTPATH/Makefile" 2>/dev/null || cat "$repo/$DISTPAN/Makefile")
+
+ if [ ! "$makefile" ]; then
+ die "Error: Failed to read Makefile"
+ return 1
+ fi
+
+ KVERSION=$(sed -nE '/^VERSION\s*:?=\s*/{s///;p;q}' <<< "$makefile")
+ KPATCHLEVEL=$(sed -nE '/^PATCHLEVEL\s*:?=\s*/{s///;p;q}' <<< "$makefile")
+ KSUBLEVEL=$(sed -nE '/^SUBLEVEL\s*:?=\s*/{s///;p;q}' <<< "$makefile")
+ KEXTRAVERSION=$(sed -nE '/^EXTRAVERSION\s*:?=\s*/{s///;p;q}' <<< "$makefile")
+
+ if [[ -z "$KVERSION" ]] || [[ -z "$KPATCHLEVEL" ]] || [[ -z "$KSUBLEVEL" ]]; then
+ die "Invalid VERSION, PATCHLEVEL or SUBLEVEL in Makefile"
+ return 1
+ fi
+
+ # RC releases are always considered pre-release
+ if [[ "$KEXTRAVERSION" == "rc"* ]] || [[ $KEXTRAVERSION == "-rc"* ]]; then
+ KRCRELEASE=1
+ fi
+
+ KDIST=$(sed -nE '/^KDIST\s*:?=\s*/{s///;p;q}' <<< "$dist_makefile")
+ KERNEL_DIST="$KDIST"
+
+ return 0
+}
+
+_first_merge_window_detection() {
+ local gitref=${1:-HEAD}
+ local repo=${2:-$TOPDIR}
+ local upstream_base upstream_lasttag upstream_gitdesc
+
+ # If KSUBLEVEL or KEXTRAVERSION is set, it's not in the first merge window of a major release
+ [[ $KSUBLEVEL -eq 0 ]] || return 1
+ [[ -n $KEXTRAVERSION ]] && return 1
+ [[ $upstream ]] || upstream="@{u}"
+
+ # Get latest merge base if forked from upstream to merge window detection
+ # merge window is an upstream-only thing
+ if upstream_base=$(git -C "$repo" merge-base "$gitref" "$upstream" 2>/dev/null); then
+ upstream_lasttag=$(git -C "$repo" describe --tags --abbrev=0 "$upstream_base" 2>/dev/null)
+ upstream_gitdesc=$(git -C "$repo" describe --tags --abbrev=12 "$upstream_base" 2>/dev/null)
+
+ if \
+ # If last tag is an tagged upstream release
+ [[ $upstream_lasttag == v$KVERSION.$KPATCHLEVEL ]] && \
+ # And if merge base is ahead of the taggewd release
+ [[ $upstream_gitdesc != "$upstream_lasttag" ]]; then
+ # Then it's in first merge window
+ return 0
+ fi
+ else
+ warn "Not tracking a valid upstream, merge window detecting is disabled ."
+ fi
+
+ return 1
+}
+
+# Get release info from git tag
+_get_rel_info_from_tag() {
+ local tag=$1 rel ret=0
+
+ if [[ $tag == *"$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"* ]]; then
+ rel=${tag#*"$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"}
+ elif [[ "$KSUBLEVEL" = "0" ]] && [[ $tag == *"$KVERSION.$KPATCHLEVEL"* ]]; then
+ rel=${tag#*"$KVERSION.$KPATCHLEVEL"}
+ elif [[ $KPREMERGEWINDOW ]] && [[ $tag == *"$KVERSION.$((KPATCHLEVEL + 1)).$KSUBLEVEL"* ]]; then
+ rel=${tag#*"$KVERSION.$((KPATCHLEVEL + 1)).$KSUBLEVEL"}
+ else
+ return 1
+ fi
+ rel=${rel#-}
+ rel=${rel#.}
+
+ local kextraversion=${KEXTRAVERSION#-}
+
+ if [[ -z "$kextraversion" ]]; then
+ # If previous KEXTRAVERSION is not empty but now empty,
+ # still consider it a valid release tag since release candidate mark may get dropped.
+ # But this really should look at the Makefile corresponding to that tag commit
+ :
+ elif [ "$kextraversion" -eq "$kextraversion" ] &>/dev/null; then
+ case $rel in
+ # Extra version is release number, ok
+ $kextraversion | "$kextraversion."* | "$kextraversion-"* ) ;;
+ * ) return 1; ;;
+ esac
+ else
+ # Remove RC liked tag, append them as suffix later.
+ case $rel in
+ # Plain version tag, eg. 5.17-rc3
+ $kextraversion )
+ rel=""
+ ;;
+ # Plain version tag plus suffix, eg. 5.17-rc3-*
+ "$kextraversion."* | "$kextraversion-"* )
+ rel=${rel#$kextraversion}
+ rel=${rel#-}
+ rel=${rel#.}
+ ;;
+ # Extra tag, eg 5.17-1.rc3*
+ *".$kextraversion"* | *"-$kextraversion"* ) ;;
+ * ) return 1; ;;
+ esac
+ fi
+
+ if [[ $rel ]]; then
+ echo "${rel/-/.}"
+ fi
+}
+
+_search_for_release_tag() {
+ local tag=$1
+ local repo=$2
+
+ # Look back for 5 commits for a valid tag
+ local limit=5
+ while :; do
+ limit=$((limit - 1))
+
+ if [[ $limit -le 0 ]] || ! tag=$(git -C "$repo" describe --tags --abbrev=0 "$tag^" 2>/dev/null); then
+ warn "No valid tag found that are eligible for versioning, please fix your repo and tag it properly."
+ return 1
+ fi
+
+ if _get_rel_info_from_tag "$tag" > /dev/null; then
+ echo "$tag"
+ return 0
+ fi
+ done
+}
+
+# Get release info from git tag
+#
+# We try to store the RPM NVR (Name, Version, Release) info's VR part in git tag
+# N: is always kernel
+# V: is kernel's major release version (eg. 5.18, 5.18.0, 5.17.2)
+# R: is a tokens seperated with '.' (eg 1[.KDIST], 2[.KDIST], 2.1[.KDIST], 0.rc1[.KDIST])
+# could also be 0.YYYYMMDDgit for snapshot release.
+# But ideally all git tag are for formal release so snapshot tag shouldn't appear in repo.
+#
+# A tag that contains VR is considered a release tag.
+#
+# $1: git tag or git commit, defaults to HEAD
+# $2: kernel source tree, should be a git repo
+# $3: optional upstream branch, remote branch name current HEAD is tracking
+get_kernel_git_version()
+{
+ local gitref=${1:-HEAD}
+ local repo=${2:-$TOPDIR}
+ local upstream=${3:-"@{u}"}
+
+ local last_tag release_tag release_info git_desc
+ local tag
+
+ # Get current commit's snapshot name, format: YYYYMMDDgit,
+ # or YYYYMMDD (Only if repo is missing, eg. running this script with tarball)
+ if ! KGIT_SNAPSHOT=$(git rev-parse --short=12 "$gitref" 2>/dev/null); then
+ warn "Invalid git reference '$gitref' or git repo is unavailable, versioning it as a dated snapshot"
+ KGIT_SNAPSHOT=$(date +"%Y%m%d")
+ KSNAPRELEASE=1
+ return
+ fi
+ KGIT_SNAPSHOT=$(date +"%Y%m%d")git$KGIT_SNAPSHOT
+
+ # Check if first merge-window, and set KPREMERGEWINDOW, see comment above about KPREMERGEWINDOW
+ if _first_merge_window_detection "$@"; then
+ KPREMERGEWINDOW=1
+ fi
+
+ # Get latest git tag of this commit
+ last_tag=$(git -C "$repo" describe --tags --abbrev=0 "$gitref" 2>/dev/null)
+ # Check and get latest release git tag, in case current tag is a test tag
+ # (eg. current tag is fix_xxxx, rebase_test_xxxx, or user tagged for fun, and previous release tag is 5.18.0-1[.KDIST])
+ if _get_rel_info_from_tag "$last_tag" > /dev/null; then
+ # Latest tag is a release tag, just use it
+ release_tag=$last_tag
+ else
+ warn "Latest git tag '$last_tag' is not a release tag, it does't match Makefile version '$KVERSION.$KPATCHLEVEL.$KSUBLEVEL$KEXTRAVERSION'"
+ if release_tag=$(_search_for_release_tag "$last_tag" "$repo"); then
+ warn "Found release tag '$release_tag'."
+ fi
+ fi
+
+ if [[ "$release_tag" ]]; then
+ git_desc=$(git -C "$repo" describe --tags --abbrev=12 "$gitref" 2>/dev/null)
+ release_info=$(_get_rel_info_from_tag "$release_tag")
+ # Remove dist suffix, it'a always added for auto generated tag
+ KGIT_RELEASE=${release_info%".$KDIST"}
+
+ if ! [[ $release_info ]]; then
+ warn "No extra release info in release tag, might be a upstream tag." \
+ "Please make a release commit with 'make dist-release' for a formal release."
+ KGIT_RELEASE_NUM=0
+ KGIT_SUB_RELEASE_NUM=0
+ elif [[ $release_info == 0.* ]]; then
+ KGIT_RELEASE_NUM=${release_info##*.}
+ KGIT_RELEASE_NUM=${KGIT_RELEASE_NUM##*-}
+ KGIT_SUB_RELEASE_NUM=${release_info%."$KGIT_RELEASE_NUM"}
+ KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM##*.}
+ else
+ KGIT_RELEASE_NUM=${release_info%%.*}
+ KGIT_RELEASE_NUM=${KGIT_RELEASE_NUM%%-*}
+ KGIT_SUB_RELEASE_NUM=${release_info#"$KGIT_RELEASE_NUM".}
+ KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM%%.*}
+ fi
+
+ # Fix release numbers, if it's not a number
+ if ! [ "$KGIT_RELEASE_NUM" -eq "$KGIT_RELEASE_NUM" ] &>/dev/null; then
+ warn "Unrecognizable release number: $KGIT_RELEASE_NUM, resetting to 0"
+ KGIT_RELEASE_NUM=0
+ fi
+ if ! [ "$KGIT_SUB_RELEASE_NUM" -eq "$KGIT_SUB_RELEASE_NUM" ] &>/dev/null; then
+ KGIT_SUB_RELEASE_NUM=0
+ fi
+
+ if [[ "$release_tag" == "$git_desc" ]]; then
+ if [[ $release_info ]] && [[ "$KGIT_RELEASE_NUM" -ne 0 ]]; then
+ # This commit is tagged and it's a valid release tag, juse use it
+ KGIT_FORCE_RELEAE=$release_info
+ KTAGRELEASE=$release_tag
+ fi
+ elif [[ "$last_tag" == "$git_desc" ]]; then
+ # A dumb assumption here, if it's not in *.* format (v5.4, 4.12.0, etc...) it's a test tag
+ if [[ $last_tag != v*.* ]] && [[ $last_tag != *.*.* ]]; then
+ warn "'$last_tag' looks like a test tag, using it as versioning suffix."
+ warn "Please tag properly for release build, now versioning it as a test build."
+ KGIT_TESTBUILD_TAG=testbuild.$last_tag
+ else
+ warn "'$last_tag' looks like a kernel release tag but out-of-sync with Makefile" \
+ "ignoring it and versioning as snapshot."
+ warn "Please tag properly for release build."
+ KSNAPRELEASE=1
+ fi
+ else
+ # Just a simple untagged commit, nothing special
+ KSNAPRELEASE=1
+ fi
+
+ KERNEL_PREV_RELREASE_TAG=$release_tag
+ else
+ KSNAPRELEASE=1
+ KGIT_RELEASE_NUM=0
+ fi
+
+}
+
+_prepare_kernel_ver() {
+ if ! get_kernel_code_version "$@"; then
+ return 1
+ fi
+
+ if ! get_kernel_git_version "$@"; then
+ return 1
+ fi
+
+ # Disable PRE-merge window detection for tagged commit,
+ # We want to following user provided tag strictly
+ if [[ ! $KGIT_FORCE_RELEAE ]]; then
+ if [[ $KPREMERGEWINDOW ]]; then
+ KPATCHLEVEL=$(( KPATCHLEVEL + 1 ))
+ fi
+ fi
+}
+
+### Generate a RPM friendly version based on kernel tag and commit info
+#
+# Examples:
+# (Ignoring pre-release window detection, see comments about KPREMERGEWINDOW)
+# (Also assume Makefile's kernel version info is all correct)
+#
+# git describe --tags Generated version (uname -r) Corresponding RPM version
+# v5.18 5.18.0-0[.KDIST] kernel[-kdist]-5.18.0-0.rc1
+# v5.18.0 5.18.0-0[.KDIST] kernel[-kdist]-5.18.0-0.rc1
+# v5.18.1 5.18.1-0[.KDIST] kernel[-kdist]-5.18.1-0.rc1
+# v5.18.0-1-gac28df2 5.18.0-0.20220428gitac28df2cd5d0[.KDIST] kernel[-kdist]-5.18.0-0.20220428gitac28df2cd5d0 *
+# v5.18.0-3-g16cadc5 5.18.0-0.20220428git16cadc58d50c[.KDIST] kernel[-kdist]-5.18.0-0.20220428git16cadc58d50c *
+# v5.18-rc1 5.18.0-0.rc1[.KDIST] kernel[-kdist]-5.18.0-0.rc1
+# v5.18-rc1-1-g380a504 5.18.0-0.20220428git380a504e42d9.rc1[.KDIST] kernel[-kdist]-5.18.0-0.20220428git380a504e42d9.rc1
+# 5.18.0-1[.KDIST] 5.18.0-1[.KDIST] kernel[-kdist]-5.18.0-1
+# 5.18.12-3[.KDIST] 5.18.12-3[.KDIST] kernel[-kdist]-5.18.12-3
+# 5.18.12-3[.KDIST]-5-g9318b03 5.18.12-0.20220428git9318b0349d5c.3[.KDIST] kernel[-kdist]-5.18.12-0.20220428git9318b0349d5c.3
+# 5.18.0-12.rc1[.KDIST] 5.18.0-12.rc1[.KDIST] kernel[-kdist]-5.18.0-12.rc1
+# 5.18.0-12[.KDIST]-2-g551f9cd 5.18.0-0.20220428git551f9cd79ece.12[.KDIST] kernel[-kdist]-5.18.0-0.20220428git551f9cd79ece.12
+# x86-5.4.119-19-0010.prerelease 5.4.119-19-0010.prerelease kernel[-kdist]-5.4.119-19-0010.prerelease **
+#
+# * NOTE: random commit snapshot can't be versioning in non-decreasing since one can always amend/rebase, so only the date stamp matters now.
+#
+# As you may have noticed, release always start with '0' unless a git tag have release >= 1,
+# The tag should be generated by other commands that comes later in this script.
+prepare_kernel_ver() {
+ _prepare_kernel_ver "$@"
+
+ # If it's a tagged commit, and the release number in tag is non-zero, use that
+ if [[ $KGIT_FORCE_RELEAE ]]; then
+ KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
+ KERNEL_RELVER="$KGIT_FORCE_RELEAE"
+ else
+ local krelease=0
+ if [[ $KSNAPRELEASE ]]; then
+ krelease=$krelease.$KGIT_SNAPSHOT
+ elif [[ $KGIT_RELEASE ]]; then
+ krelease=$krelease.$KGIT_RELEASE
+ fi
+
+ if [[ $KEXTRAVERSION ]]; then
+ krelease="$krelease.${KEXTRAVERSION##-}"
+ elif [[ $KPREMERGEWINDOW ]]; then
+ krelease="$krelease.rc0"
+ fi
+
+ if [[ $KGIT_TESTBUILD_TAG ]]; then
+ # '-' is not allowed in release name, but commonly used in tag
+ krelease="$krelease.${KGIT_TESTBUILD_TAG//-/_}"
+ fi
+
+ KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
+ KERNEL_RELVER="$krelease${KDIST:+.$KDIST}"
+ fi
+
+ KERNEL_UNAMER="$KERNEL_MAJVER-$KERNEL_RELVER"
+}
+
+### Generate formal release version based on kernel tag and commit info
+#
+# Examples:
+# (Ignoring pre-release window detection, see comments about KPREMERGEWINDOW)
+# (Also assume Makefile's kernel version info is all correct)
+#
+# git describe --tags Generated Version (uname -r) Corresponding RPM version
+# v5.18 5.18.0-1[.KDIST] kernel[-kdist]-5.18.0-1
+# v5.18.0 5.18.0-1[.KDIST] kernel[-kdist]-5.18.0-1
+# v5.18.1 5.18.1-1[.KDIST] kernel[-kdist]-5.18.1-1
+# v5.18.0-1-gac28df2 5.18.0-1[.KDIST] kernel[-kdist]-5.18.0-1
+# v5.18.0-3-g16cadc5 5.18.0-1[.KDIST] kernel[-kdist]-5.18.0-1
+# v5.18-rc1 5.18.0-1.rc1[.KDIST] kernel[-kdist]-5.18.0-1.rc1
+# v5.18-rc1-1-g380a504 5.18.0-1.rc1[.KDIST] kernel[-kdist]-5.18.0-1.rc1
+# 5.18.0-1[.KDIST] 5.18.0-2[.KDIST] kernel[-kdist]-5.18.0-2
+# 5.18.12-3[.KDIST] 5.18.12-4[.KDIST] kernel[-kdist]-5.18.12-4
+# 5.18.12-3[.KDIST]-5-g9318b03 5.18.12-4[.KDIST] kernel[-kdist]-5.18.12-4
+# 5.18.0-12.rc1[.KDIST] 5.18.0-12.rc1[.KDIST] kernel[-kdist]-5.18.0-13.rc1
+# 5.18.0-12[.KDIST]-2-g551f9cd 5.18.0-0.20220428git551f9cd79ece.12[.KDIST] kernel[-kdist]-5.18.0-13
+# x86-5.4.119-19-0010.prerelease 5.4.119-20[.KDIST] kernel[-kdist]-5.4.119-20[.KDIST]
+#
+# * NOTE: random commit snapshot can't be versioning in non-decreasing since one can always amend/rebase, so only the date stamp matters now.
+# ** NOTE: Yes, this script is compatible with TK4
+#
+# As you may have noticed, release always start with '0' unless a git tag have release >= 1,
+# The tag should be generated by other commands that comes later in this script.
+prepare_next_kernel_ver() {
+ _prepare_kernel_ver "$@"
+
+ if [[ $KPREMERGEWINDOW ]]; then
+ warn "Upstream is in merge window, forcing a formal release is not recommanded."
+ fi
+
+ krelease=$((KGIT_RELEASE_NUM + 1))
+
+ if [[ $KEXTRAVERSION ]]; then
+ krelease="$krelease.${KEXTRAVERSION##-}"
+ elif [[ $KPREMERGEWINDOW ]]; then
+ krelease="$krelease.rc0"
+ fi
+
+ KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
+ KERNEL_RELVER="$krelease${KDIST:+.$KDIST}"
+ KERNEL_UNAMER="$KERNEL_MAJVER-$KERNEL_RELVER"
+}
+
+# Get next formal kernel version based on previous git tag
+# Same as prepare_next_kernel_ver, but increase sub version instead.
+# eg. instead of 5.18.12-3[.KDIST] -> 5.18.12-4[.KDIST], this generates 5.18.12-3[.KDIST] -> 5.18.12-3.1[.KDIST]
+prepare_next_sub_kernel_ver() {
+ _prepare_kernel_ver "$@"
+
+ if [[ $KPREMERGEWINDOW ]]; then
+ warn "Upstream is in merge window, forcing a formal release is not recommanded."
+ fi
+
+ krelease=$((KGIT_RELEASE_NUM + 0))
+ krelease=$krelease.$((KGIT_SUB_RELEASE_NUM + 1))
+
+ if [[ $KEXTRAVERSION ]]; then
+ krelease="$krelease.${KEXTRAVERSION##-}"
+ elif [[ $KPREMERGEWINDOW ]]; then
+ krelease="$krelease.rc0"
+ fi
+
+ KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
+ KERNEL_RELVER="$krelease${KDIST:+.$KDIST}"
+ KERNEL_UNAMER="$KERNEL_MAJVER-$KERNEL_RELVER"
+}
diff --git a/dist/scripts/lib.sh b/dist/scripts/lib.sh
new file mode 100755
index 000000000..2bc6cbdd9
--- /dev/null
+++ b/dist/scripts/lib.sh
@@ -0,0 +1,135 @@
+#!/bin/bash
+#
+# Shell helpers
+#
+
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+YELLOW="\033[1;33m"
+NC="\033[0m"
+
+echo_green() {
+ echo -en "$GREEN"
+ echo "$@"
+ echo -en "$NC"
+}
+
+echo_yellow() {
+ echo -en "$YELLOW"
+ echo "$@"
+ echo -en "$NC"
+}
+
+echo_red() {
+ echo -en "$RED"
+ echo "$@"
+ echo -en "$NC"
+}
+
+info() {
+ echo_green -n "info: " >&2
+ echo "$@"
+}
+
+warn() {
+ echo_yellow -n "warn: " >&2
+ echo "$@" >&2
+}
+
+error() {
+ echo_red -n "error: " >&2
+ echo "$@" >&2
+}
+
+die() {
+ echo_red -n "fatal: " >&2
+ echo "$@" >&2
+ exit 1
+}
+
+get_dist_makefile_var() {
+ local _lib_source=${BASH_SOURCE[0]}
+ local _val
+
+ # Just one sed call, fast and simple
+ # Match anyline start with "^$1\s*=\s*", strip and remove matching part then store in hold buffer.
+ # Pprint the hold buffer on exit. This ensure the last assigned value is used, matches Makefile syntax well
+ _val=$(sed -nE -e \
+ "/^$1\s*:?=\s*(.*)/{s/^\s*^$1\s*:?=\s*//;h};\${x;p}" \
+ "$(dirname "$(realpath "$_lib_source")")/../Makefile")
+
+ case $_val in
+ *\$* )
+ die "Can't parse Makefile variable '$1', which references to other variables."
+ ;;
+ esac
+
+ echo "$_val"
+}
+
+[ "$TOPDIR" ] || TOPDIR=$(git rev-parse --show-toplevel 2>/dev/null)
+[ "$TOPDIR" ] || TOPDIR="$(realpath "$(dirname "$(realpath "$0")")/../..")"
+[ "$VENDOR" ] || VENDOR=$(get_dist_makefile_var VENDOR)
+[ "$DISTPATH" ] || DISTPATH=$(get_dist_makefile_var DISTPATH)
+[ "$DISTDIR" ] || DISTDIR=$TOPDIR/$DISTPATH
+[ "$SOURCEDIR" ] || SOURCEDIR=$DISTDIR/rpm/SOURCES
+[ "$SPEC_ARCH" ] || SPEC_ARCH=$(get_dist_makefile_var SPEC_ARCH)
+
+if ! [ -s "$TOPDIR/Makefile" ]; then
+ echo "Dist tools can only be run within a valid Linux Kernel git workspace." >&2
+ exit 1
+fi
+
+if [ -z "$VENDOR" ] || ! [ -s "$DISTDIR/Makefile" ]; then
+ echo "Dist tools can't work without properly configured dist file." >&2
+ exit 1
+fi
+
+# Just use uname to get native arch
+get_native_arch () {
+ uname -m
+}
+
+# Convert any arch name into linux kernel arch name
+#
+# There is an inconsistence between Linux kernel's arch naming and
+# RPM arch naming. eg. Linux kernel uses arm64 instead of aarch64
+# used by RPM, i686 vs x86, amd64 vs x86_64. Most are just same things
+# with different name due to historical reasons.
+get_kernel_arch () {
+ case $1 in
+ riscv64 )
+ echo "riscv"
+ ;;
+ arm64 | aarch64 )
+ echo "arm64"
+ ;;
+ i386 | i686 | x86 )
+ echo "x86"
+ ;;
+ amd64 | x86_64 )
+ echo "x86_64"
+ ;;
+ esac
+}
+
+# Convert any arch name into linux kernel src arch name
+#
+# Similiar to get_kernel_arch but return the corresponding
+# source code base sub path in arch/
+get_kernel_src_arch () {
+ case $1 in
+ riscv64 )
+ echo "riscv"
+ ;;
+ arm64 | aarch64 )
+ echo "arm64"
+ ;;
+ i386 | i686 | x86 | amd64 | x86_64 )
+ echo "x86"
+ ;;
+ esac
+}
+
+type git >/dev/null || die 'git is required'
+type make >/dev/null || die 'make is required'
diff --git a/dist/scripts/ls-config-files.sh b/dist/scripts/ls-config-files.sh
new file mode 100755
index 000000000..09d76ffee
--- /dev/null
+++ b/dist/scripts/ls-config-files.sh
@@ -0,0 +1,17 @@
+#!/bin/bash --norc
+#
+# List files to be generated for kernel config styles
+#
+# Params:
+# $@: [ ... ] When non-empty, only show kernel configs style matching
+
+# shellcheck source=./lib-config.sh
+. "$(dirname "$(realpath "$0")")/lib-config.sh"
+
+_echo_file() {
+ for arch in "${CONFIG_ARCH[@]}"; do
+ echo "$CONFIG_OUTDIR/$1.$arch.config"
+ done
+}
+
+for_each_config_target _echo_file "$@"
diff --git a/dist/scripts/ls-config-targets.sh b/dist/scripts/ls-config-targets.sh
new file mode 100755
index 000000000..00d35c18f
--- /dev/null
+++ b/dist/scripts/ls-config-targets.sh
@@ -0,0 +1,15 @@
+#!/bin/bash --norc
+#
+# List available kernel config styles
+#
+# Params:
+# $@: [ ... ] When non-empty, only show kernel configs style matching
+
+# shellcheck source=./lib-config.sh
+. "$(dirname "$(realpath "$0")")/lib-config.sh"
+
+_echo() {
+ echo "$1" 2>/dev/null || exit 0
+}
+
+for_each_config_target _echo "$@"
diff --git a/dist/scripts/make-release.sh b/dist/scripts/make-release.sh
new file mode 100755
index 000000000..7d66a65db
--- /dev/null
+++ b/dist/scripts/make-release.sh
@@ -0,0 +1,93 @@
+#!/bin/bash --norc
+#
+# Print out the tkernel version based on git commit and work tree.
+#
+# shellcheck source=./lib-version.sh
+. "$(dirname "$(realpath "$0")")/lib-version.sh"
+
+COMMIT=HEAD
+case $1 in
+ --sub-release )
+ prepare_next_sub_kernel_ver "$COMMIT" "$TOPDIR" || die "Failed preparing next sub release version info"
+ ;;
+ "")
+ prepare_next_kernel_ver "$COMMIT" "$TOPDIR" || die "Failed preparing next release version info"
+ ;;
+ *)
+ die "Invalid param $1"
+ ;;
+esac
+AUTHOR_NAME=$(git config user.name) || die "Failed getting author name info from git config"
+AUTHOR_MAIL=$(git config user.email) || die "Failed getting author email info from git config"
+GITLOG=$(git -C "$TOPDIR" log "$KERNEL_PREV_RELREASE_TAG..$COMMIT" --pretty=oneline) || die "Failed getting changelog from git log"
+
+AUTHOR="$AUTHOR_NAME <$AUTHOR_MAIL>"
+RELEASE_VERSION="$KERNEL_MAJVER-$KERNEL_RELVER"
+TAG_VERSION="release-$KERNEL_UNAMER"
+CHANGELOG="* $(date +"%a %b %e %Y") $AUTHOR - $RELEASE_VERSION
+$(echo "$GITLOG" | sed -E "s/^\S+/-/g")"
+
+print_info() {
+ cat << EOF
+Please review following info:
+\* DO NOT CHANGE THE FILE FORMAT \*
+
+Tag: $TAG_VERSION
+Release Version: $RELEASE_VERSION
+Release Author: $AUTHOR
+Changelog:
+$CHANGELOG
+EOF
+}
+
+dump_info() {
+ print_info > "$DISTDIR/.release.stash"
+}
+
+update_info() {
+ ${EDITOR:-vi} "$DISTDIR/.release.stash" || die "Failed to call editor to edit the release info"
+}
+
+parse_info() {
+ TAG_VERSION=$(sed -E -ne "s/^Tag:\s*(.*)/\1/p" "$DISTDIR/.release.stash")
+ RELEASE_VERSION=$(sed -E -ne "s/\s*Release Version:\s*(.*)/\1/p" "$DISTDIR/.release.stash")
+ AUTHOR=$(sed -E -ne "s/^Release Author:\s*(.*)/\1/p" "$DISTDIR/.release.stash")
+ CHANGELOG=$(sed -n '/^* /,$p' "$DISTDIR/.release.stash")
+}
+
+while :; do
+ _res="?"
+ while :; do
+ {
+ print_info
+ echo
+ echo "(Press 'q' to exit preview.)"
+ } | less
+ echo "Is this OK? (y/n/q/e, Y: Do the release, N/Q: quit, E: edit)"
+ read -r -n1 _res
+ case $_res in
+ n|N|q|Q )
+ exit 0
+ ;;
+ y|Y )
+ echo "$CHANGELOG" >> "$DISTDIR/templates/changelog.new"
+ echo "" >> "$DISTDIR/templates/changelog.new"
+ cat "$DISTDIR/templates/changelog" >> "$DISTDIR/templates/changelog.new"
+ mv "$DISTDIR/templates/changelog.new" "$DISTDIR/templates/changelog"
+ git -C "$TOPDIR" add "$DISTPATH/templates/changelog"
+ git -C "$TOPDIR" commit -m "$DISTPATH: release $RELEASE_VERSION
+
+Upstream: no
+
+Signed-off-by: $AUTHOR"
+ git -C "$TOPDIR" tag "$TAG_VERSION"
+ exit 0
+ ;;
+ e|E )
+ dump_info
+ update_info
+ parse_info
+ ;;
+ esac
+ done
+done
diff --git a/dist/sources/MLNX_OFED_SRC-5.1-2.5.8.0.46.tgz b/dist/sources/MLNX_OFED_SRC-5.1-2.5.8.0.46.tgz
new file mode 100644
index 000000000..1247913c3
Binary files /dev/null and b/dist/sources/MLNX_OFED_SRC-5.1-2.5.8.0.46.tgz differ
diff --git a/dist/sources/README b/dist/sources/README
new file mode 100644
index 000000000..e69de29bb
diff --git a/dist/sources/check-kabi b/dist/sources/check-kabi
new file mode 100755
index 000000000..0defb4d02
--- /dev/null
+++ b/dist/sources/check-kabi
@@ -0,0 +1,156 @@
+#!/usr/bin/python3
+#
+# check-kabi - Red Hat kABI reference checking tool
+#
+# We use this script to check against reference Module.kabi files.
+#
+# Author: Jon Masters
+# Copyright (C) 2007-2009 Red Hat, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# General Public License (GPL).
+
+# Changelog:
+#
+# 2018/06/01 - Update for python3 by Petr Oros.
+# 2009/08/15 - Updated for use in RHEL6.
+# 2007/06/13 - Initial rewrite in python by Jon Masters.
+
+__author__ = "Jon Masters "
+__version__ = "2.0"
+__date__ = "2009/08/15"
+__copyright__ = "Copyright (C) 2007-2009 Red Hat, Inc"
+__license__ = "GPL"
+
+import getopt
+import string
+import sys
+
+true = 1
+false = 0
+
+def load_symvers(symvers, filename):
+ """Load a Module.symvers file."""
+
+ symvers_file = open(filename, "r")
+
+ while true:
+ in_line = symvers_file.readline()
+ if in_line == "":
+ break
+ if in_line == "\n":
+ continue
+ try:
+ checksum, symbol, directory, type = in_line.split()
+ except ValueError:
+ # Firmware symbol may have an extra field
+ checksum, symbol, directory, type, extra = in_line.split()
+
+ symvers[symbol] = " ".join([checksum, symbol, directory, type])
+
+
+def load_kabi(kabi, filename):
+ """Load a Module.kabi file."""
+
+ kabi_file = open(filename, "r")
+
+ while true:
+ in_line = kabi_file.readline()
+ if in_line == "":
+ break
+ if in_line == "\n":
+ continue
+ try:
+ checksum, symbol, directory, type = in_line.split()
+ except ValueError:
+ # Firmware symbol may have an extra field
+ checksum, symbol, directory, type, extra = in_line.split()
+
+ kabi[symbol] = " ".join([checksum, symbol, directory, type])
+
+
+def check_kabi(symvers, kabi):
+ """Check Module.kabi and Module.symvers files."""
+
+ fail = 0
+ warn = 0
+ changed_symbols = []
+ moved_symbols = []
+
+ for symbol in kabi:
+ abi_hash, abi_sym, abi_dir, abi_type = kabi[symbol].split()
+ if symbol in symvers:
+ sym_hash, sym_sym, sym_dir, sym_type = symvers[symbol].split()
+ if abi_hash != sym_hash:
+ fail = 1
+ changed_symbols.append(symbol)
+
+ if abi_dir != sym_dir:
+ warn = 1
+ moved_symbols.append(symbol)
+ else:
+ fail = 1
+ changed_symbols.append(symbol)
+
+ if fail:
+ print("*** ERROR - ABI BREAKAGE WAS DETECTED ***")
+ print("")
+ print("The following symbols have been changed (this will cause an ABI breakage):")
+ print("")
+ for symbol in changed_symbols:
+ print(symbol)
+ print("")
+
+ if warn:
+ print("*** WARNING - ABI SYMBOLS MOVED ***")
+ print("")
+ print("The following symbols moved (typically caused by moving a symbol from being")
+ print("provided by the kernel vmlinux out to a loadable module):")
+ print("")
+ for symbol in moved_symbols:
+ print(symbol)
+ print("")
+
+ """Halt the build, if we got errors and/or warnings. In either case,
+ double-checkig is required to avoid introducing / concealing
+ KABI inconsistencies."""
+ if fail or warn:
+ sys.exit(1)
+ sys.exit(0)
+
+
+def usage():
+ print("""
+check-kabi: check Module.kabi and Module.symvers files.
+
+ check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
+
+""")
+
+
+if __name__ == "__main__":
+
+ symvers_file = ""
+ kabi_file = ""
+
+ opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
+
+ for o, v in opts:
+ if o == "-s":
+ symvers_file = v
+ if o == "-h":
+ usage()
+ sys.exit(0)
+ if o == "-k":
+ kabi_file = v
+
+ if (symvers_file == "") or (kabi_file == ""):
+ usage()
+ sys.exit(1)
+
+ symvers = {}
+ kabi = {}
+
+ load_symvers(symvers, symvers_file)
+ load_kabi(kabi, kabi_file)
+ check_kabi(symvers, kabi)
diff --git a/dist/sources/cpupower.config b/dist/sources/cpupower.config
new file mode 100644
index 000000000..8629a4a3e
--- /dev/null
+++ b/dist/sources/cpupower.config
@@ -0,0 +1,3 @@
+# See 'cpupower help' and cpupower(1) for more info
+CPUPOWER_START_OPTS="frequency-set -g performance"
+CPUPOWER_STOP_OPTS="frequency-set -g ondemand"
diff --git a/dist/sources/cpupower.service b/dist/sources/cpupower.service
new file mode 100644
index 000000000..5f10ab7ee
--- /dev/null
+++ b/dist/sources/cpupower.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Configure CPU power related settings
+After=syslog.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+EnvironmentFile=/etc/sysconfig/cpupower
+ExecStart=/usr/bin/cpupower $CPUPOWER_START_OPTS
+ExecStop=/usr/bin/cpupower $CPUPOWER_STOP_OPTS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dist/sources/filter-aarch64.sh b/dist/sources/filter-aarch64.sh
new file mode 100755
index 000000000..98d4e147c
--- /dev/null
+++ b/dist/sources/filter-aarch64.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Copied from Fedora
+
+# This is the aarch64 override file for the core/drivers package split. The
+# module directories listed here and in the generic list in filter-modules.sh
+# will be moved to the resulting kernel-modules package for this arch.
+# Anything not listed in those files will be in the kernel-core package.
+#
+# Please review the default list in filter-modules.sh before making
+# modifications to the overrides below. If something should be removed across
+# all arches, remove it in the default instead of per-arch.
+
+driverdirs="atm auxdisplay bcma bluetooth firewire fpga infiniband leds media memstick message mmc mtd nfc ntb pcmcia power ssb soundwire staging tty uio w1 ofed_addon"
+
+ethdrvs="3com adaptec arc alteon atheros broadcom cadence calxeda chelsio cisco dec dlink emulex marvell micrel myricom neterion nvidia packetengines qlogic rdc sfc silan sis smsc stmicro sun tehuti ti via wiznet xircom"
+
+drmdrvs="amd arm bridge ast exynos hisilicon i2c imx mgag200 meson msm nouveau panel pl111 radeon rockchip tegra sun4i tiny vc4"
+
+singlemods="ntb_netdev iscsi_ibft iscsi_boot_sysfs megaraid pmcraid qedi qla1280 9pnet_rdma rpcrdma nvmet-rdma nvme-rdma hid-picolcd hid-prodikeys hwpoison-inject target_core_user sbp_target cxgbit chcr rnbd-client rnbd-server mlx5_ib mlx5_core mlx5_vdpa dfl-emif octeontx2-cpt octeontx2-cptvf spi-altera-dfl rvu_cptpf rvu_cptvf regmap-sdw regmap-sdw-mbq hid-playstation hid-nintendo configs"
diff --git a/dist/sources/filter-modules.sh b/dist/sources/filter-modules.sh
new file mode 100755
index 000000000..4eaa27d1a
--- /dev/null
+++ b/dist/sources/filter-modules.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+#
+# Used Fedora kernel-ark repo as reference.
+#
+# Called as filter-modules.sh
+#
+# This script collects modules, and filters modules into the kernel-core and kernel-modules
+# subpackages. We list out subsystems/subdirs to prune from the installed
+# module directory. What is left is put into the kernel-core package. What is
+# pruned is contained in the kernel-modules package.
+#
+# This file contains the default subsys/subdirs to prune from all architectures.
+# If an architecture needs to differ, we source a per-arch filter-.sh file
+# that contains the set of override lists to be used instead. If a module or
+# subsys should be in kernel-modules on all arches, please change the defaults
+# listed here.
+
+# Set the default dirs and modules to filter out as external modules
+
+driverdirs="atm auxdisplay bcma bluetooth firewire fmc fpga iio infiniband isdn leds media memstick message mfd mmc mtd nfc ntb pcmcia platform power powercap ssb soundwire staging thermal tty uio w1 ofed_addon"
+
+chardrvs="mwave pcmcia"
+
+netdrvs="appletalk can dsa hamradio ieee802154 irda ppp slip usb wireless"
+
+ethdrvs="3com adaptec alteon amd aquantia arc atheros broadcom cadence calxeda chelsio cisco dec dlink emulex icplus marvell mellanox micrel myricom neterion nvidia oki-semi packetengines qlogic rdc renesas sfc silan sis smsc stmicro sun tehuti ti wiznet xircom"
+
+inputdrvs="gameport tablet touchscreen joystick"
+
+hiddrvs="surface-hid"
+
+scsidrvs="aacraid aic7xxx aic94xx be2iscsi bfa bnx2i bnx2fc csiostor cxgbi esas2r fcoe fnic hisi_sas isci libsas lpfc megaraid mpt2sas mpt3sas mvsas pm8001 qla2xxx qla4xxx sym53c8xx_2 ufs qedf"
+
+usbdrvs="atm image misc serial wusbcore"
+
+drmdrvs="amd ast bridge gma500 i2c i915 mgag200 nouveau panel radeon via"
+
+netprots="6lowpan appletalk atm ax25 batman-adv bluetooth can dccp dsa ieee802154 irda l2tp mac80211 mac802154 mpls netrom nfc rds rfkill rose sctp smc wireless"
+
+fsdrvs="affs befs cifs coda cramfs dlm ecryptfs hfs hfsplus jfs jffs2 minix ncpfs nilfs2 ocfs2 reiserfs romfs squashfs sysv ubifs ufs gfs2"
+
+# .ko files to be filtered
+singlemods="ntb_netdev iscsi_ibft iscsi_boot_sysfs megaraid pmcraid qedi qla1280 9pnet_rdma rpcrdma nvmet-rdma nvme-rdma hid-picolcd hid-prodikeys hwa-hc hwpoison-inject hid-sensor-hub target_core_user sbp_target cxgbit iw_cxgb3 iw_cxgb4 cxgb3i cxgb3i cxgb3i_ddp cxgb4i chcr chtls parport_serial ism regmap-sdw regmap-sdw-mbq arizona-micsupp hid-asus iTCO_wdt rnbd-client rnbd-server mlx5_ib mlx5_vdpa spi-altera-dfl nct6775 hid-playstation hid-nintendo ntc_thermistor configs"
+
+# Overrides is individual modules which need to remain in kernel-core due to deps.
+overrides="cec"
+
+BASE_DIR=$1
+KERNEL_UNAMER=$2
+ARCH=$3
+SYSTEM_MAP=$(realpath "$4")
+MODULE_DIR=lib/modules/$KERNEL_UNAMER
+
+# Grab the arch-specific filter list overrides
+source "$(dirname "$(realpath "$0")")/filter-$ARCH.sh"
+
+error() {
+ echo "$@">&2
+}
+
+if ! cd "$BASE_DIR"; then
+ error "Invalid base path: '$BASE_DIR'"
+ exit 1
+fi
+
+if ! cd "$MODULE_DIR"; then
+ error "Invalid kernel module path: '$MODULE_DIR'"
+ exit 1
+fi
+
+# To be read from build path
+core_modules_list=
+modules_list=
+
+# Read all kernel modules in the core modules list at the beginning
+# filter them into external modules list step by step
+#
+# Not filtering internal or vdso so start with kernel/
+core_modules_list=$(find kernel -name '*.ko')
+
+filter_mods() {
+ local prefix=$1 mods=$2 suffix=$3
+ local mod filter_list
+
+ for mod in $mods; do
+ if ! filter_list=$(grep "$prefix$mod$suffix" <<< "$core_modules_list"); then
+ error "$prefix$mod$suffix is marked as non-core module but not built, skipping."
+ else
+ core_modules_list=$(grep -v "$prefix$mod$suffix" <<< "$core_modules_list")
+ modules_list+=$filter_list
+ modules_list+=$'\n'
+ fi
+ done
+}
+
+filter_override() {
+ local filter_list
+
+ for mod in $1; do
+ if filter_list=$(grep "$mod.ko" <<< "$modules_list"); then
+ modules_list=$(grep -v "$mod.ko" <<< "$modules_list")
+ core_modules_list+=$filter_list
+ core_modules_list+=$'\n'
+ fi
+ done
+}
+
+filter_mods "drivers/" "$driverdirs" /
+filter_mods "drivers/char/" "$chardrvs" /
+filter_mods "drivers/net/" "$netdrvs" /
+filter_mods "drivers/net/ethernet/" "$ethdrvs" /
+filter_mods "drivers/input/" "$inputdrvs" /
+filter_mods "drivers/hid/" "$hiddrvs" /
+filter_mods "drivers/scsi/" "$scsidrvs" /
+filter_mods "drivers/usb"/ "$usbdrvs" /
+filter_mods "drivers/gpu/drm/" "$drmdrvs" /
+filter_mods "net/" "$netprots" /
+filter_mods "fs/" "$fsdrvs" /
+
+# Just kill sound.
+filter_mods "" "sound" /
+filter_mods "drivers" "soundwire" /
+
+# Filter single modules
+filter_mods "" "$singlemods"
+
+# Now process the override list to bring those modules back into core
+filter_override "$overrides"
+
+# Mask external mods to do a depmod check
+for mod in $modules_list; do
+ mv "$mod" "$mod.bak"
+done
+
+# Run depmod on the resulting module tree and make sure it isn't broken
+depmod_err=$(depmod "$KERNEL_UNAMER" -b "$BASE_DIR" -naeF "$SYSTEM_MAP" 2>&1 1>/dev/null)
+if [ "$depmod_err" ]; then
+ error "Failed to filter out external modules, broken depmod:"
+ error "$depmod_err"
+ exit 1
+fi
+
+# Mask external mods to do a depmod check
+for mod in $modules_list; do
+ mv "$mod.bak" "$mod"
+done
+
+# Print the modules_list after sort, and prepend /lib/modules// to each line
+echo "$modules_list" | sort -n | sed "/^$/d;s/^/\/${MODULE_DIR//\//\\\/}\//"
+
+exit 0
diff --git a/dist/sources/filter-riscv64.sh b/dist/sources/filter-riscv64.sh
new file mode 100755
index 000000000..c98da7f1d
--- /dev/null
+++ b/dist/sources/filter-riscv64.sh
@@ -0,0 +1,14 @@
+#! /bin/bash
+
+# Copied from Fedora
+
+# This is the x86_64 override file for the core/drivers package split. The
+# module directories listed here and in the generic list in filter-modules.sh
+# will be moved to the resulting kernel-modules package for this arch.
+# Anything not listed in those files will be in the kernel-core package.
+#
+# Please review the default list in filter-modules.sh before making
+# modifications to the overrides below. If something should be removed across
+# all arches, remove it in the default instead of per-arch.
+
+# Defaults work so no need to override
diff --git a/dist/sources/filter-x86_64.sh b/dist/sources/filter-x86_64.sh
new file mode 100755
index 000000000..c98da7f1d
--- /dev/null
+++ b/dist/sources/filter-x86_64.sh
@@ -0,0 +1,14 @@
+#! /bin/bash
+
+# Copied from Fedora
+
+# This is the x86_64 override file for the core/drivers package split. The
+# module directories listed here and in the generic list in filter-modules.sh
+# will be moved to the resulting kernel-modules package for this arch.
+# Anything not listed in those files will be in the kernel-core package.
+#
+# Please review the default list in filter-modules.sh before making
+# modifications to the overrides below. If something should be removed across
+# all arches, remove it in the default instead of per-arch.
+
+# Defaults work so no need to override
diff --git a/dist/sources/module-keygen.sh b/dist/sources/module-keygen.sh
new file mode 100755
index 000000000..aee46be94
--- /dev/null
+++ b/dist/sources/module-keygen.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Default keygen
+#
+# We do nothing here, just check if CONFIG_MODULE_SIG_KEY is set to
+# "certs/signing_key.pem", this is a special value for kernel config,
+# Kbuild will automatically generate keys when this value is set.
+
+KERNEL_UNAMER=$1
+BUILD_DIR=$2
+
+KCONFIG_FILE=$BUILD_DIR/.config
+
+error() {
+ echo "module-keygen: error: $*" >&2
+ exit 1
+}
+
+if ! [[ -f $KCONFIG_FILE ]]; then
+ error "can't find a valid kernel config: $KCONFIG_FILE"
+fi
+
+if ! grep -q '^CONFIG_MODULES=y' "$KCONFIG_FILE"; then
+ echo "CONFIG_MODULES not enabled, quit. "
+ exit 0
+fi
+
+if ! grep -q '^CONFIG_MODULE_SIG=y' "$KCONFIG_FILE"; then
+ echo "CONFIG_MODULE_SIG not enabled, quit. "
+ exit 0
+fi
+
+if ! grep -q '^CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"' "$KCONFIG_FILE"; then
+ error "CONFIG_MODULE_SIG_KEY=\"certs/signing_key.pem\" is not defined, can't gen keys."
+fi
+
+# Don't use Kbuild's signing, use %%{_module_signer} instead, be compatible with debuginfo and compression
+echo "module-keygen: Disabling CONFIG_MODULE_SIG_FORCE, siginig within temporary builtin key."
+sed -i -e "s/^CONFIG_MODULE_SIG_FORCE.*/# CONFIG_MODULE_SIG_FORCE is not set/" "$KCONFIG_FILE"
+
+echo "module-keygen: $KERNEL_UNAMER is using builtin keys."
diff --git a/dist/sources/module-signer.sh b/dist/sources/module-signer.sh
new file mode 100755
index 000000000..1a48a394d
--- /dev/null
+++ b/dist/sources/module-signer.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Default key-sign
+#
+# Just a wrapper for sign-file
+#
+# We depend on CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"
+# for the built-in keys.
+
+KERNEL_UNAMER=$1
+BUILD_DIR=$2
+BASE_DIR=$3
+
+KCONFIG_FILE=$BUILD_DIR/.config
+MODULE_DIR=$BASE_DIR/lib/modules/$KERNEL_UNAMER
+
+error() {
+ echo "module-signer: error: $*" >&2
+}
+
+if ! [[ -f $KCONFIG_FILE ]]; then
+ error "can't find a valid kernel config."
+ exit 1
+fi
+
+if ! grep -q '^CONFIG_MODULES=y' "$KCONFIG_FILE"; then
+ echo "CONFIG_MODULES=y is not defined in .config, skipping signing."
+ exit 0
+fi
+
+if ! grep -q '^CONFIG_MODULE_SIG=y' "$KCONFIG_FILE"; then
+ echo "CONFIG_MODULE_SIG=y is not defined in .config, skipping signing."
+ exit 0
+fi
+
+if ! [[ -x $BUILD_DIR/scripts/sign-file ]]; then
+ error "$BUILD_DIR/scripts/sign-file is not an executable file."
+ exit 1
+fi
+
+if ! grep -q '^CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"' "$KCONFIG_FILE"; then
+ error "CONFIG_MODULE_SIG_KEY is not defined in .config, can't gen keys."
+ exit 1
+fi
+
+echo "module-signer: Signing $KERNEL_UNAMER modules with builtin keys..."
+PRIKEY="$BUILD_DIR/certs/signing_key.pem"
+PUBKEY="$BUILD_DIR/certs/signing_key.x509"
+
+if ! [[ -s $PRIKEY ]]; then
+ error "private key file doesn't exist: $PRIKEY"
+ exit 1
+fi
+
+if ! [[ -s $PUBKEY ]]; then
+ error "public key file doesn't exist: $PUBKEY"
+ exit 1
+fi
+
+JOB=$(nproc)
+JOB=${JOB:-2}
+
+export BUILD_DIR
+export PRIKEY
+export PUBKEY
+# shellcheck disable=2016
+find "$MODULE_DIR" -type f -name '*.ko' -print0 | xargs -0r -n 1 -P "$JOB" sh -c '
+ $BUILD_DIR/scripts/sign-file sha256 "$PRIKEY" "$PUBKEY" "$1"
+ rm -f $1.sig $1.dig
+
+ if [ "~Module signature appended~" != "$(tail -c 28 "$1")" ]; then
+ echo "module-signer: error: failed to sign $1."
+ exit 1
+ fi
+' _ || exit $?
+
+echo "module-signer: Signing $KERNEL_UNAMER done."
diff --git a/dist/sources/tlinux_cciss_link_compat.modules b/dist/sources/tlinux_cciss_link_compat.modules
new file mode 100644
index 000000000..442be6a0c
--- /dev/null
+++ b/dist/sources/tlinux_cciss_link_compat.modules
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+if [ -b /dev/sda -a ! -b /dev/cciss/c0d0 ]; then
+ mkdir -p /dev/cciss
+ set -- 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j 10 k 11 l 12 m 13 n 14 o 15 p
+ while [ $# -ge 2 ]; do
+ c=/dev/cciss/c0d$1; shift
+ s=/dev/sd$1; shift
+ ln -s ${s} ${c}
+ ln -s ${s}1 ${c}p1
+ ln -s ${s}2 ${c}p2
+ ln -s ${s}3 ${c}p3
+ ln -s ${s}4 ${c}p4
+ done
+fi
+
diff --git a/dist/templates/changelog b/dist/templates/changelog
new file mode 100644
index 000000000..a0fe7a542
--- /dev/null
+++ b/dist/templates/changelog
@@ -0,0 +1,2 @@
+* Wed Oct 05 2022 Kairui Song - 5.4.119-19-0009.11
+- Initial dist port release
diff --git a/dist/templates/kernel.template.spec b/dist/templates/kernel.template.spec
new file mode 100644
index 000000000..6fd98af38
--- /dev/null
+++ b/dist/templates/kernel.template.spec
@@ -0,0 +1,1360 @@
+# A simplified kernel spec initially based on Tencent Linux Kernels and Fedora/CentOS
+#
+# By changing a few rpm macros, it's very convenient to build for different archs or
+# kernel config styles, and build different components.
+
+# Following variables filled by automation scripts:
+# %%{kernel_majver}: example. 5.15.0, 5.15.3, 5.16.0
+# %%{kernel_relver}: example. 2207.1, 0.20211115git1135ec008ef3.rc0.2207, rc1
+# %%{kernel_variant}: example. %%{nil}; debug
+# %%{rpm_name}: RPM package name
+# %%{rpm_version}: RPM package version
+# %%{rpm_release}: RPM package release
+# %%{rpm_vendor}: RPM package vendor
+# %%{rpm_url}: RPM url
+{{VERSIONSPEC}}
+
+# This section defines following value:
+# %%{kernel_arch}
+# Since kernel arch name differs from many other definations, this will insert a script snip
+# to handle the convertion, and error out on unsupported arch.
+{{ARCHSPEC}}
+
+# TODO: This is a workaround for kernel userspace tools (eg. perf), which doesn't
+# support LTO, and causes FTBFS, need to remove this after LTO is available in
+# upstream
+%global _lto_cflags %{nil}
+
+###### Kernel packaging options #################################################
+# Since we need to generate kernel, kernel-subpackages, perf, bpftools, from
+# this one single code tree, following build switches are very helpful.
+#
+# The following build options can be enabled or disabled with --with/--without
+# in the rpmbuild command. But may by disabled by later checks#
+#
+# This section defines following options:
+# with_core: kernel core pkg
+# with_doc: kernel doc pkg
+# with_headers: kernel headers pkg
+# with_perf: perf tools pkg
+# with_tools: kernel tools pkg
+# with_bpftool: bpftool pkg
+# with_debuginfo: debuginfo for all packages
+# with_modsign: if mod should be signed
+# with_kabichk: if kabi check is needed at the end of build
+{{PKGPARAMSPEC}}
+
+# Only use with cross build, don't touch it unless you know what you are doing
+%define with_crossbuild %{?_with_crossbuild: 1} %{?!_with_crossbuild: 0}
+
+###### Kernel signing params #################################################
+### TODO: Currently only module signing, no secureboot
+# module-keygen
+# Should be an executable accepting two params:
+# module-keygen
+# : Kernel's version-release, `uname -r` output of that kernel
+# : Kernel build dir, where built kernel objs, certs, and vmlinux is stored
+#
+# This executable should provide required keys for signing, or at least disable builtin keygen
+%define use_builtin_module_keygen %{?_module_keygen: 0} %{?!_module_keygen: 1}
+
+# module-signer
+# Should be an executable accepting three params:
+# module-signer
+# : Kernel's version-release, `uname -r` output of that kernel
+# : Kernel build dir, where built kernel objs, certs, and vmlinux is stored
+# : RPM's buildroot, where kernel modules are installed into
+#
+# This executable should sign all kernel modules in /lib/modules/
+# based on the info gatherable from .
+%define use_builtin_module_signer %{?_module_signer: 0} %{?!_module_signer: 1}
+
+###### Required RPM macros #####################################################
+### Kenrel version relation macros
+# We only have one kernel core per spec file
+# Following three macros is generated by scripts, see VERSIONSPEC above.
+# %%{kernel_majver}
+# %%{kernel_relver}
+# %%{kernel_variant}
+%define kernel_tarname kernel-%{kernel_majver}-%{kernel_relver}
+# Used for simulate `uname -r` output
+%define kernel_unamer %{kernel_majver}-%{kernel_relver}%{?kernel_variant:+%{kernel_variant}}
+# Regex to match kernel_unamer
+%define kernel_unamer_regex %{kernel_majver}-%{kernel_relver}%{?kernel_variant:[+]%{kernel_variant}}
+# kernel_unamer with distro mark
+%define kernel_unamer_dist %{kernel_unamer}%{?dist}
+
+### Debuginfo handling
+# Following macros controls RPM's builtin debuginfo extracting behaviour,
+# tune it into a kernel friendly style.
+#
+# Kernel package needs its own method to pack the debuginfo files.
+# This disables RPM's built-in debuginfo files packaging, we package
+# debuginfo files manually use find-debuginfo.sh.
+%undefine _debuginfo_subpackages
+# This disables RH vendor macro's debuginfo package template generation.
+# It only generates debuginfo for the main package, but we only want debuginfo
+# for subpackages so disable it and do things manually.
+%undefine _enable_debug_packages
+# This disable find-debuginfo.sh from appending minimal debuginfo
+# to every binary.
+%undefine _include_minidebuginfo
+# This disables debugsource package which collect source files for debug info,
+# we pack the kernel source code manually.
+%undefine _debugsource_packages
+# TODO: This prevents find-debuginfo.sh from adding unique suffix to .ko.debug files
+# that will make .ko.debug file names unrecognizable by `crash`
+# We may patch `crash` to fix that or find a better way, since this stops the unique
+# debug file renaming for userspace packages too.
+%undefine _unique_debug_names
+# Pass --reloc-debug-sections to eu-strip, .ko files are ET_REL files. So they have relocation
+# sections for debug sections. Those sections will not be relinked. This help create .debug files
+# that has cross debug section relocations resolved.
+%global _find_debuginfo_opts -r
+%global debuginfo_dir /usr/lib/debug
+
+###### Build time config #######################################################
+# Disable kernel building for non-supported arch, allow building userspace package
+%ifarch %nobuildarches noarch
+%global with_core 0
+%endif
+
+# Require cross compiler if cross compiling
+%if %{with_crossbuild}
+BuildRequires: binutils-%{_build_arch}-linux-gnu, gcc-%{_build_arch}-linux-gnu
+%global with_perf 0
+%global with_tools 0
+%global with_bpftool 0
+%global _cross_compile %{!?_cross_compile:%{_build_arch}-linux-gnu-}%{?_cross_compile:%{_cross_compile}}
+%endif
+
+# List the packages used during the kernel build
+BuildRequires: kmod, patch, bash, coreutils, tar, git-core, which, gawk
+BuildRequires: make, gcc, binutils, redhat-rpm-config, hmaccalc, bison, flex, gcc-c++
+BuildRequires: bzip2, xz, findutils, gzip, perl-interpreter, perl-Carp, perl-devel
+BuildRequires: net-tools, hostname, bc
+BuildRequires: dwarves
+BuildRequires: python3-devel, openssl-devel, elfutils-devel
+BuildRequires: openssl
+BuildRequires: gcc-plugin-devel
+# glibc-static is required for a consistent build environment (specifically
+# CONFIG_CC_CAN_LINK_STATIC=y).
+BuildRequires: glibc-static
+
+%if %{with_perf}
+BuildRequires: zlib-devel binutils-devel newt-devel perl(ExtUtils::Embed) bison flex xz-devel
+BuildRequires: audit-libs-devel
+BuildRequires: java-devel
+BuildRequires: libbabeltrace-devel
+%ifnarch aarch64
+BuildRequires: numactl-devel
+%endif
+%endif
+
+%if %{with_tools}
+BuildRequires: gettext ncurses-devel
+BuildRequires: pciutils-devel libcap-devel libnl3-devel
+%endif
+
+%if %{with_doc}
+BuildRequires: xmlto, asciidoc
+%endif
+
+%if %{with_bpftool}
+BuildRequires: llvm
+# We don't care about this utils's python version, since we only want rst2* commands during build time
+BuildRequires: /usr/bin/rst2man
+BuildRequires: zlib-devel binutils-devel
+%endif
+
+%if %{with_headers}
+BuildRequires: rsync
+%endif
+
+###### Kernel packages sources #################################################
+### Kernel tarball
+Source0: %{kernel_tarname}.tar
+
+### Build time scripts
+# Script used to assist kernel building
+Source10: filter-modules.sh
+
+Source20: module-signer.sh
+Source21: module-keygen.sh
+
+Source30: check-kabi
+
+### Arch speficied kernel configs and kABI
+# Start from Source1000 to Source1199, for kernel config
+# Start from Source1200 to Source1399, for kabi
+# Start from Source1400 to Source1599, for filter-.sh
+{{ARCHSOURCESPEC}}
+
+### Userspace tools
+# Start from Source2000 to Source2999, for userspace tools
+Source2000: cpupower.service
+Source2001: cpupower.config
+Source2002: tlinux_cciss_link_compat.modules
+
+### TK4 MLNX OFED
+Source3000: MLNX_OFED_SRC-5.1-2.5.8.0.46.tgz
+
+###### Kernel package definations ##############################################
+### Main meta package
+Summary: %{rpm_vendor} Linux kernel meta package
+Name: %{rpm_name}
+Version: %{rpm_version}
+Release: %{rpm_release}%{?dist}
+License: GPLv2
+URL: %{rpm_url}
+Vendor: ${rpm_vendor}
+
+# We can't let RPM do the dependencies automatic because it'll then pick up
+# a correct but undesirable perl dependency from the module headers which
+# isn't required for the kernel proper to function
+AutoReq: no
+AutoProv: yes
+
+# Kernel requirements
+Provides: kernel = %{version}-%{release}
+Provides: %{rpm_name} = %{version}-%{release}
+Requires: %{rpm_name}-core = %{version}-%{release}
+Requires: %{rpm_name}-modules = %{version}-%{release}
+Requires: linux-firmware
+
+%description
+This is the meta package of %{?rpm_vendor:%{rpm_vendor} }Linux kernel, the core of operating system.
+
+%if %{with_core}
+### Kernel core package
+# installonlypkg(kernel) is a hint for RPM that this package shouldn't be auto-cleaned.
+%package core
+Summary: %{rpm_vendor} Linux Kernel
+Provides: installonlypkg(kernel)
+Provides: kernel-core = %{version}-%{release}
+Requires(pre): coreutils
+Requires(post): coreutils kmod dracut
+Requires(preun): coreutils kmod
+Requires(post): %{_bindir}/kernel-install
+Requires(preun): %{_bindir}/kernel-install
+# Kernel install hooks & initramfs
+%if 0%{?rhel} == 7
+Requires(post): systemd
+Requires(preun): systemd
+%else
+Requires(post): systemd-udev
+Requires(preun): systemd-udev
+%endif
+
+%description core
+The kernel package contains the %{?rpm_vendor:%{rpm_vendor} } Linux kernel (vmlinuz), the core of
+operating system. The kernel handles the basic functions
+of the operating system: memory allocation, process allocation, device
+input and output, etc.
+
+### Kernel module package
+%package modules
+Summary: %{rpm_vendor} Kernel modules to match the %{rpm_name}-core kernel
+Provides: installonlypkg(kernel-module)
+Provides: kernel-modules = %{version}-%{release}
+Provides: kernel-modules-extra = %{version}-%{release}
+Requires: %{rpm_name}-core = %{version}-%{release}
+AutoReq: no
+AutoProv: yes
+Requires(pre): kmod
+Requires(postun): kmod
+%description modules
+This package provides commonly used kernel modules for the %{?2:%{2}-}core kernel package.
+
+### Kernel devel package
+%package devel
+Summary: Development package for building kernel modules to match the %{version}-%{release} kernel
+Release: %{release}
+Provides: installonlypkg(kernel-devel)
+Provides: kernel-devel = %{version}-%{release}
+Provides: kernel-devel-%{_target_cpu} = %{version}-%{release}
+Provides: kernel-devel-uname-r = %{version}-%{release}
+AutoReqprov: no
+%description devel
+This package provides kernel headers and makefiles sufficient to build modules
+against the %{version}-%{release} kernel package.
+
+%if %{with_debuginfo}
+### Kernel debuginfo package
+%package debuginfo
+Summary: Debug information for package %{rpm_name}
+Requires: %{rpm_name}-debuginfo-common-%{_target_cpu}
+Provides: installonlypkg(kernel-debuginfo)
+Provides: kernel-debuginfo = %{version}-%{release}
+AutoReqProv: no
+%description debuginfo
+This package provides debug information including
+vmlinux, System.map for package %{rpm_name}.
+This is required to use SystemTap with %{rpm_name}.
+# debuginfo search rule
+# If BTF presents, keep it so kernel can use it.
+%if 0%{?rhel} != 7
+# Old version of find-debuginfo.sh doesn't support this, so only do it for newer version. Old version of eu-strip seems doesn't strip BTF either, so should be fine.
+%global _find_debuginfo_opts %{_find_debuginfo_opts} --keep-section '.BTF'
+%endif
+# Debuginfo file list for main kernel package
+%global _find_debuginfo_opts %{_find_debuginfo_opts} -p '.*\/usr\/src\/kernels/.*|XXX' -o ignored-debuginfo.list -p '/.*/%{kernel_unamer_regex}/.*|/.*%{kernel_unamer_regex}(\.debug)?' -o debuginfo.list
+# with_debuginfo
+%endif
+# with_core
+%endif
+
+%if %{with_debuginfo}
+### Common debuginfo package
+%package debuginfo-common-%{_target_cpu}
+Summary: Kernel source files used by %{rpm_name}-debuginfo packages
+Provides: installonlypkg(kernel-debuginfo-common)
+Provides: kernel-debuginfo-common = %{version}-%{release}
+%description debuginfo-common-%{_target_cpu}
+This package is required by %{rpm_name}-debuginfo subpackages.
+It provides the kernel source files common to all builds.
+# No need to define extra debuginfo search rule here, use debugfiles.list
+# with_debuginfo
+%endif
+
+%if %{with_headers}
+%package headers
+Summary: Header files for the Linux kernel for use by glibc
+Obsoletes: glibc-kernheaders < 3.0-46
+Provides: glibc-kernheaders = 3.0-46
+Provides: kernel-headers = %{version}-%{release}
+%description headers
+Kernel-headers includes the C header files that specify the interface
+between the Linux kernel and userspace libraries and programs. The
+header files define structures and constants that are needed for
+building most standard programs and are also needed for rebuilding the
+glibc package.
+# with_headers
+%endif
+
+%if %{with_perf}
+%package -n perf
+Summary: Performance monitoring for the Linux kernel
+Requires: bzip2
+License: GPLv2
+%description -n perf
+This package contains the perf tool, which enables performance monitoring
+of the Linux kernel.
+
+%package -n perf-debuginfo
+Summary: Debug information for package perf
+Requires: %{rpm_name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
+AutoReqProv: no
+%description -n perf-debuginfo
+This package provides debug information for the perf package.
+# debuginfo search rule
+# Note that this pattern only works right to match the .build-id
+# symlinks because of the trailing nonmatching alternation and
+# the leading .*, because of find-debuginfo.sh's buggy handling
+# of matching the pattern against the symlinks file.
+%global _find_debuginfo_opts %{_find_debuginfo_opts} -p '.*%{_bindir}/perf(.*\.debug)?|.*%{_libexecdir}/perf-core/.*|.*%{_libdir}/libperf-jvmti.so(.*\.debug)?|XXX' -o perf-debuginfo.list
+
+%package -n python3-perf
+Summary: Python bindings for apps which will manipulate perf events
+%description -n python3-perf
+The python3-perf package contains a module that permits applications
+written in the Python programming language to use the interface
+to manipulate perf events.
+
+%package -n python3-perf-debuginfo
+Summary: Debug information for package perf python bindings
+Requires: %{rpm_name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
+AutoReqProv: no
+%description -n python3-perf-debuginfo
+This package provides debug information for the perf python bindings.
+# debuginfo search rule
+# the python_sitearch macro should already be defined from above
+%global _find_debuginfo_opts %{_find_debuginfo_opts} -p '.*%{python3_sitearch}/perf.*\.so(.*\.debug)?|XXX' -o python3-perf-debuginfo.list
+# with_perf
+%endif
+
+%if %{with_tools}
+%package -n kernel-tools
+Summary: Assortment of tools for the Linux kernel
+License: GPLv2
+%ifarch %{cpupowerarchs}
+Provides: cpupowerutils = 1:009-0.6.p1
+Obsoletes: cpupowerutils < 1:009-0.6.p1
+Provides: cpufreq-utils = 1:009-0.6.p1
+Provides: cpufrequtils = 1:009-0.6.p1
+Obsoletes: cpufreq-utils < 1:009-0.6.p1
+Obsoletes: cpufrequtils < 1:009-0.6.p1
+Obsoletes: cpuspeed < 1:1.5-16
+Requires: kernel-tools-libs = %{version}-%{release}
+%endif
+%description -n kernel-tools
+This package contains the tools/ directory from the kernel source
+and the supporting documentation.
+
+%package -n kernel-tools-libs
+Summary: Libraries for the kernels-tools
+License: GPLv2
+%description -n kernel-tools-libs
+This package contains the libraries built from the tools/ directory
+from the kernel source.
+
+%package -n kernel-tools-libs-devel
+Summary: Assortment of tools for the Linux kernel
+License: GPLv2
+Requires: kernel-tools = %{version}-%{release}
+%ifarch %{cpupowerarchs}
+Provides: cpupowerutils-devel = 1:009-0.6.p1
+Obsoletes: cpupowerutils-devel < 1:009-0.6.p1
+%endif
+Requires: kernel-tools-libs = %{version}-%{release}
+Provides: kernel-tools-devel
+%description -n kernel-tools-libs-devel
+This package contains the development files for the tools/ directory from
+the kernel source.
+
+%package -n kernel-tools-debuginfo
+Summary: Debug information for package kernel-tools
+Requires: %{rpm_name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
+AutoReqProv: no
+%description -n kernel-tools-debuginfo
+This package provides debug information for package kernel-tools.
+# debuginfo search rule
+# Note that this pattern only works right to match the .build-id
+# symlinks because of the trailing nonmatching alternation and
+# the leading .*, because of find-debuginfo.sh's buggy handling
+# of matching the pattern against the symlinks file.
+%global _find_debuginfo_opts %{_find_debuginfo_opts} -p '.*%{_bindir}/(cpupower|tmon|gpio-.*|iio_.*|ls.*|centrino-decode|powernow-k8-decode|turbostat|x86_energy_perf_policy|intel-speed-select|page_owner_sort|slabinfo)(.*\.debug)?|.*%{_libdir}/libcpupower.*|XXX' -o kernel-tools-debuginfo.list
+# with_tools
+%endif
+
+%if %{with_bpftool}
+%package -n bpftool
+Summary: Inspection and simple manipulation of eBPF programs and maps
+License: GPLv2
+%description -n bpftool
+This package contains the bpftool, which allows inspection and simple
+manipulation of eBPF programs and maps.
+
+%package -n bpftool-debuginfo
+Summary: Debug information for package bpftool
+Requires: %{rpm_name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
+AutoReqProv: no
+%description -n bpftool-debuginfo
+This package provides debug information for the bpftool package.
+# debuginfo search rule
+%global _find_debuginfo_opts %{_find_debuginfo_opts} -p '.*%{_sbindir}/bpftool(.*\.debug)?|XXX' -o bpftool-debuginfo.list
+# with_bpftool
+%endif
+
+###### common macros for build and install #####################################
+### Signing scripts
+# If externel module signer and keygen provided, ignore built-in keygen and
+# signer, else use builtin keygen and signer.
+%if %{use_builtin_module_signer}
+ # SOURCE20 is just a wrapper for $BUILD_DIR/scripts/sign-file
+ %define _module_signer %{SOURCE20}
+%endif
+%if %{use_builtin_module_keygen}
+ # SOURCE21 is a dummy file, only perform some checks, we depend on Kbuild for builtin keygen
+ %define _module_keygen %{SOURCE21}
+%endif
+
+### Prepare common build vars to share by %%prep, %%build and %%install section
+# _KernSrc: Path to kernel source, located in _buildir
+# _KernBuild: Path to the built kernel objects, located in _buildir
+# _KernVmlinuxH: path to vmlinux.h for BTF, located in _buildir
+# KernUnameR: Get `uname -r` output of the built kernel
+# KernExtVer: Kernel EXTRAVERSION plus debug/kasan/syzkaller marker
+# KernModule: Kernel modules install path, located in %%{buildroot}
+# KernDevel: Kernel headers and sources install path, located in %%{buildroot}
+%global prepare_buildvar \
+ cd %{kernel_tarname} \
+ _KernSrc=%{_builddir}/%{rpm_name}-%{kernel_unamer}/%{kernel_tarname} \
+ _KernBuild=%{_builddir}/%{rpm_name}-%{kernel_unamer}/%{kernel_unamer}-obj \
+ _KernVmlinuxH=%{_builddir}/%{rpm_name}-%{kernel_unamer}/vmlinux.h \
+ KernUnameR=%{kernel_unamer} \
+ KernExtVer=%{kernel_relver}%{?kernel_variant:+%{kernel_variant:}} \
+ KernModule=%{buildroot}/lib/modules/%{kernel_unamer} \
+ KernDevel=%{buildroot}/usr/src/kernels/%{kernel_unamer} \
+
+###### Rpmbuild Prep Stage #####################################################
+%prep
+%setup -q -c -n %{rpm_name}-%{kernel_unamer}
+%{prepare_buildvar}
+
+# TODO: Apply test patch here
+:
+
+# This Prevents scripts/setlocalversion from mucking with our version numbers.
+touch .scmversion
+
+# Mangle /usr/bin/python shebangs to /usr/bin/python3
+# Mangle all Python shebangs to be Python 3 explicitly
+# -p preserves timestamps
+# -n prevents creating ~backup files
+# -i specifies the interpreter for the shebang
+# This fixes errors such as
+# *** ERROR: ambiguous python shebang in /usr/bin/kvm_stat: #!/usr/bin/python. Change it to python3 (or python2) explicitly.
+# We patch all sources below for which we got a report/error.
+find scripts/ tools/ Documentation/ \
+ -type f -and \( \
+ -name "*.py" -or \( -not -name "*.*" -exec grep -Iq '^#!.*python' {} \; \) \
+ \) \
+ -exec pathfix.py -i "%{__python3} %{py3_shbang_opts}" -p -n {} \+;
+
+# Update kernel version and suffix info to make uname consistent with RPM version
+sed -i "/^EXTRAVERSION/cEXTRAVERSION = -$KernExtVer" $_KernSrc/Makefile
+# PATCHLEVEL inconsistent only happen on first merge window, but patch them all just in case
+sed -i "/^VESION/cVERSION = $(echo %{kernel_majver} | cut -d '.' -f 1)" $_KernSrc/Makefile
+sed -i "/^PATCHLEVEL/cPATCHLEVEL = $(echo %{kernel_majver} | cut -d '.' -f 2)" $_KernSrc/Makefile
+sed -i "/^SUBLEVEL/cSUBLEVEL = $(echo %{kernel_majver} | cut -d '.' -f 3)" $_KernSrc/Makefile
+
+###### Rpmbuild Build Stage ####################################################
+%build
+
+### Make flags
+#
+# Those defination have to be defined after %%build macro, %%build macro may change
+# some build flags, and we have to inherit these changes.
+#
+# NOTE: kernel's tools build system doesn't playwell with command line variables, some
+# `override` statement will stop working after recursive Makefile `include` call.
+# So keep these variables as environment variables so they are available globally,
+# `make` will transformed env vars into makefile variable in every iteration.
+
+## Common flags
+%global make %{__make} %{_smp_mflags}
+%global kernel_make_opts INSTALL_HDR_PATH=%{buildroot}/usr INSTALL_MOD_PATH=%{buildroot} KERNELRELEASE=$KernUnameR
+%global tools_make_opts DESTDIR="%{buildroot}" prefix=%{_prefix} lib=%{_lib} PYTHON=%{__python3} INSTALL_ROOT="%{buildroot}"
+
+## Cross compile flags
+%if %{with_crossbuild}
+%global kernel_make_opts %{kernel_make_opts} CROSS_COMPILE=%{_cross_compile} ARCH=%{kernel_arch}
+%global __strip %{_build_arch}-linux-gnu-strip
+%endif
+
+# Drop host cflags for crossbuild, arch options from build target will break host compiler
+%if !%{with_crossbuild}
+%global kernel_make_opts %{kernel_make_opts} HOSTCFLAGS="%{?build_cflags}" HOSTLDFLAGS="%{?build_ldflags}"
+%endif
+
+## make for host tool, reset arch and flags for native host bulid
+%global host_make CFLAGS= LDFLAGS= ARCH= %{make}
+
+## make for kernel
+%global kernel_make %{make} %{kernel_make_opts}
+
+## make for tools
+%global tools_make CFLAGS="${RPM_OPT_FLAGS}" LDFLAGS="%{__global_ldflags}" %{make} %{tools_make_opts}
+%global perf_make EXTRA_CFLAGS="${RPM_OPT_FLAGS}" LDFLAGS="%{__global_ldflags}" WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_STRLCPY=1 NO_BIONIC=1 %{make} %{tools_make_opts}
+%global bpftool_make EXTRA_CFLAGS="${RPM_OPT_FLAGS}" EXTRA_LDFLAGS="%{__global_ldflags}" VMLINUX_H="$_KernVmlinuxH" %{make} %{tools_make_opts}
+
+# TK4: Workaround, Makefile fails with mass parallel build
+%global tools_make %{tools_make} -j1
+
+### Real make
+%{prepare_buildvar}
+
+# Prepare Kernel config
+BuildConfig() {
+ mkdir -p $_KernBuild
+ pushd $_KernBuild
+
+ cp $1 .config
+ echo "include $_KernSrc/Makefile" > Makefile
+
+ # Ensures build-ids are unique to allow parallel debuginfo
+ sed -i -e "s/^CONFIG_BUILD_SALT.*/CONFIG_BUILD_SALT=\"$KernUnameR\"/" .config
+
+ # Call olddefconfig before make all, set all unset config to default value.
+ # The packager uses CROSS_COMPILE=scripts/dummy-tools for generating .config
+ # so compiler related config are always unset, let's just use defconfig for them for now
+ %{kernel_make} olddefconfig
+
+ %if %{with_modsign}
+ # Don't use Kbuild's signing, use %%{_module_signer} instead, be compatible with debuginfo and compression
+ sed -i -e "s/^CONFIG_MODULE_SIG_ALL.*/# CONFIG_MODULE_SIG_ALL is not set/" .config
+ %else
+ # Not signing, unset all signing related configs
+ sed -i -e "s/^CONFIG_MODULE_SIG_ALL=.*/# CONFIG_MODULE_SIG_ALL is not set/" .config
+ sed -i -e "s/^CONFIG_MODULE_SIG_FORCE=.*/# CONFIG_MODULE_SIG_FORCE is not set/" .config
+ sed -i -e "s/^CONFIG_MODULE_SIG=.*/# CONFIG_MODULE_SIG is not set/" .config
+ # Lockdown can't work without module sign
+ sed -i -e "s/^CONFIG_SECURITY_LOCKDOWN_LSM=.*/# CONFIG_SECURITY_LOCKDOWN_LSM is not set/" .config
+ sed -i -e "s/^CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=.*/# CONFIG_SECURITY_LOCKDOWN_LSM_EARLY is not set/" .config
+ %endif
+ # Don't use kernel's builtin module compression, imcompatible with debuginfo packaging and signing
+ sed -i -e "s/^\(CONFIG_DECOMPRESS_.*\)=y/# \1 is not set/" .config
+ popd
+}
+
+## $1: .config file
+BuildKernel() {
+ echo "*** Start building kernel $KernUnameR"
+ mkdir -p $_KernBuild
+ pushd $_KernBuild
+
+ %if %{with_modsign}
+ # Call keygen here, if it generate the module keys, it should come before kbuild,
+ # so kbuild may avoid regenerate cert keys.
+ %{_module_keygen} "$KernUnameR" "$_KernBuild"
+ %endif
+
+ # Build vmlinux
+ %{kernel_make} all
+ # Build modules
+ grep -q "CONFIG_MODULES=y" ".config" && %{kernel_make} modules
+ # CONFIG_KERNEL_HEADER_TEST generates some extra files in the process of
+ # testing so just delete
+ find . -name *.h.s -delete
+
+ %if %{with_bpftool}
+ echo "*** Building bootstrap bpftool and extrace vmlinux.h"
+ if ! [ -s $_KernVmlinuxH ]; then
+ # Precompile a minimized bpftool without vmlinux.h, use it to extract vmlinux.h
+ # for bootstraping the full feature bpftool
+ %{host_make} -C $_KernSrc/tools/bpf/bpftool/ VMLINUX_BTF= VMLINUX_H=
+ # Prefer to extract the vmlinux.h from the vmlinux that were just compiled
+ # fallback to use host's vmlinux
+ if grep -q "CONFIG_DEBUG_INFO_BTF=y" ".config"; then
+ $_KernSrc/tools/bpf/bpftool/bpftool btf dump file vmlinux format c > $_KernVmlinuxH
+ else
+ $_KernSrc/tools/bpf/bpftool/bpftool btf dump file /sys/kernel/btf/vmlinux format c > $_KernVmlinuxH
+ fi
+ %{host_make} -C $_KernSrc/tools/bpf/bpftool/ clean
+ fi
+ %endif
+
+ popd
+}
+
+BuildPerf() {
+ %{perf_make} -C tools/perf all
+ %{perf_make} -C tools/perf man
+}
+
+BuildTools() {
+ %{tools_make} -C tools/power/cpupower CPUFREQ_BENCH=false DEBUG=false
+
+%ifarch x86_64
+ %{tools_make} -C tools/power/cpupower/debug/x86_64 centrino-decode powernow-k8-decode
+ %{tools_make} -C tools/power/x86/x86_energy_perf_policy
+ %{tools_make} -C tools/power/x86/turbostat
+ %{tools_make} -C tools/power/x86/intel-speed-select
+%endif
+
+ %{tools_make} -C tools/thermal/tmon/
+ %{tools_make} -C tools/iio/
+ %{tools_make} -C tools/gpio/
+ %{tools_make} -C tools/vm/ slabinfo page_owner_sort
+}
+
+BuildBpfTool() {
+ %{bpftool_make} -C tools/bpf/bpftool
+}
+
+%if %{with_core}
+{{CONFBUILDSPEC}} # `BuildConfig <.config from CONFSOURCESPEC>`
+BuildKernel
+%endif
+
+%if %{with_perf}
+BuildPerf
+%endif
+
+%if %{with_tools}
+BuildTools
+%endif
+
+%if %{with_bpftool}
+BuildBpfTool
+%endif
+
+###### Rpmbuild Install Stage ##################################################
+%install
+%{prepare_buildvar}
+
+InstKernelBasic() {
+ ####### Basic environment ##################
+ # prepare and pushd into the kernel module top dir
+ mkdir -p $KernModule
+ pushd $KernModule
+
+ ####### modules_install ##################
+ pushd $_KernBuild
+ # Override $(mod-fw) because we don't want it to install any firmware
+ # we'll get it from the linux-firmware package and we don't want conflicts
+ grep -q "CONFIG_MODULES=y" ".config" && %{kernel_make} mod-fw= modules_install
+ # Check again, don't package firmware, use linux-firmware rpm instead
+ rm -rf %{buildroot}/lib/firmware
+ popd
+
+ ####### Prepare kernel modules files for packaging ################
+ # Don't package depmod files, they should be auto generated by depmod at rpm -i
+ rm -f modules.{alias,alias.bin,builtin.alias.bin,builtin.bin} \
+ modules.{dep,dep.bin,devname,softdep,symbols,symbols.bin}
+
+ # Process kernel modules
+ find . -name "*.ko" -type f | \
+ while read -r _kmodule; do
+ # Mark it executable so strip and find-debuginfo can see it
+ chmod u+x "$_kmodule"
+
+ # Detect missing or incorrect license tags
+ modinfo "$_kmodule" -l | grep -E -qv \
+ 'GPL( v2)?$|Dual BSD/GPL$|Dual MPL/GPL$|GPL and additional rights$' && \
+ echo "Module $_kmodule has incorrect license." >&2 && exit 1
+
+ # Collect module symbol reference info for later usage
+ case "$kmodule" in */drivers/*) nm -upA "$_kmodule" ;;
+ esac | sed -n 's,^.*/\([^/]*\.ko\): *U \(.*\)$,\1 \2,p' >> drivers.undef
+ done || exit $?
+
+ # Generate a list of modules for block and networking.
+ collect_modules_list() {
+ sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef |
+ LC_ALL=C sort -u > $KernModule/modules.$1
+ if [ ! -z "$3" ]; then
+ sed -r -e "/^($3)\$/d" -i $KernModule/modules.$1
+ fi
+ }
+
+ collect_modules_list networking \
+ 'register_netdev|ieee80211_register_hw|usbnet_probe|phy_driver_register|rt(l_|2x00)(pci|usb)_probe|register_netdevice'
+ collect_modules_list block \
+ 'ata_scsi_ioctl|scsi_add_host|scsi_add_host_with_dma|blk_alloc_queue|blk_init_queue|register_mtd_blktrans|scsi_esp_register|scsi_register_device_handler|blk_queue_physical_block_size' \
+ 'pktcdvd.ko|dm-mod.ko'
+ collect_modules_list drm \
+ 'drm_open|drm_init'
+ collect_modules_list modesetting \
+ 'drm_crtc_init'
+ # Finish preparing the kernel module files
+
+ ###### Install kernel core components #############################
+ mkdir -p %{buildroot}/boot
+ install -m 644 $_KernBuild/.config config
+ install -m 644 $_KernBuild/.config %{buildroot}/boot/config-$KernUnameR
+ install -m 644 $_KernBuild/System.map System.map
+ install -m 644 $_KernBuild/System.map %{buildroot}/boot/System.map-$KernUnameR
+
+ # NOTE: If we need to sign the vmlinuz, this is the place to do it.
+ %ifarch aarch64
+ install -m 644 $_KernBuild/arch/arm64/boot/Image vmlinuz
+ %endif
+
+ %ifarch riscv64
+ mkdir dtb
+ cp $_KernBuild/arch/riscv/boot/dts/*/*.dtb dtb/
+ install -m 644 $_KernBuild/arch/riscv/boot/Image vmlinuz
+ %endif
+
+ %ifarch x86_64
+ install -m 644 $_KernBuild/arch/x86/boot/bzImage vmlinuz
+ %endif
+
+ install -m 644 vmlinuz %{buildroot}/boot/vmlinuz-$KernUnameR
+
+ sha512hmac %{buildroot}/boot/vmlinuz-$KernUnameR | sed -e "s,%{buildroot},," > .vmlinuz.hmac
+ cp .vmlinuz.hmac %{buildroot}/boot/.vmlinuz-$KernUnameR.hmac
+
+ ###### kABI checking and packaging #############################
+ # Always create the kABI metadata for use in packaging
+ echo "**** GENERATING kernel ABI metadata ****"
+ gzip -c9 < $_KernBuild/Module.symvers > symvers.gz
+ cp symvers.gz %{buildroot}/boot/symvers-$KernUnameR.gz
+
+ ###### End of installing kernel modules and core
+ popd
+}
+
+CheckKernelABI() {
+ echo "**** kABI checking is enabled. ****"
+ if ! [ -s "$1" ]; then
+ echo "**** But cannot find reference Module.kabi file. ****"
+ else
+ cp $1 %{buildroot}/Module.kabi
+ %{SOURCE30} -k %{buildroot}/Module.kabi -s $_KernBuild/Module.symvers || exit 1
+ rm %{buildroot}/Module.kabi
+ fi
+}
+
+InstKernelDevel() {
+ ###### Install kernel-devel package ###############################
+ ### TODO: need tidy up
+ ### Save the headers/makefiles etc for building modules against.
+ # This all looks scary, but the end result is supposed to be:
+ # * all arch relevant include/ files
+ # * all Makefile/Kconfig files
+ # * all script/ files
+
+ # `modules_install` will symlink build to $_KernBuild, and source to $_KernSrc, remove the symlinks first
+ rm -rf $KernModule/{build,source}
+ mkdir -p $KernModule/{extra,updates,weak-updates}
+
+ # Symlink $KernDevel to kernel module build path
+ ln -sf /usr/src/kernels/$KernUnameR $KernModule/build
+ ln -sf /usr/src/kernels/$KernUnameR $KernModule/source
+
+ # Start installing kernel devel files
+ mkdir -p $KernDevel
+ pushd $KernDevel
+
+ # First copy everything
+ (cd $_KernSrc; cp --parents $(find . -type f -name "Makefile*" -o -name "Kconfig*") $KernDevel/)
+ # Copy built config and sym files
+ cp $_KernBuild/Module.symvers .
+ cp $_KernBuild/System.map .
+ cp $_KernBuild/.config .
+ if [ -s $_KernBuild/Module.markers ]; then
+ cp $_KernBuild/Module.markers .
+ fi
+
+ # We may want to keep Documentation, I got complain from users of missing Makefile
+ # of Documentation when building custom module with document.
+ # rm -rf build/Documentation
+ # Script files
+ rm -rf scripts
+ cp -a $_KernSrc/scripts .
+ cp -a $_KernBuild/scripts .
+ find scripts -iname "*.o" -o -iname "*.cmd" -delete
+
+ # Include files
+ rm -rf include
+ cp -a $_KernSrc/include .
+ cp -a $_KernBuild/include/config include/
+ cp -a $_KernBuild/include/generated include/
+
+ # SELinux
+ mkdir -p security/selinux/
+ cp -a $_KernSrc/security/selinux/include security/selinux/
+
+ # Set arch name
+ Arch=$(head -4 $_KernBuild/.config | sed -ne "s/.*Linux\/\([^\ ]*\).*/\1/p" | sed -e "s/x86_64/x86/" )
+
+ # Arch include
+ mkdir -p arch/$Arch
+ cp -a $_KernSrc/arch/$Arch/include arch/$Arch/
+ cp -a $_KernBuild/arch/$Arch/include arch/$Arch/
+
+ if [ -d $_KernBuild/arch/$Arch/scripts ]; then
+ cp -a $_KernBuild/arch/$Arch/scripts arch/$Arch/ || :
+ fi
+
+ # Kernel module build dependency
+ if [ -f $_KernBuild/tools/objtool/objtool ]; then
+ cp -a $_KernBuild/tools/objtool/objtool tools/objtool/ || :
+ fi
+
+ if [ -f $_KernBuild/tools/objtool/fixdep ]; then
+ cp -a $_KernBuild/tools/objtool/fixdep tools/objtool/ || :
+ fi
+
+ cp -a $_KernSrc/arch/$Arch/*lds arch/$Arch/ &>/dev/null || :
+ cp -a $_KernBuild/arch/$Arch/*lds arch/$Arch/ &>/dev/null || :
+
+ mkdir -p arch/$Arch/kernel
+ if [ -f $_KernSrc/arch/$Arch/kernel/module.lds ]; then
+ cp -a $_KernSrc/arch/$Arch/kernel/module.lds arch/$Arch/kernel/
+ fi
+ if [ -f $_KernBuild/arch/$Arch/kernel/module.lds ]; then
+ cp -a $_KernBuild/arch/$Arch/kernel/module.lds arch/$Arch/kernel/
+ fi
+
+ # Copy include/asm-$Arch for better compatibility with some old system
+ cp -a $_KernSrc/arch/$Arch include/asm-$Arch
+
+ # Delete obj files
+ find include -iname "*.o" -o -iname "*.cmd" -delete
+
+ # Make sure the Makefile and version.h have a matching timestamp so that
+ # external modules can be built
+ touch -r Makefile include/generated/uapi/linux/version.h
+ touch -r .config include/linux/autoconf.h
+
+ # Done
+ popd
+}
+
+InstKernelHeaders () {
+ %{kernel_make} headers_install
+ find %{buildroot}/usr/include \
+ \( -name .install -o -name .check -o \
+ -name ..install.cmd -o -name ..check.cmd \) -delete
+}
+
+InstPerf () {
+ %{perf_make} -C tools/perf install-bin install-traceevent-plugins install-python_ext install-man
+
+ # remove the 'trace' symlink.
+ rm -f %{buildroot}%{_bindir}/trace
+}
+
+InstTools() {
+ %{tools_make} -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} CPUFREQ_BENCH=false install
+ rm -f %{buildroot}%{_libdir}/*.{a,la}
+ %find_lang cpupower
+ mv cpupower.lang ../
+
+%ifarch x86_64
+ pushd tools/power/cpupower/debug/x86_64
+ install -m755 centrino-decode %{buildroot}%{_bindir}/centrino-decode
+ install -m755 powernow-k8-decode %{buildroot}%{_bindir}/powernow-k8-decode
+ popd
+%endif
+
+ chmod 0755 %{buildroot}%{_libdir}/libcpupower.so*
+ mkdir -p %{buildroot}%{_unitdir} %{buildroot}%{_sysconfdir}/sysconfig
+ install -m644 %{SOURCE2000} %{buildroot}%{_unitdir}/cpupower.service
+ install -m644 %{SOURCE2001} %{buildroot}%{_sysconfdir}/sysconfig/cpupower
+
+%ifarch x86_64
+ mkdir -p %{buildroot}%{_mandir}/man8
+ %{tools_make} -C tools/power/x86/x86_energy_perf_policy DESTDIR=%{buildroot} install
+ %{tools_make} -C tools/power/x86/turbostat DESTDIR=%{buildroot} install
+ %{tools_make} -C tools/power/x86/intel-speed-select DESTDIR=%{buildroot} install
+%endif
+
+ %{tools_make} -C tools/thermal/tmon install
+ %{tools_make} -C tools/iio install
+ %{tools_make} -C tools/gpio install
+
+ pushd tools/vm/
+ install -m755 slabinfo %{buildroot}%{_bindir}/slabinfo
+ install -m755 page_owner_sort %{buildroot}%{_bindir}/page_owner_sort
+ popd
+
+%ifarch x86_64
+ mkdir -p %{buildroot}%{_sysconfdir}/sysconfig/modules
+ install -m755 %{SOURCE2002} %{buildroot}%{_sysconfdir}/sysconfig/modules
+%endif
+ # with_tools
+}
+
+InstBpfTool () {
+ %{bpftool_make} -C tools/bpf/bpftool bash_compdir=%{_sysconfdir}/bash_completion.d/ mandir=%{_mandir} install doc-install
+}
+
+CollectKernelFile() {
+ ###### Collect file list #########################################
+ pushd %{buildroot}
+
+ # Collect all module files and dirs
+ (find lib/modules/$KernUnameR/ -not -type d | sed -e 's/^lib*/\/lib/';
+ find lib/modules/$KernUnameR/ -type d | sed -e 's/^lib*/%dir \/lib/') | sort -n > core.list
+
+ # Do module splitting, filter-modules.sh will generate a list of
+ # modules to be split into external module package
+ # Rest of the modules stay in core package
+ echo "%dir /lib/modules/$KernUnameR/" >> modules.list
+ %SOURCE10 "%{buildroot}" "$KernUnameR" "%{_target_cpu}" "$_KernBuild/System.map" >> modules.list || exit $?
+
+ comm -23 core.list modules.list > core.list.tmp
+ mv core.list.tmp core.list
+
+ popd
+
+ # Make these file list usable in rpm build dir
+ mv %{buildroot}/{core.list,modules.list} ../
+}
+
+BuildInstMLNXOFED() {
+ inst_mod() {
+ src_mod=$1
+ src_mod_name=$(basename "$src_mod")
+ dest=""
+
+ # Replace old module
+ for mod in $(find $KernModule -name "*$src_mod_name*"); do
+ echo "MLNX_OFED: REPLACING: kernel module $mod"
+ dest=$(dirname "$mod")
+ rm -f "$mod"
+ done
+
+ # Install new module
+ if [ ! -d "$dest" ]; then
+ echo "MLNX_OFED: NEW: kernel module $dest/$mod"
+ dest="$KernModule/kernel/drivers/ofed_addon"
+ mkdir -p $dest
+ fi
+
+ cp -f "$src_mod" "$dest/"
+ }
+
+ handle_rpm() {
+ rm -rf extracted
+ mkdir -p extracted && pushd extracted
+
+ rpm2cpio $1 | cpio -id
+ find . -name "*.ko" -or -name "*.ko.xz" | while read -r mod; do
+ inst_mod "$mod"
+ done
+ # find . -name "*.debug" | while read -r mod; do
+ # inst_debuginfo "$mod"
+ # done
+
+ popd
+ }
+
+ mkdir mlnx-ofed
+ pushd mlnx-ofed
+
+ tar -xzvf %{SOURCE3000}
+ pushd MLNX_OFED_SRC*
+
+ # Unset $HOME, when doing koji build, koji insert special macros into ~/.rpmmacros that will break MLNX installer:
+ # Koji sets _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm,
+ # But the installer assumes "_rpmfilename %{_build_name_fmt}" so it will fail to find the built rpm.
+ DISTRO=$(echo "%{?dist}" | sed "s/\.//g")
+ HOME= ./install.pl --build-only --kernel-only --without-depcheck --distro $DISTRO \
+ --kernel $KernUnameR --kernel-sources $KernDevel \
+ --without-mlx5_fpga_tools --without-mlnx-rdma-rxe --without-mlnx-nfsrdma \
+ --without-mlnx-nvme --without-isert --without-iser --without-srp --without-rshim --without-mdev \
+ --disable-kmp
+
+ # get all kernel module rpms that were built against target kernel
+ find RPMS -name "*.rpm" -type f | while read -r pkg; do
+ if rpm -qlp $pkg | grep "\.ko" | grep -q "$KernelUnameR"; then
+ handle_rpm "$(realpath $pkg)"
+ fi
+ done
+
+ popd
+
+ popd
+}
+
+###### Start Kernel Install
+
+%if %{with_core}
+InstKernelBasic
+
+%if %{with_kabichk}
+{{KABICHECKSPEC}} # `CheckKernelABI `
+%endif
+
+InstKernelDevel
+%endif
+
+%if %{with_headers}
+InstKernelHeaders
+%endif
+
+BuildInstMLNXOFED
+
+%if %{with_perf}
+InstPerf
+%endif
+
+%if %{with_tools}
+InstTools
+%endif
+
+%if %{with_bpftool}
+InstBpfTool
+%endif
+
+CollectKernelFile
+
+###### Debuginfo ###############################################################
+%if %{with_debuginfo}
+
+###### Kernel core debuginfo #######
+%if %{with_core}
+mkdir -p %{buildroot}%{debuginfo_dir}/lib/modules/$KernUnameR
+cp -rpf $_KernBuild/vmlinux %{buildroot}%{debuginfo_dir}/lib/modules/$KernUnameR/vmlinux
+ln -sf %{debuginfo_dir}/lib/modules/$KernUnameR/vmlinux %{buildroot}/boot/vmlinux-$KernUnameR
+%endif
+
+# All binary installation are done here, so run __debug_install_post, then undefine it.
+# This triggers find-debuginfo.sh, undefine prevents it from being triggered again
+# in post %%install. we do this here because we need to compress and sign modules
+# after the debuginfo extraction.
+%__debug_install_post
+
+# Delete the debuginfo for kernel-devel files
+rm -rf %{buildroot}%{debuginfo_dir}/usr/src
+
+%endif
+%undefine __debug_install_post
+
+###### Finally, module sign and compress ######
+%if %{with_modsign}
+### Sign after debuginfo extration, extraction breaks signature
+%{_module_signer} "$KernUnameR" "$_KernBuild" "%{buildroot}" || exit $?
+%endif
+
+### Compression after signing, compressed module can't be signed
+# Spawn at most 16 workers, at least 2 workers, each worker compress 4 files
+NPROC=$(nproc --all)
+[ "$NPROC" ] || NPROC=2
+[ "$NPROC" -gt 16 ] && NPROC=16
+find "$KernModule" -type f -name '*.ko' -print0 | xargs -0r -P${NPROC} -n4 xz -T1;
+
+### Change module path in file lists
+for list in ../*.list; do
+ sed -i -e 's/\.ko$/\.ko.xz/' $list
+done
+
+###### RPM scriptslets #########################################################
+### Core package
+# Pre
+%if %{with_core}
+%pre core
+# Best effort try to avoid installing with wrong arch
+if command -v uname > /dev/null; then
+ system_arch=$(uname -m)
+ if [ %{_target_cpu} != $system_arch ]; then
+ echo "WARN: This kernel is built for %{_target_cpu}. but your system is $system_arch." > /dev/stderr
+ fi
+fi
+
+%posttrans core
+# Weak modules
+if command -v weak-modules > /dev/null; then
+ weak-modules --add-kernel %{kernel_unamer} || exit $?
+fi
+# Boot entry and depmod files
+if command -v kernel-install > /dev/null; then
+ kernel-install add %{kernel_unamer} /lib/modules/%{kernel_unamer}/vmlinuz
+elif command -v new-kernel-pkg > /dev/null; then
+ new-kernel-pkg --package kernel --install %{kernel_unamer} --kernel-args="crashkernel=512M-12G:128M,12G-64G:256M,64G-128G:512M,128G-:768M" --make-default || exit $?
+ new-kernel-pkg --package kernel --mkinitrd --dracut --depmod --update %{kernel_unamer} || exit $?
+else
+ echo "NOTICE: No available kernel install handler found. Please make sure boot loader and initramfs are properly configured after the installation." > /dev/stderr
+fi
+
+# If match, the selinux will be disabled.
+is_set_selinux=0
+if [ -e /proc/config.gz ]; then
+ zcat /proc/config.gz | grep -q "^CONFIG_SECURITY_SELINUX=y"
+ is_set_selinux=$?
+elif [ -e /boot/config-$(uname -r) ]; then
+ cat /boot/config-$(uname -r) | grep -q "^CONFIG_SECURITY_SELINUX=y"
+ is_set_selinux=$?
+elif [ -e /proc/kallsyms ]; then
+ cat /proc/kallsyms | grep -q " selinux_init$"
+ is_set_selinux=$?
+else
+ echo "Ignore selinux adjustments"
+fi
+
+# if CONFIG_SECURITY_SELINUX is not set, we should disable selinux.
+[ $is_set_selinux -ne 0 ] && {
+ echo "Selinux is not supported by current running kernel, disabling SELinux globally to avoid potential system failure."
+ echo "Please update /etc/selinux/config manually after testing SELinux functionality. Now setting SELINUX=disabled"
+ grep -q "^SELINUX *= *.*$" /etc/selinux/config && sed -ri "s/^ *SELINUX *= *enforcing *$/SELINUX=disabled/" /etc/selinux/config || echo "SELINUX=disabled" >> /etc/selinux/config
+}
+
+# Just in case kernel-install didn't depmod
+depmod -A %{kernel_unamer}
+
+%preun core
+# Boot entry and depmod files
+if command -v kernel-install > /dev/null; then
+ kernel-install remove %{kernel_unamer} /lib/modules/%{kernel_unamer}/vmlinuz || exit $?
+elif command -v new-kernel-pkg > /dev/null; then
+ /sbin/new-kernel-pkg --rminitrd --dracut --remove %{kernel_unamer}
+else
+ echo "NOTICE: No available kernel uninstall handler found. Please make sure boot loader and initramfs are properly cleared after the uninstallation." > /dev/stderr
+fi
+
+# Weak modules
+if command -v weak-modules > /dev/null; then
+ weak-modules --remove-kernel %{kernel_unamer} || exit $?
+fi
+
+### Module package
+%post modules
+depmod -a %{kernel_unamer}
+
+%postun modules
+depmod -a %{kernel_unamer}
+
+### Devel package
+%post devel
+if [ -f /etc/sysconfig/kernel ]; then
+ . /etc/sysconfig/kernel || exit $?
+fi
+# This hardlink merges same devel files across different kernel packages
+if [ "$HARDLINK" != "no" -a -x /usr/bin/hardlink -a ! -e /run/ostree-booted ]; then
+ (cd /usr/src/kernels/%{kernel_unamer} && /usr/bin/find . -type f | while read -r f; do
+ hardlink /usr/src/kernels/*/$f $f > /dev/null
+ done)
+fi
+%endif
+
+### kernel-tools package
+%if %{with_tools}
+%post -n kernel-tools-libs
+/sbin/ldconfig
+
+%postun -n kernel-tools-libs
+/sbin/ldconfig
+%endif
+
+###### Rpmbuild packaging file list ############################################
+### empty meta-package
+%if %{with_core}
+%files
+%{nil}
+
+%files core -f core.list
+%defattr(-,root,root)
+# Mark files as ghost in case rewritten after install (eg. by kernel-install script)
+%ghost /boot/vmlinuz-%{kernel_unamer}
+%ghost /boot/.vmlinuz-%{kernel_unamer}.hmac
+/boot/System.map-%{kernel_unamer}
+/boot/config-%{kernel_unamer}
+/boot/symvers-%{kernel_unamer}.gz
+# Initramfs will be generated after install
+%ghost /boot/initramfs-%{kernel_unamer}%{?dist}.img
+# Make depmod files ghost files of the core package
+%ghost /lib/modules/%{kernel_unamer}/modules.alias
+%ghost /lib/modules/%{kernel_unamer}/modules.alias.bin
+%ghost /lib/modules/%{kernel_unamer}/modules.builtin.bin
+%ghost /lib/modules/%{kernel_unamer}/modules.builtin.alias.bin
+%ghost /lib/modules/%{kernel_unamer}/modules.dep
+%ghost /lib/modules/%{kernel_unamer}/modules.dep.bin
+%ghost /lib/modules/%{kernel_unamer}/modules.devname
+%ghost /lib/modules/%{kernel_unamer}/modules.softdep
+%ghost /lib/modules/%{kernel_unamer}/modules.symbols
+%ghost /lib/modules/%{kernel_unamer}/modules.symbols.bin
+
+%files modules -f modules.list
+%ifarch x86_64
+# This might be duplicated with tlinux_cciss_link.modules from kernel-tlinux package, but that's fine
+# since the script itself checks if it's neccessary to re-apply the workaround
+%{_sysconfdir}/sysconfig/modules/tlinux_cciss_link_compat.modules
+%endif
+%defattr(-,root,root)
+
+%files devel
+%defattr(-,root,root)
+/usr/src/kernels/%{kernel_unamer}
+
+%if %{with_debuginfo}
+%files debuginfo -f debuginfo.list
+%defattr(-,root,root)
+/boot/vmlinux-%{kernel_unamer}
+%endif
+# with_core
+%endif
+
+%if %{with_debuginfo}
+%files debuginfo-common-%{_target_cpu} -f debugfiles.list
+%defattr(-,root,root)
+%endif
+
+%if %{with_headers}
+%files headers
+%defattr(-,root,root)
+/usr/include/*
+%endif
+
+%if %{with_perf}
+%files -n perf
+%defattr(-,root,root)
+%{_bindir}/perf*
+%dir %{_libdir}/traceevent/
+%{_libdir}/traceevent/*
+%{_libdir}/libperf-jvmti.so
+%dir %{_prefix}/lib/perf
+%{_prefix}/lib/perf/*
+%dir %{_libexecdir}/perf-core
+%{_libexecdir}/perf-core/*
+%{_datadir}/perf-core/*
+%{_mandir}/man[1-8]/perf*
+%{_sysconfdir}/bash_completion.d/perf
+%{_docdir}/perf-tip/tips.txt
+# TODO: Missing doc?
+# %%doc linux-%%{kernel_unamer}/tools/perf/Documentation/examples.txt
+
+%files -n python3-perf
+%defattr(-,root,root)
+%{python3_sitearch}/*
+
+%if %{with_debuginfo}
+%files -f perf-debuginfo.list -n perf-debuginfo
+%defattr(-,root,root)
+
+%files -f python3-perf-debuginfo.list -n python3-perf-debuginfo
+%defattr(-,root,root)
+%endif
+# with_perf
+%endif
+
+%if %{with_tools}
+%files -n kernel-tools -f cpupower.lang
+%defattr(-,root,root)
+%{_bindir}/cpupower
+%{_datadir}/bash-completion/completions/cpupower
+%ifarch x86_64
+%{_bindir}/centrino-decode
+%{_bindir}/powernow-k8-decode
+%endif
+%{_unitdir}/cpupower.service
+%{_mandir}/man[1-8]/cpupower*
+%config(noreplace) %{_sysconfdir}/sysconfig/cpupower
+%ifarch x86_64
+%{_bindir}/x86_energy_perf_policy
+%{_mandir}/man8/x86_energy_perf_policy*
+%{_bindir}/turbostat
+%{_mandir}/man8/turbostat*
+%{_bindir}/intel-speed-select
+%endif
+%{_bindir}/tmon
+%{_bindir}/iio_event_monitor
+%{_bindir}/iio_generic_buffer
+%{_bindir}/lsiio
+%{_bindir}/lsgpio
+%{_bindir}/gpio-hammer
+%{_bindir}/gpio-event-mon
+%{_bindir}/page_owner_sort
+%{_bindir}/slabinfo
+
+%files -n kernel-tools-libs
+%defattr(-,root,root)
+%{_libdir}/libcpupower.so.0
+%{_libdir}/libcpupower.so.0.0.1
+
+%files -n kernel-tools-libs-devel
+%defattr(-,root,root)
+%{_libdir}/libcpupower.so
+%{_includedir}/cpufreq.h
+
+%if %{with_debuginfo}
+%files -f kernel-tools-debuginfo.list -n kernel-tools-debuginfo
+%defattr(-,root,root)
+%endif
+# with_tools
+%endif
+
+%if %{with_bpftool}
+%files -n bpftool
+%defattr(-,root,root)
+%{_sbindir}/bpftool
+%{_sysconfdir}/bash_completion.d/bpftool
+%{_mandir}/man8/bpftool-cgroup.8.gz
+%{_mandir}/man8/bpftool-gen.8.gz
+%{_mandir}/man8/bpftool-iter.8.gz
+%{_mandir}/man8/bpftool-link.8.gz
+%{_mandir}/man8/bpftool-map.8.gz
+%{_mandir}/man8/bpftool-prog.8.gz
+%{_mandir}/man8/bpftool-perf.8.gz
+%{_mandir}/man8/bpftool.8.gz
+%{_mandir}/man8/bpftool-net.8.gz
+%{_mandir}/man8/bpftool-feature.8.gz
+%{_mandir}/man8/bpftool-btf.8.gz
+%{_mandir}/man8/bpftool-struct_ops.8.gz
+%{_mandir}/man7/bpf-helpers.7.gz
+
+%if %{with_debuginfo}
+%files -f bpftool-debuginfo.list -n bpftool-debuginfo
+%defattr(-,root,root)
+%endif
+# with_bpftool
+%endif
+
+###### Changelog ###############################################################
+%changelog
+{{CHANGELOGSPEC}}
diff --git a/package/default/config.default b/package/default/config.default
index 54479518d..943c7700e 100644
--- a/package/default/config.default
+++ b/package/default/config.default
@@ -183,8 +183,8 @@ CONFIG_INITRAMFS_SOURCE=""
CONFIG_RD_GZIP=y
# CONFIG_RD_BZIP2 is not set
CONFIG_RD_LZMA=y
-# CONFIG_RD_XZ is not set
-# CONFIG_RD_LZO is not set
+CONFIG_RD_XZ=y
+CONFIG_RD_LZO=y
CONFIG_RD_LZ4=y
CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
@@ -3285,9 +3285,9 @@ CONFIG_DRM_I915_SPIN_REQUEST=5
# CONFIG_DRM_AST is not set
# CONFIG_DRM_MGAG200 is not set
# CONFIG_DRM_CIRRUS_QEMU is not set
-# CONFIG_DRM_QXL is not set
-# CONFIG_DRM_BOCHS is not set
-# CONFIG_DRM_VIRTIO_GPU is not set
+CONFIG_DRM_QXL=m
+CONFIG_DRM_BOCHS=m
+CONFIG_DRM_VIRTIO_GPU=m
CONFIG_DRM_PANEL=y
#
@@ -3341,7 +3341,7 @@ CONFIG_FB_DEFERRED_IO=y
# CONFIG_FB_IMSTT is not set
# CONFIG_FB_VGA16 is not set
# CONFIG_FB_UVESA is not set
-# CONFIG_FB_VESA is not set
+CONFIG_FB_VESA=y
CONFIG_FB_EFI=y
# CONFIG_FB_N411 is not set
# CONFIG_FB_HGA is not set