diff --git a/build.sh b/build.sh index b970a27..3423a7c 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -# script requires: git cpio make patch rpm python3 wget +# script requires: git tar xz cpio make patch rpm python3 wget # kernel requires: gcc flex bison make openssl-devel elfutils-libelf-devel bc perl-devel double-conversion-devel qt5-qtbase-devel libXi-devel rpm-build -KERNEL_VERSION="6.19.10" -LOCAL_VERSION="300.fc44" -TAG="latest" +DISTRO_VERSION="44" +LOCAL_VERSION=${KERNEL_VERSION:=6.19.10}-300.fc${DISTRO_VERSION}.ms-r1 JOBS=$(nproc) BUILD=$(pwd) CROSS="aarch64-linux-gnu-" @@ -16,23 +15,17 @@ LOGS=$BUILD/logs log() { printf '[%s] %s\n' "$(date '+%H:%M:%S')" "$*"; } die() { printf '[%s] ERROR: %s\n' "$(date '+%H:%M:%S')" "$*"; exit 1; } -if [ -n "$REMOVE" ]; then - ver=${KERNEL_VERSION}-${LOCAL_VERSION}.ms-r1 +uninstall() { log "removing modules" - pkexec rm -rf /lib/modules/$ver* || die "failed" - log "removing boot files" - pkexec rm -f /boot/vmlinuz-$ver* /boot/initrd-$ver* /boot/initramfs-$ver* /boot/System.map-$ver* /boot/config-$ver* || die "failed" - pkexec find /boot/loader/entries -name "*-${KERNEL_VERSION}-${LOCAL_VERSION}.ms-r1*" -delete || die "failed" - log "done"; exit 0 -fi + pkexec rm -rf /lib/modules/$LOCAL_VERSION* || die "failed" + log "removing boot images and configs" + pkexec find /boot -name "*-$LOCAL_VERSION*" -delete || die "failed" + log "done" +} +[ -z "$UNINSTALL" ] || { uninstall; exit 0; } [ -z "$CLEAN" ] || rm -rf $KERNEL_TREE $KERNEL_CORE $KERNEL_PATCHES $LOGS; mkdir -p "$LOGS" -log "building linux kernel ${KERNEL_VERSION} with sky1-${TAG} patches" - -if [ ! -d "$KERNEL_TREE" ]; then - log "cloning linux kernel repository" - git clone --depth=1 --branch=v$KERNEL_VERSION https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git "$KERNEL_TREE" > /dev/null 2>&1 || die "failed" -fi +log "building linux kernel ${KERNEL_VERSION} for Fedora ${DISTRO_VERSION} with sky1-${TAG:=latest} patches" append() { local series=$KERNEL_PATCHES/patches/series @@ -48,7 +41,7 @@ rebase() { } if [ ! -d "$KERNEL_PATCHES" ]; then - log "preparing for patching" + log "cloning linux-sky1 repository" git clone --depth=1 https://github.com/Sky1-Linux/linux-sky1.git > /dev/null 2>&1 || die "failed" cd $KERNEL_PATCHES rebase srcshelton main # patches: fix Kconfig deps and module reachability @@ -63,6 +56,16 @@ if [ ! -d "$KERNEL_PATCHES" ]; then rebase hotschmoe scmi-cpufreq-boost-param # cpufreq: scmi: add a boost parameter that holds from policy creation rebase lpennisi73-tech usb-cdns3-null-guards # patches: add cdns3 NULL guards for the early role switch and runtime … rebase lpennisi73-tech amvx-mmu-flexible-array-vb2-lock # patches: add amvx MMU flexible-array and vb2 queue lock fixes (6.18) +fi + +get() { + if [ -f "/tmp/$1" ]; then log "using cached file /tmp/$1" >&2; cat "/tmp/$1" + else wget -q -O "/tmp/$1" "$2/$1" || die "failed" >&2; cat "/tmp/$1"; fi +} + +if [ ! -d "$KERNEL_TREE" ]; then + log "downloading linux kernel source tree" + get "linux-${KERNEL_VERSION}.tar.xz" "https://www.kernel.org/pub/linux/kernel/v${KERNEL_VERSION:0:1}.x/" | tar -xf - -C $BUILD --xz log "applying patches" output="$LOGS/patches.log"; echo "" > $output for p in "$KERNEL_PATCHES/patches-${TAG}"/*.patch; do @@ -73,19 +76,14 @@ fi if [ ! -d "$KERNEL_CORE" ]; then log "downloading fedora kernel core" - rpm=/tmp/kernel-core.aarch64.rpm - if [ -f "$rpm" ]; then log "using cached file $rpm" - else wget -q -O "$rpm" "https://download.fedoraproject.org/pub/fedora/linux/releases/44/Everything/aarch64/os/Packages/k/kernel-core-${KERNEL_VERSION}-${LOCAL_VERSION}.aarch64.rpm" || die "failed"; fi - mkdir -p $KERNEL_CORE - cd $KERNEL_CORE - rpm2cpio "$rpm" | cpio -idm --quiet "./lib/modules/*" + get "kernel-core-${KERNEL_VERSION}-300.fc${DISTRO_VERSION}.aarch64.rpm" "https://download.fedoraproject.org/pub/fedora/linux/releases/${DISTRO_VERSION}/Everything/aarch64/os/Packages/k/" | rpm2cpio - | cpio -D $KERNEL_CORE -idm --quiet "./lib/modules/*" fi if [ ! -f "$KERNEL_TREE/.config.ms-r1" ] || [ -n "$REBUILD" ]; then log "configuring kernel" cd $KERNEL_TREE make mrproper > /dev/null 2>&1 - cp "$KERNEL_CORE/lib/modules/${KERNEL_VERSION}-${LOCAL_VERSION}.aarch64/config" .config-fedora + cp "$KERNEL_CORE/lib/modules/${KERNEL_VERSION}-300.fc44.aarch64/config" .config-fedora cp "$KERNEL_PATCHES/config/config.sky1-${TAG}" .config-sky1 ./scripts/kconfig/merge_config.sh -m -O . .config-fedora .config-sky1 > /dev/null ./scripts/kconfig/merge_config.sh -m -O . .config "$BUILD/config/ms-r1.fragment" > /dev/null @@ -93,12 +91,10 @@ if [ ! -f "$KERNEL_TREE/.config.ms-r1" ] || [ -n "$REBUILD" ]; then make ARCH=arm64 CROSS_COMPILE=$CROSS olddefconfig > /dev/null 2>&1 fi -log "compiling kernel" -make -C "$KERNEL_TREE" ARCH=arm64 CROSS_COMPILE=$CROSS -j"$JOBS" Image modules > "$LOGS/build.log" 2>&1 || die "failed (see logs/build.log)" - +log "compiling kernel"; make -C "$KERNEL_TREE" ARCH=arm64 CROSS_COMPILE=$CROSS -j"$JOBS" Image modules > "$LOGS/build.log" 2>&1 || die "failed (see logs/build.log)" log "done" -log "note: run this script with INSTALL=1 to trigger kernel install (requires root privileges)" -[ -n "$INSTALL" ] || exit 0 +[ -n "$INSTALL" ] || { log "note: run this script with INSTALL=1 to trigger kernel install (requires root privileges)"; exit 0; } +[ -z "$(find /boot -maxdepth 1 -name "*-${LOCAL_VERSION}*" 2> /dev/null)" ] || { log "removing previously built kernel ${LOCAL_VERSION}"; uninstall; } -log "installing kernel" -pkexec make -C "$KERNEL_TREE" ARCH=arm64 modules_install install +log "installing kernel"; pkexec make -C "$KERNEL_TREE" ARCH=arm64 modules_install install > "$LOGS/install.log" 2>&1 || die "failed (see logs/install.log)" +log "done"