forked from lindenis-org/lindenis-v853-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvsetup.sh
executable file
·2128 lines (1862 loc) · 62.6 KB
/
envsetup.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
function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
== before all ==
- lunch: lunch <product_name>-<build_variant>
== build project ==
- m: Make from the top of the tree.
- mm: Build package in the current directory, but not their dependencies.
- mma: Build package in the current directory, and their dependencies.
- mmb: Clean and build package in the current directory, but not their dependencies.
- p: Pack from the top of the tree.
- pd: Pack card0 from the top of the tree.
- mp: Make and pack from the top of the tree
- mpd: Make and pack card0 from the top of the tree
- mboot: Build boot0 and uboot, including uboot for nor.
- mboot0: Just build boot0.
- muboot: Build uboot, including uboot for nor.
- muboot_nor: Just build uboot for nor.
- mkernel: Build kernel.
- mlibc: Build c library.
== jump directory ==
- croot: Jump to the top of the tree.
- cboot: Jump to uboot.
- cboot0: Jump to boot0.
- cdts: Jump to device tree.
- cbin: Jump to uboot/boot0 bin directory.
- ckernel: Jump to kernel.
- cdevice: Jump to target.
- ccommon: Jump to platform common.
- cconfigs: Jump to configs of target.
- cout: Jump to out directory of target.
- ctarget: Jump to target of compile directory.
- crootfs: Jump to rootfs of compile directory.
- ctoolchain: Jump to toolchain directory.
- callwinnerpk: Jump to package allwinner directory.
- ctinatest: Jump to tinateset directory.
- godir: Go to the directory containing a file.
== grep file ==
- cgrep: Greps on all local C/C++ files.
Look at the source to view more functions. The complete list is:
EOF
T=$(gettop)
local A
A=""
for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
A="$A $i"
done
echo $A
}
function gettop
{
local TOPFILE=build/envsetup.sh
if [ -n "$TINA_TOP" -a -f "$TINA_TOP/$TOPFILE" ] ; then
# The following circumlocution ensures we remove symlinks from TOP.
(\cd $TINA_TOP; pwd)
else
if [ -f $TOPFILE ] ; then
# The following circumlocution (repeated below as well) ensures
# that we record the true directory name and not one that is
# faked up with symlink names.
(pwd)
else
local here="$(pwd)"
while [ "${here}" != "/" ]; do
if [ -f "${here}/${TOPFILE}" ]; then
(\cd ${here}; pwd)
break
fi
here="$(dirname ${here})"
done
fi
fi
}
function add_lunch_combo()
{
local c
for c in ${LUNCH_MENU_CHOICES[@]} ; do
if [ "$1" = "$c" ] ; then
return
fi
done
LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $1)
}
function print_lunch_menu()
{
local uname=$(uname)
echo
echo "You're building on" $uname
echo
echo "Lunch menu... pick a combo:"
local i=1
local choice
for choice in ${LUNCH_MENU_CHOICES[@]}
do
echo " $i. $choice"
i=$(($i+1))
done
echo
}
# check to see if the supplied product is one we can build
function check_platform()
{
local T=$(gettop)
[ -d "$T/target/allwinner" ] || return 1
local v
for v in ${PLATFORM_CHOICES}
do
[ "$v" = "$1" ] && return 0
done
return 1
}
function check_product()
{
T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
TARGET_PRODUCT=$1 \
TARGET_BUILD_VARIANT= \
TARGET_BUILD_TYPE= \
TARGET_BUILD_APPS= \
get_build_var TARGET_DEVICE > /dev/null
}
# check to see if the supplied variant is valid
function check_variant()
{
for v in ${VARIANT_CHOICES}
do
[ "$v" = "$1" ] && return 0
done
return 1
}
# check whether parameters of platform is missing.
function check_parameters()
{
chip=${TARGET_CHIP}
if [ "x$chip" = "x" ]; then
echo "platform($TARGET_PLATFORM) not support"
echo "Please check whether device is missing!"
return 1
fi
return 0
}
# Get the exact value of a build variable.
function get_build_var()
{
T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build \
command make --no-print-directory -f build/config.mk dumpvar-$1)
}
function get_chip
{
local T=$(gettop)
[ -z "$T" ] && return -1
[ -z "${TARGET_PLATFORM}" ] && return -1
[ -z "${TARGET_KERNEL_VERSION}" ] && return -1
local longan_kernel_config=$T/target/allwinner/${TARGET_BOARD}/config-${TARGET_KERNEL_VERSION}
local tina_kernel_config=$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_BOARD##*-}/linux/config-${TARGET_KERNEL_VERSION}
local tina_new_kernel_config=$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_BOARD##*-}/linux-${TARGET_KERNEL_VERSION}/config-${TARGET_KERNEL_VERSION}
[ -e "${longan_kernel_config}" ] && awk -F'[_=]' '/CONFIG_ARCH_SUN.*P.*=y/{print tolower($3)}' "${longan_kernel_config}" | head -n 1 && return
[ -e "${tina_new_kernel_config}" ] && awk -F'[_=]' '/CONFIG_ARCH_SUN.*W.*=y/{print tolower($3"p1")}' "${tina_new_kernel_config}" | head -n 1 && return
[ -e "${tina_kernel_config}" ] && awk -F'[_=]' '/CONFIG_ARCH_SUN.*P.*=y/{print tolower($3)}' "${tina_kernel_config}" | head -n 1 && return
return -1
}
function get_uboot
{
local T=$(gettop)
[ -z "$T" ] && return -1
[ -z "${TARGET_PRODUCT}" ] && return -1
local f="$T/target/allwinner/${TARGET_PRODUCT/_/-}/Makefile"
[ -f "$f" ] || return -1
awk -F":=" '/UBOOT_PATCHVER/{print $2}' $f
}
function get_kernel
{
local T=$(gettop)
[ -z "$T" ] && return -1
[ -z "${TARGET_PRODUCT}" ] && return -1
local f="$T/target/allwinner/${TARGET_PRODUCT/_/-}/Makefile"
[ -f "$f" ] || return -1
awk -F":=" '/KERNEL_PATCHVER/{print $2}' $f
}
function get_arch
{
local T=$(gettop)
[ -z "$T" ] && return -1
[ -z "${TARGET_PRODUCT}" ] && return -1
local f="$T/target/allwinner/${TARGET_PRODUCT/_/-}/Makefile"
[ -f "$f" ] || return -1
awk -F":=" '/ARCH/{print $2}' $f
}
function parse_boardconfig()
{
local special_config="$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}/BoardConfig.mk"
local default_config="$T/device/config/chips/${TARGET_PLATFORM}/configs/default/BoardConfig.mk"
local default_config_nor="$T/device/config/chips/${TARGET_PLATFORM}/configs/default/BoardConfig_nor.mk"
local config_list=""
local f="$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}/sys_config.fex"
local B="$( awk -F"=" '/^storage_type/{print $2}' $f | sed 's/^[ \t]*//g' )"
if [ x"$B" = x"3" ]; then
config_list=($default_config_nor $special_config)
else
config_list=($default_config $special_config)
fi
local fetch_list=""
local fpare_list=""
for f in ${config_list[@]}; do
if [ -f $f ]; then
fetch_list=(${fetch_list[@]} $f)
fpare_list="$fpare_list -f $f"
fi
done
local cfgkeylist=(
LICHEE_BUSSINESS
LICHEE_BRANDY_DEFCONF
LICHEE_BRANDY_SPL
LICHEE_BOARD
LICHEE_REDUNDANT_ENV_SIZE
)
local cfgkey=""
local cfgval=""
for cfgkey in ${cfgkeylist[@]}; do
#don't use current value in env
export $cfgkey=""
if [ -n "$fpare_list" ]; then
cfgval="$(echo '__unique:;@echo ${'"$cfgkey"'}' | command make -f - $fpare_list --no-print-directory __unique)"
else
cfgval=""
fi
export $cfgkey=$cfgval
done
}
function fix_after_lunch
{
local T="$(gettop)"
cd $T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}
[ -e linux-${TARGET_KERNEL_VERSION}/board.dts ] && {
rm -f board.dts
ln -s linux-${TARGET_KERNEL_VERSION}/board.dts board.dts
}
[ -L linux ] && rm -f linux
[ -e linux ] || {
ln -s linux-${TARGET_KERNEL_VERSION} linux
}
}
function lunch
{
# get last platfrom as default platform
local T="$(gettop)"
local last
if [ -f "$T/.config" ]; then
#last="$(awk -F[=_] '/CONFIG_TARGET_[a-z_0-9]*[^_]=y/{print $3 "_" $4; exit}' ${T}/.config)"
last="$(sed -n -r '/CONFIG_TARGET_[a-zA-Z_0-9]*[^_]=y/{s/CONFIG_TARGET_([a-zA-Z_0-9]*[^_])=y/\1/;p;q}' ${T}/.config)"
local last_chip="$(sed -n -r '/CONFIG_PLATFORM_[a-zA-Z_0-9].*[^_]=y/{s/CONFIG_PLATFORM_([a-zA-Z_0-9].*[^_])=y/\1/;p;q}' ${T}/.config)"
if [[ ${last_chip} =~ "-" ]]; then
last=${last/_/-}
fi
fi
# select platform
local select
if [ "$1" ] ; then
select=$1
else
print_lunch_menu
echo -n "Which would you like?"
[ -n "${last}" ] && echo -n " [Default ${last}]"
echo -n ": "
read select
fi
if [ -z "${select}" ]; then
select="${last}-tina"
elif (echo -n $select | grep -q -e "^[0-9][0-9]*$"); then
[ $select -le ${#LUNCH_MENU_CHOICES[@]} ] \
&& select=${LUNCH_MENU_CHOICES[$(($select-1))]}
elif (echo -n $select | grep -q -e "^[^\-][^\-]*-[^\-][^\-]"); then
select="$select"
else
echo
echo "Invalid lunch combo: $select" >&2
return 1
fi
# check platform
local platform=$(echo -n $select | sed -e "s/_.*$//")
check_platform ${platform}
if [ $? -ne 0 ]; then
echo
echo "** Don't have a platform spec for: '$platform'" >&2
echo "** Must be one of ${PLATFORM_CHOICES}" >&2
echo "** Do you have the right repo manifest?" >&2
platform=
fi
# check product
local product=$(echo -n $select | sed -e "s/-$VARIANT_CHOICES//")
check_product $product
if [ $? -ne 0 ]
then
echo
echo "** Don't have a product spec for: '$product'" >&2
echo "** Do you have the right repo manifest?" >&2
product=
fi
local variant
echo -n $select | grep "\-$VARIANT_CHOICES" > /dev/null
if [ $? = 0 ]; then
variant=$VARIANT_CHOICES
fi
check_variant $variant
if [ $? -ne 0 ]
then
echo
echo "** Invalid variant: '$variant'" >&2
echo "** Must be one of ${VARIANT_CHOICES}" >&2
variant=
fi
[ -z "$product" -o -z "$variant" -o -z "$platform" ] && return 1
export TARGET_PRODUCT=$product
export TARGET_PLATFORM=$platform
export TARGET_BOARD=$(get_build_var TARGET_DEVICE)
export TARGET_PLAN=${TARGET_BOARD#$TARGET_PLATFORM-}
export TARGET_BUILD_VARIANT=$variant
export TARGET_BUILD_TYPE=release
export TARGET_KERNEL_VERSION=$(get_kernel)
export TARGET_UBOOT=u-boot-$(get_uboot)
export TARGET_CHIP=$(get_chip)
export TINA_TARGET_ARCH=$(get_arch)
export TINA_BUILD_TOP=$(gettop)
export LICHEE_ARISC_PATH=${TINA_BUILD_TOP}/lichee/arisc
export LICHEE_CHIP_CONFIG_DIR=${TINA_BUILD_TOP}/device/config/chips/${TARGET_PLATFORM}
export LICHEE_BOARD_CONFIG_DIR=${LICHEE_CHIP_CONFIG_DIR}/configs/${TARGET_PLAN}
#for plat_config.sh
parse_boardconfig
export LICHEE_PACK_OUT_DIR=${TINA_BUILD_TOP}/out/${TARGET_BOARD}/image
export LICHEE_PLAT_OUT=${TINA_BUILD_TOP}/out/${TARGET_BOARD}
echo "============================================"
echo "TINA_BUILD_TOP=${TINA_BUILD_TOP}"
echo "TINA_TARGET_ARCH=${TINA_TARGET_ARCH}"
echo "TARGET_PRODUCT=${TARGET_PRODUCT}"
echo "TARGET_PLATFORM=${TARGET_PLATFORM}"
echo "TARGET_BOARD=${TARGET_BOARD}"
echo "TARGET_PLAN=${TARGET_PLAN}"
echo "TARGET_BUILD_VARIANT=${TARGET_BUILD_VARIANT}"
echo "TARGET_BUILD_TYPE=${TARGET_BUILD_TYPE}"
echo "TARGET_KERNEL_VERSION=${TARGET_KERNEL_VERSION}"
echo "TARGET_UBOOT=${TARGET_UBOOT}"
echo "TARGET_CHIP=${TARGET_CHIP}"
echo "============================================"
export BUILD_ENV_SEQUENCE_NUMBER=10
# With this environment variable new GCC can apply colors to warnings/errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
rm -rf tmp
[ -e $T/target/allwinner/${TARGET_BOARD}/${TARGET_PRODUCT}-setup.sh ] \
&& source $T/target/allwinner/${TARGET_BOARD}/${TARGET_PRODUCT}-setup.sh
check_parameters
(fix_after_lunch)
# after lunch other platform, restart buildserver
clbuildserver
prepare_buildserver
}
# Tab completion for lunch.
function _lunch
{
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
return 0
}
# Tab completion for m.
function _m
{
local T=$(gettop)
[ -z "$T" ] && return
[ -f "$T/build/toplevel.mk" ] || return
local cur prev list
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
list="$(grep "[^\.].*config:" $T/build/toplevel.mk | awk -F: '{print $1}')"
COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
}
function envsetup
{
if [ "x$SHELL" != "x/bin/bash" ]; then
case `ps -o command -p $$` in
*bash*)
;;
*)
echo -n "WARNING: Only bash is supported, "
echo "use of other shell would lead to erroneous results"
;;
esac
fi
# check top of SDK
if [ ! -f "$(pwd)/build/envsetup.sh" ]; then
echo "ERROR: Please source envsetup.sh in the root of SDK"
return -1
else
export TINA_TOP="$(pwd)"
fi
# reset these variables.
# LUNCH_MENU_CHOICES will be built up again when the vendorsetup.sh are included
unset LUNCH_MENU_CHOICES
export LUNCH_MENU_CHOICES
export VARIANT_CHOICES=tina
export PLATFORM_CHOICES="$(ls $(gettop)/target/allwinner 2>/dev/null \
| grep common | sort | uniq | sed 's/-common//g')"
# Execute the contents of any vendorsetup.sh files we can find.
local vendors vendor awchips
if [ -d "$(pwd)/device/config/chips" ]; then
# only show platfroms with chip configuration.
awchips="$(ls $(pwd)/device/config/chips | awk '{print " -e "$1"-"}')"
if [ $? -eq 0 ]; then
verdors="$(find -L target -maxdepth 4 -name 'vendorsetup.sh' | grep ${awchips} 2>/dev/null | sort)"
else
verdors="$(find -L target -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort)"
fi
else
verdors="$(find -L target -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort)"
fi
for verdor in ${verdors}
do
source ${verdor}
done
prepare_sdk
echo "Setup env done! Please run lunch next."
# completion
complete -F _lunch lunch
complete -F _m m
}
function m
{
local T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
(\cd $T && make $@)
}
function mm
{
local T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
$T/scripts/mm.sh $T $*
}
function mma
{
local T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
$T/scripts/mma.sh $T $*
}
function mmb
{
mm -B
}
function p
{
local T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
(\cd $T && pack $@)
}
function pd
{
p -d
}
function mp
{
m $@ && p
}
function mpd
{
m $@ && pd
}
# Build brandy(uboot,boot0,fes) if you want.
function build_boot()
{
local T=$(gettop)
local chip=${TARGET_CHIP}
local cmd=$1
local o_option=$2
local platform
local bin_dir
local f="$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}/sys_config.fex"
local B="$( awk -F"=" '/^storage_type/{print $2}' $f | sed 's/^[ \t]*//g' )"
if [ x"$B" = x"3" ]; then
export LICHEE_FLASH="nor"
else
export LICHEE_FLASH="default"
fi
echo $TARGET_PRODUCT $TARGET_PLATFORM $TARGET_BOARD
if [ -z "$TARGET_BOARD" -o -z "$TARGET_PLATFORM" ]; then
echo "Please use lunch to select a target board before build boot."
return 1
fi
if [ "x$chip" = "x" ]; then
echo "platform($TARGET_PLATFORM) not support"
return 1
fi
platform=${chip}
bin_dir="device/config/chips/${TARGET_PLATFORM}/bin"
if [ "${TARGET_UBOOT}" = "u-boot-2018" ]; then
\cd $T/lichee/brandy-2.0/
[ x"$o_option" = x"uboot" -a -f "u-boot-2018/configs/${chip}_tina_defconfig" ] && {
platform=${chip}_tina
}
[ x"$o_option" = x"uboot" -a -f "u-boot-2018/configs/${TARGET_BOARD}_defconfig" ] && {
platform=${TARGET_BOARD}
bin_dir="device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_BOARD#*-}/bin"
mkdir -p $T/${bin_dir}
}
[ x"$o_option" = x"uboot" -a -f "$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}/BoardConfig.mk" ] && {
if [ x"${LICHEE_BRANDY_DEFCONF}" != "x" ]; then
platform=${LICHEE_BRANDY_DEFCONF%%_def*}
fi
}
if [ x"$o_option" == "xboot0" ]; then
if [ x"${LICHEE_BRANDY_SPL}" != x ]; then
o_option=${LICHEE_BRANDY_SPL}
else
o_option=spl
fi
if [ ! -f "spl-pub/Makefile" ]; then
o_option=spl
fi
if [ ! -f "spl/Makefile" ]; then
o_option=spl-pub
fi
fi
else
\cd $T/lichee/brandy/
fi
echo "build_boot platform:$platform o_option:$o_option"
if [ x"$o_option" != "x" ] && [ "${TARGET_UBOOT}" = "u-boot-2018" ]; then
TARGET_BIN_DIR=${bin_dir} ./build.sh -p $platform -o $o_option -b ${TARGET_PLATFORM}
elif [ x"$o_option" != "x" ]; then
TARGET_BIN_DIR=${bin_dir} ./build.sh -p $platform -o $o_option
else
TARGET_BIN_DIR=${bin_dir} ./build.sh -p $platform
fi
if [ $? -ne 0 ]; then
echo "$cmd stop for build error in brandy, Please check!"
\cd - 1>/dev/null
return 1
fi
\cd - 1>/dev/null
echo "$cmd success!"
return 0
}
function mkarisc
{
echo "=== Start build scp.bin ==="
local arisc_cfg;
if [ x"mr813" != x${TARGET_PLATFORM} -a x"r818" != x${TARGET_PLATFORM} ];
then echo "Platform ${TARGET_PLATFORM} Skip marisc." && return 0
fi
if [ -f ${LICHEE_BOARD_CONFIG_DIR}/../default/arisc.config ]
then
arisc_cfg=${LICHEE_BOARD_CONFIG_DIR}/../default/arisc.config
fi
if [ -f ${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh ]
then
${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh
fi
if [ -f ${LICHEE_BOARD_CONFIG_DIR}/arisc.config ]
then
arisc_cfg=${LICHEE_BOARD_CONFIG_DIR}/arisc.config
fi
if [ ! -e ${arisc_cfg} ]
then
return 1;
fi
if [ ! -d ${LICHEE_ARISC_PATH} ];
then
echo "arisc project lost, use repo sync to get it"
return 1;
fi
cp ${arisc_cfg} ${LICHEE_ARISC_PATH}/.config
command make -C ${LICHEE_ARISC_PATH}
[ $? -ne 0 ] && print_red "Error to build scp.bin" && return 1
[ ! -e ${LICHEE_CHIP_CONFIG_DIR}/bin ] && print_red "Error Not exist bin dir." && return 1
echo "cp ${LICHEE_ARISC_PATH}/ar100s/scp.bin to ${LICHEE_CHIP_CONFIG_DIR}/bin/scp.bin"
cp ${LICHEE_ARISC_PATH}/ar100s/scp.bin ${LICHEE_CHIP_CONFIG_DIR}/bin/scp.bin
[ $? -ne 0 ] && print_red 'Error to cp scp.bin' && return 1
echo "make arisc success!"
return 0
}
function muboot
{
(build_boot muboot uboot)
}
function mboot
{
(build_boot muboot uboot)
if [ $? -ne 0 ]; then
return 1
fi
(build_boot mboot0 boot0)
}
function mboot0
{
(build_boot mboot0 boot0)
}
function muboot_nor
{
(build_boot muboot_nor uboot_nor)
}
function mkernel
{
m target/allwinner/install $@
}
function mlibc() {
local T=$(gettop)
[ -z "$T" ] \
&& echo "Couldn't locate the top of the tree. Try setting TOP." \
&& return
$T/scripts/mlibc.sh $T $*
}
function make_img_md5(){
#$1: target image
md5sum $1 | awk '{print $1}' > $1.md5
}
function ota_save_files()
{
[ $# -lt 1 ] && echo "usage:ota_save_files file_dir" && return 1
local target_dir=$1
echo target_dir:"$target_dir"
[ ! -d "$target_dir" ] && echo target_dir:"$target_dir" not exit!! && return 1
local T=$(gettop)
local BIN_DIR=$T/out/${TARGET_BOARD}
local boot_img="$(readlink -f "$BIN_DIR"/image/boot.fex)"
local rootfs_img="$(readlink -f "$BIN_DIR"/image/rootfs.fex)"
local recovery_img="$(readlink -f "$BIN_DIR"/image/recovery.fex)"
#uboot and boot0
local boot_package_img="$(readlink -f "$BIN_DIR"/image/boot_package.fex)"
local boot0_nand_img="$(readlink -f "$BIN_DIR"/image/boot0_nand.fex)"
local boot0_sdcard_img="$(readlink -f "$BIN_DIR"/image/boot0_sdcard.fex)"
rm -f "$target_dir"/*.img "$target_dir"/*.md5 "$target_dir"/*.signature
[ -f "$boot_img" ] \
&& cp "$boot_img" "$target_dir"/boot.img \
&& make_img_md5 "$target_dir"/boot.img
[ -f "$rootfs_img" ] \
&& cp "$rootfs_img" "$target_dir"/rootfs.img \
&& make_img_md5 "$target_dir"/rootfs.img
[ -f "$recovery_img" ] \
&& cp "$recovery_img" "$target_dir"/recovery.img \
&& make_img_md5 "$target_dir"/recovery.img
[ -f "$boot_package_img" ] \
&& cp "$boot_package_img" "$target_dir"/boot_package.img \
&& make_img_md5 "$target_dir"/boot_package.img
[ -f "$boot0_nand_img" ] \
&& cp "$boot0_nand_img" "$target_dir"/boot0_nand.img \
&& make_img_md5 "$target_dir"/boot0_nand.img
[ -f "$boot0_sdcard_img" ] \
&& cp "$boot0_sdcard_img" "$target_dir"/boot0_sdcard.img \
&& make_img_md5 "$target_dir"/boot0_sdcard.img
ls -l "$target_dir"
}
function make_ota_image(){
local T=$(gettop)
local chip=sunxi
local need_usr=0
local make_ota_fail=0
[ x$CHIP = x"sun5i" ] && chip=sun5i
local BIN_DIR=$T/out/${TARGET_BOARD}
local OTA_DIR=$BIN_DIR/ota
mkdir -p $OTA_DIR
print_red "build ota package"
grep "CONFIG_SUNXI_SMALL_STORAGE_OTA=y" $T/target/allwinner/${TARGET_BOARD}/defconfig \
&& need_usr=1
#target image
target_list="$BIN_DIR/boot.img $BIN_DIR/rootfs.img $BIN_DIR/usr.img"
if [ $need_usr -eq 0 ];then
target_list="$BIN_DIR/boot.img $BIN_DIR/rootfs.img"
fi
[ -n "$1" ] && [ x"$1" = x"--force" ] && rm -rf $target_list
for i in $target_list; do
if [ ! -f "$i" ]; then
img=${i##*/}
print_red "$i is not exsit! rebuild the image."
make -j16
if [ $? -ne 0 ]
then
print_red "make $img file! make_ota_image fail!"
make_ota_fail=1
fi
break
fi
done
rm -rf $OTA_DIR/target_sys
mkdir -p $OTA_DIR/target_sys
dd if=$BIN_DIR/boot.img of=$OTA_DIR/target_sys/boot.img
make_img_md5 $OTA_DIR/target_sys/boot.img
dd if=$BIN_DIR/rootfs.img of=$OTA_DIR/target_sys/rootfs.img
make_img_md5 $OTA_DIR/target_sys/rootfs.img
local storage_type_nor=0
local f="$T/device/config/chips/${TARGET_PLATFORM}/configs/${TARGET_PLAN}/sys_config.fex"
local B="$( awk -F"=" '/^storage_type/{print $2}' $f | sed 's/^[ \t]*//g' )"
case $B in
*-1)
print_red "###storage type error###"
print_red "###cannot choose boot0, please config storage_type in sys_config ###"
;;
*0 | *5)
local boot0_img=boot0_nand.fex
;;
*1 | *2 | *4)
local boot0_img=boot0_sdcard.fex
;;
3)
local boot0_img=boot0_spinor.fex
storage_type_nor=1
;;
*)
print_red "###storage type error###"
print_red "###cannot choose boot0, please config storage_type in sys_config ###"
;;
esac
rm -rf $OTA_DIR/boot0_sys
[ -n "$boot0_img" ] && {
mkdir -p $OTA_DIR/boot0_sys
dd if=$BIN_DIR/image/$boot0_img of=$OTA_DIR/boot0_sys/boot0.img
make_img_md5 $OTA_DIR/boot0_sys/boot0.img
}
local U="$(get_uboot)"
if [[ "$U" =~ "2011" ]]; then
local uboot_img=u-boot.fex
else
if [ x"$storage_type_nor" = x"1" ]; then
local uboot_img=boot_package_nor.fex
else
local uboot_img=boot_package.fex
fi
fi
rm -rf $OTA_DIR/uboot_sys
mkdir -p $OTA_DIR/uboot_sys
dd if=$BIN_DIR/image/$uboot_img of=$OTA_DIR/uboot_sys/uboot.img
make_img_md5 $OTA_DIR/uboot_sys/uboot.img
if [ $need_usr -eq 1 ];then
rm -rf $OTA_DIR/usr_sys
mkdir -p $OTA_DIR/usr_sys
dd if=$BIN_DIR/usr.img of=$OTA_DIR/usr_sys/usr.img
make_img_md5 $OTA_DIR/usr_sys/usr.img
fi
grep -v -e CONFIG_TARGET_ROOTFS_INITRAMFS \
$T/target/allwinner/${TARGET_BOARD}/defconfig_ota > .config_ota
echo 'CONFIG_TARGET_ROOTFS_INITRAMFS=y' >> .config_ota
echo 'CONFIG_TARGET_AW_OTA_INITRAMFS=y' >> .config_ota
echo 'CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ=y' >> .config_ota
make V=s -j16 TARGET_CONFIG=.config_ota
if [ $? -ne 0 ]
then
print_red "make_ota_image fail!"
make_ota_fail=1
fi
rm -rf $OTA_DIR/ramdisk_sys
mkdir -p $OTA_DIR/ramdisk_sys
local recovery_img_source="boot_initramfs.img"
local recovery_img_dest="boot_initramfs.img"
if grep -q CONFIG_SUNXI_BOOT_IMAGE_NAME_SUFFIX_RECOVERY=y .config_ota; then
echo "have CONFIG_SUNXI_BOOT_IMAGE_NAME_SUFFIX_RECOVERY"
echo "use boot_initramfs_recovery.img"
recovery_img_source="boot_initramfs_recovery.img"
fi
dd if=$BIN_DIR/$recovery_img_source of=$OTA_DIR/ramdisk_sys/$recovery_img_dest
make_img_md5 $OTA_DIR/ramdisk_sys/$recovery_img_dest
###########################################################
rm -rf $OTA_DIR/package_sys
mkdir -p $OTA_DIR/package_sys
dd if=$OTA_DIR/ramdisk_sys/$recovery_img_dest of=$OTA_DIR/package_sys/recovery.img
make_img_md5 $OTA_DIR/package_sys/recovery.img
dd if=$OTA_DIR/target_sys/boot.img of=$OTA_DIR/package_sys/boot.img
make_img_md5 $OTA_DIR/package_sys/boot.img
dd if=$OTA_DIR/target_sys/rootfs.img of=$OTA_DIR/package_sys/rootfs.img
make_img_md5 $OTA_DIR/package_sys/rootfs.img
dd if=$OTA_DIR/boot0_sys/boot0.img of=$OTA_DIR/package_sys/boot0.img
make_img_md5 $OTA_DIR/package_sys/boot0.img
dd if=$OTA_DIR/uboot_sys/uboot.img of=$OTA_DIR/package_sys/uboot.img
make_img_md5 $OTA_DIR/package_sys/uboot.img
if [ -f $BIN_DIR/image/bootlogo.fex ]; then
dd if=$BIN_DIR/image/bootlogo.fex of=$OTA_DIR/package_sys/bootlogo.img
make_img_md5 $OTA_DIR/package_sys/bootlogo.img
fi
ota_tar="ota"$1".tar"
echo "#####${ota_tar}#####"
cd $OTA_DIR/package_sys/ && \
tar -rvf ${ota_tar} boot.img && \
tar -rvf ${ota_tar} boot.img.md5 && \
tar -rvf ${ota_tar} rootfs.img && \
tar -rvf ${ota_tar} rootfs.img.md5 && \
tar -rvf ${ota_tar} recovery.img && \
tar -rvf ${ota_tar} recovery.img.md5 && \
tar -rvf ${ota_tar} boot0.img && \
tar -rvf ${ota_tar} boot0.img.md5 && \
tar -rvf ${ota_tar} uboot.img && \
tar -rvf ${ota_tar} uboot.img.md5 && \
if [ -f bootlogo.img ]; then
tar -rvf ${ota_tar} bootlogo.img
tar -rvf ${ota_tar} bootlogo.img.md5
fi
\cd $T
##############################################################
if [ $need_usr -eq 1 ];then
\cd $OTA_DIR && \
tar -zcvf target_sys.tar.gz target_sys && \
tar -zcvf ramdisk_sys.tar.gz ramdisk_sys && \
tar -zcvf boot0_sys.tar.gz boot0_sys && \
tar -zcvf uboot_sys.tar.gz uboot_sys && \
tar -zcvf usr_sys.tar.gz usr_sys && \
\cd $T
else
\cd $OTA_DIR && \
tar -zcvf target_sys.tar.gz target_sys && \
tar -zcvf ramdisk_sys.tar.gz ramdisk_sys && \
tar -zcvf boot0_sys.tar.gz boot0_sys && \
tar -zcvf uboot_sys.tar.gz uboot_sys && \
\cd $T
fi
if [ $make_ota_fail -ne 0 ];then
print_red "build ota package fail!"
else
print_green "build ota package finish!"
fi
}
function make_ota_package_for_dual_app
{
local T=$(gettop)
local BIN_DIR=$T/out/${TARGET_BOARD}
local OTA_DIR=$BIN_DIR/ota_dual_app
local make_fail=0
local ota_package=app_ota.tar
mkdir -p "$OTA_DIR"
\cd "$OTA_DIR"
rm -f $ota_package $ota_package.md5
target_list="$BIN_DIR/image/app.fex"
for i in $target_list; do
img=${i##*/}
if [ ! -f "$i" ]; then
print_red "$i not exsit!"
make_fail=1
break
fi
dd if="$i" of="$img" bs=512 conv=sync
make_img_md5 "$img"
tar -rvf "$ota_package" "$img"
tar -rvf "$ota_package" "$img.md5"
done
if [ x$make_fail = x"1" ]; then
print_red "make fail"
rm -f $ota_package
else
make_img_md5 "$ota_package"
print_red "$OTA_DIR/$ota_package"
fi
\cd - > /dev/null
}
function swupdate_init_key() {
T=$(gettop)
local password="swupdate"
local SWUPDATE_CONFIG_DIR="$T/target/allwinner/${TARGET_BOARD}/swupdate"
local BUSYBOX_BASEFILE_DIR="$T/target/allwinner/${TARGET_BOARD}/busybox-init-base-files"
local PROCD_BASEFILE_DIR="$T/target/allwinner/${TARGET_BOARD}/base-files"
local KEY_DIR="etc"
mkdir -p $SWUPDATE_CONFIG_DIR
\cd $SWUPDATE_CONFIG_DIR
echo "-------------------- init password --------------------"
if [ "$1" ] ; then
password="$1"
fi
echo "$password" > swupdate_priv.password
echo "-------------------- init priv key --------------------"
openssl genrsa -aes256 -passout file:swupdate_priv.password -out swupdate_priv.pem
echo "-------------------- init public key --------------------"
openssl rsa -in swupdate_priv.pem -passin file:swupdate_priv.password -out swupdate_public.pem -outform PEM -pubout