1 # Copyright 2011 The Android Open Source Project 2 # 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 15 # Use the default values if they weren't explicitly set 16 if test "$XLOADERSRC" = "" 17 then 18 XLOADERSRC=xloader.img 19 fi 20 if test "$BOOTLOADERSRC" = "" 21 then 22 BOOTLOADERSRC=bootloader.img 23 fi 24 if test "$RADIOSRC" = "" 25 then 26 RADIOSRC=radio.img 27 fi 28 if test "$SLEEPDURATION" = "" 29 then 30 SLEEPDURATION=5 31 fi 32 33 # Prepare the staging directory 34 rm -rf tmp 35 mkdir -p tmp/$PRODUCT-$VERSION 36 37 # Extract the bootloader(s) and radio(s) as necessary 38 if test "$XLOADER" != "" 39 then 40 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$XLOADERSRC 41 fi 42 if test "$BOOTLOADERFILE" = "" 43 then 44 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$BOOTLOADERSRC 45 fi 46 if test "$RADIO" != "" -a "$RADIOFILE" = "" 47 then 48 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/$RADIOSRC 49 fi 50 if test "$CDMARADIO" != "" -a "$CDMARADIOFILE" = "" 51 then 52 unzip -d tmp ${SRCPREFIX}$PRODUCT-target_files-$BUILD.zip RADIO/radio-cdma.img 53 fi 54 55 # Copy the various images in their staging location 56 cp ${SRCPREFIX}$PRODUCT-img-$BUILD.zip tmp/$PRODUCT-$VERSION/image-$PRODUCT-$VERSION.zip 57 if test "$XLOADER" != "" 58 then 59 cp tmp/RADIO/$XLOADERSRC tmp/$PRODUCT-$VERSION/xloader-$DEVICE-$XLOADER.img 60 fi 61 if test "$BOOTLOADERFILE" = "" 62 then 63 cp tmp/RADIO/$BOOTLOADERSRC tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img 64 else 65 cp $BOOTLOADERFILE tmp/$PRODUCT-$VERSION/bootloader-$DEVICE-$BOOTLOADER.img 66 fi 67 if test "$RADIO" != "" 68 then 69 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 75 fi 76 if test "$CDMARADIO" != "" 77 then 78 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 84 fi 85 86 # Write flash-all.sh 87 cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 88 #!/bin/sh 89 90 # Copyright 2012 The Android Open Source Project 91 # 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 104 EOF 105 if test "$UNLOCKBOOTLOADER" = "true" 106 then 107 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 108 fastboot oem unlock 109 EOF 110 fi 111 if test "$ERASEALL" = "true" 112 then 113 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 114 fastboot erase boot 115 fastboot erase cache 116 fastboot erase recovery 117 fastboot erase system 118 fastboot erase userdata 119 EOF 120 fi 121 if test "$XLOADER" != "" 122 then 123 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 124 fastboot flash xloader xloader-$DEVICE-$XLOADER.img 125 EOF 126 fi 127 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 128 fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img 129 EOF 130 if test "$TWINBOOTLOADERS" = "true" 131 then 132 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 133 fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img 134 EOF 135 fi 136 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 137 fastboot reboot-bootloader 138 sleep $SLEEPDURATION 139 EOF 140 if test "$RADIO" != "" 141 then 142 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 143 fastboot flash radio radio-$DEVICE-$RADIO.img 144 fastboot reboot-bootloader 145 sleep $SLEEPDURATION 146 EOF 147 fi 148 if test "$CDMARADIO" != "" 149 then 150 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 151 fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img 152 fastboot reboot-bootloader 153 sleep $SLEEPDURATION 154 EOF 155 fi 156 cat >> tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 157 fastboot -w update image-$PRODUCT-$VERSION.zip 158 EOF 159 chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh 160 161 # Write flash-all.bat 162 cat > 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 178 PATH=%PATH%;"%SYSTEMROOT%\System32" 179 EOF 180 if test "$UNLOCKBOOTLOADER" = "true" 181 then 182 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 183 fastboot oem unlock 184 EOF 185 fi 186 if test "$ERASEALL" = "true" 187 then 188 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 189 fastboot erase boot 190 fastboot erase cache 191 fastboot erase recovery 192 fastboot erase system 193 fastboot erase userdata 194 EOF 195 fi 196 if test "$XLOADER" != "" 197 then 198 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 199 fastboot flash xloader xloader-$DEVICE-$XLOADER.img 200 EOF 201 fi 202 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 203 fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img 204 EOF 205 if test "$TWINBOOTLOADERS" = "true" 206 then 207 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 208 fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img 209 EOF 210 fi 211 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 212 fastboot reboot-bootloader 213 ping -n $SLEEPDURATION 127.0.0.1 >nul 214 EOF 215 if test "$RADIO" != "" 216 then 217 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 218 fastboot flash radio radio-$DEVICE-$RADIO.img 219 fastboot reboot-bootloader 220 ping -n $SLEEPDURATION 127.0.0.1 >nul 221 EOF 222 fi 223 if test "$CDMARADIO" != "" 224 then 225 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 226 fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img 227 fastboot reboot-bootloader 228 ping -n $SLEEPDURATION 127.0.0.1 >nul 229 EOF 230 fi 231 cat >> tmp/$PRODUCT-$VERSION/flash-all.bat << EOF 232 fastboot -w update image-$PRODUCT-$VERSION.zip 233 234 echo Press any key to exit... 235 pause >nul 236 exit 237 EOF 238 239 # Write flash-base.sh 240 cat > tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 241 #!/bin/sh 242 243 # Copyright 2012 The Android Open Source Project 244 # 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 257 EOF 258 if test "$XLOADER" != "" 259 then 260 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 261 fastboot flash xloader xloader-$DEVICE-$XLOADER.img 262 EOF 263 fi 264 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 265 fastboot flash bootloader bootloader-$DEVICE-$BOOTLOADER.img 266 EOF 267 if test "$TWINBOOTLOADERS" = "true" 268 then 269 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 270 fastboot flash bootloader2 bootloader-$DEVICE-$BOOTLOADER.img 271 EOF 272 fi 273 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 274 fastboot reboot-bootloader 275 sleep $SLEEPDURATION 276 EOF 277 if test "$RADIO" != "" 278 then 279 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 280 fastboot flash radio radio-$DEVICE-$RADIO.img 281 fastboot reboot-bootloader 282 sleep $SLEEPDURATION 283 EOF 284 fi 285 if test "$CDMARADIO" != "" 286 then 287 cat >> tmp/$PRODUCT-$VERSION/flash-base.sh << EOF 288 fastboot flash radio-cdma radio-cdma-$DEVICE-$CDMARADIO.img 289 fastboot reboot-bootloader 290 sleep $SLEEPDURATION 291 EOF 292 fi 293 chmod a+x tmp/$PRODUCT-$VERSION/flash-base.sh 294 295 # Create the distributable package 296 (cd tmp ; zip -r ../$PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION) 297 mv $PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION-factory-$(sha256sum < $PRODUCT-$VERSION-factory.zip | cut -b -8).zip 298 299 # Clean up 300 rm -rf tmp 301