-
Notifications
You must be signed in to change notification settings - Fork 54
/
build_kernel.sh
executable file
·138 lines (119 loc) · 5.19 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#set -e
## Copy this script inside the kernel directory
LINKER="lld"
DIR=$(readlink -f .)
MAIN=$(readlink -f ${DIR}/..)
export PATH="$MAIN/clang/bin:$PATH"
export ARCH=arm64
export SUBARCH=arm64
export KBUILD_COMPILER_STRING="$($MAIN/clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')"
if ! [ -d "$MAIN/clang" ]; then
echo "No clang compiler found ... Cloning from GitHub"
# Prompt user to choose Clang version
echo "Choose which Clang to use:"
echo "1. ZyC Stable"
echo "2. WeebX Stable"
read -p "Enter the number of your choice: " clang_choice
# Download and extract the selected Clang version
if [ "$clang_choice" = "1" ]; then
wget "$(curl -s https://raw.githubusercontent.com/v3kt0r-87/Clang-Stable/main/clang-zyc.txt)" -O "zyc-clang.tar.gz"
rm -rf clang && mkdir clang && tar -xvf zyc-clang.tar.gz -C clang && rm -rf zyc-clang.tar.gz
elif [ "$clang_choice" = "2" ]; then
wget "$(curl -s https://raw.githubusercontent.com/v3kt0r-87/Clang-Stable/main/clang-weebx.txt)" -O "weebx-clang.tar.gz"
rm -rf clang && mkdir clang && tar -xvf weebx-clang.tar.gz -C clang && rm -rf weebx-clang.tar.gz
else
echo "Invalid choice. Exiting..."
exit 1
fi
fi
KERNEL_DIR=$(pwd)
ZIMAGE_DIR="$KERNEL_DIR/out/arch/arm64/boot"
# Speed up build process
MAKE="./makeparallel"
BUILD_START=$(date +"%s")
blue='\033[0;34m'
cyan='\033[0;36m'
yellow='\033[0;33m'
red='\033[0;31m'
nocol='\033[0m'
# Function to revert modifications
revert_modifications() {
if [ "$choice" = "miui" ]; then
if [ "$device" = "apollo" ]; then
sed -i 's/qcom,mdss-pan-physical-width-dimension = <700>;$/qcom,mdss-pan-physical-width-dimension = <70>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
sed -i 's/qcom,mdss-pan-physical-height-dimension = <1540>;$/qcom,mdss-pan-physical-height-dimension = <155>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
elif [ "$device" = "alioth" ]; then
sed -i 's/qcom,mdss-pan-physical-width-dimension = <700>;$/qcom,mdss-pan-physical-width-dimension = <70>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
sed -i 's/qcom,mdss-pan-physical-height-dimension = <1540>;$/qcom,mdss-pan-physical-height-dimension = <155>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
fi
fi
git checkout arch/arm64/boot/dts/vendor/qcom/dsi-panel-* &>/dev/null
}
echo -e "$blue***********************************************"
echo " BUILDING KERNEL "
echo -e "***********************************************$nocol"
# Prompt for device choice
read -p "Choose device (apollo/alioth): " device
if [ "$device" = "apollo" ]; then
KERNEL_DEFCONFIG=apollo_defconfig
DEVICE_NAME1="apollo"
DEVICE_NAME2="apollon"
IS_SLOT_DEVICE=0
# Remove vendor_boot block for apollo
VENDOR_BOOT_LINES_REMOVED=1
else
KERNEL_DEFCONFIG=alioth_defconfig
DEVICE_NAME1="alioth"
DEVICE_NAME2="aliothin"
IS_SLOT_DEVICE=1
VENDOR_BOOT_LINES_REMOVED=0
fi
# Prompt for MIUI or AOSP
read -p "Do you want MIUI or AOSP? (miui/aosp): " choice
if [ "$choice" = "miui" ]; then
# Modify the dimensions for MIUI
if [ "$device" = "apollo" ]; then
sed -i 's/qcom,mdss-pan-physical-width-dimension = <70>;$/qcom,mdss-pan-physical-width-dimension = <700>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
sed -i 's/qcom,mdss-pan-physical-height-dimension = <155>;$/qcom,mdss-pan-physical-height-dimension = <1540>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
elif [ "$device" = "alioth" ]; then
sed -i 's/qcom,mdss-pan-physical-width-dimension = <70>;$/qcom,mdss-pan-physical-width-dimension = <700>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
sed -i 's/qcom,mdss-pan-physical-height-dimension = <155>;$/qcom,mdss-pan-physical-height-dimension = <1540>;/' arch/arm64/boot/dts/vendor/qcom/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
fi
fi
# Backup anykernel.sh
cp -p anykernel/anykernel.sh anykernel/anykernel.sh.bak
# Modify anykernel.sh based on device and is_slot_device
sed -i "s/device.name1=.*/device.name1=$DEVICE_NAME1/" anykernel/anykernel.sh
sed -i "s/device.name2=.*/device.name2=$DEVICE_NAME2/" anykernel/anykernel.sh
sed -i "s/is_slot_device=.*/is_slot_device=$IS_SLOT_DEVICE/" anykernel/anykernel.sh
# Remove vendor_boot block if necessary
if [ "$VENDOR_BOOT_LINES_REMOVED" -eq 1 ]; then
sed -i '/## vendor_boot shell variables/,/## end vendor_boot install/d' anykernel/anykernel.sh
fi
# kernel-Compilation
make $KERNEL_DEFCONFIG O=out CC=clang
make -j$(nproc --all) O=out \
CC=clang \
ARCH=arm64 \
CROSS_COMPILE=aarch64-linux-gnu- \
NM=llvm-nm \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip
TIME="$(date "+%Y%m%d-%H%M%S")"
mkdir -p tmp
cp -fp $ZIMAGE_DIR/Image.gz tmp
cp -fp $ZIMAGE_DIR/dtbo.img tmp
cp -fp $ZIMAGE_DIR/dtb tmp
cp -rp ./anykernel/* tmp
cd tmp
7za a -mx9 tmp.zip *
cd ..
rm *.zip
cp -fp tmp/tmp.zip RealKing-$device-$choice-$TIME.zip
rm -rf tmp
echo $TIME
# Restore anykernel.sh
mv -f anykernel/anykernel.sh.bak anykernel/anykernel.sh
# Revert changes back to the original state
revert_modifications