summaryrefslogtreecommitdiff
path: root/scripts/update_payload/payload.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/update_payload/payload.py')
-rw-r--r--scripts/update_payload/payload.py46
1 files changed, 15 insertions, 31 deletions
diff --git a/scripts/update_payload/payload.py b/scripts/update_payload/payload.py
index 2a0cb58d..998703ad 100644
--- a/scripts/update_payload/payload.py
+++ b/scripts/update_payload/payload.py
@@ -16,10 +16,14 @@
"""Tools for reading, verifying and applying Chrome OS update payloads."""
+from __future__ import absolute_import
from __future__ import print_function
import hashlib
+import io
+import mmap
import struct
+import zipfile
from update_payload import applier
from update_payload import checker
@@ -64,7 +68,7 @@ class Payload(object):
"""Update payload header struct."""
# Header constants; sizes are in bytes.
- _MAGIC = 'CrAU'
+ _MAGIC = b'CrAU'
_VERSION_SIZE = 8
_MANIFEST_LEN_SIZE = 8
_METADATA_SIGNATURE_LEN_SIZE = 4
@@ -111,7 +115,6 @@ class Payload(object):
payload_file, self._METADATA_SIGNATURE_LEN_SIZE, True,
hasher=hasher)
-
def __init__(self, payload_file, payload_file_offset=0):
"""Initialize the payload object.
@@ -119,7 +122,15 @@ class Payload(object):
payload_file: update payload file object open for reading
payload_file_offset: the offset of the actual payload
"""
- self.payload_file = payload_file
+ if zipfile.is_zipfile(payload_file):
+ with zipfile.ZipFile(payload_file) as zfp:
+ self.payload_file = zfp.open("payload.bin", "r")
+ elif isinstance(payload_file, str):
+ payload_fp = open(payload_file, "rb")
+ payload_bytes = mmap.mmap(payload_fp.fileno(), 0, access=mmap.ACCESS_READ)
+ self.payload_file = io.BytesIO(payload_bytes)
+ else:
+ self.payload_file = payload_file
self.payload_file_offset = payload_file_offset
self.manifest_hasher = None
self.is_init = False
@@ -226,31 +237,6 @@ class Payload(object):
self.is_init = True
- def Describe(self):
- """Emits the payload embedded description data to standard output."""
- def _DescribeImageInfo(description, image_info):
- """Display info about the image."""
- def _DisplayIndentedValue(name, value):
- print(' {:<14} {}'.format(name+':', value))
-
- print('%s:' % description)
- _DisplayIndentedValue('Channel', image_info.channel)
- _DisplayIndentedValue('Board', image_info.board)
- _DisplayIndentedValue('Version', image_info.version)
- _DisplayIndentedValue('Key', image_info.key)
-
- if image_info.build_channel != image_info.channel:
- _DisplayIndentedValue('Build channel', image_info.build_channel)
-
- if image_info.build_version != image_info.version:
- _DisplayIndentedValue('Build version', image_info.build_version)
-
- if self.manifest.HasField('old_image_info'):
- _DescribeImageInfo('Old Image', self.manifest.old_image_info)
-
- if self.manifest.HasField('new_image_info'):
- _DescribeImageInfo('New Image', self.manifest.new_image_info)
-
def _AssertInit(self):
"""Raises an exception if the object was not initialized."""
if not self.is_init:
@@ -263,9 +249,7 @@ class Payload(object):
def IsDelta(self):
"""Returns True iff the payload appears to be a delta."""
self._AssertInit()
- return (self.manifest.HasField('old_kernel_info') or
- self.manifest.HasField('old_rootfs_info') or
- any(partition.HasField('old_partition_info')
+ return (any(partition.HasField('old_partition_info')
for partition in self.manifest.partitions))
def IsFull(self):