blob: b7c959f13f2f74fb8f0ff6ed3b8fad4f58cdac39 [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 Querudfff6012012-11-02 10:00:23 -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 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
Jean-Baptiste Querudfff6012012-11-02 10:00:23 -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
78 cp tmp/RADIO/radio-cdma.img tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
79fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070080
81# Write flash-all.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070082cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
83#!/bin/sh
84
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070085# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070086#
87# Licensed under the Apache License, Version 2.0 (the "License");
88# you may not use this file except in compliance with the License.
89# You may obtain a copy of the License at
90#
91# http://www.apache.org/licenses/LICENSE-2.0
92#
93# Unless required by applicable law or agreed to in writing, software
94# distributed under the License is distributed on an "AS IS" BASIS,
95# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96# See the License for the specific language governing permissions and
97# limitations under the License.
98
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -070099EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800100if test "$UNLOCKBOOTLOADER" = "true"
101then
102cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
103fastboot oem unlock
104EOF
105fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700106if test "$ERASEALL" = "true"
107then
108cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
109fastboot erase boot
110fastboot erase cache
111fastboot erase recovery
112fastboot erase system
113fastboot erase userdata
114EOF
115fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700116if test "$XLOADER" != ""
117then
118cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
119fastboot flash xloader xloader-$DEVICE-$XLOADER.img
120EOF
121fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700122cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700123fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700124EOF
125if test "$TWINBOOTLOADERS" = "true"
126then
127cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
128fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
129EOF
130fi
131cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700132fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700133sleep $SLEEPDURATION
134EOF
135if test "$RADIO" != ""
136then
137cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700138fastboot flash radio radio-$DEVICE-$RADIO.img
139fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700140sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700141EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700142fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700143if test "$CDMARADIO" != ""
144then
145cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
146fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
147fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700148sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700149EOF
150fi
151cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
152fastboot -w update image-$PRODUCT-$VERSION.zip
153EOF
154chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700155
156# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700157cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
158@ECHO OFF
159:: Copyright 2012 The Android Open Source Project
160::
161:: Licensed under the Apache License, Version 2.0 (the "License");
162:: you may not use this file except in compliance with the License.
163:: You may obtain a copy of the License at
164::
165:: http://www.apache.org/licenses/LICENSE-2.0
166::
167:: Unless required by applicable law or agreed to in writing, software
168:: distributed under the License is distributed on an "AS IS" BASIS,
169:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170:: See the License for the specific language governing permissions and
171:: limitations under the License.
172
173PATH=%PATH%;"%SYSTEMROOT%\System32"
174EOF
Jean-Baptiste Querua7055312012-11-19 08:30:28 -0800175if test "$UNLOCKBOOTLOADER" = "true"
176then
177cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
178fastboot oem unlock
179EOF
180fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700181if test "$ERASEALL" = "true"
182then
183cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
184fastboot erase boot
185fastboot erase cache
186fastboot erase recovery
187fastboot erase system
188fastboot erase userdata
189EOF
190fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700191if test "$XLOADER" != ""
192then
193cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
194fastboot flash xloader xloader-$DEVICE-$XLOADER.img
195EOF
196fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700197cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
198fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700199EOF
200if test "$TWINBOOTLOADERS" = "true"
201then
202cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
203fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
204EOF
205fi
206cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700207fastboot reboot-bootloader
208ping -n $SLEEPDURATION 127.0.0.1 >nul
209EOF
210if test "$RADIO" != ""
211then
212cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
213fastboot flash radio radio-$DEVICE-$RADIO.img
214fastboot reboot-bootloader
215ping -n $SLEEPDURATION 127.0.0.1 >nul
216EOF
217fi
218if test "$CDMARADIO" != ""
219then
220cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
221fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
222fastboot reboot-bootloader
223ping -n $SLEEPDURATION 127.0.0.1 >nul
224EOF
225fi
226cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
227fastboot -w update image-$PRODUCT-$VERSION.zip
228
229echo Press any key to exit...
230pause >nul
231exit
232EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700233
234# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700235cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
236#!/bin/sh
237
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700238# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700239#
240# Licensed under the Apache License, Version 2.0 (the "License");
241# you may not use this file except in compliance with the License.
242# You may obtain a copy of the License at
243#
244# http://www.apache.org/licenses/LICENSE-2.0
245#
246# Unless required by applicable law or agreed to in writing, software
247# distributed under the License is distributed on an "AS IS" BASIS,
248# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249# See the License for the specific language governing permissions and
250# limitations under the License.
251
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700252EOF
253if test "$XLOADER" != ""
254then
255cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
256fastboot flash xloader xloader-$DEVICE-$XLOADER.img
257EOF
258fi
259cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700260fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700261EOF
262if test "$TWINBOOTLOADERS" = "true"
263then
264cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
265fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
266EOF
267fi
268cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700269fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700270sleep $SLEEPDURATION
271EOF
272if test "$RADIO" != ""
273then
274cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700275fastboot flash radio radio-$DEVICE-$RADIO.img
276fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700277sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700278EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700279fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700280if test "$CDMARADIO" != ""
281then
282cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
283fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
284fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700285sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700286EOF
287fi
288chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700289
290# Create the distributable package
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700291(cd tmp ; tar zcvf ../$PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION)
292mv $PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION-factory-$(sha1sum < $PRODUCT-$VERSION-factory.tgz | cut -b -8).tgz
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700293
294# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700295rm -rf tmp