blob: 417bc8b9e0064072ee4ab04bc9bb086e378a6dd0 [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 Queruf5f56fa2012-10-08 13:49:06 -070057cp tmp/RADIO/$XLOADERSRC tmp/$PRODUCT-$VERSION/xloader-$DEVICE-$XLOADER.img
Jean-Baptiste Querud06dd402012-04-27 18:31:48 -070058if test "$BOOTLOADERFILE" = ""
59then
60 cp tmp/RADIO/$BOOTLOADERSRC tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img
61else
62 cp $BOOTLOADERFILE tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img
63fi
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070064if test "$RADIO" != ""
65then
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070066 if test "$RADIOFILE" = ""
67 then
68 cp tmp/RADIO/$RADIOSRC tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
69 else
70 cp $RADIOFILE tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
71 fi
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -070072fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070073if test "$CDMARADIO" != ""
74then
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070075 if test "$CDMARADIOFILE" = ""
76 then
77 cp tmp/RADIO/radio-cdma.img tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
78 else
79 cp $CDMARADIOFILE tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
80 fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070081fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070082
83# Write flash-all.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070084cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
85#!/bin/sh
86
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -070087# Copyright 2012 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070088#
89# Licensed under the Apache License, Version 2.0 (the "License");
90# you may not use this file except in compliance with the License.
91# You may obtain a copy of the License at
92#
93# http://www.apache.org/licenses/LICENSE-2.0
94#
95# Unless required by applicable law or agreed to in writing, software
96# distributed under the License is distributed on an "AS IS" BASIS,
97# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98# See the License for the specific language governing permissions and
99# limitations under the License.
100
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700101EOF
102if test "$ERASEALL" = "true"
103then
104cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
105fastboot erase boot
106fastboot erase cache
107fastboot erase recovery
108fastboot erase system
109fastboot erase userdata
110EOF
111fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700112if test "$XLOADER" != ""
113then
114cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
115fastboot flash xloader xloader-$DEVICE-$XLOADER.img
116EOF
117fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700118cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700119fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700120EOF
121if test "$TWINBOOTLOADERS" = "true"
122then
123cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
124fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
125EOF
126fi
127cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700128fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700129sleep $SLEEPDURATION
130EOF
131if test "$RADIO" != ""
132then
133cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700134fastboot flash radio radio-$DEVICE-$RADIO.img
135fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700136sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700137EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700138fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700139if test "$CDMARADIO" != ""
140then
141cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
142fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
143fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700144sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700145EOF
146fi
147cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
148fastboot -w update image-$PRODUCT-$VERSION.zip
149EOF
150chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700151
152# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700153cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
154@ECHO OFF
155:: Copyright 2012 The Android Open Source Project
156::
157:: Licensed under the Apache License, Version 2.0 (the "License");
158:: you may not use this file except in compliance with the License.
159:: You may obtain a copy of the License at
160::
161:: http://www.apache.org/licenses/LICENSE-2.0
162::
163:: Unless required by applicable law or agreed to in writing, software
164:: distributed under the License is distributed on an "AS IS" BASIS,
165:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166:: See the License for the specific language governing permissions and
167:: limitations under the License.
168
169PATH=%PATH%;"%SYSTEMROOT%\System32"
170EOF
171if test "$ERASEALL" = "true"
172then
173cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
174fastboot erase boot
175fastboot erase cache
176fastboot erase recovery
177fastboot erase system
178fastboot erase userdata
179EOF
180fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700181if test "$XLOADER" != ""
182then
183cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
184fastboot flash xloader xloader-$DEVICE-$XLOADER.img
185EOF
186fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700187cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
188fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700189EOF
190if test "$TWINBOOTLOADERS" = "true"
191then
192cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
193fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
194EOF
195fi
196cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700197fastboot reboot-bootloader
198ping -n $SLEEPDURATION 127.0.0.1 >nul
199EOF
200if test "$RADIO" != ""
201then
202cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
203fastboot flash radio radio-$DEVICE-$RADIO.img
204fastboot reboot-bootloader
205ping -n $SLEEPDURATION 127.0.0.1 >nul
206EOF
207fi
208if test "$CDMARADIO" != ""
209then
210cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
211fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
212fastboot reboot-bootloader
213ping -n $SLEEPDURATION 127.0.0.1 >nul
214EOF
215fi
216cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
217fastboot -w update image-$PRODUCT-$VERSION.zip
218
219echo Press any key to exit...
220pause >nul
221exit
222EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700223
224# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700225cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
226#!/bin/sh
227
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -0700228# Copyright 2012 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700229#
230# Licensed under the Apache License, Version 2.0 (the "License");
231# you may not use this file except in compliance with the License.
232# You may obtain a copy of the License at
233#
234# http://www.apache.org/licenses/LICENSE-2.0
235#
236# Unless required by applicable law or agreed to in writing, software
237# distributed under the License is distributed on an "AS IS" BASIS,
238# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
239# See the License for the specific language governing permissions and
240# limitations under the License.
241
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700242EOF
243if test "$XLOADER" != ""
244then
245cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
246fastboot flash xloader xloader-$DEVICE-$XLOADER.img
247EOF
248fi
249cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700250fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700251EOF
252if test "$TWINBOOTLOADERS" = "true"
253then
254cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
255fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
256EOF
257fi
258cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700259fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700260sleep $SLEEPDURATION
261EOF
262if test "$RADIO" != ""
263then
264cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700265fastboot flash radio radio-$DEVICE-$RADIO.img
266fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700267sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700268EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700269fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700270if test "$CDMARADIO" != ""
271then
272cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
273fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
274fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700275sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700276EOF
277fi
278chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700279
280# Create the distributable package
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700281(cd tmp ; tar zcvf ../$PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION)
282mv $PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION-factory-$(sha1sum < $PRODUCT-$VERSION-factory.tgz | cut -b -8).tgz
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700283
284# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700285rm -rf tmp