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 Toro during OTA installation 16 (installing the bootloader and radio images).""" 17 18 import common 19 20 def FullOTA_InstallEnd(info): 21 try: 22 bootloader_img = info.input_zip.read("RADIO/bootloader.img") 23 except KeyError: 24 print "no bootloader.img in target_files; skipping install" 25 else: 26 WriteBootloader(info, bootloader_img) 27 28 # LTE Radio 29 try: 30 radio_img = info.input_zip.read("RADIO/radio.img") 31 except KeyError: 32 print "no radio.img in target_files; skipping install" 33 else: 34 WriteRadioLte(info, radio_img) 35 36 # CDMA Radio 37 try: 38 radio_cdma_img = info.input_zip.read("RADIO/radio-cdma.img") 39 except KeyError: 40 print "no radio.img in target_files; skipping install" 41 else: 42 WriteRadioCdma(info, radio_cdma_img) 43 44 def IncrementalOTA_VerifyEnd(info): 45 try: 46 target_radio_img = info.target_zip.read("RADIO/radio.img") 47 source_radio_img = info.source_zip.read("RADIO/radio.img") 48 except KeyError: 49 # No source or target radio. Nothing to verify 50 pass 51 else: 52 if source_radio_img != target_radio_img: 53 info.script.CacheFreeSpaceCheck(len(source_radio_img)) 54 radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) 55 info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( 56 radio_type, radio_device, 57 len(source_radio_img), common.sha1(source_radio_img).hexdigest(), 58 len(target_radio_img), common.sha1(target_radio_img).hexdigest())) 59 60 def IncrementalOTA_InstallEnd(info): 61 try: 62 target_bootloader_img = info.target_zip.read("RADIO/bootloader.img") 63 try: 64 source_bootloader_img = info.source_zip.read("RADIO/bootloader.img") 65 except KeyError: 66 source_bootloader_img = None 67 68 if source_bootloader_img == target_bootloader_img: 69 print "bootloader unchanged; skipping" 70 else: 71 WriteBootloader(info, target_bootloader_img) 72 except KeyError: 73 print "no bootloader.img in target target_files; skipping install" 74 75 # LTE Radio 76 try: 77 target_radio_img = info.target_zip.read("RADIO/radio.img") 78 try: 79 source_radio_img = info.source_zip.read("RADIO/radio.img") 80 except KeyError: 81 source_radio_img = None 82 83 WriteRadioLte(info, target_radio_img, source_radio_img) 84 except KeyError: 85 print "no radio.img in target target_files; skipping install" 86 87 # CDMA Radio 88 try: 89 target_radio_cdma_img = info.target_zip.read("RADIO/radio-cdma.img") 90 try: 91 source_radio_cdma_img = info.source_zip.read("RADIO/radio-cdma.img") 92 except KeyError: 93 source_radio_cdma_img = None 94 95 if source_radio_cdma_img == target_radio_cdma_img: 96 print "radio-cdma unchanged; skipping" 97 else: 98 WriteRadioCdma(info, target_radio_cdma_img) 99 except KeyError: 100 print "no radio-cdma.img in target target_files; skipping install" 101 102 def WriteBootloader(info, bootloader_img): 103 common.ZipWriteStr(info.output_zip, "bootloader.img", bootloader_img) 104 fstab = info.info_dict["fstab"] 105 106 info.script.Print("Writing bootloader...") 107 info.script.AppendExtra('''assert(samsung.write_bootloader( 108 package_extract_file("bootloader.img"), "%s", "%s"));''' % \ 109 (fstab["/xloader"].device, fstab["/sbl"].device)) 110 111 def WriteRadioLte(info, target_radio_img, source_radio_img=None): 112 tf = common.File("radio.img", target_radio_img) 113 if source_radio_img is None: 114 tf.AddToZip(info.output_zip) 115 info.script.Print("Writing LTE radio...") 116 info.script.WriteRawImage("/radio", tf.name) 117 else: 118 sf = common.File("radio.img", source_radio_img); 119 if tf.sha1 == sf.sha1: 120 print "LTE radio image unchanged; skipping" 121 else: 122 diff = common.Difference(tf, sf, diff_program="bsdiff") 123 common.ComputeDifferences([diff]) 124 _, _, d = diff.GetPatch() 125 if d is None or len(d) > tf.size * common.OPTIONS.patch_threshold: 126 # computing difference failed, or difference is nearly as 127 # big as the target: simply send the target. 128 tf.AddToZip(info.output_zip) 129 info.script.Print("Writing LTE radio...") 130 info.script.WriteRawImage("/radio", tf.name) 131 else: 132 common.ZipWriteStr(info.output_zip, "radio.img.p", d) 133 info.script.Print("Patching LTE radio...") 134 radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) 135 info.script.ApplyPatch( 136 "%s:%s:%d:%s:%d:%s" % (radio_type, radio_device, 137 sf.size, sf.sha1, tf.size, tf.sha1), 138 "-", tf.size, tf.sha1, sf.sha1, "radio.img.p") 139 140 def WriteRadioCdma(info, radio_cdma_img): 141 common.ZipWriteStr(info.output_zip, "radio-cdma.img", radio_cdma_img) 142 info.script.Print("Writing CDMA radio...") 143 info.script.AppendExtra('''assert(samsung.update_cdma_modem( 144 package_extract_file("radio-cdma.img")));''') 145