1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/usr/bin/env bash
# build-inc.sh: incremental build of os.mainlineKernel on april, for the
# kexec test loop (kexec-test.sh). See ../../../MAINLINE.md.
#
# Same tarball, patches, device trees, fragment, toolchain and make flags
# as ../../../build/kernel-mainline.go, but the source tree and object
# directory persist in april:~/tolino-ml, so a dts change rebuilds only
# the dtb and a driver change only its files: ~20 s instead of a full
# build. Not reproducible, and the fragment is merged without the
# builder's checks: when something works, build the real derivation.
#
# Prints the local directory holding zImage, the dtb and .config
# (./tmp/tolino/mainline-inc). Build output goes to stderr.
#
# The patched tree is rebuilt in a staging copy every time and synced into
# the build tree by content (rsync --checksum --no-times), so only files
# whose content changed get a new mtime, and make rebuilds only those.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
repo=$(git -C "$here" rev-parse --show-toplevel)
cd "$repo"
. "$here/april-check.sh"
T=users/Profpatsch/tolino/os/kernel/mainline
out=tmp/tolino/mainline-inc
mkdir --parents "$out"
d=$(nix-instantiate --attr users.Profpatsch.tolino.os.mainlineKernel 2>/dev/null)
env_json=$(nix derivation show "$d" 2>/dev/null)
get() {
python3 -c 'import json,sys; j=json.load(sys.stdin); print(list(j.values())[0]["env"][sys.argv[1]])' \
"$1" <<<"$env_json"
}
src=$(get src)
tc=$(get toolchain)
prefix=$(get prefix)
dtb=$(get dtb)
defconfig=$(get defconfig)
patch=$(get patch)
toolPath=$patch/bin:$(get toolPath)
# The inputs (tarball, toolchain, tools) onto april.
paths="$src $tc $patch $(tr : '\n' <<<"$toolPath" | sed 's|/bin$||')"
nix-store --realise $paths >/dev/null 2>&1
nix-copy-closure --to april $paths >&2
# Our inputs, by content.
ssh april 'mkdir -p tolino-ml/in'
rsync --recursive --checksum --delete \
"$T/patches" "$T/dts" "$T/config.fragment" april:tolino-ml/in/ >&2
# april runs Nix rootless (store under ~/.local/share/nix/root): store
# paths only exist inside its namespace, which `nix shell` enters.
ssh april nix shell "$patch" "$tc" --command bash -s -- \
"$src" "$tc" "$prefix" "$toolPath" "$dtb" "$defconfig" >&2 <<'EOF'
set -euo pipefail
src=$1 tc=$2 prefix=$3 toolPath=$4 dtb=$5 defconfig=$6
cd ~/tolino-ml
export PATH=$toolPath:$PATH
if [ ! -d pristine ] || [ "$(cat pristine.src 2>/dev/null)" != "$src" ]; then
rm -rf pristine linux obj
mkdir pristine
tar --use-compress-program=xz -xf "$src" -C pristine --strip-components=1
echo "$src" > pristine.src
fi
rm -rf staging
cp -a pristine staging
for p in $(ls in/patches/*.patch | sort); do
patch -d staging -p1 --forward --batch --quiet < "$p"
done
cp in/dts/* staging/arch/arm/boot/dts/allwinner/
printf '\ndtb-y += %s\n' "$dtb" >> staging/arch/arm/boot/dts/allwinner/Makefile
touch staging/.scmversion
mkdir -p linux obj
rsync --recursive --links --checksum --no-times --delete staging/ linux/
rm -rf staging
mk() {
make -C linux O=$PWD/obj -j"$(nproc)" ARCH=arm CROSS_COMPILE="$tc/bin/$prefix" \
KBUILD_BUILD_USER=tolino KBUILD_BUILD_HOST=nix \
"KBUILD_BUILD_TIMESTAMP=Thu Jan 1 00:00:00 UTC 1970" KBUILD_BUILD_VERSION=1 "$@"
}
# The config only when the fragment or the defconfig changed: defconfig
# plus the fragment, as merge_config.sh does.
want=$(cat in/config.fragment linux/arch/arm/configs/$defconfig | sha256sum)
if [ "$(cat obj/config.hash 2>/dev/null)" != "$want" ]; then
mk "$defconfig" >/dev/null
linux/scripts/kconfig/merge_config.sh -m -O obj obj/.config in/config.fragment >/dev/null
mk olddefconfig >/dev/null
echo "$want" > obj/config.hash
fi
# Not through a pipe: a failed build must fail (a stale zImage stays).
mk zImage "allwinner/$dtb" > obj/build.log 2>&1 || { tail -30 obj/build.log; exit 1; }
grep -v '^make\[' obj/build.log | tail -3
EOF
scp -q "april:tolino-ml/obj/arch/arm/boot/zImage" \
"april:tolino-ml/obj/arch/arm/boot/dts/allwinner/$dtb" \
"april:tolino-ml/obj/.config" "$out/"
echo "$out"
|