-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_kernel
More file actions
executable file
·95 lines (73 loc) · 3.38 KB
/
build_kernel
File metadata and controls
executable file
·95 lines (73 loc) · 3.38 KB
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
#!/bin/bash
#This script will build and install new kernel on a Raspberry Pi 4
# exits the script when any command fails
set -e
# specifying all excutables' paths
readonly SUDO=/usr/bin/sudo
readonly APT=/usr/bin/apt
# installs all prerequisite packages
$SUDO $APT install -y raspberrypi-kernel-headers build-essential bc git wget bison flex libssl-dev make tar sed grep bc
# specifying all excutables' paths for newly installed packages and some file names
readonly RM=/bin/rm
readonly MKDIR=/bin/mkdir
readonly SED=/bin/sed
readonly MAKE=/usr/bin/make
readonly CP=/bin/cp
readonly GIT=/usr/bin/git
readonly BASH=/bin/bash
readonly PKILL=/usr/bin/pkill
readonly TAR=/bin/tar
readonly UNAME=/bin/uname
readonly TEE=/usr/bin/tee
readonly FIRST_PERF_SCRIPT=first_perf_script
readonly SECOND_PERF_SCRIPT=second_perf_script
readonly REBOOT=/sbin/reboot
# stops other running scripts if received an interrupting signal
trap stop_other_scripts SIGHUP SIGINT SIGTERM
stop_other_scripts() {
# sends a USR1 signal to first performance script so it can exit, then kills the process
$SUDO $PKILL --signal USR1 -f $FIRST_PERF_SCRIPT
# sends a USR2 signal to second performance script so it can reset led and exit, then kills the process
$SUDO $PKILL --signal USR2 -f $SECOND_PERF_SCRIPT
# resets led trigger state to default. This is a backup command in addition to the one in the second perf script
echo mmc0 | $SUDO $TEE /sys/class/leds/led0/trigger
}
# creates a working directory for the scripts (deletes the folder if it already exists and creates a new one)
$SUDO $RM -r -f workdir; $MKDIR workdir
cd workdir || exit
# checks outs to my git repo using SSH (note: you will need a SSH key pair)
$GIT clone git@github.com:s3714110/RaspberryPi4Kernel.git
# creates a backup of the current kernel modules and compresses it into a tar file
$TAR -c -f kernel-backup.tar "/lib/modules/$($UNAME -r)"
# creates a backup of the boot folder and compresses it into a tar file
$TAR -c -f boot-backup.tar /boot
# clones the content of raspberry pi kernel repository
$GIT clone --depth=1 https://github.com/raspberrypi/linux
cd linux || exit
# creates a default config file for Raspberry Pi 4 model
KERNEL=kernel7l
$MAKE bcm2711_defconfig
# Modyfying config file
# appeneds my student number to the kernel verision
$SED -i '/^CONFIG_LOCALVERSION/s/.*/CONFIG_LOCALVERSION="-v7l-s3714110"/' .config
# disables support for video and camera
$SED -i '/^CONFIG_MEDIA_CAMERA_SUPPORT=/s/.*/# CONFIG_MEDIA_CAMERA_SUPPORT is not set/' .config
# runs first and second performance script in the background
cd ../../
$BASH ./$FIRST_PERF_SCRIPT &
$BASH ./$SECOND_PERF_SCRIPT &
# starts compling the kernel, the -j4 indicates 4 cores will be used
cd workdir/linux; $MAKE -j4 zImage modules dtbs
# sends a USR1 signal to first performance script so it can exit, then kills the process
$SUDO $PKILL --signal USR1 -f $FIRST_PERF_SCRIPT
# sends a USR2 signal to second performance script so it can reset led and exit, then kills the process
$SUDO $PKILL --signal USR2 -f $SECOND_PERF_SCRIPT
# installs the kernel modules
$SUDO $MAKE modules_install
# copys the neccesary files to the /boot folder
$SUDO $CP arch/arm/boot/dts/*.dtb /boot/
$SUDO $CP arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
$SUDO $CP arch/arm/boot/dts/overlays/README /boot/overlays/
$SUDO $CP arch/arm/boot/zImage /boot/$KERNEL.img
# reboots Pi to load up the new kernel
$SUDO $REBOOT