forked from renesas-rz/rza_linux-4.19_bsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·1329 lines (1139 loc) · 39.2 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Function: usage
function usage {
echo -ne "\033[1;31m" # RED TEXT
echo -e "\nWhat do you want to build?"
echo -ne "\033[00m" # END TEXT COLOR
echo -e " ./build.sh config : Target Board Selection ($BOARD)"
echo -e ""
echo -e " ./build.sh buildroot : Builds Root File System (and installs toolchain)"
echo -e " ./build.sh u-boot : Builds u-boot"
echo -e " ./build.sh kernel : Builds Linux kernel. Default is to build uImage"
echo -e " ./build.sh axfs : Builds an AXFS image"
echo -e ""
echo -e " ./build.sh env : Set up the Build environment so you can run 'make' directly"
echo -e ""
echo -e " ./build.sh jlink : Download a binary image to RAM so you can program it into QSPI"
echo -e ""
echo -e " You may also do things like:"
echo -e " ./build.sh kernel menuconfig : Open the kernel config GUI to enable options/drivers"
echo -e " ./build.sh kernel rskrza1_xip_defconfig : Switch to XIP version of the kernel"
echo -e " ./build.sh kernel xipImage : Build the XIP kernel image"
echo -e " ./build.sh buildroot menuconfig : Open the Buildroot config GUI to select additinal apps to build"
echo -e ""
echo -e " Current Target: $BOARD"
echo -e ""
}
# Function: banner_color
function banner_yellow {
echo -ne "\033[1;33m" # YELLOW TEXT
echo "============== $1 =============="
echo -ne "\033[00m"
}
function banner_red {
echo -ne "\033[1;31m" # RED TEXT
echo "============== $1 =============="
echo -ne "\033[00m"
}
function banner_green {
echo -ne "\033[1;32m" # GREEN TEXT
echo "============== $1 =============="
echo -ne "\033[00m"
}
##### Check for required Host packages #####
MISSING_A_PACKAGE=0
PACAKGE_LIST=(git make gcc g++ python bison flex)
for i in 0 1 2 3 4 5 6; do
CHECK=$(which ${PACAKGE_LIST[$i]})
if [ "$CHECK" == "" ] ; then
echo "ERROR: Missing host package: ${PACAKGE_LIST[$i]}"
MISSING_A_PACKAGE=1
fi
done
CHECK=$(dpkg -l 'libncurses5-dev' | grep '^ii')
if [ "$CHECK" == "" ] ; then
MISSING_A_PACKAGE=1
fi
if [ "$MISSING_A_PACKAGE" != "0" ] ; then
banner_red "Missing mandatory host packages"
echo "Please make sure the following packages are installed on your machine."
echo " git"
echo " make"
echo " gcc"
echo " g++"
echo " libncurses5-dev libncursesw5-dev"
echo " python"
echo " bison"
echo " flex"
echo ""
echo "The following command line will ensure all packages are installed."
echo ""
echo " sudo apt-get install git make gcc g++ libncurses5-dev libncursesw5-dev python bison flex"
echo ""
exit 1
fi
##### Check if toolchain is installed correctly #####
function check_for_toolchain {
CHECK=$(which ${CROSS_COMPILE}gcc)
if [ "$CHECK" == "" ] ; then
# Toolchain was found in path, so maybe it was hard coded in setup_env.sh
return
fi
if [ ! -e $OUTDIR/br_version.txt ] ; then
banner_red "Toolchain not installed yet."
echo -e "Buildroot will download and install the toolchain."
echo -e "Plesae run \"./build.sh buildroot\" first and select the toolchain you would like to use."
exit 1
fi
}
# Save current config settings to file
function save_config {
echo "BOARD=$BOARD" > output/config.txt
echo "SOC=$SOC" >> output/config.txt
echo "DLRAM_ADDR=$DLRAM_ADDR" >> output/config.txt
echo "UBOOT_ADDR=$UBOOT_ADDR" >> output/config.txt
echo "DTB_ADDR=$DTB_ADDR" >> output/config.txt
echo "KERNEL_ADDR=$KERNEL_ADDR" >> output/config.txt
echo "ROOTFS_ADDR=$ROOTFS_ADDR" >> output/config.txt
echo "QSPI=$QSPI" >> output/config.txt
}
# Set environment to a different board configuration
# Set NEW_BOARD before calling
function change_config {
BOARD=${NEW_BOARD}
BRD_SOC_xxxx=BRD_SOC_${NEW_BOARD}
eval SOC=$(eval echo \${$BRD_SOC_xxxx})
BRD_DLRAM_xxxx=BRD_DLRAM_${NEW_BOARD}
eval DLRAM_ADDR=$(eval echo \${$BRD_DLRAM_xxxx})
BRD_DLRAMSZ_xxxx=BRD_DLRAMSZ_${NEW_BOARD}
eval DLRAM_SZ=$(eval echo \${$BRD_DLRAMSZ_xxxx})
BRD_UBOOT_xxxx=BRD_UBOOT_${NEW_BOARD}
eval UBOOT_ADDR=$(eval echo \${$BRD_UBOOT_xxxx})
BRD_DTB_xxxx=BRD_DTB_${NEW_BOARD}
eval DTB_ADDR=$(eval echo \${$BRD_DTB_xxxx})
BRD_KERNEL_xxxx=BRD_KERNEL_${NEW_BOARD}
eval KERNEL_ADDR=$(eval echo \${$BRD_KERNEL_xxxx})
BRD_ROOTFS_xxxx=BRD_ROOTFS_${NEW_BOARD}
eval ROOTFS_ADDR=$(eval echo \${$BRD_ROOTFS_xxxx})
BRD_QSPI_xxxx=BRD_QSPI_${NEW_BOARD}
eval QSPI=$(eval echo \${$BRD_QSPI_xxxx})
# for debugging only
#echo "BOARD = $BOARD"
#echo "SOC = $SOC"
#echo "DLRAM_ADDR = $DLRAM_ADDR"
#echo "DLRAM_SZ = $DLRAM_SZ"
#echo "UBOOT_ADDR = $UBOOT_ADDR"
#echo "DTB_ADDR = $DTB_ADDR"
#echo "KERNEL_ADDR = $KERNEL_ADDR"
#echo "ROOTFS_ADDR = $ROOTFS_ADDR"
#echo "QSPI = $QSPI"
}
###############################################################################
# script start
###############################################################################
# Save current directory
ROOTDIR=`pwd`
#Defaults (for RZ/A1 RSK)
BOARD=rskrza1
SOC=RZA1H
DLRAM_ADDR=0x08000000
DLRAM_SZ=0x2000000
UBOOT_ADDR=0x18000000
DTB_ADDR=0x180C0000
KERNEL_ADDR=0x18200000
ROOTFS_ADDR=0x18800000
QSPI=DUAL
# Create output build directory
if [ ! -e output ] ; then
mkdir -p output
fi
# Create config.txt file, or read in current settings
if [ ! -e output/config.txt ] ; then
save_config
else
source output/config.txt
fi
# Check command line
if [ "$1" == "" ] ; then
usage
exit 0
fi
# Run build environment setup
if [ "$ENV_SET" != "1" ] ; then
# Because we are using 'source', ROOTDIR can be seen in setup_env.sh
source ./setup_env.sh
fi
# Find out how many CPU processor cores we have on this machine
# so we can build faster by using multi-threaded builds
NPROC=2
if [ "$(which nproc)" != "" ] ; then # make sure nproc is installed
NPROC=$(nproc)
fi
BUILD_THREADS=$(expr $NPROC + $NPROC)
###############################################################################
# config
###############################################################################
if [ "$1" == "config" ] ; then
# read in our list of boards
source boards_renesas.txt
source boards_custom.txt
# make a list of all boards
ALL_BOARDS="$RENESAS_BOARDS $CUSTOM_BOARDS"
# save the current board so can know the user selected a new one
ORIGINAL_BOARD=$BOARD
# Check if a board name was passed on the command line
if [ "$2" != "" ] ; then
# If a board name was passed, make sure it is in the list
FOUND=0
for i in `echo $ALL_BOARDS` ; do
if [ "$2" == "$i" ] ; then
FOUND=1
break
fi
done
if [ "$FOUND" == "0" ] ; then
banner_red "ERROR: Board name not found"
echo -e "Please select one of the following boards: $ALL_BOARDS\n"
exit -1
fi
NEW_BOARD=$2
change_config
save_config
# If our board selection has changed, then delete the .config files
# for u-boot and kernel which will force a new defconfig
if [ "$ORIGINAL_BOARD" != "$BOARD" ] ; then
if [ -e $OUTDIR/u-boot-2017.05/.config ] ; then
rm $OUTDIR/u-boot-2017.05/.config
fi
if [ -e $OUTDIR/linux-4.19/.config ] ; then
rm $OUTDIR/linux-4.19/.config
fi
fi
banner_green "BSP configured for $BOARD"
exit 0
fi
while [ "1" == "1" ]
do
CURRENT_DESC="error"
# What is the current selected board?
for i in `echo $ALL_BOARDS` ; do
if [ "$BOARD" == "$i" ] ; then
BRD_DESC_xxxx=BRD_DESC_${i}
CURRENT_DESC=$(eval echo \${$BRD_DESC_xxxx})
break
fi
done
# show the main selection menu
whiptail --title "Build Environment Setup" --noitem --menu "Make changes the items below as needed.\nYou may use ESC+ESC to cancel." 0 0 0 \
" Target Board: $BOARD [$CURRENT_DESC]" "" \
" Device: $SOC" "" \
" RAM addr: $DLRAM_ADDR" "" \
" u-boot addr: $UBOOT_ADDR" "" \
" DTB addr: $DTB_ADDR" "" \
" kernel addr: $KERNEL_ADDR" "" \
" rootfs addr: $ROOTFS_ADDR" "" \
" QSPI: $QSPI" "" \
"Save" "" 2> /tmp/answer.txt
#ans=$(head -c 3 /tmp/answer.txt)
ans=$(cat /tmp/answer.txt)
if [ "$ans" == "" ]; then
break;
fi
if [ "$(grep "Target Board" /tmp/answer.txt)" != "" ] ; then
WT_TEXT="whiptail --title \"Build Environment Setup\" --menu \
\"Please select the board you want to build for.\n\"\
\"If you have your own custom board, please manually edit\n\"\
\"file [boards_custom.txt] and then your board will show up\n\"\
\"in this menu.\n\"\
0 0 40 "
# add boards to menu
for i in `echo $ALL_BOARDS` ; do
BRD_DESC_xxxx=BRD_DESC_${i}
CURRENT_DESC=$(eval echo \${$BRD_DESC_xxxx})
WT_TEXT="$WT_TEXT \"$i\" \"$CURRENT_DESC\" "
done
# Display menu
eval $WT_TEXT 2> /tmp/answer.txt
ans=$(cat /tmp/answer.txt)
# No selection (cancel)
if [ "$ans" == "" ] ; then
continue
fi
NEW_BOARD=${ans}
change_config
continue
fi # (answer = Target Board)
if [ "$(grep "Save" /tmp/answer.txt)" != "" ] ; then
save_config
# If our board selection has changed, then delete the .config files
# for u-boot and kernel which will force a new defconfig
if [ "$ORIGINAL_BOARD" != "$BOARD" ] ; then
if [ -e $OUTDIR/u-boot-2017.05/.config ] ; then
rm $OUTDIR/u-boot-2017.05/.config
fi
if [ -e $OUTDIR/linux-4.19/.config ] ; then
rm $OUTDIR/linux-4.19/.config
fi
fi
break;
fi # (answer = Save)
done # (while loop)
exit 0
fi
###############################################################################
# env
###############################################################################
if [ "$1" == "env" ] ; then
check_for_toolchain
echo "Copy/paste this line and execute it in your command window."
echo ""
echo 'export ROOTDIR=$(pwd) ; source ./setup_env.sh'
echo ""
echo "Then, you can execute 'make' directly in u-boot, linux, buildroot, etc..."
exit 0
fi
###############################################################################
# jlink
###############################################################################
if [ "$1" == "jlink" ] ; then
echo "-------------------------------------------------------"
echo "Download binary files to on-board RAM or SPI Flash"
echo "-------------------------------------------------------"
FILE1=output/u-boot-2017.05/u-boot.bin
if [ "$SOC" != "RZA2M" ] ; then
FILE2=output/linux-4.19/arch/arm/boot/dts/r7s72100-$BOARD.dtb
else
FILE2=output/linux-4.19/arch/arm/boot/dts/r7s9210-$BOARD.dtb
fi
FILE3=output/linux-4.19/arch/arm/boot/uImage
FILE4=output/linux-4.19/arch/arm/boot/xipImage
FILE5=output/buildroot-$BR_VERSION/output/images/rootfs.squashfs
FILE6=output/buildroot-$BR_VERSION/output/images/rootfs.axfs
FILE7=output/buildroot-$BR_VERSION/output/images/rootfs.cramfs
FILE8=output/axfs/rootfs.axfs.bin
if [ "$2" == "" ] ; then
echo "
usage: ./build.sh jlink {FILE} {ADDRESS} {SPI}
FILE: The path to the file to download.
ADDRESS: (Optional) RAM or SPI Flash address. Default is $DLRAM_ADDR (beginning of your RAM)
SPI: (Optional) 'single' or 'dual' SPI Flash. Default is 'single' SPI flash programming
Examples: (prepare - Erase beginning of QSPI flash because existing code is interfearing with programming)
./build.sh jlink prepare
Examples: (full path)
./build.sh jlink output/u-boot-2017.05/u-boot.bin $UBOOT_ADDR
Examples: (shortcut names)
./build.sh jlink u-boot # u-boot
./build.sh jlink dtb # Device Tree"
if [ -e $FILE3 ] ; then echo " ./build.sh jlink uImage # Linux Kernel"
fi
if [ -e $FILE4 ] ; then echo " ./build.sh jlink xipImage # Linux XIP Kernel"
fi
if [ -e $FILE5 ] ; then echo " ./build.sh jlink rootfs_squashfs # Root File System"
fi
if [ -e $FILE6 ] || [ -e $FILE8 ] ; then echo " ./build.sh jlink rootfs_axfs # Root File System"
fi
if [ -e $FILE7 ] ; then echo " ./build.sh jlink rootfs_cramfs # Root File System"
fi
echo "
Examples: (file number)
./build.sh jlink 1
File Numbers:"
if [ -e $FILE1 ] ; then echo " 1 = $FILE1"
fi
if [ -e $FILE2 ] ; then echo " 2 = $FILE2"
fi
if [ -e $FILE3 ] ; then echo " 3 = $FILE3"
fi
if [ -e $FILE4 ] ; then echo " 4 = $FILE4"
fi
if [ -e $FILE5 ] ; then echo " 5 = $FILE5"
fi
if [ -e $FILE6 ] ; then echo " 6 = $FILE6"
fi
if [ -e $FILE7 ] ; then echo " 7 = $FILE7"
fi
if [ -e $FILE8 ] ; then echo " 8 = $FILE8"
fi
echo "
Examples: (Download directory to QSPI Flash)
./build.sh jlink u-boot $UBOOT_ADDR
./build.sh jlink dtb $DTB_ADDR
"
if [ "$QSPI" == "SINGLE" ] ; then
echo \
" ./build.sh jlink uImage $KERNEL_ADDR
./build.sh jlink xipImage $KERNEL_ADDR
./build.sh jlink rootfs_squashfs $ROOTFS_ADDR
./build.sh jlink rootfs_axfs $ROOTFS_ADDR
./build.sh jlink rootfs_cramfs $ROOTFS_ADDR
"
fi
echo -ne "\033[1;31m" # RED TEXT
echo -ne "\nNOTE:"
echo -ne "\033[00m" # END TEXT COLOR
echo -e "Your board should be up and running in u-boot first\n (ie, not Linux) before executing this command."
exit 0
fi
# Shortcuts
# Change our passed arguments to full paths
if [ "$2" == "uboot" ] || [ "$2" == "u-boot" ] ; then
if [ "$3" == "" ] ; then
set -- $1 $FILE1 $UBOOT_ADDR $4
else
set -- $1 $FILE1 $3 $4
fi
fi
if [ "$2" == "dtb" ] ; then
if [ "$3" == "" ] ; then
set -- $1 $FILE2 $DTB_ADDR $4
else
set -- $1 $FILE2 $3 $4
fi
fi
if [ "$2" == "uImage" ] ; then
set -- $1 $FILE3 $3 $4
fi
if [ "$2" == "xipImage" ] ; then
set -- $1 $FILE4 $3 $4
fi
if [ "$2" == "rootfs_squashfs" ] ; then
set -- $1 $FILE5 $3 $4
fi
if [ "$2" == "rootfs_cramfs" ] ; then
set -- $1 $FILE7 $3 $4
fi
if [ "$2" == "rootfs_axfs" ] ; then
# Choose Buildroot as default
if [ -e $FILE6 ] ; then
set -- $1 $FILE6 $3 $4
else
set -- $1 $FILE7 $3 $4
fi
fi
# File Numbers
if [ "$2" == "1" ] ; then
if [ "$3" == "" ] ; then
set -- $1 $FILE1 $UBOOT_ADDR $4
else
set -- $1 $FILE1 $3 $4
fi
fi
if [ "$2" == "2" ] ; then
if [ "$3" == "" ] ; then
set -- $1 $FILE2 $DTB_ADDR $4
else
set -- $1 $FILE2 $3 $4
fi
fi
if [ "$2" == "3" ] ; then
set -- $1 $FILE3 $3 $4
fi
if [ "$2" == "4" ] ; then
set -- $1 $FILE4 $3 $4
fi
if [ "$2" == "5" ] ; then
set -- $1 $FILE5 $3 $4
fi
if [ "$2" == "6" ] ; then
set -- $1 $FILE6 $3 $4
fi
if [ "$2" == "7" ] ; then
set -- $1 $FILE7 $3 $4
fi
if [ "$2" == "8" ] ; then
set -- $1 $FILE8 $3 $4
fi
# prepare
if [ "$2" == "prepare" ] ; then
FF_FILE=/tmp/ff.dat
if [ -e $FF_FILE ] ; then rm $FF_FILE ; fi
for i in `seq 1 16` ; do
echo -n -e '\xFF' >> $FF_FILE
done
set -- $1 $FF_FILE $UBOOT_ADDR
banner_yellow "Erasing boot vector of QSPI flash"
sleep 3
fi
# File check
if [ ! -e "$2" ] ; then
echo "ERROR: File does not exist. $2"
exit 128
fi
filename=$(basename "$2")
extension="${filename##*.}"
#filename_only="${filename%.*}"
# Jlink must have a file extension of .bin for downloading
if [ "$extension" == "bin" ] ; then
dlfile=/tmp/$filename
else
dlfile=/tmp/$filename.bin
fi
cp -v "$2" $dlfile
ramaddr=$3
if [ "$ramaddr" == "" ] ; then
ramaddr=$DLRAM_ADDR
fi
# check single or dual
if [ "$4" != "" ] ; then
if [ "$4" != "single" ] && [ "$4" != "dual" ] ; then
echo ""
banner_red "Argument 4 must be either 'single' or 'dual'"
echo ""
exit 128
fi
fi
# Create a jlink script and execute it
if [ "$2" == "$FF_FILE" ] ; then
echo "rx 0" > /tmp/jlink_load.txt
echo "loadbin $dlfile,$ramaddr" >> /tmp/jlink_load.txt
echo "rx 1" >> /tmp/jlink_load.txt
echo "exit" >> /tmp/jlink_load.txt
else
echo "loadbin $dlfile,$ramaddr" > /tmp/jlink_load.txt
echo "g" >> /tmp/jlink_load.txt
echo "exit" >> /tmp/jlink_load.txt
fi
# After version 5.10, a new command line option is needed
CHECK=`which JLinkExe`
JLINKPATH=$(readlink -f $CHECK | sed 's:/JLinkExe::')
if [ -e $JLINKPATH/libjlinkarm.so.5 ] ; then
JLINKVER=$(ls $JLINKPATH/libjlinkarm.so.5.* | sed "s:$JLINKPATH/libjlinkarm.so.::")
# Since version numbers are not really 'numbers', we'll use 'sort' to figure
# out what one is the smallest, and if 5.10 is still the first number in the list,
# then we know the current version is either the same or later
ORDER=$(echo -e "5.10\\n$JLINKVER" | sort -V)
if [ "${ORDER:0:4}" == "5.10" ] ; then
JTAGCONF='-jtagconf -1,-1'
fi
fi
if [ -e $JLINKPATH/libjlinkarm.so.6 ] ; then
JTAGCONF='-jtagconf -1,-1'
fi
# clear our log
echo "" > /tmp/jlink.log
# keep a copy of the output (using 'tee') in a log file to check if the operation
# was successful or not because jlink does not return an error code
if [ "$SOC" != "RZA2M" ] ; then
# == RZ/A1 ==
if [ "$4" == "dual" ] ; then
JLinkExe -speed 15000 -if JTAG $JTAGCONF -device R7S721001_DualSPI -CommanderScript /tmp/jlink_load.txt | tee /tmp/jlink.log
else
JLinkExe -speed 15000 -if JTAG $JTAGCONF -device R7S721001 -CommanderScript /tmp/jlink_load.txt | tee /tmp/jlink.log
fi
else
# == RZ/A2 ==
JLinkExe -speed 15000 -if JTAG $JTAGCONF -device R7S921053VCBG -CommanderScript /tmp/jlink_load.txt | tee /tmp/jlink.log
fi
# Check to see if download we successful
CHECK=`grep -m1 FAILED /tmp/jlink.log`
CHECK2=`grep -m1 " Error:" /tmp/jlink.log`
CHECK3=`grep -m1 "Cannot connect to target" /tmp/jlink.log`
if [ "$CHECK" != "" ] ; then
banner_red "$CHECK"
exit 128
fi
if [ "$CHECK2" != "" ] ; then
banner_red "$CHECK2"
exit 128
fi
if [ "$CHECK3" != "" ] ; then
banner_red "$CHECK3"
exit 128
fi
echo "-----------------------------------------------------"
echo -en "\tFile size was:\n\t"
du -h $dlfile
echo "-----------------------------------------------------"
FILESIZE=$(cat $dlfile | wc -c)
CHECK=`grep "Comparing flash" /tmp/jlink.log`
if [ "$CHECK" != "" ] ; then
exit 128
fi
SF_PROBE=""
if [ "$QSPI" == "DUAL" ] ; then
SF_PROBE=":1"
fi
############ u-boot Programming ############
CHECK=$(echo $dlfile | grep u-boot)
if [ "$CHECK" != "" ] ; then
echo "Example program operations:
# Rewrite u-boot (512 KB):
=> sf probe 0 ; sf erase 0 80000 ; sf write $ramaddr 0 80000
"
exit 0
fi
############ DTB Programming ############
CHECK=$(echo $dlfile | grep dtb)
if [ "$CHECK" != "" ] ; then
SPI_ADDR=$(printf "%x\n" $(($DTB_ADDR-$UBOOT_ADDR)))
echo "Example program operations:
# Program DTB (32 KB)
=> sf probe 0 ; sf erase $SPI_ADDR 40000 ; sf write $ramaddr $SPI_ADDR 8000
"
exit 0
fi
############ Kernel Programming ############
CHECK=$(echo $dlfile | grep Image)
if [ "$CHECK" != "" ] ; then
# Determine SPI flash offset
SPI_ADDR=$(printf "%x\n" $(($KERNEL_ADDR-$UBOOT_ADDR)))
# Calculate how much you need to program (round up to next 1MB)
SPI_SZ_P=$(printf "%d\n" $(($FILESIZE/0x100000 + 1)))
SPI_SZ_MB=$(printf "%d\n" $(($SPI_SZ_P)))
SPI_SZ_P=$(printf "%x\n" $(($SPI_SZ_P*0x100000)))
echo -e "Example program operations:\n"
# Make adjustments for Dual SPI flash
if [ "$QSPI" == "DUAL" ] ; then
SPI_ADDR=$(printf "%x\n" $((0x$SPI_ADDR/2))) # SPI address is half
SPI_SZ_E=$(printf "%x\n" $((0x$SPI_SZ_P/2))) # Erase size is half of program size
else
SPI_SZ_E=$SPI_SZ_P
fi
echo "# Program Kernel (${SPI_SZ_MB}MB, $QSPI SPI flash)
=> sf probe 0$SF_PROBE ; sf erase $SPI_ADDR $SPI_SZ_E ; sf write $ramaddr $SPI_ADDR $SPI_SZ_P"
exit 0
fi
############ Rootfs Programming ############
CHECK=$(echo $dlfile | grep rootfs)
if [ "$CHECK" != "" ] ; then
# Determine SPI flash offset
SPI_ADDR=$(printf "%x\n" $(($ROOTFS_ADDR-$UBOOT_ADDR)))
# Calculate how much you need to program (round up to next 1MB)
SPI_SZ_P=$(printf "%d\n" $(($FILESIZE/0x100000 + 1)))
SPI_SZ_MB=$(printf "%d\n" $(($SPI_SZ_P)))
SPI_SZ_P=$(printf "%x\n" $(($SPI_SZ_P*0x100000)))
echo -e "Example program operations:\n"
# Make adjustments for Dual SPI flash
if [ "$QSPI" == "DUAL" ] ; then
SPI_ADDR=$(printf "%x\n" $((0x$SPI_ADDR/2))) # SPI address is half
SPI_SZ_E=$(printf "%x\n" $((0x$SPI_SZ_P/2))) # Erase size is half of program size
else
SPI_SZ_E=$SPI_SZ_P
fi
echo "# Program Rootfs (${SPI_SZ_MB}MB, $QSPI SPI flash)
=> sf probe 0$SF_PROBE ; sf erase $SPI_ADDR $SPI_SZ_E ; sf write $ramaddr $SPI_ADDR $SPI_SZ_P"
if [ "$BOARD" == "rskrza1" ] && [ $FILESIZE -ge $((0x2000000)) ] ; then # >= 32MB?
echo "Are you sure you have enough SDRAM space? The RSK only has 32MB of SDRAM."
fi
echo -e "\n"
exit 0
fi
fi
# Create output build directory
if [ ! -e $OUTDIR ] ; then
mkdir -p $OUTDIR
fi
##### Check if we have all the host tools we need for menuconfig #####
if [ "$2" == "menuconfig" ] ; then
CHECK=$(which ncurses5-config)
if [ "$CHECK" == "" ] ; then
banner_red "ncurses is not installed"
echo -e "You need the package ncurses installed in order to use menuconfig."
echo -e "In Ubuntu, you can install it by running:\n\tsudo apt-get install ncurses-dev\n"
echo -e "Existing build script.\n"
exit 1
fi
fi
###############################################################################
# build kernel
###############################################################################
if [ "$1" == "kernel" ] || [ "$1" == "k" ] ; then
banner_yellow "Building kernel"
check_for_toolchain
if [ "$2" == "" ] ; then
echo " "
echo "What do you want to build?"
echo "For example: (case sensitive)"
echo " Traditional kernel: ./build.sh kernel uImage"
echo " XIP kernel: ./build.sh kernel xipImage"
echo " Kernel config GUI: ./build.sh kernel menuconfig"
exit 0
fi
if [ "$2" == "uImage" ] ; then
CHECK=$(which mkimage)
if [ "$CHECK" == "" ] ; then
banner_red "mkimage is not installed"
echo -e "You need the program mkimage installed in order to build a kernel uImage."
echo -e "In Ubuntu, you can install it by running:\n\tsudo apt-get install u-boot-tools\n"
echo -e "Existing build script.\n"
exit 0
fi
fi
cd $OUTDIR
# install linux-4.19
if [ ! -e linux-4.19 ] ;then
# Download linux-4.19
# We need git to be installed
CHECK=`which git`
if [ "$CHECK" == "" ] ; then
banner_red "git is not installed"
echo -e "You need git in order to download the kernel"
echo -e "In Ubuntu, you can install it by running:\n\tsudo apt-get install git\n"
echo -e "Existing build script.\n"
exit 1
fi
# Download the current repository
git clone https://github.com/renesas-rz/rza_linux-4.19.git linux-4.19
fi
cd linux-4.19
# Do the build operation
IMG_BUILD=0
XIPCHECK=`grep -s CONFIG_XIP_KERNEL=y .config`
if [ "$2" == "uImage" ] ;then
IMG_BUILD=1
if [ ! -e .config ] || [ "$XIPCHECK" != "" ]; then
# Need to configure kernel first
make ${BOARD}_defconfig
fi
# To build a uImage, you need to specify LOADADDR.
if [ "$BOARD" == "rskrza1" ] || [ "$BOARD" == "genmai" ] || [ "$BOARD" == "ylcdrza1h" ] ; then
MY_LOADADDR='LOADADDR=0x08008000'
fi
if [ "$BOARD" == "streamit" ] ; then
MY_LOADADDR='LOADADDR=0x0C008000'
fi
if [ "$3" != "" ] ; then
MY_LOADADDR=LOADADDR=$3
fi
if [ "$MY_LOADADDR" == "" ] ; then
banner_red "Missing load address (LOADADDR)"
echo "When building a uImage, you need to specify the load address on the kernel"
echo "build command line (make LOADADDR=0x55555555 uImage) so u-boot"
echo "will know where in RAM to decompress the kernel to."
echo "Please specify that address according to your SDRAM location."
echo "Examples:"
echo " ./build.sh kernel uImage 0x08008000"
echo " ./build.sh kernel uImage 0x0C008000"
exit 128
fi
fi
if [ "$2" == "xipImage" ] ;then
IMG_BUILD=2
if [ ! -e .config ] || [ "$XIPCHECK" == "" ]; then
# Need to configure kernel first
make ${BOARD}_xip_defconfig
fi
# re-configure kernel if we changed target board
#CHECK=$(grep -i CONFIG_MACH_${BOARD}=y .config )
#if [ "$CHECK" == "" ] ; then
# echo "Reconfiguring for new board..."
# make ${BOARD}_xip_defconfig
#fi
# LOADADDR is not needed when building a xipImage
MY_LOADADDR=
fi
if [ "$IMG_BUILD" != "0" ] ; then
# NOTE: Adding "LOCALVERSION=" to the command line will get rid of the
# plus sign (+) at the end of the kernel version string. Alternatively,
# we could have created a empty ".scmversion" file in the root.
# NOTE: We have to make the Device Tree Blobs too, so we'll add 'dtbs' to
# the command line
echo -e "make $MY_LOADADDR LOCALVERSION= -j$BUILD_THREADS $2 dtbs\n"
make $MY_LOADADDR LOCALVERSION= -j$BUILD_THREADS $2 dtbs
RETURN_CODE=$?
if [ ! -e vmlinux ] ; then
# did not build, so exit
banner_red "Kernel Build failed. Exiting build script."
else
banner_green "Kernel Build Successful"
fi
else
# user wants to build something special
banner_yellow "Custom Build"
echo -e "make -j$BUILD_THREADS $2 $3 $4\n"
make -j$BUILD_THREADS $2 $3 $4
RETURN_CODE=$?
fi
exit $RETURN_CODE
fi
###############################################################################
# build u-boot
###############################################################################
if [ "$1" == "u-boot" ] || [ "$1" == "u" ] ; then
banner_yellow "Building u-boot"
check_for_toolchain
cd $OUTDIR
# install u-boot-2017.05
if [ ! -e u-boot-2017.05 ] ; then
# We need git to be installed
CHECK=`which git`
if [ "$CHECK" == "" ] ; then
banner_red "git is not installed"
echo -e "You need git in order to download the kernel"
echo -e "In Ubuntu, you can install it by running:\n\tsudo apt-get install git\n"
echo -e "Existing build script.\n"
exit 1
fi
# Download the latest head of the repository
git clone https://github.com/renesas-rz/rza_u-boot-2017.05.git u-boot-2017.05
fi
cd u-boot-2017.05
# Patch u-boot
if [ ! -e include/configs/rskrza1.h ] ;then
# Combine all the patches, then patch at once
cat $ROOTDIR/patches-uboot/* > /tmp/uboot_patches.patch
patch -p1 -i /tmp/uboot_patches.patch
fi
# Configure u-boot
if [ ! -e .config ] ;then
make ${BOARD}_config
fi
# re-configure u-boot if we changed target board
#CHECK=$(grep CONFIG_SYS_BOARD .config | grep $BOARD)
#if [ "$CHECK" == "" ] ; then
# echo "Reconfiguring for new board..."
# make ${BOARD}_config
#fi
# Build u-boot
if [ "$2" == "" ] ;then
# default build
make
RETURN_CODE=$?
if [ ! -e u-boot.bin ] ; then
# did not build, so exit
banner_red "u-boot Build failed. Exiting build script."
else
banner_green "u-boot Build Successful"
fi
else
# user wants to build something special
banner_yellow "Custom Build"
echo -e "make $2 $3 $4\n"
make $2 $3 $4
RETURN_CODE=$?
fi
exit $RETURN_CODE
fi
###############################################################################
# build buildroot
###############################################################################
if [ "$1" == "buildroot" ] || [ "$1" == "b" ] ; then
banner_yellow "Building buildroot"
cd $OUTDIR
if [ ! -e br_version.txt ] ; then
echo "What version of Buildroot do you want to use?"
echo "1. Buildroot-2017.02.10 (EOL)"
echo "2. Buildroot-2018.02.12 (EOL)"
echo "3. Buildroot-2019.02.x (updates until March 2020)"
echo -n "(select number)=> "
read ANSWER
if [ "$ANSWER" == "1" ] ; then
echo "export BR_VERSION=2017.02" > br_version.txt
elif [ "$ANSWER" == "2" ] ; then
echo "export BR_VERSION=2018.02" > br_version.txt
elif [ "$ANSWER" == "3" ] ; then
echo "export BR_VERSION=2019.02" > br_version.txt
else
echo "ERROR: \"$ANSWER\" is an invalid selection!"
exit 128
fi
source br_version.txt
fi
# Download buildroot-$BR_VERSION.tar.bz2
if [ ! -e buildroot-$BR_VERSION.tar.bz2 ] ;then
wget http://buildroot.uclibc.org/downloads/buildroot-$BR_VERSION.tar.bz2
if [ "$?" != "0" ] ; then
exit 128 # could not download
fi
fi
# extract buildroot-$BR_VERSION
if [ ! -e buildroot-$BR_VERSION/README ] ;then
echo "extracting buildroot..."
tar -xf buildroot-$BR_VERSION.tar.bz2
if [ "$?" != "0" ] ; then
exit 128 # could not extract
fi
fi
if [ ! -e buildroot-$BR_VERSION ] ;then
# something went wrong
exit 128
fi
cd buildroot-$BR_VERSION
# Apply Renesas Buildroot patches that have not been applied yet.
# Buildroot LTS update patches were made doing this in the Buildroot mainline repoistory:
# git diff 2018.02 2018.02.1 > br_2018.02.0_to_2018.02.1.patch
# git diff 2018.02.1 2018.02.2 > br_2018.02.1_to_2018.02.2.patch