-
Notifications
You must be signed in to change notification settings - Fork 10
/
mk.sh
executable file
·312 lines (264 loc) · 11.6 KB
/
mk.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
#!/bin/bash
function show_help {
echo "USAGE: $0 [--nongki] [--abi]"
echo
echo " --arch for ARCH, build 64 or 32 bit kernel, arm|arm64[default], require parameter value"
echo " --abi for ABI, call build_abi.sh not build.sh, 1|0[default], not require parameter value"
echo " --build_config for BUILD_CONFIG, common_drivers/build.config.amlogic[default]|common/build.config.gki.aarch64, require parameter value"
echo " --lto for LTO, full|thin[default]|none, require parameter value"
echo " --menuconfig for only menuconfig, not require parameter value"
echo " --basicconfig for basicconfig, m(menuconfig)[default]|n"
echo " --image for only build kernel, not require parameter value"
echo " --modules for only build modules, not require parameter value"
echo " --dtbs for only build dtbs, not require parameter value"
echo " --kernel_dir for KERNEL_DIR, common[default]|other dir, require parameter value"
echo " --common_drivers_dir for COMMON_DRIVERS_DIR, common[default]|other dir, require parameter value"
echo " --build_dir for BUILD_DIR, build[default]|other dir, require parameter value"
echo " --check_defconfig for check defconfig"
echo " --modules_depend for check modules depend"
echo " --android_project for android project build"
echo " --gki_20 for build gki 2.0 kernel: gki_defconfig + amlogic_gki.fragment"
echo " --gki_10 for build gki 1.0 kernel: gki_defconfig + amlogic_gki.fragment + amlogic_gki.10 + amlogic_gki.debug"
echo " --fast_build for fast build"
echo " --upgrade for android upgrade builtin module optimize vendor_boot size" following with android project name
echo " --manual_insmod_module for insmod ko manually when kernel is booting.It's usually used in debug test"
echo " --patch for only am patches"
echo " --check_gki_20 for gki 2.0 check kernel build"
echo " --dev_config for use the config specified by oem instead of amlogic like ./mk.sh --dev_config a_config+b_config+c_config"
echo " --use_prebuilt_gki for use prebuilt gki, require parameter value, https://ci.android.com/builds/submitted/10412065/kernel_aarch64/latest, --use_prebuilt_gki 10412065"
echo " --kasan for build kernel with config kasan"
}
# handle the dir parameters for amlogic_utils.sh
VA=
ARGS=()
for i in "$@"
do
case $i in
--kernel_dir)
KERNEL_DIR=$2
VA=1
shift
;;
--common_drivers_dir)
COMMON_DRIVERS_DIR=$2
VA=1
shift
;;
--patch)
ONLY_PATCH=1
PATCH_PARM=$2
if [[ "${PATCH_PARM}" == "lunch" ]]; then
VA=1
fi
CURRENT_DIR=`pwd`
cd $(dirname $0)
shift
;;
*)
if [[ -n $1 ]];
then
if [[ -z ${VA} ]];
then
ARGS+=("$1")
fi
fi
VA=
shift
;;
esac
done
if [[ -z "${KERNEL_DIR}" ]]; then
KERNEL_DIR=common
fi
if [[ ! -f ${KERNEL_DIR}/init/main.c ]]; then
echo "The directory of kernel does not exist";
exit
fi
if [[ -z "${COMMON_DRIVERS_DIR}" ]]; then
if [[ -d ${KERNEL_DIR}/../common_drivers ]]; then
COMMON_DRIVERS_DIR=../common_drivers
elif [[ -d "${KERNEL_DIR}/common_drivers" ]]; then
COMMON_DRIVERS_DIR=common_drivers
fi
fi
if [[ ! -f ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/amlogic_utils.sh ]]; then
echo "The directory of common_drivers does not exist";
exit
fi
set -- "${ARGS[@]}" # other parameters are used as script parameters to handle_input_parameters
source "${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/amlogic_utils.sh"
handle_input_parameters "$@"
set_default_parameters # set amlogic parameters default value
set -- "${ARGS[@]}" # other parameters are used as script parameters of build_abi.sh or build.sh
set -e
export_env_variable
copy_pre_commit
adjust_config_action
build_part_of_kernel
if [[ "${FULL_KERNEL_VERSION}" != "common13-5.15" && "${ARCH}" = "arm64" && ${BAZEL} == 1 ]]; then
args=$@
[[ -z ${PREBUILT_GKI} ]] && args="${args} --lto=${LTO}"
[[ -z ${GKI_CONFIG} ]] && args="${args} --notrim --nokmi_symbol_list_strict_mode"
PROJECT_DIR=${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/project
[[ -d ${PROJECT_DIR} ]] || mkdir -p ${PROJECT_DIR}
pushd ${ROOT_DIR}/${KERNEL_DIR}
git checkout android/abi_gki_aarch64_amlogic
cat ${COMMON_DRIVERS_DIR}/android/${FULL_KERNEL_VERSION}_abi_gki_aarch64_amlogic >> android/abi_gki_aarch64_amlogic
cat ${COMMON_DRIVERS_DIR}/android/${FULL_KERNEL_VERSION}_abi_gki_aarch64_amlogic.10 >> android/abi_gki_aarch64_amlogic
cat ${COMMON_DRIVERS_DIR}/android/${FULL_KERNEL_VERSION}_abi_gki_aarch64_amlogic.debug >> android/abi_gki_aarch64_amlogic
cat ${COMMON_DRIVERS_DIR}/android/${FULL_KERNEL_VERSION}_abi_gki_aarch64_amlogic.illegal >> android/abi_gki_aarch64_amlogic
popd
if [[ ! -f ${PROJECT_DIR}/build.config.project ]]; then
touch ${PROJECT_DIR}/build.config.project
echo "# SPDX-License-Identifier: GPL-2.0" > ${PROJECT_DIR}/build.config.project
echo >> ${PROJECT_DIR}/build.config.project
fi
[[ -f ${PROJECT_DIR}/build.config.gki10 ]] || touch ${PROJECT_DIR}/build.config.gki10
echo "# SPDX-License-Identifier: GPL-2.0" > ${PROJECT_DIR}/build.config.gki10
echo >> ${PROJECT_DIR}/build.config.gki10
echo "GKI_CONFIG=${GKI_CONFIG}" >> ${PROJECT_DIR}/build.config.gki10
echo "ANDROID_PROJECT=${ANDROID_PROJECT}" >> ${PROJECT_DIR}/build.config.gki10
echo "COMMON_DRIVERS_DIR=${COMMON_DRIVERS_DIR}" >> ${PROJECT_DIR}/build.config.gki10
echo "UPGRADE_PROJECT=${UPGRADE_PROJECT}" >> ${PROJECT_DIR}/build.config.gki10
echo "DEV_CONFIGS=\"${DEV_CONFIGS}\"" >> ${PROJECT_DIR}/build.config.gki10
echo "KASAN=${KASAN}" >> ${PROJECT_DIR}/build.config.gki10
echo "CHECK_GKI_20=${CHECK_GKI_20}" >> ${PROJECT_DIR}/build.config.gki10
if [[ -z ${ANDROID_PROJECT} ]]; then
[[ -f ${PROJECT_DIR}/Kconfig.ext_modules ]] && rm -rf ${PROJECT_DIR}/Kconfig.ext_modules
touch ${PROJECT_DIR}/Kconfig.ext_modules
echo "# SPDX-License-Identifier: GPL-2.0" > ${PROJECT_DIR}/Kconfig.ext_modules
echo >> ${PROJECT_DIR}/Kconfig.ext_modules
[[ -f ${PROJECT_DIR}/project.bzl ]] && rm -f ${PROJECT_DIR}/project.bzl
touch ${PROJECT_DIR}/project.bzl
echo "# SPDX-License-Identifier: GPL-2.0" > ${PROJECT_DIR}/project.bzl
echo >> ${PROJECT_DIR}/project.bzl
echo >> ${PROJECT_DIR}/project.bzl
echo "EXT_MODULES_ANDROID = [" >> ${PROJECT_DIR}/project.bzl
echo "]" >> ${PROJECT_DIR}/project.bzl
echo >> ${PROJECT_DIR}/project.bzl
echo "MODULES_OUT_REMOVE = [" >> ${PROJECT_DIR}/project.bzl
echo "]" >> ${PROJECT_DIR}/project.bzl
echo >> ${PROJECT_DIR}/project.bzl
echo "MODULES_OUT_ADD = [" >> ${PROJECT_DIR}/project.bzl
echo "]" >> ${PROJECT_DIR}/project.bzl
echo >> ${PROJECT_DIR}/project.bzl
echo "KCONFIG_EXT_SRCS = [" >> ${PROJECT_DIR}/project.bzl
echo "]" >> ${PROJECT_DIR}/project.bzl
fi
echo >> ${PROJECT_DIR}/project.bzl
sed -i "/ANDROID_PROJECT/d" ${PROJECT_DIR}/project.bzl
echo "ANDROID_PROJECT = \"${ANDROID_PROJECT}\"" >> ${PROJECT_DIR}/project.bzl
sed -i "/GKI_CONFIG/d" ${PROJECT_DIR}/project.bzl
echo "GKI_CONFIG = \"${GKI_CONFIG}\"" >> ${PROJECT_DIR}/project.bzl
sed -i "/UPGRADE_PROJECT/d" ${PROJECT_DIR}/project.bzl
echo "UPGRADE_PROJECT = \"${UPGRADE_PROJECT}\"" >> ${PROJECT_DIR}/project.bzl
[[ -f ${PROJECT_DIR}/dtb.bzl ]] || touch ${PROJECT_DIR}/dtb.bzl
echo "# SPDX-License-Identifier: GPL-2.0" > ${PROJECT_DIR}/dtb.bzl
echo >> ${PROJECT_DIR}/dtb.bzl
echo "AMLOGIC_DTBS = [" >> ${PROJECT_DIR}/dtb.bzl
cat ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/boot/dts/amlogic/Makefile | grep -n "dtb" | cut -d "=" -f 2 | sed 's/[[:space:]][[:space:]]*/ /g' | sed 's/^[ ]*//' | sed 's/[ ]*$//' | sed '/^#/d;/^$/d' | sed 's/^/ "/' | sed 's/$/",/' >> ${PROJECT_DIR}/dtb.bzl
echo "]" >> ${PROJECT_DIR}/dtb.bzl
if [[ "${GKI_CONFIG}" != "gki_20" || -n ${KASAN} || -z ${ANDROID_PROJECT} ]]; then
args="${args} --gki_build_config_fragment=//common:common_drivers/build.config.amlogic.fragment.bazel"
fi
if [[ ${GKI_CONFIG} != gki_20 || -n ${KASAN} || -n ${CHECK_GKI_20} ]]; then
args="${args} --allow_undeclared_modules"
fi
[[ -n ${KASAN} ]] && args="${args} --kasan"
if [[ -n ${CHECK_GKI_20} ]]; then
args="${args} --lto=none --notrim --nokmi_symbol_list_strict_mode"
fi
echo args=${args}
set -x
if [[ -n ${GOOGLE_BAZEL_BUILD_COMMAND_LINE} ]]; then
if [[${GOOGLE_BAZEL_BUILD_COMMAND_LINE} =~ "--kasan" ]]; then
GOOGLE_BAZEL_BUILD_COMMAND_LINE="${GOOGLE_BAZEL_BUILD_COMMAND_LINE} \
--gki_build_config_fragment=//common:common_drivers/build.config.amlogic.fragment.bazel \
--allow_undeclared_modules"
fi
${GOOGLE_BAZEL_BUILD_COMMAND_LINE}
elif [[ "${ABI}" -eq "1" ]]; then
tools/bazel run //common:amlogic_abi_update_symbol_list --sandbox_debug --verbose_failures ${args}
tools/bazel run //common:kernel_aarch64_abi_dist --sandbox_debug --verbose_failures ${args}
exit
elif [[ -n ${PREBUILT_GKI} ]]; then
tools/bazel run --use_prebuilt_gki=${PREBUILT_GKI} //common:amlogic_dist --sandbox_debug --verbose_failures ${args}
else
tools/bazel run //common:amlogic_dist --sandbox_debug --verbose_failures ${args}
fi
set +x
echo "========================================================"
echo "after compiling with bazel and organizing the document"
source ${KERNEL_DIR}/build.config.constants
export COMMON_OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out${OUT_DIR_SUFFIX}/${BRANCH}})
export DIST_DIR=$(readlink -m ${DIST_DIR:-${COMMON_OUT_DIR}/dist})
source ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/amlogic_utils.sh
bazel_extra_cmds
if [[ -n ${COPY_DEV_CONFIGS} ]]; then
for config_name in ${COPY_DEV_CONFIGS}; do
if [[ -f ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/configs/${config_name} ]]; then
rm -f ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/configs/${config_name}
else
echo "ERROR: config file ${config_name} is not in the right path!!"
exit
fi
done
fi
else
if [ "${ABI}" -eq "1" ]; then
export OUT_DIR_SUFFIX="_abi"
else
OUT_DIR_SUFFIX=
fi
if [ "${ABI}" -eq "1" ]; then
${ROOT_DIR}/${BUILD_DIR}/build_abi.sh "$@"
else
if [[ "${FULL_KERNEL_VERSION}" != "common13-5.15" && "${ARCH}" = "arm64" ]]; then
if [[ -z ${EXT_MODULES} ]]; then
echo
echo
echo "========================================================"
echo " Build GKI boot image and GKI modules"
echo
source ${KERNEL_DIR}/build.config.constants
export OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out${OUT_DIR_SUFFIX}/${BRANCH}_gki})
COMMON_OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out${OUT_DIR_SUFFIX}/${BRANCH}})
export DIST_GKI_DIR=$(readlink -m ${DIST_DIR:-${COMMON_OUT_DIR}/dist})
if [[ "${GKI_CONFIG}" == "gki_20" ]]; then
BUILD_CONFIG=${KERNEL_DIR}/build.config.gki.aarch64 ${ROOT_DIR}/${BUILD_DIR}/build.sh
else
export IN_BUILD_GKI_10=1
${ROOT_DIR}/${BUILD_DIR}/build.sh
unset IN_BUILD_GKI_10
fi
unset OUT_DIR
fi
echo
echo
echo "========================================================"
echo " Build Vendor modules"
echo
${ROOT_DIR}/${BUILD_DIR}/build.sh "$@"
else
if [[ "${FULL_KERNEL_VERSION}" != "common13-5.15" && "${ARCH}" = "arm" ]]; then
build_android_32bit $@
else
clear_files_compressed_with_lzma_in_last_build
${ROOT_DIR}/${BUILD_DIR}/build.sh "$@"
fi
fi
fi
fi
source ${ROOT_DIR}/${BUILD_CONFIG}
source ${KERNEL_BUILD_VAR_FILE}
if [[ -n ${RM_KERNEL_BUILD_VAR_FILE} ]]; then
rm -f ${KERNEL_BUILD_VAR_FILE}
fi
rename_external_module_name
rebuild_rootfs ${ARCH}
set +e
check_undefined_symbol
abi_symbol_list_detect
if [[ ${ARCH} = "arm64" ]]; then
generate_lzma_format_image
fi