-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhikey-kernel-builder.sh
executable file
·314 lines (269 loc) · 12.8 KB
/
hikey-kernel-builder.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
usage()
{
echo "usage: [-s] -v=[4.4|4.9|4.14|v4.19] -a={AOSP|Q|P|O-MR1} -t=clang-r349610 -b=[hikey|960]"
echo "-s = skip download"
echo "-v = kernel version"
echo "-a = android version"
echo "-t = toolchain to use from prebuilts"
echo "-m = mirror build, use premerge mirror"
echo "-c = continue build, no download, no reconfig, just build"
}
# export TOOLCHAIN="clang-r349610b"
# March clang
export TOOLCHAIN="clang-r353983e"
export nproc=9
export ANDROID_VERSION="P"
export PASTRY_BUILD=1
export REFERENCE_BUILD_URL="http://testdata.linaro.org/lkft/aosp-stable/android-8.1.0_r29/"
export KERNEL_DIR="hikey-linaro"
export C_COMPILER="clang"
export usegcc="0"
# Some works about trees
# android-hikey-linaro-4.4 android-hikey-linaro-4.9 android-hikey-linaro-4.14 android-hikey-linaro-4.19
# These are the blend of Common (aosp-mainline) + LTS for booting mainline + hikey support
# android-4.4-p, android-4.9-p, android-4.14-p represent the blend of Common for P and LTS but no hikey support
# android-4.4-p-hikey, android-4.9-p-hikey, android-4.14-p-hikey represent the blend of Common for P, LTS and hikey support
# checkout -b android-hikey-linaro-4.9 origin/android-hikey-linaro-4.9
while [ "$1" != "" ]; do
case $1 in
-b | --board ) shift
export BOARD=$1
;;
-v | --version ) shift
export VERSION=$1
;;
-a | --android ) shift
export ANDROID_VERSION=$1
;;
-t | --toolchain ) shift
toolchain=$1
;;
-s | --skipdownloads ) skipdownloads=1
;;
-g | --gcc ) usegcc=1
;;
-c | --continue ) cont=1
skipdownloads=1
;;
-i | --side ) side=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ "$VERSION" = "4.9" ]; then
if [ "$ANDROID_VERSION" = "AOSP" ]; then
export KERNEL_BRANCH=android-hikey-linaro-4.9
else
export KERNEL_BRANCH=android-4.9
fi
export ANDROID_KERNEL_CONFIG_DIR="android-4.9"
elif [ "$VERSION" = "4.14" ]; then
if [ "$ANDROID_VERSION" = "AOSP" ]; then
export KERNEL_BRANCH=android-hikey-linaro-4.14
else
export KERNEL_BRANCH=android-4.14
fi
export ANDROID_KERNEL_CONFIG_DIR="android-4.14"
elif [ "$VERSION" = "4.19" ]; then
if [ "$ANDROID_VERSION" = "AOSP" ]; then
export KERNEL_BRANCH=android-hikey-linaro-4.19
elif [ "$ANDROID_VERSION" = "Q" ]; then
export KERNEL_BRANCH=android-4.19
export ANDROID_KERNEL_CONFIG_DIR="android-4.19"
else
export KERNEL_BRANCH=android-4.19
fi
# export ANDROID_KERNEL_CONFIG_DIR="android-4.19"
# export KERNEL_BRANCH=android-hikey-linaro-4.19
# export ANDROID_KERNEL_CONFIG_DIR="android-4.19"
# export PASTRY_BUILD=0
elif [ "$VERSION" = "4.4" ]; then
if [ "$ANDROID_VERSION" = "AOSP" ]; then
export KERNEL_BRANCH=android-hikey-linaro-4.4
else
export KERNEL_BRANCH=android-4.4
fi
export ANDROID_KERNEL_CONFIG_DIR="android-4.4"
elif [ "$VERSION" = "mainline" ]; then
export KERNEL_BRANCH=android-mainline
fi
# android-4.14 android-4.4 android-4.9 o o-mr1 p
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
export CONFIG_FRAGMENTS_PATH="o-mr1"
elif [ "$ANDROID_VERSION" = "P" ]; then
export CONFIG_FRAGMENTS_PATH="p"
fi
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
export REFERENCE_BUILD_URL="http://testdata.linaro.org/lkft/aosp-stable/android-8.1.0_r29/"
elif [ "$ANDROID_VERSION" = "P" ]; then
export REFERENCE_BUILD_URL="https://snapshots.linaro.org/android/android-lcr-reference-hikey-p/latest/"
# export REFERENCE_BUILD_URL="http://people.linaro.org/~yongqin.liu/images/hikey/pie/"
elif [ "$ANDROID_VERSION" = "Q" ]; then
export REFERENCE_BUILD_URL="https://snapshots.linaro.org/android/android-lcr-reference-hikey-p/latest/"
else
echo "need AOSP master ref"
export PASTRY_BUILD=0
fi
echo "git checkout -b "$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey origin/"$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey "
if [ "$skipdownloads" != "1" ]; then
git clone --depth=1 https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
git clone --depth=1 https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86
fi
export PATH=${PWD}/aarch64-linux-android-4.9/bin/:${PWD}/linux-x86/${TOOLCHAIN}/bin/:${PATH}
set -x
if [ "$skipdownloads" != "1" ]; then
# wget -q https://android-git.linaro.org/platform/system/core.git/plain/mkbootimg/mkbootimg.py -O mkbootimg
# chmod +x mkbootimg
wget -q http://releases.linaro.org/android/reference-lcr/hikey/9.0-19.01/ramdisk.img
fi
if [ "$usegcc" = "1" ]; then
export PATH=/opt/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:${PATH}
fi
if [ "$skipdownloads" != "1" ]; then
mkdir patches
cd patches
wget -r -np -nH -R index.html --cut-dirs=2 http://people.linaro.org/~tom.gall/patches/
cd ..
fi
#if [ "$skipdownloads" != "1" ]; then
# git clone /~https://github.com/tom-gall/LinaroAndroidKernelConfigs.git
#fi
if [ "$BOARD" = "960" ]; then
CMD = "androidboot.hardware=hikey960 firmware_class.path=/vendor/firmware efi=noruntime init=/init androidboot.boot_devices=soc/ff3b0000.ufs loglevel=15 buildvariant=userdebug console=ttyAMA6 "
else
if echo "$ANDROID_VERSION" | grep -i aosp ; then
CMD="androidboot.console=ttyFIQ0 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab video=HDMI-A-1:1280x720@60"
elif [ "$ANDROID_VERSION" = "Q" ]; then
CMD="console=ttyAMA3,115200 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab_v2 rootwait ro init=/init root=/dev/dm-0 dm=\"system none ro,0 1 android-verity 179:9\" androidboot.verifiedbootstate=orange printk.devkmsg=on buildvariant=userdebug veritykeyid=id:7e4333f9bba00adfe0ede979e28ed1920492b40f"
elif [ "$VERSION" = "4.19" ]; then
CMD="console=ttyAMA3,115200 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab initrd=0x11000000,0x17E28A"
# this one works CMD="console=ttyAMA3 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug"
# CMD="console=ttyAMA3,115200 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab initrd=0x11000000,0x17E28A"
# console=ttyAMA3,115200 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug
elif [ "$ANDROID_VERSION" = "O-MR1" ]; then
CMD="androidboot.console=ttyFIQ0 androidboot.hardware=hikey firmware_class.path=/system/etc/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug"
# CMD="androidboot.console=ttyFIQ0 androidboot.hardware=hikey firmware_class.path=/system/etc/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug video=HDMI-A-1:1280x720@60"
elif [ "$ANDROID_VERSION" = "P" ]; then
CMD="console=ttyAMA3,115200 androidboot.console=ttyAMA3 androidboot.hardware=hikey firmware_class.path=/vendor/firmware efi=noruntime printk.devkmsg=on buildvariant=userdebug overlay_mgr.overlay_dt_entry=hardware_cfg_enable_android_fstab initrd=0x11000000,0x17E28A"
else
echo "What Andoid Version are you planning to run?"
fi
fi
#### set command line
if [ "$skipdownloads" = "1" ]; then
cd "$KERNEL_DIR"
if [ "$cont" = "1" ]; then
# nothing to do
echo "nothing to do"
else
make mrproper
fi
# git checkout master
# git clean -fd
# git pull
# git checkout "$KERNEL_BRANCH"
# git pull
else
if [ "$side" = "1" ]; then
cp -r ~/git/hikey-linaro .
cd "$KERNEL_DIR"
else
if [ "$PASTRY_BUILD" = "1" ]; then
if [ "$VERSION" = "4.19" ]; then
if [ "$ANDROID_VERSION" = "P" ]; then
git clone https://android.googlesource.com/kernel/hikey-linaro
else
git clone /~https://github.com/tom-gall/hikey-linaro.git
fi
else
git clone /~https://github.com/tom-gall/hikey-linaro.git
fi
else
git clone https://android.googlesource.com/kernel/hikey-linaro
fi
cd "$KERNEL_DIR"
if [ "$PASTRY_BUILD" = "1" ]; then
if [ "$VERSION" = "4.19" ]; then
if [ "$ANDROID_VERSION" = "P" ]; then
git checkout -b "$KERNEL_BRANCH" origin/"$KERNEL_BRANCH"
else
git checkout -b "$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey origin/"$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey
fi
else
git checkout -b "$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey origin/"$KERNEL_BRANCH"-"${ANDROID_VERSION,,}"-hikey
fi
else
git checkout -b "$KERNEL_BRANCH" origin/"$KERNEL_BRANCH"
fi
### side
fi
if [ "$VERSION" = "4.9" ]; then
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
git revert --no-edit bbab5cb8a5bd598af247d9eaf5a3033e7d12104e
fi
fi
if [ "$VERSION" = "4.14" ]; then
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
git revert --no-edit 20ebc74d51a1542e4290abf5ac9e32b524f891d1
git revert --no-edit d0455063e17c07841eb40b8e755f4c9241506de5
fi
fi
fi
cd ..
export CLANG_TRIPLE=aarch64-linux-gnu-
export CROSS_COMPILE=aarch64-linux-android-
cd "$KERNEL_DIR"
if [ "$cont" != "1" ]; then
if [ "$BOARD" = "960" ]; then
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" hikey960_defconfig
else
# copy kernel config for any version besides AOSP
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
cp ../LinaroAndroidKernelConfigs/${ANDROID_VERSION}/${VERSION}/hikey_defconfig .config
elif [ "$ANDROID_VERSION" = "Q" ]; then
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" hikey_defconfig
elif [ "$VERSION" = "4.19" ]; then
ARCH=arm64 scripts/kconfig/merge_config.sh arch/arm64/configs/hikey_defconfig ../configs/${ANDROID_KERNEL_CONFIG_DIR}/android-base.config ../configs/${ANDROID_KERNEL_CONFIG_DIR}/android-recommended-arm64.config
elif [ "$ANDROID_VERSION" = "P" ]; then
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" hikey_defconfig
# cp arch/arm64/configs/hikey_defconfig .config
# cp ../LinaroAndroidKernelConfigs/${ANDROID_VERSION}/${VERSION}/hikey_defconfig .config
else # AOSP BUILD
ARCH=arm64 scripts/kconfig/merge_config.sh arch/arm64/configs/hikey_defconfig ../configs/${CONFIG_FRAGMENTS_PATH}/${ANDROID_KERNEL_CONFIG_DIR}/android-base.config ../configs/${CONFIG_FRAGMENTS_PATH}/${ANDROID_KERNEL_CONFIG_DIR}/android-recommended-arm64.config
fi
fi
fi
cp .config ../defconfig
if [ "$usegcc" = "1" ]; then
export C_COMPILER=gcc
fi
if [ "$VERSION" = "4.19" ]; then
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" -j$(nproc) Image-dtb
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" -j$(nproc) dtbs
# make ARCH=arm64 CC=clang HOSTCC=clang -j$(nproc) Image
# make ARCH=arm64 CC=clang HOSTCC=clang -j$(nproc) dtbs
cat arch/arm64/boot/Image arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb > arch/arm64/boot/Image-dtb
elif [ "$VERSION" = "mainline" ]; then
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" -j$(nproc) Image
make ARCH=arm64 CC="${C_COMPILER}" HOSTCC="${C_COMPILER}" -j$(nproc) dtbs
cat arch/arm64/boot/Image arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb > arch/arm64/boot/Image-dtb
else
make ARCH=arm64 CC=clang HOSTCC=clang -j$(nproc) Image-dtb
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) Image.gz-dtb
fi
cd ..
if [ "$ANDROID_VERSION" = "O-MR1" ]; then
mkbootimg --kernel ${PWD}/"$KERNEL_DIR"/arch/arm64/boot/Image-dtb --cmdline "${CMD}" --os_version O --os_patch_level 2016-11-05 --ramdisk ./ramdisk.img --output boot.img
elif [ "$ANDROID_VERSION" = "Q" ]; then
mkbootimg --kernel ${PWD}/"$KERNEL_DIR"/arch/arm64/boot/Image-dtb --cmdline "${CMD}" --os_version Q --os_patch_level 2019-03-05 --ramdisk ./ramdisk.img --output boot.img
else
# mkbootimg --kernel ${PWD}/"$KERNEL_DIR"/arch/arm64/boot/Image.gz-dtb --cmdline "${CMD}" --os_version P --os_patch_level 2018-09-01 --ramdisk ./ramdisk.img --output boot.img
mkbootimg --kernel ${PWD}/"$KERNEL_DIR"/arch/arm64/boot/Image-dtb --cmdline "${CMD}" --os_version P --os_patch_level 2018-09-01 --ramdisk ./ramdisk.img --output boot.img
fi
#