/
build.sh
executable file
·148 lines (139 loc) · 5.09 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
#!/bin/bash
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
board="bpi-r3"
#board="bpi-r64"
device="sdmmc"
#device="emmc"
#device="spim-nand"
#device="nor"
#https://forum.banana-pi.org/t/tutorial-build-customize-and-use-mediatek-open-source-u-boot-and-atf/13785/
mkimg="USE_MKIMAGE=1 MKIMAGE=./tools/mkimage"
if [[ -e build.conf ]];then
. build.conf
fi
case $device in
"spi-nand") device="spim-nand";;
"spi-nor") device="nor";;
esac
#DEFCONFIG="mt7986_rfb_${device}_defconfig"
case $board in
"bpi-r64") PLAT="mt7622";;
"bpi-r3") PLAT="mt7986";;
esac
case $1 in
#"importconfig")
# make $DEFCONFIG
#;;
#"defconfig")
# nano configs/$DEFCONFIG
#;;
"config")
make menuconfig
;;
"build")
#make -f Makefile PLAT=mt7622 BOOT_DEVICE=sdmmc DDR3_FLYBY=1 all fip
#make -f Makefile PLAT=mt7986 BOOT_DEVICE=sdmmc DRAM_USE_DDR4=1 all fip
case "$board" in
"bpi-r64") makeflags="PLAT=${PLAT} DDR3_FLYBY=1";;
"bpi-r3") makeflags="PLAT=${PLAT} DRAM_USE_DDR4=1";;
esac
makeflags="$makeflags BL33=u-boot.bin"
make $makeflags $mkimg BOOT_DEVICE=$device all fip
;;
"install")
if [[ "$device" != "sdmmc" ]];then echo "$1 not supported for $device";exit 1;fi
DEV=/dev/sdb
read -e -i "$DEV" -p "Please enter target device: " DEV
case $board in
"bpi-r64")
set -x
sudo dd if=build/${PLAT}/release/bl2.img of=${DEV} bs=512 seek=1024 conv=notrunc,fsync #1> /dev/null 2>&1
sudo dd if=build/${PLAT}/release/fip.bin of=${DEV} bs=512 seek=2048 conv=notrunc,fsync #1> /dev/null 2>&1
set +x
;;
"bpi-r3")
set -x
sudo dd if=build/${PLAT}/release/bl2.img of=${DEV}1 conv=notrunc,fsync #1> /dev/null 2>&1
sudo dd if=build/${PLAT}/release/fip.bin of=${DEV}4 conv=notrunc,fsync #1> /dev/null 2>&1
set +x
;;
esac
;;
"createimg")
if [[ "$device" != "sdmmc" ]];then echo "$1 not supported for $device";exit 1;fi
IMGDIR=.
IMGNAME=${board}_${device}
REALSIZE=7000
dd if=/dev/zero of=$IMGDIR/$IMGNAME.img bs=1M count=$REALSIZE 1> /dev/null 2>&1
LDEV=`sudo losetup -f`
DEV=`echo $LDEV | cut -d "/" -f 3` #mount image to loop device
echo "run losetup to assign image $IMGNAME.img to loopdev $LDEV ($DEV)"
sudo losetup $LDEV $IMGDIR/$IMGNAME.img 1> /dev/null #2>&1
bootsize=100
rootsize=6144
if [[ "$2" != "non-interactive" ]];then
read -p "size of boot? (MiB): " -ei $bootsize bootsize
read -p "size of root? (MiB): " -ei $rootsize rootsize
fi
case $board in
"bpi-r64")
bootstart=8192
bootend=$(( ${bootstart}+(${bootsize}*1024*2)-1 ))
rootstart=$(( ${bootend}+1 ))
rootend=$(( ${rootstart} + (${rootsize}*1024*2) ))
sudo sgdisk -o ${LDEV}
sudo sgdisk -a 1 -n 1:2048:6143 -t 1:8300 -c 1:"fip" ${LDEV}
sudo sgdisk -a 1 -n 2:6144:7167 -t 2:8300 -c 2:"config" ${LDEV}
sudo sgdisk -a 1 -n 3:7168:8191 -t 3:8300 -c 3:"rf" ${LDEV}
sudo sgdisk -a 1024 -n 4:${bootstart}:${bootend} -t 4:0700 -c 4:"kernel" ${LDEV}
sudo sgdisk -a 1024 -n 5:${rootstart}:${rootend} -t 5:8300 -c 5:"root" ${LDEV}
#r64 needs special MBR
sudo dd of=${LDEV} if=r64_header_sdmmc.bin
sudo dd of=${LDEV} if=build/${PLAT}/release/bl2.img bs=512 seek=1024
sudo dd of=${LDEV} if=build/${PLAT}/release/fip.bin bs=512 seek=2048
#re-read part table
sudo losetup -d $LDEV
sudo losetup -P $LDEV $IMGDIR/$IMGNAME.img 1> /dev/null #2>&1
sudo mkfs.vfat "${LDEV}p4" -n BPI-BOOT #1> /dev/null 2>&1
sudo mkfs.ext4 -O ^metadata_csum,^64bit "${LDEV}p5" -L BPI-ROOT #1> /dev/null 2>&1
;;
"bpi-r3")
bootstart=17408
bootend=$(( ${bootstart}+(${bootsize}*1024*2)-1 ))
rootstart=$(( ${bootend}+1 ))
rootend=$(( ${rootstart} + (${rootsize}*1024*2) ))
sudo sgdisk -o ${LDEV}
sudo sgdisk -a 1 -n 1:34:8191 -A 1:set:2 -t 1:8300 -c 1:"bl2" ${LDEV}
#sudo sgdisk --attributes=1:set:2 ${LDEV}
sudo sgdisk -a 1 -n 2:8192:9215 -t 2:8300 -c 2:"u-boot-env" ${LDEV}
sudo sgdisk -a 1 -n 3:9216:13311 -t 3:8300 -c 3:"factory" ${LDEV}
sudo sgdisk -a 1 -n 4:13312:17407 -t 4:8300 -c 4:"fip" ${LDEV}
sudo sgdisk -a 1024 -n 5:17408:${bootend} -t 5:8300 -c 5:"boot" ${LDEV}
sudo sgdisk -a 1024 -n 6:${rootstart}:${rootend} -t 6:8300 -c 6:"rootfs" ${LDEV}
#sudo dd if=gpt_${device}_100m6g.img of=$LDEV conv=notrunc,fsync #1> /dev/null 2>&1
#try to repair MBR/GPT
#sudo sgdisk --backup=bpi-r3_sgdisk.gpt /dev/sdb
#sudo sgdisk --load-backup=bpi-r3_sgdisk.gpt /dev/sdb
#re-read part table
sudo losetup -d $LDEV
sudo losetup -P $LDEV $IMGDIR/$IMGNAME.img 1> /dev/null #2>&1
#sudo partprobe $LDEV #1> /dev/null 2>&1
sudo dd if=build/${PLAT}/release/bl2.img of=${LDEV}p1 conv=notrunc,fsync #1> /dev/null 2>&1
sudo dd if=build/${PLAT}/release/fip.bin of=${LDEV}p4 conv=notrunc,fsync #1> /dev/null 2>&1
sudo mkfs.vfat "${LDEV}p5" -n BPI-BOOT #1> /dev/null 2>&1
sudo mkfs.ext4 -O ^metadata_csum,^64bit "${LDEV}p6" -L BPI-ROOT #1> /dev/null 2>&1
;;
esac
sudo losetup -d $LDEV
echo "packing image..."
gzip $IMGDIR/$IMGNAME.img
;;
"rename")
cp build/${PLAT}/release/bl2.img ${board}_${device}_bl2.img
cp build/${PLAT}/release/fip.bin ${board}_${device}_fip.bin
;;
"")
$0 build
;;
esac