-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·163 lines (129 loc) · 4.58 KB
/
build.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
# Copyright (C) 2018 Abubakar Yagob (blacksuan19)
# Copyright (C) 2018 Rama Bondan Prakoso (rama982)
# SPDX-License-Identifier: GPL-3.0-or-later
# Color
green='\033[0;32m'
echo -e "$green"
# Main Environment
KERNEL_DIR=$PWD
KERN_IMG=$KERNEL_DIR/out/arch/arm64/boot/Image.gz-dtb
ZIP_DIR=$KERNEL_DIR/AnyKernel3
CONFIG=RMX1801_defconfig
CORES=$(grep -c ^processor /proc/cpuinfo)
THREAD="-j$CORES"
CROSS_COMPILE+="ccache "
CROSS_COMPILE+="$PWD/aarch64-cortex_a53-linux-gnueabi-uber/bin/aarch64-cortex_a53-linux-gnueabi-"
CROSS_COMPILE_ARM32+="$PWD/arm-linaro-gcc-6.1/bin/arm-linux-gnueabihf-"
# Modules environtment
OUTDIR="$PWD/out/"
SRCDIR="$PWD/"
MODULEDIR="$PWD/AnyKernel3/modules/system/lib/modules/"
PRIMA="$PWD/AnyKernel3/modules/vendor/lib/modules/wlan.ko"
PRONTO="$PWD/AnyKernel3/modules/vendor/lib/modules/pronto/pronto_wlan.ko"
STRIP="$PWD/aarch64-cortex_a53-linux-gnueabi-uber/bin/$(echo "$(find "$PWD/aarch64-cortex_a53-linux-gnueabi-uber/bin" -type f -name "aarch64-*-gcc")" | awk -F '/' '{print $NF}' |\
sed -e 's/gcc/strip/')"
# Export
export ARCH=arm64
export SUBARCH=arm64
export PATH=/usr/lib/ccache:$PATH
export CROSS_COMPILE
export CROSS_COMPILE_ARM32
export KBUILD_BUILD_USER=VijayMalav
export KBUILD_BUILD_HOST=Gcloud
# Main script
while true; do
echo -e "\n[1] Build Kernel"
echo -e "[2] Regenerate defconfig"
echo -e "[3] Source cleanup"
echo -e "[4] Create flashable zip"
echo -e "[5] Quit"
echo -ne "\n(i) Please enter a choice[1-5]: "
read choice
if [ "$choice" == "1" ]; then
echo -e "\n(i) Cloning toolcahins if folder not exist..."
git clone https://gitlab.com/Vijaymalav564/arm-linaro-gcc-6.1.git
git clone https://github.com/SmokeyMcBong/aarch64-cortex_a53-linux-gnueabi-uber
echo -e ""
make O=out $CONFIG $THREAD &>/dev/null
make O=out $THREAD & pid=$!
BUILD_START=$(date +"%s")
DATE=`date`
echo -e "\n#######################################################################"
echo -e "(i) Build started at $DATE using $CORES thread"
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"
echo -ne "\n[Please wait...] ${spin[0]}"
while kill -0 $pid &>/dev/null
do
for i in "${spin[@]}"
do
echo -ne "\b$i"
sleep 0.1
done
done
if ! [ -a $KERN_IMG ]; then
echo -e "\n(!) Kernel compilation failed, See buildlog to fix errors"
echo -e "#######################################################################"
exit 1
fi
BUILD_END=$(date +"%s")
DIFF=$(($BUILD_END - $BUILD_START))
echo -e "\nImage-dtb compiled successfully."
echo -e "#######################################################################"
echo -e "(i) Total time elapsed: $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds."
echo -e "#######################################################################"
fi
if [ "$choice" == "2" ]; then
echo -e "\n#######################################################################"
make O=out $CONFIG savedefconfig &>/dev/null
cp out/defconfig arch/arm64/configs/$CONFIG &>/dev/null
echo -e "(i) Defconfig generated."
echo -e "#######################################################################"
fi
if [ "$choice" == "3" ]; then
echo -e "\n#######################################################################"
make O=out clean &>/dev/null
make mrproper &>/dev/null
rm -rf out/*
echo -e "(i) Kernel source cleaned up."
echo -e "#######################################################################"
fi
if [ "$choice" == "4" ]; then
echo -e "\n#######################################################################"
echo -e "\n(i) Cloning AnyKernel3 if folder not exist..."
git clone -b rmx1801 https://github.com/Vijaymalav564/AnyKernel3.git
echo -e "\n(i) Strip and move modules to AnyKernel3..."
# thanks to @adekmaulana
cd $ZIP_DIR
make clean &>/dev/null
cd ..
for MOD in $(find "${OUTDIR}" -name '*.ko') ; do
"${STRIP}" --strip-unneeded --strip-debug "${MOD}" &> /dev/null
"${SRCDIR}"/scripts/sign-file sha512 \
"${OUTDIR}/signing_key.priv" \
"${OUTDIR}/signing_key.x509" \
"${MOD}"
find "${OUTDIR}" -name '*.ko' -exec cp {} "${MODULEDIR}" \;
case ${MOD} in
*/wlan.ko)
cp -ar "${MOD}" "${PRIMA}"
cp -ar "${MOD}" "${PRONTO}"
esac
done
echo -e "\n(i) Done moving modules"
rm $PWD/AnyKernel3/modules/system/lib/modules/wlan.ko
cd $ZIP_DIR
cp $KERN_IMG $ZIP_DIR/zImage
make normal &>/dev/null
cd ..
echo -e "Flashable zip generated under $ZIP_DIR."
echo -e "#######################################################################"
fi
if [ "$choice" == "5" ]; then
exit
fi
done
echo -e "$nc"