ExclusiveArch: aarch64 armv7hl %undefine _debugsource_packages %define with_cross %{?_with_cross: 1} %{?!_with_cross: 0} # 忘记从哪里抄来的了 %define patchlevel 31 %define Arch arm64 %define kversion 5.10.160 %define krelease 6%{?dist} %define KernelVer %{kversion}-%{krelease}.%{_target_cpu} Name: orangepi-3b Version: %{kversion} Release: %{krelease} Summary: Kernel for Orange Pi 3B License: GPLv2 URL: https://github.com/orangepi-xunlong/linux-orangepi/tree/orange-pi-5.10-rk35xx Source0: linux-orangepi.tar.gz Source1: orangepi-3b.config # https://lore.kernel.org/lkml/CAMj1kXE+LBOBavOre1O8LTGPCmB8m58fbfo92Sx4WukyNAur-A@mail.gmail.com/ Patch0: fix-missing-build-id.patch BuildRequires: kmod, patch, bash, coreutils, tar BuildRequires: bzip2, xz, findutils, gzip, m4, perl, perl-Carp, make, diffutils, gawk BuildRequires: gcc, binutils, redhat-rpm-config, hmaccalc, git BuildRequires: net-tools, hostname, bc BuildRequires: elfutils-devel zlib-devel binutils-devel newt-devel python3-devel perl(ExtUtils::Embed) bison flex xz-devel BuildRequires: audit-libs-devel BuildRequires: pciutils-devel gettext ncurses-devel BuildRequires: openssl-devel # dtbs中需要编译两个uboot 的scr,将来可能会顺便编译boot.scr # 需要在copr中额外引入第三方仓库 BuildRequires: uboot-tools %if %{with_cross} BuildRequires: binutils-%{_build_arch}-linux-gnu, gcc-%{_build_arch}-linux-gnu %define cross_opts CROSS_COMPILE=%{_build_arch}-linux-gnu- %define __strip %{_build_arch}-linux-gnu-strip %endif # Compile with SELinux but disable per default #Patch100: bcm2709_selinux_config.patch #Patch101: bcm2711_selinux_config.patch %description Kernel for Orange Pi 3B %package kernel Group: System Environment/Kernel Summary: The Linux kernel Provides: kernel = %{version}-%{release} Provides: installonlypkg(kernel) Requires: coreutils Requires: dracut Requires: uboot-tools %description kernel Linux operating system. The kernel handles the basic functions of the operating system: memory allocation, process allocation, device input and output, etc. %package kernel-devel Group: System Environment/Kernel Summary: Development package for building kernel modules to match the kernel Provides: kernel-devel = %{version}-%{release} Provides: kernel-devel-uname-r = %{version}-%{release} Provides: installonlypkg(kernel) Autoreq: no Requires(pre): findutils Requires: findutils Requires: perl-interpreter %description kernel-devel This package provides kernel headers and makefiles sufficient to build modules against the kernel package. %package dtb Summary: DTB for Orange Pi 3B Obsoletes: grub, grubby, efibootmgr Provides: grubby=8.40-10 Provides: installonlypkg(kernel-module) %description dtb /boot/内的dtb已经包含在kernel内了,这个包只是占位符,避免系统安装grub、grubby、efibootmgr包。 %prep %setup -q -n linux-orangepi cp %{SOURCE1} . %patch0 -p0 # 内核源代码中有一些脚本,它们的shebang只写了python,没有指明python2还是python3 # 这既会在编译时带来问题,需要手动把python指向python3,修完之后的%check阶段又通不过rpmbuild的检查 # 所以需要手动修复源代码,把它们都指向python3 # This fixes errors such as # *** ERROR: ambiguous python shebang in /usr/bin/kvm_stat: #!/usr/bin/python. Change it to python3 (or python2) explicitly. # We patch all sources below for which we got a report/error. echo "Fixing Python shebangs..." %py3_shebang_fix \ tools/kvm/kvm_stat/kvm_stat \ scripts/show_delta \ scripts/diffconfig \ scripts/bloat-o-meter \ scripts/jobserver-exec \ scripts/tracing \ scripts/bmpconvert \ scripts/clang-wrapper.py \ scripts/gcc-wrapper.py \ scripts/mkmultidtb.py \ scripts/spdxcheck.py \ tools \ Documentation \ scripts/clang-tools 2> /dev/null %build # 交叉编译 ## 根据fedora官方spec中的注释,交叉编译时不能启用%{?build_cflags} %{?build_ldflags},因为这些来自 redhat-rpm-config 里的宏 # 假设 host == target %if !%{with_cross} %define build_hostcflags %{?build_cflags} %define build_hostldflags %{?build_ldflags} %endif # 修改内核版本代码 # make sure EXTRAVERSION says what we want it to say # Trim the release if this is a CI build, since KERNELVERSION is limited to 64 characters ShortRel=$(perl -e "print \"%{release}\" =~ s/\.pr\.[0-9A-Fa-f]{32}//r") perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${ShortRel}.%{_target_cpu}${Variant:++${Variant}}/" Makefile # if pre-rc1 devel kernel, must fix up PATCHLEVEL for our versioning scheme # if we are post rc1 this should match anyway so this won't matter #perl -p -i -e 's/^PATCHLEVEL.*/PATCHLEVEL = %{patchlevel}/' Makefile # make -j8 CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 help # 可以得到平台相关的target的解释 #make %{?cross_opts} ARCH=%{Arch} bcm%{bcmmodel}_defconfig cp orangepi-3b.config .config make %{?_smp_mflags} %{?cross_opts} ARCH=%{Arch} HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}" V=1 Image make %{?_smp_mflags} %{?cross_opts} ARCH=%{Arch} HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}" V=1 modules make %{?_smp_mflags} %{?cross_opts} ARCH=%{Arch} HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}" V=1 dtbs %install # 创建目录 mkdir -p $RPM_BUILD_ROOT ## 内核镜像 mkdir -p $RPM_BUILD_ROOT/boot ## 内核模块 mkdir -p $RPM_BUILD_ROOT/lib/modules/%{KernelVer} mkdir -p $RPM_BUILD_ROOT/usr/include/ # 开始安装 ## 内核 install -m 644 .config $RPM_BUILD_ROOT/boot/config-%{KernelVer} install -m 644 .config $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/config install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-%{KernelVer} install -m 644 System.map $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/System.map cp arch/arm64/boot/Image $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} chmod 755 $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} cp $RPM_BUILD_ROOT/boot/vmlinuz-%{KernelVer} $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/vmlinuz ## 设备树 make %{?_smp_mflags} ARCH=%{Arch} INSTALL_DTBS_PATH=$RPM_BUILD_ROOT/boot/dtb-%{KernelVer} V=1 dtbs_install cp -r $RPM_BUILD_ROOT/boot/dtb-%{KernelVer} $RPM_BUILD_ROOT/lib/modules/%{KernelVer}/dtb find arch/%{Arch}/boot/dts -name '*.dtb' -type f -delete ## 内核模块 make %{?_smp_mflags} ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT KERNELRELEASE=%{KernelVer} V=1 modules_install ## kernel-devel (来自Almalinux) DevelDir=/usr/src/kernels/%{KernelVer} mkdir -p %{buildroot}$DevelDir # first copy everything cp -p -v Module.symvers System.map %{buildroot}$DevelDir cp --parents `find -type f -name "Makefile*" -o -name "Kconfig*"` %{buildroot}$DevelDir # then drop all but the needed Makefiles/Kconfig files rm -rf %{buildroot}$DevelDir/Documentation rm -rf %{buildroot}$DevelDir/scripts rm -rf %{buildroot}$DevelDir/include cp .config %{buildroot}$DevelDir cp -a scripts %{buildroot}$DevelDir cp -a include %{buildroot}$DevelDir if [ -d arch/%{Arch}/scripts ]; then cp -a arch/%{Arch}/scripts %{buildroot}$DevelDir/arch/%{Arch} || : fi if [ -f arch/%{Arch}/*lds ]; then cp -a arch/%{Arch}/*lds %{buildroot}$DevelDir/arch/%{Arch}/ || : fi if [ -f arch/%{Arch}/kernel/module.lds ]; then cp -a --parents arch/%{Arch}/kernel/module.lds %{buildroot}$DevelDir/ fi rm -f %{buildroot}$DevelDir/scripts/*.o rm -f %{buildroot}$DevelDir/scripts/*/*.o cp -a --parents arch/%{Arch}/include %{buildroot}$DevelDir cp include/generated/uapi/linux/version.h %{buildroot}$DevelDir/include/linux touch -r %{buildroot}$DevelDir/Makefile %{buildroot}$DevelDir/include/linux/version.h rm -f %{buildroot}/lib/modules/%{KernelVer}/build rm -f %{buildroot}/lib/modules/%{KernelVer}/source ln -s $DevelDir %{buildroot}/lib/modules/%{KernelVer}/build ln -s build %{buildroot}/lib/modules/%{KernelVer}/source %files kernel %defattr(-,root,root,-) /boot/config-%{KernelVer} /boot/System.map-%{KernelVer} /boot/vmlinuz-%{KernelVer} /lib/modules/%{KernelVer} /lib/modules/%{KernelVer}/config /lib/modules/%{KernelVer}/System.map /lib/modules/%{KernelVer}/vmlinuz /boot/dtb-%{KernelVer} /lib/modules/%{KernelVer}/kernel /lib/modules/%{KernelVer}/modules.* /lib/modules/%{KernelVer}/build /lib/modules/%{KernelVer}/source %postun kernel rm -f /boot/uinitramfs-%{KernelVer}.img %posttrans kernel # 从uboot那边下手,一切都轻松起来了 dracut -f /boot/initramfs-%{KernelVer}.img %{KernelVer} mkimage -A arm64 -O linux -T ramdisk -C gzip -a 0 -e 00 -n Linux -d /boot/initramfs-%{KernelVer}.img /boot/uinitramfs-%{KernelVer}.img rm -f /boot/initramfs-%{KernelVer}.img %files kernel-devel %defattr(-,root,root) /usr/src/kernels/%{KernelVer} %files dtb %defattr(-,root,root,-) /lib/modules/%{KernelVer}/dtb %changelog