forked from nathanchance/env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi-kernel
executable file
·115 lines (96 loc) · 3.29 KB
/
pi-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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2018 Nathan Chancellor
#
# Script to build and install a Raspberry Pi kernel image
source "$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" || return; pwd)/common"
trap 'echo; die "Manually aborted!"' SIGINT SIGTERM
# Hide all non-error output unless verbosity is requsted
[[ ! "${*}" =~ "-v" ]] && exec > /dev/null
# Allow specification of 32-bit versus 64-bit
[[ "${*}" =~ "-32" ]] && ARCH=arm
[[ "${*}" =~ "-64" ]] && ARCH=arm64
[[ -z ${ARCH} ]] && ARCH=arm
# Kernel variable
KERNEL=kernel7
# Message file for Telegram messages
TG_MSG_FILE=$(mktemp)
trap 'rm -f "${TG_MSG_FILE}"' EXIT
# Check if we are compiling on the Raspberry Pi or not
[[ "$(whoami)" = "pi" ]] && PI=true
# Set toolchain to use
if [[ -n ${PI} ]]; then
cd "${HOME}/Documents/Kernel" || die "Kernel source doesn't exist!"
else
# SC2153: Possible misspelling: TC_FOLDER may not be assigned, but GCC_FOLDER is.
# shellcheck disable=SC2153
case "${*}" in
*"-7"*) GCC_FOLDER=${TC_FOLDER}/btg-linaro-gcc-7.3.1-${ARCH} ;;
*"-8"*) GCC_FOLDER=${TC_FOLDER}/btg-gcc-8.2.1-${ARCH} ;;
esac
[[ -z ${GCC_FOLDER} ]] && GCC_FOLDER=${TC_FOLDER}/btg-gcc-8.2.1-${ARCH}
GCC=$(find "${GCC_FOLDER}/bin" \( -type f -o -type l \) -name '*-gcc' | head -n1)
[[ -z ${GCC} ]] && die "GCC toolchain could not be found!"
CC=${GCC%gcc}
SOURCE_FOLDER=${HOME}/kernels/pi
cd "${SOURCE_FOLDER}" || die "Kernel source doesn't exist!"
fi
# Make function for both host and cross compiling
function kmake() {
if [[ -n ${PI} ]]; then
make "${JOBS_FLAG}" O=out "${@}"
else
make "${JOBS_FLAG}" ARCH=${ARCH} CROSS_COMPILE="${CCACHE} ${CC}" O=out "${@}"
fi
}
function build() {
START="$(date +"%s")"
{
echo "\`\`\`"
echo "Raspberry Pi kernel build starting..."
echo
echo "Version $(make kernelversion)"
echo "\`\`\`"
} > "${TG_MSG_FILE}"
[[ -n ${PI} || "${*}" =~ "-t" ]] && notify "$(cat "${TG_MSG_FILE}")"
rm -rf out
if [[ ${ARCH} = "arm" ]]; then
DEFCONFIG=bcm2709_defconfig
IMAGE=zImage
else
DEFCONFIG=bcmrpi3_defconfig
IMAGE=Image
fi
kmake "${DEFCONFIG}"
if time kmake "${IMAGE}" modules dtbs; then
RESULT_STRING="completed successfully"
else
RESULT_STRING="failed"
fi
{
TIME_STRING="$(format_time "${START}" "$(date +"%s")")"
echo "\`\`\`"
echo "Raspberry Pi kernel build ${RESULT_STRING}!"
echo
echo "Duration: ${TIME_STRING,,}"
echo "\`\`\`"
} > "${TG_MSG_FILE}"
[[ -n ${PI} || "${*}" =~ "-t" ]] && notify "$(cat "${TG_MSG_FILE}")"
if [[ -z ${PI} ]]; then
mkdir -p "${SOURCE_FOLDER}/out/pi_root"
kmake INSTALL_MOD_PATH="${SOURCE_FOLDER}/out/pi_root" modules_install
fi
}
function install() {
if [[ -f out/arch/arm/boot/zImage ]]; then
sudo make O=out modules_install
sudo cp out/arch/arm/boot/dts/*.dtb /boot/
sudo cp out/arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp out/arch/arm/boot/zImage /boot/$KERNEL.img
fi
}
[[ "${*}" =~ "-b" ]] && build "${@}"
[[ "${*}" =~ "-i" && ${PI} ]] && install