diff options
Diffstat (limited to 'fastboot.sh')
-rwxr-xr-x | fastboot.sh | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/fastboot.sh b/fastboot.sh new file mode 100755 index 0000000..77449dd --- /dev/null +++ b/fastboot.sh | |||
@@ -0,0 +1,256 @@ | |||
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 | ## poll the board to find out its configuration | ||
63 | #product=`${FASTBOOT} getvar product 2>&1 | grep product | awk '{print$2}'` | ||
64 | cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'` | ||
65 | cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'` | ||
66 | boardrev=`${FASTBOOT} getvar board_rev 2>&1 | grep board_rev | awk '{print$2}'` | ||
67 | |||
68 | |||
69 | # Make EMU = HS | ||
70 | if [ ${cputype} = "EMU" ] || [ ${cputype} = "HS" ]; then | ||
71 | cputype="HS" | ||
72 | xloader="${PRODUCT_OUT}${cputype}_QSPI_MLO" | ||
73 | uboot="${PRODUCT_OUT}${cputype}_u-boot.img" | ||
74 | # If fastboot does not support getvar default to GP | ||
75 | elif [ ${cputype} = "" ] || [ ${cputype} = "GP" ]; then | ||
76 | cputype="GP" | ||
77 | xloader="${PRODUCT_OUT}${cputype}_MLO" | ||
78 | uboot="${PRODUCT_OUT}u-boot.img" | ||
79 | fi | ||
80 | |||
81 | # Based on cpu, decide the dtb to flash, default fall back to J6 and LCD 10 | ||
82 | if [ ${cpu} = "J6ECO" ]; then | ||
83 | if [ ${boardrev} = "C" ]; then | ||
84 | environment="${PRODUCT_OUT}dra72-evm-lcd-osd.dtb" | ||
85 | else | ||
86 | environment="${PRODUCT_OUT}dra72-evm-lcd10.dtb" | ||
87 | fi | ||
88 | else | ||
89 | if [ ${boardrev} = "H" ]; then | ||
90 | environment="${PRODUCT_OUT}dra7-evm-lcd-osd.dtb" | ||
91 | else | ||
92 | environment="${PRODUCT_OUT}dra7-evm-lcd10.dtb" | ||
93 | fi | ||
94 | fi | ||
95 | |||
96 | # Create the filename | ||
97 | bootimg="${PRODUCT_OUT}boot.img" | ||
98 | systemimg="${PRODUCT_OUT}system.img" | ||
99 | userdataimg="${PRODUCT_OUT}userdata.img" | ||
100 | cacheimg="${PRODUCT_OUT}cache.img" | ||
101 | efsimg="${PRODUCT_OUT}efs.img" | ||
102 | recoveryimg="${PRODUCT_OUT}recovery.img" | ||
103 | |||
104 | |||
105 | # Verify that all the files required for the fastboot flash | ||
106 | # process are available | ||
107 | |||
108 | if [ ! -e "${bootimg}" ] ; then | ||
109 | echo "Missing ${bootimg}" | ||
110 | exit -1; | ||
111 | fi | ||
112 | if [ ! -e "$xloader" ] ; then | ||
113 | echo "Missing ${xloader}" | ||
114 | exit -1; | ||
115 | fi | ||
116 | if [ ! -e "${uboot}" ] ; then | ||
117 | echo "Missing ${uboot}" | ||
118 | exit -1; | ||
119 | fi | ||
120 | if [ ! -e "${environment}" ] ; then | ||
121 | echo "Missing ${environment}" | ||
122 | exit -1; | ||
123 | else | ||
124 | echo "DTB = ${environment}" | ||
125 | fi | ||
126 | if [ ! -e "${systemimg}" ] ; then | ||
127 | echo "Missing ${systemimg}" | ||
128 | exit -1; | ||
129 | fi | ||
130 | if [ ! -e "${userdataimg}" ] ; then | ||
131 | echo "Missing ${userdataimg}" | ||
132 | exit -1; | ||
133 | fi | ||
134 | if [ ! -e "${cacheimg}" ] ; then | ||
135 | echo "Missing ${cacheimg}" | ||
136 | exit -1; | ||
137 | fi | ||
138 | if [ ! -e "${recoveryimg}" ] ; then | ||
139 | echo "Missing ${recoveryimg}" | ||
140 | exit -1; | ||
141 | fi | ||
142 | |||
143 | echo "Create GPT partition table" | ||
144 | ${FASTBOOT} oem format | ||
145 | |||
146 | echo "Setting target for bootloader to SPI" | ||
147 | ${FASTBOOT} oem spi | ||
148 | |||
149 | sleep 3 | ||
150 | |||
151 | echo "Flashing bootloader....." | ||
152 | echo " xloader: ${xloader}" | ||
153 | ${FASTBOOT} flash xloader ${xloader} | ||
154 | |||
155 | sleep 3 | ||
156 | echo " bootloader: ${uboot}" | ||
157 | ${FASTBOOT} flash bootloader ${uboot} | ||
158 | |||
159 | #echo "Reboot: make sure new bootloader runs..." | ||
160 | ${FASTBOOT} reboot-bootloader | ||
161 | |||
162 | sleep 5 | ||
163 | |||
164 | echo "Re-creating GPT partition table with new bootloader" | ||
165 | ${FASTBOOT} oem format | ||
166 | |||
167 | echo "Flash android partitions" | ||
168 | ${FASTBOOT} flash boot ${bootimg} | ||
169 | echo "Flashing environemnt....." | ||
170 | echo " environment: ${environment}" | ||
171 | ${FASTBOOT} flash environment ${environment} | ||
172 | ${FASTBOOT} flash recovery ${recoveryimg} | ||
173 | ${FASTBOOT} flash system ${systemimg} | ||
174 | |||
175 | userdataimg_orig="${userdataimg}.orig" | ||
176 | if [ ! -f $userdataimg_orig ]; then | ||
177 | cp $userdataimg $userdataimg_orig | ||
178 | else | ||
179 | cp $userdataimg_orig $userdataimg | ||
180 | fi | ||
181 | |||
182 | echo "Resizing userdata.img" | ||
183 | resizefail=0 | ||
184 | userdatasize=`./fastboot getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'` | ||
185 | if [ -n "$userdatasize" ]; then | ||
186 | while [ 1 ];do | ||
187 | echo Current userdata partition size=${userdatasize} KB | ||
188 | if [ -d "./data" ]; then | ||
189 | echo "Removing data" | ||
190 | rm -rf ./data || resizefail=1 | ||
191 | if [ $resizefail -eq 1 ]; then | ||
192 | echo "unable to remove data folder" && break | ||
193 | fi | ||
194 | fi | ||
195 | mkdir ./data | ||
196 | ./simg2img userdata.img userdata.img.raw | ||
197 | mount -o loop -o grpid -t ext4 ./userdata.img.raw ./data || resizefail=1 | ||
198 | if [ $resizefail -eq 1 ]; then | ||
199 | echo "Mount failed" && break | ||
200 | fi | ||
201 | ./make_ext4fs -s -l ${userdatasize}K -a data userdata.img data/ | ||
202 | sync | ||
203 | umount data | ||
204 | sync | ||
205 | rm -rf ./data | ||
206 | rm userdata.img.raw | ||
207 | break | ||
208 | done | ||
209 | else | ||
210 | resizefail=1 | ||
211 | fi | ||
212 | |||
213 | if [ $resizefail -eq 1 ]; then | ||
214 | echo "userdata resize failed." | ||
215 | echo "Eg: sudo ./fastboot.sh" | ||
216 | echo "For now, we are defaulting to original userdata.img" | ||
217 | cp $userdataimg_orig $userdataimg | ||
218 | fi | ||
219 | ${FASTBOOT} flash userdata ${userdataimg} | ||
220 | |||
221 | if [ "$1" != "--noefs" ] ; then | ||
222 | if [ ! -f ${efsimg} ] ; then | ||
223 | echo "Creating efs.img as 16M ext4 img..." | ||
224 | test -d ./efs/ || mkdir efs | ||
225 | ./make_ext4fs -s -l 16M -a efs efs.img efs/ | ||
226 | else | ||
227 | echo "Using previously created efs.img..." | ||
228 | fi | ||
229 | |||
230 | ${FASTBOOT} flash efs ${efsimg} | ||
231 | else | ||
232 | echo "efs partition is untouched" | ||
233 | fi | ||
234 | |||
235 | #flash cache.img | ||
236 | ${FASTBOOT} flash cache ${cacheimg} | ||
237 | |||
238 | #reboot now | ||
239 | #${FASTBOOT} reboot | ||
240 | |||
241 | #if [ $resizefail -eq 1 ]; then | ||
242 | # echo "--------------------------------------------------" | ||
243 | # echo "Attempt was made to resize the userdata partition image" | ||
244 | # echo "to the size available on your SOM. But it failed either" | ||
245 | # echo "because it failed to remove existing ./data folder or because" | ||
246 | # echo "you are not running this script with superuser privileges" | ||
247 | # echo "Don't panic! The script just loaded the original userdata.img" | ||
248 | # echo "so, things should just work as expected. Just that the size" | ||
249 | # echo "of /data will be smaller on target." | ||
250 | # echo "" | ||
251 | # echo "If you really want to resize userdata.img, remove any existing" | ||
252 | # echo "./data folder and run \"sudo ./fastboot.sh\"" | ||
253 | # echo "For now, we are defaulting to original userdata.img" | ||
254 | # echo "--------------------------------------------------" | ||
255 | #fi | ||
256 | |||