Michael Ward | e03df73 | 2011-06-30 19:05:19 -0700 | [diff] [blame] | 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 Prime 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 | try: |
| 29 | radio_img = info.input_zip.read("RADIO/radio.img") |
| 30 | except KeyError: |
| 31 | print "no radio.img in target_files; skipping install" |
| 32 | else: |
| 33 | WriteRadio(info, radio_img) |
| 34 | |
Ken Sumrall | 726553e | 2012-01-04 20:58:40 -0800 | [diff] [blame] | 35 | FsSizeFix(info) |
| 36 | |
Michael Ward | f5f4c67 | 2011-07-10 17:38:16 -0700 | [diff] [blame] | 37 | def IncrementalOTA_VerifyEnd(info): |
| 38 | try: |
| 39 | target_radio_img = info.target_zip.read("RADIO/radio.img") |
| 40 | source_radio_img = info.source_zip.read("RADIO/radio.img") |
| 41 | except KeyError: |
| 42 | # No source or target radio. Nothing to verify |
| 43 | pass |
| 44 | else: |
| 45 | if source_radio_img != target_radio_img: |
| 46 | info.script.CacheFreeSpaceCheck(len(source_radio_img)) |
| 47 | radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) |
| 48 | info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( |
| 49 | radio_type, radio_device, |
| 50 | len(source_radio_img), common.sha1(source_radio_img).hexdigest(), |
| 51 | len(target_radio_img), common.sha1(target_radio_img).hexdigest())) |
| 52 | |
Michael Ward | e03df73 | 2011-06-30 19:05:19 -0700 | [diff] [blame] | 53 | def IncrementalOTA_InstallEnd(info): |
| 54 | try: |
| 55 | target_bootloader_img = info.target_zip.read("RADIO/bootloader.img") |
| 56 | try: |
| 57 | source_bootloader_img = info.source_zip.read("RADIO/bootloader.img") |
| 58 | except KeyError: |
| 59 | source_bootloader_img = None |
| 60 | |
| 61 | if source_bootloader_img == target_bootloader_img: |
| 62 | print "bootloader unchanged; skipping" |
| 63 | else: |
| 64 | WriteBootloader(info, target_bootloader_img) |
| 65 | except KeyError: |
| 66 | print "no bootloader.img in target target_files; skipping install" |
| 67 | |
| 68 | try: |
| 69 | target_radio_img = info.target_zip.read("RADIO/radio.img") |
| 70 | try: |
| 71 | source_radio_img = info.source_zip.read("RADIO/radio.img") |
| 72 | except KeyError: |
| 73 | source_radio_img = None |
| 74 | |
Michael Ward | f5f4c67 | 2011-07-10 17:38:16 -0700 | [diff] [blame] | 75 | WriteRadio(info, target_radio_img, source_radio_img) |
Michael Ward | e03df73 | 2011-06-30 19:05:19 -0700 | [diff] [blame] | 76 | except KeyError: |
| 77 | print "no radio.img in target target_files; skipping install" |
| 78 | |
Ken Sumrall | 726553e | 2012-01-04 20:58:40 -0800 | [diff] [blame] | 79 | FsSizeFix(info) |
| 80 | |
| 81 | def FsSizeFix(info): |
| 82 | info.script.Print("Fixing fs_size in crypto footer...") |
| 83 | info.script.AppendExtra('''assert(samsung.fs_size_fix());''') |
| 84 | |
Michael Ward | e03df73 | 2011-06-30 19:05:19 -0700 | [diff] [blame] | 85 | def WriteBootloader(info, bootloader_img): |
| 86 | common.ZipWriteStr(info.output_zip, "bootloader.img", bootloader_img) |
| 87 | fstab = info.info_dict["fstab"] |
| 88 | |
| 89 | info.script.Print("Writing bootloader...") |
Michael Ward | f5f4c67 | 2011-07-10 17:38:16 -0700 | [diff] [blame] | 90 | info.script.AppendExtra('''assert(samsung.write_bootloader( |
| 91 | package_extract_file("bootloader.img"), "%s", "%s"));''' % \ |
Michael Ward | e03df73 | 2011-06-30 19:05:19 -0700 | [diff] [blame] | 92 | (fstab["/xloader"].device, fstab["/sbl"].device)) |
| 93 | |
Michael Ward | f5f4c67 | 2011-07-10 17:38:16 -0700 | [diff] [blame] | 94 | def WriteRadio(info, target_radio_img, source_radio_img=None): |
| 95 | tf = common.File("radio.img", target_radio_img) |
| 96 | if source_radio_img is None: |
| 97 | tf.AddToZip(info.output_zip) |
| 98 | info.script.Print("Writing radio...") |
| 99 | info.script.WriteRawImage("/radio", tf.name) |
| 100 | else: |
| 101 | sf = common.File("radio.img", source_radio_img); |
| 102 | if tf.sha1 == sf.sha1: |
| 103 | print "radio image unchanged; skipping" |
| 104 | else: |
Doug Zongker | 4761c26 | 2012-08-14 16:31:51 -0700 | [diff] [blame] | 105 | diff = common.Difference(tf, sf, diff_program="bsdiff") |
Michael Ward | f5f4c67 | 2011-07-10 17:38:16 -0700 | [diff] [blame] | 106 | common.ComputeDifferences([diff]) |
| 107 | _, _, d = diff.GetPatch() |
| 108 | if d is None or len(d) > tf.size * common.OPTIONS.patch_threshold: |
| 109 | # computing difference failed, or difference is nearly as |
| 110 | # big as the target: simply send the target. |
| 111 | tf.AddToZip(info.output_zip) |
| 112 | info.script.Print("Writing radio...") |
| 113 | info.script.WriteRawImage("/radio", tf.name) |
| 114 | else: |
| 115 | common.ZipWriteStr(info.output_zip, "radio.img.p", d) |
| 116 | info.script.Print("Patching radio...") |
| 117 | radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) |
| 118 | info.script.ApplyPatch( |
| 119 | "%s:%s:%d:%s:%d:%s" % (radio_type, radio_device, |
| 120 | sf.size, sf.sha1, tf.size, tf.sha1), |
| 121 | "-", tf.size, tf.sha1, sf.sha1, "radio.img.p") |