summaryrefslogtreecommitdiffstats
path: root/releasetools.py
diff options
context:
space:
mode:
Diffstat (limited to 'releasetools.py')
-rw-r--r--releasetools.py53
1 files changed, 43 insertions, 10 deletions
diff --git a/releasetools.py b/releasetools.py
index 493f94f..aa3786a 100644
--- a/releasetools.py
+++ b/releasetools.py
@@ -12,12 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import sha
+
import common
def FullOTA_InstallEnd(info):
try:
bootloader_img = info.input_zip.read("RADIO/bootloader.img")
common.ZipWriteStr(info.output_zip, "bootloader.img", bootloader_img)
+ info.script.Print("Writing bootloader...")
info.script.WriteRawImage("bootloader", "bootloader.img")
except KeyError:
print "no bootloader.img in target_files; skipping install"
@@ -25,10 +28,23 @@ def FullOTA_InstallEnd(info):
try:
radio_img = info.input_zip.read("RADIO/radio.img")
common.ZipWriteStr(info.output_zip, "radio.img", radio_img)
+ info.script.Print("Writing radio...")
info.script.WriteRawImage("radio", "radio.img")
except KeyError:
print "no radio.img in target_files; skipping install"
+def IncrementalOTA_VerifyEnd(info):
+ try:
+ target_radio_img = info.target_zip.read("RADIO/radio.img")
+ source_radio_img = info.source_zip.read("RADIO/radio.img")
+ if source_radio_img != target_radio_img:
+ info.script.CacheFreeSpaceCheck(len(source_radio_img))
+ info.script.PatchCheck("MTD:radio:%d:%s:%d:%s" % (
+ len(source_radio_img), sha.sha(source_radio_img).hexdigest(),
+ len(target_radio_img), sha.sha(target_radio_img).hexdigest()))
+ except KeyError:
+ pass
+
def IncrementalOTA_InstallEnd(info):
try:
target_bootloader_img = info.target_zip.read("RADIO/bootloader.img")
@@ -41,24 +57,41 @@ def IncrementalOTA_InstallEnd(info):
print "bootloader unchanged; skipping"
else:
common.ZipWriteStr(info.output_zip, "bootloader.img", bootloader_img)
+ info.script.Print("Writing bootloader...")
info.script.WriteRawImage("bootloader", "bootloader.img")
except KeyError:
print "no bootloader.img in target target_files; skipping install"
+
try:
- target_radio_img = info.target_zip.read("RADIO/radio.img")
+ tf = common.File("radio.img", info.target_zip.read("RADIO/radio.img"))
try:
- source_radio_img = info.source_zip.read("RADIO/radio.img")
- except KeyError:
- source_radio_img = None
+ sf = common.File("radio.img", info.source_zip.read("RADIO/radio.img"))
- if source_radio_img == target_radio_img:
- print "radio unchanged; skipping"
- else:
- # TODO: send radio image as binary patch
+ diff = common.Difference(tf, sf)
+ common.ComputeDifferences([diff])
+ _, _, d = diff.GetPatch()
+ if d is None or len(d) > tf.size * common.OPTIONS.patch_threshold:
+ # computing difference failed, or difference is nearly as
+ # big as the target: simply send the target.
+ tf.AddToZip(info.output_zip)
+ info.script.Print("Writing radio...")
+ info.script.WriteRawImage("radio", tf.name)
+ else:
+ common.ZipWriteStr(info.output_zip, "radio.img.p", d)
+ info.script.Print("Patching radio...")
+ info.script.ApplyPatch(
+ "MTD:radio:%d:%s:%d:%s" % (sf.size, sf.sha1, tf.size, tf.sha1),
+ "-", tf.size, tf.sha1, sf.sha1, "radio.img.p")
+
+ except KeyError:
+ # failed to read SOURCE radio image: include the whole target
+ # radio image.
+ tf.AddToZip(info.output_zip)
+ info.script.Print("Writing radio...")
+ info.script.WriteRawImage("radio", tf.name)
- common.ZipWriteStr(info.output_zip, "radio.img", radio_img)
- info.script.WriteRawImage("radio", "radio.img")
except KeyError:
+ # failed to read TARGET radio image: don't include any radio in update.
print "no radio.img in target target_files; skipping install"