1# Copyright (C) 2009 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"""Emit commands needed for HTC devices during OTA installation 16(installing the radio image).""" 17 18import common 19import re 20import sha 21 22def FullOTA_Assertions(info): 23 AddBootloaderAssertion(info, info.input_zip) 24 25 26def IncrementalOTA_Assertions(info): 27 AddBootloaderAssertion(info, info.target_zip) 28 29 30def AddBootloaderAssertion(info, input_zip): 31 android_info = input_zip.read("OTA/android-info.txt") 32 m = re.search(r"require\s+version-bootloader\s*=\s*(\S+)", android_info) 33 if m: 34 bootloaders = m.group(1).split("|") 35 if "*" not in bootloaders: 36 info.script.AssertSomeBootloader(*bootloaders) 37 info.metadata["pre-bootloader"] = m.group(1) 38 39 40def InstallRadio(radio_img, api_version, input_zip, info): 41 common.ZipWriteStr(info.output_zip, "radio.img", radio_img) 42 43 if api_version >= 3: 44 bitmap_txt = input_zip.read("RADIO/bitmap_size.txt") 45 install_img = input_zip.read("RADIO/firmware_install.565") 46 error_img = input_zip.read("RADIO/firmware_error.565") 47 width, height, bpp = bitmap_txt.split() 48 49 radio_sha = sha.sha(radio_img).hexdigest() 50 51 info.script.UnmountAll() 52 info.script.AppendExtra((''' 53assert(htc.install_radio(package_extract_file("radio.img"), 54 %(width)s, %(height)s, %(bpp)s, 55 package_extract_file("install.565"), 56 package_extract_file("error.565"), 57 %(radio_sha)s)); 58''' % locals()).lstrip()) 59 60 common.ZipWriteStr(info.output_zip, "install.565", install_img) 61 common.ZipWriteStr(info.output_zip, "error.565", error_img) 62 elif info.input_version >= 2: 63 info.script.AppendExtra( 64 'write_firmware_image("PACKAGE:radio.img", "radio");') 65 else: 66 info.script.AppendExtra( 67 ('assert(package_extract_file("radio.img", "/tmp/radio.img"),\n' 68 ' write_firmware_image("/tmp/radio.img", "radio"));\n')) 69 70 71def FullOTA_InstallEnd(info): 72 try: 73 radio_img = info.input_zip.read("RADIO/radio.img") 74 except KeyError: 75 print "warning: no radio image in input target_files; not flashing radio" 76 return 77 78 info.script.Print("Writing radio image...") 79 80 InstallRadio(radio_img, info.input_version, info.input_zip, info) 81 82 83def IncrementalOTA_InstallEnd(info): 84 try: 85 target_radio = info.target_zip.read("RADIO/radio.img") 86 except KeyError: 87 print "warning: radio image missing from target; not flashing radio" 88 return 89 90 try: 91 source_radio = info.source_zip.read("RADIO/radio.img") 92 except KeyError: 93 source_radio = None 94 95 if source_radio == target_radio: 96 print "Radio image unchanged; skipping" 97 return 98 99 InstallRadio(target_radio, info.target_version, info.target_zip, info) 100