summaryrefslogtreecommitdiff
path: root/scripts/update_payload/common.py
diff options
context:
space:
mode:
authorTianjie <xunchang@google.com>2020-06-19 00:22:59 -0700
committerTianjie <xunchang@google.com>2020-07-06 11:24:36 -0700
commit55abd3cbae6bd150b3534728a63befd1cadd6c5e (patch)
tree0077b57b1ef96c194380908311ce2a993fb1a89c /scripts/update_payload/common.py
parent99d570d67bd5dab11de321068c4002ab76ae774a (diff)
parent694eeb0dece40f88e11ece3a776d995d855be79b (diff)
Merge remote-tracking branch 'aosp/upstream-master' into merge
It's a merge from chrome OS with some reverts. 1. the fd watcher change, because the libbrillo version isn't compatible in aosp. commit 6955bcc4ffe4cc9d62a88186b9a7e75d095a7897 commit 493fecb3f48c8478fd3ef244d631d857730dd14d 2. two libcurl unittest. Because the RunOnce() of the fake message loop seems to have different behavior in aosp. commit d3d84218cafbc1a95e7d6bbb775b495d1bebf4d2 Put preprocessor guards to use the old code in aosp. And we can switch to the new code in the other path after adopting the new libbrillo & libchrome. Test: unit tests pass, apply an OTA Change-Id: Id613599834b0f44f92841dbeae6303601db5490d
Diffstat (limited to 'scripts/update_payload/common.py')
-rw-r--r--scripts/update_payload/common.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/scripts/update_payload/common.py b/scripts/update_payload/common.py
index 9061a754..b934cf88 100644
--- a/scripts/update_payload/common.py
+++ b/scripts/update_payload/common.py
@@ -16,8 +16,11 @@
"""Utilities for update payload processing."""
+from __future__ import absolute_import
from __future__ import print_function
+import base64
+
from update_payload import update_metadata_pb2
from update_payload.error import PayloadError
@@ -25,18 +28,14 @@ from update_payload.error import PayloadError
#
# Constants.
#
-PSEUDO_EXTENT_MARKER = (1L << 64) - 1 # UINT64_MAX
-
SIG_ASN1_HEADER = (
- '\x30\x31\x30\x0d\x06\x09\x60\x86'
- '\x48\x01\x65\x03\x04\x02\x01\x05'
- '\x00\x04\x20'
+ b'\x30\x31\x30\x0d\x06\x09\x60\x86'
+ b'\x48\x01\x65\x03\x04\x02\x01\x05'
+ b'\x00\x04\x20'
)
-CHROMEOS_MAJOR_PAYLOAD_VERSION = 1
BRILLO_MAJOR_PAYLOAD_VERSION = 2
-INPLACE_MINOR_PAYLOAD_VERSION = 1
SOURCE_MINOR_PAYLOAD_VERSION = 2
OPSRCHASH_MINOR_PAYLOAD_VERSION = 3
BROTLI_BSDIFF_MINOR_PAYLOAD_VERSION = 4
@@ -47,6 +46,7 @@ ROOTFS = 'root'
# Tuple of (name in system, name in protobuf).
CROS_PARTITIONS = ((KERNEL, KERNEL), (ROOTFS, 'rootfs'))
+
#
# Payload operation types.
#
@@ -55,8 +55,6 @@ class OpType(object):
_CLASS = update_metadata_pb2.InstallOperation
REPLACE = _CLASS.REPLACE
REPLACE_BZ = _CLASS.REPLACE_BZ
- MOVE = _CLASS.MOVE
- BSDIFF = _CLASS.BSDIFF
SOURCE_COPY = _CLASS.SOURCE_COPY
SOURCE_BSDIFF = _CLASS.SOURCE_BSDIFF
ZERO = _CLASS.ZERO
@@ -64,13 +62,11 @@ class OpType(object):
REPLACE_XZ = _CLASS.REPLACE_XZ
PUFFDIFF = _CLASS.PUFFDIFF
BROTLI_BSDIFF = _CLASS.BROTLI_BSDIFF
- ALL = (REPLACE, REPLACE_BZ, MOVE, BSDIFF, SOURCE_COPY, SOURCE_BSDIFF, ZERO,
+ ALL = (REPLACE, REPLACE_BZ, SOURCE_COPY, SOURCE_BSDIFF, ZERO,
DISCARD, REPLACE_XZ, PUFFDIFF, BROTLI_BSDIFF)
NAMES = {
REPLACE: 'REPLACE',
REPLACE_BZ: 'REPLACE_BZ',
- MOVE: 'MOVE',
- BSDIFF: 'BSDIFF',
SOURCE_COPY: 'SOURCE_COPY',
SOURCE_BSDIFF: 'SOURCE_BSDIFF',
ZERO: 'ZERO',
@@ -146,7 +142,7 @@ def Read(file_obj, length, offset=None, hasher=None):
try:
data = file_obj.read(length)
- except IOError, e:
+ except IOError as e:
raise PayloadError('error reading from file (%s): %s' % (file_obj.name, e))
if len(data) != length:
@@ -167,13 +163,12 @@ def FormatExtent(ex, block_size=0):
end_block = ex.start_block + ex.num_blocks
if block_size:
return '%d->%d * %d' % (ex.start_block, end_block, block_size)
- else:
- return '%d->%d' % (ex.start_block, end_block)
+ return '%d->%d' % (ex.start_block, end_block)
def FormatSha256(digest):
"""Returns a canonical string representation of a SHA256 digest."""
- return digest.encode('base64').strip()
+ return base64.b64encode(digest).decode('utf-8')
#