diff options
author | Praneeth Bajjuri | 2018-10-15 17:35:11 -0500 |
---|---|---|
committer | Praneeth Bajjuri | 2018-10-15 17:40:20 -0500 |
commit | 00e023dbde76d24d05dd50849326e0f65dfa9e85 (patch) | |
tree | 68d116d76057cec9c175d600f9daaa7ceddc40d7 | |
parent | 97b8ca534f223a24aa1e66c185dd54f0082925ba (diff) | |
download | device-ti-am65xevm-00e023dbde76d24d05dd50849326e0f65dfa9e85.tar.gz device-ti-am65xevm-00e023dbde76d24d05dd50849326e0f65dfa9e85.tar.xz device-ti-am65xevm-00e023dbde76d24d05dd50849326e0f65dfa9e85.zip |
am65xevm: Initial fastboot script
Initial Fastboot flashing script to flash all
android images on am65xevm
Signed-off-by: Praneeth Bajjuri <praneeth@ti.com>
-rwxr-xr-x | fastboot.sh | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/fastboot.sh b/fastboot.sh new file mode 100755 index 0000000..f90eeba --- /dev/null +++ b/fastboot.sh | |||
@@ -0,0 +1,202 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage () | ||
4 | { | ||
5 | echo "Usage: sudo fastboot.sh <options>"; | ||
6 | echo "options:"; | ||
7 | echo " --help Show this message and exit" | ||
8 | exit 1; | ||
9 | } | ||
10 | |||
11 | #no args case | ||
12 | if [ "$1" = "--help" ] ; then | ||
13 | usage | ||
14 | fi | ||
15 | |||
16 | # Pre-packaged DB | ||
17 | export FASTBOOT=${FASTBOOT-"./fastboot"} | ||
18 | export PRODUCT_OUT=${PRODUCT_OUT-"./"} | ||
19 | export LD_LIBRARY_PATH=./ | ||
20 | |||
21 | echo "Fastboot: $FASTBOOT" | ||
22 | echo "Image location: $PRODUCT_OUT" | ||
23 | |||
24 | |||
25 | # ============================================================================= | ||
26 | # pre-run | ||
27 | # ============================================================================= | ||
28 | |||
29 | # Verify fastboot program is available | ||
30 | # Verify user permission to run fastboot | ||
31 | # Verify fastboot detects a device, otherwise exit | ||
32 | if [ -f ${FASTBOOT} ]; then | ||
33 | fastboot_status=`${FASTBOOT} devices 2>&1` | ||
34 | if [ `echo $fastboot_status | grep -wc "no permissions"` -gt 0 ]; then | ||
35 | cat <<-EOF >&2 | ||
36 | ------------------------------------------- | ||
37 | Fastboot requires administrator permissions | ||
38 | Please run the script as root or create a | ||
39 | fastboot udev rule, e.g: | ||
40 | |||
41 | % cat /etc/udev/rules.d/99_android.rules | ||
42 | SUBSYSTEM=="usb", | ||
43 | SYSFS{idVendor}=="0451" | ||
44 | OWNER="<username>" | ||
45 | GROUP="adm" | ||
46 | ------------------------------------------- | ||
47 | EOF | ||
48 | exit 1 | ||
49 | elif [ "X$fastboot_status" = "X" ]; then | ||
50 | echo "No device detected. Please ensure that" \ | ||
51 | "fastboot is running on the target device" | ||
52 | exit -1; | ||
53 | else | ||
54 | device=`echo $fastboot_status | awk '{print$1}'` | ||
55 | echo -e "\nFastboot - device detected: $device\n" | ||
56 | fi | ||
57 | else | ||
58 | echo "Error: fastboot is not available at ${FASTBOOT}" | ||
59 | exit -1; | ||
60 | fi | ||
61 | |||
62 | # make bootloader image | ||
63 | # bootloader.img is FAT Image consisting | ||
64 | # sysfw.itb, u-boot.img and tispl.bin | ||
65 | dd if=/dev/zero of=bootloader.img bs=1048576 count=8 | ||
66 | mkfs.vfat bootloader.img | ||
67 | mcopy -i bootloader.img tispl.bin ::tispl.bin | ||
68 | mcopy -i bootloader.img u-boot.img ::u-boot.img | ||
69 | mcopy -i bootloader.img sysfw.itb ::sysfw.itb | ||
70 | |||
71 | ## poll the board to find out its configuration | ||
72 | cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'` | ||
73 | cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'` | ||
74 | boardrev=`${FASTBOOT} getvar board_rev 2>&1 | grep board_rev | awk '{print$2}' | cut -b 1` | ||
75 | |||
76 | # Create the filename | ||
77 | tiboot3bin="${PRODUCT_OUT}tiboot3.bin" | ||
78 | bootloaderimg="${PRODUCT_OUT}bootloader.img" | ||
79 | systemimg="${PRODUCT_OUT}system.img" | ||
80 | userdataimg="${PRODUCT_OUT}userdata.img" | ||
81 | vendorimg="${PRODUCT_OUT}vendor.img" | ||
82 | bootfitimg="${PRODUCT_OUT}boot_fit.img" | ||
83 | |||
84 | # Verify that all the files required for the fastboot flash | ||
85 | # process are available | ||
86 | |||
87 | if [ ! -e "${tiboot3bin}" ] ; then | ||
88 | echo "Missing ${tiboot3bin}" | ||
89 | exit -1; | ||
90 | fi | ||
91 | if [ ! -e "${bootloaderimg}" ] ; then | ||
92 | echo "Missing ${bootloaderimg}" | ||
93 | exit -1; | ||
94 | fi | ||
95 | if [ ! -e "${systemimg}" ] ; then | ||
96 | echo "Missing ${systemimg}" | ||
97 | exit -1; | ||
98 | fi | ||
99 | if [ ! -e "${userdataimg}" ] ; then | ||
100 | echo "Missing ${userdataimg}" | ||
101 | exit -1; | ||
102 | fi | ||
103 | if [ ! -e "${vendorimg}" ] ; then | ||
104 | echo "Missing ${vendorimg}" | ||
105 | exit -1; | ||
106 | fi | ||
107 | if [ ! -e "${bootfitimg}" ] ; then | ||
108 | echo "Missing ${bootfitimg}" | ||
109 | exit -1; | ||
110 | fi | ||
111 | |||
112 | #echo "Create GPT partition table" | ||
113 | #${FASTBOOT} oem format | ||
114 | |||
115 | sleep 3 | ||
116 | |||
117 | echo "Flashing tiboot3....." | ||
118 | echo " tiboot3bin: ${tiboot3bin}" | ||
119 | ${FASTBOOT} flash tiboot3 ${tiboot3bin} | ||
120 | |||
121 | sleep 3 | ||
122 | echo " bootloader: ${bootloaderimg}" | ||
123 | ${FASTBOOT} flash bootloader ${bootloaderimg} | ||
124 | |||
125 | # echo "Reboot: make sure new bootloader runs..." | ||
126 | # ${FASTBOOT} reboot-bootloader | ||
127 | # sleep 5 | ||
128 | |||
129 | #echo "Re-creating GPT partition table with new bootloader" | ||
130 | #${FASTBOOT} oem format | ||
131 | |||
132 | echo "Flash android partitions" | ||
133 | ${FASTBOOT} flash system ${systemimg} | ||
134 | ${FASTBOOT} flash vendor ${vendorimg} | ||
135 | |||
136 | echo "Flashing FIT Boot Image" | ||
137 | ${FASTBOOT} flash boot ${bootfitimg} | ||
138 | |||
139 | userdataimg_orig="${userdataimg}.orig" | ||
140 | if [ ! -f $userdataimg_orig ]; then | ||
141 | cp $userdataimg $userdataimg_orig | ||
142 | else | ||
143 | cp $userdataimg_orig $userdataimg | ||
144 | fi | ||
145 | |||
146 | echo "Resizing userdata.img" | ||
147 | resizefail=0 | ||
148 | userdatasize=`${FASTBOOT} getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'` | ||
149 | if [ -n "$userdatasize" ]; then | ||
150 | while [ 1 ];do | ||
151 | echo Current userdata partition size=${userdatasize} KB | ||
152 | if [ -d "./data" ]; then | ||
153 | echo "Removing data" | ||
154 | rm -rf ./data || resizefail=1 | ||
155 | if [ $resizefail -eq 1 ]; then | ||
156 | echo "unable to remove data folder" && break | ||
157 | fi | ||
158 | fi | ||
159 | mkdir ./data | ||
160 | ./simg2img ${userdataimg} ${userdataimg}.raw | ||
161 | mount -o loop -o grpid -t ext4 ${userdataimg}.raw ./data || resizefail=1 | ||
162 | if [ $resizefail -eq 1 ]; then | ||
163 | echo "Mount failed" && break | ||
164 | fi | ||
165 | ./make_ext4fs -s -l ${userdatasize}K -a data ${userdataimg} data/ | ||
166 | sync | ||
167 | umount data | ||
168 | sync | ||
169 | rm -rf ./data | ||
170 | rm ${userdataimg}.raw | ||
171 | break | ||
172 | done | ||
173 | else | ||
174 | resizefail=1 | ||
175 | fi | ||
176 | |||
177 | if [ $resizefail -eq 1 ]; then | ||
178 | echo "userdata resize failed." | ||
179 | echo "Eg: sudo ./fastboot.sh" | ||
180 | echo "For now, we are defaulting to original userdata.img" | ||
181 | cp $userdataimg_orig $userdataimg | ||
182 | fi | ||
183 | ${FASTBOOT} flash userdata ${userdataimg} | ||
184 | |||
185 | #reboot now | ||
186 | #${FASTBOOT} reboot | ||
187 | |||
188 | #if [ $resizefail -eq 1 ]; then | ||
189 | # echo "--------------------------------------------------" | ||
190 | # echo "Attempt was made to resize the userdata partition image" | ||
191 | # echo "to the size available on your SOM. But it failed either" | ||
192 | # echo "because it failed to remove existing ./data folder or because" | ||
193 | # echo "you are not running this script with superuser privileges" | ||
194 | # echo "Don't panic! The script just loaded the original userdata.img" | ||
195 | # echo "so, things should just work as expected. Just that the size" | ||
196 | # echo "of /data will be smaller on target." | ||
197 | # echo "" | ||
198 | # echo "If you really want to resize userdata.img, remove any existing" | ||
199 | # echo "./data folder and run \"sudo ./fastboot.sh\"" | ||
200 | # echo "For now, we are defaulting to original userdata.img" | ||
201 | # echo "--------------------------------------------------" | ||
202 | #fi | ||