summaryrefslogblamecommitdiffstats
blob: 7dbd2584f5c2ca5c137ce091f8562fdbba8c56f8 (plain) (tree)














































































































                                                                                            

                                 










                                                


                                               
 

                                                          







                                            
                              
                                         
#!/bin/bash

usage ()
{
	echo "Usage: sudo fastboot.sh <options>";
	echo "options:";
	echo "  --help Show this message and exit"
	exit 1;
}

#no args case
if [ "$1" = "--help" ] ; then
	usage
fi

# Pre-packaged DB
export FASTBOOT=${FASTBOOT-"./fastboot"}
export PRODUCT_OUT=${PRODUCT_OUT-"./"}
export LD_LIBRARY_PATH=./

echo "Fastboot: $FASTBOOT"
echo "Image location: $PRODUCT_OUT"


# =============================================================================
# pre-run
# =============================================================================

# Verify fastboot program is available
# Verify user permission to run fastboot
# Verify fastboot detects a device, otherwise exit
if [ -f ${FASTBOOT} ]; then
	fastboot_status=`${FASTBOOT} devices 2>&1`
	if [ `echo $fastboot_status | grep -wc "no permissions"` -gt 0 ]; then
		cat <<-EOF >&2
		-------------------------------------------
		 Fastboot requires administrator permissions
		 Please run the script as root or create a
		 fastboot udev rule, e.g:

		 % cat /etc/udev/rules.d/99_android.rules
		   SUBSYSTEM=="usb",
		   SYSFS{idVendor}=="0451"
		   OWNER="<username>"
		   GROUP="adm"
		-------------------------------------------
		EOF
		exit 1
	elif [ "X$fastboot_status" = "X" ]; then
		echo "No device detected. Please ensure that" \
			 "fastboot is running on the target device"
                exit -1;
	else
		device=`echo $fastboot_status | awk '{print$1}'`
		echo -e "\nFastboot - device detected: $device\n"
	fi
else
	echo "Error: fastboot is not available at ${FASTBOOT}"
        exit -1;
fi

# make bootloader image
# bootloader.img is FAT Image consisting
# sysfw.itb, u-boot.img and tispl.bin
dd if=/dev/zero of=bootloader.img bs=1048576 count=8
mkfs.vfat bootloader.img
mcopy -i bootloader.img tispl.bin ::tispl.bin
mcopy -i bootloader.img u-boot.img ::u-boot.img
mcopy -i bootloader.img sysfw.itb ::sysfw.itb

## poll the board to find out its configuration
cpu=`${FASTBOOT} getvar cpu 2>&1         | grep cpu     | awk '{print$2}'`
cputype=`${FASTBOOT} getvar secure 2>&1  | grep secure  | awk '{print$2}'`
boardrev=`${FASTBOOT} getvar board_rev 2>&1  | grep board_rev  | awk '{print$2}' | cut -b 1`

# Create the filename
tiboot3bin="${PRODUCT_OUT}tiboot3.bin"
bootloaderimg="${PRODUCT_OUT}bootloader.img"
systemimg="${PRODUCT_OUT}system.img"
userdataimg="${PRODUCT_OUT}userdata.img"
vendorimg="${PRODUCT_OUT}vendor.img"
bootfitimg="${PRODUCT_OUT}boot_fit.img"

# Verify that all the files required for the fastboot flash
# process are available

if [ ! -e "${tiboot3bin}" ] ; then
  echo "Missing ${tiboot3bin}"
  exit -1;
fi
if [ ! -e "${bootloaderimg}" ] ; then
  echo "Missing ${bootloaderimg}"
  exit -1;
fi
if [ ! -e "${systemimg}" ] ; then
  echo "Missing ${systemimg}"
  exit -1;
fi
if [ ! -e "${userdataimg}" ] ; then
  echo "Missing ${userdataimg}"
  exit -1;
fi
if [ ! -e "${vendorimg}" ] ; then
  echo "Missing ${vendorimg}"
  exit -1;
fi
if [ ! -e "${bootfitimg}" ] ; then
  echo "Missing ${bootfitimg}"
  exit -1;
fi

echo "Create GPT partition table"
${FASTBOOT} oem format

sleep 3

echo "Flashing tiboot3....."
echo "   tiboot3bin:     ${tiboot3bin}"
${FASTBOOT} flash tiboot3	${tiboot3bin}

sleep 3
echo "   bootloader:  ${bootloaderimg}"
${FASTBOOT} flash bootloader	${bootloaderimg}

echo "Reboot: make sure new bootloader runs..."
${FASTBOOT} reboot-bootloader
sleep 5

echo "Re-creating GPT partition table with new bootloader"
${FASTBOOT} oem format

echo "Flash android partitions"
${FASTBOOT} flash system	${systemimg}
${FASTBOOT} flash vendor	${vendorimg}

echo "Flashing FIT Boot Image"
${FASTBOOT} flash boot ${bootfitimg}

echo "Flashing userdata Image"
${FASTBOOT} flash userdata ${userdataimg}