summaryrefslogtreecommitdiffstats
blob: 7dbd2584f5c2ca5c137ce091f8562fdbba8c56f8 (plain) (blame)
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
#!/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}