# Maintainer: Antoine Martin (ayakael) # Contributor: Antoine Martin (ayakael) pkgname=linux-rm pkgver=5.4.70 _rmver=1.3.3 pkgrel=2 pkgdesc="Linux kernel with reMarkable patches" url=https://github.com/reMarkable/linux depends="initramfs-generator linux-firmware-brcm linux-firmware-cypress" _depends_dev="perl gmp-dev elfutils-dev bash mpc1-dev mpfr-dev" makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware mawk bison flex openssl-dev>3 diffutils pahole findutils xz lzop " options="!strip !check" builddir="$srcdir"/linux-RM1XX_${pkgver}_v$_rmver source=" https://github.com/reMarkable/linux/archive/refs/tags/RM1XX_${pkgver}_v$_rmver.tar.gz enable-automatic-partial-refreshing.patch enable-sdhc1.patch config-changes-rm.armv7 config-changes-rm.armhf " arch="armv7 armhf" license="GPL-2.0" for _i in $source; do case $_i in config-*.$CARCH) _f=${_i%."$CARCH"} _f=${_f#config-changes-} _flavors="$_flavors $_f" [ "linux-$_f" != "$pkgname" ] && subpackages="$subpackages linux-$_f::$CTARGET_ARCH" subpackages="$subpackages linux-$_f-dev:_dev:$CBUILD_ARCH" ;; esac done _carch=$CARCH case "$CARCH" in aarch64) _carch="arm64" ;; arm*) _carch="arm" ;; esac # generate config from defconfig and apply local changes. # config-changes-$flavor.$CARCH holds a list of = delimited # config command and values used by kernel scripts/config script. _genconfig() { local flavor=$1 defconfig= local subbuilddir="$srcdir"/build-$flavor local defconfig= case $flavor in rm) defconfig=zero-gravitas_defconfig ;; rm2) defconfig=zero-sugar_defconfig ;; *) die "Unknown flavor: $flavor" ;; esac cp "$builddir"/arch/$_carch/configs/$defconfig \ "$subbuilddir"/.config while read -r line; do # skip comments case "$line" in "#"*) continue;; esac local option=${line%%=*} str= local cmd=$(echo $line | cut -d= -f2) case "$cmd" in y) cmd="enable";; n) cmd="disable";; m) cmd="module";; '"'*) cmd="set-str"; str="${line#*=}";; [0-9]*) cmd="set-val"; str="${line#*=}";; *) die "Command $cmd not accepted" ;; esac msg "[$flavor] $cmd: $option $str" "$builddir"/scripts/config \ --file "$subbuilddir"/.config \ --$cmd "$option" "${str//\"/}" done < "$srcdir"/config-changes-$flavor.$CARCH } # verify if options are set to correct value _verifyconfig() { local flavor=$1 local subbuilddir="$srcdir"/build-$flavor while read -r line; do [ ${line:0:1} = "#" ] && continue local option=${line%%=*} str= invert= local cmd=$(echo $line | cut -d= -f2) case "$cmd" in enable) str="$option=y" ;; disable) str="$option"; invert="-v" ;; module) str="$option=m" ;; set-val) str="$option=${line##*=}" ;; set-str) str=${line##*=} str="$option=\"${str//\"/}\"" ;; esac grep -q $invert "^$str" "$subbuilddir"/.config || \ die "Config: $option not properly set!" done < "$srcdir"/config-changes-$flavor.$CARCH } prepare() { default_prepare local flavor= for flavor in $_flavors; do local _builddir="$srcdir"/build-$flavor mkdir -p "$_builddir" echo "-$pkgrel-$flavor" > "$_builddir"/localversion-alpine _genconfig $flavor make -C "$builddir" \ O="$_builddir" \ ARCH="$_carch" \ olddefconfig _verifyconfig $flavor done } build() { unset LDFLAGS for i in $_flavors; do cd "$srcdir"/build-$i local _kver=$(make kernelversion) if [ "$_kver" != "$pkgver" ]; then error "Version in Makefile ($_kver) does not correspond with pkgver ($pkgver)" return 1 fi make ARCH="$_carch" CC="${CC:-gcc}" KLZOP="/usr/bin/lzop" \ KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" done } _package() { local _flavor="$1" _outdir="$2" local _builddir="$srcdir"/build-$_flavor local _abi_release="$(make -C "$_builddir" -s kernelrelease)" cd "$srcdir"/build-$_flavor mkdir -p "$_outdir"/boot "$_outdir"/lib/modules local _install="zinstall dtbs_install" cd "$srcdir"/build-$_flavor # modules_install seems to regenerate a defect Modules.symvers. Work # around it by backing it up and restore it after modules_install cp Module.symvers Module.symvers.backup local INSTALL_DTBS_PATH="$_outdir"/boot make -j1 modules_install $_install \ ARCH="$_carch" \ INSTALL_MOD_PATH="$_outdir" \ INSTALL_MOD_STRIP=1 \ INSTALL_PATH="$_outdir"/boot \ INSTALL_DTBS_PATH="$INSTALL_DTBS_PATH" cp Module.symvers.backup Module.symvers cp "$_builddir"/arch/arm/boot/zImage "$_outdir"/boot/zImage rm "$_outdir"/boot/vmlinuz-$_flavor rm -f "$_outdir"/lib/modules/$_abi_release/build \ "$_outdir"/lib/modules/$_abi_release/source rm -rf "$_outdir"/lib/firmware install -D -m644 include/config/kernel.release \ "$_outdir"/usr/share/kernel/$_flavor/kernel.release } # main flavor installs in $pkgdir package() { _package rm "$pkgdir" } # subflavors install in $subpkgdir rm2() { depends="initramfs-generator linux-firmware-brcm linux-firmware-cypress" _package rm2 "$subpkgdir" } _dev() { local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g') local _builddir="$srcdir"/build-$_flavor local _abi_release="$(make -C "$_builddir" -s kernelrelease)" # 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 $_flavor kernel" depends="$_depends_dev" 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 "$_builddir"/.config "$dir"/.config echo "-$pkgrel-$_flavor" > "$dir"/localversion-alpine make -j1 -C "$builddir" \ O="$dir" \ ARCH="$_carch" \ AWK="${AWK:-mawk}" \ syncconfig prepare modules_prepare scripts # remove the stuff that points 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/ubuntu/ubuntu-zesty.git/tree/debian/rules.d/3-binary-indep.mk cd "$builddir" 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' \) \ -print | cpio -pdm "$dir" cp -a scripts include "$dir" # shellcheck disable=SC2046 find $(find arch -name include -type d -print) -type f \ | cpio -pdm "$dir" install -Dm644 "$_builddir"/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 } sha512sums=" 80ab274ca3d30935d9913490662f17499c1ceedb438fe171554097d25ffc1cf85ee53f0c1642e94c0b833fdfb17636cd554bf685e4a6f5dac20cf122c1a25447 RM1XX_5.4.70_v1.3.3.tar.gz 0f47278c5bfafb939e46224fbf16f9491e3cc560ac128dcf430a1f6cf9064fb1c5bf5db1a3076c35d30c004aec525a7d6616a647564f197bb29c57701c1db982 enable-automatic-partial-refreshing.patch 6f2036a2f88b0d80ba5e37e3d119aebd2dc33453f5a5d84b319ec50c0c00d8cb93fc4b3f5e10f3d56c1496f3cb297551c405f36c5d864af112398f0792f1549a enable-sdhc1.patch 7f118de35f63960c0d9dc8d8ed56c4097006a3545d4672b618b1d430a7a9c018dbda4c2bfe900cd013c5f65766ddd62b1638ddfeb1bafde307f77d25891bd438 config-changes-rm.armv7 7f118de35f63960c0d9dc8d8ed56c4097006a3545d4672b618b1d430a7a9c018dbda4c2bfe900cd013c5f65766ddd62b1638ddfeb1bafde307f77d25891bd438 config-changes-rm.armhf "