forked from simonvanderveldt/docker-rpi3-kernel-builder
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-rpi3-kernel
executable file
·76 lines (62 loc) · 2.4 KB
/
build-rpi3-kernel
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
#!/usr/bin/env bash
set -x -e
export LINUX_SRC_DIR=${LINUX_SRC_DIR:-${WORKDIR}/linux}
# Use -j<nproc> as default if MAKEFLAGS is not set
if [[ -z "${MAKEFLAGS}" ]]; then
export MAKEFLAGS="-j$(nproc)"
fi
# Start building the kernel
patch_dir_array=( "${PATCH_DIRS}" )
for patch_dir in "${patch_dir_array[@]}"
do
# Apply patches if `patch_dir` exists
if [ -d "${patch_dir}" ]; then
echo "Applying patches from ${patch_dir}"
for patch in "${patch_dir}/"*.patch; do
echo "Applying patch ${patch}"
patch -p1 < "${patch}"
done
fi
done
# Configure kernel
if [[ -v "${ALLCONFIG}" ]]; then
make KCONFIG_ALLCONFIG="${KCONFIG_ALLCONFIG:-arch/arm/configs/bcm2709_defconfig}" ${ALLCONFIG}
else
make "${DEFCONFIG:-bcm2709_defconfig}"
fi
# Store and print kernelrease
make kernelrelease
KERNEL_VERSION=$(make kernelrelease | grep "^[45].")
echo "Building kernel ${KERNEL_VERSION}"
# Build everything
make "${MAKEFLAGS}" zImage modules dtbs
# Package for each platform
for platform in $(cd platform && \ls -1d *)
do
# Copy to tmp destination
export TMP_DEST="/tmp/build.${platform}"
INSTALL_MOD_PATH="${TMP_DEST}" make modules_install
mkdir -p "${TMP_DEST}/boot/overlays"
cp arch/arm/boot/zImage "${TMP_DEST}/boot/kernel-${KERNEL_VERSION}.img"
cp arch/arm/boot/dts/*.dtb "${TMP_DEST}"/boot/
cp arch/arm/boot/dts/overlays/*.dtb* "${TMP_DEST}"/boot/overlays/
cp arch/arm/boot/dts/overlays/README "${TMP_DEST}"/boot/overlays/
# Copy config.txt to /boot if it exists
if [ -f platform/"${platform}"/config.txt ] ; then
cp platform/"${platform}"/config.txt "${TMP_DEST}"/boot/
# Add kernel version to config.txt
echo -e "\nkernel=kernel-${KERNEL_VERSION}.img" >> "${TMP_DEST}"/boot/config.txt
fi
# Copy cmdline.txt to /boot if it exists
if [ -f platform/"${platform}"/cmdline.txt ] ; then
cp platform/"${platform}"/cmdline.txt "${TMP_DEST}"/boot/
fi
# Compile and copy dt-blob.dts to /boot/dt-blob.bin if it exists
if [ -f dt-blob.dts ] ; then
./scripts/dtc/dtc -I dts -O dtb -o "${TMP_DEST}"/boot/dt-blob.bin dt-blob.dts
fi
# Create tar file of everything
mkdir -p "${BUILD_DEST}"
tar -cvzf "${BUILD_DEST}/kernel-${KERNEL_VERSION}-${platform}.tar.gz" -C $TMP_DEST .
sha256sum "${BUILD_DEST}/kernel-${KERNEL_VERSION}-${platform}.tar.gz" > "${BUILD_DEST}/kernel-${KERNEL_VERSION}-${platform}.sha256"
done