forked from niflostancu/rpi-debian-build-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-kernel.sh
executable file
·51 lines (40 loc) · 1.52 KB
/
build-kernel.sh
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
#!/bin/bash
# Cross-compiles a raspberry pi kernel (with optional patches).
set -eo pipefail
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/" && pwd)"
source "$SRC_DIR/lib/common.sh"
[[ -n "$KERNEL_DEST" ]] || log_fatal "No KERNEL_DEST given!"
KERNEL_BRANCH=${KERNEL_BRANCH:-"unknown_branch"}
KERNEL_ARCH=${KERNEL_ARCH:-"arm64"}
KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:-"unknown_defconfig"}
KERNEL_LOCALVERSION=${KERNEL_LOCALVERSION:-'-rpi'}
if [[ ! -d "$KERNEL_DEST" ]]; then
mkdir -p "$(dirname "$KERNEL_DEST")"
git clone --depth=1 https://github.com/raspberrypi/linux \
--branch "$KERNEL_BRANCH" --single-branch "$KERNEL_DEST"
fi
cd "$KERNEL_DEST"
pwd
if [[ -n "$KERNEL_PATCHES_DIR" ]] && [[ -d "$KERNEL_PATCHES_DIR" ]]; then
log_info "Using patch dir: $KERNEL_PATCHES_DIR"
for pfile in "$KERNEL_PATCHES_DIR/"*.patch; do
# idempotency: check if patch has already been applied
if ! patch -R -p1 -s -f --dry-run <"$pfile"; then
log_debug "Applying patch $pfile"
patch -p1 < "$pfile"
fi
done
fi
if [[ "$CLEAN" == "1" ]]; then
make clean
fi
MAKE_ARGS=(ARCH="$KERNEL_ARCH" CROSS_COMPILE="$CROSS_COMPILER")
# kernel configuration phase
make "${MAKE_ARGS[@]}" "$KERNEL_DEFCONFIG"
if [[ -n "$KERNEL_LOCALVERSION" ]]; then
./scripts/config --set-str LOCALVERSION "$KERNEL_LOCALVERSION"
fi
# compilation phase
make "${MAKE_ARGS[@]}" -j "$KERNEL_MAKE_THREADS" Image modules dtbs
# finally: generate .dep with binaries
make "${MAKE_ARGS[@]}" -j "$KERNEL_MAKE_THREADS" bindeb-pkg