Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | usage () |
| 4 | { |
Vishal Mahaveer | 0556166 | 2014-08-08 10:37:38 -0500 | [diff] [blame] | 5 | echo "Usage: sudo fastboot.sh <options>"; |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 6 | echo "options:"; |
Vishal Mahaveer | 0556166 | 2014-08-08 10:37:38 -0500 | [diff] [blame] | 7 | echo " --help Show this message and exit" |
| 8 | echo " --revg Flashes the dtb required for Rev-G J6 EVm which has 10inch panel"; |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 9 | exit 1; |
| 10 | } |
| 11 | |
| 12 | #no args case |
| 13 | if [ "$1" = "--help" ] ; then |
| 14 | usage |
| 15 | fi |
| 16 | |
| 17 | # Pre-packaged DB |
| 18 | export FASTBOOT=${FASTBOOT-"./fastboot"} |
| 19 | export PRODUCT_OUT=${PRODUCT_OUT-"./"} |
| 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 | |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 62 | ## poll the board to find out its configuration |
| 63 | #product=`${FASTBOOT} getvar product 2>&1 | grep product | awk '{print$2}'` |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 64 | cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'` |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 65 | cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'` |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 66 | |
| 67 | |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 68 | # Make EMU = HS |
Vishal Mahaveer | 4e53504 | 2014-08-25 13:24:48 -0500 | [diff] [blame] | 69 | if [ ${cputype} = "EMU" ] || [ ${cputype} = "HS" ]; then |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 70 | cputype="HS" |
Vishal Mahaveer | 4e53504 | 2014-08-25 13:24:48 -0500 | [diff] [blame] | 71 | xloader="${PRODUCT_OUT}${cputype}_QSPI_MLO" |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 72 | fi |
Vishal Mahaveer | 4e53504 | 2014-08-25 13:24:48 -0500 | [diff] [blame] | 73 | |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 74 | # If fastboot does not support getvar default to GP |
Vishal Mahaveer | 18655bb | 2014-08-26 16:28:05 -0500 | [diff] [blame] | 75 | if [ ${cputype} = "" ] || [ ${cputype} = "GP" ]; then |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 76 | cputype="GP" |
Vishal Mahaveer | 4e53504 | 2014-08-25 13:24:48 -0500 | [diff] [blame] | 77 | xloader="${PRODUCT_OUT}${cputype}_MLO" |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 78 | fi |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 79 | |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 80 | # Based on cpu, decide the dtb to flash, default fall back to J6 |
| 81 | if [ ${cpu} = "J6ECO" ]; then |
Vishal Mahaveer | 03f3b8a | 2014-10-22 10:35:54 -0500 | [diff] [blame] | 82 | environment="${PRODUCT_OUT}dra72-evm-lcd10.dtb" |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 83 | else |
Vishal Mahaveer | d0b1d21 | 2014-11-14 11:46:36 -0600 | [diff] [blame] | 84 | environment="${PRODUCT_OUT}dra7-evm-lcd7.dtb" |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 85 | fi |
| 86 | |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 87 | # Create the filename |
| 88 | bootimg="${PRODUCT_OUT}boot.img" |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 89 | uboot="${PRODUCT_OUT}u-boot.img" |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 90 | systemimg="${PRODUCT_OUT}system.img" |
| 91 | userdataimg="${PRODUCT_OUT}userdata.img" |
| 92 | cacheimg="${PRODUCT_OUT}cache.img" |
| 93 | efsimg="${PRODUCT_OUT}efs.img" |
| 94 | recoveryimg="${PRODUCT_OUT}recovery.img" |
| 95 | |
| 96 | |
| 97 | # Verify that all the files required for the fastboot flash |
| 98 | # process are available |
| 99 | |
| 100 | if [ ! -e "${bootimg}" ] ; then |
| 101 | echo "Missing ${bootimg}" |
| 102 | exit -1; |
| 103 | fi |
| 104 | if [ ! -e "$xloader" ] ; then |
| 105 | echo "Missing ${xloader}" |
| 106 | exit -1; |
| 107 | fi |
| 108 | if [ ! -e "${uboot}" ] ; then |
| 109 | echo "Missing ${uboot}" |
| 110 | exit -1; |
| 111 | fi |
| 112 | if [ ! -e "${environment}" ] ; then |
| 113 | echo "Missing ${environment}" |
| 114 | exit -1; |
| 115 | fi |
| 116 | if [ ! -e "${systemimg}" ] ; then |
| 117 | echo "Missing ${systemimg}" |
| 118 | exit -1; |
| 119 | fi |
| 120 | if [ ! -e "${userdataimg}" ] ; then |
| 121 | echo "Missing ${userdataimg}" |
| 122 | exit -1; |
| 123 | fi |
| 124 | if [ ! -e "${cacheimg}" ] ; then |
| 125 | echo "Missing ${cacheimg}" |
| 126 | # exit -1; |
| 127 | fi |
| 128 | if [ ! -e "${recoveryimg}" ] ; then |
| 129 | echo "Missing ${recoveryimg}" |
Vishal Mahaveer | 4a63e63 | 2014-01-24 08:30:03 -0600 | [diff] [blame] | 130 | exit -1; |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 131 | fi |
| 132 | |
| 133 | echo "Create GPT partition table" |
| 134 | ${FASTBOOT} oem format |
| 135 | |
Shankar Rao | 903e499 | 2013-08-02 14:34:04 -0500 | [diff] [blame] | 136 | echo "Setting target for bootloader to SPI" |
| 137 | ${FASTBOOT} oem spi |
| 138 | |
Shankar Rao | 7cc8dd7 | 2013-08-05 19:17:08 -0500 | [diff] [blame] | 139 | sleep 3 |
| 140 | |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 141 | echo "Flashing bootloader....." |
| 142 | echo " xloader: ${xloader}" |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 143 | ${FASTBOOT} flash xloader ${xloader} |
Shankar Rao | 7cc8dd7 | 2013-08-05 19:17:08 -0500 | [diff] [blame] | 144 | |
| 145 | sleep 3 |
| 146 | |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 147 | ${FASTBOOT} flash bootloader ${uboot} |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 148 | |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 149 | #echo "Reboot: make sure new bootloader runs..." |
Vishal Mahaveer | a39c17b | 2013-09-05 11:58:06 -0500 | [diff] [blame] | 150 | ${FASTBOOT} reboot-bootloader |
| 151 | |
| 152 | sleep 5 |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 153 | |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 154 | echo "Re-creating GPT partition table with new bootloader" |
| 155 | ${FASTBOOT} oem format |
| 156 | |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 157 | echo "Flash android partitions" |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 158 | ${FASTBOOT} flash boot ${bootimg} |
Vishal Mahaveer | 09e75ed | 2014-05-14 12:04:39 -0500 | [diff] [blame] | 159 | echo "Flashing device tree ${environment}" |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 160 | ${FASTBOOT} flash environment ${environment} |
Vishal Mahaveer | 4a63e63 | 2014-01-24 08:30:03 -0600 | [diff] [blame] | 161 | ${FASTBOOT} flash recovery ${recoveryimg} |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 162 | ${FASTBOOT} flash system ${systemimg} |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 163 | |
Vishal Mahaveer | 7734fca | 2013-10-10 09:30:29 -0500 | [diff] [blame] | 164 | userdataimg_orig="${userdataimg}.orig" |
| 165 | if [ ! -f $userdataimg_orig ]; then |
| 166 | cp $userdataimg $userdataimg_orig |
| 167 | else |
| 168 | cp $userdataimg_orig $userdataimg |
| 169 | fi |
| 170 | |
| 171 | echo "Resizing userdata.img" |
| 172 | resizefail=0 |
| 173 | userdatasize=`./fastboot getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'` |
| 174 | if [ -n "$userdatasize" ]; then |
| 175 | while [ 1 ];do |
| 176 | echo Current userdata partition size=${userdatasize} KB |
| 177 | if [ -d "./data" ]; then |
| 178 | echo "Removing data" |
| 179 | rm -rf ./data || resizefail=1 |
| 180 | if [ $resizefail -eq 1 ]; then |
| 181 | echo "unable to remove data folder" && break |
| 182 | fi |
| 183 | fi |
| 184 | mkdir ./data |
| 185 | ./simg2img userdata.img userdata.img.raw |
| 186 | mount -o loop -o grpid -t ext4 ./userdata.img.raw ./data || resizefail=1 |
| 187 | if [ $resizefail -eq 1 ]; then |
| 188 | echo "Mount failed" && break |
| 189 | fi |
| 190 | ./make_ext4fs -s -l ${userdatasize}K -a data userdata.img data/ |
| 191 | sync |
| 192 | umount data |
| 193 | sync |
| 194 | rm -rf ./data |
| 195 | rm userdata.img.raw |
| 196 | break |
| 197 | done |
| 198 | else |
| 199 | resizefail=1 |
| 200 | fi |
| 201 | |
| 202 | if [ $resizefail -eq 1 ]; then |
| 203 | echo "userdata resize failed." |
| 204 | echo "Eg: sudo ./fastboot.sh" |
| 205 | echo "For now, we are defaulting to original userdata.img" |
| 206 | cp $userdataimg_orig $userdataimg |
| 207 | fi |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 208 | ${FASTBOOT} flash userdata ${userdataimg} |
| 209 | |
| 210 | if [ "$1" != "--noefs" ] ; then |
| 211 | if [ ! -f ${efsimg} ] ; then |
| 212 | echo "Creating efs.img as 16M ext4 img..." |
| 213 | test -d ./efs/ || mkdir efs |
| 214 | ./make_ext4fs -s -l 16M -a efs efs.img efs/ |
| 215 | else |
| 216 | echo "Using previously created efs.img..." |
| 217 | fi |
| 218 | |
| 219 | ${FASTBOOT} flash efs ${efsimg} |
| 220 | else |
| 221 | echo "efs partition is untouched" |
| 222 | fi |
| 223 | |
| 224 | #Create cache.img |
| 225 | if [ ! -f ${cacheimg} ] |
| 226 | then |
| 227 | echo "Creating cache.img as empty ext4 img...." |
| 228 | rm -rf /tmp/fastboot-cache |
| 229 | mkdir /tmp/fastboot-cache |
Vishal Mahaveer | 49d9e76 | 2013-08-01 10:21:11 -0500 | [diff] [blame] | 230 | ./make_ext4fs -s -l 256M -a cache ${cacheimg} /tmp/fastboot-cache/ |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 231 | rm -rf /tmp/fastboot-cache |
| 232 | fi |
| 233 | |
| 234 | #flash cache.img |
Subramaniam Chanderashekarapuram | c795bdf | 2013-10-28 17:40:02 -0400 | [diff] [blame] | 235 | ${FASTBOOT} flash cache ${cacheimg} |
Vishal Mahaveer | 6b7b620 | 2013-07-26 18:24:59 -0500 | [diff] [blame] | 236 | |
| 237 | #reboot now |
| 238 | #${FASTBOOT} reboot |
| 239 | |
| 240 | #if [ $resizefail -eq 1 ]; then |
| 241 | # echo "--------------------------------------------------" |
| 242 | # echo "Attempt was made to resize the userdata partition image" |
| 243 | # echo "to the size available on your SOM. But it failed either" |
| 244 | # echo "because it failed to remove existing ./data folder or because" |
| 245 | # echo "you are not running this script with superuser privileges" |
| 246 | # echo "Don't panic! The script just loaded the original userdata.img" |
| 247 | # echo "so, things should just work as expected. Just that the size" |
| 248 | # echo "of /data will be smaller on target." |
| 249 | # echo "" |
| 250 | # echo "If you really want to resize userdata.img, remove any existing" |
| 251 | # echo "./data folder and run \"sudo ./fastboot.sh\"" |
| 252 | # echo "For now, we are defaulting to original userdata.img" |
| 253 | # echo "--------------------------------------------------" |
| 254 | #fi |
| 255 | |