# Maintainer: Natanael Copa _mainflavor=rpi pkgname=linux-$_mainflavor pkgver=3.18.16 case $pkgver in *.*.*) _kernver=${pkgver%.*};; *.*) _kernver=${pkgver};; esac pkgrel=0 pkgdesc="Linux kernel with Raspberry Pi patches" url=https://github.com/raspberrypi/linux depends="mkinitfs linux-firmware" makedepends="perl installkernel bash gmp-dev bc" options="!strip" install= source="http://ftp.kernel.org/pub/linux/kernel/v3.x/linux-$_kernver.tar.xz http://ftp.kernel.org/pub/linux/kernel/v3.x/patch-$pkgver.xz http://dev.alpinelinux.org/~tteras/linux-3.18.y-rpi-20150617.patch aslr-pie.patch config-rpi.armhf config-rpi2.armhf markdt " subpackages="$pkgname-dev" _flavors= for _i in $source; do case $_i in config-*.$CARCH) _f=${_i%.$CARCH} _f=${_f#config-} _flavors="$_flavors ${_f}" if [ "linux-$_f" != "$pkgname" ]; then subpackages="$subpackages linux-${_f}" fi ;; esac done arch="armhf" license="GPL-2" prepare() { local _patch_failed= cd "$srcdir"/linux-$_kernver if [ "${pkgver%.0}" = "$pkgver" ]; then msg "Applying patch-$pkgver.xz" unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N || return 1 fi # first apply patches in specified order for i in $source; do case $i in *.patch) msg "Applying $i..." if ! patch -s -p1 -N -i "$srcdir"/${i##*/}; then echo $i >>failed _patch_failed=1 fi ;; esac done if ! [ -z "$_patch_failed" ]; then error "The following patches failed:" cat failed return 1 fi # remove localversion from patch if any rm -f localversion* for i in $_flavors; do local _config=config-$i.${CARCH} local _builddir="$srcdir"/build-$i mkdir -p "$_builddir" echo "-$pkgrel-$i" > "$srcdir"/build-$i/localversion-alpine \ || return 1 cp "$srcdir"/$_config "$_builddir"/.config || return 1 make -C "$srcdir"/linux-$_kernver \ O="$_builddir" \ HOSTCC="${CC:-gcc}" \ silentoldconfig || return 1 done } build() { export GCC_SPECS=hardenednopie.specs for i in $_flavors; do cd "$srcdir"/build-$i make CC="${CC:-gcc}" \ KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \ || return 1 done } _package() { local _buildflavor="$1" _outdir="$2" local _abi_release=${pkgver}-${pkgrel}-${_buildflavor} cd "$srcdir"/build-$_buildflavor || return 1 mkdir -p "$_outdir"/boot "$_outdir"/lib/modules local _install case "$CARCH" in arm*) local _dtbdir="$_outdir"/usr/lib/linux-${_abi_release} mkdir -p "$_dtbdir" "$_dtbdir"/overlays for i in arch/arm/boot/dts/*.dtb ; do case "$i" in *-overlay.dtb) install -m644 "$i" "$_dtbdir/overlays" ;; *.dtb) install -m644 "$i" "$_dtbdir" ;; esac done _install=zinstall ;; *) _install=install ;; esac make -j1 modules_install firmware_install $_install \ INSTALL_MOD_PATH="$_outdir" \ INSTALL_PATH="$_outdir"/boot \ || return 1 # tell rpi bootloader we are device tree capable "$srcdir"/markdt "$_outdir"/boot/vmlinuz-$_buildflavor \ || return 1 rm -f "$_outdir"/lib/modules/${_abi_release}/build \ "$_outdir"/lib/modules/${_abi_release}/source rm -rf "$_outdir"/lib/firmware install -D include/config/kernel.release \ "$_outdir"/usr/share/kernel/$_buildflavor/kernel.release } # main flavor installs in $pkgdir package() { _package rpi "$pkgdir" } # subflavors install in $subpkgdir rpi2() { _package rpi2 "$subpkgdir" } # we only provide -dev for main flavor for now dev() { local _abi_release=${pkgver}-${pkgrel}-$_mainflavor # copy the only the parts that we really need for build 3rd party # kernel modules and install those as /usr/src/linux-headers, # simlar to what ubuntu does # # this way you dont need to install the 300-400 kernel sources to # build a tiny kernel module # pkgdesc="Headers and script for third party modules for grsec kernel" depends="gmp-dev bash" local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release} # first we import config, run prepare to set up for building # external modules, and create the scripts mkdir -p "$dir" cp "$srcdir"/config-$_mainflavor.${CARCH} "$dir"/.config make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \ silentoldconfig prepare modules_prepare scripts # remove the stuff that poits to real sources. we want 3rd party # modules to believe this is the soruces rm "$dir"/Makefile "$dir"/source # copy the needed stuff from real sources # # this is taken from ubuntu kernel build script # http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-jaunty.git;a=blob;f=debian/rules.d/3-binary-indep.mk;hb=HEAD cd "$srcdir"/linux-$_kernver find . -path './include/*' -prune -o -path './scripts/*' -prune \ -o -type f \( -name 'Makefile*' -o -name 'Kconfig*' \ -o -name 'Kbuild*' -o -name '*.sh' -o -name '*.pl' \ -o -name '*.lds' \) | cpio -pdm "$dir" cp -a drivers/media/dvb/dvb-core/*.h "$dir"/drivers/media/dvb/dvb-core cp -a drivers/media/video/*.h "$dir"/drivers/media/video cp -a drivers/media/dvb/frontends/*.h "$dir"/drivers/media/dvb/frontends cp -a scripts include "$dir" find $(find arch -name include -type d -print) -type f \ | cpio -pdm "$dir" install -Dm644 "$srcdir"/build-$_mainflavor/Module.symvers \ "$dir"/Module.symvers mkdir -p "$subpkgdir"/lib/modules/${_abi_release} ln -sf /usr/src/linux-headers-${_abi_release} \ "$subpkgdir"/lib/modules/${_abi_release}/build } md5sums="9e854df51ca3fef8bfe566dbd7b89241 linux-3.18.tar.xz 96aeccef48037aee98911634664af68e patch-3.18.16.xz 4224a13261d65db5c09e88e6a14d670b linux-3.18.y-rpi-20150617.patch 6f5854b710be8f38f67fc7ec8f3d0625 aslr-pie.patch 1363c986e464d95a090c9e30fa2b5253 config-rpi.armhf 895a0286802f8dc0eeecd2d31443074d config-rpi2.armhf 1f3dda659442fa7e2afc62bffeceb129 markdt" sha256sums="becc413cc9e6d7f5cc52a3ce66d65c3725bc1d1cc1001f4ce6c32b69eb188cbd linux-3.18.tar.xz f60602c8de2ae7b1507c538b6af65d5b933727a06f56075898ff64fdcf650313 patch-3.18.16.xz 82f881bfbb3f761ae4c81ec6272ee0b62f1066deb9fff9b290774f844d838638 linux-3.18.y-rpi-20150617.patch e1db8126b13507f4442b1fa5c3d2648fa453f0ca3ea75145ec6f0faeab923c08 aslr-pie.patch d4d77d5b9defb84add2f77e045c39ba4a067f7fdd908d13be0e7b6b18caf00c4 config-rpi.armhf 927ec7509b059fc8f4f4220f917571c68404c15683724e0090e3669417e32fd3 config-rpi2.armhf 289a7509bc294295b65680c7fff0b2ec07cf359ea8a57cef00267396885f9b54 markdt" sha512sums="2f0b72466e9bc538a675738aa416573d41bbbd7e3e2ffd5b5b127afde609ebc278cec5a3c37e73479607e957c13f1b4ed9782a3795e0dcc2cf8e550228594009 linux-3.18.tar.xz 868de9793e67e741dc69d61339f66c25d08d36a7d67b09d5644e855e05faf239c1e6e01299812a68edc52a39e132d7ec459929cb5d8a0936fe6aa580a72af80c patch-3.18.16.xz f48822399d842f60d533d11be0c1eeb881d21fb69fa110d19cb0778d271e9f2bd230673a9dffca98483a317150fac62c0eb1e0fae50d85751b05fa0b7a58132f linux-3.18.y-rpi-20150617.patch 8b2080b72cd0a1bf8f528e8a7a4ab7921ee9e1e425a5c0439e9409b599eca23ad992f5fec67924da736c20de9728c7f0cb2f3087212a278e82ba8ecfc8fac7d0 aslr-pie.patch 35a51b1fb94605cc522a76389be940f9283361fe4062de3fd0439f87e1b2fdc8852de3e7c93b0657641577f266697cfe7e953b3ec5d82e45f45ba7901b2d0e74 config-rpi.armhf 98943cedaa265f0e7a1b45ba12ee6bcc5118841b2ae1789036e475da640f2d3fa65e871cd8e184a1acdc3120bda98001de92682cdbaaaad737de7da4a50b9632 config-rpi2.armhf 89601aa0e4f77fb07fb1d58c6a9394c8683bc7dfc905ca6612d607ef4188637662d295fa3d5640e3e0a4cd08c98c10511a4f3cea41e7568167b12d0a6c813e8b markdt"