blob: 0ff6868aa2543a3c7fe0593740b4d1c885d1c4e7 [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 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
66 cp tmp/RADIO/$RADIOSRC tmp/$PRODUCT-$VERSION/radio-$DEVICE-$RADIO.img
67fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070068if test "$CDMARADIO" != ""
69then
70 cp tmp/RADIO/radio-cdma.img tmp/$PRODUCT-$VERSION/radio-cdma-$DEVICE-$CDMARADIO.img
71fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070072
73# Write flash-all.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070074cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
75#!/bin/sh
76
Jean-Baptiste Queru84222772012-10-01 16:13:55 -070077# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -070078#
79# Licensed under the Apache License, Version 2.0 (the "License");
80# you may not use this file except in compliance with the License.
81# You may obtain a copy of the License at
82#
83# http://www.apache.org/licenses/LICENSE-2.0
84#
85# Unless required by applicable law or agreed to in writing, software
86# distributed under the License is distributed on an "AS IS" BASIS,
87# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88# See the License for the specific language governing permissions and
89# limitations under the License.
90
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -070091EOF
92if test "$ERASEALL" = "true"
93then
94cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
95fastboot erase boot
96fastboot erase cache
97fastboot erase recovery
98fastboot erase system
99fastboot erase userdata
100EOF
101fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700102if test "$XLOADER" != ""
103then
104cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
105fastboot flash xloader xloader-$DEVICE-$XLOADER.img
106EOF
107fi
Jean-Baptiste Queru9ceee562012-06-26 08:35:16 -0700108cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700109fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700110EOF
111if test "$TWINBOOTLOADERS" = "true"
112then
113cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
114fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
115EOF
116fi
117cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700118fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700119sleep $SLEEPDURATION
120EOF
121if test "$RADIO" != ""
122then
123cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700124fastboot flash radio radio-$DEVICE-$RADIO.img
125fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700126sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700127EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700128fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700129if test "$CDMARADIO" != ""
130then
131cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
132fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
133fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700134sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700135EOF
136fi
137cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF
138fastboot -w update image-$PRODUCT-$VERSION.zip
139EOF
140chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700141
142# Write flash-all.bat
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700143cat > tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
144@ECHO OFF
145:: Copyright 2012 The Android Open Source Project
146::
147:: Licensed under the Apache License, Version 2.0 (the "License");
148:: you may not use this file except in compliance with the License.
149:: You may obtain a copy of the License at
150::
151:: http://www.apache.org/licenses/LICENSE-2.0
152::
153:: Unless required by applicable law or agreed to in writing, software
154:: distributed under the License is distributed on an "AS IS" BASIS,
155:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
156:: See the License for the specific language governing permissions and
157:: limitations under the License.
158
159PATH=%PATH%;"%SYSTEMROOT%\System32"
160EOF
161if test "$ERASEALL" = "true"
162then
163cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
164fastboot erase boot
165fastboot erase cache
166fastboot erase recovery
167fastboot erase system
168fastboot erase userdata
169EOF
170fi
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700171if test "$XLOADER" != ""
172then
173cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
174fastboot flash xloader xloader-$DEVICE-$XLOADER.img
175EOF
176fi
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700177cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
178fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700179EOF
180if test "$TWINBOOTLOADERS" = "true"
181then
182cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
183fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
184EOF
185fi
186cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
Wug Freshb5e3c7d2012-09-10 09:35:32 -0700187fastboot reboot-bootloader
188ping -n $SLEEPDURATION 127.0.0.1 >nul
189EOF
190if test "$RADIO" != ""
191then
192cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
193fastboot flash radio radio-$DEVICE-$RADIO.img
194fastboot reboot-bootloader
195ping -n $SLEEPDURATION 127.0.0.1 >nul
196EOF
197fi
198if test "$CDMARADIO" != ""
199then
200cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
201fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
202fastboot reboot-bootloader
203ping -n $SLEEPDURATION 127.0.0.1 >nul
204EOF
205fi
206cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF
207fastboot -w update image-$PRODUCT-$VERSION.zip
208
209echo Press any key to exit...
210pause >nul
211exit
212EOF
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700213
214# Write flash-base.sh
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700215cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
216#!/bin/sh
217
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700218# Copyright 2011 The Android Open Source Project
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700219#
220# Licensed under the Apache License, Version 2.0 (the "License");
221# you may not use this file except in compliance with the License.
222# You may obtain a copy of the License at
223#
224# http://www.apache.org/licenses/LICENSE-2.0
225#
226# Unless required by applicable law or agreed to in writing, software
227# distributed under the License is distributed on an "AS IS" BASIS,
228# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
229# See the License for the specific language governing permissions and
230# limitations under the License.
231
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700232EOF
233if test "$XLOADER" != ""
234then
235cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
236fastboot flash xloader xloader-$DEVICE-$XLOADER.img
237EOF
238fi
239cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700240fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img
Jean-Baptiste Queru2466e5e2012-10-01 17:34:18 -0700241EOF
242if test "$TWINBOOTLOADERS" = "true"
243then
244cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
245fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img
246EOF
247fi
248cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700249fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700250sleep $SLEEPDURATION
251EOF
252if test "$RADIO" != ""
253then
254cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700255fastboot flash radio radio-$DEVICE-$RADIO.img
256fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700257sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700258EOF
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700259fi
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700260if test "$CDMARADIO" != ""
261then
262cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF
263fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img
264fastboot reboot-bootloader
Jean-Baptiste Queru9cb1b4a2012-04-19 08:44:21 -0700265sleep $SLEEPDURATION
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700266EOF
267fi
268chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700269
270# Create the distributable package
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700271(cd tmp ; tar zcvf ../$PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION)
272mv $PRODUCT-$VERSION-factory.tgz $PRODUCT-$VERSION-factory-$(sha1sum < $PRODUCT-$VERSION-factory.tgz | cut -b -8).tgz
Jean-Baptiste Queru84222772012-10-01 16:13:55 -0700273
274# Clean up
Jean-Baptiste Queru36cbd9a2012-04-02 11:01:12 -0700275rm -rf tmp