blob: 63ab26062c4d22e756d6193ae776b6ebab177359 [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
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700104EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800105if test "$UNLOCKBOOTLOADER" = "true"
106then
107cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
108fastboot oem unlock
109EOF
110fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700111if test "$ERASEALL" = "true"
112then
113cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
114fastboot erase boot
115fastboot erase cache
116fastboot erase recovery
117fastboot erase system
118fastboot erase userdata
119EOF
120fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700121if test "$XLOADER" != ""
122then
123cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
124fastboot flash xloader xloader-$DEVICE-$XLOADER.img
125EOF
126fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700127cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700128fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700129EOF
130if test "$TWINBOOTLOADERS" = "true"
131then
132cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
133fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
134EOF
135fi
136cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700137fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700138sleep $SLEEPDURATION
139EOF
140if test "$RADIO" != ""
141then
142cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700143fastboot flash radio radio-$DEVICE-$RADIO.img
144fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700145sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700146EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700147fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700148if test "$CDMARADIO" != ""
149then
150cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
151fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
152fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700153sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700154EOF
155fi
156cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
157fastboot -w update image-$PRODUCT-$VERSION.zip
158EOF
159chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700160
161# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700162cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
163@ECHO OFF
164:: Copyright 2012 The Android Open Source Project
165::
166:: Licensed under the Apache License, Version 2.0 (the "License");
167:: you may not use this file except in compliance with the License.
168:: You may obtain a copy of the License at
169::
170:: http://www.apache.org/licenses/LICENSE-2.0
171::
172:: Unless required by applicable law or agreed to in writing, software
173:: distributed under the License is distributed on an "AS IS" BASIS,
174:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175:: See the License for the specific language governing permissions and
176:: limitations under the License.
177
178PATH=%PATH%;"%SYSTEMROOT%\System32"
179EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800180if test "$UNLOCKBOOTLOADER" = "true"
181then
182cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
183fastboot oem unlock
184EOF
185fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700186if test "$ERASEALL" = "true"
187then
188cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
189fastboot erase boot
190fastboot erase cache
191fastboot erase recovery
192fastboot erase system
193fastboot erase userdata
194EOF
195fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700196if test "$XLOADER" != ""
197then
198cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
199fastboot flash xloader xloader-$DEVICE-$XLOADER.img
200EOF
201fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700202cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
203fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700204EOF
205if test "$TWINBOOTLOADERS" = "true"
206then
207cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
208fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
209EOF
210fi
211cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700212fastboot reboot-bootloader
213ping -n $SLEEPDURATION 127.0.0.1 >nul
214EOF
215if test "$RADIO" != ""
216then
217cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
218fastboot flash radio radio-$DEVICE-$RADIO.img
219fastboot reboot-bootloader
220ping -n $SLEEPDURATION 127.0.0.1 >nul
221EOF
222fi
223if test "$CDMARADIO" != ""
224then
225cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
226fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
227fastboot reboot-bootloader
228ping -n $SLEEPDURATION 127.0.0.1 >nul
229EOF
230fi
231cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
232fastboot -w update image-$PRODUCT-$VERSION.zip
233
234echo Press any key to exit...
235pause >nul
236exit
237EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700238
239# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700240cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
241#!/bin/sh
242
Jean-Baptiste Querufdec7042012-09-11 14:18:35 -0700243# Copyright 2012 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700244#
245# Licensed under the Apache License, Version 2.0 (the "License");
246# you may not use this file except in compliance with the License.
247# You may obtain a copy of the License at
248#
249# http://www.apache.org/licenses/LICENSE-2.0
250#
251# Unless required by applicable law or agreed to in writing, software
252# distributed under the License is distributed on an "AS IS" BASIS,
253# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254# See the License for the specific language governing permissions and
255# limitations under the License.
256
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700257EOF
258if test "$XLOADER" != ""
259then
260cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
261fastboot flash xloader xloader-$DEVICE-$XLOADER.img
262EOF
263fi
264cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700265fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700266EOF
267if test "$TWINBOOTLOADERS" = "true"
268then
269cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
270fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
271EOF
272fi
273cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700274fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700275sleep $SLEEPDURATION
276EOF
277if test "$RADIO" != ""
278then
279cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700280fastboot flash radio radio-$DEVICE-$RADIO.img
281fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700282sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700283EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700284fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700285if test "$CDMARADIO" != ""
286then
287cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
288fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
289fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700290sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700291EOF
292fi
293chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700294
295# Create the distributable package
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700296(cd tmp ; tar zcvf ../$PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION)
297mv $PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION-factory-$(sha1sum < $PRODUCT-$VERSION-factory.tgz | cut -b -8).tgz
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700298
299# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700300rm -rf tmp