-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_kernel.sh
More file actions
executable file
·83 lines (62 loc) · 1.81 KB
/
build_kernel.sh
File metadata and controls
executable file
·83 lines (62 loc) · 1.81 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
#!/bin/bash
# Set the cross-compiler and architecture
CROSS_COMPILE=aarch64-linux-gnu-
ARCH=arm64
# Paths
KERNEL_DIR=$(pwd)/kernel
HEADERS_DIR=$KERNEL_DIR/../kernel_headers
export KERNEL=kernel8
# Number of jobs for make (adjust based on your CPU cores)
JOBS=$(nproc)
# Function to build the kernel
build_kernel() {
echo "Configuring the kernel for Raspberry Pi 4..."
cd $KERNEL_DIR
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE bcm2711_defconfig
if [ $? -ne 0 ]; then
echo "Kernel configuration failed!"
exit 1
fi
echo "Kernel configured successfully."
echo "Building the Linux kernel..."
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE -j$JOBS Image dtbs modules
if [ $? -ne 0 ]; then
echo "Kernel build failed!"
exit 1
fi
echo "Kernel build completed successfully."
echo "Installing kernel headers..."
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE headers_install INSTALL_HDR_PATH=$HEADERS_DIR
if [ $? -ne 0 ]; then
echo "Installing kernel headers failed!"
exit 1
fi
echo "Kernel headers installed to $HEADERS_DIR."
}
# Function to clean the kernel build
clean_kernel() {
echo "Cleaning the kernel build..."
cd $KERNEL_DIR
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE clean
if [ $? -ne 0 ]; then
echo "Kernel clean failed!"
exit 1
fi
echo "Kernel build cleaned successfully."
echo "Removing installed kernel headers..."
rm -rf $HEADERS_DIR
if [ $? -ne 0 ]; then
echo "Failed to remove kernel headers directory!"
exit 1
fi
echo "Kernel headers directory removed successfully."
}
# Main script logic
if [ "$1" == "clean" ]; then
clean_kernel
elif [ "$1" == "build" ]; then
build_kernel
else
echo "Usage: $0 [build|clean]"
exit 1
fi