# Maintainer: John Vogel maintainer="John Vogel " _flavor=dragon pkgname=linux-$_flavor pkgver=7.0.11 _kernver=${pkgver%.*} pkgrel=0 pkgdesc="Linux mainline (development kernel for Radxa Dragon Q6A" url="https://www.kernel.org" depends="initramfs-generator" _depends_dev="perl gmp-dev mpc1-dev mpfr-dev elfutils-dev bash flex bison zstd" makedepends="$_depends_dev bc bpftool diffutils elfutils findutils gcc>=13.1.1_git20230624 grep installkernel linux-firmware-qcom linux-firmware-realtek linux-firmware-rtl_nic linux-headers mawk openssl-dev>3 pahole python3 sed zstd " options="!strip !check" source="https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz https://stygian.me/distfiles/dragon-$pkgver-alpine.patch 0001-arm64-dts-qcom-kodiak-avoid-EFI-overlap-for-ADSP-rem.patch 0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch 0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch 0003-kexec-add-kexec_load_disabled-boot-option.patch 0004-objtool-respect-AWK-setting.patch 0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch tools-headers.patch dragon.aarch64.config " subpackages="$pkgname-dev:_dev:$CBUILD_ARCH $pkgname-doc" for _i in $source; do case $_i in *.$CARCH.config) _f=${_i%."$CARCH".config} _flavors="$_flavors $_f" if [ "linux-$_f" != "$pkgname" ]; then subpackages="$subpackages linux-$_f::$CBUILD_ARCH linux-$_f-dev:_dev:$CBUILD_ARCH" fi ;; esac done builddir="$srcdir"/linux-"$_kernver" if [ "${pkgver%.0}" = "$pkgver" ]; then # Prepend to apply first source="patch-$pkgver.patch.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz $source" fi arch="aarch64" license="GPL-2.0-only" prepare() { default_prepare # remove localversion from patch if any rm -f localversion* } _kernelarch() { local arch="$1" case "$arch" in aarch64*) arch="arm64" ;; *) arch="" ;; esac echo "$arch" } _prepareconfig() { local _flavor="$1" local _arch="$2" local _config=$_flavor.$_arch.config local _builddir="$srcdir"/build-$_flavor.$_arch mkdir -p "$_builddir" echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine cp "$srcdir"/$_config "$_builddir"/.config msg "Configuring $_flavor kernel ($_arch)" make -C "$builddir" \ O="$_builddir" \ ARCH="$(_kernelarch $_arch)" \ olddefconfig if grep "CONFIG_MODULE_SIG=y" "$_builddir"/.config >/dev/null; then if [ -f "$KERNEL_SIGNING_KEY" ]; then sed -i -e "s:^CONFIG_MODULE_SIG_KEY=.*:CONFIG_MODULE_SIG_KEY=\"$KERNEL_SIGNING_KEY\":" \ "$_builddir"/.config msg "Using $KERNEL_SIGNING_KEY to sign $_flavor kernel ($_arch) modules" else warning "KERNEL_SIGNING_KEY was not set. A signing key will be generated, but 3rd" warning "party modules can not be signed" fi fi } listconfigs() { for i in $source; do case "$i" in *.config) echo $i;; esac done } prepareconfigs() { for _config in $(listconfigs); do local _flavor=${_config%%.*} local _arch=${_config%.config} _arch=${_arch#*.} local _builddir="$srcdir"/build-$_flavor.$_arch _prepareconfig "$_flavor" "$_arch" done } # this is supposed to be run before version is bumped so we can compare # what new kernel config knobs are introduced prepareupdate() { clean && fetch && unpack && prepare && deps prepareconfigs rm -r "$builddir" } updateconfigs() { if ! [ -d "$builddir" ]; then deps && fetch && unpack && prepare fi for _config in ${CONFIGS:-$(listconfigs)}; do msg "updating $_config" local _flavor=${_config%%.*} local _arch=${_config%.config} _arch=${_arch#*.} local _builddir="$srcdir"/build-$_flavor.$_arch mkdir -p "$_builddir" echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine local actions="listnewconfig oldconfig" if ! [ -f "$_builddir"/.config ]; then cp "$srcdir"/$_config "$_builddir"/.config actions="olddefconfig" fi env | grep ^CONFIG_ >> "$_builddir"/.config || true make -j1 -C "$builddir" \ O="$_builddir" \ ARCH="$(_kernelarch $_arch)" \ $actions savedefconfig cp "$_builddir"/defconfig "$startdir"/$_config done } set_kbuild_timestamp() { # KBUILD_BUILD_TIMESTAMP needs to be parsable by busybox date export KBUILD_BUILD_TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S' -u${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})" } build() { unset LDFLAGS # for some reason these sometimes leak into the kernel build, # -Werror=format-security breaks some stuff unset CFLAGS CPPFLAGS CXXFLAGS set_kbuild_timestamp for i in $_flavors; do _prepareconfig "$i" "$CARCH" done for i in $_flavors; do msg "Building $i kernel" cd "$srcdir"/build-$i.$CARCH # set org in cert for modules signing # https://www.kernel.org/doc/html/v6.1/admin-guide/module-signing.html#generating-signing-keys mkdir -p certs sed -e 's/#O = Unspecified company/O = alpinelinux.org/' \ "$builddir"/certs/default_x509.genkey \ > certs/x509.genkey make ARCH="$(_kernelarch $CARCH)" \ CC="${CC:-gcc}" \ AWK="${AWK:-mawk}" \ KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" if grep -q '^CONFIG_DEBUG_INFO_BTF=y' .config; then # Generate vmlinux.h bpftool btf dump file vmlinux format c > vmlinux.h if [ "$CARCH" = "ppc64le" ]; then # ppc64le installs the uncompressed vmlinux, which is extremely # large with BTF debuginfo unless stripped eu-strip --remove-comment vmlinux fi fi done } _package() { local _buildflavor="$1" _outdir="$2" set_kbuild_timestamp cd "$srcdir"/build-$_buildflavor.$CARCH local _abi_release="$(make -s kernelrelease)" # modules_install seems to regenerate a defect Modules.symvers on s390x. Work # around it by backing it up and restore it after modules_install cp Module.symvers Module.symvers.backup mkdir -p "$_outdir"/boot "$_outdir"/lib/modules local _install case "$CARCH" in arm*|aarch64|riscv*) _install="zinstall dtbs_install";; *) _install=install;; esac make modules_install $_install \ ARCH="$(_kernelarch $CARCH)" \ INSTALL_MOD_PATH="$_outdir" \ INSTALL_MOD_STRIP=1 \ INSTALL_PATH="$_outdir"/boot \ INSTALL_DTBS_PATH="$_outdir/boot/dtbs-$_buildflavor" cp Module.symvers.backup Module.symvers 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/$_buildflavor/kernel.release } # main flavor installs in $pkgdir package() { depends="$depends linux-firmware-any" _package "$_flavor" "$pkgdir" # copy files for linux-stable-doc sub package mkdir -p "$pkgdir"/usr/share/doc cp -r "$builddir"/Documentation \ "$pkgdir"/usr/share/doc/linux-stable-doc-"$pkgver"/ # remove files that aren't part of the documentation itself for nondoc in .gitignore conf.py docutils.conf Kconfig Makefile; do rm "$pkgdir"/usr/share/doc/linux-stable-doc-"$pkgver"/"$nondoc" done # create /usr/share/doc/linux-stable-doc symlink cd "$pkgdir"/usr/share/doc; ln -s linux-stable-doc-"$pkgver" linux-stable-doc } _dev() { local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g') local _builddir="$srcdir"/build-$_flavor.$CARCH local _abi_release="$(make -C "$_builddir" -s kernelrelease)" local _karch="$(_kernelarch $CARCH | sed 's/x86_64/x86/')" # copy the only the parts that we really need for build 3rd party # kernel modules and install those as /usr/src/linux-headers, # similar 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" set_kbuild_timestamp # first we import config, run prepare to set up for building # external modules, and create the scripts mkdir -p "$dir" cp -a "$_builddir"/.config "$_builddir"/localversion-alpine \ "$dir"/ install -D -t "$dir"/certs "$_builddir"/certs/signing_key.x509 || : # Install vmlinux.h if grep -q '^CONFIG_DEBUG_INFO_BTF=y' "$_builddir"/.config; then install -Dm644 "$_builddir"/vmlinux.h -t "$dir/" fi make -C "$builddir" \ O="$dir" \ ARCH="$(_kernelarch $CARCH)" \ AWK="${AWK:-mawk}" \ prepare modules_prepare scripts # remove the stuff that points to real sources. we want 3rd party # modules to believe this is the sources 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' -o -name 'Platform' \) \ -print | cpio -pdm "$dir" cp -a scripts include "$dir" find "arch/$_karch" "tools/include" "tools/arch/$_karch" -type f -path '*/include/*' \ -print | cpio -pdm "$dir" install -Dm644 "$srcdir"/build-$_flavor.$CARCH/Module.symvers \ "$dir"/Module.symvers # remove unneeded things msg "Removing documentation..." rm -r "$dir"/Documentation sed -i -e '/Documentation/d' "$dir"/Kconfig find "$dir" -type f \( -name '*.o' -o -name '*.cmd' \) -exec rm -v -- {} + mkdir -p "$subpkgdir"/lib/modules/"$_abi_release" ln -sf /usr/src/linux-headers-"$_abi_release" \ "$subpkgdir"/lib/modules/"$_abi_release"/build } sha512sums=" 6e20f47171270b47774b1f62f96b81a498544894ccc3c027785c0aec6751ad7b55dc96bc0fcdc52ea7cad57a1501fc651d024a2ac51383e3d753b0dcaeafb76d patch-7.0.11.patch.xz 8c85b708342f8f09ca25b2234b22e93b62b144a9ef919fbb21827f52fa47498e778c79db1559524dd7fb360f95b2ce174171443c1859656c281be41d2b6c5a0b linux-7.0.tar.xz 73b5860e4bec31a2c81c768fd4c00c198d48f7ef4b13bc78a98a95ab3e5ef3b5d95f1dfc8fd0be22f088b8b864f153d3a6e185969ef89d58f920ef262c992e3d dragon-7.0.11-alpine.patch fe4716f94a10fba23504d1439e52630b68ab92f3c0943378540a1d3c8549039b78949a3345e60fc487b605f33ca5db9440101a07052e5771545b045d99e3c9be 0001-arm64-dts-qcom-kodiak-avoid-EFI-overlap-for-ADSP-rem.patch ce735e313a409147e51c429512bc94515f3e8bf23c19cccf2ef2d65c42587ead9a4657ba6dd63934929e3c83680d930b4ef4fb1511db6080286929f84329ebc0 0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch 25ff1b351d1aeb2a892260a90e6ba2179b217e7f961e397a5a6e91621aef8c41ef9e952d351502a12f96aea6f5ebf3a846478dd3d615ac3b31448e06b6ad24e2 0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch 7651ef4f896e2da3a6c002b04b42ada27809efd10eb4a15dace6e9ef2e67c69135f30d2ff2f29854749d57e383b6c45c9ad16f0e53b3e03a7ef93e760f591b1c 0003-kexec-add-kexec_load_disabled-boot-option.patch 3ee2ede7354e8f37cab474f06d90dc70aad4ab6b51de68782018a3a93835c608daf4d97151376bb8d7054ea43bb675ef26a4750f9c2a9d562ef3ef55718fa197 0004-objtool-respect-AWK-setting.patch a2170a58f5bc7eba7591f28d2329077027f276e84c2bb2af875cd787d0f37ef17f348d28bc9e1ede6154030283b2c9759e53bf6f3fc7dcd6f112b2c426cc184d 0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch fc6c32491ef1388a0efc8f499c776042c9596f4137e452ccd1c6435323cbb4c47fa0c1a632ee022b3cd1ca4797ef0917aa93369004c846ba1b68aa9492741074 tools-headers.patch 1cb18f3d44a4c688595e4e0b2a5e4c6b98e51f62d5e3cc099b8f3f20fd45ae0845fc14740336fc1f078491bc44ff587ddfacd631582657d1a735092073ce6f60 dragon.aarch64.config "