blob: 2fc5ebf397b6ed0063786f3f66da04228e80a98b [file] [log] [blame]
Jean-Baptiste Queru84222772012-10-01 16:13:55 -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 Queru9cb1b4a2012-04-19 08:44:21 -070046if test "$RADIO" != ""
47then
48 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$RADIOSRC
49fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070050if test "$CDMARADIO" != ""
51then
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
69 cp tmp/RADIO/$RADIOSRC tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
70fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070071if test "$CDMARADIO" != ""
72then
73 cp tmp/RADIO/radio-cdma.img tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
74fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070075
76# Write flash-all.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070077cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
78#!/bin/sh
79
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070080# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070081#
82# Licensed under the Apache License, Version 2.0 (the "License");
83# you may not use this file except in compliance with the License.
84# You may obtain a copy of the License at
85#
86# http://www.apache.org/licenses/LICENSE-2.0
87#
88# Unless required by applicable law or agreed to in writing, software
89# distributed under the License is distributed on an "AS IS" BASIS,
90# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91# See the License for the specific language governing permissions and
92# limitations under the License.
93
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -070094EOF
95if test "$ERASEALL" = "true"
96then
97cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
98fastboot erase boot
99fastboot erase cache
100fastboot erase recovery
101fastboot erase system
102fastboot erase userdata
103EOF
104fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700105if test "$XLOADER" != ""
106then
107cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
108fastboot flash xloader xloader-$DEVICE-$XLOADER.img
109EOF
110fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700111cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700112fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700113EOF
114if test "$TWINBOOTLOADERS" = "true"
115then
116cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
117fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
118EOF
119fi
120cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700121fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700122sleep $SLEEPDURATION
123EOF
124if test "$RADIO" != ""
125then
126cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700127fastboot flash radio radio-$DEVICE-$RADIO.img
128fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700129sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700130EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700131fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700132if test "$CDMARADIO" != ""
133then
134cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
135fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
136fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700137sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700138EOF
139fi
140cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
141fastboot -w update image-$PRODUCT-$VERSION.zip
142EOF
143chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700144
145# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700146cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
147@ECHO OFF
148:: Copyright 2012 The Android Open Source Project
149::
150:: Licensed under the Apache License, Version 2.0 (the "License");
151:: you may not use this file except in compliance with the License.
152:: You may obtain a copy of the License at
153::
154:: http://www.apache.org/licenses/LICENSE-2.0
155::
156:: Unless required by applicable law or agreed to in writing, software
157:: distributed under the License is distributed on an "AS IS" BASIS,
158:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159:: See the License for the specific language governing permissions and
160:: limitations under the License.
161
162PATH=%PATH%;"%SYSTEMROOT%\System32"
163EOF
164if test "$ERASEALL" = "true"
165then
166cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
167fastboot erase boot
168fastboot erase cache
169fastboot erase recovery
170fastboot erase system
171fastboot erase userdata
172EOF
173fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700174if test "$XLOADER" != ""
175then
176cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
177fastboot flash xloader xloader-$DEVICE-$XLOADER.img
178EOF
179fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700180cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
181fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700182EOF
183if test "$TWINBOOTLOADERS" = "true"
184then
185cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
186fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
187EOF
188fi
189cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700190fastboot reboot-bootloader
191ping -n $SLEEPDURATION 127.0.0.1 >nul
192EOF
193if test "$RADIO" != ""
194then
195cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
196fastboot flash radio radio-$DEVICE-$RADIO.img
197fastboot reboot-bootloader
198ping -n $SLEEPDURATION 127.0.0.1 >nul
199EOF
200fi
201if test "$CDMARADIO" != ""
202then
203cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
204fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
205fastboot reboot-bootloader
206ping -n $SLEEPDURATION 127.0.0.1 >nul
207EOF
208fi
209cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
210fastboot -w update image-$PRODUCT-$VERSION.zip
211
212echo Press any key to exit...
213pause >nul
214exit
215EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700216
217# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700218cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
219#!/bin/sh
220
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700221# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700222#
223# Licensed under the Apache License, Version 2.0 (the "License");
224# you may not use this file except in compliance with the License.
225# You may obtain a copy of the License at
226#
227# http://www.apache.org/licenses/LICENSE-2.0
228#
229# Unless required by applicable law or agreed to in writing, software
230# distributed under the License is distributed on an "AS IS" BASIS,
231# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
232# See the License for the specific language governing permissions and
233# limitations under the License.
234
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700235EOF
236if test "$XLOADER" != ""
237then
238cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
239fastboot flash xloader xloader-$DEVICE-$XLOADER.img
240EOF
241fi
242cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700243fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700244EOF
245if test "$TWINBOOTLOADERS" = "true"
246then
247cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
248fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
249EOF
250fi
251cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700252fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700253sleep $SLEEPDURATION
254EOF
255if test "$RADIO" != ""
256then
257cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700258fastboot flash radio radio-$DEVICE-$RADIO.img
259fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700260sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700261EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700262fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700263if test "$CDMARADIO" != ""
264then
265cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
266fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
267fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700268sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700269EOF
270fi
271chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700272
273# Create the distributable package
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700274(cd tmp ; tar zcvf ../$PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION)
275mv $PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION-factory-$(sha1sum < $PRODUCT-$VERSION-factory.tgz | cut -b -8).tgz
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700276
277# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700278rm -rf tmp