commit | author | age
|
a07526
|
1 |
#!/bin/bash |
H |
2 |
|
|
3 |
export LC_ALL=C |
|
4 |
export LD_LIBRARY_PATH= |
|
5 |
unset RK_CFG_TOOLCHAIN |
|
6 |
|
|
7 |
err_handler() { |
|
8 |
ret=$? |
|
9 |
[ "$ret" -eq 0 ] && return |
|
10 |
|
|
11 |
echo "ERROR: Running ${FUNCNAME[1]} failed!" |
|
12 |
echo "ERROR: exit code $ret from line ${BASH_LINENO[0]}:" |
|
13 |
echo " $BASH_COMMAND" |
|
14 |
exit $ret |
|
15 |
} |
|
16 |
trap 'err_handler' ERR |
|
17 |
set -eE |
|
18 |
|
|
19 |
function finish_build(){ |
|
20 |
echo "Running ${FUNCNAME[1]} succeeded." |
|
21 |
cd $TOP_DIR |
|
22 |
} |
|
23 |
|
|
24 |
function check_config(){ |
|
25 |
unset missing |
|
26 |
for var in $@; do |
|
27 |
eval [ \$$var ] && continue |
|
28 |
|
|
29 |
missing="$missing $var" |
|
30 |
done |
|
31 |
|
|
32 |
[ -z "$missing" ] && return 0 |
|
33 |
|
|
34 |
echo "Skipping ${FUNCNAME[1]} for missing configs: $missing." |
|
35 |
return 1 |
|
36 |
} |
|
37 |
|
|
38 |
function choose_target_board() |
|
39 |
{ |
|
40 |
echo |
|
41 |
echo "You're building on Linux" |
|
42 |
echo "Lunch menu...pick a combo:" |
|
43 |
echo "" |
|
44 |
|
|
45 |
echo "0. default BoardConfig.mk" |
|
46 |
echo ${RK_TARGET_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/\n/. /" |
|
47 |
|
|
48 |
local INDEX |
|
49 |
read -p "Which would you like? [0]: " INDEX |
|
50 |
INDEX=$((${INDEX:-0} - 1)) |
|
51 |
|
|
52 |
if echo $INDEX | grep -vq [^0-9]; then |
|
53 |
RK_BUILD_TARGET_BOARD="${RK_TARGET_BOARD_ARRAY[$INDEX]}" |
|
54 |
else |
|
55 |
echo "Lunching for Default BoardConfig.mk boards..." |
|
56 |
RK_BUILD_TARGET_BOARD=BoardConfig.mk |
|
57 |
fi |
|
58 |
} |
|
59 |
|
|
60 |
function build_select_board() |
|
61 |
{ |
|
62 |
RK_TARGET_BOARD_ARRAY=( $(cd ${TARGET_PRODUCT_DIR}/; ls BoardConfig*.mk | sort) ) |
|
63 |
|
|
64 |
RK_TARGET_BOARD_ARRAY_LEN=${#RK_TARGET_BOARD_ARRAY[@]} |
|
65 |
if [ $RK_TARGET_BOARD_ARRAY_LEN -eq 0 ]; then |
|
66 |
echo "No available Board Config" |
|
67 |
return |
|
68 |
fi |
|
69 |
|
|
70 |
choose_target_board |
|
71 |
|
|
72 |
ln -rfs $TARGET_PRODUCT_DIR/$RK_BUILD_TARGET_BOARD device/rockchip/.BoardConfig.mk |
|
73 |
echo "switching to board: `realpath $BOARD_CONFIG`" |
|
74 |
} |
|
75 |
|
|
76 |
function unset_board_config_all() |
|
77 |
{ |
|
78 |
local tmp_file=`mktemp` |
|
79 |
grep -oh "^export.*RK_.*=" `find device -name "Board*.mk"` > $tmp_file |
|
80 |
source $tmp_file |
|
81 |
rm -f $tmp_file |
|
82 |
} |
|
83 |
|
|
84 |
CMD=`realpath $0` |
|
85 |
COMMON_DIR=`dirname $CMD` |
|
86 |
TOP_DIR=$(realpath $COMMON_DIR/../../..) |
|
87 |
cd $TOP_DIR |
|
88 |
|
|
89 |
BOARD_CONFIG=$TOP_DIR/device/rockchip/.BoardConfig.mk |
|
90 |
TARGET_PRODUCT="$TOP_DIR/device/rockchip/.target_product" |
|
91 |
TARGET_PRODUCT_DIR=$(realpath ${TARGET_PRODUCT}) |
|
92 |
|
|
93 |
if [ ! -L "$BOARD_CONFIG" -a "$1" != "lunch" ]; then |
|
94 |
build_select_board |
|
95 |
fi |
|
96 |
unset_board_config_all |
|
97 |
[ -L "$BOARD_CONFIG" ] && source $BOARD_CONFIG |
|
98 |
|
|
99 |
function prebuild_uboot() |
|
100 |
{ |
|
101 |
UBOOT_COMPILE_COMMANDS="\ |
|
102 |
${RK_TRUST_INI_CONFIG:+../rkbin/RKTRUST/$RK_TRUST_INI_CONFIG} \ |
|
103 |
${RK_SPL_INI_CONFIG:+../rkbin/RKBOOT/$RK_SPL_INI_CONFIG} \ |
|
104 |
${RK_UBOOT_SIZE_CONFIG:+--sz-uboot $RK_UBOOT_SIZE_CONFIG} \ |
|
105 |
${RK_TRUST_SIZE_CONFIG:+--sz-trust $RK_TRUST_SIZE_CONFIG}" |
|
106 |
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)" |
|
107 |
|
|
108 |
if [ "$RK_LOADER_UPDATE_SPL" = "true" ]; then |
|
109 |
UBOOT_COMPILE_COMMANDS="--spl-new $UBOOT_COMPILE_COMMANDS" |
|
110 |
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)" |
|
111 |
fi |
|
112 |
|
|
113 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then |
|
114 |
UBOOT_COMPILE_COMMANDS=" \ |
|
115 |
$UBOOT_COMPILE_COMMANDS \ |
|
116 |
${RK_ROLLBACK_INDEX_BOOT:+--rollback-index-boot $RK_ROLLBACK_INDEX_BOOT} \ |
|
117 |
${RK_ROLLBACK_INDEX_UBOOT:+--rollback-index-uboot $RK_ROLLBACK_INDEX_UBOOT} " |
|
118 |
fi |
|
119 |
} |
|
120 |
|
|
121 |
function prebuild_security_uboot() |
|
122 |
{ |
|
123 |
local mode=$1 |
|
124 |
|
|
125 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then |
|
126 |
if [ "$RK_SECURITY_OTP_DEBUG" != "true" ]; then |
|
127 |
UBOOT_COMPILE_COMMANDS="$UBOOT_COMPILE_COMMANDS --burn-key-hash" |
|
128 |
fi |
|
129 |
|
|
130 |
case "${mode:-normal}" in |
|
131 |
uboot) |
|
132 |
;; |
|
133 |
boot) |
|
134 |
UBOOT_COMPILE_COMMANDS=" \ |
|
135 |
--boot_img $TOP_DIR/u-boot/boot.img \ |
|
136 |
$UBOOT_COMPILE_COMMANDS " |
|
137 |
;; |
|
138 |
recovery) |
|
139 |
UBOOT_COMPILE_COMMANDS=" \ |
|
140 |
--recovery_img $TOP_DIR/u-boot/recovery.img |
|
141 |
$UBOOT_COMPILE_COMMANDS " |
|
142 |
;; |
|
143 |
*) |
|
144 |
UBOOT_COMPILE_COMMANDS=" \ |
|
145 |
--boot_img $TOP_DIR/u-boot/boot.img \ |
|
146 |
$UBOOT_COMPILE_COMMANDS " |
|
147 |
test -z "${RK_PACKAGE_FILE_AB}" && \ |
|
148 |
UBOOT_COMPILE_COMMANDS="$UBOOT_COMPILE_COMMANDS --recovery_img $TOP_DIR/u-boot/recovery.img" |
|
149 |
;; |
|
150 |
esac |
|
151 |
|
|
152 |
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)" |
|
153 |
fi |
|
154 |
} |
|
155 |
|
|
156 |
function usagekernel() |
|
157 |
{ |
|
158 |
check_config RK_KERNEL_DTS RK_KERNEL_DEFCONFIG || return 0 |
|
159 |
|
|
160 |
echo "cd kernel" |
|
161 |
echo "make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT" |
|
162 |
echo "make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBS" |
|
163 |
} |
|
164 |
|
|
165 |
function usageuboot() |
|
166 |
{ |
|
167 |
check_config RK_UBOOT_DEFCONFIG || return 0 |
|
168 |
prebuild_uboot |
|
169 |
prebuild_security_uboot $1 |
|
170 |
|
|
171 |
cd u-boot |
|
172 |
echo "cd u-boot" |
|
173 |
if [ -n "$RK_UBOOT_DEFCONFIG_FRAGMENT" ]; then |
|
174 |
if [ -f "configs/${RK_UBOOT_DEFCONFIG}_defconfig" ]; then |
|
175 |
echo "make ${RK_UBOOT_DEFCONFIG}_defconfig $RK_UBOOT_DEFCONFIG_FRAGMENT" |
|
176 |
else |
|
177 |
echo "make ${RK_UBOOT_DEFCONFIG}.config $RK_UBOOT_DEFCONFIG_FRAGMENT" |
|
178 |
fi |
|
179 |
echo "./make.sh $UBOOT_COMPILE_COMMANDS" |
|
180 |
else |
|
181 |
echo "./make.sh $RK_UBOOT_DEFCONFIG $UBOOT_COMPILE_COMMANDS" |
|
182 |
fi |
|
183 |
|
|
184 |
if [ "$RK_IDBLOCK_UPDATE_SPL" = "true" ]; then |
|
185 |
echo "./make.sh --idblock --spl" |
|
186 |
fi |
|
187 |
|
|
188 |
finish_build |
|
189 |
} |
|
190 |
|
|
191 |
function usagerootfs() |
|
192 |
{ |
|
193 |
check_config RK_ROOTFS_IMG || return 0 |
|
194 |
|
|
195 |
if [ "${RK_CFG_BUILDROOT}x" != "x" ];then |
|
196 |
echo "source envsetup.sh $RK_CFG_BUILDROOT" |
|
197 |
else |
|
198 |
if [ "${RK_CFG_RAMBOOT}x" != "x" ];then |
|
199 |
echo "source envsetup.sh $RK_CFG_RAMBOOT" |
|
200 |
else |
|
201 |
echo "Not found config buildroot. Please Check !!!" |
|
202 |
fi |
|
203 |
fi |
|
204 |
|
|
205 |
case "${RK_ROOTFS_SYSTEM:-buildroot}" in |
|
206 |
yocto) |
|
207 |
;; |
|
208 |
debian) |
|
209 |
;; |
|
210 |
ubuntu) |
|
211 |
;; |
|
212 |
*) |
|
213 |
echo "make" |
|
214 |
;; |
|
215 |
esac |
|
216 |
} |
|
217 |
|
|
218 |
function usagerecovery() |
|
219 |
{ |
|
220 |
check_config RK_CFG_RECOVERY || return 0 |
|
221 |
|
|
222 |
echo "source envsetup.sh $RK_CFG_RECOVERY" |
|
223 |
echo "$COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY" |
|
224 |
} |
|
225 |
|
|
226 |
function usageramboot() |
|
227 |
{ |
|
228 |
check_config RK_CFG_RAMBOOT || return 0 |
|
229 |
|
|
230 |
echo "source envsetup.sh $RK_CFG_RAMBOOT" |
|
231 |
echo "$COMMON_DIR/mk-ramdisk.sh ramboot.img $RK_CFG_RAMBOOT" |
|
232 |
} |
|
233 |
|
|
234 |
function usagemodules() |
|
235 |
{ |
|
236 |
check_config RK_KERNEL_DEFCONFIG || return 0 |
|
237 |
|
|
238 |
echo "cd kernel" |
|
239 |
echo "make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG" |
|
240 |
echo "make ARCH=$RK_ARCH modules -j$RK_JOBS" |
|
241 |
} |
|
242 |
|
|
243 |
function usagesecurity() |
|
244 |
{ |
|
245 |
case "$1" in |
|
246 |
uboot) usageboot $1;; |
|
247 |
boot) |
|
248 |
usageramboot; |
|
249 |
echo "cp buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img u-boot/boot.img" |
|
250 |
usageuboot $1;; |
|
251 |
recovery) |
|
252 |
usagerecovery; |
|
253 |
echo "cp buildroot/output/$RK_CFG_RECOVERY/images/recovery.img u-boot/recovery.img" |
|
254 |
usageuboot $1;; |
|
255 |
rootfs) |
|
256 |
usagerootfs; |
|
257 |
usagesecurity boot;; |
|
258 |
*);; |
|
259 |
esac |
|
260 |
} |
|
261 |
|
|
262 |
function usagesecurity_uboot() |
|
263 |
{ |
|
264 |
usageuboot uboot |
|
265 |
} |
|
266 |
|
|
267 |
function usagesecurity_boot() |
|
268 |
{ |
|
269 |
usagesecurity boot |
|
270 |
} |
|
271 |
|
|
272 |
function usagesecurity_recovery() |
|
273 |
{ |
|
274 |
usagesecurity recovery |
|
275 |
} |
|
276 |
|
|
277 |
function usagesecurity_rootfs() |
|
278 |
{ |
|
279 |
usagesecurity rootfs |
|
280 |
} |
|
281 |
|
|
282 |
function usage() |
|
283 |
{ |
|
284 |
echo "Usage: build.sh [OPTIONS]" |
|
285 |
echo "Available options:" |
|
286 |
echo "BoardConfig*.mk -switch to specified board config" |
|
287 |
echo "lunch -list current SDK boards and switch to specified board config" |
|
288 |
echo "uboot -build uboot" |
|
289 |
echo "uefi -build uefi" |
|
290 |
echo "spl -build spl" |
|
291 |
echo "loader -build loader" |
|
292 |
echo "kernel -build kernel" |
|
293 |
echo "modules -build kernel modules" |
|
294 |
echo "toolchain -build toolchain" |
|
295 |
echo "rootfs -build default rootfs, currently build buildroot as default" |
|
296 |
echo "buildroot -build buildroot rootfs" |
|
297 |
echo "ramboot -build ramboot image" |
|
298 |
echo "multi-npu_boot -build boot image for multi-npu board" |
|
299 |
echo "yocto -build yocto rootfs" |
|
300 |
echo "debian -build debian rootfs" |
|
301 |
echo "ubuntu -build ubuntu rootfs" |
|
302 |
echo "pcba -build pcba" |
|
303 |
echo "recovery -build recovery" |
|
304 |
echo "all -build uboot, kernel, rootfs, recovery image" |
|
305 |
echo "cleanall -clean uboot, kernel, rootfs, recovery" |
|
306 |
echo "firmware -pack all the image we need to boot up system" |
|
307 |
echo "updateimg -pack update image" |
|
308 |
echo "otapackage -pack ab update otapackage image (update_ota.img)" |
|
309 |
echo "sdpackage -pack update sdcard package image (update_sdcard.img)" |
|
310 |
echo "save -save images, patches, commands used to debug" |
|
311 |
echo "allsave -build all & firmware & updateimg & save" |
|
312 |
echo "check -check the environment of building" |
|
313 |
echo "info -see the current board building information" |
|
314 |
echo "app/<pkg> -build packages in the dir of app/*" |
|
315 |
echo "external/<pkg> -build packages in the dir of external/*" |
|
316 |
echo "" |
|
317 |
echo "createkeys -create secureboot root keys" |
|
318 |
echo "security_rootfs -build rootfs and some relevant images with security paramter (just for dm-v)" |
|
319 |
echo "security_boot -build boot with security paramter" |
|
320 |
echo "security_uboot -build uboot with security paramter" |
|
321 |
echo "security_recovery -build recovery with security paramter" |
|
322 |
echo "security_check -check security paramter if it's good" |
|
323 |
echo "" |
|
324 |
echo "Default option is 'allsave'." |
|
325 |
} |
|
326 |
|
|
327 |
function build_info(){ |
|
328 |
if [ ! -L $TARGET_PRODUCT_DIR ];then |
|
329 |
echo "No found target product!!!" |
|
330 |
fi |
|
331 |
if [ ! -L $BOARD_CONFIG ];then |
|
332 |
echo "No found target board config!!!" |
|
333 |
fi |
|
334 |
|
|
335 |
if [ -f .repo/manifest.xml ]; then |
|
336 |
local sdk_ver="" |
|
337 |
sdk_ver=`grep "include name" .repo/manifest.xml | awk -F\" '{print $2}'` |
|
338 |
sdk_ver=`realpath .repo/manifests/${sdk_ver}` |
|
339 |
echo "Build SDK version: `basename ${sdk_ver}`" |
|
340 |
else |
|
341 |
echo "Not found .repo/manifest.xml [ignore] !!!" |
|
342 |
fi |
|
343 |
|
|
344 |
echo "Current Building Information:" |
|
345 |
echo "Target Product: $TARGET_PRODUCT_DIR" |
|
346 |
echo "Target BoardConfig: `realpath $BOARD_CONFIG`" |
|
347 |
echo "Target Misc config:" |
|
348 |
echo "`env |grep "^RK_" | grep -v "=$" | sort`" |
|
349 |
|
|
350 |
local kernel_file_dtb |
|
351 |
|
|
352 |
if [ "$RK_ARCH" == "arm" ]; then |
|
353 |
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm/boot/dts/${RK_KERNEL_DTS}.dtb" |
|
354 |
else |
|
355 |
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/${RK_KERNEL_DTS}.dtb" |
|
356 |
fi |
|
357 |
|
|
358 |
rm -f $kernel_file_dtb |
|
359 |
|
|
360 |
cd kernel |
|
361 |
make ARCH=$RK_ARCH dtbs -j$RK_JOBS |
|
362 |
|
|
363 |
build_check_power_domain |
|
364 |
} |
|
365 |
|
|
366 |
function build_check_power_domain(){ |
|
367 |
local dump_kernel_dtb_file |
|
368 |
local tmp_phandle_file |
|
369 |
local tmp_io_domain_file |
|
370 |
local tmp_regulator_microvolt_file |
|
371 |
local tmp_final_target |
|
372 |
local tmp_none_item |
|
373 |
local kernel_file_dtb_dts |
|
374 |
|
|
375 |
if [ "$RK_ARCH" == "arm" ]; then |
|
376 |
kernel_file_dtb_dts="${TOP_DIR}/kernel/arch/arm/boot/dts/$RK_KERNEL_DTS" |
|
377 |
else |
|
378 |
kernel_file_dtb_dts="${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/$RK_KERNEL_DTS" |
|
379 |
fi |
|
380 |
|
|
381 |
dump_kernel_dtb_file=${kernel_file_dtb_dts}.dump.dts |
|
382 |
tmp_phandle_file=`mktemp` |
|
383 |
tmp_io_domain_file=`mktemp` |
|
384 |
tmp_regulator_microvolt_file=`mktemp` |
|
385 |
tmp_final_target=`mktemp` |
|
386 |
tmp_grep_file=`mktemp` |
|
387 |
|
|
388 |
dtc -I dtb -O dts -o ${dump_kernel_dtb_file} ${kernel_file_dtb_dts}.dtb 2>/dev/null |
|
389 |
|
|
390 |
if [ "$RK_SYSTEM_CHECK_METHOD" = "DM-E" ] ; then |
|
391 |
if ! grep "compatible = \"linaro,optee-tz\";" $dump_kernel_dtb_file > /dev/null 2>&1 ; then |
|
392 |
echo "Please add: " |
|
393 |
echo " optee: optee {" |
|
394 |
echo " compatible = \"linaro,optee-tz\";" |
|
395 |
echo " method = \"smc\";" |
|
396 |
echo " status = \"okay\";" |
|
397 |
echo " }" |
|
398 |
echo "To your dts file" |
|
399 |
return -1; |
|
400 |
fi |
|
401 |
fi |
|
402 |
|
|
403 |
if ! grep -Pzo "io-domains\s*{(\n|\w|-|;|=|<|>|\"|_|\s|,)*};" $dump_kernel_dtb_file 1>$tmp_grep_file 2>/dev/null; then |
|
404 |
echo "Not Found io-domains in ${kernel_file_dtb_dts}.dts" |
|
405 |
rm -f $tmp_grep_file |
|
406 |
return 0 |
|
407 |
fi |
|
408 |
grep -a supply $tmp_grep_file > $tmp_io_domain_file |
|
409 |
rm -f $tmp_grep_file |
|
410 |
awk '{print "phandle = " $3}' $tmp_io_domain_file > $tmp_phandle_file |
|
411 |
|
|
412 |
|
|
413 |
while IFS= read -r item_phandle && IFS= read -u 3 -r item_domain |
|
414 |
do |
|
415 |
echo "${item_domain% *}" >> $tmp_regulator_microvolt_file |
|
416 |
tmp_none_item=${item_domain% *} |
|
417 |
cmds="grep -Pzo \"{(\\n|\w|-|;|=|<|>|\\\"|_|\s)*"$item_phandle\" |
|
418 |
|
|
419 |
eval "$cmds $dump_kernel_dtb_file | strings | grep "regulator-m..-microvolt" >> $tmp_regulator_microvolt_file" || \ |
|
420 |
eval "sed -i \"/${tmp_none_item}/d\" $tmp_regulator_microvolt_file" && continue |
|
421 |
|
|
422 |
echo >> $tmp_regulator_microvolt_file |
|
423 |
done < $tmp_phandle_file 3<$tmp_io_domain_file |
|
424 |
|
|
425 |
while read -r regulator_val |
|
426 |
do |
|
427 |
if echo ${regulator_val} | grep supply &>/dev/null; then |
|
428 |
echo -e "\n\n\e[1;33m${regulator_val%*=}\e[0m" >> $tmp_final_target |
|
429 |
else |
|
430 |
tmp_none_item=${regulator_val##*<} |
|
431 |
tmp_none_item=${tmp_none_item%%>*} |
|
432 |
echo -e "${regulator_val%%<*} \e[1;31m$(( $tmp_none_item / 1000 ))mV\e[0m" >> $tmp_final_target |
|
433 |
fi |
|
434 |
done < $tmp_regulator_microvolt_file |
|
435 |
|
|
436 |
echo -e "\e[41;1;30m PLEASE CHECK BOARD GPIO POWER DOMAIN CONFIGURATION !!!!!\e[0m" |
|
437 |
echo -e "\e[41;1;30m <<< ESPECIALLY Wi-Fi/Flash/Ethernet IO power domain >>> !!!!!\e[0m" |
|
438 |
echo -e "\e[41;1;30m Check Node [pmu_io_domains] in the file: ${kernel_file_dtb_dts}.dts \e[0m" |
|
439 |
echo |
|
440 |
echo -e "\e[41;1;30m 请再次确认板级的电源域配置!!!!!!\e[0m" |
|
441 |
echo -e "\e[41;1;30m <<< 特别是Wi-Fi,FLASH,以太网这几路IO电源的配置 >>> !!!!!\e[0m" |
|
442 |
echo -e "\e[41;1;30m 检查内核文件 ${kernel_file_dtb_dts}.dts 的节点 [pmu_io_domains] \e[0m" |
|
443 |
cat $tmp_final_target |
|
444 |
|
|
445 |
rm -f $tmp_phandle_file |
|
446 |
rm -f $tmp_regulator_microvolt_file |
|
447 |
rm -f $tmp_io_domain_file |
|
448 |
rm -f $tmp_final_target |
|
449 |
rm -f $dump_kernel_dtb_file |
|
450 |
} |
|
451 |
|
|
452 |
function build_check_cross_compile(){ |
|
453 |
|
|
454 |
case $RK_ARCH in |
|
455 |
arm|armhf) |
|
456 |
if [ -d "$TOP_DIR/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf" ]; then |
|
457 |
CROSS_COMPILE=$(realpath $TOP_DIR)/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-linux-gnueabihf- |
|
458 |
export CROSS_COMPILE=$CROSS_COMPILE |
|
459 |
fi |
|
460 |
;; |
|
461 |
arm64|aarch64) |
|
462 |
if [ -d "$TOP_DIR/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu" ]; then |
|
463 |
CROSS_COMPILE=$(realpath $TOP_DIR)/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- |
|
464 |
export CROSS_COMPILE=$CROSS_COMPILE |
|
465 |
fi |
|
466 |
;; |
|
467 |
*) |
|
468 |
echo "the $RK_ARCH not supported for now, please check it again\n" |
|
469 |
;; |
|
470 |
esac |
|
471 |
} |
|
472 |
|
|
473 |
function build_check(){ |
|
474 |
local build_depend_cfg="build-depend-tools.txt" |
|
475 |
common_product_build_tools="device/rockchip/common/$build_depend_cfg" |
|
476 |
target_product_build_tools="device/rockchip/$RK_TARGET_PRODUCT/$build_depend_cfg" |
|
477 |
cat $common_product_build_tools $target_product_build_tools 2>/dev/null | while read chk_item |
|
478 |
do |
|
479 |
chk_item=${chk_item###*} |
|
480 |
if [ -z "$chk_item" ]; then |
|
481 |
continue |
|
482 |
fi |
|
483 |
|
|
484 |
dst=${chk_item%%,*} |
|
485 |
src=${chk_item##*,} |
|
486 |
echo "**************************************" |
|
487 |
if eval $dst &>/dev/null;then |
|
488 |
echo "Check [OK]: $dst" |
|
489 |
else |
|
490 |
echo "Please install ${dst%% *} first" |
|
491 |
echo " sudo apt-get install $src" |
|
492 |
fi |
|
493 |
done |
|
494 |
} |
|
495 |
|
|
496 |
function build_pkg() { |
|
497 |
check_config RK_CFG_BUILDROOT || check_config RK_CFG_RAMBOOT || check_config RK_CFG_RECOVERY || check_config RK_CFG_PCBA || return 0 |
|
498 |
|
|
499 |
local target_pkg=$1 |
|
500 |
target_pkg=${target_pkg%*/} |
|
501 |
|
|
502 |
if [ ! -d $target_pkg ];then |
|
503 |
echo "build pkg: error: not found package $target_pkg" |
|
504 |
return 1 |
|
505 |
fi |
|
506 |
|
|
507 |
if ! eval [ $rk_package_mk_arrry ];then |
|
508 |
rk_package_mk_arrry=( $(find buildroot/package/rockchip/ -name "*.mk" | sort) ) |
|
509 |
fi |
|
510 |
|
|
511 |
local pkg_mk pkg_config_in pkg_br pkg_final_target pkg_final_target_upper pkg_cfg |
|
512 |
|
|
513 |
for it in ${rk_package_mk_arrry[@]} |
|
514 |
do |
|
515 |
pkg_final_target=$(basename $it) |
|
516 |
pkg_final_target=${pkg_final_target%%.mk*} |
|
517 |
pkg_final_target_upper=${pkg_final_target^^} |
|
518 |
pkg_final_target_upper=${pkg_final_target_upper//-/_} |
|
519 |
if grep "${pkg_final_target_upper}_SITE.*$target_pkg" $it &>/dev/null; then |
|
520 |
pkg_mk=$it |
|
521 |
pkg_config_in=$(dirname $pkg_mk)/Config.in |
|
522 |
pkg_br=BR2_PACKAGE_$pkg_final_target_upper |
|
523 |
|
|
524 |
for cfg in RK_CFG_BUILDROOT RK_CFG_RAMBOOT RK_CFG_RECOVERY RK_CFG_PCBA |
|
525 |
do |
|
526 |
if eval [ \$$cfg ] ;then |
|
527 |
pkg_cfg=$( eval "echo \$$cfg" ) |
|
528 |
if grep -wq ${pkg_br}=y buildroot/output/$pkg_cfg/.config; then |
|
529 |
echo "Found $pkg_br in buildroot/output/$pkg_cfg/.config " |
|
530 |
make -C buildroot/output/$pkg_cfg ${pkg_final_target}-dirclean O=buildroot/output/$pkg_cfg |
|
531 |
make -C buildroot/output/$pkg_cfg ${pkg_final_target}-rebuild O=buildroot/output/$pkg_cfg |
|
532 |
else |
|
533 |
echo "[SKIP BUILD $target_pkg] NOT Found ${pkg_br}=y in buildroot/output/$pkg_cfg/.config" |
|
534 |
fi |
|
535 |
fi |
|
536 |
done |
|
537 |
fi |
|
538 |
done |
|
539 |
|
|
540 |
finish_build |
|
541 |
} |
|
542 |
|
|
543 |
function build_uefi(){ |
|
544 |
build_check_cross_compile |
|
545 |
local kernel_file_dtb |
|
546 |
|
|
547 |
if [ "$RK_ARCH" == "arm" ]; then |
|
548 |
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm/boot/dts/${RK_KERNEL_DTS}.dtb" |
|
549 |
else |
|
550 |
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/${RK_KERNEL_DTS}.dtb" |
|
551 |
fi |
|
552 |
|
|
553 |
echo "============Start building uefi============" |
|
554 |
echo "Copy kernel dtb $kernel_file_dtb to uefi/edk2-platforms/Platform/Rockchip/DeviceTree/rk3588.dtb" |
|
555 |
echo "=========================================" |
|
556 |
if [ ! -f $kernel_file_dtb ]; then |
|
557 |
echo "Please compile the kernel before" |
|
558 |
return -1 |
|
559 |
fi |
|
560 |
|
|
561 |
cp $kernel_file_dtb uefi/edk2-platforms/Platform/Rockchip/DeviceTree/rk3588.dtb |
|
562 |
cd uefi |
|
563 |
./make.sh $RK_UBOOT_DEFCONFIG |
|
564 |
cd - |
|
565 |
|
|
566 |
finish_build |
|
567 |
} |
|
568 |
|
|
569 |
function build_uboot(){ |
|
570 |
check_config RK_UBOOT_DEFCONFIG || return 0 |
|
571 |
build_check_cross_compile |
|
572 |
prebuild_uboot |
|
573 |
prebuild_security_uboot $@ |
|
574 |
|
|
575 |
echo "============Start building uboot============" |
|
576 |
echo "TARGET_UBOOT_CONFIG=$RK_UBOOT_DEFCONFIG" |
|
577 |
echo "=========================================" |
|
578 |
|
|
579 |
cd u-boot |
|
580 |
rm -f *_loader_*.bin |
|
581 |
if [ "$RK_LOADER_UPDATE_SPL" = "true" ]; then |
|
582 |
rm -f *spl.bin |
|
583 |
fi |
|
584 |
|
|
585 |
if [ -n "$RK_UBOOT_DEFCONFIG_FRAGMENT" ]; then |
|
586 |
if [ -f "configs/${RK_UBOOT_DEFCONFIG}_defconfig" ]; then |
|
587 |
make ${RK_UBOOT_DEFCONFIG}_defconfig $RK_UBOOT_DEFCONFIG_FRAGMENT |
|
588 |
else |
|
589 |
make ${RK_UBOOT_DEFCONFIG}.config $RK_UBOOT_DEFCONFIG_FRAGMENT |
|
590 |
fi |
|
591 |
./make.sh $UBOOT_COMPILE_COMMANDS |
|
592 |
elif [ -d "$TOP_DIR/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf" ]; then |
|
593 |
./make.sh $RK_UBOOT_DEFCONFIG \ |
|
594 |
$UBOOT_COMPILE_COMMANDS CROSS_COMPILE=$CROSS_COMPILE |
|
595 |
elif [ -d "$TOP_DIR/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu" ]; then |
|
596 |
./make.sh $RK_UBOOT_DEFCONFIG \ |
|
597 |
$UBOOT_COMPILE_COMMANDS CROSS_COMPILE=$CROSS_COMPILE |
|
598 |
else |
|
599 |
./make.sh $RK_UBOOT_DEFCONFIG \ |
|
600 |
$UBOOT_COMPILE_COMMANDS |
|
601 |
fi |
|
602 |
|
|
603 |
if [ "$RK_IDBLOCK_UPDATE_SPL" = "true" ]; then |
|
604 |
./make.sh --idblock --spl |
|
605 |
fi |
|
606 |
|
|
607 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then |
|
608 |
ln -rsf $TOP_DIR/u-boot/boot.img $TOP_DIR/rockdev/ |
|
609 |
test -z "${RK_PACKAGE_FILE_AB}" && \ |
|
610 |
ln -rsf $TOP_DIR/u-boot/recovery.img $TOP_DIR/rockdev/ || true |
|
611 |
fi |
|
612 |
|
|
613 |
finish_build |
|
614 |
} |
|
615 |
|
|
616 |
# TODO: build_spl can be replaced by build_uboot with define RK_LOADER_UPDATE_SPL |
|
617 |
function build_spl(){ |
|
618 |
check_config RK_SPL_DEFCONFIG || return 0 |
|
619 |
|
|
620 |
echo "============Start building spl============" |
|
621 |
echo "TARGET_SPL_CONFIG=$RK_SPL_DEFCONFIG" |
|
622 |
echo "=========================================" |
|
623 |
|
|
624 |
cd u-boot |
|
625 |
rm -f *spl.bin |
|
626 |
./make.sh $RK_SPL_DEFCONFIG |
|
627 |
./make.sh --spl |
|
628 |
|
|
629 |
finish_build |
|
630 |
} |
|
631 |
|
|
632 |
function build_loader(){ |
|
633 |
check_config RK_LOADER_BUILD_TARGET || return 0 |
|
634 |
|
|
635 |
echo "============Start building loader============" |
|
636 |
echo "RK_LOADER_BUILD_TARGET=$RK_LOADER_BUILD_TARGET" |
|
637 |
echo "==========================================" |
|
638 |
|
|
639 |
cd loader |
|
640 |
./build.sh $RK_LOADER_BUILD_TARGET |
|
641 |
|
|
642 |
finish_build |
|
643 |
} |
|
644 |
|
|
645 |
function build_kernel(){ |
|
646 |
check_config RK_KERNEL_DTS RK_KERNEL_DEFCONFIG || return 0 |
|
647 |
|
|
648 |
echo "============Start building kernel============" |
|
649 |
echo "TARGET_ARCH =$RK_ARCH" |
|
650 |
echo "TARGET_KERNEL_CONFIG =$RK_KERNEL_DEFCONFIG" |
|
651 |
echo "TARGET_KERNEL_DTS =$RK_KERNEL_DTS" |
|
652 |
echo "TARGET_KERNEL_CONFIG_FRAGMENT =$RK_KERNEL_DEFCONFIG_FRAGMENT" |
|
653 |
echo "==========================================" |
|
654 |
|
|
655 |
build_check_cross_compile |
|
656 |
|
|
657 |
cd kernel |
|
658 |
make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT |
|
659 |
make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBS |
|
660 |
if [ -f "$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_KERNEL_FIT_ITS" ]; then |
|
661 |
$COMMON_DIR/mk-fitimage.sh $TOP_DIR/kernel/$RK_BOOT_IMG \ |
|
662 |
$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_KERNEL_FIT_ITS |
|
663 |
fi |
|
664 |
|
|
665 |
if [ -f "$TOP_DIR/kernel/$RK_BOOT_IMG" ]; then |
|
666 |
mkdir -p $TOP_DIR/rockdev |
|
667 |
ln -sf $TOP_DIR/kernel/$RK_BOOT_IMG $TOP_DIR/rockdev/boot.img |
|
668 |
fi |
|
669 |
|
|
670 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then |
|
671 |
cp $TOP_DIR/kernel/$RK_BOOT_IMG \ |
|
672 |
$TOP_DIR/u-boot/boot.img |
|
673 |
fi |
|
674 |
|
|
675 |
build_check_power_domain |
|
676 |
|
|
677 |
finish_build |
|
678 |
} |
|
679 |
|
|
680 |
function build_modules(){ |
|
681 |
check_config RK_KERNEL_DEFCONFIG || return 0 |
|
682 |
|
|
683 |
echo "============Start building kernel modules============" |
|
684 |
echo "TARGET_ARCH =$RK_ARCH" |
|
685 |
echo "TARGET_KERNEL_CONFIG =$RK_KERNEL_DEFCONFIG" |
|
686 |
echo "TARGET_KERNEL_CONFIG_FRAGMENT =$RK_KERNEL_DEFCONFIG_FRAGMENT" |
|
687 |
echo "==================================================" |
|
688 |
|
|
689 |
build_check_cross_compile |
|
690 |
|
|
691 |
cd kernel |
|
692 |
make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT |
|
693 |
make ARCH=$RK_ARCH modules -j$RK_JOBS |
|
694 |
|
|
695 |
finish_build |
|
696 |
} |
|
697 |
|
|
698 |
function build_toolchain(){ |
|
699 |
check_config RK_CFG_TOOLCHAIN || return 0 |
|
700 |
|
|
701 |
echo "==========Start building toolchain ==========" |
|
702 |
echo "TARGET_TOOLCHAIN_CONFIG=$RK_CFG_TOOLCHAIN" |
|
703 |
echo "=========================================" |
|
704 |
|
|
705 |
/usr/bin/time -f "you take %E to build toolchain" \ |
|
706 |
$COMMON_DIR/mk-toolchain.sh $BOARD_CONFIG |
|
707 |
|
|
708 |
finish_build |
|
709 |
} |
|
710 |
|
|
711 |
function build_buildroot(){ |
|
712 |
check_config RK_CFG_BUILDROOT || return 0 |
|
713 |
|
|
714 |
echo "==========Start building buildroot==========" |
|
715 |
echo "TARGET_BUILDROOT_CONFIG=$RK_CFG_BUILDROOT" |
|
716 |
echo "=========================================" |
|
717 |
|
|
718 |
/usr/bin/time -f "you take %E to build builroot" \ |
|
719 |
$COMMON_DIR/mk-buildroot.sh $BOARD_CONFIG |
|
720 |
|
|
721 |
finish_build |
|
722 |
} |
|
723 |
|
|
724 |
function build_ramboot(){ |
|
725 |
check_config RK_CFG_RAMBOOT || return 0 |
|
726 |
|
|
727 |
echo "=========Start building ramboot=========" |
|
728 |
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT" |
|
729 |
echo "=====================================" |
|
730 |
|
|
731 |
/usr/bin/time -f "you take %E to build ramboot" \ |
|
732 |
$COMMON_DIR/mk-ramdisk.sh ramboot.img $RK_CFG_RAMBOOT |
|
733 |
|
|
734 |
ln -rsf buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img \ |
|
735 |
rockdev/boot.img |
|
736 |
|
|
737 |
cp buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img \ |
|
738 |
u-boot/boot.img |
|
739 |
|
|
740 |
finish_build |
|
741 |
} |
|
742 |
|
|
743 |
function build_multi-npu_boot(){ |
|
744 |
check_config RK_MULTINPU_BOOT || return 0 |
|
745 |
|
|
746 |
echo "=========Start building multi-npu boot=========" |
|
747 |
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT" |
|
748 |
echo "=====================================" |
|
749 |
|
|
750 |
/usr/bin/time -f "you take %E to build multi-npu boot" \ |
|
751 |
$COMMON_DIR/mk-multi-npu_boot.sh |
|
752 |
|
|
753 |
finish_build |
|
754 |
} |
|
755 |
|
|
756 |
function kernel_version(){ |
|
757 |
VERSION_KEYS="VERSION PATCHLEVEL" |
|
758 |
VERSION="" |
|
759 |
|
|
760 |
for k in $VERSION_KEYS; do |
|
761 |
v=$(grep "^$k = " $1/Makefile | cut -d' ' -f3) |
|
762 |
VERSION=${VERSION:+${VERSION}.}$v |
|
763 |
done |
|
764 |
echo $VERSION |
|
765 |
} |
|
766 |
|
|
767 |
function build_yocto(){ |
|
768 |
check_config RK_YOCTO_MACHINE || return 0 |
|
769 |
|
|
770 |
echo "=========Start building ramboot=========" |
|
771 |
echo "TARGET_MACHINE=$RK_YOCTO_MACHINE" |
|
772 |
echo "=====================================" |
|
773 |
|
|
774 |
KERNEL_VERSION=$(kernel_version kernel/) |
|
775 |
|
|
776 |
cd yocto |
|
777 |
ln -sf $RK_YOCTO_MACHINE.conf build/conf/local.conf |
|
778 |
source oe-init-build-env |
|
779 |
LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8 \ |
|
780 |
bitbake core-image-minimal -r conf/include/rksdk.conf \ |
|
781 |
-r conf/include/kernel-$KERNEL_VERSION.conf |
|
782 |
|
|
783 |
finish_build |
|
784 |
} |
|
785 |
|
|
786 |
function build_debian(){ |
|
787 |
ARCH=${RK_DEBIAN_ARCH:-${RK_ARCH}} |
|
788 |
case $ARCH in |
|
789 |
arm|armhf) ARCH=armhf ;; |
|
790 |
*) ARCH=arm64 ;; |
|
791 |
esac |
|
792 |
|
|
793 |
echo "=========Start building debian for $ARCH=========" |
|
794 |
|
|
795 |
cd debian |
|
796 |
if [ ! -e linaro-$RK_DEBIAN_VERSION-alip-*.tar.gz ]; then |
|
797 |
RELEASE=$RK_DEBIAN_VERSION TARGET=desktop ARCH=$ARCH ./mk-base-debian.sh |
|
798 |
ln -rsf linaro-$RK_DEBIAN_VERSION-alip-*.tar.gz linaro-$RK_DEBIAN_VERSION-$ARCH.tar.gz |
|
799 |
fi |
|
800 |
|
|
801 |
VERSION=debug ARCH=$ARCH ./mk-rootfs-$RK_DEBIAN_VERSION.sh |
|
802 |
./mk-image.sh |
|
803 |
|
|
804 |
finish_build |
|
805 |
} |
|
806 |
|
|
807 |
function build_ubuntu(){ |
|
808 |
echo "=========Start building ubuntu for $ARCH=========" |
|
809 |
|
|
810 |
cd ubuntu |
|
811 |
./mk-rootfs-ubuntu.sh |
|
812 |
./mk-image.sh |
|
813 |
|
|
814 |
finish_build |
|
815 |
} |
|
816 |
|
|
817 |
function build_rootfs(){ |
|
818 |
check_config RK_ROOTFS_IMG || return 0 |
|
819 |
|
|
820 |
RK_ROOTFS_DIR=.rootfs |
|
821 |
ROOTFS_IMG=${RK_ROOTFS_IMG##*/} |
|
822 |
|
|
823 |
rm -rf $RK_ROOTFS_IMG $RK_ROOTFS_DIR |
|
824 |
mkdir -p ${RK_ROOTFS_IMG%/*} $RK_ROOTFS_DIR |
|
825 |
|
|
826 |
case "$1" in |
|
827 |
yocto) |
|
828 |
build_yocto |
|
829 |
ln -rsf yocto/build/latest/rootfs.img \ |
|
830 |
$RK_ROOTFS_DIR/rootfs.ext4 |
|
831 |
;; |
|
832 |
debian) |
|
833 |
build_debian |
|
834 |
ln -rsf debian/linaro-rootfs.img \ |
|
835 |
$RK_ROOTFS_DIR/rootfs.ext4 |
|
836 |
;; |
|
837 |
ubuntu) |
|
838 |
build_ubuntu |
|
839 |
ln -rsf ubuntu/ubuntu-rootfs.img \ |
|
840 |
$RK_ROOTFS_DIR/rootfs.ext4 |
|
841 |
;; |
|
842 |
*) |
|
843 |
|
|
844 |
build_buildroot |
|
845 |
for f in $(ls buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.*);do |
|
846 |
ln -rsf $f $RK_ROOTFS_DIR/ |
|
847 |
done |
|
848 |
;; |
|
849 |
esac |
|
850 |
|
|
851 |
if [ ! -f "$RK_ROOTFS_DIR/$ROOTFS_IMG" ]; then |
|
852 |
echo "There's no $ROOTFS_IMG generated..." |
|
853 |
exit 1 |
|
854 |
fi |
|
855 |
|
|
856 |
ln -rsf $RK_ROOTFS_DIR/$ROOTFS_IMG $RK_ROOTFS_IMG |
|
857 |
|
|
858 |
finish_build |
|
859 |
} |
|
860 |
|
|
861 |
function build_recovery(){ |
|
862 |
|
|
863 |
if [ "$RK_UPDATE_SDCARD_ENABLE_FOR_AB" = "true" ] ;then |
|
864 |
RK_CFG_RECOVERY=$RK_UPDATE_SDCARD_CFG_RECOVERY |
|
865 |
fi |
|
866 |
|
|
867 |
if [ ! -z "$RK_PACKAGE_FILE_AB" ]; then |
|
868 |
return 0 |
|
869 |
fi |
|
870 |
|
|
871 |
check_config RK_CFG_RECOVERY || return 0 |
|
872 |
|
|
873 |
echo "==========Start building recovery==========" |
|
874 |
echo "TARGET_RECOVERY_CONFIG=$RK_CFG_RECOVERY" |
|
875 |
echo "========================================" |
|
876 |
|
|
877 |
/usr/bin/time -f "you take %E to build recovery" \ |
|
878 |
$COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY |
|
879 |
|
|
880 |
ln -rsf buildroot/output/$RK_CFG_RECOVERY/images/recovery.img \ |
|
881 |
rockdev/recovery.img |
|
882 |
|
|
883 |
cp buildroot/output/$RK_CFG_RECOVERY/images/recovery.img \ |
|
884 |
u-boot/recovery.img |
|
885 |
|
|
886 |
finish_build |
|
887 |
} |
|
888 |
|
|
889 |
function build_pcba(){ |
|
890 |
check_config RK_CFG_PCBA || return 0 |
|
891 |
|
|
892 |
echo "==========Start building pcba==========" |
|
893 |
echo "TARGET_PCBA_CONFIG=$RK_CFG_PCBA" |
|
894 |
echo "====================================" |
|
895 |
|
|
896 |
/usr/bin/time -f "you take %E to build pcba" \ |
|
897 |
$COMMON_DIR/mk-ramdisk.sh pcba.img $RK_CFG_PCBA |
|
898 |
|
|
899 |
finish_build |
|
900 |
} |
|
901 |
|
|
902 |
BOOT_FIXED_CONFIGS=" |
|
903 |
CONFIG_BLK_DEV_DM |
|
904 |
CONFIG_DM_CRYPT |
|
905 |
CONFIG_BLK_DEV_CRYPTOLOOP |
|
906 |
CONFIG_DM_VERITY" |
|
907 |
|
|
908 |
BOOT_OPTEE_FIXED_CONFIGS=" |
|
909 |
CONFIG_TEE |
|
910 |
CONFIG_OPTEE" |
|
911 |
|
|
912 |
UBOOT_FIXED_CONFIGS=" |
|
913 |
CONFIG_FIT_SIGNATURE |
|
914 |
CONFIG_SPL_FIT_SIGNATURE" |
|
915 |
|
|
916 |
UBOOT_AB_FIXED_CONFIGS=" |
|
917 |
CONFIG_ANDROID_AB" |
|
918 |
|
|
919 |
ROOTFS_UPDATE_ENGINEBIN_CONFIGS=" |
|
920 |
BR2_PACKAGE_RECOVERY |
|
921 |
BR2_PACKAGE_RECOVERY_UPDATEENGINEBIN" |
|
922 |
|
|
923 |
ROOTFS_AB_FIXED_CONFIGS=" |
|
924 |
$ROOTFS_UPDATE_ENGINEBIN_CONFIGS |
|
925 |
BR2_PACKAGE_RECOVERY_BOOTCONTROL" |
|
926 |
|
|
927 |
function defconfig_check() { |
|
928 |
# 1. defconfig 2. fixed config |
|
929 |
echo debug-$1 |
|
930 |
for i in $2 |
|
931 |
do |
|
932 |
echo "look for $i" |
|
933 |
result=$(cat $1 | grep "${i}=y" -w || echo "No found") |
|
934 |
if [ "$result" = "No found" ]; then |
|
935 |
echo -e "\e[41;1;37mSecurity: No found config ${i} in $1 \e[0m" |
|
936 |
echo "make sure your config include this list" |
|
937 |
echo "---------------------------------------" |
|
938 |
echo "$2" |
|
939 |
echo "---------------------------------------" |
|
940 |
return -1; |
|
941 |
fi |
|
942 |
done |
|
943 |
return 0 |
|
944 |
} |
|
945 |
|
|
946 |
function find_string_in_config(){ |
|
947 |
result=$(cat "$2" | grep "$1" || echo "No found") |
|
948 |
if [ "$result" = "No found" ]; then |
|
949 |
echo "Security: No found string $1 in $2" |
|
950 |
return -1; |
|
951 |
fi |
|
952 |
return 0; |
|
953 |
} |
|
954 |
|
|
955 |
function check_security_condition(){ |
|
956 |
# check security enabled |
|
957 |
test -z "$RK_SYSTEM_CHECK_METHOD" && return 0 |
|
958 |
|
|
959 |
if [ ! -d u-boot/keys ]; then |
|
960 |
echo "ERROR: No root keys(u-boot/keys) found in u-boot" |
|
961 |
echo " Create it by ./build.sh createkeys or move your key to it" |
|
962 |
return -1 |
|
963 |
fi |
|
964 |
|
|
965 |
if [ "$RK_SYSTEM_CHECK_METHOD" = "DM-E" ]; then |
|
966 |
if [ ! -e u-boot/keys/root_passwd ]; then |
|
967 |
echo "ERROR: No root passwd(u-boot/keys/root_passwd) found in u-boot" |
|
968 |
echo " echo your root key for sudo to u-boot/keys/root_passwd" |
|
969 |
echo " some operations need supper user permission when create encrypt image" |
|
970 |
return -1 |
|
971 |
fi |
|
972 |
|
|
973 |
if [ ! -e u-boot/keys/system_enc_key ]; then |
|
974 |
echo "ERROR: No enc key(u-boot/keys/system_enc_key) found in u-boot" |
|
975 |
echo " Create it by ./build.sh createkeys or move your key to it" |
|
976 |
return -1 |
|
977 |
fi |
|
978 |
|
|
979 |
BOOT_FIXED_CONFIGS="${BOOT_FIXED_CONFIGS} |
|
980 |
${BOOT_OPTEE_FIXED_CONFIGS}" |
|
981 |
fi |
|
982 |
|
|
983 |
echo "check kernel defconfig" |
|
984 |
defconfig_check kernel/arch/$RK_ARCH/configs/$RK_KERNEL_DEFCONFIG "$BOOT_FIXED_CONFIGS" |
|
985 |
|
|
986 |
if [ ! -z "${RK_PACKAGE_FILE_AB}" ]; then |
|
987 |
UBOOT_FIXED_CONFIGS="${UBOOT_FIXED_CONFIGS} |
|
988 |
${UBOOT_AB_FIXED_CONFIGS}" |
|
989 |
|
|
990 |
defconfig_check buildroot/configs/${RK_CFG_BUILDROOT}_defconfig "$ROOTFS_AB_FIXED_CONFIGS" |
|
991 |
fi |
|
992 |
echo "check uboot defconfig" |
|
993 |
defconfig_check u-boot/configs/${RK_UBOOT_DEFCONFIG}_defconfig "$UBOOT_FIXED_CONFIGS" |
|
994 |
|
|
995 |
if [ "$RK_SYSTEM_CHECK_METHOD" = "DM-E" ]; then |
|
996 |
echo "check ramdisk defconfig" |
|
997 |
defconfig_check buildroot/configs/${RK_CFG_RAMBOOT}_defconfig "$ROOTFS_UPDATE_ENGINEBIN_CONFIGS" |
|
998 |
fi |
|
999 |
|
|
1000 |
echo "check rootfs defconfig" |
|
1001 |
find_string_in_config "BR2_ROOTFS_OVERLAY=\".*board/rockchip/common/security-system-overlay.*" "buildroot/configs/${RK_CFG_BUILDROOT}_defconfig" |
|
1002 |
|
|
1003 |
echo "Security: finish check" |
|
1004 |
} |
|
1005 |
|
|
1006 |
function build_all(){ |
|
1007 |
echo "============================================" |
|
1008 |
echo "TARGET_ARCH=$RK_ARCH" |
|
1009 |
echo "TARGET_PLATFORM=$RK_TARGET_PRODUCT" |
|
1010 |
echo "TARGET_UBOOT_CONFIG=$RK_UBOOT_DEFCONFIG" |
|
1011 |
echo "TARGET_SPL_CONFIG=$RK_SPL_DEFCONFIG" |
|
1012 |
echo "TARGET_KERNEL_CONFIG=$RK_KERNEL_DEFCONFIG" |
|
1013 |
echo "TARGET_KERNEL_DTS=$RK_KERNEL_DTS" |
|
1014 |
echo "TARGET_TOOLCHAIN_CONFIG=$RK_CFG_TOOLCHAIN" |
|
1015 |
echo "TARGET_BUILDROOT_CONFIG=$RK_CFG_BUILDROOT" |
|
1016 |
echo "TARGET_RECOVERY_CONFIG=$RK_CFG_RECOVERY" |
|
1017 |
echo "TARGET_PCBA_CONFIG=$RK_CFG_PCBA" |
|
1018 |
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT" |
|
1019 |
echo "============================================" |
|
1020 |
|
|
1021 |
# NOTE: On secure boot-up world, if the images build with fit(flattened image tree) |
|
1022 |
# we will build kernel and ramboot firstly, |
|
1023 |
# and then copy images into u-boot to sign the images. |
|
1024 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" != "true" ];then |
|
1025 |
#note: if build spl, it will delete loader.bin in uboot directory, |
|
1026 |
# so can not build uboot and spl at the same time. |
|
1027 |
if [ -z $RK_SPL_DEFCONFIG ]; then |
|
1028 |
build_uboot |
|
1029 |
else |
|
1030 |
build_spl |
|
1031 |
fi |
|
1032 |
fi |
|
1033 |
|
|
1034 |
check_security_condition |
|
1035 |
build_loader |
|
1036 |
build_kernel |
|
1037 |
build_toolchain |
|
1038 |
build_rootfs ${RK_ROOTFS_SYSTEM:-buildroot} |
|
1039 |
build_recovery |
|
1040 |
build_ramboot |
|
1041 |
|
|
1042 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then |
|
1043 |
#note: if build spl, it will delete loader.bin in uboot directory, |
|
1044 |
# so can not build uboot and spl at the same time. |
|
1045 |
if [ -z $RK_SPL_DEFCONFIG ]; then |
|
1046 |
build_uboot |
|
1047 |
else |
|
1048 |
build_spl |
|
1049 |
fi |
|
1050 |
fi |
|
1051 |
|
|
1052 |
finish_build |
|
1053 |
} |
|
1054 |
|
|
1055 |
function build_cleanall(){ |
|
1056 |
echo "clean uboot, kernel, rootfs, recovery" |
|
1057 |
|
|
1058 |
cd u-boot |
|
1059 |
make distclean |
|
1060 |
cd - |
|
1061 |
cd kernel |
|
1062 |
make distclean |
|
1063 |
cd - |
|
1064 |
rm -rf buildroot/output |
|
1065 |
rm -rf yocto/build/tmp |
|
1066 |
rm -rf debian/binary |
|
1067 |
rm -rf debian/linaro-rootfs.img |
|
1068 |
rm -rf ubuntu/binary |
|
1069 |
rm -rf ubuntu/ubuntu-rootfs.img |
|
1070 |
rm -rf rockdev/* |
|
1071 |
finish_build |
|
1072 |
} |
|
1073 |
|
|
1074 |
function build_firmware(){ |
|
1075 |
./mkfirmware.sh $BOARD_CONFIG |
|
1076 |
|
|
1077 |
finish_build |
|
1078 |
} |
|
1079 |
|
|
1080 |
function build_updateimg(){ |
|
1081 |
IMAGE_PATH=$TOP_DIR/rockdev |
|
1082 |
PACK_TOOL_DIR=$TOP_DIR/tools/linux/Linux_Pack_Firmware |
|
1083 |
|
|
1084 |
cd $PACK_TOOL_DIR/rockdev |
|
1085 |
|
|
1086 |
if [ -f "$RK_PACKAGE_FILE_AB" ]; then |
|
1087 |
build_sdcard_package |
|
1088 |
build_otapackage |
|
1089 |
|
|
1090 |
cd $PACK_TOOL_DIR/rockdev |
|
1091 |
echo "Make Linux a/b update_ab.img." |
|
1092 |
source_package_file_name=`ls -lh package-file | awk -F ' ' '{print $NF}'` |
|
1093 |
ln -fs "$RK_PACKAGE_FILE_AB" package-file |
|
1094 |
./mkupdate.sh |
|
1095 |
mv update.img $IMAGE_PATH/update_ab.img |
|
1096 |
ln -fs $source_package_file_name package-file |
|
1097 |
else |
|
1098 |
echo "Make update.img" |
|
1099 |
|
|
1100 |
if [ -f "$RK_PACKAGE_FILE" ]; then |
|
1101 |
source_package_file_name=`ls -lh package-file | awk -F ' ' '{print $NF}'` |
|
1102 |
ln -fs "$RK_PACKAGE_FILE" package-file |
|
1103 |
./mkupdate.sh |
|
1104 |
ln -fs $source_package_file_name package-file |
|
1105 |
else |
|
1106 |
./mkupdate.sh |
|
1107 |
fi |
|
1108 |
mv update.img $IMAGE_PATH |
|
1109 |
fi |
|
1110 |
|
|
1111 |
finish_build |
|
1112 |
} |
|
1113 |
|
|
1114 |
function build_otapackage(){ |
|
1115 |
IMAGE_PATH=$TOP_DIR/rockdev |
|
1116 |
PACK_TOOL_DIR=$TOP_DIR/tools/linux/Linux_Pack_Firmware |
|
1117 |
|
|
1118 |
echo "Make ota ab update_ota.img" |
|
1119 |
cd $PACK_TOOL_DIR/rockdev |
|
1120 |
if [ -f "$RK_PACKAGE_FILE_OTA" ]; then |
|
1121 |
source_package_file_name=`ls -lh $PACK_TOOL_DIR/rockdev/package-file | awk -F ' ' '{print $NF}'` |
|
1122 |
ln -fs "$RK_PACKAGE_FILE_OTA" package-file |
|
1123 |
./mkupdate.sh |
|
1124 |
mv update.img $IMAGE_PATH/update_ota.img |
|
1125 |
ln -fs $source_package_file_name package-file |
|
1126 |
fi |
|
1127 |
|
|
1128 |
finish_build |
|
1129 |
} |
|
1130 |
|
|
1131 |
function build_sdcard_package(){ |
|
1132 |
|
|
1133 |
check_config RK_UPDATE_SDCARD_ENABLE_FOR_AB || return 0 |
|
1134 |
|
|
1135 |
local image_path=$TOP_DIR/rockdev |
|
1136 |
local pack_tool_dir=$TOP_DIR/tools/linux/Linux_Pack_Firmware |
|
1137 |
local rk_sdupdate_ab_misc=${RK_SDUPDATE_AB_MISC:=sdupdate-ab-misc.img} |
|
1138 |
local rk_parameter_sdupdate=${RK_PARAMETER_SDUPDATE:=parameter-sdupdate.txt} |
|
1139 |
local rk_package_file_sdcard_update=${RK_PACKAGE_FILE_SDCARD_UPDATE:=sdcard-update-package-file} |
|
1140 |
local sdupdate_ab_misc_img=$TOP_DIR/device/rockchip/rockimg/$rk_sdupdate_ab_misc |
|
1141 |
local parameter_sdupdate=$TOP_DIR/device/rockchip/rockimg/$rk_parameter_sdupdate |
|
1142 |
local recovery_img=$TOP_DIR/buildroot/output/$RK_UPDATE_SDCARD_CFG_RECOVERY/images/recovery.img |
|
1143 |
|
|
1144 |
if [ $RK_UPDATE_SDCARD_CFG_RECOVERY ]; then |
|
1145 |
if [ -f $recovery_img ]; then |
|
1146 |
echo -n "create recovery.img..." |
|
1147 |
ln -rsf $recovery_img $image_path/recovery.img |
|
1148 |
else |
|
1149 |
echo "error: $recovery_img not found!" |
|
1150 |
return 1 |
|
1151 |
fi |
|
1152 |
fi |
|
1153 |
|
|
1154 |
|
|
1155 |
echo "Make sdcard update update_sdcard.img" |
|
1156 |
cd $pack_tool_dir/rockdev |
|
1157 |
if [ -f "$rk_package_file_sdcard_update" ]; then |
|
1158 |
|
|
1159 |
if [ $rk_parameter_sdupdate ]; then |
|
1160 |
if [ -f $parameter_sdupdate ]; then |
|
1161 |
echo -n "create sdcard update image parameter..." |
|
1162 |
ln -rsf $parameter_sdupdate $image_path/ |
|
1163 |
fi |
|
1164 |
fi |
|
1165 |
|
|
1166 |
if [ $rk_sdupdate_ab_misc ]; then |
|
1167 |
if [ -f $sdupdate_ab_misc_img ]; then |
|
1168 |
echo -n "create sdupdate ab misc.img..." |
|
1169 |
ln -rsf $sdupdate_ab_misc_img $image_path/ |
|
1170 |
fi |
|
1171 |
fi |
|
1172 |
|
|
1173 |
source_package_file_name=`ls -lh $pack_tool_dir/rockdev/package-file | awk -F ' ' '{print $NF}'` |
|
1174 |
ln -fs "$rk_package_file_sdcard_update" package-file |
|
1175 |
./mkupdate.sh |
|
1176 |
mv update.img $image_path/update_sdcard.img |
|
1177 |
ln -fs $source_package_file_name package-file |
|
1178 |
rm -f $image_path/$rk_sdupdate_ab_misc $image_path/$rk_parameter_sdupdate $image_path/recovery.img |
|
1179 |
fi |
|
1180 |
|
|
1181 |
finish_build |
|
1182 |
} |
|
1183 |
|
|
1184 |
function build_save(){ |
|
1185 |
IMAGE_PATH=$TOP_DIR/rockdev |
|
1186 |
DATE=$(date +%Y%m%d.%H%M) |
|
1187 |
STUB_PATH=Image/"$RK_KERNEL_DTS"_"$DATE"_RELEASE_TEST |
|
1188 |
STUB_PATH="$(echo $STUB_PATH | tr '[:lower:]' '[:upper:]')" |
|
1189 |
export STUB_PATH=$TOP_DIR/$STUB_PATH |
|
1190 |
export STUB_PATCH_PATH=$STUB_PATH/PATCHES |
|
1191 |
mkdir -p $STUB_PATH |
|
1192 |
|
|
1193 |
#Generate patches |
|
1194 |
.repo/repo/repo forall -c \ |
|
1195 |
"$TOP_DIR/device/rockchip/common/gen_patches_body.sh" |
|
1196 |
|
|
1197 |
#Copy stubs |
|
1198 |
.repo/repo/repo manifest -r -o $STUB_PATH/manifest_${DATE}.xml |
|
1199 |
mkdir -p $STUB_PATCH_PATH/kernel |
|
1200 |
cp kernel/.config $STUB_PATCH_PATH/kernel |
|
1201 |
cp kernel/vmlinux $STUB_PATCH_PATH/kernel |
|
1202 |
mkdir -p $STUB_PATH/IMAGES/ |
|
1203 |
cp $IMAGE_PATH/* $STUB_PATH/IMAGES/ |
|
1204 |
|
|
1205 |
#Save build command info |
|
1206 |
echo "UBOOT: defconfig: $RK_UBOOT_DEFCONFIG" >> $STUB_PATH/build_cmd_info |
|
1207 |
echo "KERNEL: defconfig: $RK_KERNEL_DEFCONFIG, dts: $RK_KERNEL_DTS" >> $STUB_PATH/build_cmd_info |
|
1208 |
echo "BUILDROOT: $RK_CFG_BUILDROOT" >> $STUB_PATH/build_cmd_info |
|
1209 |
|
|
1210 |
finish_build |
|
1211 |
} |
|
1212 |
|
|
1213 |
function build_allsave(){ |
|
1214 |
rm -fr $TOP_DIR/rockdev |
|
1215 |
build_all |
|
1216 |
build_firmware |
|
1217 |
build_updateimg |
|
1218 |
#build_save |
|
1219 |
|
|
1220 |
#build_check_power_domain |
|
1221 |
|
|
1222 |
finish_build |
|
1223 |
} |
|
1224 |
|
|
1225 |
function create_keys() { |
|
1226 |
test -d u-boot/keys && echo "ERROR: u-boot/keys has existed" && return -1 |
|
1227 |
|
|
1228 |
mkdir u-boot/keys -p |
|
1229 |
cd u-boot/keys |
|
1230 |
$TOP_DIR/rkbin/tools/rk_sign_tool kk --bits 2048 |
|
1231 |
cd - |
|
1232 |
|
|
1233 |
ln -s private_key.pem u-boot/keys/dev.key |
|
1234 |
ln -s public_key.pem u-boot/keys/dev.pubkey |
|
1235 |
openssl req -batch -new -x509 -key u-boot/keys/dev.key -out u-boot/keys/dev.crt |
|
1236 |
|
|
1237 |
openssl rand -out u-boot/keys/system_enc_key -hex 32 |
|
1238 |
} |
|
1239 |
|
|
1240 |
function security_is_enabled() |
|
1241 |
{ |
|
1242 |
if [ "$RK_RAMDISK_SECURITY_BOOTUP" != "true" ]; then |
|
1243 |
echo "No security paramter found in .BoardConfig.mk" |
|
1244 |
exit -1 |
|
1245 |
fi |
|
1246 |
} |
|
1247 |
|
|
1248 |
|
|
1249 |
#========================= |
|
1250 |
# build targets |
|
1251 |
#========================= |
|
1252 |
|
|
1253 |
if echo $@|grep -wqE "help|-h"; then |
|
1254 |
if [ -n "$2" -a "$(type -t usage$2)" == function ]; then |
|
1255 |
echo "###Current SDK Default [ $2 ] Build Command###" |
|
1256 |
eval usage$2 |
|
1257 |
else |
|
1258 |
usage |
|
1259 |
fi |
|
1260 |
exit 0 |
|
1261 |
fi |
|
1262 |
|
|
1263 |
OPTIONS="${@:-allsave}" |
|
1264 |
|
|
1265 |
[ -f "device/rockchip/$RK_TARGET_PRODUCT/$RK_BOARD_PRE_BUILD_SCRIPT" ] \ |
|
1266 |
&& source "device/rockchip/$RK_TARGET_PRODUCT/$RK_BOARD_PRE_BUILD_SCRIPT" # board hooks |
|
1267 |
|
|
1268 |
for option in ${OPTIONS}; do |
|
1269 |
echo "processing option: $option" |
|
1270 |
case $option in |
|
1271 |
BoardConfig*.mk) |
|
1272 |
option=device/rockchip/$RK_TARGET_PRODUCT/$option |
|
1273 |
;& |
|
1274 |
*.mk) |
|
1275 |
CONF=$(realpath $option) |
|
1276 |
echo "switching to board: $CONF" |
|
1277 |
if [ ! -f $CONF ]; then |
|
1278 |
echo "not exist!" |
|
1279 |
exit 1 |
|
1280 |
fi |
|
1281 |
|
|
1282 |
ln -rsf $CONF $BOARD_CONFIG |
|
1283 |
;; |
|
1284 |
lunch) build_select_board ;; |
|
1285 |
all) build_all ;; |
|
1286 |
save) build_save ;; |
|
1287 |
allsave) build_allsave ;; |
|
1288 |
check) build_check ;; |
|
1289 |
cleanall) build_cleanall ;; |
|
1290 |
firmware) build_firmware ;; |
|
1291 |
updateimg) build_updateimg ;; |
|
1292 |
otapackage) build_otapackage ;; |
|
1293 |
sdpackage) build_sdcard_package ;; |
|
1294 |
toolchain) build_toolchain ;; |
|
1295 |
spl) build_spl ;; |
|
1296 |
uboot) build_uboot ;; |
|
1297 |
uefi) build_uefi ;; |
|
1298 |
loader) build_loader ;; |
|
1299 |
kernel) build_kernel ;; |
|
1300 |
modules) build_modules ;; |
|
1301 |
rootfs|buildroot|debian|yocto|ubuntu) build_rootfs $option ;; |
|
1302 |
pcba) build_pcba ;; |
|
1303 |
ramboot) build_ramboot ;; |
|
1304 |
recovery) build_recovery ;; |
|
1305 |
multi-npu_boot) build_multi-npu_boot ;; |
|
1306 |
info) build_info ;; |
|
1307 |
app/*|external/*) build_pkg $option ;; |
|
1308 |
createkeys) create_keys ;; |
|
1309 |
security_boot) security_is_enabled; build_ramboot; build_uboot boot ;; |
|
1310 |
security_uboot) security_is_enabled; build_uboot uboot ;; |
|
1311 |
security_recovery) security_is_enabled; build_recovery; build_uboot recovery ;; |
|
1312 |
security_check) check_security_condition ;; |
|
1313 |
security_rootfs) |
|
1314 |
security_is_enabled |
|
1315 |
build_rootfs |
|
1316 |
build_ramboot |
|
1317 |
build_uboot |
|
1318 |
echo "please update rootfs.img / boot.img" |
|
1319 |
;; |
|
1320 |
*) usage ;; |
|
1321 |
esac |
|
1322 |
done |