-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathpack_img.sh
executable file
·2154 lines (1899 loc) · 74.1 KB
/
pack_img.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
#
# pack/pack
# (c) Copyright 2013 - 2016 Allwinner
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# James Deng <[email protected]>
# Trace Wong <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
############################ Notice #####################################
# a. Some config files priority is as follows:
# - xxx_${platform}.{cfg|fex} > xxx.{cfg|fex}
# - ${chip}/${board}/*.{cfg|fex} > ${chip}/default/*.{cfg|fex}
# - ${chip}/default/*.cfg > common/imagecfg/*.cfg
# - ${chip}/default/*.fex > common/partition/*.fex
# e.g. sun8iw7p1/configs/perf/image_linux.cfg > sun8iw7p1/configs/default/image_linux.cfg
# > common/imagecfg/image_linux.cfg > sun8iw7p1/configs/perf/image.cfg
# > sun8iw7p1/configs/default/image.cfg > common/imagecfg/image.cfg
#
# b. Support Nor storages rule:
# - Need to create sys_partition_nor.fex or sys_partition_nor_${platform}.fex
# - Add "{filename = "full_img.fex", maintype = "12345678", \
# subtype = "FULLIMG_00000000",}" to image[_${platform}].cfg
#
# c. Switch uart port
# - Need to add your chip configs into ${LONGAN_COMMON_DIR}/debug/card_debug_pin
# - Call pack with 'debug' parameters
enable_pause=0
function get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
function pause()
{
if [ "x$1" != "x" ] ;then
echo "$1"
fi
if [ $enable_pause -eq 1 ] ; then
echo "Press any key to continue!"
char=`get_char`
fi
}
function pack_error()
{
echo -e "\033[47;31mERROR: $*\033[0m"
}
function pack_warn()
{
echo -e "\033[47;34mWARN: $*\033[0m"
}
function pack_info()
{
echo -e "\033[47;30mINFO: $*\033[0m"
}
source scripts/shflags
# define option, format:
# 'long option' 'default value' 'help message' 'short option'
DEFINE_string 'chip' '' 'chip to build, e.g. sun7i' 'c'
DEFINE_string 'platform' '' 'platform to build, e.g. linux, android, camdroid' 'p'
DEFINE_string 'board' '' 'board to build, e.g. evb' 'b'
DEFINE_string 'kernel' '' 'kernel to build, e.g. linux-3.4, linux-3.10' 'k'
DEFINE_string 'debug_mode' 'uart0' 'config debug mode, e.g. uart0, card0' 'd'
DEFINE_string 'signture' 'none' 'pack boot signture to do secure boot' 's'
DEFINE_string 'secure' 'none' 'pack secure boot with -v arg' 'v'
DEFINE_string 'mode' 'normal' 'pack dump firmware' 'm'
DEFINE_string 'function' 'android' 'pack private firmware' 'f'
DEFINE_string 'topdir' 'none' 'sdk top dir' 't'
#create img for emmc programmer
DEFINE_string 'programmer' '' 'creat programmer img or not' 'w'
#create img for nand programmer
DEFINE_string 'tar_image' '' 'creat downloadfile img .tar.gz or not' 'i'
# parse the command-line
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
PACK_CHIP=${FLAGS_chip}
PACK_PLATFORM=${FLAGS_platform}
PACK_BOARD=${FLAGS_board}
PACK_KERN=${FLAGS_kernel}
PACK_DEBUG=${FLAGS_debug_mode}
PACK_SIG=${FLAGS_signture}
PACK_SECURE=${FLAGS_secure}
PACK_MODE=${FLAGS_mode}
PACK_FUNC=${FLAGS_function}
PACK_PROGRAMMER=${FLAGS_programmer}
PACK_TAR_IMAGE=${FLAGS_tar_image}
PACK_TOPDIR=${FLAGS_topdir}
function show_args
{
echo --==========--
echo "PACK_CHIP " ${FLAGS_chip}
echo "PACK_PLATFORM " ${FLAGS_platform}
echo "PACK_BOARD " ${FLAGS_board}
echo "PACK_KERN " ${FLAGS_kernel}
echo "PACK_DEBUG " ${FLAGS_debug_mode}
echo "PACK_SIG " ${FLAGS_signture}
echo "PACK_SECURE " ${FLAGS_secure}
echo "PACK_MODE " ${FLAGS_mode}
echo "PACK_FUNC " ${FLAGS_function}
echo "PACK_PROGRAMMER " ${FLAGS_programmer}
echo "PACK_TAR_IMAGE " ${FLAGS_tar_image}
echo "PACK_TOPDIR " ${FLAGS_topdir}
echo --==========--
}
show_args
ROOT_DIR=${PACK_TOPDIR}/out/${PACK_BOARD}
OTA_TEST_NAME="ota_test"
export PATH=${PACK_TOPDIR}/out/host/bin/:$PATH
if [ "x${PACK_CHIP}" = "xsun5i" ]; then
PACK_BOARD_PLATFORM=unclear
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw5p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw6p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw7p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw8p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw11p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw10p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw15p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw17p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw18p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw20p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw21p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw19p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun3iw1p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun50iw1p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm64
elif [ "x${PACK_CHIP}" = "xsun50iw3p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm64
elif [ "x${PACK_CHIP}" = "xsun8iw12p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun8iw16p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm
elif [ "x${PACK_CHIP}" = "xsun50iw6p1" -o "x${PACK_CHIP}" = "xsun50iw9p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm64
elif [ "x${PACK_CHIP}" = "xsun50iw10p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm64
elif [ "x${PACK_CHIP}" = "xsun50iw11p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=arm64
elif [ "x${PACK_CHIP}" = "xsun20iw1p1" ]; then
PACK_BOARD_PLATFORM=${PACK_BOARD%%-*}
ARCH=riscv
else
echo "board_platform($PACK_CHIP) not support"
fi
TINA_CONFIG_DIR="${PACK_TOPDIR}/target/allwinner"
LONGAN_CONFIG_DIR="${PACK_TOPDIR}/device/config/chips/${PACK_BOARD_PLATFORM}/configs"
LONGAN_COMMON_DIR="${PACK_TOPDIR}/device/config/common"
LICHEE_CHIP_CONFIG_DIR="${PACK_TOPDIR}/device/config/chips/${PACK_BOARD_PLATFORM}"
PACK_PLATFORM_IMAGE_CFG=$PACK_PLATFORM
[ x"$PACK_PLATFORM" = x"tina" ] && PACK_PLATFORM_IMAGE_CFG="linux"
tools_file_list=(
${TINA_CONFIG_DIR}/generic/tools/split_xxxx.fex
${TINA_CONFIG_DIR}/generic/tools/usbtool_test.fex
${TINA_CONFIG_DIR}/generic/tools/usbtool_crash.fex
${TINA_CONFIG_DIR}/generic/tools/cardscript.fex
${TINA_CONFIG_DIR}/generic/tools/cardscript_secure.fex
${TINA_CONFIG_DIR}/generic/tools/cardtool.fex
${TINA_CONFIG_DIR}/generic/tools/usbtool.fex
${TINA_CONFIG_DIR}/generic/tools/aultls32.fex
${TINA_CONFIG_DIR}/generic/tools/aultools.fex
${LONGAN_COMMON_DIR}/tools/split_xxxx.fex
${LONGAN_COMMON_DIR}/tools/usbtool_test.fex
${LONGAN_COMMON_DIR}/tools/usbtool_crash.fex
${LONGAN_COMMON_DIR}/tools/cardscript.fex
${LONGAN_COMMON_DIR}/tools/cardscript_secure.fex
${LONGAN_COMMON_DIR}/tools/cardtool.fex
${LONGAN_COMMON_DIR}/tools/usbtool.fex
${LONGAN_COMMON_DIR}/tools/aultls32.fex
${LONGAN_COMMON_DIR}/tools/aultools.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/split_xxxx.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/usbtool_test.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/usbtool_crash.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/cardscript.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/cardscript_secure.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/cardtool.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/usbtool.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/aultls32.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/aultools.fex
${LONGAN_CONFIG_DIR}/../tools/split_xxxx.fex
${LONGAN_CONFIG_DIR}/../tools/usbtool_test.fex
${LONGAN_CONFIG_DIR}/../tools/usbtool_crash.fex
${LONGAN_CONFIG_DIR}/../tools/cardscript.fex
${LONGAN_CONFIG_DIR}/../tools/cardscript_secure.fex
${LONGAN_CONFIG_DIR}/../tools/cardtool.fex
${LONGAN_CONFIG_DIR}/../tools/usbtool.fex
${LONGAN_CONFIG_DIR}/../tools/aultls32.fex
${LONGAN_CONFIG_DIR}/../tools/aultools.fex
)
configs_file_list=(
${TINA_CONFIG_DIR}/generic/toc/toc1.fex
${TINA_CONFIG_DIR}/generic/toc/toc0.fex
${TINA_CONFIG_DIR}/generic/toc/boot_package.fex
${TINA_CONFIG_DIR}/generic/dtb/sunxi.fex
${TINA_CONFIG_DIR}/generic/configs/*.fex
${TINA_CONFIG_DIR}/generic/configs/*.cfg
${TINA_CONFIG_DIR}/generic/version/version_base.mk
${LONGAN_COMMON_DIR}/toc/*.fex
${LONGAN_COMMON_DIR}/hdcp/esm.fex
${LONGAN_COMMON_DIR}/dtb/sunxi.fex
${LONGAN_COMMON_DIR}/imagecfg/*.cfg
${LONGAN_COMMON_DIR}/partition/sys_partition_dump.fex
${LONGAN_COMMON_DIR}/partition/sys_partition_private.fex
${LONGAN_COMMON_DIR}/version/version_base.mk
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/configs/*.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/configs/*.cfg
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/configs/*.its
${TINA_CONFIG_DIR}/${PACK_BOARD}/configs/*.fex
${TINA_CONFIG_DIR}/${PACK_BOARD}/configs/*.cfg
${LONGAN_CONFIG_DIR}/default/*.fex
${LONGAN_CONFIG_DIR}/default/*.cfg
${LONGAN_CONFIG_DIR}/default/*.its
${LONGAN_CONFIG_DIR}/default/version_base.mk
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/*.fex
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/*.cfg
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/linux/*.fex
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/linux/*.cfg
)
boot_resource_list=(
${TINA_CONFIG_DIR}/generic/boot-resource/boot-resource:image/
${TINA_CONFIG_DIR}/generic/boot-resource/boot-resource.ini:image/
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/boot-resource:image/
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/boot-resource.ini:image/
${TINA_CONFIG_DIR}/${PACK_BOARD}/configs/*.bmp:image/boot-resource/
${LONGAN_CONFIG_DIR}/default/boot-resource:image/
${LONGAN_CONFIG_DIR}/default/boot-resource.ini:image/
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/configs/*.bmp:image/boot-resource/
)
possible_bin_path=(
bin
configs/${PACK_BOARD#*-}/bin
configs/${PACK_BOARD#*-}/${PACK_PLATFORM_IMAGE_CFG}/bin
)
boot_file_list=(
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_nand_${PACK_CHIP}.bin:${ROOT_DIR}/image/boot0_nand.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_sdcard_${PACK_CHIP}.bin:${ROOT_DIR}/image/boot0_sdcard.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_spinor_${PACK_CHIP}.bin:${ROOT_DIR}/image/boot0_spinor.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/fes1_${PACK_CHIP}.bin:${ROOT_DIR}/image/fes1.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-${PACK_CHIP}.bin:${ROOT_DIR}/image/u-boot.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-crashdump-${PACK_CHIP}.bin:${ROOT_DIR}/image/u-boot-crash.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-crashdump-spinor-${PACK_CHIP}.bin:${ROOT_DIR}/image/u-boot-spinor-crash.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/bl31.bin:${ROOT_DIR}/image/monitor.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/scp.bin:${ROOT_DIR}/image/scp.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}-monitor.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/opensbi_${PACK_CHIP}.bin:${ROOT_DIR}/image/opensbi.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-spinor-${PACK_CHIP}.bin:${ROOT_DIR}/image/u-boot-spinor.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_nand_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/boot0_nand-${OTA_TEST_NAME}.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_sdcard_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/boot0_sdcard-${OTA_TEST_NAME}.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/boot0_spinor_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/boot0_spinor-${OTA_TEST_NAME}.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/u-boot-${OTA_TEST_NAME}.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-spinor-${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/u-boot-spinor-${OTA_TEST_NAME}.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/dsp0.bin:${ROOT_DIR}/image/dsp0.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/dsp1.bin:${ROOT_DIR}/image/dsp1.fex
)
arm_boot_file_secure=(
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${ROOT_DIR}/image/semelis.bin
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/u-boot-${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/u-boot.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${ROOT_DIR}/image/semelis.bin
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/u-boot-${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/u-boot.fex
${TINA_CONFIG_DIR}/${PACK_BOARD}/\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${ROOT_DIR}/image/semelis.bin
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/u-boot-${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/u-boot.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${ROOT_DIR}/image/semelis.bin
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/u-boot-${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/u-boot.fex
${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
)
arm64_boot_file_secure=(
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
# ${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/optee_${PACK_CHIP}-secure.bin:${ROOT_DIR}/image/optee.fex
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
# ${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/sboot_${PACK_CHIP}-${OTA_TEST_NAME}.bin:${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin
)
riscv_boot_file_secure=(
${LONGAN_CONFIG_DIR}/../\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${ROOT_DIR}/image/sboot.bin
)
function get_partition_downfile_size()
{
local downloadfile_name=`echo $1 | awk -F '=' '{print $2}'`
if [ x${downloadfile_name: 0-4} != x".fex" ]; then
pack_error "downloadfile format is wrong, it should be end with .fex"
exit -1
fi
if [ ! -f ${downloadfile_name} ]; then
echo " file ${downloadfile_name} not find"
else
if [ -L ${downloadfile_name} ]; then
local downloadfile_name_link=`readlink -f ${downloadfile_name}`
local linkfile_name=${downloadfile_name_link##*/}
echo " ${downloadfile_name} -> ${downloadfile_name_link}"
if [ ! -f ${downloadfile_name_link} ]; then
echo " link file ${linkfile_name} not find"
else
local linkfile_size=`ls -lh ${downloadfile_name_link} | awk '{print $5}'`
echo " ${linkfile_name} size : ${linkfile_size} byte"
fi
else
local downloadfile_size=`ls -lh ${downloadfile_name} | awk '{print $5}'`
echo " ${downloadfile_name} size : ${downloadfile_size} byte"
fi
fi
}
function get_partition_mbr_size()
{
local partition_size_name=`echo $1 | awk -F '=' '{print $1}' | sed 's/partition/mbr/g'`
local partition_size=`echo $1 | awk -F '=' '{print $2}'`
echo " ${partition_size_name} : ${partition_size} Kbyte"
}
function show_partition_message()
{
grep -c '[mbr]' $1 > /dev/null
if [ $? -eq 0 ]; then
cp $1 ./show_sys_partition.tmp;
sed -i '/^[\r;]/d' ./show_sys_partition.tmp;
sed -i '/partition_start/d' ./show_sys_partition.tmp;
sed -i '/user_type/d' ./show_sys_partition.tmp;
sed -i 's/\[partition\]/------------------------------------/g' ./show_sys_partition.tmp;
sed -i 's/[ "\r]//g' ./show_sys_partition.tmp;
sed -i '/^[;]/d' ./show_sys_partition.tmp;
sed -i 's/name/partition_name/g' ./show_sys_partition.tmp;
sed -i 's/size/partition_size/g' ./show_sys_partition.tmp;
echo "------------------------------------"
while read line
do
if [ "$line" == "------------------------------------" ];then
echo "$line"
else
echo " $line" | sed 's/=/ : /g'
echo " $line" | grep "mbr" >> /dev/null
if [ $? -eq 0 ]; then
read line
get_partition_mbr_size $line
fi
echo "$line" | grep "downloadfile" >> /dev/null
if [ $? -eq 0 ]; then
get_partition_downfile_size $line
fi
fi
done < ./show_sys_partition.tmp
echo "------------------------------------"
rm ./show_sys_partition.tmp
else
echo "==========input is not a partition file=========="
fi
}
function show_boards()
{
printf "\nAll avaiable chips, platforms and boards:\n\n"
printf "Chip Board\n"
for chipdir in $(find chips/ -mindepth 1 -maxdepth 1 -type d) ; do
chip=`basename ${chipdir}`
printf "${chip}\n"
for boarddir in $(find chips/${chip}/configs/${platform} \
-mindepth 1 -maxdepth 1 -type d) ; do
board=`basename ${boarddir}`
printf " ${board}\n"
done
done
printf "\nFor Usage:\n"
printf " $(basename $0) -h\n\n"
}
function do_platform_pack_hook()
{
PWD=$(pwd)
if [ -e ${TINA_CONFIG_DIR}/${PACK_BOARD}/hooks/pack_${1}_hook.sh ] ; then
pack_info "--Call platform pack ${1} hook now--"
cd ${TINA_CONFIG_DIR}/${PACK_BOARD}/hooks/
./pack_${1}_hook.sh
cd ${PWD}
fi
}
function call_platform_pack_hook()
{
hook_type=$1
do_platform_pack_hook $hook_type
}
function call_platform_pack_prepare_hook()
{
call_platform_pack_hook prepare
}
function uart_switch()
{
local DEBUG_DIR="${LONGAN_COMMON_DIR}/debug"
rm -rf ${ROOT_DIR}/image/awk_debug_card0
touch ${ROOT_DIR}/image/awk_debug_card0
TX=`awk '$0~"'$PACK_CHIP'"{print $2}' ${DEBUG_DIR}/card_debug_pin`
RX=`awk '$0~"'$PACK_CHIP'"{print $3}' ${DEBUG_DIR}/card_debug_pin`
PORT=`awk '$0~"'$PACK_CHIP'"{print $4}' ${DEBUG_DIR}/card_debug_pin`
MS=`awk '$0~"'$PACK_CHIP'"{print $5}' ${DEBUG_DIR}/card_debug_pin`
CK=`awk '$0~"'$PACK_CHIP'"{print $6}' ${DEBUG_DIR}/card_debug_pin`
DO=`awk '$0~"'$PACK_CHIP'"{print $7}' ${DEBUG_DIR}/card_debug_pin`
DI=`awk '$0~"'$PACK_CHIP'"{print $8}' ${DEBUG_DIR}/card_debug_pin`
BOOT_UART_ST=`awk '$0~"'$PACK_CHIP'"{print $2}' ${DEBUG_DIR}/card_debug_string`
BOOT_PORT_ST=`awk '$0~"'$PACK_CHIP'"{print $3}' ${DEBUG_DIR}/card_debug_string`
BOOT_TX_ST=`awk '$0~"'$PACK_CHIP'"{print $4}' ${DEBUG_DIR}/card_debug_string`
BOOT_RX_ST=`awk '$0~"'$PACK_CHIP'"{print $5}' ${DEBUG_DIR}/card_debug_string`
UART0_ST=`awk '$0~"'$PACK_CHIP'"{print $6}' ${DEBUG_DIR}/card_debug_string`
UART0_USED_ST=`awk '$0~"'$PACK_CHIP'"{print $7}' ${DEBUG_DIR}/card_debug_string`
UART0_PORT_ST=`awk '$0~"'$PACK_CHIP'"{print $8}' ${DEBUG_DIR}/card_debug_string`
UART0_TX_ST=`awk '$0~"'$PACK_CHIP'"{print $9}' ${DEBUG_DIR}/card_debug_string`
UART0_RX_ST=`awk '$0~"'$PACK_CHIP'"{print $10}' ${DEBUG_DIR}/card_debug_string`
UART1_ST=`awk '$0~"'$PACK_CHIP'"{print $11}' ${DEBUG_DIR}/card_debug_string`
JTAG_ST=`awk '$0~"'$PACK_CHIP'"{print $12}' ${DEBUG_DIR}/card_debug_string`
MS_ST=`awk '$0~"'$PACK_CHIP'"{print $13}' ${DEBUG_DIR}/card_debug_string`
CK_ST=`awk '$0~"'$PACK_CHIP'"{print $14}' ${DEBUG_DIR}/card_debug_string`
DO_ST=`awk '$0~"'$PACK_CHIP'"{print $15}' ${DEBUG_DIR}/card_debug_string`
DI_ST=`awk '$0~"'$PACK_CHIP'"{print $16}' ${DEBUG_DIR}/card_debug_string`
MMC0_ST=`awk '$0~"'$PACK_CHIP'"{print $17}' ${DEBUG_DIR}/card_debug_string`
MMC0_USED_ST=`awk '$0~"'$PACK_CHIP'"{print $18}' ${DEBUG_DIR}/card_debug_string`
echo '$0!~";" && $0~"'$BOOT_TX_ST'"{if(C)$0="'$BOOT_TX_ST' = '$TX'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$BOOT_RX_ST'"{if(C)$0="'$BOOT_RX_ST' = '$RX'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$BOOT_PORT_ST'"{if(C)$0="'$BOOT_PORT_ST' = '$PORT'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
if [ "`grep "auto_print_used" "${ROOT_DIR}/image//sys_config.fex" | grep "1"`" ]; then
echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 1";A=0} \' >> ${ROOT_DIR}/image/awk_debug_card0
else
echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 0";A=0} \' >> ${ROOT_DIR}/image/awk_debug_card0
fi
echo '$0!~";" && $0~"\\['$MMC0_ST'\\]"{A=1} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$UART0_TX_ST'"{if(B)$0="'$UART0_TX_ST' = '$TX'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$UART0_RX_ST'"{if(B)$0="'$UART0_RX_ST' = '$RX'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"\\['$UART0_ST'\\]"{B=1} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$UART0_USED_ST'"{if(B)$0="'$UART0_USED_ST' = 1"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '/^'$UART0_PORT_ST'/{next} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"\\['$UART1_ST'\\]"{B=0} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"\\['$BOOT_UART_ST'\\]"{C=1} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"\\['$JTAG_ST'\\]"{C=0} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$MS_ST'"{$0="'$MS_ST' = '$MS'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$CK_ST'"{$0="'$CK_ST' = '$CK'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$DO_ST'"{$0="'$DO_ST' = '$DO'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '$0!~";" && $0~"'$DI_ST'"{$0="'$DI_ST' = '$DI'"} \' >> ${ROOT_DIR}/image/awk_debug_card0
echo '1' >> ${ROOT_DIR}/image/awk_debug_card0
if [ "`grep "auto_print_used" "${ROOT_DIR}/image/sys_config.fex" | grep "1"`" ]; then
sed -i -e '/^uart0_rx/a\pinctrl-1=' ${ROOT_DIR}/image/sys_config.fex
sed -i -e '/^uart0_rx/a\pinctrl-0=' ${ROOT_DIR}/image/sys_config.fex
fi
awk -f ${ROOT_DIR}/image/awk_debug_card0 ${ROOT_DIR}/image/sys_config.fex > ${ROOT_DIR}/image/sys_config_debug.fex
rm -f ${ROOT_DIR}/image/sys_config.fex
mv ${ROOT_DIR}/image/sys_config_debug.fex ${ROOT_DIR}/image/sys_config.fex
echo "uart -> card0"
}
function copy_ota_test_file()
{
printf "ota test bootloader by diff bootlogo\n"
mv ${ROOT_DIR}/image/boot-resource/bootlogo_ota_test.bmp ${ROOT_DIR}/image/boot-resource/bootlogo.bmp
printf "copying ota test boot file\n"
if [ -f ${ROOT_DIR}/image/sys_partition_nor.fex -o \
-f ${ROOT_DIR}/image/sys_partition_nor_${PACK_PLATFORM}.fex ]; then
mv ${ROOT_DIR}/image/boot0_spinor-${OTA_TEST_NAME}.fex ${ROOT_DIR}/image/boot0_spinor.fex
mv ${ROOT_DIR}/image/u-boot-spinor-${OTA_TEST_NAME}.fex ${ROOT_DIR}/image/u-boot-spinor.fex
else
mv ${ROOT_DIR}/image/boot0_nand-${OTA_TEST_NAME}.fex ${ROOT_DIR}/image/boot0_nand.fex
mv ${ROOT_DIR}/image/boot0_sdcard-${OTA_TEST_NAME}.fex ${ROOT_DIR}/image/boot0_sdcard.fex
mv ${ROOT_DIR}/image/u-boot-${OTA_TEST_NAME}.fex ${ROOT_DIR}/image/u-boot.fex
fi
if [ "x${PACK_SECURE}" = "xsecure" -o "x${PACK_SIG}" = "prev_refurbish"] ; then
printf "Copying ota test secure boot file\n"
mv ${ROOT_DIR}/image/sboot-${OTA_TEST_NAME}.bin ${ROOT_DIR}/image/sboot.bin
fi
printf "OTA test env by bootdelay(10) and logolevel(8)\n"
sed -i 's/\(logolevel=\).*/\18/' ${ROOT_DIR}/image/env.cfg
sed -i 's/\(bootdelay=\).*/\110/' ${ROOT_DIR}/image/env.cfg
}
function add_lzma_header()
{
lzma_file=$1
original_file=$2
file_size=$(printf "%.8x\n" `stat -c%s ${lzma_file}`)
original_file_size=$(printf "%.8x\n" `stat -c%s ${original_file}`)
bin_str=""
file_size_len=${#file_size}
#"LZMA"+size+origin_size
bin_str="\x4c\x5a\x4d\x41\x${file_size:6:2}\x${file_size:4:2}\x${file_size:2:2}\x${file_size:0:2}"
bin_str+="\x${original_file_size:6:2}\x${original_file_size:4:2}\x${original_file_size:2:2}\x${original_file_size:0:2}"
printf "%b" ${bin_str} > tempbin
cat ${lzma_file} >> tempbin
mv tempbin "${lzma_file}.head"
}
function update_mbr_to_sys_config()
{
cd ${ROOT_DIR}/image
#use sys_partition_tmp
cp $1 sys_partition_tmp.fex
#convert sys_partition.fex to sunxi_mbr.fex
#don't care about downloadfile
sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp.fex
/bin/busybox unix2dos sys_partition_tmp.fex
script sys_partition_tmp.fex > /dev/null
update_mbr sys_partition_tmp.bin 1 sunxi_mbr_tmp.fex > /dev/null
#get size and offset
local PART_INDEX
local PART_NAME
local PART_SIZE
local PART_OFFSET
echo "" >> ${ROOT_DIR}/image/sys_config.fex
echo "[partitions]" >> ${ROOT_DIR}/image/sys_config.fex
echo "" >> ${ROOT_DIR}/image/sys_config.fex
# add one partition to sys_config
# PART_NAME="vital"
# PART_SIZE=`parser_mbr sunxi_mbr_tmp.fex get_size_by_name ${PART_NAME}`
# PART_OFFSET=`parser_mbr sunxi_mbr_tmp.fex get_offset_by_name ${PART_NAME}`
# #update to sys_config
# echo "[partitions/vital]" >> ${ROOT_DIR}/image/sys_config.fex
# echo "offset = ${PART_OFFSET}" >> ${ROOT_DIR}/image/sys_config.fex
# echo "size = ${PART_SIZE}" >> ${ROOT_DIR}/image/sys_config.fex
# add all partitions to sys_config
total_num=`parser_mbr sunxi_mbr_tmp.fex get_total_num`
let total_num--
for PART_INDEX in $( /usr/bin/seq 0 ${total_num} )
do
PART_NAME=`parser_mbr sunxi_mbr_tmp.fex get_name_by_index ${PART_INDEX}`
PART_SIZE=`parser_mbr sunxi_mbr_tmp.fex get_size_by_index ${PART_INDEX}`
PART_OFFSET=`parser_mbr sunxi_mbr_tmp.fex get_offset_by_index ${PART_INDEX}`
echo "[partitions/${PART_NAME}]" >> ${ROOT_DIR}/image/sys_config.fex
echo "offset = ${PART_OFFSET}" >> ${ROOT_DIR}/image/sys_config.fex
echo "size = ${PART_SIZE}" >> ${ROOT_DIR}/image/sys_config.fex
echo "" >> ${ROOT_DIR}/image/sys_config.fex
done
#clean
rm -f sys_partition_tmp.fex sys_partition_tmp.bin sunxi_mbr_tmp.fex dlinfo.fex
cd - > /dev/null
}
function sparse_ext4()
{
local img=$1
local sparse_img=$2
if file $img | grep -q ext4 ;then
echo "now make sparse ext4 img: $img"
else
echo "$img is not ext4 img"
file $img
return
fi
img2simg $img $sparse_img
}
# pack user resources to a vfat filesystem
# To use this, please add a folder "user-resource" in configs to save files, and add a partition to sys_partition.fex/sys_partition_nor.fex like this:
# [partition]
# name = user-res
# size = 1024
# downloadfile = "user-resource.fex"
# user_type = 0x8000
function make_user_res()
{
printf "make user resource for : $1\n"
local USER_RES_SYS_PARTITION=$1
local USER_RES_PART_NAME=user-res
local USER_RES_FILE=user-resource
printf "handle partition ${USER_RES_PART_NAME}\n"
local USER_RES_PART_DOWNLOAD_FILE=`awk 'BEGIN {FS="\n"; RS=""} /'${USER_RES_PART_NAME}'/{print $0}' ${USER_RES_SYS_PARTITION} | awk '{if($1 == "downloadfile"){print $3}}' | sed 's/"//g'`
local USER_RES_PART_SIZE=`awk 'BEGIN {FS="\n"; RS=""} /'${USER_RES_PART_NAME}'/{print $0}' $1 | awk '$0~"size"{print $3/2}'`
local USER_RES_FILE_PATH=${TINA_CONFIG_DIR}/${PACK_BOARD}/configs/${USER_RES_FILE}
if [ x${USER_RES_PART_DOWNLOAD_FILE} != x'' -a x${USER_RES_PART_SIZE} != x'' ];then
rm -f ${ROOT_DIR}/image/user-resource.fex
mkfs.vfat ${ROOT_DIR}/image/user-resource.fex -C ${USER_RES_PART_SIZE}
if [ -d ${USER_RES_FILE_PATH} ];then
USER_RES_FILE_SIZE=`du --summarize "${USER_RES_FILE_PATH}" | awk '{print $1}'`
printf "file size: ${USER_RES_FILE_SIZE}\n"
printf "partition size: ${USER_RES_PART_SIZE}\n"
if [ ${USER_RES_PART_SIZE} -le ${USER_RES_FILE_SIZE} ]; then
printf "file size is larger than partition size, please check your configuration\n"
printf "please enlarge size of ${USER_RES_PART_NAME} in sys_partition or remove some files in $USER_RES_FILE_PATH\n"
exit -1
fi
mcopy -s -v -i ${ROOT_DIR}/image/${USER_RES_PART_DOWNLOAD_FILE} ${USER_RES_FILE_PATH}/* ::
if [ $? -ne 0 ]; then
printf "mcopy file fail, exit\n"
exit -1
fi
else
printf "can not find ${USER_RES_FILE_PATH}, ignore it\n"
fi
else
printf "no user resource partitions\n"
fi
}
function make_app_res()
{
cd ${ROOT_DIR}/image
local APP_PART_NAME=app
cp $1 sys_partition_tmp_app.fex
sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_app.fex
/bin/busybox unix2dos sys_partition_tmp_app.fex
script sys_partition_tmp_app.fex > /dev/null
update_mbr sys_partition_tmp_app.bin 1 sunxi_mbr_tmp_app.fex > /dev/null
local APP_PART_DOWNLOAD_FILE=app.fex
local APP_PART_FILE_PATH=${PACK_TOPDIR}/out/${TARGET_BOARD}/compile_dir/target/app
local APP_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_app.fex get_size_by_name ${APP_PART_NAME}`
if [ x${APP_PART_DOWNLOAD_FILE} != x'' -a x${APP_PART_SIZE_IN_SECTOR} != x'' ]; then
let APP_PART_SIZE_IN_K=$APP_PART_SIZE_IN_SECTOR/2
echo "APP_PART_DOWNLOAD_FILE = ${ROOT_DIR}/image/${APP_PART_DOWNLOAD_FILE}"
rm -f ${ROOT_DIR}/image/${APP_PART_DOWNLOAD_FILE}
${PACK_TOPDIR}/out/host/bin/make_ext4fs -l ${APP_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${ROOT_DIR}/image/${APP_PART_DOWNLOAD_FILE} ${APP_PART_FILE_PATH}
else
printf "no app resource partitions\n"
fi
cd - > /dev/null
}
function make_data_res()
{
cd ${ROOT_DIR}/image
local DATA_PART_NAME=data
cp $1 sys_partition_tmp_data.fex
sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_data.fex
/bin/busybox unix2dos sys_partition_tmp_data.fex
script sys_partition_tmp_data.fex > /dev/null
update_mbr sys_partition_tmp_data.bin 1 sunxi_mbr_tmp_data.fex > /dev/null
local DATA_PART_DOWNLOAD_FILE=data.fex
local DATA_PART_DOWNLOAD_FILE_SPARSE=data_s.fex
local DATA_PART_FILE_PATH=${PACK_TOPDIR}/out/${TARGET_BOARD}/compile_dir/target/data
local DATA_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_data.fex get_size_by_name ${DATA_PART_NAME}`
if [ x${DATA_PART_DOWNLOAD_FILE} != x'' -a x${DATA_PART_SIZE_IN_SECTOR} != x'0' ]; then
let DATA_PART_SIZE_IN_K=$DATA_PART_SIZE_IN_SECTOR/2
echo "DATA_PART_DOWNLOAD_FILE = ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE}"
rm -f ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE}
rm -f ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE_SPARSE}
${PACK_TOPDIR}/out/host/bin/make_ext4fs -l ${DATA_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE} ${DATA_PART_FILE_PATH}
sparse_ext4 ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE} ${ROOT_DIR}/image/${DATA_PART_DOWNLOAD_FILE_SPARSE}
else
printf "no data resource partitions\n"
fi
cd - > /dev/null
}
function make_boottone_fex()
{
local BOOTTONE_FILE_PATH=${TINA_CONFIG_DIR}/${PACK_BOARD}/configs/boottone_res
if [ -e $BOOTTONE_FILE_PATH ];then
echo "make boottone.fex"
${PACK_TOPDIR}/out/host/bin/make_ext4fs -l 512k -b 1024 -m 0 -J ${ROOT_DIR}/image/boottone.fex $BOOTTONE_FILE_PATH
fi
}
ENV_SUFFIX=
function get_kernel
{
local f="${TINA_CONFIG_DIR}/${PACK_BOARD}/Makefile"
[ -f "$f" ] || return -1
awk -F":=" '/KERNEL_PATCHVER/{print $2}' $f
}
function do_prepare()
{
if [ -z "${PACK_CHIP}" -o -z "${PACK_PLATFORM}" -o -z "${PACK_BOARD}" ] ; then
pack_error "Invalid parameters Chip: ${PACK_CHIP}, \
Platform: ${PACK_PLATFORM}, Board: ${PACK_BOARD}"
show_boards
exit 1
fi
[ -d ${TINA_CONFIG_DIR}/${PACK_BOARD}/configs -o -d ${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/linux ] || {
pack_error "Board's directory \
\"${TINA_CONFIG_DIR}/${PACK_BOARD}/configs or ${LONGAN_CONFIG_DIR}/${PACK_BOARD#*-}/linux\" not exist."
show_boards
exit 1
}
if [ -z "${PACK_KERN}" ] ; then
printf "No kernel param, parse it from ${PACK_BOARD_PLATFORM}\n"
[ "x$(get_kernel)" != "x" ] && {
PACK_KERN="linux-$(get_kernel)"
ENV_SUFFIX=$(get_kernel)
}
if [ -z "${PACK_KERN}" ] ; then
pack_error "Failed to parse kernel param from ${PACK_BOARD_PLATFORM}"
exit 1
fi
fi
# Cleanup
rm -rf ${ROOT_DIR}/image
mkdir -p ${ROOT_DIR}/image
call_platform_pack_prepare_hook
printf "copying tools file\n"
for file in ${tools_file_list[@]} ; do
cp -f $file ${ROOT_DIR}/image/ 2> /dev/null
done
if [ "x${PACK_KERN}" = "xlinux-3.4" ]; then
if [ -f ${LONGAN_COMMON_DIR}/tools/cardscript.fex ]; then
cp -f ${LONGAN_COMMON_DIR}/tools/cardscript.fex ${ROOT_DIR}/image/ 2> /dev/null
else
cp -f ${TINA_CONFIG_DIR}/generic/tools/cardscript.fex ${ROOT_DIR}/image/ 2> /dev/null
fi
fi
printf "copying configs file\n"
for file in ${configs_file_list[@]} ; do
cp -f $file ${ROOT_DIR}/image/ 2> /dev/null
done
if [ -f ${ROOT_DIR}/image/sys_config_${PACK_KERN}.fex ]; then
cp ${ROOT_DIR}/image/sys_config_${PACK_KERN}.fex ${ROOT_DIR}/image/sys_config.fex
fi
# get storage_type value from sys_config.fex
if [ ! -f ${ROOT_DIR}/image/sys_config.fex ];then
echo "sys_config.fex is not exist."
exit 1
fi
# If platform config files exist, we will cover the default files
# For example, mv out/image_linux.cfg out/image.cfg
cd ${ROOT_DIR}
find image/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
sed "s#\(.*\)_${PACK_PLATFORM_IMAGE_CFG}\(\..*\)#mv -fv & \1\2#e" > /dev/null
cd - > /dev/null
local storage_type
storage_type=`sed -e '/^$/d' -e '/^;/d' -e '/^\[/d' -n -e '/^storage_type/p' ${ROOT_DIR}/image/sys_config.fex | sed 's/=/ /g' | awk '{ print $2;}'`
echo "storage_type value is ${storage_type}"
image_instruction="image is for nand/emmc"
case ${storage_type} in
3)
echo "storage type is nor"
if [ -f ${ROOT_DIR}/image/image_nor.cfg ];then
echo "image_nor.cfg is exist"
mv ${ROOT_DIR}/image/image_nor.cfg ${ROOT_DIR}/image/image.cfg && echo "mv image_nor.cfg image.cfg"
image_instruction="image is for nor"
IMG_FLASH="_nor"
fi
;;
-1)
;;
*)
if [ -f ${ROOT_DIR}/image/sys_partition_nor.fex ];then
rm ${ROOT_DIR}/image/sys_partition_nor.fex && echo "rm ${ROOT_DIR}/image/sys_partition_nor.fex"
fi
if [ -f ${ROOT_DIR}/image/image_nor.cfg ];then
rm ${ROOT_DIR}/image/image_nor.cfg && echo "rm ${ROOT_DIR}/image/image_nor.cfg"
fi
;;
esac
# amend env copy
mv ${ROOT_DIR}/image/env-${ENV_SUFFIX}.cfg ${ROOT_DIR}/image/env.cfg 2> /dev/null
if [ "x${PACK_MODE}" = "xdump" ] ; then
cp -vf ${ROOT_DIR}/image/sys_partition_dump.fex ${ROOT_DIR}/image/sys_partition.fex
cp -vf ${ROOT_DIR}/image/usbtool_test.fex ${ROOT_DIR}/image/usbtool.fex
elif [ "x${PACK_FUNC}" = "xprvt" ] ; then
cp -vf ${ROOT_DIR}/image/sys_partition_private.fex ${ROOT_DIR}/image/sys_partition.fex
fi
grep "CONFIG_USE_DM_VERITY=y" ${PACK_TOPDIR}/.config > /dev/null
if [ $? -eq 0 ]; then
cp -vf ${ROOT_DIR}/image/sys_partition_secure.fex ${ROOT_DIR}/image/sys_partition.fex
fi
printf "copying boot resource\n"
for file in ${boot_resource_list[@]} ; do
cp -rf `echo $file | awk -F: '{print $1}'` \
${ROOT_DIR}/`echo $file | awk -F: '{print $2}'` 2>/dev/null
done
# Support boot0 load bmp logo to kernel
if [ -f "${ROOT_DIR}/image/boot-resource/bootlogo.bmp" ]; then
xz --format=lzma -k ${ROOT_DIR}/image/boot-resource/bootlogo.bmp
add_lzma_header "${ROOT_DIR}/image/boot-resource/bootlogo.bmp.lzma" "${ROOT_DIR}/image/boot-resource/bootlogo.bmp"
mv ${ROOT_DIR}/image/boot-resource/bootlogo.bmp.lzma.head ${ROOT_DIR}/image/bootlogo.bmp.lzma
rm ${ROOT_DIR}/image/boot-resource/bootlogo.bmp.lzma
fi
# Support boot0 load bmp logo to uboot
# lzma e ${ROOT_DIR}/image/boot-resource/bootlogo.bmp ${ROOT_DIR}/image/bootlogo.bmp.lzma
printf "copying boot file\n"
for d in ${possible_bin_path[@]}; do
[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
BIN_PATH=$d
for file in ${boot_file_list[@]} ; do
eval cp -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
done
done
[ -z "${BIN_PATH}" ] &&
pack_error "No BIN_PATH found!" && exit 1
if [ "x${PACK_SECURE}" = "xsecure" -o "x${PACK_SIG}" = "xsecure" -o "x${PACK_SIG}" = "xprev_refurbish" ] ; then
printf "copying ${ARCH}_boot_file_secure secure boot file\n"
for d in ${possible_bin_path[@]}; do
BIN_PATH=$d
for file in $(eval echo '$'"{${ARCH}_boot_file_secure[@]}"); do
eval cp -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
done
done
fi
# If longan platform config use
if [ -f ${LONGAN_CONFIG_DIR}/../tools/plat_config.sh ] ; then
${LONGAN_CONFIG_DIR}/../tools/plat_config.sh
fi
# If tina platform config use
if [ -f ${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/plat_config.sh ] ; then
${TINA_CONFIG_DIR}/${PACK_BOARD_PLATFORM}-common/tools/plat_config.sh
fi
if [ "x${PACK_SECURE}" = "xsecure" -o "x${PACK_SIG}" = "xsecure" ] ; then
printf "add burn_secure_mode in target in sys config\n"
sed -i -e '/^\[target\]/a\burn_secure_mode=1' ${ROOT_DIR}/image/sys_config.fex
sed -i -e '/^\[platform\]/a\secure_without_OS=0' ${ROOT_DIR}/image/sys_config.fex
elif [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
printf "add burn_secure_mode in target in sys config\n"
sed -i -e '/^\[target\]/a\burn_secure_mode=1' ${ROOT_DIR}/image/sys_config.fex
sed -i -e '/^\[platform\]/a\secure_without_OS=1' ${ROOT_DIR}/image/sys_config.fex
else
sed -i '/^burn_secure_mod/d' ${ROOT_DIR}/image/sys_config.fex
sed -i '/^secure_without_OS/d' ${ROOT_DIR}/image/sys_config.fex
fi
if [ "x${PACK_MODE}" = "xota_test" ] ; then
printf "copy ota test file\n"
copy_ota_test_file
fi
if [ "x${PACK_PROGRAMMER}" = "xprogrammer" ]; then
printf "add programmer img info target in sys config\n"
sed -i -e '/^\[target\]/a\programmer=1' out/sys_config.fex
fi
# Here, we can switch uart to card or normal
if [ "x${PACK_DEBUG}" = "xcard0" -a "x${PACK_MODE}" != "xdump" \
-a "x${PACK_FUNC}" != "xprvt" ] ; then \
uart_switch
else
sed -i -e '/^auto_print_used/s\1\0\' ${ROOT_DIR}/image/sys_config.fex
fi
sed -i 's/\\boot-resource/\/boot-resource/g' ${ROOT_DIR}/image/boot-resource.ini
sed -i 's/\\\\/\//g' ${ROOT_DIR}/image/image.cfg
sed -i 's/^imagename/;imagename/g' ${ROOT_DIR}/image/image.cfg
IMG_NAME="${PACK_PLATFORM}_${PACK_BOARD}_${PACK_DEBUG}"
if [ "x${PACK_SIG}" != "xnone" ]; then
IMG_NAME="${IMG_NAME}_${PACK_SIG}"
fi
if [ "x${PACK_MODE}" = "xdump" -o "x${PACK_MODE}" = "xota_test" -o "x${PACK_MODE}" = "xcrashdump" ] ; then
IMG_NAME="${IMG_NAME}_${PACK_MODE}"
fi
if [ "x${PACK_FUNC}" = "xprvt" ] ; then
IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
fi
if [ "x${PACK_SECURE}" = "xsecure" ] ; then
IMG_NAME="${IMG_NAME}_${PACK_SECURE}"
fi
if [ "x${PACK_FUNC}" = "xprev_refurbish" ] ; then
IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
fi
IMG_NAME="${IMG_NAME}${IMG_FLASH}"
IMG_PROGRAMMER_NAME="${IMG_NAME}_programmer.img"
if [ "x${PACK_SECURE}" != "xnone" -o "x${PACK_SIG}" != "xnone" ]; then