diff options
| author | Ricardo Cerqueira <ricardo@cyngn.com> | 2015-01-15 04:59:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@cyngn.com> | 2015-02-15 07:28:20 +0000 |
| commit | e5aa8b0d1400a86a2edca598b7283541535361c0 (patch) | |
| tree | bef438653f62ed29f11c9698d33f90628fc60dfc /releasetools.py | |
| parent | f3f9be0b64da09b603d1176d16f4a2f7471de486 (diff) | |
releasetools: SHA1 sum against the incoming file length
Ignore the precomputed checksums from the file, too. We can do
them at packaging time to make sure there are no mismatches
Change-Id: Ibcc774142dafa804aac2089a382fa048f8f5be86
Diffstat (limited to 'releasetools.py')
| -rwxr-xr-x | releasetools.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/releasetools.py b/releasetools.py index 9c9f403..532f7ba 100755 --- a/releasetools.py +++ b/releasetools.py @@ -16,6 +16,7 @@ """Emit commands needed for QCOM devices during OTA installation (installing the radio image).""" +import hashlib import common import re @@ -30,9 +31,12 @@ def LoadFilesMap(zip): line = line.strip() if not line or line.startswith("#"): continue pieces = line.split() - if not (len(pieces) == 3): + if not (len(pieces) == 2 or len(pieces) == 3): raise ValueError("malformed filesmap line: \"%s\"" % (line,)) - d[pieces[0]] = (pieces[1], pieces[2]) + file_size = zip.getinfo("RADIO/"+pieces[0]).file_size + sha1 = hashlib.sha1() + sha1.update(zip.read("RADIO/"+pieces[0])) + d[pieces[0]] = (pieces[1], sha1.hexdigest(), file_size) return d def GetRadioFiles(z): @@ -59,13 +63,13 @@ def InstallRawImage(image_data, api_version, input_zip, fn, info, filesmap): return partition = filesmap[filename][0] checksum = filesmap[filename][1] - info.script.AppendExtra('run_program("/sbin/dd", "if=%s", "of=/tmp/test.img");' - % (partition)) - info.script.AppendExtra('ifelse((sha1_check(read_file("/tmp/test.img")) == "%s"),' + file_size = filesmap[filename][2] + # read_file returns a blob or NULL. Use sha1_check to convert to a string + # that can be evaluated (a NULL results in an empty string) + info.script.AppendExtra('ifelse((sha1_check(read_file("EMMC:%s:%d:%s")) != ""),' '(ui_print("%s already up to date")),' '(package_extract_file("%s", "%s")));' - % (checksum, partition, filename, partition)) - info.script.AppendExtra('delete("/tmp/test.img");') + % (partition, file_size, checksum, partition, filename, partition)) common.ZipWriteStr(info.output_zip, filename, image_data) return else: |
