-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnvmassfusegen.sh
More file actions
executable file
·1319 lines (1185 loc) · 31.3 KB
/
nvmassfusegen.sh
File metadata and controls
executable file
·1319 lines (1185 loc) · 31.3 KB
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
# Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
hdrsize=$((LINENO - 2));
hdrtxt=$(head -n ${hdrsize} "$0");
set -o pipefail;
set -o errtrace;
shopt -s extglob;
curdir=$(cd "$(dirname "$0")" && pwd);
nargs=$#;
ext_target_board=${!nargs};
if [ ! -r ${ext_target_board}.conf ]; then
echo "Error: Invalid target board - ${ext_target_board}.";
exit 1;
fi
LDK_DIR=$(readlink -f "${curdir}");
source ${ext_target_board}.conf;
BLDIRNAME="bootloader";
BLDIR="${LDK_DIR}/${BLDIRNAME}";
FUSECMD="fusecmd.sh";
MFGENCMD="mfgencmd.txt";
mfusedir="mfuse_${ext_target_board}";
mfusetmpdir="mfusetmp_${ext_target_board}";
FUSEBLOB="${curdir}/fuseblob.tbz2";
TARGET_DIR="${BLDIR}/${ext_target_board}";
KERNEL_DIR="${LDK_DIR}/kernel";
DTB_DIR="${KERNEL_DIR}/dtb";
export PATH="${LDK_DIR}/pkc:${KERNEL_DIR}:${PATH}";
gen_afuse_sh_v1()
{
local afuse_txt;
afuse_txt=`cat << EOF
usbarg="--instance \\\$1";
cidarg="--chip AFARG_CHIPID";
rcmarg="--rcm AFARG_RCMARG";
bctarg="--bct AFARG_BCTARG";
dlbctarg="--download bct AFARG_DLBCTARG";
wrbctarg="--write BCT AFARG_WRBCTARG";
ebtarg="--download ebt AFARG_EBTARG 0 0"; # type file [loadaddr entry]
rp1arg="--download rp1 AFARG_RP1ARG 0 0"; # type file [loadaddr entry]
pttarg="--pt AFARG_PTTARG.bin";
bfsarg="--updatebfsinfo AFARG_PTTARG.bin";
storagefile="\\\$\\\$_storage_info.bin";
fusecfgbin="AFARG_FUSECFGARG";
chkerr()
{
if [ \\\$? -ne 0 ]; then
echo "*** Error: \\\$1 failed.";
rm -f \\\${storagefile};
exit 1;
fi;
echo "*** \\\$1 succeeded.";
}
execmd ()
{
local banner="\\\$1";
local cmd="\\\$2";
local nochk="\\\$3";
echo; echo "*** \\\${banner}";
echo "\\\${cmd}";
if [ "\\\${nochk}" != "" ]; then
\\\${cmd};
return;
fi;
\\\${cmd};
chkerr "\\\${banner}";
}
curdir=\\\$(cd \\\`dirname \\\$0\\\` && pwd);
pushd \\\${curdir} > /dev/null 2>&1;
banner="Boot Rom communication";
cmd="\\\${curdir}/tegrarcm \\\${usbarg} \\\${cidarg} \\\${rcmarg}";
execmd "\\\${banner}" "\\\${cmd}";
banner="Blowing fuses";
cmd="\\\${curdir}/tegrarcm \\\${usbarg} --oem blowfuses \\\${fusecfgbin}";
execmd "\\\${banner}" "\\\${cmd}";
popd > /dev/null 2>&1;
exit 0;
EOF`;
echo "${hdrtxt}" > nvafuse.sh;
echo "${afuse_txt}" >> nvafuse.sh;
chmod +x nvafuse.sh;
local conv="";
conv+="-e s/AFARG_RCMARG/${rcmarg}/g ";
conv+="-e s/AFARG_BCTARG/${bctarg}/g ";
conv+="-e s/AFARG_DLBCTARG/${dlbctarg}/g ";
conv+="-e s/AFARG_WRBCTARG/${wrbctarg}/g ";
conv+="-e s/AFARG_EBTARG/${ebtarg}/g ";
conv+="-e s/AFARG_RP1ARG/${rp1arg}/g ";
conv+="-e s/AFARG_PTTARG/${pttarg}/g ";
conv+="-e s/AFARG_FUSECFGARG/${fusecfgbin}/g ";
if ! sed -i ${conv} nvafuse.sh; then
echo "Error: Setting up nvafuse.sh";
exit 1;
fi;
fc=$(cat nvafuse.sh | sed -e s/AFARG_CHIPID/"${cidarg}"/g);
echo "${fc}" > nvafuse.sh;
}
gen_afuse_sh_v2()
{
local afuse_txt;
afuse_txt=`cat << EOF
export PATH=".:${PATH}";
usbarg="--instance \\\$1";
cidarg="--chip AFARG_CHIPID";
rcmarg="--rcm AFARG_RCMARG";
rcmsfarg="AFARG_RCMSFARG";
pttarg="--pt AFARG_PTTARG.bin";
storagefile="storage_info.bin";
dlbrbctarg="--download bct_bootrom AFARG_DLBRBCTARG";
wrbrbctarg="--write BCT AFARG_WRBRBCTARG";
mb1bctarg="AFARG_DLMB1BCTARG";
dlmb1bctarg="--download bct_mb1 AFARG_DLMB1BCTARG";
wrmb1bctarg="--write MB1_BCT AFARG_WRMB1BCTARG";
wrmb1bctbarg="--write MB1_BCT_b AFARG_WRMB1BCTARG";
membctarg="AFARG_MEMBCTARG";
dlmembctarg="--download bct_mem AFARG_DLMEMBCTARG";
wrmembctarg="--write MEM_BCT AFARG_WRMEMBCTARG";
wrmembctbarg="--write MEM_BCT_b AFARG_WRMEMBCTARG";
memcbctarg="AFARG_MEMCBCTARG";
fusecfgbin="AFARG_FUSECFGARG";
fusedummy="AFARG_FUSEDUMMYARG";
chkerr()
{
if [ \\\$? -ne 0 ]; then
echo "*** Error: \\\$1 failed.";
exit 1;
fi;
echo "*** \\\$1 succeeded.";
}
execmd ()
{
local banner="\\\$1";
local cmd="\\\$2";
local nochk="\\\$3";
echo; echo "*** \\\${banner}";
echo "\\\${cmd}";
if [ "\\\${nochk}" != "" ]; then
\\\${cmd};
return;
fi;
\\\${cmd};
chkerr "\\\${banner}";
}
curdir=\\\$(cd \\\`dirname \\\$0\\\` && pwd);
pushd \\\${curdir} > /dev/null 2>&1;
banner="Boot Rom communication";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} \\\${cidarg} ";
if [ "\\\${rcmsfarg}" != "" ]; then
cmd+="--rcm \\\${rcmsfarg} ";
fi;
cmd+="\\\${rcmarg} ";
execmd "\\\${banner}" "\\\${cmd}";
banner="Checking applet";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} --isapplet";
execmd "\\\${banner}" "\\\${cmd}";
banner="Sending BCTs";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} \\\${dlbrbctarg} ";
if [ "\\\${mb1bctarg}" != "" ]; then
cmd+="\\\${dlmb1bctarg} ";
fi;
if [ "\\\${membctarg}" != "" ]; then
cmd+="\\\${dlmembctarg}";
fi;
execmd "\\\${banner}" "\\\${cmd}";
banner="Sending bootloader and pre-requisite binaries";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} --download blob blob.bin";
execmd "\\\${banner}" "\\\${cmd}";
banner="Booting Recovery";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} --boot recovery";
execmd "\\\${banner}" "\\\${cmd}";
banner="Checking applet";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} --isapplet";
execmd "\\\${banner}" "\\\${cmd}" "1";
sleep 3;
banner="Checking CPU bootloader";
cmd="\\\${curdir}/tegradevflash_v2 \\\${usbarg} --iscpubl";
execmd "\\\${banner}" "\\\${cmd}";
banner="Fusing the device";
cmd="\\\${curdir}/tegradevflash_v2 \\\${usbarg} --oem burnfuses \\\${fusedummy} \\\${fusecfgbin}";
execmd "\\\${banner}" "\\\${cmd}";
banner="Rebooting the device";
cmd="\\\${curdir}/tegradevflash_v2 \\\${usbarg} --reboot recovery";
execmd "\\\${banner}" "\\\${cmd}";
popd > /dev/null 2>&1;
exit 0;
EOF`;
echo "${hdrtxt}" > nvafuse.sh;
echo "${afuse_txt}" >> nvafuse.sh;
chmod +x nvafuse.sh;
local conv="";
conv+="-e s/AFARG_RCMSFARG/${rcmsfarg}/g ";
conv+="-e s/AFARG_RCMARG/${rcmarg}/g ";
conv+="-e s/AFARG_PTTARG/${pttarg}/g ";
conv+="-e s/AFARG_DLBRBCTARG/${dlbrbctarg}/g ";
conv+="-e s/AFARG_WRBRBCTARG/${dlbrbctarg}/g ";
conv+="-e s/AFARG_DLMB1BCTARG/${dlmb1bctarg}/g ";
conv+="-e s/AFARG_WRMB1BCTARG/${wrmb1bctarg}/g ";
conv+="-e s/AFARG_MEMBCTARG/${membctarg}/g ";
conv+="-e s/AFARG_DLMEMBCTARG/${dlmembctarg}/g ";
conv+="-e s/AFARG_WRMEMBCTARG/${wrmembctarg}/g ";
conv+="-e s/AFARG_MEMCBCTARG/${memcbctarg}/g ";
conv+="-e s/AFARG_FUSECFGARG/${fusecfgbin}/g ";
conv+="-e s/AFARG_FUSEDUMMYARG/${fusedummy}/g ";
if ! sed -i ${conv} nvafuse.sh; then
echo "Error: Setting up nvafuse.sh";
exit 1;
fi;
fc=$(cat nvafuse.sh | sed -e s/AFARG_CHIPID/"${cidarg}"/g);
echo "${fc}" > nvafuse.sh;
}
gen_afuse_sh_v3()
{
local afuse_txt;
afuse_txt=`cat << EOF
export PATH=".:${PATH}";
usbarg="--instance \\\$1";
cidarg="--chip AFARG_CHIPID";
rcmarg="--download mb1 AFARG_RCMARG";
rcmsfarg="AFARG_RCMSFARG";
pttarg="--pt AFARG_PTTARG.bin";
storagefile="storage_info.bin";
dlbrbctarg="--download bct_br AFARG_DLBRBCTARG";
wrbrbctarg="--write BCT AFARG_WRBRBCTARG";
mb1bctarg="AFARG_DLMB1BCTARG";
dlmb1bctarg="--download bct_mb1 AFARG_DLMB1BCTARG";
wrmb1bctarg="--write MB1_BCT AFARG_WRMB1BCTARG";
wrmb1bctbarg="--write MB1_BCT_b AFARG_WRMB1BCTARG";
membctarg="AFARG_MEMBCTARG";
dlmembctarg="--download bct_mem AFARG_DLMEMBCTARG";
wrmembctarg="--write MEM_BCT AFARG_WRMEMBCTARG";
wrmembctbarg="--write MEM_BCT_b AFARG_WRMEMBCTARG";
memcbctarg="AFARG_MEMCBCTARG";
fusecfgbin="AFARG_FUSECFGARG";
fusedummy="AFARG_FUSEDUMMYARG";
dlbl1pscarg="--download psc_bl1 AFARG_PSCBL1";
chkerr()
{
if [ \\\$? -ne 0 ]; then
echo "*** Error: \\\$1 failed.";
exit 1;
fi;
echo "*** \\\$1 succeeded.";
}
execmd ()
{
local banner="\\\$1";
local cmd="\\\$2";
local nochk="\\\$3";
echo; echo "*** \\\${banner}";
echo "\\\${cmd}";
if [ "\\\${nochk}" != "" ]; then
\\\${cmd};
return;
fi;
\\\${cmd};
chkerr "\\\${banner}";
}
curdir=\\\$(cd \\\`dirname \\\$0\\\` && pwd);
pushd \\\${curdir} > /dev/null 2>&1;
banner="Boot Rom communication";
cmd="\\\${curdir}/tegrarcm_v2 --new_session \\\${usbarg} \\\${cidarg} --uid ";
cmd+="\\\${dlbrbctarg} \\\${rcmarg} \\\${dlbl1pscarg} \\\${dlmb1bctarg}";
execmd "\\\${banner}" "\\\${cmd}";
banner="Sending membct and RCM blob";
cmd="\\\${curdir}/tegrarcm_v2 \\\${usbarg} \\\${cidarg} --pollbl ";
cmd+="\\\${dlmembctarg} "
cmd+="--download blob blob.bin ";
execmd "\\\${banner}" "\\\${cmd}";
popd > /dev/null 2>&1;
exit 0;
EOF`;
echo "${hdrtxt}" > nvafuse.sh;
echo "${afuse_txt}" >> nvafuse.sh;
chmod +x nvafuse.sh;
local conv="";
conv+="-e s/AFARG_RCMSFARG/${rcmsfarg}/g ";
conv+="-e s/AFARG_RCMARG/${rcmarg}/g ";
conv+="-e s/AFARG_PTTARG/${pttarg}/g ";
conv+="-e s/AFARG_DLBRBCTARG/${dlbrbctarg}/g ";
conv+="-e s/AFARG_WRBRBCTARG/${dlbrbctarg}/g ";
conv+="-e s/AFARG_DLMB1BCTARG/${dlmb1bctarg}/g ";
conv+="-e s/AFARG_WRMB1BCTARG/${wrmb1bctarg}/g ";
conv+="-e s/AFARG_MEMBCTARG/${membctarg}/g ";
conv+="-e s/AFARG_DLMEMBCTARG/${dlmembctarg}/g ";
conv+="-e s/AFARG_WRMEMBCTARG/${wrmembctarg}/g ";
conv+="-e s/AFARG_MEMCBCTARG/${memcbctarg}/g ";
conv+="-e s/AFARG_FUSECFGARG/${fusecfgbin}/g ";
conv+="-e s/AFARG_FUSEDUMMYARG/${fusedummy}/g ";
conv+="-e s/AFARG_PSCBL1/${pscbl1arg}/g ";
if ! sed -i ${conv} nvafuse.sh; then
echo "Error: Setting up nvafuse.sh";
exit 1;
fi;
fc=$(cat nvafuse.sh | sed -e s/AFARG_CHIPID/"${cidarg}"/g);
echo "${fc}" > nvafuse.sh;
}
gen_afuse_sh()
{
local tfv=$1;
case ${tfv} in
1) gen_afuse_sh_v1; ;;
2) if [ "${CHIPID}" = "0x23" ]; then
gen_afuse_sh_v3;
else
gen_afuse_sh_v2;
fi;
;;
*) echo "Error: Unknown tegraflash version"; exit 1; ;;
esac;
}
gen_mfuse_sh()
{
local mfuse_txt;
mfuse_txt=`cat << EOF
curdir=\\\$(cd \\\`dirname \\\$0\\\` && pwd);
showlogs=0;
if [ "\\\$1" = "--showlogs" ]; then
showlogs=1;
fi;
# Find devices to fuse
devpaths=(\\\$(find /sys/bus/usb/devices/usb*/ \\\\
-name devnum -print0 | {
found=()
while read -r -d "" fn_devnum; do
dir="\\\$(dirname "\\\${fn_devnum}")"
vendor="\\\$(cat "\\\${dir}/idVendor")"
if [ "\\\${vendor}" != "0955" ]; then
continue
fi
product="\\\$(cat "\\\${dir}/idProduct")"
case "\\\${product}" in
"7023") ;;
"7721") ;;
"7f21") ;;
"7018") ;;
"7c18") ;;
"7121") ;;
"7019") ;;
"7819") ;;
"7e19") ;;
"7418") ;;
*)
continue
;;
esac
fn_busnum="\\\${dir}/busnum"
if [ ! -f "\\\${fn_busnum}" ]; then
continue
fi
fn_devpath="\\\${dir}/devpath"
if [ ! -f "\\\${fn_devpath}" ]; then
continue
fi
busnum="\\\$(cat "\\\${fn_busnum}")"
devpath="\\\$(cat "\\\${fn_devpath}")"
found+=("\\\${busnum}-\\\${devpath}")
done
echo "\\\${found[@]}"
}))
# Exit if no devices to fuse
if [ \\\${#devpaths[@]} -eq 0 ]; then
echo "No devices to fuse"
exit 1
fi
# Create a folder for saving log
mkdir -p mfuselogs;
pid="\\\$\\\$"
ts=\\\`date +%Y%m%d-%H%M%S\\\`;
# Fuse burning all devices in background
fuse_pids=()
for devpath in "\\\${devpaths[@]}"; do
fn_log="mfuselogs/\\\${ts}_\\\${pid}_fuse_\\\${devpath}.log"
cmd="\\\${curdir}/nvafuse.sh \\\${devpath}";
\\\${cmd} > "\\\${fn_log}" 2>&1 &
fuse_pid="\\\$!";
fuse_pids+=("\\\${fuse_pid}")
echo "Start fusing device: \\\${devpath}, PID: \\\${fuse_pid}";
if [ \\\${showlogs} -eq 1 ]; then
gnome-terminal -e "tail -f \\\${fn_log}" -t \\\${fn_log} > /dev/null 2>&1 &
fi;
done
# Wait until all fuse processes done
failure=0
while true; do
running=0
if [ \\\${showlogs} -ne 1 ]; then
echo -n "Ongoing processes:"
fi;
new_fuse_pids=()
for fuse_pid in "\\\${fuse_pids[@]}"; do
if [ -e "/proc/\\\${fuse_pid}" ]; then
if [ \\\${showlogs} -ne 1 ]; then
echo -n " \\\${fuse_pid}"
fi;
running=\\\$((\\\${running} + 1))
new_fuse_pids+=("\\\${fuse_pid}")
else
wait "\\\${fuse_pid}" || failure=1
fi
done
if [ \\\${showlogs} -ne 1 ]; then
echo
fi;
if [ \\\${running} -eq 0 ]; then
break
fi
fuse_pids=("\\\${new_fuse_pids[@]}")
sleep 5
done
if [ \\\${failure} -ne 0 ]; then
echo "Fuse burn complete (WITH FAILURES)";
exit 1
fi
echo "Fuse burn complete (SUCCESS)"
EOF`;
echo "${hdrtxt}" > nvmfuse.sh;
echo "${mfuse_txt}" >> nvmfuse.sh;
chmod +x nvmfuse.sh;
}
getidx()
{
local i;
local f;
local s;
local a;
f="$1";
s="$2";
shift; shift;
a=($@);
for (( i=0; i<${#a[@]}; i++ )); do
if [ "$f" != "${a[$i]}" ]; then
continue;
fi;
i=$(( i+1 ));
if [ "${s}" != "" ]; then
if [ "$s" != "${a[$i]}" ]; then
continue;
fi;
i=$(( i+1 ));
fi;
return $i;
done;
echo "Error: $f $s not found";
exit 1;
}
chkidx()
{
local i;
local f;
local a;
f="$1";
shift;
a=($@);
for (( i=0; i<${#a[@]}; i++ )); do
if [ "$f" != "${a[$i]}" ]; then
continue;
fi;
return 0;
done;
return 1;
}
chext ()
{
local i;
local var;
local fname;
local OIFS;
local na;
local nasize;
var="$1";
fname=$(basename "$2");
OIFS=${IFS};
IFS='.';
na=($fname);
IFS=${OIFS};
nasize=${#na[@]};
if [ ${nasize} -lt 2 ]; then
echo "Error: invalid file name: ${fname}";
exit 1;
fi;
na[$((nasize-1))]=${3};
local newname="";
for (( i=0; i < nasize; i++ )); do
newname+="${na[$i]}";
if [ $i -lt $((nasize-1)) ]; then
newname+=".";
fi;
done;
eval "${var}=${newname}";
}
gen_param()
{
local tf_v;
local len;
local binsidx;
local a;
local OIFS;
tf_v=1;
a=$(echo "$1" | sed -e s/\"//g -e s/\;//g);
OIFS=${IFS};
IFS=' ';
a=($a);
IFS=$OIFS;
blobxmltxt="";
if chkidx "--bl" "${a[@]}"; then
getidx "--bl" "" "${a[@]}";
ebtarg="${a[$?]}";
fi;
getidx "--chip" "" "${a[@]}";
cidarg="${a[$?]}";
len=$(expr length "${cidarg}");
if [ ${len} -le 4 ]; then
tgid="${cidarg}";
if [ "${CHIPMAJOR}" != "" ]; then
cidarg="${cidarg} ${CHIPMAJOR}";
else
local addchipmajor="true";
local relfile="${LDK_DIR}/rootfs/etc/nv_tegra_release";
if [ -f "${relfile}" ]; then
rel=$(head -n 1 "${relfile}");
rel=$(echo "${rel}" | awk -F ' ' '{print $2}');
if [ "${rel}" \< "R32" ]; then
addchipmajor="false";
fi;
fi;
if [ "${addchipmajor}" = "true" ]; then
cidarg="${cidarg} 0";
fi;
fi;
else
tgid=$(echo "${cidarg}" | awk -F ' ' '{print $1}');
fi;
tf_v=2;
getidx "--applet" "" "${a[@]}";
rcmarg="${a[$?]}";
aplarg="${rcmarg}";
if [ "${rcmarg}" = "nvtboot_recovery.bin" ] || \
[ "${rcmarg}" = "mb1_recovery_prod.bin" ] || \
[ "${rcmarg}" = "mb1_t194_prod.bin" ]; then
rcmarg="rcm_list_signed.xml";
fi;
if chkidx "--cfg" "${a[@]}"; then
getidx "--cfg" "" "${a[@]}";
pttarg="${a[$?]}";
fi;
if chkidx "--bins" "${a[@]}"; then
getidx "--bins" "" "${a[@]}";
binsidx=$?;
else
if chkidx "--bin" "${a[@]}"; then
getidx "--bin" "" "${a[@]}";
binsidx=$?;
fi;
fi;
if [ ${tf_v} -eq 1 ]; then
# Tegraflash V1
getidx "blowfuses" "" "${a[@]}";
fusecfg="${a[$?]}";
chext fusecfgbin "${fusecfg}" "bin";
return ${tf_v};
fi;
# Tegraflash V2
# BCT params
if chkidx "--bct" "${a[@]}"; then
getidx "--bct" "" "${a[@]}";
bctarg="${a[$?]}";
dlbrbctarg="${bctarg}";
else
dlbrbctarg="br_bct_BR.bct";
fi;
wrbrbctarg="${dlbrbctarg}";
if chkidx "--applet_softfuse" "${a[@]}"; then
getidx "--applet_softfuse" "" "${a[@]}";
rcmsfarg="${a[$?]}";
fi;
if chkidx "--mb1_bct" "${a[@]}"; then
getidx "--mb1_bct" "" "${a[@]}";
mb1bctarg="${a[$?]}";
dlmb1bctarg="${mb1bctarg}";
else
dlmb1bctarg="mb1_bct_MB1_sigheader.bct";
if chkidx "--key" "${a[@]}"; then
dlmb1bctarg+=".signed";
else
dlmb1bctarg+=".encrypt";
fi;
fi;
if chkidx "--mb1_cold_boot_bct" "${a[@]}"; then
getidx "--mb1_cold_boot_bct" "" "${a[@]}";
mb1cbctarg="${a[$?]}";
wrmb1bctarg="${mb1cbctarg}";
else
wrmb1bctarg="mb1_cold_boot_bct_MB1_sigheader.bct";
wrmb1bctarg+=".encrypt";
fi;
if [ "${tgid}" = "0x19" ]; then
if chkidx "--mem_bct" "${a[@]}"; then
getidx "--mem_bct" "" "${a[@]}";
membctarg="${a[$?]}";
dlmembctarg="${membctarg}";
else
dlmembctarg="mem_rcm_sigheader.bct";
dlmembctarg+=".encrypt";
if [ "${tgid}" = "0x19" ]; then
membctarg="${dlmembctarg}";
fi;
fi;
if chkidx "--mem_bct_cold_boot" "${a[@]}"; then
getidx "--mem_bct_cold_boot" "" "${a[@]}";
memcbctarg="${a[$?]}";
wrmembctarg="${memcbctarg}";
else
wrmembctarg="mem_coldboot_sigheader.bct";
wrmembctarg+=".encrypt";
fi;
fi;
if chkidx "blowfuses" "${a[@]}"; then
getidx "blowfuses" "" "${a[@]}";
fusecfg="${a[$?]}";
else
if chkidx "burnfuses" "${a[@]}"; then
getidx "burnfuses" "" "${a[@]}";
idx=$?;
fusecfg="${a[${idx}]}";
if [ "${fusecfg}" = "dummy" ]; then
idx=$((idx + 1));
fusecfg="${a[${idx}]}";
fusedummy="dummy";
fi;
chext fusecfgbin "${fusecfg}" "bin";
fi;
fi;
# Tegraflash V3
# Hidden file in image lists:
if [ "${CHIPID}" = "0x23" ]; then
rcmarg="mb1_t234_prod_aligned_sigheader.bin.encrypt";
pscbl1arg=psc_bl1_t234_prod_aligned_sigheader.bin.encrypt;
dlmembctarg="mem_rcm_sigheader.bct.encrypt";
fi;
# BIN params
echo "Generating blob";
blobxmltxt+="<file_list mode=\"blob\">";
blobxmltxt+="<!--Auto generated by tegraflash.py-->";
blobfiles="";
# The first entry is EBT binary.
if [ "${bctarg}" != "" ] && [ "${mb1bctarg}" != "" ]; then
blobxmltxt+="<file name=\"";
blobxmltxt+="${ebtarg}\" ";
blobfiles+="${ebtarg} ";
blobxmltxt+="type=\"bootloader\" />";
for (( i=binsidx; i<${#a[@]}; i++ )); do
if [[ ${a[$i]} =~ ^\-\- ]]; then
break;
fi;
blobxmltxt+="<file name=\"";
blobxmltxt+="${a[$((i+1))]}\" ";
blobfiles+="${a[$((i+1))]} ";
blobxmltxt+="type=\"${a[$i]}\" />";
i=$((i+1));
done;
elif [ "${CHIPID}" = "0x23" ]; then
local binsimg_23=("dce_fw" "mts_mce" "mb2_bootloader" "fusebypass" "mb2_applet" "bootloader_dtb" "spe_fw" "bpmp_fw" "bpmp_fw_dtb" "psc_fw" "tos" "eks" "sce_fw" "ape_fw" "tsec_fw" "nvdec" "xusb_fw" "rce_fw" "fsi_fw" "fskp_bin" "bpmp_ist" "ccplex_ist" "ist_ucode");
local na;
local suf;
na=$(echo "${ebtarg}" | cut -d'.' -f1);
suf=$(echo "${ebtarg}" | cut -d'.' -f2);
bn="${na}_sigheader.${suf}.encrypt";
blobfiles+="${bn} ";
blobxmltxt+="<file type=\"bootloader\" ";
blobxmltxt+="name=\"${bn}\" />";
for (( i=0; i<${#binsimg_23[@]}; i++ )); do
if ! chkidx "${binsimg_23[$i]}" "${a[@]}"; then
continue;
fi;
getidx "${binsimg_23[$i]}" "" "${a[@]}";
idx=$?;
binsfilename="${a[${idx}]}";
na=$(echo "${binsfilename}" | cut -d'.' -f1);
suf=$(echo "${binsfilename}" | cut -d'.' -f2);
if [ "${binsimg_23[$i]}" = "mb2_bootloader" ]; then
bn="${na}_with_mb2_bct_MB2_aligned_sigheader.${suf}.encrypt";
elif [ "${binsimg_23[$i]}" = "dce_fw" ]; then
# 1. Concatenate kernel dtb to dce_fw
# 2. Change dec_fw name
#
# dce_bin = display-t234-dce.bin
# kernel_dtb = kernel_tegra234-p3701-0000-p3737-0000.dtb
# dce_with_dtb = display-t234-dce_with_kernel_tegra234-p3701-0000-p3737-0000.bin
if ! chkidx "kernel_dtb" "${a[@]}"; then
echo "Error: Could not find kernel dtb";
exit 1;
fi;
getidx "kernel_dtb" "" "${a[@]}";
j=$?;
bn="${na}_with_${a[$j]}_sigheader.${suf}.encrypt";
cp -f "${binsfilename}" "${bn}";
cat "${a[$j]}" >> "${bn}";
elif [ "${binsimg_23[$i]}" = "bpmp_fw_dtb" ]; then
bn="${na}_with_odm_sigheader.${suf}.encrypt";
else
bn="${na}_sigheader.${suf}.encrypt";
fi;
# Sign a bins file.
blobfiles+="${bn} ";
blobxmltxt+="<file type=\"${binsimg_23[$i]}\" ";
blobxmltxt+="name=\"${bn}\" />";
done;
else
local na;
local suf;
na="$(echo "${ebtarg}" | cut -d'.' -f1)";
suf="$(echo "${ebtarg}" | cut -d'.' -f2)";
blobxmltxt+="<file name=\"";
blobxmltxt+="${na}_sigheader.${suf}.encrypt\" ";
blobfiles+="${na}_sigheader.${suf}.encrypt ";
blobxmltxt+="type=\"bootloader\" />";
for (( i=binsidx; i<${#a[@]}; i++ )); do
if [[ ${a[$i]} =~ ^\-\- ]]; then
break;
fi;
if [ "${a[$i]}" = "kernel" ] || \
[ "${a[$i]}" = "kernel_dtb" ]; then
i=$((i+1));
continue;
fi;
na=$(echo "${a[$((i+1))]}" | cut -d'.' -f1);
suf=$(echo "${a[$((i+1))]}" | cut -d'.' -f2);
bn="${na}_sigheader.${suf}.encrypt";
blobfiles+="${bn} ";
blobxmltxt+="<file type=\"${a[$i]}\" ";
blobxmltxt+="name=\"${bn}\" />";
i=$((i+1));
done;
fi;
blobxmltxt+="</file_list>";
return ${tf_v};
}
findadev()
{
local devpaths;
devpaths=($(find /sys/bus/usb/devices/usb*/ -name devnum -print0 | {
local fn_devnum;
local found=();
while read -r -d "" fn_devnum; do
local dir;
local vendor;
dir="$(dirname "${fn_devnum}")";
vendor="$(cat "${dir}/idVendor")";
if [ "${vendor}" != "0955" ]; then
continue
fi;
local product;
product="$(cat "${dir}/idProduct")";
case "${product}" in
"7023") ;;
"7721") ;;
"7f21") ;;
"7018") ;;
"7c18") ;;
"7121") ;;
"7019") ;;
"7819") ;;
"7e19") ;;
"7418") ;;
*) continue ;;
esac
local fn_busnum;
fn_busnum="${dir}/busnum";
if [ ! -f "${fn_busnum}" ]; then
continue;
fi;
local fn_devpath;
fn_devpath="${dir}/devpath";
if [ ! -f "${fn_devpath}" ]; then
continue;
fi;
local busnum;
local devpath;
busnum="$(cat "${fn_busnum}")";
devpath="$(cat "${fn_devpath}")";
found+=("${busnum}-${devpath}");
done;
echo "${found[@]}";
}))
echo "${#devpaths[@]} Jetson devices in RCM mode. USB: ${devpaths[@]}";
return "${#devpaths[@]}";
}
chkerr()
{
if [ $? -ne 0 ]; then
echo "*** Error: $1 failed.";
rm -f "${storagefile}";
exit 1;
fi;
echo "*** $1 succeeded.";
}
execmd ()
{
local banner="$1";
local cmd="$2";
local nochk="$3";
echo; echo "*** ${banner}";
echo "${cmd}";
if [ "${nochk}" != "" ]; then
${cmd};
return;
fi;
${cmd};
chkerr "${banner}";
}
create_signdir_v1 ()
{
local i;
local v;
local f;
local cmd;
local l=(\
"aplarg" \
"fusecfg" \
);
local a=(\
"tegraparser" \
"tegrarcm" \
"tegrasign" \
);
if [ "$1" = "" ]; then
echo "Error: Null sign directory name.";
exit 1;
fi;
rm -rf "$1";
mkdir "$1";
pushd "$1" > /dev/null 2>&1 || exit 1;
for (( i=0; i<${#l[@]}; i++ )); do
v=${l[$i]};
if [ ! -f "../${!v}" ]; then
echo "Error: ../${!v} does not exist";
exit 1;
fi;
echo -n "copying ${!v} ... ";
if cp -f "../${!v}" .; then
echo "succeeded."
else
echo "failed."
exit 1;
fi;
done;
for (( i=0; i<${#a[@]}; i++ )); do
if [ -f "${a[$i]}" ]; then
continue;
fi;
if [ ! -f "../${a[$i]}" ]; then
echo "Error: ${a[$i]} does not exist.";
exit 1;
fi;
echo -n "copying ${a[$i]} ... ";
if cp "../${a[$i]}" .; then
echo "succeeded."
else
echo "failed."
exit 1;
fi;
done;
banner="Parsing fuse info as per xml file";
cmd="./tegraparser --fuse_info ${fusecfg} ${fusecfgbin}";
execmd "${banner}" "${cmd}";
banner="Generating RCM messages";
cmd="./tegrarcm --listrcm rcm_list.xml ";
cmd+="--chip ${cidarg} ";
cmd+="--download rcm ${aplarg} 0 0";
execmd "${banner}" "${cmd}"; # Generates rcm_list.xml, rcm_?.rcm
banner="Signing RCM messages";
cmd="./tegrasign --key None --list rcm_list.xml ";
cmd+="--pubkeyhash pub_key.key";
execmd "${banner}" "${cmd}"; # Generates rcm_list_signed.xml
banner="Copying signature to RCM messages";
cmd="./tegrarcm --chip ${cidarg} ";
cmd+="--updatesig rcm_list_signed.xml ";
execmd "${banner}" "${cmd}"; # Updates signatures in rcm_?.rcm files
popd > /dev/null 2>&1 || exit 1;
}
fill_mfusetmpdir ()
{
local i;
local l;
local tf_v1=(\
"nvmfuse.sh" \
"nvafuse.sh" \
);