kernel.inc (5792B)
1 #!/bin/sh 2 # mk/kernel.inc - shared kbuild recipe and config policy for the packages/linux 3 # template carried by each channel layer. Sourced at template top level via 4 # . "${UNOS_MKDIR}/kernel.inc" (UNOS_MKDIR is exported by the driver before the 5 # template is sourced). 6 # 7 # The template supplies only what is genuinely per-line -- version, checksum, 8 # distfiles -- then calls the standard phases: 9 # do_configure() { kernel_configure; } 10 # do_build() { kernel_build; } 11 # do_install() { kernel_install; } 12 # sub_linux_headers() { spick usr/include; } 13 # 14 # Conventions (locked here, not per template): 15 # - defconfig + explicit deltas + olddefconfig. Deltas and asserts are 16 # fail-loud: a renamed/vanished symbol breaks the build, never the boot. 17 # - modules_install with INSTALL_MOD_STRIP=1; build/source symlinks removed 18 # (absolute links into the build tree must never ship). Module dependency 19 # maps are generated at build time with host kmod depmod -b (explicit 20 # version: uname lies in containers) and asserted present. 21 # - headers = sanitized `headers_install` (user API). A module-build tree 22 # (full source for out-of-tree .ko like openbcm) is a separate follow-up, 23 # not silently half-shipped here. 24 # - KREL (e.g. 6.18.51, 7.3.0-rc3) is derived via `make kernelrelease`, 25 # never assumed from ${version}: pre-release trees differ (7.3_rc3 apk 26 # version vs 7.3.0-rc3 uname). All install paths use KREL. 27 # - Reproducibility: KBUILD_BUILD_USER/HOST/TIMESTAMP (from 28 # SOURCE_DATE_EPOCH, driver-exported). 29 30 # Feature policy is a property of UNOS, not of a kernel line: a switch needs 31 # the same dataplane whichever channel it tracks. Holding these here rather 32 # than in each layer's template is what stops lts, stable and edge from 33 # silently diverging. Symbols move between releases, so the asserts below are 34 # the tripwire -- a delta that stops applying breaks the build, never the boot. 35 KDELTA_ENABLE="IKCONFIG IKCONFIG_PROC NET_L3_MASTER_DEV IPV6_MULTIPLE_TABLES BLK_DEV_NVME MMC MMC_BLOCK BRIDGE VLAN_8021Q" 36 KDELTA_MODULE="NET_VRF" 37 KDELTA_DISABLE="" 38 KASSERT_Y="IPV6 IP_MULTIPLE_TABLES IPV6_MULTIPLE_TABLES NET_L3_MASTER_DEV DEVTMPFS_MOUNT BLK_DEV_INITRD SERIAL_8250_CONSOLE MODULES IKCONFIG IKCONFIG_PROC EFI_STUB BLK_DEV_NVME MMC MMC_BLOCK NVME_CORE BRIDGE VLAN_8021Q" 39 KASSERT_M="NET_VRF" 40 KASSERT_N="MODULE_SIG" 41 42 kernel_configure() { 43 cd "${WRKSRC}" 44 [ -f scripts/config ] || die "kernel: scripts/config missing" 45 # ARCH defaults to x86_64 for the primary target; aarch64 when cross-building 46 # (the conductor dispatches per-arch, builder calls ARCH=aarch64 make). 47 : "${ARCH:=x86_64}" 48 case "${ARCH}" in arm64) ARCH=aarch64 ;; esac 49 msg "kernel: defconfig (ARCH=${ARCH})" 50 make ARCH="${ARCH}" defconfig >/dev/null || die "kernel: defconfig failed" 51 for s in ${KDELTA_ENABLE:-}; do 52 ./scripts/config --enable "CONFIG_${s}" || die "kernel: cannot enable CONFIG_${s}" 53 done 54 for s in ${KDELTA_MODULE:-}; do 55 ./scripts/config --module "CONFIG_${s}" || die "kernel: cannot modularize CONFIG_${s}" 56 done 57 for s in ${KDELTA_DISABLE:-}; do 58 ./scripts/config --disable "CONFIG_${s}" || die "kernel: cannot disable CONFIG_${s}" 59 done 60 if [ -n "${KDELTA_ENABLE:-}${KDELTA_MODULE:-}${KDELTA_DISABLE:-}" ]; then 61 make ARCH="${ARCH}" olddefconfig >/dev/null || die "kernel: olddefconfig failed" 62 fi 63 for s in ${KASSERT_Y:-}; do 64 grep -qx "CONFIG_${s}=y" .config || die "kernel: CONFIG_${s} is not =y" 65 done 66 for s in ${KASSERT_M:-}; do 67 grep -qx "CONFIG_${s}=m" .config || die "kernel: CONFIG_${s} is not =m" 68 done 69 for s in ${KASSERT_N:-}; do 70 grep -qx "# CONFIG_${s} is not set" .config || die "kernel: CONFIG_${s} is set" 71 done 72 KREL=$(make -s ARCH="${ARCH}" kernelrelease) || die "kernel: kernelrelease failed" 73 [ -n "${KREL}" ] || die "kernel: empty KREL" 74 export KREL 75 msg "kernel: release ${KREL}" 76 } 77 78 kernel_build() { 79 cd "${WRKSRC}" 80 : "${ARCH:=x86_64}" 81 case "${ARCH}" in arm64) ARCH=aarch64 ;; esac 82 make ARCH="${ARCH}" -j"$(nproc)" \ 83 KBUILD_BUILD_USER=unos \ 84 KBUILD_BUILD_HOST=unos \ 85 KBUILD_BUILD_TIMESTAMP="$(date -u -d "@${SOURCE_DATE_EPOCH}" '+%Y-%m-%d %H:%M:%S')" \ 86 bzImage modules || die "kernel: build failed" 87 # bzImage path varies by arch 88 case "${ARCH}" in 89 x86_64) [ -f arch/x86/boot/bzImage ] || die "kernel: bzImage missing" ;; 90 aarch64) [ -f arch/arm64/boot/Image ] || die "kernel: Image missing (aarch64)" ;; 91 esac 92 } 93 94 kernel_install() { 95 cd "${WRKSRC}" 96 : "${ARCH:=x86_64}" 97 case "${ARCH}" in arm64) ARCH=aarch64 ;; esac 98 case "${ARCH}" in 99 x86_64) install -D -m 644 arch/x86/boot/bzImage "${DESTDIR}/boot/vmlinuz-${KREL}" ;; 100 aarch64) install -D -m 644 arch/arm64/boot/Image "${DESTDIR}/boot/vmlinuz-${KREL}" ;; 101 esac 102 ln -sf "vmlinuz-${KREL}" "${DESTDIR}/boot/vmlinuz" 103 install -D -m 644 System.map "${DESTDIR}/boot/System.map-${KREL}" 104 install -D -m 644 .config "${DESTDIR}/boot/config-${KREL}" 105 make ARCH="${ARCH}" INSTALL_MOD_PATH="${DESTDIR}" INSTALL_MOD_STRIP=1 \ 106 modules_install >/dev/null || die "kernel: modules_install failed" 107 # absolute build-tree symlinks must never ship 108 rm -f "${DESTDIR}/lib/modules/${KREL}/build" "${DESTDIR}/lib/modules/${KREL}/source" 109 make ARCH="${ARCH}" INSTALL_HDR_PATH="${DESTDIR}/usr" \ 110 headers_install >/dev/null || die "kernel: headers_install failed" 111 # dependency maps at build time (explicit version: uname lies in userns) 112 command -v depmod >/dev/null 2>&1 || die "kernel: host depmod missing" 113 depmod -b "${DESTDIR}" "${KREL}" || die "kernel: depmod failed" 114 [ -d "${DESTDIR}/lib/modules/${KREL}" ] || die "kernel: no modules dir" 115 [ -f "${DESTDIR}/lib/modules/${KREL}/modules.dep" ] || die "kernel: no modules.dep" 116 [ -f "${DESTDIR}/usr/include/linux/version.h" ] || die "kernel: no headers" 117 }