#!/bin/sh # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # # Create the kernel tree for a device: the pinned upstream commit with our # patches applied on top. The tree is build output (build/linux-), # never source; the source is the shared tree at the repository root # (../refs/linux/, KERNEL_REF in kernel/PIN) plus the patches. # # Usage: fetch-kernel.sh DEVICEDIR DESTDIR # # The shared tree is cloned locally (hardlinks, no network) and must be at # KERNEL_COMMIT; a drift is an error, not a silent fetch of something else. # A device that names KERNEL_COMMIT but no KERNEL_REF falls back to KERNEL_URL # (the old behaviour, for a device built from its own tree). # An existing DESTDIR is left alone. set -eu . "$(dirname "$0")/lib.sh" [ $# -eq 2 ] || { echo "usage: $0 DEVICEDIR DESTDIR" >&2; exit 2; } load_device "$1" dest=$2 # the device's own pin, else the shared one : "${KERNEL_URL:=}" "${KERNEL_COMMIT:=}" "${KERNEL_PATCHDIR:=}" "${KERNEL_REF:=}" env_url=$KERNEL_URL if [ -z "$KERNEL_COMMIT" ]; then . "$ROOT/kernel/PIN" fi [ -z "$env_url" ] || KERNEL_URL=$env_url patchdir=$ROOT/$KERNEL_PATCHDIR if [ -e "$dest/.git" ]; then echo "$dest exists, left alone" exit 0 fi if [ -n "$KERNEL_REF" ]; then case $KERNEL_REF in /*) ref=$KERNEL_REF ;; *) ref=$ROOT/../$KERNEL_REF ;; esac [ -e "$ref/.git" ] || die "$KERNEL_REF missing; run: git submodule update --init --depth 1 $KERNEL_REF" have=$(git -C "$ref" rev-parse HEAD) || die "cannot read $KERNEL_REF" [ "$have" = "$KERNEL_COMMIT" ] || die "$KERNEL_REF is at $have, kernel/PIN says $KERNEL_COMMIT" # local clone: hardlinks, no network, stays shallow git clone -q --no-checkout "$ref" "$dest" || die "cannot clone $KERNEL_REF" else git clone -q --no-checkout "$KERNEL_URL" "$dest" fi git -C "$dest" checkout -q "$KERNEL_COMMIT" # Reproducible commits: a fixed committer and each patch's own date as the # commit date, so the same series gives the same commit hashes -- and the # same kernel release name (setlocalversion appends -g), so modules # built in one fresh tree load with a kernel built in another. Without it # git am stamped the time of the run (2026-11-10: same source tree, # release names g4db1692fd and g425f6d5c4). for p in "$patchdir"/*.patch; do [ -e "$p" ] || break GIT_COMMITTER_NAME="Makronix Mobile" \ GIT_COMMITTER_EMAIL="mobile@makronix.invalid" \ git -C "$dest" am -q --committer-date-is-author-date "$p" || { echo "$0: $p does not apply" >&2; exit 1; } done git -C "$dest" log --oneline -3