# openmamba kernel specfile for embedded kernels # Copyright (C) 2011-2021 by Silvan Calarco # # To build a specific target: # # rpmbuild -ba --define="KERNEL_TARGET " kernel.spec # # To cross-compile: # rpmbuild -ba kernel-rpi2.spec --target arm --define="cross_target_cpu arm" # # To cross-compile using an alternative compiler: # rpmbuild -ba kernel-rpi2.spec --target arm --define="cross_target_cpu arm" \ # --define="_target_platform arm-openmamba-linux-gnueabi" # #% define kernel_ver %(echo %version | cut -d. -f1-3) %define kernel_ver %(echo %version | cut -d. -f1-3) %define kernel_majver %(echo %version | cut -d. -f1-2) %define gitdirver 1.%(echo %version | cut -d. -f4) %ifarch aarch64 %define KERNEL_TARGET rpi-v8 %else %if "%{?KERNEL_TARGET}" == "" %define KERNEL_TARGET rpi-v7l %endif %endif %if "%{_target_cpu}" == "arm" %define KIMAGE arch/arm/boot/zImage %define KIMAGE_DEST kernel %define DEPMOD /sbin/depmod %define target_cpu %{_target_cpu} %endif %if "%{_target_cpu}" == "aarch64" %define KIMAGE arch/arm64/boot/Image %define KIMAGE_DEST kernel %define DEPMOD /sbin/depmod %define target_cpu arm64 %endif # disable internal dependency generator for scriptlets %define _use_internal_dependency_generator 1 Name: kernel-rpi Version: 5.4.51.20200902 Release: 2mamba Summary: The Linux Kernel, the operating system core itself for the RaspberryPI Group: System/Kernel and Hardware Vendor: openmamba Distribution: openmamba Packager: Silvan Calarco URL: https://github.com/raspberrypi/linux Source0: git://github.com/raspberrypi/linux.git/raspberrypi-kernel_%{gitdirver}-1/linux-%{version}.tar.bz2 Source20: kernel-rpi-logo.png Source100: %{name}-v7-%{kernel_majver}-arm-config Source101: %{name}-%{kernel_majver}-arm-config Source102: kernel-rpi-v7l-%{kernel_majver}-arm-config Source103: kernel-rpi-v8-%{kernel_majver}-aarch64-config License: GPL ## AUTOBUILDREQ-BEGIN BuildRequires: glibc-devel BuildRequires: libperl BuildRequires: perl-devel ## AUTOBUILDREQ-END BuildRequires: /bin/bash BuildRequires: /bin/sh BuildRequires: /usr/bin/perl BuildRequires: kmod Provides: kernel-%{KERNEL_TARGET}-modules Obsoletes: kernel-%{KERNEL_TARGET}-modules Provides: kernel Provides: kernelmodules Requires(post): dracut Requires: linux_firmware Requires: raspberrypi-firmware BuildRoot: %{_tmppath}/%{name}-build %description The Linux Kernel, the operating system core itself for the Raspberry PI. The kernel package contains the Linux kernel (%{KIMAGE_DEST}), the operating system core itself. The kernel handles the basic functions of the operating system: memory allocation, process allocation, device input and output, etc. This is the source package used to build kernel for different architectures and targets. This kernel was build for %{_target_cpu} architecture and the following target: %{?KERNEL_TARGET}. %if "%{KERNEL_TARGET}" != "rpi" %package -n kernel-%{KERNEL_TARGET} Group: Development/Kernel Summary: The Linux Kernel, the operating system core itself for the RaspberryPI (%{KERNEL_TARGET}) Provides: kernel-%{KERNEL_TARGET}-modules Obsoletes: kernel-%{KERNEL_TARGET}-modules %if "%{KERNEL_TARGET}" == "rpi-v7" Provides: kernel-rpi2 Obsoletes: kernel-rpi2 Provides: kernel-rpi2-modules Obsoletes: kernel-rpi2-modules %endif Provides: kernel Provides: kernelmodules Requires(post): dracut Requires: linux_firmware Requires: raspberrypi-firmware %description -n kernel-%{KERNEL_TARGET} The Linux Kernel, the operating system core itself for the Raspberry PI. The kernel package contains the Linux kernel (%{KIMAGE_DEST}), the operating system core itself. The kernel handles the basic functions of the operating system: memory allocation, process allocation, device input and output, etc. This is the source package used to build kernel for different architectures and targets. This kernel was build for %{_target_cpu} architecture and the following target: %{?KERNEL_TARGET}. %endif %package -n kernel-%{KERNEL_TARGET}-source Group: Development/Kernel Summary: The source code for the Linux kernel Requires: kernel-%{KERNEL_TARGET}-headers == %{version}-%{release} Provides: kernelsource %if "%{KERNEL_TARGET}" == "rpi-v7" Provides: kernel-rpi2-source Obsoletes: kernel-rpi2-source %endif %description -n kernel-%{KERNEL_TARGET}-source The kernel-source package contains the source code files for the Linux kernel. The source files can be used to build a custom kernel that is better tuned to your particular hardware, if you are so inclined (and you know what you're doing). This kernel sources are configured for %{TARGET_CPU} architecture and the following target: %{?KERNEL_TARGET}. %package -n kernel-%{KERNEL_TARGET}-headers Group: Development/Kernel Summary: Headers, scripts, configuration and Makefile for the linux kernel Provides: kernelheaders %if "%{KERNEL_TARGET}" == "rpi-v7" Provides: kernel-rpi2-headers Obsoletes: kernel-rpi2-headers %endif %description -n kernel-%{KERNEL_TARGET}-headers The kernel-headers package contains the headers, scripts, configuration and Makefile to develop with the linux kernel The kernel-headers can be used to build modules for the kernel. This kernel headers are configured for %{TARGET_CPU} architecture and the following target: %{?KERNEL_TARGET}. %package -n kernel-%{KERNEL_TARGET}-headers-sanitised Group: Development/Kernel Summary: Sanitised kernel headers used for glibc build Provides: kernelsanitisedheaders %if "%{KERNEL_TARGET}" == "rpi-v7" Provides: kernel-rpi2-headers-sanitised Obsoletes: kernel-rpi2-headers-sanitised %endif %description -n kernel-%{KERNEL_TARGET}-headers-sanitised Sanitised kernel headers used for glibc build. This kernel sanitised headers are configured for %{TARGET_CPU} architecture and the following target: %{?KERNEL_TARGET}. %package -n kernel-%{KERNEL_TARGET}-firmware Group: System/Kernel and Hardware Summary: Firmware files used by %{name} Requires: kernel-%{KERNEL_TARGET} == %{version}-%{release} Provides: kernelfirmware = %{version} Provides: linux_firmware %if "%{KERNEL_TARGET}" == "rpi-v7" Provides: kernel-rpi2-firmware Obsoletes: kernel-rpi2-firmware %endif %description -n kernel-%{KERNEL_TARGET}-firmware Firmware files used by the Linux Kernel. %package -n kernel-%{KERNEL_TARGET}-dtbs Group: System/Kernel and Hardware Summary: Device Tree blobs provided with %{name} Requires: kernel-%{KERNEL_TARGET} == %{version}-%{release} %description -n kernel-%{KERNEL_TARGET}-dtbs Device Tree blobs provided with %{name}. %prep %setup -q -n linux-%{version} #-D -T #:<< _EOF %if "%{?KERNEL_TARGET}" == "" echo "No target specified, aborting." exit 1 %else echo "I'm going to build a %{KERNEL_TARGET} kernel..." %endif # # patch and configure STANDARD kernel # #% patch0 -p1 #% patch1 -p1 make mrproper # create build dirs for each kernel # and copy proper configuration %if %{_target_cpu} == arm case %{?KERNEL_TARGET} in rpi) kernel_cfg=%{SOURCE101} ;; rpi-v7) kernel_cfg=%{SOURCE100} ;; rpi-v7l) kernel_cfg=%{SOURCE102} ;; esac %endif %if %{_target_cpu} == aarch64 case %{?KERNEL_TARGET} in rpi-v8) kernel_cfg=%{SOURCE103} ;; esac %endif cp $kernel_cfg ./.config cp Makefile Makefile.orig sed -i "s/\(EXTRAVERSION =.*\)/\1-%{?KERNEL_TARGET}/" Makefile # add custom logo pngtopnm %{SOURCE20} | ppmquant -plain 224 > drivers/video/logo/logo_linux_clut224.ppm %build #:<< _EOF # # build kernel for given target # ARCH=%{target_cpu} make oldconfig ARCH=%{target_cpu} make CROSS_COMPILE=%{_target_platform}- %{?_smp_mflags} ARCH=%{target_cpu} make CROSS_COMPILE=%{_target_platform}- %{?_smp_mflags} modules dtbs %install [ "%{buildroot}" != / ] && rm -rf "%{buildroot}" # create system dirs in install environment install -d %{buildroot}{/usr/src/,/boot,%{_initrddir},/lib/modules,/lib/firmware} ARCH=%{target_cpu} make \ modules_install INSTALL_MOD_PATH=%{buildroot} DEPMOD=%{DEPMOD} install -m0644 modules.builtin %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/ install -m0644 modules.order %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/ (cd %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET} rm -f build && ln -sf /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} build ) %if %{_target_cpu} == arm case %{?KERNEL_TARGET} in rpi) kimage_dest="kernel.img" ;; rpi-v7) kimage_dest="kernel7.img" ;; rpi-v7l) kimage_dest="kernel7l.img" ;; esac %endif %if %{_target_cpu} == aarch64 case %{?KERNEL_TARGET} in rpi-v8) kimage_dest="kernel8.img" ;; esac %endif cp %{KIMAGE} %{buildroot}/boot/${kimage_dest} cp System.map %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/System.map # install dtbs install -d -m0755 %{buildroot}/boot/overlays/ #cp arch/%{target_cpu}/boot/dts/*.dtb %{buildroot}/boot/ cp arch/arm/boot/dts/overlays/*.dtb* %{buildroot}/boot/overlays/ # recreate kernel sources [ -e kernel-headers.files ] && rm -f kernel-headers.files [ -e kernel-source.files ] && rm -f kernel-source.files cp -R %{_builddir}/linux-%{version} %{buildroot}/usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} cd %{buildroot}/usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} ARCH=%{target_cpu} make mrproper %if %{_target_cpu} == arm case %{?KERNEL_TARGET} in rpi) kernel_cfg=%{SOURCE101} ;; rpi-v7) kernel_cfg=%{SOURCE100} ;; rpi-v7l) kernel_cfg=%{SOURCE102} ;; esac %endif %if %{_target_cpu} == aarch64 case %{?KERNEL_TARGET} in rpi-v8) kernel_cfg=%{SOURCE103} ;; esac %endif cp $kernel_cfg %{buildroot}/usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.config cp %{_builddir}/linux-%{version}/Module.symvers %{buildroot}/usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} ARCH=%{target_cpu} make oldconfig #cp Makefile Makefile.orig #sed -i "s/\(EXTRAVERSION =.*\)/\1-%{?KERNEL_TARGET}/" Makefile #%if "%{_target_platform}" == "%{_build}" ARCH=%{target_cpu} make \ HOSTCC=%{_build}-gcc \ CROSS_COMPILE=%{_target_platform}- \ prepare scripts oldconfig #%endif rm .config.old # clean modules files created by depmod rm -f %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.{alias,alias.bin,ccwmap,dep,dep.bin,devname,ieee1394map} rm -f %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.{inputmap,isapnpmap,ofmap,pcimap,seriomap,softdep} rm -f %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.{symbols,symbols.bin,usbmap} # remove .tmp files if any rm -f %{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.tmp* || true # fix symlink pointing to sources rm -f %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/source ln -s %{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} %{buildroot}/lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/source # # create kernel-source.files and kernel-headers.files # cd %{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET} splitdirs="block crypto drivers fs ipc kernel lib mm net security sound" case %{_target_cpu} in arm) headers_arch="arm" ;; aarch64) headers_arch="arm64" ;; esac find $splitdirs -name *.h -exec \ echo "%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/"{} >> \ %{_builddir}/linux-%{version}/kernel-headers.files \; %if "%{with_full_source}" == "1" find $splitdirs -not -type d -a -not -name *.h -exec \ echo "%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/"{} >> \ %{_builddir}/linux-%{version}/kernel-source.files \; %else touch %{_builddir}/linux-%{version}/kernel-source.files find $splitdirs -not -type d -a -not -name *.h -exec rm -f {} \; rm -rf firmware samples virt %endif archs=" `ls %{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/arch` " for i in $archs; do [ "$i" == "$headers_arch" ] || \ %if "%{with_full_source}" == "1" echo "%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/arch/$i" >> \ %{_builddir}/linux-%{version}/kernel-source.files %else rm -rf arch/$i %endif done echo "%{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/arch/$headers_arch" >> \ %{_builddir}/linux-%{version}/kernel-headers.files # install sanitised headers used by glibc ARCH=%{target_cpu} make headers_install \ HOSTCC=%{_build}-gcc \ CROSS_COMPILE=%{_target_platform}- \ INSTALL_HDR_PATH=%{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{KERNEL_TARGET}/usr # Do not package cross-platform host tools if [ "%{_build}" != "%{_target_platform}" ]; then for f in asn1_compiler conmakehash extract-cert kallsyms sortextable; do rm -f %{buildroot}/usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/scripts/$f done fi rm -f %{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{KERNEL_TARGET}/{.cocciconfig,.gitattributes} rm -rf %{buildroot}%{_prefix}/src/linux-%{kernel_ver}-%{KERNEL_TARGET}/.github %clean [ "%{buildroot}" != / ] && rm -rf "%{buildroot}" %post -n kernel-%{KERNEL_TARGET} # new install or upgrade if [ $1 -ge 1 ]; then /sbin/depmod -A -F /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/System.map \ %{kernel_ver}-%{?KERNEL_TARGET} &>/dev/null #mkinitrd -f /boot/initramfs-%{kernel_ver}-%{?KERNEL_TARGET}.img %{kernel_ver}-%{?KERNEL_TARGET} fi : %postun -n kernel-%{KERNEL_TARGET} # erase this package if [ $1 -eq 0 ]; then [ -f /boot/%{KIMAGE_DEST}-%{kernel_ver}-%{?KERNEL_TARGET} ] || rm -f /boot/initramfs-%{kernel_ver}-%{?KERNEL_TARGET}.img fi : %post -n kernel-%{KERNEL_TARGET}-headers # touch file so it results up-to-date on make touch %{_prefix}/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/include/config/MARKER : %files -n kernel-%{KERNEL_TARGET} %defattr (-, root, root) /boot/kernel*.img %dir /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET} /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/System.map /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.builtin /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.builtin.bin /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.builtin.alias.bin /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.builtin.modinfo /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/modules.order %dir /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/kernel /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/kernel/* %files -n kernel-%{KERNEL_TARGET}-dtbs %defattr (-, root, root) #/boot/*.dtb* /boot/overlays/*.dtb* %files -n kernel-%{KERNEL_TARGET}-source #-f kernel-source.files %defattr(-,root,root) /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.clang-format %dir /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/LICENSES /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/LICENSES/* /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/arch/.gitignore /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Documentation /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/certs /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/init /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/gen_initramfs_list.sh /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/gen_init_cpio.c /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/initramfs_data*.S /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/Kconfig /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/Makefile /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/.gitignore /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/tools /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.missing-syscalls.d /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.mailmap /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Kconfig %if "%{with_full_source}" == "1" /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/block /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/firmware /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/samples /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/virt %endif %files -n kernel-%{KERNEL_TARGET}-headers-sanitised %defattr(-,root,root) /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/usr/include %files -n kernel-%{KERNEL_TARGET}-headers -f kernel-headers.files %defattr(-,root,root) /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/COPYING /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/CREDITS /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Kbuild /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/include /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Makefile /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Makefile.orig /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/Module.symvers /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/MAINTAINERS /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/README /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/scripts /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.config /usr/src/linux-%{kernel_ver}-%{?KERNEL_TARGET}/.get_maintainer.ignore /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/build /lib/modules/%{kernel_ver}-%{?KERNEL_TARGET}/source #%files -n kernel-%{KERNEL_TARGET}-firmware #%defattr (-, root, root) #%dir /lib/firmware #/lib/firmware/* %changelog * Sun Oct 04 2020 Silvan Calarco 5.4.51.20200902-2mamba - merge kernel-*-modules into main kernel package; fix depmod after moving System.map away from /boot * Thu Oct 01 2020 Silvan Calarco 5.4.51.20200902-1mamba - update to 5.4.51.20200902 * Wed Sep 09 2020 Silvan Calarco 5.4.51.20200819-1mamba - update to 5.4.51.20200819 * Fri Apr 03 2020 Silvan Calarco 4.19.97.20200212-1mamba - update to 4.19.113.20200212 * Mon Jan 27 2020 Silvan Calarco 4.19.93.20200114-1mamba - update to 4.19.93.20200114 * Wed Jan 15 2020 Silvan Calarco 4.19.75.20190925-1mamba - update to 4.19.75.20190925 * Mon Dec 10 2018 Silvan Calarco 4.14.79.20181112-2mamba - rebuilt after configuration fixes * Sun Dec 09 2018 Silvan Calarco 4.14.79.20181112-1mamba - update to 4.14.79.20181112 * Fri Feb 17 2017 Silvan Calarco 4.4.38.20161215-1mamba - update to 4.4.38.20161215 * Thu Feb 16 2017 Silvan Calarco 4.4.1.20161020-2mamba - configs: enabled KEXEC and built-id IKCONFIG * Thu Nov 10 2016 Silvan Calarco 4.4.1.20161020-1mamba - update to 4.4.1.20161020 * Tue Jul 12 2016 Silvan Calarco 4.4.1.20160620-1mamba - update to 4.4.1.20160620 * Fri Feb 27 2015 Silvan Calarco 3.18.7.20150227git-1mamba - update to 3.18.7.20150227git * Sun Dec 07 2014 Silvan Calarco 3.12.34.20141207git-1mamba - update to 3.12.34.20141207git * Sat Dec 06 2014 Silvan Calarco 3.14.6.20140831git-3mamba - rebuilt with newer gcc to see if it works * Sat Sep 06 2014 Silvan Calarco 3.14.6.20140831git-2mamba - update configuration, sync with arch/arm/configs/bcmrpi_defconfig * Sun Aug 31 2014 Automatic Build System 3.14.6.20140831git-1mamba - update to 3.14.6.20140831git * Mon Sep 09 2013 Silvan Calarco 3.6.11.20130909git-1mamba - package created from kernel-hannspad template