dist: initial support

Upstream: no
Check-Patch: no

Imported from OCKS-2303:
https://github.com/openCloudOS/OpenCloudOS-Kernel-Stream/tree/ocks-2303

This build system is re-written from scratch except some code snips:

- Compatible with systems that were using TK kernel.
- Compatible with RHEL-like systems.
- Resolved tons of hacks and workaround from TK/RHEL. (leftovers are
  marked as TODO)
- All RPM builtin debuginfo utilities are well leveraged (buildid
  re-generate, dwarf compression, etc...)
- For bpftool and BTF info extracting, this package will try self-bootstrap
  and don't depend on host kernel during build time.
- Well commented, and targeted for maximum compatibility.
- Integrated config management system.
- Integrated with version management system.
- Provides many utils.
- Cross-build and cross packaging, also cross kABI checking/updating.
- ...

To start, just run:
make dist-rpm

And for help, just run:
make dist-help

It will build following packages:
  kernel
    Main meta package, empty, depend on kernel-core and kernel-modules
  kernel-core
    The package contains kernel image and core modules, able to boot
    all machines, all kinds of VMs etc.
  kernel-modules
    Contains extra modules and drivers, most modules that are not
    required for VMs and common hardware should go into this pacakge.
  kernel-devel
    Devel files for building custom kernel modules.
  kernel-headers
    Kernel headers.
  perf
  python3-perf
    Userspace tool perf.
  kernel-tools
  kernel-tools-libs
  kernel-tools-libs-devel
    Userspace tools like cpupower, slabinfo, etc...
  bpftool
    bpftool
  kernel-debuginfo
  kernel-debuginfo-common
  perf-debuginfo
  python3-perf-debuginfo
  kernel-tools-debuginfo
  bpftool-debuginfo
    All kinds of debuginfo

Signed-off-by: Kairui Song <kasong@tencent.com>
This commit is contained in:
Kairui Song 2023-11-16 17:29:06 +08:00
parent 0c38b88c33
commit cf5d03932d
49 changed files with 8455 additions and 0 deletions

1
.gitattributes vendored
View File

@ -3,3 +3,4 @@
*.dts diff=dts
*.dts[io] diff=dts
*.rs diff=rust
dist/ export-ignore

8
.gitignore vendored
View File

@ -170,3 +170,11 @@ sphinx_*/
# Rust analyzer configuration
/rust-project.json
# Dist files
/dist/rpm
/dist/workdir
# Tencent dist files
/dist/rpm
/dist/workdir

View File

@ -1,3 +1,10 @@
# 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 = 6
PATCHLEVEL = 6
@ -2053,3 +2060,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

399
dist/Makefile vendored Normal file
View File

@ -0,0 +1,399 @@
# 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 = opencloudos
VENDOR_CAPITALIZED = OpenCloudOS
URL = https://github.com/OpenCloudOS/OpenCloudOS-Kernel-Stream
### 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 <PARAM>=<VALUE>` ######
# 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
# Which kernel config to use, this build system supports multiple config targets,
# Get the available config by scripts/ls-config.sh
CONFIG := $(shell $(DISTDIR)/scripts/ls-config-targets.sh | tail -n 1)
# Build a specific tag/commit with `make TAG=<tag>` or `make COMMIT=<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)
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
# If COMMIT is specified, this line won't take effect
COMMIT := $(shell git rev-parse --verify --quiet $(TAG))
ifeq ($(COMMIT),)
$(error Invalid git reference, tag '$(TAG)' commit '$(COMMIT)', aborting)
endif
# Prefer using TAG, if not set, use COMMIT
TAG := $(COMMIT)
GITREF := $(TAG)
### RPM dir and workdir
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
WORKDIRS = $(DISTWORKDIR) $(RPM_TOPDIR) $(RPM_BUILDDIR) $(RPM_RPMDIR) $(RPM_SOURCEDIR) $(RPM_SPECDIR) $(RPM_SRCRPMDIR) $(RPM_BUILDROOTDIR)
# Prepare workdir and variables for dist scripts
$(shell mkdir -p $(WORKDIRS); \
{ \
echo "KDIST=$(KDIST)"; \
echo "VENDOR=$(VENDOR)"; \
echo "VENDOR_CAPITALIZED=$(VENDOR_CAPITALIZED)"; \
echo "URL=$(URL)"; \
} > $(DISTPATH)/.distenv \
)
### Build files
KFULLVER := $(shell $(DISTDIR)/scripts/get-version.sh $(GITREF) vr)
CONFIGFILE := $(shell $(DISTDIR)/scripts/ls-config-files.sh $(CONFIG))
SPECFILE = $(RPM_SOURCEDIR)/kernel.spec
TARFILE = $(RPM_SOURCEDIR)/kernel-$(KFULLVER).tar.gz
TESTPATCH = $(RPM_SOURCEDIR)/linux-kernel-test.patch
ifeq ($(CONFIGFILE),)
$(error Invalid CONFIG value '$(CONFIG)', no matching config target found)
endif
### RPM build options
# All params enabled by default (except kABI check, see below), ENABLED overrides DEFAULT_DISABLE.
DISABLED=$(DEFAULT_DISABLED)
ENABLED=$(DEFAULT_ENABLED)
## A few shortcut for commonly used params:
# Disable KABI check by default
KABI=0
ifeq ($(KABI), 0)
override DISABLED := kabichk $(DISABLED)
endif
# Enabled module sign by default
MODSIGN=1
ifeq ($(MODSIGN), 0)
override DISABLED := modsign $(DISABLED)
endif
# Disable private key pkg by default
KEYPKG=0
ifeq ($(KEYPKG), 0)
override DISABLED := keypkg $(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 ($(DIST),)
override RPMFLAGS := --define "dist .$(DIST)" $(RPMFLAGS)
$(info "NOTE: DIST is set, building for another distro $(DIST)")
$(info " You shoudn't do this unless you know what you are doing.")
endif
default: dist-help
$(TARFILE):
@echo "Generating kernel source tar: $(TARFILE)"
@cd $(TOPDIR); git archive $(GITREF) $(TOPDIR) --format=tar.gz --prefix=kernel-$(KFULLVER)/ --output $(TARFILE)
dist-tarball: $(TARFILE)
@echo "$(TARFILE)"
$(CONFIGFILE): $(DISTFILES)
@echo "Generating kernel config style '$(CONFIG)'"
@$(DISTDIR)/scripts/gen-configs.sh "$(CONFIG)" "$(GITREF)"
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 dist-configs
@echo "Generating kernel RPM spec: $(SPECFILE)"
@$(DISTDIR)/scripts/gen-spec.sh \
--gitref "$(GITREF)" \
--build-arch "$(SRPM_ARCH)" \
--kernel-config "$(CONFIG)" \
--set-default-disabled "$(DISABLED)" \
--set-default-enabled "$(ENABLED)" \
> $(SPECFILE)
@grep -A2 "# == Package options ==" $(SPECFILE) | cut -c3-
dist-specfile: $(SPECFILE)
@echo "$(SPECFILE)"
dist-sources: dist-configs $(TARFILE) $(DISTSOURCES) $(DISTKABIS) $(SPECFILE)
@cp $(DISTSOURCES) $(DISTKABIS) $(RPM_SOURCEDIR)
define DO_RPMBUILD
@echo "=== DISTBUILD ==="
@echo "Building kernel: $(shell rpmspec -q --qf "%{name}-%{version}-%{release}\n" --srpm $(SPECFILE))"
@echo "Kernel uname-r: $(shell rpmspec -q --provides $(SPECFILE) | grep kernel-uname-r | awk -F ' = ' '{print $$2}')"
@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: dist-new-maj-release
dist-new-maj-release:
@$(DISTDIR)/scripts/make-release.sh --maj-release
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: dist-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: dist-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 \
--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 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 ' 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

10
dist/README vendored Normal file
View File

@ -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 <kasong@tencent.com>
Katrin Zhou <katrinzhou@tencent.com>
Kaixu Xia <kaixuxia@tencent.com>
Bundle with the Linux Kernel, licensed under the GPLv2

View File

View File

@ -0,0 +1,9 @@
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
# CONFIG_LOCALVERSION_AUTO is not set

View File

3046
dist/configs/00base/generic/riscv64.config vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -0,0 +1,134 @@
CONFIG_ACPI_APEI_ERST_DEBUG=m
CONFIG_LOCALVERSION="+debug"
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_FUTEX=y
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=y
CONFIG_KASAN_INLINE=y
CONFIG_KASAN_KUNIT_TEST=m
# CONFIG_KASAN_OUTLINE is not set
CONFIG_KASAN_VMALLOC=y
CONFIG_KCOV=y
CONFIG_KCOV_ENABLE_COMPARISONS=y
CONFIG_KCOV_INSTRUMENT_ALL=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

View File

@ -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

View File

@ -0,0 +1,3 @@
CONFIG_GCOV_KERNEL=y
CONFIG_GCOV_PROFILE_ALL=y
CONFIG_LOCALVERSION="+gcov"

View File

0
dist/kabi/Module.kabi_aarch64 vendored Normal file
View File

0
dist/kabi/Module.kabi_riscv64 vendored Normal file
View File

0
dist/kabi/Module.kabi_x86_64 vendored Normal file
View File

331
dist/scripts/check-commits.sh vendored Executable file
View File

@ -0,0 +1,331 @@
#!/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 <commit>...
--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=<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 <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> (\"<title line>\")'"
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) ([^[:space:]]+)/\2/pg")
upstream_status=$(echo "$commit_body" | sed -nE "s/^(Upstream status:|Upstream:) ([^[:space:]]+)/\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: <no/pending/downstream-only...>'
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: <no/pending/downstream-only...>'
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: <commit id>"
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: <commit id>"
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: <commit id>"
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: <none/refactored/minor/resolved...>"
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 <yourname@$VENDOR.com>\""
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" | {
ERROR=0
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
ERROR=$(( ERROR + 1 ))
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
exit "$ERROR"
}
exit $?

215
dist/scripts/check-configs.sh vendored Executable file
View File

@ -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] [ <config targets> ... ]
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

23
dist/scripts/check-tag.sh vendored Executable file
View File

@ -0,0 +1,23 @@
#!/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 "$@"
KERNEL_UNAMER="$KERNEL_UNAMER_BASE.<dist>.<arch>"
if [[ $KERNEL_UNAMER_FORCE ]]; then
KERNEL_UNAMER="$KERNEL_UNAMER_FORCE"
fi
# If tag is not recognized, prepare_kernel_ver will version it as snapshot
# use this as an indicator of invalid tag
if ! [[ $KTAGRELEASE ]]; then
warn "Invalid tag, will override with Kernel uname-r '$KERNEL_UNAMER', RPM NVR version '${KERNEL_NAME}-${KERNEL_MAJVER}-${KERNEL_RELVER}'"
exit 1
else
info "Tag '$KTAGRELEASE' OK, Kernel uname-r '$KERNEL_UNAMER', RPM NVR version '${KERNEL_NAME}-${KERNEL_MAJVER}-${KERNEL_RELVER}'"
fi

111
dist/scripts/dummy-tools/gcc vendored Executable file
View File

@ -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 <word-you-are-searching-for> "$@"
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

30
dist/scripts/dummy-tools/ld vendored Executable file
View File

@ -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 <word-you-are-searching-for> "$@"
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

1
dist/scripts/dummy-tools/nm vendored Symbolic link
View File

@ -0,0 +1 @@
ld

1
dist/scripts/dummy-tools/objcopy vendored Symbolic link
View File

@ -0,0 +1 @@
ld

14
dist/scripts/format-configs.sh vendored Executable file
View File

@ -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

19
dist/scripts/gen-configs.sh vendored Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash --norc
# SPDX-License-Identifier: GPL-2.0
#
# Generate kernel config according to config matrix
#
# Params:
# $@: [ <filter>... ] When non-empty, only generate kernel configs style matching <filter>
# 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 "$@"
# Check config values (eg. LOCALVERSION)
sanity_check_configs "$@"

249
dist/scripts/gen-spec.sh vendored Executable file
View File

@ -0,0 +1,249 @@
#!/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
}
# gen-spec need to parse info from source (currently only parse LOCALVERSION from config),
# so check if the kernel configs are valid here.
prepare_source_info() {
local localversion arch_localversion file
if [ -z "$KERNEL_CONFIG" ]; then
die "Config target not specified."
fi
for arch in $BUILD_ARCH; do
file="$SOURCEDIR/$KERNEL_CONFIG.$arch.config"
if ! [ -e "$file" ]; then
die "Config file missing '$file'"
fi
if [ -z "$localversion" ]; then
localversion=$(sed -ne 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/pg' "$file")
else
arch_localversion=$(sed -ne 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/pg' "$file")
if [ "$arch_localversion" != "$localversion" ]; then
die "LOCALVERSION inconsistent between sub-arches for config target '$file', this breaks SRPM package naming."
fi
fi
done
localversion=${localversion#\"}
localversion=${localversion%\"}
LOCALVERSION=$localversion
}
DEFAULT_DISALBED=""
while [[ $# -gt 0 ]]; do
case $1 in
--kernel-config )
KERNEL_CONFIG=$2
shift 2
;;
--build-arch )
BUILD_ARCH=$2
shift 2
;;
--gitref )
GITREF=$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
BUILD_ARCH="${BUILD_ARCH:-$SPEC_ARCH}"
# This helper prepares LOCALVERSION
prepare_source_info
# This function will prepare $KERNEL_MAJVER, $KERNEL_RELVER
prepare_kernel_ver "${GITREF:-HEAD}" "$LOCALVERSION"
_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 kernel_majver $KERNEL_MAJVER
%define kernel_relver $KERNEL_RELVER
%define kernel_variant ${LOCALVERSION:-"%{nil}"}
%define kernel_unamer_base $KERNEL_UNAMER_BASE
%define kernel_unamer_force ${KERNEL_UNAMER_FORCE:-"%{nil}"}
%define rpm_name $KERNEL_NAME
%define rpm_vendor $VENDOR_CAPITALIZED
%define rpm_url $URL
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
}
_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 \
traceevent_dyn \
keypkg
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"

9
dist/scripts/get-next-sub-version.sh vendored Executable file
View File

@ -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_BASE"

9
dist/scripts/get-next-version.sh vendored Executable file
View File

@ -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_BASE"

23
dist/scripts/get-version.sh vendored Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash --norc
# SPDX-License-Identifier: GPL-2.0
#
# Print out the tkernel version based on git commit and work tree.
#
# $1: git reference, tag or commit
# $2: version type, 'nvr' or 'unamer', defaults to 'unamer'
#
# shellcheck source=./lib-version.sh
. "$(dirname "$(realpath "$0")")/lib-version.sh"
prepare_kernel_ver "$1"
case $2 in
vr )
echo "$KERNEL_MAJVER"-"$KERNEL_RELVER"
;;
nvr )
echo "$KERNEL_NAME"-"$KERNEL_MAJVER"-"$KERNEL_RELVER"
;;
* | unamer )
echo "$KERNEL_UNAMER"
;;
esac

88
dist/scripts/helper/backporter.sh vendored Executable file
View File

@ -0,0 +1,88 @@
#!/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)>"
REASON=$1
COMMIT=$2
UPSTRAM="upstream"
[ -z "$COMMIT" ] && die "Usage: $0 <upstream commit id>"
_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 \
--message \
"$(git log -1 --format=%s "$COMMIT")
commit $COMMIT $UPSTRAM
Conflicts: $CONFLICT
Back$(echo "port-reason: $REASON" | fold -s -w 75 | sed -e '2,$s/^/ /')
$(git show --pretty=format:"%B" --no-patch "$COMMIT" | tail -n +3)
Signed-off-by: $AUTHOR"

80
dist/scripts/helper/dist-repo-init.sh vendored Executable file
View File

@ -0,0 +1,80 @@
#!/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."
}
if [[ $1 == "--reset" ]]; then
### Clean up changelog
echo -n > "$DISTDIR"/templates/changelog
### Clean up kABI
for i in $SPEC_ARCH; do
echo -n > "$DISTDIR"/kabi/Module.kabi_$i
done
### Clean up generic-default config
echo -n > "$DISTDIR"/configs/00base/generic/default.config
for i in $SPEC_ARCH; do
echo -n > "$DISTDIR"/configs/00base/generic/$i.config
done
fi
### 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 "$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
}

116
dist/scripts/helper/gen-module-kabi.sh vendored Executable file
View File

@ -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 <kernel name>] [--symver <symver file>] [<module name or file>, ...]
<kernel name>: default to \$(uname -r), or specify a installed kernel
<symver file>: default to /usr/lib/<kernel name>/symvers.gz, or specify a symver file
<module>: 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

27
dist/scripts/helper/update-kabi.sh vendored Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env sh
#
error() {
echo "error: $*" > /dev/stderr
}
usage() {
cat << EOF
update-kabi.sh: <kABI Module.symvers> <new Module.symvers>
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$//"

457
dist/scripts/lib-config.sh vendored Executable file
View File

@ -0,0 +1,457 @@
#!/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 \
| sed -e 's/[ \t]*$//' \
| cut -d ' ' -f 2-
}
# Iterate the dot product of all config options
# param: <callback> [<filter>... ]
# [<filter>... ]: Filters config targets to use. eg. kernel-default-*, kernel-minimal-debug
# <callback>: A callback function, see below for <callback> params.
#
# Will generate a matrix, and call <callback> like this:
# <callback> <config-target> [ <dir entry of configs in inherit order> ... ]
#
# eg.
# <callback> "kernel-generic-release" "$TOPDIR/00pending/kernel" "$TOPDIR/20preset/generic" "$TOPDIR/50variant/release"
# <callback> "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: <callback> [<filter>... ]
# [<filter>... ]: Filters config targets to use. eg. kernel-default-*, kernel-minimal-debug
# <callback>: A callback function, see below for <callback> params.
#
# Will generate a matrix, and call <callback> like this:
# <callback> <arch> <config-file> [ <backing config files in inherit order>... ]
#
# eg.
# <callback> "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"
# <callback> "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: <name>.<arch>.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 "$@"
}
sanity_check_configs () {
# We use LOCALVERSION in Kconfig for variant, save a make flag, but require more sanity check to avoid misuse.
# First ensure all arch have the same value
# Then ensure it's in a acceptable format
_sanity_check_configs() {
local target=$1; shift
local populated_config
local localversion arch_localversion auto_localversion conf_localversion
for arch in "${CONFIG_ARCH[@]}"; do
populated_config="$CONFIG_OUTDIR/$target.$arch.config"
# config base name is always in this format: <name>.<arch>.config
echo "Checking $(basename "$populated_config")..."
if ! [ -f "$populated_config" ]; then
error "Config not populated: '$populated_config'"
error "sanity_check_configs need to be called after the configs are populated"
exit 1
fi
auto_localversion=$(sed -ne 's/^CONFIG_LOCALVERSION_AUTO=\(.*\)$/\1/pg' "$populated_config")
if [ -n "$auto_localversion" ] && [ "$auto_localversion" != "n" ]; then
error "CONFIG_LOCALVERSION_AUTO must be unset, but it's set in config target $target"
error "This will break dist build system's release versioning."
exit 1
fi
conf_localversion=$(sed -ne 's/^CONFIG_LOCALVERSION=\(.*\)$/\1/pg' "$populated_config")
conf_localversion=${conf_localversion##\"}
conf_localversion=${conf_localversion%%\"}
if [ 1 -lt "$(echo "$conf_localversion" | wc -l)" ]; then
error "More than one LOCALVERSION is set for config target '$target'"
exit 1
fi
if [ -z "$localversion" ]; then
localversion=$conf_localversion
else
arch_localversion=$conf_localversion
if [ "$arch_localversion" != "$localversion" ]; then
error "Unexpected '$arch_localversion' != '$localversion':"
error "This breaks SRPM package naming, LOCALVERSION inconsistent between sub-arches for config target '$target'"
exit 1
fi
fi
done
localversion=${localversion#\"}
localversion=${localversion%\"}
case $localversion in
+debuginfo|+core|+devel|+headers|+modules|+$KDIST )
error "Unexpected LOCALVERSION '$localversion':"
error "LOCALVERSION is using a reserved keyword, this will cause package dependency breakage."
exit 1
;;
+* )
;;
'' )
# Empty value is default and fine
;;
*)
error "Unexpected LOCALVERSION '$localversion':"
error "LOCALVERSION is not in acceptable format, for dist building system, it need to start with a '+'"
error "to distinguish it from release string, and dist build system also need to manipulate the string based on above fact."
exit 1
esac
}
for_each_config_target _sanity_check_configs "$@"
}

743
dist/scripts/lib-version.sh vendored Executable file
View File

@ -0,0 +1,743 @@
#!/bin/bash
#
# Version conversion helpers for building a TK kernel.
#
# shellcheck source=./lib.sh
. "$(dirname "$(realpath "$0")")/lib.sh"
## Standardized kernel package version and uname are composed as follows:
#
# A valid tag: [PREFIX-]<KERNEL_MAJVER>-<KERNEL_RELVER>[.<KERNEL_DIST>]
# uname -r: <KERNEL_MAJVER>-<KERNEL_RELVER>[.<KERNEL_DIST>][+<LOCALVER>]
# RPM NVR: kepnel[-<KERNEL_DIST>][-<LOCALVER>]-<KERNEL_MAJVER>-<KERNEL_RELVER>
# <NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN>-<VVVVVVVVVVVVV>-<RRRRRRRRRRRRR>
#
# Some NOTES about why we compose these string in above way:
# - Notice KERNEL_DIST is moved to N part of the RPM NVR, this is how TK3/TK4 release have been doing
# and that is correct because we need to distingush between kernel release streams. And there are
# things will break if we move it out of this part (mostly due to package name change).
# - RPM split the whole package name by '-', then recognize the right most part as R, second right
# most part is V, so KERNEL_MAJVER and KERNEL_RELVER can't contain '-'.
# - LOCALVER is commonly used to present variants of kernel, that is, using same kernel repo commit/version/tag,
# just built with a different config.
# A example is RPM pkg kernel-5.4.119-1 (uname 5.4.119-1) and kernel-debug-5.4.119-1 (uname 5.4.119-1+debug),
# the later one is same kernel built with more debug configs enabled. When kernel-5.4.119-1 run into unkown
# issues, kernel-debug-5.4.119-1 could be installed to do more diagnosis.
# - Notice LOCALVER is moved to "N" part of the RPM NVR, because adding to "V" or "R" part breaks kernel
# package versioning. A suffix, prefix or in-fix of "V" or "R" could cause the package or repo manager
# to make variants override each other, and fails the system unexpectly. For example, an debug kernel
# could be wrongly installed with a normal system wide package update, since the suffix made it had a
# high version number and it shares same Name with vanilla kernel.
# - Some old TK4 tag will have KERNEL_DIST as part of KERNEL_RELVER, we cover that too.
#
## More explanations of each field:
#
### PREFIX: <none>/release/x86/aarch64/oc/....
# - Could be some well-known string like "release", "x86", ..., could be used to make tags more distinguishable.
#
### KERNEL_MAJVER: <VERSION>.<PATCHLEVEL>.<SUBLEVEL>
# - It's the standdard upstream linux kernel release version, presents in kernel's root Makefile, eg:
# VERSION = 5
# PATCHLEVEL = 4
# SUBLEVEL = 203
# Which stands for kernel 5.4.203
#
### KERNEL_RELVER: [0.<SNAPSHOT>.][<EXTRAVERSION>.]<REL>
# - If starts with 0, indicates it's a snapshot, unofficial release. Else it must be a tagged release.
# The <SNAPSHOT> string is automatically generated using git commit as versioning base for untagged
# test builds.
# - If EXTRAVERSION is non-empty, it must present here.
# - REL is a custom release string, should be alphanums be splitted by '.'.
# eg. 0011, 0009.12, 0011.prerelease1, ...
# eg. 2207.1.1, 2207.1.2, ...
#
# NOTE: due to historical reason, in KERNEL_RELVER, it could contain '-', but the final generated string that will be used in
# spec file and uname will always be converted to contain '.' only, to comply the RPM NVR naming style, also make things cleaner.
#
### KERNEL_DIST: <none>/tks/tlinux4/stable/stream/...
# Indicates this is a special build kernel, will show up in RPM package name to distinguish different kernel release stream.
# Is configurable through the KDIST variable in dist/Makefile.
#
# NOTE: Due to historical reason, if KDIST is added as first part of KERNEL_RELVER's <REL> string, it will be move to tail.
# To make the KERNEL_RELVER part consistent between RPM name, tag and uname.
#
# Example:
# git describe --tag RPM uname -r
# 5.4.119-1-tlinux4-0007 kernel-tlinux4-5.4.119-1.0007 5.4.119-1.0007.tlinux4
# 5.4.119-1-tlinux4-0007-2-g884a77bf0ba6 kernel-tlinux4-5.4.119-0.20211115git1135ec008ef3.1.0007 5.4.119-0.20211115git1135ec008ef3.1.0007.tlinux4
# 5.4.119-1-tlinux4-0007.subrelease kernel-tlinux4-5.4.119-1.0007.subrelease 5.4.119-1.0007.subrelease.tlinux4
# 5.4.119-1-tlinux4-0007~rc1 kernel-tlinux4-5.4.119-1.0007~rc1 5.4.119-1.0007~rc1.tlinux4 (*)
#
# 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:
# Alias of four-part linux kernel version from kernel's Makefile
KVERSION=
KPATCHLEVEL=
KSUBLEVEL=
KEXTRAVERSION=
# 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=
# Set to true if this is a rolling build tracks upstream
KROLLING=
# Set to 1 to allow git tag force override uname
KFORCEUNAMER=
# git snapshot versioning
KGIT_SNAPSHOT=
# Raw info from current git tag
KGIT_TAG_RELEASE_INFO_RAW=
# Set if current commit is tagged with valid release info
KGIT_TAG_RELEASE_INFO=
# Set if a previous commit is found tagged with valid release info
KGIT_LATEST_TAG_RELEASE_INFO=
# 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_NUM=
KGIT_SUB_RELEASE_NUM=
### The formal kernel version and release
# Simulate base part of uname output, which is always "$KVERSION.$KPATCHLEVEL.$KSUBLEVEL$KEXTRAVERSION"
# The full `uname -r` will also include <dist>.<arch>[+<flavor>]
export KERNEL_UNAMER_BASE=
# Force set a value for `uname -r`, see KFORCEUNAMER.
export KERNEL_UNAMER_FORCE=
# Basically: $KVERSION.$KPATCHLEVEL.$KSUBLEVEL (eg. 5.17.0, 5.16.3)
export KERNEL_MAJVER=
# Release version (eg. 1, 0.rc0, 0.20220329gita11bf64a6e8f), see comments at the beginning of this file
export KERNEL_RELVER=
# Kernel dist repo variable (eg. tks, tlinux4, <none>), with any leading "." or "-" removed, see comments at the beginning of this file
export KERNEL_DIST=
# Only used for make-release sub command, get latest release tag of current commit
export KERNEL_PREV_RELREASE_TAG=
# Set if it's a tagged release
export KTAGRELEASE=
# KTESTRELEASE: If we are building based on a test tag
KTESTRELEASE=
# KSNAPRELEASE: If we are building a snapshot-release
KSNAPRELEASE=
# KRCRELEASE: If we are building a rc-release
KRCRELEASE=
_is_num() {
[ "$1" -eq "$1" ] &>/dev/null
}
# Get the tag of a git ref, if the git ref itself is a valid tag, just return itself
# else, search latest tag before this git ref.
_get_git_tag_of() {
local gitref=$1; shift
local tag tags
tags=$(git "$@" tag --points-at "$gitref")
# If multiple tags presents, used the one specified by user
for tag in $tags; do
if [[ "$tag" == "$gitref" ]]; then
echo "$tag"
return
fi
done
# If HEAD is tagged with multiple tags and user is not asking to use one of them,
# use the first one found matching release info.
for tag in $tags; do
if _get_rel_info_from_tag "$tag" > /dev/null; then
echo "$tag"
return
fi
done
# Else just return the first tag
for tag in $tags; do
echo "$tag"
return
done
}
# git-describe, but customized for kernel, and prefer specified tag
_get_git_describe_of() {
local gitref=$1; shift
local gitdesc
gitdesc=$(_get_git_tag_of "$gitref" "$@")
if [[ -n "$gitdesc" ]]; then
echo "$gitdesc"
else
git "$@" describe --always --tags --abbrev=12 "$gitref"
fi
}
# Get the tag of a git ref, if the git ref itself is a valid tag, just return itself
# else, search latest tag before this git ref.
# Return 1 if git ref is tagged,
_get_last_git_tag_of() {
local gitref=$1; shift
local gittag
gittag=$(_get_git_tag_of "$gitref" "$@")
if [[ -z "$gittag" ]]; then
git "$@" describe --always --tags --abbrev=0 "$gitref"
return 0
else
echo "$gittag"
return 1
fi
}
# $1: git tag or git commit, defaults to HEAD
# $2: kernel source tree, should be a git repo
# Parse fondunmental kernel versioning info from Makefiles.
get_kernel_code_version() {
local gitref=${1:-HEAD}
local repo=${2:-$TOPDIR}
local makefile
makefile=$(git -C "$repo" show "$gitref:Makefile" 2>/dev/null || cat "$repo/Makefile")
if [ ! "$makefile" ]; then
die "Error: Failed to read Makefile"
return 1
fi
KVERSION=$(get_makefile_var VERSION <<< "$makefile")
KPATCHLEVEL=$(get_makefile_var PATCHLEVEL <<< "$makefile")
KSUBLEVEL=$(get_makefile_var SUBLEVEL <<< "$makefile")
KEXTRAVERSION=$(get_makefile_var EXTRAVERSION <<< "$makefile")
# Replace '-' in KEXTRAVERSION
KEXTRAVERSION=${KEXTRAVERSION//-/.}
KEXTRAVERSION=${KEXTRAVERSION#.}
if [[ -z "$KVERSION" ]] || [[ -z "$KPATCHLEVEL" ]] || [[ -z "$KSUBLEVEL" ]]; then
error "Invalid VERSION, PATCHLEVEL or SUBLEVEL in Makefile:"
error "$KVERSION.$KPATCHLEVEL.$KSUBLEVEL:"
exit 1
fi
if [[ "$KEXTRAVERSION" == "rc"* ]] || [[ $KEXTRAVERSION == "-rc"* ]]; then
KRCRELEASE=1
fi
# Read KDIST using gitref for historical accurate value.
KERNEL_DIST=$(get_dist_makefile_var KDIST "$gitref" "$repo")
return 0
}
_first_merge_window_detection() {
local gitref=${1:-HEAD}
local repo=${2:-$TOPDIR}
local upstream_base upstream_lasttag upstream_gitdesc
local tagged
# 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_gitdesc=$(git -C "$repo" describe --tags --abbrev=12 "$upstream_base" 2>/dev/null)
upstream_lasttag=$(_get_last_git_tag_of "$upstream_base" -C "$repo")
tagged=$?
if \
# If last tag is an tagged upstream release
[[ $upstream_lasttag == v$KVERSION.$KPATCHLEVEL ]] && \
# And if merge base is ahead of the taggewd release
[[ "$tagged" -eq 1 ]]; 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
}
_do_strip_kernel_majver() {
local rel
if [[ $1 == *"$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"* ]]; then
rel=${1#*"$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"}
elif [[ "$KSUBLEVEL" = "0" ]] && [[ $1 == *"$KVERSION.$KPATCHLEVEL"* ]]; then
rel=${1#*"$KVERSION.$KPATCHLEVEL"}
elif [[ $KPREMERGEWINDOW ]] && [[ $1 == *"$KVERSION.$((KPATCHLEVEL + 1)).$KSUBLEVEL"* ]]; then
rel=${1#*"$KVERSION.$((KPATCHLEVEL + 1)).$KSUBLEVEL"}
else
return 1
fi
echo "$rel"
}
# Check and strip the leading VERSION.PATCHLEVEL.SUBLEVEL of a tag,
# (eg. 5.18.19) and potential prefixes. If the tag doesn't match its corresponding,
# kernel version, return 1.
_check_strip_kernel_majver() {
local tag=$1 rel
local makefile
local _kversion _kpatchlevel _ksublevel
if rel=$(_do_strip_kernel_majver "$tag"); then
echo "$rel"
return 0
fi
# Update VERSION/PATCHLEVEL/SUBLEVEL using target Makefile, because y upstream
# changes them very frequently and may out of sync with previous tag.
if makefile=$(git show "$tag:Makefile" 2>/dev/null); then
_kversion=$(get_makefile_var VERSION <<< "$makefile")
_kpatchlevel=$(get_makefile_var PATCHLEVEL <<< "$makefile")
_ksublevel=$(get_makefile_var SUBLEVEL <<< "$makefile")
fi
if rel=$(KVERSION=$_kversion KPATCHLEVEL=$_kpatchlevel KSUBLEVEL=$_ksublevel _do_strip_kernel_majver "$tag"); then
echo "$rel"
return 0
fi
return 1
}
# Get release info from git tag
_get_rel_info_from_tag() {
local tag=$1 rel
if ! rel=$(_check_strip_kernel_majver "$@"); then
return 1
fi
rel=${rel//-/.}
rel=${rel#.}
# If KERNEL_DIST is added as prefix/semi-prefix/suffix, remove it from rel
if [[ $KERNEL_DIST ]]; then
case $rel in
$KERNEL_DIST.*)
rel=${rel#$KERNEL_DIST.}
;;
$KEXTRAVERSION.$KERNEL_DIST.*)
rel=${rel#$KEXTRAVERSION.$KERNEL_DIST.}
rel=$KEXTRAVERSION.$rel
;;
*.$KERNEL_DIST)
rel=${rel%.$KERNEL_DIST}
;;
esac
fi
# If KEXTRAVERSION is added, remove it
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 _is_num "$KEXTRAVERSION"; then
case $rel in
# Extra version is release number, remove it and add later
$KEXTRAVERSION | "$KEXTRAVERSION."* )
rel=${rel#$KEXTRAVERSION}
rel=${rel#.}
;;
* ) 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."* )
rel=${rel#$KEXTRAVERSION.}
;;
# Already appended as , eg 5.17-1.rc3*
*".$KEXTRAVERSION" )
rel=${rel%.$KEXTRAVERSION}
;;
* ) return 1; ;;
esac
fi
echo "$rel"
}
_search_for_release_tag() {
local gitref=$1; shift
local tag
# Look back for 10 commits for a valid tag
local limit=10
while [[ $limit -gt 0 ]]; do
# Check if any tag is eligible as a release tag
for tag in $(git "$@" tag --points-at "$gitref"); do
if _get_rel_info_from_tag "$tag" > /dev/null; then
echo "$tag"
return 0
fi
done
# Find a previous tagged commit
gitref=$(git "$@" describe --first-parent --tags --abbrev=0 "$gitref^" 2>/dev/null) || break
limit=$((limit - 1))
done
warn "No valid tag found that are eligible for versioning, please fix your repo and tag it properly."
return 1
}
# Get release info from git tag
#
# We try to parse and verify RPM NVR (Name, Version, Release) info's 'VR' part using git tag or commit info
# 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<commit> for snapshot release.
# But ideally all git tag are for formal release so snapshot tag shouldn't appear in repo.
#
# With a tag that contains valid VR info it's considered a tag release, else it's a snapshot release.
#
# $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 tagged
# Get current commit's snapshot name, format: YYYYMMDDgit<commit>,
# 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 [[ $KROLLING ]] && _first_merge_window_detection "$@"; then
KPREMERGEWINDOW=1
fi
# Get latest git tag of this commit
last_tag=$(_get_last_git_tag_of "$gitref" -C "$repo")
tagged=$?
# 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 HEAD -C "$repo"); then
warn "Found release tag '$release_tag'."
fi
fi
if [[ "$release_tag" ]]; then
git_desc=$(_get_git_describe_of "$gitref" -C "$repo")
release_info=$(_get_rel_info_from_tag "$release_tag")
release_info_raw=$(_check_strip_kernel_majver "$release_tag")
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."
release_info=0
KGIT_RELEASE_NUM=0
KGIT_SUB_RELEASE_NUM=0
elif [[ $release_info == 0.* ]]; then
KGIT_RELEASE_NUM=${release_info##*.}
KGIT_SUB_RELEASE_NUM=${release_info%$KGIT_RELEASE_NUM}
KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM%.}
KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM##*.}
else
KGIT_RELEASE_NUM=${release_info%%.*}
KGIT_SUB_RELEASE_NUM=${release_info#$KGIT_RELEASE_NUM}
KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM#.}
KGIT_SUB_RELEASE_NUM=${KGIT_SUB_RELEASE_NUM%%.*}
fi
KERNEL_PREV_RELREASE_TAG=$release_tag
KGIT_LATEST_TAG_RELEASE_INFO=$release_info
if [[ "$tagged" -eq 1 ]] && [[ "$release_tag" == "$last_tag" ]]; then
if [[ $release_info ]]; then
# This commit is tagged and it's a valid release tag, juse use it
if [[ "$KGIT_RELEASE_NUM" != '0' ]]; then
KGIT_TAG_RELEASE_INFO=$release_info
KGIT_TAG_RELEASE_INFO_RAW=$release_info_raw
KTAGRELEASE=$release_tag
else
warn "'$release_tag' is not a formal release tag, using snapshot versioning."
KGIT_SNAPSHOT=1
fi
else
# Tagged but no release info from current tag, could be upstream style tag
KGIT_TAG_RELEASE_INFO=1
# It's not a valid tag
KTAGRELEASE=
fi
# If current tag is release tag, previous release tag should be another one
KERNEL_PREV_RELREASE_TAG=$(_search_for_release_tag ${release_tag}^ -C "$repo")
elif [[ "$last_tag" == "$git_desc" ]]; then
# It's tagged, but the tag is not a release tag
# 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=test.$last_tag
KGIT_TESTBUILD_TAG=${KGIT_TESTBUILD_TAG//-/_}
KTESTRELEASE=1
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
else
# No tag or no repo info available, use snapshot version
KSNAPRELEASE=1
KGIT_RELEASE_NUM=0
KGIT_SUB_RELEASE_NUM=0
fi
# Fix release numbers, if it's not a number
if ! _is_num "$KGIT_RELEASE_NUM"; then
warn "Unrecognizable release number: $KGIT_RELEASE_NUM, resetting to 0"
KGIT_RELEASE_NUM=0
fi
if ! _is_num "$KGIT_SUB_RELEASE_NUM"; then
KGIT_SUB_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 [[ $KPREMERGEWINDOW ]]; then
if [[ ! $KTAGRELEASE ]]; then
KPATCHLEVEL=$(( KPATCHLEVEL + 1 ))
KEXTRAVERSION="rc0"
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() {
local gitref=$1 localversion=$2
local krelease
case $localversion in
+* | '' ) localversion=${localversion#+} ;;
*) die "Unexpected LOCALVERSION '$localversion', run dist-check-configs for more info."
esac
_prepare_kernel_ver "$gitref"
if [[ $KSNAPRELEASE ]]; then
# For snpashot version, it should start with 0. and
# KEXTRAVERSION will be appended at the tail of git info.
krelease=0.$KGIT_SNAPSHOT
[[ ${KEXTRAVERSION:-0} != "0" ]] && krelease=$krelease.$KEXTRAVERSION
# Release numbers will be appended too if available as a version hint for users.
[[ ${KGIT_RELEASE_NUM:-0} != "0" ]] && krelease=$krelease.$KGIT_RELEASE_NUM
[[ ${KGIT_SUB_RELEASE_NUM:-0} != "0" ]] && krelease=$krelease.$KGIT_SUB_RELEASE_NUM
elif [[ $KTESTRELEASE ]]; then
# For test tag, use the most recent release tag we can find and
# append the test suffix.
krelease=0
[[ ${KEXTRAVERSION:-0} != "0" ]] && krelease=$krelease.$KEXTRAVERSION
[[ $KGIT_LATEST_TAG_RELEASE_INFO ]] && krelease=$krelease.$KGIT_LATEST_TAG_RELEASE_INFO.$KGIT_TESTBUILD_TAG
else
if [[ $KTAGRELEASE ]]; then
# If the git tag matches all release info, respect it.
krelease=$KGIT_TAG_RELEASE_INFO
else
# Upstream or unknown, set release to start with "0."
# so it can be updated easily later.
# And if it's a rc release, use "0.0" to ensure it have
# lower priority.
if [[ "$KRCRELEASE" ]]; then
krelease=0.0
else
krelease=0.1
fi
fi
# If KEXTRAVERSION is not number it will break the release syntax
# if added as prefix, add as suffix in such case
if [[ $KEXTRAVERSION ]]; then
if _is_num "${KEXTRAVERSION%%.*}"; then
krelease="$KEXTRAVERSION.$krelease"
else
krelease="$krelease.$KEXTRAVERSION"
fi
fi
fi
case $krelease in
*.* )
;;
*)
krelease=0.$krelease
;;
esac
KERNEL_NAME="kernel${KDIST:+-$KDIST}"
if [[ $localversion ]]; then
KERNEL_NAME="$KERNEL_NAME-$localversion"
fi
KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
KERNEL_RELVER="$krelease"
KERNEL_UNAMER_BASE="$KERNEL_MAJVER-$KERNEL_RELVER${KDIST:+.$KDIST}"
if [[ $KFORCEUNAMER ]] && [[ $KGIT_TAG_RELEASE_INFO_RAW ]]; then
KERNEL_UNAMER_FORCE="$KERNEL_MAJVER$KGIT_TAG_RELEASE_INFO_RAW"
if [[ $localversion ]]; then
KERNEL_UNAMER_FORCE="$KERNEL_UNAMER_FORCE+$localversion"
fi
fi
}
### 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
# TK4 left-pads the release number with 0
KGIT_RELEASE_NUM=$(echo "$KGIT_RELEASE_NUM" | sed 's/^0*//')
krelease=$((KGIT_RELEASE_NUM + 1))
if [[ $KEXTRAVERSION ]]; then
if _is_num "${KEXTRAVERSION%%.*}"; then
krelease="$KEXTRAVERSION.$krelease"
else
krelease="$krelease.$KEXTRAVERSION"
fi
fi
KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
KERNEL_RELVER="$krelease"
KERNEL_UNAMER="$KERNEL_MAJVER-$KERNEL_RELVER${KDIST:+.$KDIST}"
}
# 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
KGIT_RELEASE_NUM=$(echo "$KGIT_RELEASE_NUM" | sed 's/^0*//')
krelease=$KGIT_RELEASE_NUM
krelease=$krelease.$((KGIT_SUB_RELEASE_NUM + 1))
if [[ $KEXTRAVERSION ]]; then
if _is_num "${KEXTRAVERSION%%.*}"; then
krelease="$KEXTRAVERSION.$krelease"
else
krelease="$krelease.$KEXTRAVERSION"
fi
fi
KERNEL_MAJVER="$KVERSION.$KPATCHLEVEL.$KSUBLEVEL"
KERNEL_RELVER="$krelease"
KERNEL_UNAMER="$KERNEL_MAJVER-$KERNEL_RELVER${KDIST:+.$KDIST}"
}

198
dist/scripts/lib.sh vendored Executable file
View File

@ -0,0 +1,198 @@
#!/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 "$@" >&2
}
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
}
# $1: relative dir path
# $2: optional git ref, if not set current worktree is used
# $3: optional git repo
ls_repo_dir() {
local _path=$1
local _gitref=$2
local _repo=${3:-$TOPDIR}
local _gitshow
# If git reference is set and git repo is valid, try use the versioned Makefile
if [[ "$_gitref" ]]; then
if _gitshow=$(git -C "$_repo" show "$_gitref:$_path" 2>/dev/null); then
echo "$_gitshow" | tail -n +3
return 0
fi
warn "Failed to ls '$_path' from git reference '$_gitref', using current worktree as build source."
fi
ls -1ap "$_repo/$_path/"
}
# $1: relative file path
# $2: optional git ref, if not set current worktree is used
# $3: optional git repo
cat_repo_file() {
local _path=$1
local _gitref=$2
local _repo=${3:-$TOPDIR}
# If git reference is set and git repo is valid, try use the versioned Makefile
if [[ "$_gitref" ]]; then
if git -C "$_repo" show "$_gitref:$_path" 2>/dev/null; then
return 0
fi
warn "Failed to retrive '$_path' from git reference '$_gitref', using current worktree as build source."
fi
cat "$_repo"/"$1"
}
# $1: keyword
# $2: optional git ref, if not set current Makefile is used
# $3: optional git repo
get_makefile_var() {
local _val
local _sedexp="/^${1}[[:space:]]*[:?]?=[[:space:]]*(.*)/{s/^${1}[[:space:]]*[:?]?=[[:space:]]*//;h;};\${x;p;}"
_val=$(sed -nE -e "$_sedexp")
case $_val in
*\$* )
die "Can't parse Makefile variable '$1', it references to other variables."
;;
esac
echo "$_val"
}
# $1: keyword
# $2: optional git ref, if not set current Makefile is used
# $3: optional git repo
get_dist_makefile_var() {
local _var=$1
local _gitref=$2
cat_repo_file "dist/Makefile" "$_gitref" | get_makefile_var "$1"
}
[ "$TOPDIR" ] || TOPDIR=$(git rev-parse --show-toplevel 2>/dev/null)
[ "$TOPDIR" ] || TOPDIR="$(realpath "$(dirname "$(realpath "$0")")/../..")"
[ "$DISTPATH" ] || DISTPATH=$(get_dist_makefile_var DISTPATH)
[ -s "$DISTPATH/.distenv" ] && source "$DISTPATH/.distenv"
[ "$DISTDIR" ] || DISTDIR=$TOPDIR/$DISTPATH
[ "$SOURCEDIR" ] || SOURCEDIR=$DISTDIR/rpm/SOURCES
[ "$SPEC_ARCH" ] || SPEC_ARCH=$(get_dist_makefile_var SPEC_ARCH)
# Meta values, if not set read from dist Makefile. (If set to empty, respect the empty value)
[ "${KDIST--}" == - ] && KDIST=$(get_dist_makefile_var KDIST)
[ "${VENDOR--}" == - ] && VENDOR=$(get_dist_makefile_var VENDOR)
[ "${URL--}" == - ] && URL=$(get_dist_makefile_var URL)
if [ "$(echo "$VENDOR_CAPITALIZED" | tr '[:upper:]' '[:lower:]')" != "$(echo "$VENDOR" | tr '[:upper:]' '[:lower:]')" ]; then
VENDOR_CAPITALIZED=$(echo "$VENDOR" | sed 's/./\U&/')
info "Overriding VENDOR_CAPITALIZED to '$VENDOR_CAPITALIZED'"
fi
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"
;;
loongarch64 )
echo "loongarch"
;;
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
loongarch64 )
echo "loongarch"
;;
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'

17
dist/scripts/ls-config-files.sh vendored Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash --norc
#
# List files to be generated for kernel config styles
#
# Params:
# $@: [ <filter>... ] When non-empty, only show kernel configs style matching <filter>
# 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 "$@"

15
dist/scripts/ls-config-targets.sh vendored Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash --norc
#
# List available kernel config styles
#
# Params:
# $@: [ <filter>... ] When non-empty, only show kernel configs style matching <filter>
# shellcheck source=./lib-config.sh
. "$(dirname "$(realpath "$0")")/lib-config.sh"
_echo() {
echo "$1" 2>/dev/null || exit 0
}
for_each_config_target _echo "$@"

131
dist/scripts/make-release.sh vendored Executable file
View File

@ -0,0 +1,131 @@
#!/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"
;;
--maj-release)
prepare_next_kernel_ver "$COMMIT" "$TOPDIR" || die "Failed preparing next release version info"
;;
*)
die "Invalid param $1, usage $0 {--maj-release|--sub-release}"
;;
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"
if [[ "$KTAGRELEASE" ]]; then
warn "You are generating changelog from a tagged release commit, however changelog update"
warn "should be done before tagging a release, please be careful with what you are doing or fix your workflow."
prepare_kernel_ver "$COMMIT"
fi
if [[ -z "$GITLOG" ]]; then
error "No change found since last tag, using dummy changelog."
GITLOG="- Accumulated bug fix and improvements."
fi
AUTHOR="$AUTHOR_NAME <$AUTHOR_MAIL>"
RELEASE_VERSION="$KERNEL_MAJVER-$KERNEL_RELVER"
TAG_VERSION="$KERNEL_UNAMER_BASE"
CHANGELOG_HDR="* $(date +"%a %b %e %Y") $AUTHOR - $RELEASE_VERSION"
CHANGELOG="$(echo "$GITLOG" | sed -E "s/^\S+/-/g")"
print_preview() {
cat << EOF
Please review following info:
Tag: ${TAG_VERSION:-<skipped>}
Release Version: $RELEASE_VERSION
Release Author: $AUTHOR
Changelog:
$CHANGELOG_HDR
$CHANGELOG
EOF
}
print_info() {
cat << EOF
Please review following info:
!!! DO NOT CHANGE THE FILE FORMAT !!!
// You can set "Tag:" to empty to skip tagging.
// but it's strongly recommended to tag after changlog update, to make versioning more consistent.
Tag: $TAG_VERSION
Release Version: $RELEASE_VERSION
Release Author: $AUTHOR
Changelog:
* $(date +"%a %b %e %Y") <Author> - <Release Version>"
$CHANGELOG
EOF
}
dump_info() {
print_info > "$DISTDIR/.release.stash"
}
update_info() {
${EDITOR:-vi} "$DISTDIR/.release.stash" >/dev/tty
[[ $? -eq 0 ]] || 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" | tail -n +2)
CHANGELOG_HDR="* $(date +"%a %b %e %Y") $AUTHOR - $RELEASE_VERSION"
}
while :; do
_res="?"
while :; do
{
print_preview
echo
echo "(Press 'q' to exit preview, Press 'e' to edit above info, Press 'y' to commit.)"
} | 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 )
info "Updating spec changelog and tagging HEAD... "
echo "$CHANGELOG_HDR" >> "$DISTDIR/templates/changelog.new"
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"
if [[ $TAG_VERSION ]]; then
if ! git -C "$TOPDIR" tag "$TAG_VERSION"; then
error "Failed to tag '$TAG_VERSION', this tag may already exists."
error "Changelog update should be done before tagging a release, so you may either use dist-new-release to tag, or fix the tag later manually."
fi
else
warn "Please ensure a tag corresponding to '$RELEASE_VERSION' is added to repo to make changelog consistent."
fi
exit 0
;;
e|E )
dump_info
update_info
parse_info
;;
esac
done
done

0
dist/sources/README vendored Normal file
View File

156
dist/sources/check-kabi vendored Executable file
View File

@ -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 <jcm@redhat.com>
# 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 <jcm@redhat.com>"
__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)

3
dist/sources/cpupower.config vendored Normal file
View File

@ -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"

13
dist/sources/cpupower.service vendored Normal file
View File

@ -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

186
dist/sources/filter-modules.sh vendored Executable file
View File

@ -0,0 +1,186 @@
#!/bin/bash
#
# Used Fedora kernel-ark repo as reference.
#
# Called as filter-modules.sh <depmod base path> <kernel version> <arch> <System.map>
#
# 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-<arch>.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"
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 cifs"
# Overrides is individual modules which need to remain in kernel-core due to deps.
overrides="cec wmi"
BASE_DIR=$1
KERNEL_UNAMER=$2
ARCH=$3
SYSTEM_MAP=$(realpath "$4")
MODULEPKG=$5
MODULE_DIR=lib/modules/$KERNEL_UNAMER
# Some distro will hide /sbin for non-root user but we need depmod to work.
# depmod can work well without root permission in dry-run mode.
PATH=$PATH:/usr/sbin:/sbin
error() {
echo "filter-modules.sh: $*" >&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
}
# Check if modules dependency are still sane after splitting these mods out
# args: moduled to be spliited out
check_modules_dependency_after_split() {
# 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
# Move the mods back
for mod in $modules_list; do
mv "$mod.bak" "$mod"
done
}
# Modules override for differnet arch
case $ARCH in
aarch64 )
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 cifs"
;;
riscv64 )
;;
loongarch64 )
;;
x86_64 )
;;
* )
error "Unknown arch '$ARCH'"
;;
esac
# Filter for split and verify
case $MODULEPKG in
non-core-modules )
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"
;;
* )
error "Invalid module packaging param '$1'"
exit 1
;;
esac
# Ensure this packaging splitting won't break core modules dependency
check_modules_dependency_after_split
# Print the modules_list after sort, and prepend /lib/modules/<KERNEL_UNAMER>/ to each line
echo "%dir /lib/modules/$KERNEL_UNAMER/"
echo "$modules_list" | sort -n | sed "/^$/d;s/^/\/${MODULE_DIR//\//\\\/}\//"
exit 0

42
dist/sources/module-keygen.sh vendored Executable file
View File

@ -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."

78
dist/sources/module-signer.sh vendored Executable file
View File

@ -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."

2
dist/templates/changelog vendored Normal file
View File

@ -0,0 +1,2 @@
* Mon Mar 14 2022 Kairui Song <kasong@tencent.com> - 5.17.0-0.20220314git47581bb4d9ae.rc7-tks
- Initial release

1423
dist/templates/kernel.template.spec vendored Normal file

File diff suppressed because it is too large Load Diff