-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-kernel.sh
executable file
·59 lines (53 loc) · 1.38 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
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Environment
## make
export ARCH=arm64
export TARGET=shrink_defconfig
## dir
export WORKDIR=$(pwd)
export SOURCE=raspberrypi-kernel
export KERNEL_REPO=kernel
export TEMP_DIR=temp
set -e
# Prepare
## mkdir
cd ${WORKDIR}
if [ ! -d "${SOURCE}" ]; then
echo "No raspberrypi-kernel. Wrong Path!"
exit 1
fi
if [ ! -d "${KERNEL_REPO}" ]; then
echo "No kernel-repo."
mkdir ${KERNEL_REPO}
cd ${WORKDIR}/${KERNEL_REPO}
git init .
fi
mkdir ${TEMP_DIR}
## clean
cd ${WORKDIR}/${SOURCE} && make mrproper
cd ${WORKDIR}/${KERNEL_REPO} && git rm -r .
cd ${WORKDIR}/${TEMP_DIR} && rm -rf *
# Compile
cd ${WORKDIR}/${SOURCE}
## kernel
make ${TARGET} && make -j$($(nproc) || echo 4)
# Collect
## kernel
make INSTALL_MOD_PATH=${WORKDIR}/${TEMP_DIR}/ modules_install
cp ${WORKDIR}/${SOURCE}/arch/${ARCH}/boot/Image ${WORKDIR}/${TEMP_DIR}/
## device tree binary
cp ${WORKDIR}/${SOURCE}/arch/${ARCH}/boot/dts/broadcom/*.dtb ${WORKDIR}/${TEMP_DIR}/
mkdir ${WORKDIR}/${TEMP_DIR}/overlays
cp ${WORKDIR}/${SOURCE}/arch/${ARCH}/boot/dts/overlays/*.dtb* ${WORKDIR}/${TEMP_DIR}/overlays/
# Finish
cd ${WORKDIR}
## size
SIZE=$(du -d 0 ${TEMP_DIR} | awk '{print $1}')
## target_defconfig
cp ${WORKDIR}/${SOURCE}/arch/${ARCH}/configs/${TARGET} ${WORKDIR}/${TEMP_DIR}
## mv
cp -rf ${WORKDIR}/${TEMP_DIR}/* ${WORKDIR}/${KERNEL_REPO}/
# Git
cd ${WORKDIR}/${KERNEL_REPO}
git add .
git commit -m "${SIZE}"