forked from ariaboard-com/rockchip_rk3568_linux_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·1381 lines (1151 loc) · 38.6 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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
export LC_ALL=C
export LD_LIBRARY_PATH=
unset RK_CFG_TOOLCHAIN
SBINCHECK="$(echo $PATH | grep sbin)"
if [ x"${SBINCHECK}" = x"" ]; then
export PATH="${PATH}:/sbin:/usr/sbin"
fi
err_handler() {
ret=$?
[ "$ret" -eq 0 ] && return
echo "ERROR: Running ${FUNCNAME[1]} failed!"
echo "ERROR: exit code $ret from line ${BASH_LINENO[0]}:"
echo " $BASH_COMMAND"
exit $ret
}
trap 'err_handler' ERR
set -eE
function finish_build(){
echo "Running ${FUNCNAME[1]} succeeded."
cd $TOP_DIR
}
function check_config(){
unset missing
for var in $@; do
eval [ \$$var ] && continue
missing="$missing $var"
done
[ -z "$missing" ] && return 0
echo "Skipping ${FUNCNAME[1]} for missing configs: $missing."
return 1
}
function choose_target_board()
{
echo
echo "You're building on Linux"
echo "Lunch menu...pick a combo:"
echo ""
echo "0. default BoardConfig.mk"
echo ${RK_TARGET_BOARD_ARRAY[@]} | xargs -n 1 | sed "=" | sed "N;s/\n/. /"
local INDEX
read -p "Which would you like? [0]: " INDEX
INDEX=$((${INDEX:-0} - 1))
if echo $INDEX | grep -vq [^0-9]; then
RK_BUILD_TARGET_BOARD="${RK_TARGET_BOARD_ARRAY[$INDEX]}"
else
echo "Lunching for Default BoardConfig.mk boards..."
RK_BUILD_TARGET_BOARD=BoardConfig.mk
fi
}
function build_select_board()
{
RK_TARGET_BOARD_ARRAY=( $(cd ${TARGET_PRODUCT_DIR}/; ls *.mk | sort) )
RK_TARGET_BOARD_ARRAY_LEN=${#RK_TARGET_BOARD_ARRAY[@]}
if [ $RK_TARGET_BOARD_ARRAY_LEN -eq 0 ]; then
echo "No available Board Config"
return
fi
choose_target_board
ln -rfs $TARGET_PRODUCT_DIR/$RK_BUILD_TARGET_BOARD device/rockchip/.BoardConfig.mk
echo "switching to board: `realpath $BOARD_CONFIG`"
}
function unset_board_config_all()
{
local tmp_file=`mktemp`
grep -o "^export.*RK_.*=" `find $TOP_DIR/device/rockchip -name "Board*.mk" -type f` -h | sort | uniq > $tmp_file
source $tmp_file
rm -f $tmp_file
}
CMD=`realpath $0`
COMMON_DIR=`dirname $CMD`
TOP_DIR=$(realpath $COMMON_DIR/../../..)
IMGNAME=
BOARD_CONFIG=$TOP_DIR/device/rockchip/.BoardConfig.mk
TARGET_PRODUCT="$TOP_DIR/device/rockchip/.target_product"
TARGET_PRODUCT_DIR=$(realpath ${TARGET_PRODUCT})
unset_board_config_all
[ -L "$BOARD_CONFIG" ] && source $BOARD_CONFIG
source $TOP_DIR/device/rockchip/common/Version.mk
CFG_DIR=$TOP_DIR/device/rockchip
ROCKDEV=$TOP_DIR/rockdev
PARAMETER=$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_PARAMETER
SD_PARAMETER=$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_SD_PARAMETER
NPROC=`nproc`
export RK_JOBS=$NPROC
if [ ! -d "$TOP_DIR/rockdev/pack" ];then
mkdir -p rockdev/pack
fi
function prebuild_uboot()
{
UBOOT_COMPILE_COMMANDS="\
${RK_TRUST_INI_CONFIG:+../rkbin/RKTRUST/$RK_TRUST_INI_CONFIG} \
${RK_SPL_INI_CONFIG:+../rkbin/RKBOOT/$RK_SPL_INI_CONFIG} \
${RK_UBOOT_SIZE_CONFIG:+--sz-uboot $RK_UBOOT_SIZE_CONFIG} \
${RK_TRUST_SIZE_CONFIG:+--sz-trust $RK_TRUST_SIZE_CONFIG}"
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)"
if [ "$RK_LOADER_UPDATE_SPL" = "true" ]; then
UBOOT_COMPILE_COMMANDS="--spl-new $UBOOT_COMPILE_COMMANDS"
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)"
fi
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then
UBOOT_COMPILE_COMMANDS=" \
--boot_img $(cd $TOP_DIR && realpath ./rockdev/boot.img) \
--burn-key-hash $UBOOT_COMPILE_COMMANDS \
${RK_ROLLBACK_INDEX_BOOT:+--rollback-index-boot $RK_ROLLBACK_INDEX_BOOT} \
${RK_ROLLBACK_INDEX_UBOOT:+--rollback-index-uboot $RK_ROLLBACK_INDEX_UBOOT} "
UBOOT_COMPILE_COMMANDS="$(echo $UBOOT_COMPILE_COMMANDS)"
fi
}
function usagekernel()
{
check_config RK_KERNEL_DTS RK_KERNEL_DEFCONFIG || return 0
echo "cd kernel"
echo "make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT"
echo "make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBS"
}
function usageuboot()
{
check_config RK_UBOOT_DEFCONFIG || return 0
prebuild_uboot
cd u-boot
echo "cd u-boot"
if [ -n "$RK_UBOOT_DEFCONFIG_FRAGMENT" ]; then
if [ -f "configs/${RK_UBOOT_DEFCONFIG}_defconfig" ]; then
echo "make ${RK_UBOOT_DEFCONFIG}_defconfig $RK_UBOOT_DEFCONFIG_FRAGMENT"
else
echo "make ${RK_UBOOT_DEFCONFIG}.config $RK_UBOOT_DEFCONFIG_FRAGMENT"
fi
echo "./make.sh $UBOOT_COMPILE_COMMANDS"
else
echo "./make.sh $RK_UBOOT_DEFCONFIG $UBOOT_COMPILE_COMMANDS"
fi
if [ "$RK_IDBLOCK_UPDATE_SPL" = "true" ]; then
echo "./make.sh --idblock --spl"
fi
finish_build
}
function usagerootfs()
{
check_config RK_ROOTFS_IMG || return 0
if [ "${RK_CFG_BUILDROOT}x" != "x" ];then
echo "source envsetup.sh $RK_CFG_BUILDROOT"
else
if [ "${RK_CFG_RAMBOOT}x" != "x" ];then
echo "source envsetup.sh $RK_CFG_RAMBOOT"
else
echo "Not found config buildroot. Please Check !!!"
fi
fi
case "${RK_ROOTFS_SYSTEM:-buildroot}" in
yocto)
;;
debian)
;;
distro)
;;
*)
echo "make"
;;
esac
}
function usagerecovery()
{
check_config RK_CFG_RECOVERY || return 0
echo "source envsetup.sh $RK_CFG_RECOVERY"
echo "$COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY"
}
function usageramboot()
{
check_config RK_CFG_RAMBOOT || return 0
echo "source envsetup.sh $RK_CFG_RAMBOOT"
echo "$COMMON_DIR/mk-ramdisk.sh ramboot.img $RK_CFG_RAMBOOT"
}
function usagemodules()
{
check_config RK_KERNEL_DEFCONFIG || return 0
echo "cd kernel"
echo "make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG"
echo "make ARCH=$RK_ARCH modules -j$RK_JOBS"
}
function build_openwrt()
{
TARGET_OPENWRT_CONFIG="base_defconfig"
/usr/bin/time -f "you take %E to build OpenWRT" $COMMON_DIR/mk-openwrt.sh $TARGET_OPENWRT_CONFIG
if [ $? -eq 0 ]; then
echo "====Building OpenWRT OK!===="
else
echo "====Building OpenWRT failed!===="
exit 1
fi
}
function build_openwrt_sdimg()
{
IMAGE_PATH="${TOP_DIR}/rockdev"
BASE_IMG="${TOP_DIR}/device/rockchip/rockimg/sd.img.gz"
TARGET_IMG="${IMAGE_PATH}/openwrt-sdcard.img"
BOOT_IMG="${IMAGE_PATH}/openwrt-sdbootfs.img"
if [ ! -f "${TOP_DIR}/kernel/arch/arm64/boot/Image" ]; then
echo "No kernel found, please build kernel first!"
exit 1
fi
if [ ! -f "${IMAGE_PATH}/rootfs.img" ]; then
echo "No OpenWRT system image found, please build OpenWRT first!"
exit 1
fi
dd if=/dev/zero of="${BOOT_IMG}" bs=1M count=128
/sbin/mkfs.vfat -F 32 "${BOOT_IMG}"
mmd -i "${BOOT_IMG}" ::extlinux
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/device/rockchip/rockimg/sd-extlinux.conf" ::extlinux/extlinux.conf
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/kernel/arch/arm64/boot/Image" ::Image
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/rk3568-photonicat-openwrt.dtb" ::rk3568-photonicat-openwrt.dtb
gunzip -c "${BASE_IMG}" > "${TARGET_IMG}"
dd if="${BOOT_IMG}" of="${TARGET_IMG}" bs=1M count=128 seek=1 conv=notrunc
dd if="${IMAGE_PATH}/rootfs.img" of="${TARGET_IMG}" bs=1M count=1024 seek=129 conv=notrunc
rm -f "${BOOT_IMG}"
gzip -f "${TARGET_IMG}"
}
function build_openwrt_sdupdateimg()
{
IMAGE_PATH="${TOP_DIR}/rockdev"
BASE_IMG="${TOP_DIR}/device/rockchip/rockimg/sdupdate.img.gz"
TARGET_IMG="${IMAGE_PATH}/openwrt-update-sdcard.img"
BOOT_IMG="${IMAGE_PATH}/openwrt-sdbootfs.img"
UPDATEIMAGE_IMG="${IMAGE_PATH}/openwrt-sdimgfs.img"
if [ ! -f "${TOP_DIR}/kernel/arch/arm64/boot/Image" ]; then
echo "No kernel found, please build kernel first!"
exit 1
fi
if [ ! -f "${IMAGE_PATH}/rootfs.img" ]; then
echo "No OpenWRT system image found, please build OpenWRT first!"
exit 1
fi
if [ ! -f "${IMAGE_PATH}/boot.img" ]; then
echo "No boot image found, please build kernel first!"
exit 1
fi
dd if=/dev/zero of="${BOOT_IMG}" bs=1M count=128
/sbin/mkfs.vfat -F 32 "${BOOT_IMG}"
mmd -i "${BOOT_IMG}" ::extlinux
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/device/rockchip/rockimg/sdupdate-extlinux.conf" ::extlinux/extlinux.conf
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/kernel/arch/arm64/boot/Image" ::Image
mcopy -i "${BOOT_IMG}" "${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/rk3568-photonicat-openwrt.dtb" ::rk3568-photonicat-openwrt.dtb
mkdir -p "${IMAGE_PATH}/updatefs"
gzip -c "${IMAGE_PATH}/boot.img" > "${IMAGE_PATH}/updatefs/boot.img.gz"
gzip -c "${IMAGE_PATH}/rootfs.img" > "${IMAGE_PATH}/updatefs/rootfs.img.gz"
genext2fs -B 4096 -b 524288 -d "${IMAGE_PATH}/updatefs" "${UPDATEIMAGE_IMG}"
rm -rf "${IMAGE_PATH}/updatefs"
gunzip -c "${BASE_IMG}" > "${TARGET_IMG}"
dd if="${BOOT_IMG}" of="${TARGET_IMG}" bs=1M count=128 seek=1 conv=notrunc
dd if="${IMAGE_PATH}/rootfs.img" of="${TARGET_IMG}" bs=1M count=1024 seek=129 conv=notrunc
dd if="${UPDATEIMAGE_IMG}" of="${TARGET_IMG}" bs=1M count=2048 seek=1153 conv=notrunc
rm -f "${BOOT_IMG}"
rm -f "${UPDATEIMAGE_IMG}"
gzip -f "${TARGET_IMG}"
}
function usage()
{
echo "Usage: build.sh [OPTIONS]"
echo "Available options:"
echo "*.mk -switch to specified board config"
echo "lunch -list current SDK boards and switch to specified board config"
echo "uboot -build uboot"
echo "spl -build spl"
echo "loader -build loader"
echo "kernel -build kernel"
echo "modules -build kernel modules"
echo "toolchain -build toolchain"
echo "extboot -build extlinux boot.img, boot from EFI partition"
echo "rootfs -build default rootfs, currently build buildroot as default"
echo "buildroot -build buildroot rootfs"
echo "ramboot -build ramboot image"
echo "multi-npu_boot -build boot image for multi-npu board"
echo "yocto -build yocto rootfs"
echo "debian -build debian10 buster rootfs"
echo "openwrt -build OpenWRT rootfs"
echo "pcba -build pcba"
echo "recovery -build recovery"
echo "all -build uboot, kernel, rootfs, recovery image"
echo "cleanall -clean uboot, kernel, rootfs, recovery"
echo "firmware -pack all the image we need to boot up system"
echo "updateimg -pack update image"
echo "otapackage -pack ab update otapackage image (update_ota.img)"
echo "sdpackage -pack update sdcard package image (update_sdcard.img)"
echo "save -save images, patches, commands used to debug"
echo "allsave -build all & firmware & updateimg & save"
echo "check -check the environment of building"
echo "info -see the current board building information"
echo "app/<pkg> -build packages in the dir of app/*"
echo "external/<pkg> -build packages in the dir of external/*"
echo "openwrt-sdimg -build bootable OpenWRT SD card image which can be used in uboot"
echo "openwrt-sdupdateimg -build bootable SD card for update OpenWRT on eMMC, can be used in uboot"
echo ""
echo "Default option is 'allff'."
}
function build_info(){
if [ ! -L $TARGET_PRODUCT_DIR ];then
echo "No found target product!!!"
fi
if [ ! -L $BOARD_CONFIG ];then
echo "No found target board config!!!"
fi
echo "Current Building Information:"
echo "Target Product: $TARGET_PRODUCT_DIR"
echo "Target BoardConfig: `realpath $BOARD_CONFIG`"
echo "Target Misc config:"
echo "`env |grep "^RK_" | grep -v "=$" | sort`"
local kernel_file_dtb
if [ "$RK_ARCH" == "arm" ]; then
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm/boot/dts/${RK_KERNEL_DTS}.dtb"
else
kernel_file_dtb="${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/${RK_KERNEL_DTS}.dtb"
fi
rm -f $kernel_file_dtb
cd kernel
make ARCH=$RK_ARCH dtbs -j$RK_JOBS
}
function build_check_power_domain(){
local dump_kernel_dtb_file
local tmp_phandle_file
local tmp_io_domain_file
local tmp_regulator_microvolt_file
local tmp_final_target
local tmp_none_item
local kernel_file_dtb_dts
if [ "$RK_ARCH" == "arm" ]; then
kernel_file_dtb_dts="${TOP_DIR}/kernel/arch/arm/boot/dts/$RK_KERNEL_DTS"
else
kernel_file_dtb_dts="${TOP_DIR}/kernel/arch/arm64/boot/dts/rockchip/$RK_KERNEL_DTS"
fi
dump_kernel_dtb_file=${kernel_file_dtb_dts}.dump.dts
tmp_phandle_file=`mktemp`
tmp_io_domain_file=`mktemp`
tmp_regulator_microvolt_file=`mktemp`
tmp_final_target=`mktemp`
dtc -I dtb -O dts -o ${dump_kernel_dtb_file} ${kernel_file_dtb_dts}.dtb 2>/dev/null
grep -Pzo "io-domains\s*{(\n|\w|-|;|=|<|>|\"|_|\s|,)*};" $dump_kernel_dtb_file | grep -a supply > $tmp_io_domain_file
awk '{print "phandle = " $3}' $tmp_io_domain_file > $tmp_phandle_file
while IFS= read -r item_phandle && IFS= read -u 3 -r item_domain
do
echo "${item_domain% *}" >> $tmp_regulator_microvolt_file
tmp_none_item=${item_domain% *}
cmds="grep -Pzo \"{(\\n|\w|-|;|=|<|>|\\\"|_|\s)*"$item_phandle\"
eval "$cmds $dump_kernel_dtb_file | strings | grep "regulator-m..-microvolt" >> $tmp_regulator_microvolt_file" || \
eval "sed -i \"/${tmp_none_item}/d\" $tmp_regulator_microvolt_file" && continue
echo >> $tmp_regulator_microvolt_file
done < $tmp_phandle_file 3<$tmp_io_domain_file
while read -r regulator_val
do
if echo ${regulator_val} | grep supply &>/dev/null; then
echo -e "\n\n\e[1;33m${regulator_val%*=}\e[0m" >> $tmp_final_target
else
tmp_none_item=${regulator_val##*<}
tmp_none_item=${tmp_none_item%%>*}
echo -e "${regulator_val%%<*} \e[1;31m$(( $tmp_none_item / 1000 ))mV\e[0m" >> $tmp_final_target
fi
done < $tmp_regulator_microvolt_file
echo -e "\e[41;1;30m PLEASE CHECK BOARD GPIO POWER DOMAIN CONFIGURATION !!!!!\e[0m"
echo -e "\e[41;1;30m <<< ESPECIALLY Wi-Fi/Flash/Ethernet IO power domain >>> !!!!!\e[0m"
echo -e "\e[41;1;30m Check Node [pmu_io_domains] in the file: ${kernel_file_dtb_dts}.dts \e[0m"
echo
echo -e "\e[41;1;30m 请再次确认板级的电源域配置!!!!!!\e[0m"
echo -e "\e[41;1;30m <<< 特别是Wi-Fi,FLASH,以太网这几路IO电源的配置 >>> !!!!!\e[0m"
echo -e "\e[41;1;30m 检查内核文件 ${kernel_file_dtb_dts}.dts 的节点 [pmu_io_domains] \e[0m"
cat $tmp_final_target
rm -f $tmp_phandle_file
rm -f $tmp_regulator_microvolt_file
rm -f $tmp_io_domain_file
rm -f $tmp_final_target
rm -f $dump_kernel_dtb_file
}
function build_check(){
local build_depend_cfg="build-depend-tools.txt"
common_product_build_tools="$TOP_DIR/device/rockchip/common/$build_depend_cfg"
target_product_build_tools="$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$build_depend_cfg"
cat $common_product_build_tools $target_product_build_tools 2>/dev/null | while read chk_item
do
chk_item=${chk_item###*}
echo $chk_item
if [ -z "$chk_item" ]; then
continue
fi
dst=${chk_item%%,*}
src=${chk_item##*,}
echo "**************************************"
if eval $dst &>/dev/null;then
echo "Check [OK]: $dst"
else
echo "Please install ${dst%% *} first"
echo " sudo apt-get install $src"
fi
done
}
function build_pkg() {
check_config RK_CFG_BUILDROOT || check_config RK_CFG_RAMBOOT || check_config RK_CFG_RECOVERY || check_config RK_CFG_PCBA || return 0
local target_pkg=$1
target_pkg=${target_pkg%*/}
if [ ! -d $target_pkg ];then
echo "build pkg: error: not found package $target_pkg"
return 1
fi
if ! eval [ $rk_package_mk_arrry ];then
rk_package_mk_arrry=( $(find buildroot/package/rockchip/ -name "*.mk" | sort) )
fi
local pkg_mk pkg_config_in pkg_br pkg_final_target pkg_final_target_upper pkg_cfg
for it in ${rk_package_mk_arrry[@]}
do
pkg_final_target=$(basename $it)
pkg_final_target=${pkg_final_target%%.mk*}
pkg_final_target_upper=${pkg_final_target^^}
pkg_final_target_upper=${pkg_final_target_upper//-/_}
if grep "${pkg_final_target_upper}_SITE.*$target_pkg$" $it &>/dev/null; then
pkg_mk=$it
pkg_config_in=$(dirname $pkg_mk)/Config.in
pkg_br=BR2_PACKAGE_$pkg_final_target_upper
for cfg in RK_CFG_BUILDROOT RK_CFG_RAMBOOT RK_CFG_RECOVERY RK_CFG_PCBA
do
if eval [ \$$cfg ] ;then
pkg_cfg=$( eval "echo \$$cfg" )
if grep -wq ${pkg_br}=y buildroot/output/$pkg_cfg/.config; then
echo "Found $pkg_br in buildroot/output/$pkg_cfg/.config "
make ${pkg_final_target}-dirclean O=buildroot/output/$pkg_cfg
make ${pkg_final_target}-rebuild O=buildroot/output/$pkg_cfg
else
echo "[SKIP BUILD $target_pkg] NOT Found ${pkg_br}=y in buildroot/output/$pkg_cfg/.config"
fi
fi
done
fi
done
finish_build
}
function build_uboot(){
check_config RK_UBOOT_DEFCONFIG || return 0
prebuild_uboot
echo "============Start building uboot============"
echo "TARGET_UBOOT_CONFIG=$RK_UBOOT_DEFCONFIG"
echo "========================================="
cd u-boot
rm -f *_loader_*.bin
if [ "$RK_LOADER_UPDATE_SPL" = "true" ]; then
rm -f *spl.bin
fi
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then
rm -f $TOP_DIR/u-boot/boot.img
fi
if [ -n "$RK_UBOOT_DEFCONFIG_FRAGMENT" ]; then
if [ -f "configs/${RK_UBOOT_DEFCONFIG}_defconfig" ]; then
make ${RK_UBOOT_DEFCONFIG}_defconfig $RK_UBOOT_DEFCONFIG_FRAGMENT
else
make ${RK_UBOOT_DEFCONFIG}.config $RK_UBOOT_DEFCONFIG_FRAGMENT
fi
./make.sh $UBOOT_COMPILE_COMMANDS
else
./make.sh $RK_UBOOT_DEFCONFIG \
$UBOOT_COMPILE_COMMANDS
fi
if [ "$RK_LOADER_UPDATE_TPL" = "true" ]; then
./make.sh --tpl
fi
if [ "$RK_IDBLOCK_UPDATE_SPL" = "true" ]; then
./make.sh --idblock --spl
fi
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then
ln -rsf $TOP_DIR/u-boot/boot.img $TOP_DIR/rockdev/
fi
finish_build
}
# TODO: build_spl can be replaced by build_uboot with define RK_LOADER_UPDATE_SPL
function build_spl(){
check_config RK_SPL_DEFCONFIG || return 0
echo "============Start building spl============"
echo "TARGET_SPL_CONFIG=$RK_SPL_DEFCONFIG"
echo "========================================="
if [ -f u-boot/*spl.bin ]; then
rm u-boot/*spl.bin
fi
cd u-boot && ./make.sh $RK_SPL_DEFCONFIG && ./make.sh spl-s && cd -
if [ $? -eq 0 ]; then
echo "====Build spl ok!===="
else
echo "====Build spl failed!===="
exit 1
fi
finish_build
}
function build_loader(){
check_config RK_LOADER_BUILD_TARGET || return 0
echo "============Start building loader============"
echo "RK_LOADER_BUILD_TARGET=$RK_LOADER_BUILD_TARGET"
echo "=========================================="
cd loader && ./build.sh $RK_LOADER_BUILD_TARGET && cd -
if [ $? -eq 0 ]; then
echo "====Build loader ok!===="
else
echo "====Build loader failed!===="
exit 1
fi
finish_build
}
function build_kernel(){
check_config RK_KERNEL_DTS RK_KERNEL_DEFCONFIG || return 0
echo "============Start building kernel============"
echo "TARGET_ARCH =$RK_ARCH"
echo "TARGET_KERNEL_CONFIG =$RK_KERNEL_DEFCONFIG"
echo "TARGET_KERNEL_DTS =$RK_KERNEL_DTS"
echo "TARGET_KERNEL_CONFIG_FRAGMENT =$RK_KERNEL_DEFCONFIG_FRAGMENT"
echo "=========================================="
pwd
cd kernel
make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT
make ARCH=$RK_ARCH $RK_KERNEL_DTS.img -j$RK_JOBS
if [ -f "$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_KERNEL_FIT_ITS" ]; then
$COMMON_DIR/mk-fitimage.sh $TOP_DIR/kernel/$RK_BOOT_IMG \
$TOP_DIR/device/rockchip/$RK_TARGET_PRODUCT/$RK_KERNEL_FIT_ITS \
$TOP_DIR/kernel/ramdisk.img
fi
finish_build
}
function build_modules(){
check_config RK_KERNEL_DEFCONFIG || return 0
echo "============Start building kernel modules============"
echo "TARGET_ARCH =$RK_ARCH"
echo "TARGET_KERNEL_CONFIG =$RK_KERNEL_DEFCONFIG"
echo "TARGET_KERNEL_CONFIG_FRAGMENT =$RK_KERNEL_DEFCONFIG_FRAGMENT"
echo "=================================================="
COMMON_KMODS_DIR="${TOP_DIR}/kmods/linux"
OPENWRT_KMODS_DIR="${TOP_DIR}/kmods/openwrt"
if [ -d "${COMMON_KMODS_DIR}" ]; then
rm -rf "${COMMON_KMODS_DIR}"
fi
if [ -d "${OPENWRT_KMODS_DIR}" ]; then
rm -rf "${OPENWRT_KMODS_DIR}"
fi
mkdir -p "${COMMON_KMODS_DIR}"
mkdir -p "${OPENWRT_KMODS_DIR}"
cd $TOP_DIR/kernel && make ARCH=$RK_ARCH $RK_KERNEL_DEFCONFIG $RK_KERNEL_DEFCONFIG_FRAGMENT && \
make ARCH=$RK_ARCH modules -j$RK_JOBS && \
make ARCH=$RK_ARCH modules_install INSTALL_MOD_PATH="${COMMON_KMODS_DIR}" INSTALL_MOD_STRIP=1 && cd -
RELEASE_NAME=$(basename "${COMMON_KMODS_DIR}/lib/modules/"*)
OPENWRT_FULL_KMODS_DIR="${OPENWRT_KMODS_DIR}/lib/modules/${RELEASE_NAME}"
mkdir -p "${OPENWRT_FULL_KMODS_DIR}"
find "${COMMON_KMODS_DIR}/lib/modules/" -name "*.ko" -exec cp {} "${OPENWRT_FULL_KMODS_DIR}" \;
if [ -d "$TOP_DIR/modules-backports" ]; then
cd "$TOP_DIR/modules-backports" && \
make ARCH=$RK_ARCH KLIB_BUILD="$TOP_DIR/kernel" KLIB="$COMMON_KMODS_DIR" defconfig-rk3568 && \
make ARCH=$RK_ARCH KLIB_BUILD="$TOP_DIR/kernel" KLIB="$COMMON_KMODS_DIR" -j$RK_JOBS && \
make ARCH=$RK_ARCH KLIB_BUILD="$TOP_DIR/kernel" KLIB="$COMMON_KMODS_DIR" install && cd -
find "${COMMON_KMODS_DIR}/lib/modules/${RELEASE_NAME}/updates" -name "*.ko" -exec cp {} "${OPENWRT_FULL_KMODS_DIR}" \;
fi
tar -czf "${TOP_DIR}/kmods/kmods.tar.gz" -C "${COMMON_KMODS_DIR}" . --owner=0 --group=0
tar -czf "${TOP_DIR}/kmods/kmods-openwrt.tar.gz" -C "${OPENWRT_KMODS_DIR}" . --owner=0 --group=0
if [ $? -eq 0 ]; then
echo "====Build kernel ok!===="
else
echo "====Build kernel failed!===="
exit 1
fi
}
function build_toolchain(){
check_config RK_CFG_TOOLCHAIN || return 0
echo "==========Start building toolchain =========="
echo "TARGET_TOOLCHAIN_CONFIG=$RK_CFG_TOOLCHAIN"
echo "========================================="
[[ $RK_CFG_TOOLCHAIN ]] \
&& /usr/bin/time -f "you take %E to build toolchain" $COMMON_DIR/mk-toolchain.sh $BOARD_CONFIG \
|| echo "No toolchain step, skip!"
if [ $? -eq 0 ]; then
echo "====Build toolchain ok!===="
else
echo "====Build toolchain failed!===="
exit 1
fi
finish_build
}
function build_buildroot(){
check_config RK_CFG_BUILDROOT || return 0
echo "==========Start building buildroot=========="
echo "TARGET_BUILDROOT_CONFIG=$RK_CFG_BUILDROOT"
echo "========================================="
if [ -z ${RK_CFG_BUILDROOT} ];then
echo "====No Found config on `realpath $BOARD_CONFIG`. Just exit ..."
return
fi
/usr/bin/time -f "you take %E to build builroot" $COMMON_DIR/mk-buildroot.sh $BOARD_CONFIG
if [ $? -eq 0 ]; then
echo "====Build buildroot ok!===="
else
echo "====Build buildroot failed!===="
exit 1
fi
}
function build_ramboot(){
check_config RK_CFG_RAMBOOT || return 0
echo "=========Start building ramboot========="
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT"
echo "====================================="
if [ -z ${RK_CFG_RAMBOOT} ];then
echo "====No Found config on `realpath $BOARD_CONFIG`. Just exit ..."
return
fi
/usr/bin/time -f "you take %E to build ramboot" $COMMON_DIR/mk-ramdisk.sh ramboot.img $RK_CFG_RAMBOOT
if [ $? -eq 0 ]; then
rm $TOP_DIR/rockdev/boot.img
ln -rfs $TOP_DIR/buildroot/output/$RK_CFG_RAMBOOT/images/ramboot.img $TOP_DIR/rockdev/boot.img
echo "====Build ramboot ok!===="
else
echo "====Build ramboot failed!===="
exit 1
fi
finish_build
}
function build_multi-npu_boot(){
check_config RK_MULTINPU_BOOT || return 0
echo "=========Start building multi-npu boot========="
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT"
echo "====================================="
/usr/bin/time -f "you take %E to build multi-npu boot" $COMMON_DIR/mk-multi-npu_boot.sh
if [ $? -eq 0 ]; then
echo "====Build multi-npu boot ok!===="
else
echo "====Build multi-npu boot failed!===="
exit 1
fi
}
function build_yocto(){
check_config RK_YOCTO_MACHINE || return 0
echo "=========Start build ramboot========="
echo "TARGET_MACHINE=$RK_YOCTO_MACHINE"
echo "====================================="
export LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8
cd yocto
ln -sf $RK_YOCTO_MACHINE.conf build/conf/local.conf
source oe-init-build-env
cd ..
bitbake core-image-minimal -r conf/include/rksdk.conf
if [ $? -eq 0 ]; then
echo "====Build yocto ok!===="
else
echo "====Build yocto failed!===="
exit 1
fi
}
function build_debian(){
ARCH=${RK_DEBIAN_ARCH:-${RK_ARCH}}
case $ARCH in
arm|armhf) ARCH=armhf ;;
*) ARCH=arm64 ;;
esac
echo "=========Start building debian for $ARCH========="
cd debian
if [ ! -e linaro-buster-$ARCH.tar.gz ]; then
RELEASE=buster TARGET=desktop ARCH=$ARCH ./mk-base-debian.sh
ln -rsf linaro-buster-alip-*.tar.gz linaro-buster-$ARCH.tar.gz
fi
VERSION=debug ARCH=$ARCH ./mk-rootfs-buster.sh
./mk-image.sh
cd ..
if [ $? -eq 0 ]; then
echo "====Build Debian10 ok!===="
else
echo "====Build Debian10 failed!===="
exit 1
fi
}
function build_distro(){
check_config RK_DISTRO_DEFCONFIG || return 0
echo "===========Start building distro==========="
echo "TARGET_ARCH=$RK_ARCH"
echo "RK_DISTRO_DEFCONFIG=$RK_DISTRO_DEFCONFIG"
echo "========================================"
cd distro && make $RK_DISTRO_DEFCONFIG && /usr/bin/time -f "you take %E to build debian" $TOP_DIR/distro/make.sh && cd -
if [ $? -eq 0 ]; then
echo "====Build debian ok!===="
else
echo "====Build debian failed!===="
exit 1
fi
}
function build_rootfs(){
check_config RK_ROOTFS_IMG || return 0
RK_ROOTFS_DIR=.rootfs
ROOTFS_IMG=${RK_ROOTFS_IMG##*/}
if [ "x${RK_ROOTFS_SYSTEM}" != "xubuntu" ]; then
rm -rf $RK_ROOTFS_IMG $RK_ROOTFS_DIR
mkdir -p ${RK_ROOTFS_IMG%/*} $RK_ROOTFS_DIR
fi
case "$1" in
yocto)
build_yocto
ROOTFS_IMG=yocto/build/tmp/deploy/images/$RK_YOCTO_MACHINE/rootfs.img
;;
debian)
build_debian
ROOTFS_IMG=debian/linaro-rootfs.img
;;
distro)
build_distro
ROOTFS_IMG=distro/output/images/rootfs.$RK_ROOTFS_TYPE
;;
openwrt)
build_openwrt
ROOTFS_IMG="openwrt/build_dir/target-aarch64_cortex-a53_musl/linux-armvirt_64/root.squashfs"
;;
*)
if [ -n $RK_CFG_BUILDROOT ];then
build_buildroot
ROOTFS_IMG=buildroot/output/$RK_CFG_BUILDROOT/images/rootfs.$RK_ROOTFS_TYPE
fi
;;
esac
[ -z "$ROOTFS_IMG" ] && return
if [ ! -f "$ROOTFS_IMG" ]; then
echo "$ROOTFS_IMG not generated?"
else
mkdir -p ${RK_ROOTFS_IMG%/*}
rm -f $RK_ROOTFS_IMG
ln -rsf $TOP_DIR/$ROOTFS_IMG $RK_ROOTFS_IMG
fi
finish_build
}
function build_recovery(){
if [ "$RK_UPDATE_SDCARD_ENABLE_FOR_AB" = "true" ] ;then
RK_CFG_RECOVERY=$RK_UPDATE_SDCARD_CFG_RECOVERY
fi
echo "==========Start building recovery=========="
echo "TARGET_RECOVERY_CONFIG=$RK_CFG_RECOVERY"
echo "========================================"
/usr/bin/time -f "you take %E to build recovery" $COMMON_DIR/mk-ramdisk.sh recovery.img $RK_CFG_RECOVERY
if [ $? -eq 0 ]; then
echo "====Build recovery ok!===="
else
echo "====Build recovery failed!===="
exit 1
fi
finish_build
}
function build_pcba(){
check_config RK_CFG_PCBA || return 0
echo "==========Start building pcba=========="
echo "TARGET_PCBA_CONFIG=$RK_CFG_PCBA"
echo "===================================="
if [ -z ${RK_CFG_PCBA} ];then
echo "====No Found config on `realpath $BOARD_CONFIG`. Just exit ..."
return
fi
/usr/bin/time -f "you take %E to build pcba" $COMMON_DIR/mk-ramdisk.sh pcba.img $RK_CFG_PCBA
if [ $? -eq 0 ]; then
echo "====Build pcba ok!===="
else
echo "====Build pcba failed!===="
exit 1
fi
}
function build_all(){
echo "============================================"
echo "TARGET_ARCH=$RK_ARCH"
echo "TARGET_PLATFORM=$RK_TARGET_PRODUCT"
echo "TARGET_UBOOT_CONFIG=$RK_UBOOT_DEFCONFIG"
echo "TARGET_SPL_CONFIG=$RK_SPL_DEFCONFIG"
echo "TARGET_KERNEL_CONFIG=$RK_KERNEL_DEFCONFIG"
echo "TARGET_KERNEL_DTS=$RK_KERNEL_DTS"
echo "TARGET_TOOLCHAIN_CONFIG=$RK_CFG_TOOLCHAIN"
echo "TARGET_BUILDROOT_CONFIG=$RK_CFG_BUILDROOT"
echo "TARGET_RECOVERY_CONFIG=$RK_CFG_RECOVERY"
echo "TARGET_PCBA_CONFIG=$RK_CFG_PCBA"
echo "TARGET_RAMBOOT_CONFIG=$RK_CFG_RAMBOOT"
echo "============================================"
# NOTE: On secure boot-up world, if the images build with fit(flattened image tree)
# we will build kernel and ramboot firstly,
# and then copy images into u-boot to sign the images.
if [ "$RK_RAMDISK_SECURITY_BOOTUP" != "true" ];then
#note: if build spl, it will delete loader.bin in uboot directory,
# so can not build uboot and spl at the same time.
if [ -z $RK_SPL_DEFCONFIG ]; then
build_uboot
else
build_spl
fi
fi
build_loader
build_kernel
build_modules
build_toolchain && \
build_rootfs ${RK_ROOTFS_SYSTEM:-buildroot}
build_recovery
build_ramboot
if [ "$RK_RAMDISK_SECURITY_BOOTUP" = "true" ];then
#note: if build spl, it will delete loader.bin in uboot directory,
# so can not build uboot and spl at the same time.
if [ -z $RK_SPL_DEFCONFIG ]; then
build_uboot
else
build_spl
fi
fi
finish_build
}
function build_cleanall(){
echo "clean uboot, kernel, rootfs, recovery"
cd $TOP_DIR/u-boot/ && make distclean && cd -
cd $TOP_DIR/kernel && make distclean && cd -
rm -rf $TOP_DIR/buildroot/output
rm -rf $TOP_DIR/yocto/build/tmp
rm -rf $TOP_DIR/distro/output
rm -rf $TOP_DIR/debian/binary
}
function build_firmware(){
./mkfirmware.sh $BOARD_CONFIG
if [ $? -eq 0 ]; then
echo "Make image ok!"
else
echo "Make image failed!"
exit 1
fi
}
function gen_file_name() {
day=$(date +%Y%m%d)
time=$(date +%H%M)
typeset -u board
board=$(basename $(readlink ${BOARD_CONFIG}))
board=${board%%.MK}
rootfs=$(ls -l $TOP_DIR/rockdev/ | grep rootfs.img | awk -F '/' '{print $(NF)}'|awk -F '_' '{print $2}')
board=${board}${rootfs}-GPT
if [ -n "$1" ];then
board=$board-$1
fi
echo -e "File name is \e[36m $board \e[0m"
read -t 10 -e -p "Rename the file? [N|y]" ANS || :
ANS=${ANS:-n}
case $ANS in
Y|y|yes|YES|Yes) rename=1;;