blob: 55fa1704a94dd92d029b503209cd3f9d32aec87c [file] [log] [blame]
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -07001# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -07002#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070015# Use the default values if they weren't explicitly set
16if test "$XLOADERSRC" = ""
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070017then
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070018 XLOADERSRC=xloader.img
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070019fi
20if test "$BOOTLOADERSRC" = ""
21then
Jean-Baptiste Queru28b6c522012-04-02 12:17:56 -070022 BOOTLOADERSRC=bootloader.img
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070023fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070024if test "$RADIOSRC" = ""
25then
26 RADIOSRC=radio.img
27fi
28if test "$SLEEPDURATION" = ""
29then
30 SLEEPDURATION=5
31fi
32
33# Prepare the staging directory
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070034rm -rf tmp
35mkdir -p tmp/$PRODUCT-$VERSION
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070036
37# Extract the bootloader(s) and radio(s) as necessary
38if test "$XLOADER" != ""
39then
40 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$XLOADERSRC
41fi
Jean-Baptiste Querud06dd402012-04-27 18:31:48 -070042if test "$BOOTLOADERFILE" = ""
43then
44 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$BOOTLOADERSRC
45fi
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070046if test "$RADIO" != "" -a "$RADIOFILE" = ""
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070047then
48 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$RADIOSRC
49fi
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070050if test "$CDMARADIO" != "" -a "$CDMARADIOFILE" = ""
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070051then
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070052 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/radio-cdma.img
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070053fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070054
55# Copy the various images in their staging location
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070056cp ${SRCPREFIX}$PRODUCT-img-$BUILD.zip tmp/$PRODUCT-$VERSION/image-$PRODUCT-$VERSION.zip
Jean-Baptiste Queru241b6682012-11-02 08:48:35 -070057if test "$XLOADER" != ""
58then
59 cp tmp/RADIO/$XLOADERSRC tmp/$PRODUCT-$VERSION/xloader-$DEVICE-$XLOADER.img
60fi
Jean-Baptiste Querud06dd402012-04-27 18:31:48 -070061if test "$BOOTLOADERFILE" = ""
62then
63 cp tmp/RADIO/$BOOTLOADERSRC tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img
64else
65 cp $BOOTLOADERFILE tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img
66fi
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070067if test "$RADIO" != ""
68then
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070069 if test "$RADIOFILE" = ""
70 then
71 cp tmp/RADIO/$RADIOSRC tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
72 else
73 cp $RADIOFILE tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
74 fi
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070075fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070076if test "$CDMARADIO" != ""
77then
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070078 if test "$CDMARADIOFILE" = ""
79 then
80 cp tmp/RADIO/radio-cdma.img tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
81 else
82 cp $CDMARADIOFILE tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
83 fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070084fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070085
86# Write flash-all.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070087cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
88#!/bin/sh
89
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070090# Copyright 2012 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070091#
92# Licensed under the Apache License, Version 2.0 (the "License");
93# you may not use this file except in compliance with the License.
94# You may obtain a copy of the License at
95#
96# http://www.apache.org/licenses/LICENSE-2.0
97#
98# Unless required by applicable law or agreed to in writing, software
99# distributed under the License is distributed on an "AS IS" BASIS,
100# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101# See the License for the specific language governing permissions and
102# limitations under the License.
103
Bill Yi9d2a0d02019-02-26 10:43:22 -0800104if ! [ \$(\$(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 2802 ]; then
Xin Li20e35d32018-03-29 15:33:27 -0700105 echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html"
Xin Libaf936a2017-10-30 09:21:28 -0700106 exit 1
107fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700108EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800109if test "$UNLOCKBOOTLOADER" = "true"
110then
111cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
112fastboot oem unlock
113EOF
114fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700115if test "$ERASEALL" = "true"
116then
117cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
118fastboot erase boot
119fastboot erase cache
120fastboot erase recovery
121fastboot erase system
122fastboot erase userdata
123EOF
124fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700125if test "$XLOADER" != ""
126then
127cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
128fastboot flash xloader xloader-$DEVICE-$XLOADER.img
129EOF
130fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700131cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700132fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700133EOF
134if test "$TWINBOOTLOADERS" = "true"
135then
136cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
137fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
138EOF
139fi
140cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700141fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700142sleep $SLEEPDURATION
143EOF
144if test "$RADIO" != ""
145then
146cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700147fastboot flash radio radio-$DEVICE-$RADIO.img
148fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700149sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700150EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700151fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700152if test "$CDMARADIO" != ""
153then
154cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
155fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
156fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700157sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700158EOF
159fi
160cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
161fastboot -w update image-$PRODUCT-$VERSION.zip
162EOF
163chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700164
165# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700166cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
167@ECHO OFF
168:: Copyright 2012 The Android Open Source Project
169::
170:: Licensed under the Apache License, Version 2.0 (the "License");
171:: you may not use this file except in compliance with the License.
172:: You may obtain a copy of the License at
173::
174:: http://www.apache.org/licenses/LICENSE-2.0
175::
176:: Unless required by applicable law or agreed to in writing, software
177:: distributed under the License is distributed on an "AS IS" BASIS,
178:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179:: See the License for the specific language governing permissions and
180:: limitations under the License.
181
182PATH=%PATH%;"%SYSTEMROOT%\System32"
183EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800184if test "$UNLOCKBOOTLOADER" = "true"
185then
186cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
187fastboot oem unlock
188EOF
189fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700190if test "$ERASEALL" = "true"
191then
192cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
193fastboot erase boot
194fastboot erase cache
195fastboot erase recovery
196fastboot erase system
197fastboot erase userdata
198EOF
199fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700200if test "$XLOADER" != ""
201then
202cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
203fastboot flash xloader xloader-$DEVICE-$XLOADER.img
204EOF
205fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700206cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
207fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700208EOF
209if test "$TWINBOOTLOADERS" = "true"
210then
211cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
212fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
213EOF
214fi
215cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700216fastboot reboot-bootloader
217ping -n $SLEEPDURATION 127.0.0.1 >nul
218EOF
219if test "$RADIO" != ""
220then
221cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
222fastboot flash radio radio-$DEVICE-$RADIO.img
223fastboot reboot-bootloader
224ping -n $SLEEPDURATION 127.0.0.1 >nul
225EOF
226fi
227if test "$CDMARADIO" != ""
228then
229cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
230fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
231fastboot reboot-bootloader
232ping -n $SLEEPDURATION 127.0.0.1 >nul
233EOF
234fi
235cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
236fastboot -w update image-$PRODUCT-$VERSION.zip
237
238echo Press any key to exit...
239pause >nul
240exit
241EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700242
243# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700244cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
245#!/bin/sh
246
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -0700247# Copyright 2012 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700248#
249# Licensed under the Apache License, Version 2.0 (the "License");
250# you may not use this file except in compliance with the License.
251# You may obtain a copy of the License at
252#
253# http://www.apache.org/licenses/LICENSE-2.0
254#
255# Unless required by applicable law or agreed to in writing, software
256# distributed under the License is distributed on an "AS IS" BASIS,
257# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
258# See the License for the specific language governing permissions and
259# limitations under the License.
260
Bill Yi9d2a0d02019-02-26 10:43:22 -0800261if ! [ \$(\$(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 2802 ]; then
Xin Li20e35d32018-03-29 15:33:27 -0700262 echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html"
Xin Libaf936a2017-10-30 09:21:28 -0700263 exit 1
264fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700265EOF
266if test "$XLOADER" != ""
267then
268cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
269fastboot flash xloader xloader-$DEVICE-$XLOADER.img
270EOF
271fi
272cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700273fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700274EOF
275if test "$TWINBOOTLOADERS" = "true"
276then
277cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
278fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
279EOF
280fi
281cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700282fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700283sleep $SLEEPDURATION
284EOF
285if test "$RADIO" != ""
286then
287cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700288fastboot flash radio radio-$DEVICE-$RADIO.img
289fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700290sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700291EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700292fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700293if test "$CDMARADIO" != ""
294then
295cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
296fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
297fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700298sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700299EOF
300fi
301chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700302
303# Create the distributable package
Bill Yid68beab2016-08-31 10:34:36 -0700304(cd tmp ; zip -r ../$PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION)
305mv $PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION-factory-$(sha256sum < $PRODUCT-$VERSION-factory.zip | cut -b -8).zip
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700306
307# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700308rm -rf tmp