summaryrefslogtreecommitdiff
path: root/kernel.spec
diff options
context:
space:
mode:
Diffstat (limited to 'kernel.spec')
-rw-r--r--kernel.spec1277
1 files changed, 1172 insertions, 105 deletions
diff --git a/kernel.spec b/kernel.spec
index c9a9371..ec5cd99 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -1,132 +1,1199 @@
-# kernel 6.18.50 (upstream: gregkh/linux tag v6.18.50)
-# topdir: linux-6.18.50 (确认方式: tar tf linux-6.18.50.tar.xz | head -1)
+%define with_signmodules 1
+%define with_kabichk 0
+
+# Default without toolchain_clang
+%bcond_with toolchain_clang
+
+%if %{with toolchain_clang}
+%global toolchain clang
+%endif
+
+%bcond_with clang_lto
+
+%if %{with clang_lto} && "%{toolchain}" != "clang"
+%{error:clang_lto requires --with toolchain_clang}
+%endif
+
+%define modsign_cmd %{SOURCE10}
+
+%if 0%{?openEuler_sign_rsa}
+# Use the open-source signature when the EBS permission is insufficient.
+# Now only the admin user in EBS can send the signature request. But the
+# user triggering the acces control build task and the personal build
+# task is non-admin. Inorder to avoid build failures caused by failed
+# signing, use the open-source signature.
+# The flag_openEuler_has_sign_perm used in the rpm execution phase
+# The openEuler_has_sign_perm used in the rpm execution phase
+
+%define openEuler_check_EBS_perm openEuler_has_sign_perm=0 \
+echo "" >> test_openEuler_sign.ko \
+sh /usr/lib/rpm/brp-ebs-sign --module test_openEuler_sign.ko || \
+[ $? -ne 2 ] && openEuler_has_sign_perm=1 \
+%global flag_openEuler_has_sign_perm $openEuler_has_sign_perm \
+rm -f test_openEuler_sign.ko test_openEuler_sign.ko.sig
+%endif
+
+%global Arch $(echo %{_host_cpu} | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e s/aarch64.*/arm64/ -e s/riscv.*/riscv/ -e s/powerpc64le/powerpc/ -e s/loongarch64/loongarch/)
+
+%global KernelVer %{version}-%{release}.%{_target_cpu}
+%global debuginfodir /usr/lib/debug
+
+%global upstream_version 7.3
+%global upstream_sublevel 0
+%global devel_release 0
+%global maintenance_release .0.0
+%global pkg_release .17
+
+%global openeuler_lts 0
+%global openeuler_major 0
+%global openeuler_minor 0
+
#
-# 构建说明: 内核使用 Makefile/Kbuild 构建(无 CMake/meson/autotools),
-# 本 spec 以 x86_64 defconfig 为基准构建 bzImage + modules,
-# 关闭调试信息 / BTF / 模块签名以缩短构建时间并避免依赖外部密钥。
-
-%global debug_package %{nil}
-%global _build_id_links none
-%global _missing_build_ids_terminate_build 0
-# 内核模块不是普通共享库,跳过 rpm 的 strip / find-requires / find-provides 后处理
-%global __os_install_post %{nil}
-%global __find_provides %{nil}
-%global __find_requires %{nil}
-# SRPM 内的裸 tarball 已 xz 压缩,payload 用最快档,避免重复压缩耗时
-%global _source_payload w0.gzdio
-%global _binary_payload w3.zstdio
-
-# 各架构最终内核镜像路径(%build 生成的同名产物)
-%ifarch x86_64
-%global kernel_image arch/x86/boot/bzImage
+# Support input parameter to overwrite the preceding version numbers.
+#
+
+%bcond_with openeuler_version
+
+%if %{with openeuler_version}
+%global openeuler_lts %{?_openeuler_lts} %{?!_openeuler_lts: 0}
+%global openeuler_major %{?_openeuler_major} %{?!_openeuler_major: 0}
+%global openeuler_minor %{?_openeuler_minor} %{?!_openeuler_minor: 0}
%endif
+
+%define with_debuginfo 1
+# Do not recompute the build-id of vmlinux in find-debuginfo.sh
+%global _missing_build_ids_terminate_build 1
+%global _no_recompute_build_ids 1
+%undefine _include_minidebuginfo
+%undefine _include_gdb_index
+%undefine _unique_build_ids
+
+%define with_source 1
+%define with_python2 0
+
+# failed if there is new config options
+%define listnewconfig_fail 1
+
%ifarch aarch64
-%global kernel_image arch/arm64/boot/Image
-%endif
-
-Name: kernel
-Version: 6.18.50
-Release: 1%{?dist}
-Summary: The Linux kernel
-License: GPL-2.0-only
-URL: https://github.com/gregkh/linux
-Source0: https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-%{version}.tar.xz
-
-BuildRequires: gcc
-BuildRequires: gcc-c++
-BuildRequires: binutils
-BuildRequires: make
-BuildRequires: bc
-BuildRequires: bison
-BuildRequires: flex
-BuildRequires: openssl
-BuildRequires: openssl-devel
-BuildRequires: elfutils-libelf-devel
-BuildRequires: perl
-BuildRequires: python3
-BuildRequires: rsync
-BuildRequires: tar
-BuildRequires: xz
-BuildRequires: gzip
-BuildRequires: bzip2
-BuildRequires: zstd
-BuildRequires: lz4
-BuildRequires: cpio
-BuildRequires: kmod
-BuildRequires: dwarves
-BuildRequires: hostname
-BuildRequires: diffutils
-BuildRequires: findutils
-BuildRequires: which
-BuildRequires: glibc-devel
-BuildRequires: ncurses-devel
-BuildRequires: ca-certificates
-
-Requires(post): kmod
-Requires(postun): kmod
+%define with_64kb %{?_with_64kb: 1} %{?!_with_64kb: 0}
+%if %{with_64kb}
+%global package64kb -64k
+%endif
+%else
+%define with_64kb 0
+%endif
+
+#default is enabled. You can disable it with --without option
+%define with_perf %{?_without_perf: 0} %{?!_without_perf: 1}
+
+Name: kernel%{?package64kb}
+Version: %{upstream_version}.%{upstream_sublevel}
+Release: %{devel_release}%{?maintenance_release}%{?pkg_release}
+Summary: Linux Kernel
+License: GPLv2
+URL: http://www.kernel.org/
+Source0: kernel.tar.gz
+Source10: sign-modules
+Source11: x509.genkey
+Source12: extra_certificates
+
+%if 0%{?openEuler_sign_rsa}
+Source15: openeuler_kernel_cert.cer
+Source16: sign-modules-openeuler
+%endif
+
+%if 0%{?with_kabichk}
+Source18: check-kabi
+Source20: Module.kabi_aarch64
+Source21: Module.kabi_x86_64
+%endif
+
+Source200: mkgrub-menu-aarch64.sh
+
+Source2000: cpupower.service
+Source2001: cpupower.config
+
+Source3000: kernel-aarch64.config
+Source3001: kernel-x86_64.config
+Source3002: kernel-riscv64.config
+
+%if 0%{?with_patch}
+Source9000: apply-patches
+Source9001: guards
+Source9002: series.conf
+Source9998: patches.tar.bz2
+%endif
+
+#BuildRequires:
+BuildRequires: module-init-tools, patch >= 2.5.4, bash >= 2.03, tar
+BuildRequires: bzip2, xz, findutils, gzip, m4, perl, make >= 3.78, diffutils, gawk
+BuildRequires: libcap-devel, libcap-ng-devel, rsync
+BuildRequires: gcc >= 3.4.2, binutils >= 2.12
+BuildRequires: hostname, net-tools, bc
+BuildRequires: xmlto, asciidoc
+BuildRequires: openssl-devel openssl
+BuildRequires: libkcapi
+BuildRequires: ncurses-devel
+#BuildRequires: pesign >= 0.109-4
+BuildRequires: elfutils-libelf-devel
+BuildRequires: rpm >= 4.14.2
+#BuildRequires: sparse >= 0.4.1
+%if 0%{?with_python2}
+BuildRequires: python-devel
+%endif
+
+BuildRequires: elfutils-devel zlib-devel binutils-devel newt-devel perl(ExtUtils::Embed) bison
+BuildRequires: audit-libs-devel libpfm-devel libtraceevent-devel
+BuildRequires: pciutils-devel gettext
+BuildRequires: rpm-build, elfutils
+BuildRequires: numactl-devel python3-devel glibc-static python3-docutils
+BuildRequires: perl-generators perl(Carp) libunwind-devel gtk2-devel libbabeltrace-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel perl-devel
+
+AutoReq: no
+AutoProv: yes
+
+Conflicts: device-mapper-libs < 1.02.63-2 e2fsprogs < 1.37-4 initscripts < 7.23 iptables < 1.3.2-1
+Conflicts: ipw2200-firmware < 2.4 isdn4k-utils < 3.2-32 iwl4965-firmware < 228.57.2 jfsutils < 1.1.7-2
+Conflicts: mdadm < 3.2.1-5 nfs-utils < 1.0.7-12 oprofile < 0.9.1-2 ppp < 2.4.3-3 procps < 3.2.5-6.3
+Conflicts: reiserfs-utils < 3.6.19-2 selinux-policy-targeted < 1.25.3-14 squashfs-tools < 4.0
+Conflicts: udev < 063-6 util-linux < 2.12 wireless-tools < 29-3 xfsprogs < 2.6.13-4
+
+Provides: %{name}-%{_target_cpu} = %{version}-%{release} %{name}-drm = 4.3.0 %{name}-drm-nouveau = 16 %{name}-modeset = 1
+Provides: %{name}-uname-r = %{KernelVer} %{name}=%{KernelVer}
+
+Requires: dracut >= 001-7 grubby >= 8.28-2 initscripts >= 8.11.1-1 linux-firmware >= 20100806-2 module-init-tools >= 3.16-2
+
+ExclusiveArch: noarch aarch64 i686 x86_64 riscv64 ppc64le loongarch64
+ExclusiveOS: Linux
+
+%if %{with_perf}
+BuildRequires: flex xz-devel libzstd-devel
+BuildRequires: java-devel
+%ifarch aarch64
+BuildRequires: OpenCSD
+%endif
+%endif
+
+BuildRequires: dwarves
+BuildRequires: clang >= 10.0.0
+BuildRequires: llvm
+BuildRequires: llvm-devel
+%if %{with clang_lto}
+BuildRequires: lld
+%endif
%description
-The Linux kernel, version %{version}, built from the upstream stable tree
-(gregkh/linux tag v%{version}). This package provides the kernel image
-(bzImage), the in-tree modules, the kernel configuration and System.map.
+The Linux Kernel, the operating system core itself.
+
+%package headers
+Summary: Header files for the Linux kernel for use by glibc
+Obsoletes: glibc-kernheaders < 3.0-46
+Provides: glibc-kernheaders = 3.0-46
+%description headers
+Kernel-headers includes the C header files that specify the interface
+between the Linux kernel and userspace libraries and programs. The
+header files define structures and constants that are needed for
+building most standard programs and are also needed for rebuilding the
+glibc package.
+
+
+%package devel
+Summary: Development package for building kernel modules to match the %{KernelVer} kernel
+AutoReqProv: no
+Provides: %{name}-devel-uname-r = %{KernelVer}
+Provides: %{name}-devel-%{_target_cpu} = %{version}-%{release}
+Requires: perl findutils
+
+%description devel
+This package provides kernel headers and makefiles sufficient to build modules
+against the %{KernelVer} kernel package.
+
+%package tools
+Summary: Assortment of tools for the Linux kernel
+Provides: %{name}-tools-libs
+Obsoletes: %{name}-tools-libs
+Provides: cpufreq-utils = 1:009-0.6.p1
+Provides: cpufrequtils = 1:009-0.6.p1
+Obsoletes: cpufreq-utils < 1:009-0.6.p1
+Obsoletes: cpufrequtils < 1:009-0.6.p1
+Obsoletes: cpuspeed < 1:1.5-16
+%description tools
+This package contains the tools/ directory from the kernel source
+and the supporting documentation.
+
+%package tools-devel
+Summary: Assortment of tools for the Linux kernel
+Requires: %{name}-tools = %{version}-%{release}
+Requires: %{name}-tools-libs = %{version}-%{release}
+Provides: %{name}-tools-libs-devel = %{version}-%{release}
+Obsoletes: %{name}-tools-libs-devel
+%description tools-devel
+This package contains the development files for the tools/ directory from
+the kernel source.
+
+%if %{with_perf}
+%package -n perf
+Summary: Performance monitoring for the Linux kernel
+%description -n perf
+This package contains the perf tool, which enables performance monitoring
+of the Linux kernel.
+
+%if 0%{?with_python2}
+%package -n python2-perf
+Provides: python-perf = %{version}-%{release}
+Obsoletes: python-perf
+Summary: Python bindings for apps which will manipulate perf events
+
+%description -n python2-perf
+A Python module that permits applications written in the Python programming
+language to use the interface to manipulate perf events.
+%endif
+
+%package -n python3-perf
+Summary: Python bindings for apps which will manipulate perf events
+%description -n python3-perf
+A Python module that permits applications written in the Python programming
+language to use the interface to manipulate perf events.
+# with_perf
+%endif
+
+%package -n bpftool
+Summary: Inspection and simple manipulation of eBPF programs and maps
+%description -n bpftool
+This package contains the bpftool, which allows inspection and simple
+manipulation of eBPF programs and maps.
+
+%package source
+Summary: the kernel source
+%description source
+This package contains vaious source files from the kernel.
+
+%if 0%{?with_debuginfo}
+%define _debuginfo_template %{nil}
+%define _debuginfo_subpackages 0
+
+%define debuginfo_template(n:) \
+%package -n %{-n*}-debuginfo\
+Summary: Debug information for package %{-n*}\
+Group: Development/Debug\
+AutoReq: 0\
+AutoProv: 1\
+%description -n %{-n*}-debuginfo\
+This package provides debug information for package %{-n*}.\
+Debug information is useful when developing applications that use this\
+package or when debugging this package.\
+%{nil}
+
+%debuginfo_template -n %{name}
+%files -n %{name}-debuginfo -f kernel-debugfiles.list -f debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} --keep-section '.BTF' -p '.*/%{KernelVer}/.*|.*/vmlinux|XXX' -o kernel-debugfiles.list}
+
+%debuginfo_template -n bpftool
+%files -n bpftool-debuginfo -f bpftool-debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%{_sbindir}/bpftool.*(\.debug)?|XXX' -o bpftool-debugfiles.list}
+
+%debuginfo_template -n %{name}-tools
+%files -n %{name}-tools-debuginfo -f kernel-tools-debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%{_bindir}/centrino-decode.*(\.debug)?|.*%{_bindir}/powernow-k8-decode.*(\.debug)?|.*%{_bindir}/cpupower.*(\.debug)?|.*%{_libdir}/libcpupower.*|.*%{_libdir}/libcpupower.*|.*%{_bindir}/turbostat.(\.debug)?|.*%{_bindir}/.*gpio.*(\.debug)?|.*%{_bindir}/.*iio.*(\.debug)?|.*%{_bindir}/tmon.*(.debug)?|XXX' -o kernel-tools-debugfiles.list}
+
+%if %{with_perf}
+%debuginfo_template -n perf
+%files -n perf-debuginfo -f perf-debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%{_bindir}/perf.*(\.debug)?|.*%{_libexecdir}/perf-core/.*|.*%{_libdir}/traceevent/.*|XXX' -o perf-debugfiles.list}
+
+%if 0%{?with_python2}
+%debuginfo_template -n python2-perf
+%files -n python2-perf-debuginfo -f python2-perf-debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%{python2_sitearch}/perf.*(.debug)?|XXX' -o python2-perf-debugfiles.list}
+%endif
+
+%debuginfo_template -n python3-perf
+%files -n python3-perf-debuginfo -f python3-perf-debugfiles.list
+%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%{python3_sitearch}/perf.*(.debug)?|XXX' -o python3-perf-debugfiles.list}
+#with_perf
+%endif
+
+%endif
%prep
-%autosetup -n linux-%{version}
+%setup -q -n %{name}-%{version} -c
-%build
-# 目标架构默认配置
-make defconfig
-
-# 精简构建:关闭调试信息 / BTF / 模块签名 / WERROR,避免构建期依赖外部密钥与
-# 新版 pahole,并显著缩短构建时间(gcc 12.3.1 下 -Werror 风险高)
-for opt in DEBUG_INFO DEBUG_INFO_DWARF5 DEBUG_INFO_BTF DEBUG_INFO_BTF_MODULES \
- GDB_SCRIPTS MODULE_SIG MODULE_SIG_ALL MODULE_COMPRESS WERROR \
- LOCALVERSION_AUTO; do
- ./scripts/config --file .config -d "$opt" || :
-done
-./scripts/config --file .config --set-str SYSTEM_TRUSTED_KEYS "" || :
-make olddefconfig
+%if 0%{?with_patch}
+tar -xjf %{SOURCE9998}
+%endif
+
+mv kernel linux-%{KernelVer}
+cd linux-%{KernelVer}
+
+%if 0%{?with_patch}
+cp %{SOURCE9000} .
+cp %{SOURCE9001} .
+cp %{SOURCE9002} .
-if grep -q '^CONFIG_DEBUG_INFO=y' .config; then
- echo "ERROR: failed to disable CONFIG_DEBUG_INFO" >&2
- exit 1
+if [ ! -d patches ];then
+ mv ../patches .
fi
-echo "[kernel] kernelrelease = $(make -s kernelrelease)"
-test "$(make -s kernelrelease)" = "%{version}"
+Applypatches()
+{
+ set -e
+ set -o pipefail
+ local SERIESCONF=$1
+ local PATCH_DIR=$2
+ sed -i '/^#/d' $SERIESCONF
+ sed -i '/^[\s]*$/d' $SERIESCONF
+ (
+ echo "trap 'echo \"*** patch \$_ failed ***\"' ERR"
+ echo "set -ex"
+ cat $SERIESCONF | \
+ sed "s!^!patch -s -F0 -E -p1 --no-backup-if-mismatch -i $PATCH_DIR/!" \
+ ) | sh
+}
-%ifarch x86_64
-make %{?_smp_mflags} bzImage modules
+Applypatches series.conf %{_builddir}/%{name}-%{version}/linux-%{KernelVer}
%endif
+
+# riscv-kernel patch
+%ifarch riscv64
+%endif
+
+%if "%toolchain" == "clang"
+%endif
+
+find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null
+find . -name .gitignore -exec rm -f {} \; >/dev/null
+
+%if 0%{?with_source}
+# Copy directory backup for kernel-source
+cp -a ../linux-%{KernelVer} ../linux-%{KernelVer}-source
+find ../linux-%{KernelVer}-source -type f -name "\.*" -exec rm -rf {} \; >/dev/null
+%endif
+
+cp -a tools/perf tools/python3-perf
+
+%build
+cd linux-%{KernelVer}
+
+perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}.%{_target_cpu}/" Makefile
+
+%if %{with openeuler_version}
+perl -p -i -e "s/^OPENEULER_LTS.*/OPENEULER_LTS = %{openeuler_lts}/" Makefile.oever
+perl -p -i -e "s/^OPENEULER_MAJOR.*/OPENEULER_MAJOR = %{openeuler_major}/" Makefile.oever
+perl -p -i -e "s/^OPENEULER_MINOR.*/OPENEULER_MINOR = %{openeuler_minor}/" Makefile.oever
+perl -p -i -e "s/^OPENEULER_RELEASE.*/OPENEULER_RELEASE = \"%{release}\"/" Makefile.oever
+%endif
+
+## make linux
+make mrproper %{_smp_mflags}
+
+%if 0%{?with_signmodules}
+ cp %{SOURCE11} certs/.
+%endif
+
+%if %{listnewconfig_fail}
+%ifarch aarch64 x86_64
+ cp $RPM_SOURCE_DIR/kernel-%{_host_cpu}.config .config
+ make ARCH=%{Arch} listnewconfig > .newconfig.list 2>/dev/null
+ if grep -q '^CONFIG_' .newconfig.list; then
+ echo "ERROR: new Kconfig options not set in kernel-%{_host_cpu}.config"
+ echo "Please review each option and set it to an appropriate value"
+ echo "(y/m/n), then update the config before building. New options"
+ echo "and their defaults:"
+ cat .newconfig.list
+ exit 1
+ fi
+ rm -f .config .newconfig.list
+%endif
+%endif
+
+%ifnarch loongarch64
+cp $RPM_SOURCE_DIR/kernel-%{_host_cpu}.config arch/%{Arch}/configs/openeuler_defconfig
+%endif
+
+%if %{with_64kb}
+sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_4K_PAGES.*/CONFIG_ARM64_64K_PAGES=y/'
+sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_PA_BITS=.*/CONFIG_ARM64_PA_BITS=52/'
+sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_PA_BITS_.*/CONFIG_ARM64_PA_BITS_52=y/'
+sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_VA_BITS=.*/CONFIG_ARM64_VA_BITS=52/'
+sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_VA_BITS_.*/CONFIG_ARM64_VA_BITS_52=y/'
+%endif
+
+%if "%toolchain" == "clang"
+
+%ifarch s390x ppc64le
+%global llvm_ias 0
+%else
+%global llvm_ias 1
+%endif
+
+%global clang_make_opts HOSTCC=clang CC=clang LLVM_IAS=%{llvm_ias}
+
+%if %{with clang_lto}
+%global clang_make_opts %{clang_make_opts} HOSTLD=ld.lld LD=ld.lld AR=llvm-ar NM=llvm-nm HOSTAR=llvm-ar HOSTNM=llvm-nm
+%endif
+
+%endif
+
+%global make %{__make} %{?clang_make_opts} HOSTCFLAGS="%{?build_cflags}" HOSTLDFLAGS="%{?build_ldflags}"
+
+%ifarch loongarch64
+echo "CONFIG_DEBUG_INFO_BTF=y" >> arch/loongarch/configs/loongson3_defconfig
+echo "CONFIG_DEBUG_INFO=y" >>arch/loongarch/configs/loongson3_defconfig
+echo "CONFIG_DEBUG_INFO_DWARF5=y" >>arch/loongarch/configs/loongson3_defconfig
+sed -i 's/CONFIG_MODULE_COMPRESS=y/# CONFIG_MODULE_COMPRESS is not set/g' arch/loongarch/configs/loongson3_defconfig
+
+%if 0%{with_signmodules}
+echo "CONFIG_MODULE_SIG=y" >> arch/loongarch/configs/loongson3_defconfig
+%endif
+
+make ARCH=%{Arch} loongson3_defconfig
+
+%else
+%{make} ARCH=%{Arch} openeuler_defconfig
+%endif
+
+%if %{with clang_lto}
+scripts/config -e LTO_CLANG_FULL
+sed -i 's/# CONFIG_LTO_CLANG_FULL is not set/CONFIG_LTO_CLANG_FULL=y/' .config
+sed -i 's/CONFIG_LTO_NONE=y/# CONFIG_LTO_NONE is not set/' .config
+%endif
+
+%if 0%{?openEuler_sign_rsa}
+ %{openEuler_check_EBS_perm}
+ if [ $openEuler_has_sign_perm -eq 1 ]; then
+ cp %{SOURCE15} ./certs/openeuler-cert.pem
+ # close kernel native signature
+ sed -i 's/CONFIG_MODULE_SIG_KEY=.*$/CONFIG_MODULE_SIG_KEY=""/g' .config
+ sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS=.*$/CONFIG_SYSTEM_TRUSTED_KEYS="certs\/openeuler-cert.pem"/g' .config
+ sed -i 's/CONFIG_MODULE_SIG_ALL=y$/CONFIG_MODULE_SIG_ALL=n/g' .config
+ fi
+%endif
+
+TargetImage=$(basename $(make -s image_name))
+
+%{make} ARCH=%{Arch} $TargetImage %{?_smp_mflags}
+%ifarch loongarch64
+%{make} ARCH=%{Arch} vmlinuz.efi %{?_smp_mflags}
+%endif
+%{make} ARCH=%{Arch} modules %{?_smp_mflags}
+
+%if 0%{?with_kabichk}
+ chmod 0755 %{SOURCE18}
+ if [ -e $RPM_SOURCE_DIR/Module.kabi_%{_target_cpu} ]; then
+ %{SOURCE18} -k $RPM_SOURCE_DIR/Module.kabi_%{_target_cpu} -s Module.symvers || exit 1
+ else
+ echo "**** NOTE: Cannot find reference Module.kabi file. ****"
+ fi
+%endif
+
+# aarch64 make dtbs
+%ifarch aarch64 riscv64
+ %{make} ARCH=%{Arch} dtbs
+%endif
+
+## make tools
+%if %{with_perf}
+# perf
%ifarch aarch64
-make %{?_smp_mflags} Image modules
+# aarch64 make perf with CORESIGHT=1
+%global perf_make \
+ LDFLAGS="-Wl,--no-as-needed -lstdc++ %{?build_ldflags}" make %{?clang_make_opts} EXTRA_LDFLAGS="%[ "%{toolchain}" == "clang" ? "-z now" : "" ]" EXTRA_CFLAGS="%[ "%{toolchain}" == "clang" ? "" : "-Wl,-z,now" ] -g -Wall -fstack-protector-strong -fPIC" EXTRA_PERFLIBS="-fpie" %{?_smp_mflags} -s V=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_LIBNUMA=1 NO_STRLCPY=1 CORESIGHT=1 prefix=%{_prefix}
+%else
+%global perf_make \
+ LDFLAGS="-Wl,--no-as-needed -lstdc++ %{?build_ldflags}" make %{?clang_make_opts} EXTRA_LDFLAGS="%[ "%{toolchain}" == "clang" ? "-z now" : "" ]" EXTRA_CFLAGS="%[ "%{toolchain}" == "clang" ? "" : "-Wl,-z,now" ] -g -Wall -fstack-protector-strong -fPIC" EXTRA_PERFLIBS="-fpie" %{?_smp_mflags} -s V=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_LIBNUMA=1 NO_STRLCPY=1 prefix=%{_prefix}
+%endif
+%if 0%{?with_python2}
+%global perf_python2 -C tools/perf PYTHON=%{__python2}
+%global perf_python3 -C tools/python3-perf PYTHON=%{__python3}
+%else
+%global perf_python3 -C tools/perf PYTHON=%{__python3}
+%endif
+
+chmod +x tools/perf/check-headers.sh
+# perf
+%if 0%{?with_python2}
+%{perf_make} %{perf_python2} all
+%endif
+
+# make sure check-headers.sh is executable
+chmod +x tools/python3-perf/check-headers.sh
+%{perf_make} %{perf_python3} all
+
+pushd tools/perf/Documentation/
+%{make} %{?_smp_mflags} man
+popd
%endif
+# bpftool
+pushd tools/bpf/bpftool
+%{make}
+popd
+
+# cpupower
+chmod +x tools/power/cpupower/utils/version-gen.sh
+%{make} %{?_smp_mflags} -C tools/power/cpupower CPUFREQ_BENCH=false
+%ifarch %{ix86}
+ pushd tools/power/cpupower/debug/i386
+ %{make} %{?_smp_mflags} centrino-decode powernow-k8-decode
+ popd
+%endif
+%ifarch x86_64
+ pushd tools/power/cpupower/debug/x86_64
+ %{make} %{?_smp_mflags} centrino-decode powernow-k8-decode
+ popd
+%endif
+%ifarch %{ix86} x86_64
+ pushd tools/power/x86/x86_energy_perf_policy/
+ %{make}
+ popd
+ pushd tools/power/x86/turbostat
+ %{make}
+ popd
+%endif
+# thermal
+pushd tools/thermal/tmon/
+%{make}
+popd
+# iio
+pushd tools/iio/
+%{make}
+popd
+# gpio
+pushd tools/gpio/
+%{make}
+popd
+# kvm
+pushd tools/kvm/kvm_stat/
+popd
+# libbpf.a and bpf_helper_defs.h
+pushd tools/lib/bpf
+%{make}
+popd
+
%install
-make modules_install INSTALL_MOD_PATH=%{buildroot} INSTALL_MOD_STRIP=1
+%if 0%{?with_source}
+ %define _python_bytecompile_errors_terminate_build 0
+ mkdir -p $RPM_BUILD_ROOT/usr/src/
+ mv linux-%{KernelVer}-source $RPM_BUILD_ROOT/usr/src/linux-%{KernelVer}
+ cp linux-%{KernelVer}/.config $RPM_BUILD_ROOT/usr/src/linux-%{KernelVer}/
+%endif
+
+cd linux-%{KernelVer}
+
+## install linux
+
+# deal with kernel-source, now we don't need kernel-source
+#mkdir $RPM_BUILD_ROOT/usr/src/linux-%{KernelVer}
+#tar cf - --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git --exclude=.tmp_versions --exclude=*vmlinux* --exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation --exclude=.config.old --exclude=.missing-syscalls.d --exclude=patches . | tar xf - -C %{buildroot}/usr/src/linux-%{KernelVer}
+
+mkdir -p $RPM_BUILD_ROOT/boot
+dd if=/dev/zero of=$RPM_BUILD_ROOT/boot/initramfs-%{KernelVer}.img bs=1M count=20
+
+%ifarch loongarch64
+strip -s vmlinux -o vmlinux.elf
+install -m 755 vmlinux.elf $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}
+install -m 755 arch/loongarch/boot/vmlinuz.efi $RPM_BUILD_ROOT/boot/efi-vmlinuz-%{KernelVer}
+%else
+install -m 755 $(make -s image_name) $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}
+%endif
+
+%if 0%{?openEuler_sign_rsa}
+ %{openEuler_check_EBS_perm}
+ if [ $openEuler_has_sign_perm -eq 1 ]; then
+ echo "start sign"
+ %ifarch %arm aarch64
+ gunzip -c $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}>$RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip.efi
+ sh /usr/lib/rpm/brp-ebs-sign --efi $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip.efi
+ mv $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip.efi.sig $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip.efi
+ mv $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip.efi $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip
+ gzip -c $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip>$RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}
+ rm -f $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.unzip
+ %endif
+ %ifarch x86_64
+ mv $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.efi
+ sh /usr/lib/rpm/brp-ebs-sign --efi $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.efi
+ mv $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.efi.sig $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.efi
+ mv $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}.efi $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer}
+ %endif
+ %ifarch loongarch64
+ sh /usr/lib/rpm/brp-ebs-sign --efi $RPM_BUILD_ROOT/boot/efi-vmlinuz-%{KernelVer}
+ mv $RPM_BUILD_ROOT/boot/efi-vmlinuz-%{KernelVer}.sig $RPM_BUILD_ROOT/boot/efi-vmlinuz-%{KernelVer}
+ %endif
+ fi
+%endif
+
+pushd $RPM_BUILD_ROOT/boot
+sha512hmac ./vmlinuz-%{KernelVer} >./.vmlinuz-%{KernelVer}.hmac
+popd
+
+install -m 644 .config $RPM_BUILD_ROOT/boot/config-%{KernelVer}
+install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-%{KernelVer}
+
+%if 0%{?with_kabichk}
+gzip -c9 < Module.symvers > $RPM_BUILD_ROOT/boot/symvers-%{KernelVer}.gz
+%endif
+
+mkdir -p $RPM_BUILD_ROOT%{_sbindir}
+install -m 755 %{SOURCE200} $RPM_BUILD_ROOT%{_sbindir}/mkgrub-menu-%{version}-%{devel_release}%{?maintenance_release}%{?pkg_release}.sh
+
+
+%if 0%{?with_debuginfo}
+ mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/%{KernelVer}
+ cp vmlinux $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/%{KernelVer}
+%endif
+
+# deal with module, if not kdump
+%{make} ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=%{KernelVer} mod-fw=
+######## to collect ko to module.filelist about netwoking. block. drm. modesetting ###############
+pushd $RPM_BUILD_ROOT/lib/modules/%{KernelVer}
+find -type f -name "*.ko" >modnames
+
+# mark modules executable so that strip-to-file can strip them
+xargs --no-run-if-empty chmod u+x < modnames
+
+# Generate a list of modules for block and networking.
+
+grep -F /drivers/ modnames | xargs --no-run-if-empty nm -upA |
+sed -n 's,^.*/\([^/]*\.ko\): *U \(.*\)$,\1 \2,p' > drivers.undef
+
+collect_modules_list()
+{
+ sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef |
+ LC_ALL=C sort -u > modules.$1
+ if [ ! -z "$3" ]; then
+ sed -r -e "/^($3)\$/d" -i modules.$1
+ fi
+}
+
+collect_modules_list networking \
+ 'register_netdev|ieee80211_register_hw|usbnet_probe|phy_driver_register|rt2x00(pci|usb)_probe|register_netdevice'
+collect_modules_list block \
+ 'ata_scsi_ioctl|scsi_add_host|scsi_add_host_with_dma|blk_alloc_queue|blk_init_queue|register_mtd_blktrans|scsi_esp_register|scsi_register_device_handler|blk_queue_physical_block_size|ahci_platform_get_resources' 'pktcdvd.ko|dm-mod.ko'
+collect_modules_list drm \
+ 'drm_open|drm_init'
+collect_modules_list modesetting \
+ 'drm_crtc_init'
+
+# detect missing or incorrect license tags
+rm -f modinfo
+while read i
+do
+ echo -n "$i " >> modinfo
+ /sbin/modinfo -l $i >> modinfo
+done < modnames
+
+grep -E -v \
+ 'GPL( v2)?$|Dual BSD/GPL$|Dual MPL/GPL$|GPL and additional rights$' \
+ modinfo && exit 1
+
+rm -f modinfo modnames drivers.undef
+
+for i in alias alias.bin builtin.bin ccwmap dep dep.bin ieee1394map inputmap isapnpmap ofmap pcimap seriomap symbols symbols.bin usbmap
+do
+ rm -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/modules.$i
+done
+popd
+# modsign module ko;need after find-debuginfo,strip
+%define __modsign_install_post \
+ if [ "%{with_signmodules}" -eq "1" ];then \
+ cp certs/signing_key.pem . \
+ cp certs/signing_key.x509 . \
+ chmod 0755 %{modsign_cmd} \
+ %{modsign_cmd} $RPM_BUILD_ROOT/lib/modules/%{KernelVer} || exit 1 \
+ fi \
+ find $RPM_BUILD_ROOT/lib/modules/ -type f -name '*.ko' | xargs -n1 -P`nproc --all` xz; \
+%{nil}
+
+%if 0%{?openEuler_sign_rsa}
+%define __modsign_install_post \
+ if [ "%{with_signmodules}" -eq "1" ];then \
+ if [ %flag_openEuler_has_sign_perm -eq 1 ]; then \
+ sh %{SOURCE16} $RPM_BUILD_ROOT/lib/modules/%{KernelVer} || exit 1 \
+ else \
+ cp certs/signing_key.pem . \
+ cp certs/signing_key.x509 . \
+ chmod 0755 %{modsign_cmd} \
+ %{modsign_cmd} $RPM_BUILD_ROOT/lib/modules/%{KernelVer} || exit 1 \
+ fi \
+ fi \
+ find $RPM_BUILD_ROOT/lib/modules/ -type f -name '*.ko' | xargs -n1 -P`nproc --all` xz; \
+%{nil}
+%endif
+
+# deal with header
+%{make} ARCH=%{Arch} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install
+find $RPM_BUILD_ROOT/usr/include -name "\.*" -exec rm -rf {} \;
+
+# dtbs install
+%ifarch aarch64 riscv64
+ mkdir -p $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}
+ install -m 644 $(find arch/%{Arch}/boot -name "*.dtb") $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/
+ rm -f $(find arch/%{Arch}/boot -name "*.dtb")
+%endif
+
+# deal with riscv SoC dtb search path
+%ifarch riscv64
+ mkdir -p $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/thead
+ mv $(find $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/ -name "th1520*.dtb") $RPM_BUILD_ROOT/boot/dtb-%{KernelVer}/thead
+%endif
+
+# deal with vdso
+%ifnarch ppc64le
+%{make} -s ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=%{KernelVer}
+%endif
+if [ ! -s ldconfig-kernel.conf ]; then
+ echo "# Placeholder file, no vDSO hwcap entries used in this kernel." >ldconfig-kernel.conf
+fi
+install -D -m 444 ldconfig-kernel.conf $RPM_BUILD_ROOT/etc/ld.so.conf.d/kernel-%{KernelVer}.conf
+
+# deal with /lib/module/ path- sub path: build source kernel
+rm -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build
+rm -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/source
+mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build
+mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/extra
+mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/updates
+mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/weak-updates
+############ to do collect devel file #########
+# 1. Makefile And Kconfig, .config sysmbol
+# 2. scrpits dir
+# 3. .h file
+find -type f \( -name "Makefile*" -o -name "Kconfig*" \) -exec cp --parents {} $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build \;
+for f in Module.symvers System.map Module.markers .config;do
+ test -f $f || continue
+ cp $f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build
+done
+
+cp -a scripts $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build
+if [ -d arch/%{Arch}/scripts ]; then
+ cp -a arch/%{Arch}/scripts $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/arch/%{_arch} || :
+fi
+if [ -f arch/%{Arch}/*lds ]; then
+ cp -a arch/%{Arch}/*lds $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/arch/%{_arch}/ || :
+fi
+find $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/scripts/ -name "*.o" -exec rm -rf {} \;
+
+if [ -d arch/%{Arch}/include ]; then
+ cp -a --parents arch/%{Arch}/include $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/
+fi
+cp -a include $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build
+
+if [ -f arch/%{Arch}/kernel/module.lds ]; then
+ cp -a --parents arch/%{Arch}/kernel/module.lds $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/
+fi
+
+# module.lds is moved to scripts by commit 596b0474d3d9 in linux 5.10.
+if [ -f scripts/module.lds ]; then
+ cp -a --parents scripts/module.lds $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/
+fi
+
+%ifarch aarch64
+ cp -a --parents arch/arm/include/asm $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/
+%endif
+
+# copy objtool for kernel-devel (needed for building external modules)
+if grep -q CONFIG_OBJTOOL=y .config; then
+ mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/tools/objtool
+ cp -a tools/objtool/objtool $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/tools/objtool
+fi
+
+# Make sure the Makefile and version.h have a matching timestamp so that
+# external modules can be built
+if [ -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/generated/uapi/linux/version.h ]; then
+ touch -r $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/Makefile $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/generated/uapi/linux/version.h
+fi
+if [ -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/generated/autoconf.h ]; then
+ touch -r $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/.config $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/generated/autoconf.h
+fi
+# for make prepare
+if [ ! -f $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/config/auto.conf ];then
+ mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/config
+ cp .config $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build/include/config/auto.conf
+fi
+
+mkdir -p %{buildroot}/usr/src/kernels
+mv $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/build $RPM_BUILD_ROOT/usr/src/kernels/%{KernelVer}
+
+find $RPM_BUILD_ROOT/usr/src/kernels/%{KernelVer} -name ".*.cmd" -exec rm -f {} \;
+
+pushd $RPM_BUILD_ROOT/lib/modules/%{KernelVer}
+ln -sf /usr/src/kernels/%{KernelVer} build
+ln -sf build source
+popd
+
+
+# deal with doc , now we don't need
-install -D -p -m 0755 %{kernel_image} %{buildroot}/boot/vmlinuz-%{version}
-install -D -p -m 0644 System.map %{buildroot}/boot/System.map-%{version}
-install -D -p -m 0644 .config %{buildroot}/boot/config-%{version}
-# 源码树符号链接指向构建目录,安装包中必须去掉
-rm -f %{buildroot}/lib/modules/%{version}/build \
- %{buildroot}/lib/modules/%{version}/source
+# deal with kernel abi whitelists. now we don't need
+
+
+## install tools
+%if %{with_perf}
+# perf
+# perf tool binary and supporting scripts/binaries
+%if 0%{?with_python2}
+%{perf_make} %{perf_python2} DESTDIR=%{buildroot} lib=%{_lib} install-bin
+%else
+%{perf_make} %{perf_python3} DESTDIR=%{buildroot} lib=%{_lib} install-bin
+%endif
+# remove the 'trace' symlink.
+rm -f %{buildroot}%{_bindir}/trace
+
+# remove examples
+rm -rf %{buildroot}/usr/lib/perf/examples
+# remove the stray header file that somehow got packaged in examples
+rm -rf %{buildroot}/usr/lib/perf/include/bpf/
+
+# python-perf extension
+%{perf_make} %{perf_python3} DESTDIR=%{buildroot} install-python_ext
+%if 0%{?with_python2}
+%{perf_make} %{perf_python2} DESTDIR=%{buildroot} install-python_ext
+%endif
+
+# perf man pages (note: implicit rpm magic compresses them later)
+install -d %{buildroot}/%{_mandir}/man1
+install -pm0644 tools/perf/Documentation/*.1 %{buildroot}/%{_mandir}/man1/
+%endif
+
+# bpftool
+pushd tools/bpf/bpftool
+%{make} DESTDIR=%{buildroot} prefix=%{_prefix} bash_compdir=%{_sysconfdir}/bash_completion.d/ mandir=%{_mandir} install doc-install
+popd
+
+# resolve_btfids
+mkdir -p %{buildroot}/usr/src/kernels/%{KernelVer}/tools/bpf/resolve_btfids
+cp tools/bpf/resolve_btfids/resolve_btfids %{buildroot}/usr/src/kernels/%{KernelVer}/tools/bpf/resolve_btfids
+
+# cpupower
+%{make} -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} CPUFREQ_BENCH=false install
+rm -f %{buildroot}%{_libdir}/*.{a,la}
+%find_lang cpupower
+mv cpupower.lang ../
+%ifarch %{ix86}
+ pushd tools/power/cpupower/debug/i386
+ install -m755 centrino-decode %{buildroot}%{_bindir}/centrino-decode
+ install -m755 powernow-k8-decode %{buildroot}%{_bindir}/powernow-k8-decode
+ popd
+%endif
+%ifarch x86_64
+ pushd tools/power/cpupower/debug/x86_64
+ install -m755 centrino-decode %{buildroot}%{_bindir}/centrino-decode
+ install -m755 powernow-k8-decode %{buildroot}%{_bindir}/powernow-k8-decode
+ popd
+%endif
+chmod 0755 %{buildroot}%{_libdir}/libcpupower.so*
+mkdir -p %{buildroot}%{_unitdir} %{buildroot}%{_sysconfdir}/sysconfig
+install -m644 %{SOURCE2000} %{buildroot}%{_unitdir}/cpupower.service
+install -m644 %{SOURCE2001} %{buildroot}%{_sysconfdir}/sysconfig/cpupower
+%ifarch %{ix86} x86_64
+ mkdir -p %{buildroot}%{_mandir}/man8
+ pushd tools/power/x86/x86_energy_perf_policy
+ %{make} DESTDIR=%{buildroot} install
+ popd
+ pushd tools/power/x86/turbostat
+ %{make} DESTDIR=%{buildroot} install
+ popd
+%endif
+# thermal
+pushd tools/thermal/tmon
+%{make} INSTALL_ROOT=%{buildroot} install
+popd
+# iio
+pushd tools/iio
+%{make} DESTDIR=%{buildroot} install
+popd
+# gpio
+pushd tools/gpio
+%{make} DESTDIR=%{buildroot} install
+popd
+# kvm
+pushd tools/kvm/kvm_stat
+%{make} INSTALL_ROOT=%{buildroot} install-tools
+popd
+
+# Install COPYING for kernel-tools and bpftool (%license workaround for RPM 4.18)
+install -d -m 755 %{buildroot}/usr/share/licenses/kernel-tools
+cp -a COPYING %{buildroot}/usr/share/licenses/kernel-tools/COPYING
+install -d -m 755 %{buildroot}/usr/share/licenses/bpftool
+cp -a COPYING %{buildroot}/usr/share/licenses/bpftool/COPYING
+
+%define __spec_install_post\
+%{?__debug_package:%{__debug_install_post}}\
+%{__arch_install_post}\
+%{__os_install_post}\
+%{__modsign_install_post}\
+%{nil}
%post
-/sbin/depmod -a %{version} >/dev/null 2>&1 || :
+%{_sbindir}/new-kernel-pkg --package kernel --install %{KernelVer} || exit $?
+
+%preun
+%ifarch loongarch64
+if command -v grubby > /dev/null; then
+ grubby --remove-kernel=/boot/efi-vmlinuz-%{KernelVer} >/dev/null 2>&1 || :
+fi
+%endif
+if [ `uname -i` == "aarch64" ] &&
+ [ -f /boot/EFI/grub2/grub.cfg ]; then
+ /usr/bin/sh %{_sbindir}/mkgrub-menu-%{version}-%{devel_release}%{?maintenance_release}%{?pkg_release}.sh %{version}-%{release}.aarch64 /boot/EFI/grub2/grub.cfg remove
+fi
%postun
-/sbin/depmod -a %{version} >/dev/null 2>&1 || :
+%{_sbindir}/new-kernel-pkg --rminitrd --rmmoddep --remove %{KernelVer} || exit $?
+if [ -x %{_sbindir}/weak-modules ]
+then
+ %{_sbindir}/weak-modules --remove-kernel %{KernelVer} || exit $?
+fi
+
+# remove empty directory
+if [ -d /lib/modules/%{KernelVer} ] && [ "`ls -A /lib/modules/%{KernelVer}`" = "" ]; then
+ rm -rf /lib/modules/%{KernelVer}
+fi
+if [ `uname -i` == "loongarch64" ];then
+ [ -f /etc/grub2.cfg ] && GRUB_CFG=`readlink -f /etc/grub2.cfg`
+ [ "x${GRUB_CFG}" == "x" ] && [ -f /etc/grub2-efi.cfg ] && GRUB_CFG=`readlink -f /etc/grub2-efi.cfg`
+ [ "x${GRUB_CFG}" == "x" ] && [ -f /boot/efi/EFI/openEuler/grub.cfg ] && GRUB_CFG=/boot/efi/EFI/openEuler/grub.cfg
+ [ "x${GRUB_CFG}" != "x" ] && grub2-mkconfig -o ${GRUB_CFG}
+fi
+
+%posttrans
+%{_sbindir}/new-kernel-pkg --package kernel --mkinitrd --dracut --depmod --update %{KernelVer} || exit $?
+%{_sbindir}/new-kernel-pkg --package kernel --rpmposttrans %{KernelVer} || exit $?
+if [ `uname -i` == "aarch64" ] &&
+ [ -f /boot/EFI/grub2/grub.cfg ]; then
+ /usr/bin/sh %{_sbindir}/mkgrub-menu-%{version}-%{devel_release}%{?maintenance_release}%{?pkg_release}.sh %{version}-%{release}.aarch64 /boot/EFI/grub2/grub.cfg update
+fi
+if [ `uname -i` == "loongarch64" ];then
+ [ -f /etc/grub2.cfg ] && GRUB_CFG=`readlink -f /etc/grub2.cfg`
+ [ "x${GRUB_CFG}" == "x" ] && [ -f /etc/grub2-efi.cfg ] && GRUB_CFG=`readlink -f /etc/grub2-efi.cfg`
+ [ "x${GRUB_CFG}" == "x" ] && [ -f /boot/efi/EFI/openEuler/grub.cfg ] && GRUB_CFG=/boot/efi/EFI/openEuler/grub.cfg
+ [ "x${GRUB_CFG}" != "x" ] && grub2-mkconfig -o ${GRUB_CFG}
+ grubby --set-default=/boot/vmlinuz-%{KernelVer}
+fi
+if [ -x %{_sbindir}/weak-modules ] && [ -f /boot/symvers-%{KernelVer}* ]
+then
+ %{_sbindir}/weak-modules --add-kernel %{KernelVer} || exit $?
+fi
+%post devel
+if [ -f /etc/sysconfig/kernel ]
+then
+ . /etc/sysconfig/kernel || exit $?
+fi
+if [ "$HARDLINK" != "no" -a -x /usr/sbin/hardlink ]
+then
+ (cd /usr/src/kernels/%{KernelVer} &&
+ /usr/bin/find . -type f | while read f; do
+ hardlink -c /usr/src/kernels/*.oe*.*/$f $f
+ done)
+fi
+
+%post -n %{name}-tools
+/sbin/ldconfig
+%systemd_post cpupower.service
+
+%preun -n %{name}-tools
+%systemd_preun cpupower.service
+
+%postun -n %{name}-tools
+/sbin/ldconfig
+%systemd_postun cpupower.service
%files
-%license COPYING
-%doc README
-/boot/vmlinuz-%{version}
-/boot/System.map-%{version}
-/boot/config-%{version}
-/lib/modules/%{version}
+%defattr (-, root, root)
+%doc
+/boot/config-*
+%ifarch aarch64 riscv64
+/boot/dtb-*
+%endif
+%if 0%{?with_kabichk}
+/boot/symvers-*
+%endif
+/boot/System.map-*
+/boot/vmlinuz-*
+%ifarch loongarch64
+/boot/efi-vmlinuz-%{KernelVer}
+%endif
+%ghost /boot/initramfs-%{KernelVer}.img
+/boot/.vmlinuz-*.hmac
+/etc/ld.so.conf.d/*
+/lib/modules/%{KernelVer}/
+%exclude /lib/modules/%{KernelVer}/source
+%exclude /lib/modules/%{KernelVer}/build
+%{_sbindir}/mkgrub-menu*.sh
+
+%files devel
+%defattr (-, root, root)
+%doc
+/lib/modules/%{KernelVer}/source
+/lib/modules/%{KernelVer}/build
+/usr/src/kernels/%{KernelVer}
+
+%files headers
+%defattr (-, root, root)
+/usr/include/*
+%exclude %{_includedir}/cpufreq.h
+%exclude %{_includedir}/cpuidle.h
+
+%if %{with_perf}
+%files -n perf
+%{_bindir}/perf
+%{_libdir}/libperf-jvmti.so
+%{_libexecdir}/perf-core
+%{_mandir}/man[1-8]/perf*
+%{_sysconfdir}/bash_completion.d/perf
+%doc linux-%{KernelVer}/tools/perf/Documentation/examples.txt
+%dir %{_datadir}/doc/perf-tip
+%{_datadir}/doc/perf-tip/*
+%license linux-%{KernelVer}/COPYING
+
+%if 0%{?with_python2}
+%files -n python2-perf
+%license linux-%{KernelVer}/COPYING
+%{python2_sitearch}/*
+%endif
+
+%files -n python3-perf
+%license linux-%{KernelVer}/COPYING
+%{python3_sitearch}/*
+%endif
+
+%files -n %{name}-tools -f cpupower.lang
+%{_bindir}/cpupower
+%ifarch %{ix86} x86_64
+%{_bindir}/centrino-decode
+%{_bindir}/powernow-k8-decode
+%endif
+%{_unitdir}/cpupower.service
+%{_datadir}/bash-completion/completions/cpupower
+%{_mandir}/man[1-8]/cpupower*
+%config(noreplace) %{_sysconfdir}/sysconfig/cpupower
+%config(noreplace) %{_sysconfdir}/cpupower-service.conf
+%{_libexecdir}/cpupower
+%ifarch %{ix86} x86_64
+%{_bindir}/x86_energy_perf_policy
+%{_mandir}/man8/x86_energy_perf_policy*
+%{_bindir}/turbostat
+%{_mandir}/man8/turbostat*
+%endif
+%{_bindir}/tmon
+%{_bindir}/iio_event_monitor
+%{_bindir}/iio_generic_buffer
+%{_bindir}/lsiio
+%{_bindir}/lsgpio
+%{_bindir}/gpio-hammer
+%{_bindir}/gpio-event-mon
+%{_bindir}/gpio-watch
+%{_bindir}/kvm_stat
+%{_libdir}/libcpupower.so.1
+%{_libdir}/libcpupower.so.1.0.1
+%license linux-%{KernelVer}/COPYING
+
+%files -n %{name}-tools-devel
+%{_libdir}/libcpupower.so
+%{_includedir}/cpufreq.h
+%{_includedir}/cpuidle.h
+
+%files -n bpftool
+%{_sbindir}/bpftool
+%{_sysconfdir}/bash_completion.d/bpftool
+%{_mandir}/man8/bpftool-cgroup.8.gz
+%{_mandir}/man8/bpftool-map.8.gz
+%{_mandir}/man8/bpftool-prog.8.gz
+%{_mandir}/man8/bpftool-perf.8.gz
+%{_mandir}/man8/bpftool.8.gz
+%{_mandir}/man8/bpftool-btf.8.gz
+%{_mandir}/man8/bpftool-feature.8.gz
+%{_mandir}/man8/bpftool-gen.8.gz
+%{_mandir}/man8/bpftool-iter.8.gz
+%{_mandir}/man8/bpftool-link.8.gz
+%{_mandir}/man8/bpftool-net.8.gz
+%{_mandir}/man8/bpftool-struct_ops.8.gz
+%{_mandir}/man8/bpftool-token.8.gz
+%license linux-%{KernelVer}/COPYING
+
+%if 0%{?with_source}
+%files source
+%defattr(-,root,root)
+/usr/src/linux-%{KernelVer}/*
+/usr/src/linux-%{KernelVer}/.config
+%endif
%changelog
-* Sat Nov 07 2026 openEuler Builder <builder@openeuler.org> - 6.18.50-1
-- Initial package of the Linux kernel 6.18.50 from gregkh/linux v6.18.50
+* Tue Nov 3 2026 Xie XiuQi <xiexiuqi@huawei.com> - 7.3.0-0.0.0.17
+- kernel: update to v7.3
+- config: regenerate kernel-aarch64.config and kernel-x86_64.config against the v7.3 Kconfig tree
+- config: record ML-DSA module signing key options as disabled in kernel-x86_64.config
+
+* Wed Oct 14 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.56-0.0.0.16
+- kernel: update to v6.18.56
+- config: add ARM64_ERRATUM_3821522 on aarch64, X86_AMD_PSTATE_DYNAMIC_EPP on x86_64
+
+* Tue Sep 1 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.48-0.0.0.15
+- kernel: update to v6.18.48
+
+* Tue Aug 11 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.40-0.0.0.14
+- Add self-service EulerMaker EBS cloud build (scripts/ebs-build.sh)
+- Add scripts/gen-source-tarball.sh for local kernel.tar.gz generation
+- Add ebs-build.conf.example and newcomer guide docs/ebs-build.md
+- Update README/README_cn with cloud and local build instructions
+- Add SPDX license header to scripts/clean-config
+
+* Tue Aug 11 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.40-0.0.0.13
+- Add README and README_cn, drop empty readme placeholder
+- config: enable wifi/bluetooth/touchpad drivers for DevStation
+- kernel.spec: fail the build when new Kconfig options are found
+- config: apply security hardening and feature choices
+- config: regenerate aarch64/x86_64 configs for v6.18.40
+- Add clean-config script to strip toolchain auto-detection options
+
+* Wed Jul 29 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.40-0.0.0.12
+- kernel: update to v6.18.40
+- kernel.spec: fix $Arch to %{Arch} for dtb install
+- kernel.spec: fix $KernelVer to %{KernelVer} in module cleanup
+- kernel.spec: fix {error} macro syntax (missing percent prefix)
+- kernel.spec: remove duplicate %posttrans new-kernel-pkg calls
+- kernel.spec: add COPYING license for kernel-tools and bpftool
+
+* Tue Jul 07 2026 gaihuiying <eaglegai@163.com> - 6.18.18-0.0.0.11
+- fix multi include path for kernel-devel
+
+* Fri Jul 03 2026 Wenlong Zhang <zhangwenlong@loongson.cn> - 6.18.18-0.0.0.10
+- use loongson3_defconfig on loongarch64 as default
+- fix build error on loongarch64
+
+* Mon Jun 15 2026 Ming Wang <wangming01@loongson.cn> - 6.18.18-0.0.0.9
+- LoongArch: rename packaged EFI kernel image to avoid auto boot entry generation
+
+* Mon Jun 01 2026 Ming Wang <wangming01@loongson.cn> - 6.18.18-0.0.0.8
+- LoongArch: package EFI kernel image
+
+* Thu May 07 2026 zhangqiumiao <zhangqiumiao1@h-partners.com> - 6.18.18-0.0.0.7
+- kernel.spec: fix symbol conflicts between 4K and 64K page packages
+
+* Thu Apr 16 2026 Xie XiuQi <xiexiuqi@huawei.com> - 6.18.18-0.0.0.6
+- kernel: update to 6.18.18
+- kernel.spec: fix build and install for v6.18 on modern toolchain
+- kernel.spec: update file lists for v6.18 packaging
+- kernel.spec: replace hmaccalc with libkcapi for openEuler compatibility
+
+* Thu Mar 19 2026 Wang Kui <wangkui35@h-partners.com> - 6.12.33-0.0.0.5
+- check /boot/symvers-* in posttrans
+
+*Wed Mar 18 2026 zhangqiumiao <zhangqiumiao1@h-partners.com> - 6.12.33-0.0.0.4
+- fix build failure with 64K page
+
+*Fri Feb 27 2026 zhangqiumiao <zhangqiumiao1@h-partners.com> - 6.12.33-0.0.0.3
+- change the package name of 64KB page size kernel to kernel-64k
+
+*Tue Aug 19 2025 yuelg <yuelg@chinaunicom.cn> - 6.12.33-0.0.0.2
+- adjust copying x509.genkey to be after mrproper
+
+* Wed Jun 18 2025 laokz <zhangkai@iscas.ac.cn> - 6.12.33-0.0.0.1
+- upgrade to upstream v6.12.33
+- reset %with_debuginfo
+
+* Sat Jun 07 2025 Xie XiuQi <xiexiuqi@huawei.com> - 6.12.0-0.0.0.1
+- upgrade to v6.12
+
+* Sat Jan 14 2023 Xie XiuQi <xiexiuqi@huawei.com> - 6.1.0-1.0.0.1
+- package init based on upstream v6.1