summaryrefslogtreecommitdiff
path: root/scripts/update_device.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/update_device.py')
-rwxr-xr-xscripts/update_device.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/scripts/update_device.py b/scripts/update_device.py
index 371a89a8..354972b7 100755
--- a/scripts/update_device.py
+++ b/scripts/update_device.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/env python
#
# Copyright (C) 2017 The Android Open Source Project
#
@@ -17,8 +17,10 @@
"""Send an A/B update to an Android device over adb."""
+from __future__ import print_function
+from __future__ import absolute_import
+
import argparse
-import BaseHTTPServer
import binascii
import hashlib
import logging
@@ -31,6 +33,8 @@ import threading
import xml.etree.ElementTree
import zipfile
+from six.moves import BaseHTTPServer
+
import update_payload.payload
@@ -43,6 +47,7 @@ PAYLOAD_KEY_PATH = '/etc/update_engine/update-payload-key.pub.pem'
# The port on the device that update_engine should connect to.
DEVICE_PORT = 1234
+
def CopyFileObjLength(fsrc, fdst, buffer_size=128 * 1024, copy_length=None):
"""Copy from a file object to another.
@@ -99,7 +104,7 @@ class AndroidOTAPackage(object):
if payload_info.compress_type != 0:
logging.error(
- "Expected layload to be uncompressed, got compression method %d",
+ "Expected payload to be uncompressed, got compression method %d",
payload_info.compress_type)
# Don't use len(payload_info.extra). Because that returns size of extra
# fields in central directory. We need to look at local file directory,
@@ -120,10 +125,10 @@ class AndroidOTAPackage(object):
payload_header = fp.read(4)
if payload_header != self.PAYLOAD_MAGIC_HEADER:
logging.warning(
- "Invalid header, expeted %s, got %s."
+ "Invalid header, expected %s, got %s."
"Either the offset is not correct, or payload is corrupted",
binascii.hexlify(self.PAYLOAD_MAGIC_HEADER),
- payload_header)
+ binascii.hexlify(payload_header))
property_entry = (self.SECONDARY_OTA_PAYLOAD_PROPERTIES_TXT if
secondary_payload else self.OTA_PAYLOAD_PROPERTIES_TXT)
@@ -164,7 +169,6 @@ class UpdateHandler(BaseHTTPServer.BaseHTTPRequestHandler):
start_range = file_size - int(e)
return start_range, end_range
-
def do_GET(self): # pylint: disable=invalid-name
"""Reply with the requested payload file."""
if self.path != '/payload':
@@ -207,7 +211,6 @@ class UpdateHandler(BaseHTTPServer.BaseHTTPRequestHandler):
f.seek(serving_start + start_range)
CopyFileObjLength(f, self.wfile, copy_length=end_range - start_range)
-
def do_POST(self): # pylint: disable=invalid-name
"""Reply with the omaha response xml."""
if self.path != '/update':
@@ -303,6 +306,7 @@ class ServerThread(threading.Thread):
logging.info('Server Terminated')
def StopServer(self):
+ self._httpd.shutdown()
self._httpd.socket.close()
@@ -316,13 +320,13 @@ def AndroidUpdateCommand(ota_filename, secondary, payload_url, extra_headers):
"""Return the command to run to start the update in the Android device."""
ota = AndroidOTAPackage(ota_filename, secondary)
headers = ota.properties
- headers += 'USER_AGENT=Dalvik (something, something)\n'
- headers += 'NETWORK_ID=0\n'
- headers += extra_headers
+ headers += b'USER_AGENT=Dalvik (something, something)\n'
+ headers += b'NETWORK_ID=0\n'
+ headers += extra_headers.encode()
return ['update_engine_client', '--update', '--follow',
'--payload=%s' % payload_url, '--offset=%d' % ota.offset,
- '--size=%d' % ota.size, '--headers="%s"' % headers]
+ '--size=%d' % ota.size, '--headers="%s"' % headers.decode()]
def OmahaUpdateCommand(omaha_url):
@@ -399,6 +403,8 @@ def main():
help='Extra headers to pass to the device.')
parser.add_argument('--secondary', action='store_true',
help='Update with the secondary payload in the package.')
+ parser.add_argument('--no-slot-switch', action='store_true',
+ help='Do not perform slot switch after the update.')
args = parser.parse_args()
logging.basicConfig(
level=logging.WARNING if args.no_verbose else logging.INFO)
@@ -416,6 +422,9 @@ def main():
help_cmd = ['shell', 'su', '0', 'update_engine_client', '--help']
use_omaha = 'omaha' in dut.adb_output(help_cmd)
+ if args.no_slot_switch:
+ args.extra_headers += "\nSWITCH_SLOT_ON_REBOOT=0"
+
if args.file:
# Update via pushing a file to /data.
device_ota_file = os.path.join(OTA_PACKAGE_PATH, 'debug.zip')
@@ -478,5 +487,6 @@ def main():
return 0
+
if __name__ == '__main__':
sys.exit(main())