blob: 4c4069618a9e94f82b3219cc7d5b84ff2c698fd8 [file] [log] [blame]
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -07001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -07005"""Code to provide functions for FAFT tests.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -07006
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -07007These can be exposed via a xmlrpci server running on the DUT.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -07008"""
9
Tom Wai-Hong Tam9434b142015-08-05 02:35:49 +080010import functools, os, tempfile
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070011
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070012import common
Tom Wai-Hong Tam533eed72015-07-31 07:37:27 +080013from autotest_lib.client.cros.faft.utils import (cgpt_handler,
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +080014 os_interface,
David Sodman3ad51642015-01-22 11:15:33 -080015 firmware_check_keys,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070016 firmware_updater,
17 flashrom_handler,
18 kernel_handler,
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +080019 rootfs_handler,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070020 saft_flashrom_util,
21 tpm_handler,
22 )
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070023
24
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080025def allow_multiple_section_input(image_operator):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080026 """Decorate a method to support multiple sections.
27
28 @param image_operator: Method accepting one section as its argument.
29 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080030 @functools.wraps(image_operator)
31 def wrapper(self, section):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080032 """Wrapper method to support multiple sections.
33
34 @param section: A list of sections of just a section.
35 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080036 if type(section) in (tuple, list):
37 for sec in section:
38 image_operator(self, sec)
39 else:
40 image_operator(self, section)
41 return wrapper
42
43
Vic Yang13d22ec2012-06-18 15:12:47 +080044class LazyFlashromHandlerProxy:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080045 """Proxy of FlashromHandler for lazy initialization."""
Vic Yang13d22ec2012-06-18 15:12:47 +080046 _loaded = False
47 _obj = None
48
49 def __init__(self, *args, **kargs):
50 self._args = args
51 self._kargs = kargs
52
53 def _load(self):
54 self._obj = flashrom_handler.FlashromHandler()
55 self._obj.init(*self._args, **self._kargs)
56 self._obj.new_image()
57 self._loaded = True
58
59 def __getattr__(self, name):
60 if not self._loaded:
61 self._load()
62 return getattr(self._obj, name)
63
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080064 def reload(self):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080065 """Reload the FlashromHandler class."""
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080066 self._loaded = False
67
Vic Yang13d22ec2012-06-18 15:12:47 +080068
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -070069class RPCFunctions(object):
70 """A class which aggregates some useful functions for firmware testing.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070071
72 This class can be exposed via a XMLRPC server such that its functions can
Chun-ting Changd43aa9b2012-11-16 10:12:05 +080073 be accessed remotely. Method naming should fit the naming rule
74 '_[categories]_[method_name]' where categories contains system, ec, bios,
75 kernel, cgpt, tpm, updater, etc. Methods should be called by
76 'FAFTClient.[categories].[method_name]', because _dispatch will rename
77 this name to '_[categories]_[method_name]'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070078
79 Attributes:
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +080080 _os_if: An object to encapsulate OS services functions.
Vic Yang59cac9c2012-05-21 15:28:42 +080081 _bios_handler: An object to automate BIOS flashrom testing.
82 _ec_handler: An object to automate EC flashrom testing.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070083 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080084 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070085 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080086 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080087 _temp_path: Path of a temp directory.
88 _keys_path: Path of a directory, keys/, in temp directory.
89 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070090 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070091 def __init__(self):
92 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070093 # TODO(waihong): Move the explicit object.init() methods to the
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +080094 # objects' constructors (OSInterface, FlashromHandler,
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070095 # KernelHandler, and TpmHandler).
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +080096 self._os_if = os_interface.OSInterface()
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +080097 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +080098 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +080099 self._log_file = os.path.join(state_dir, 'faft_client.log')
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800100 self._os_if.init(state_dir, log_file=self._log_file)
danny chan6dc580a2015-08-08 00:14:02 +0000101 os.chdir(state_dir)
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800102
Vic Yang13d22ec2012-06-18 15:12:47 +0800103 self._bios_handler = LazyFlashromHandlerProxy(
104 saft_flashrom_util,
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800105 self._os_if,
Vic Yang59cac9c2012-05-21 15:28:42 +0800106 None,
107 '/usr/share/vboot/devkeys',
108 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800109
Todd Brochf2b1d012012-06-14 12:55:21 -0700110 self._ec_handler = None
111 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800112 self._ec_handler = LazyFlashromHandlerProxy(
113 saft_flashrom_util,
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800114 self._os_if,
Vic Yang13d22ec2012-06-18 15:12:47 +0800115 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700116 '/usr/share/vboot/devkeys',
117 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700118
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700119 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam9434b142015-08-05 02:35:49 +0800120 self._kernel_handler.init(self._os_if,
121 dev_key_path='/usr/share/vboot/devkeys',
122 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700123
124 self._tpm_handler = tpm_handler.TpmHandler()
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800125 self._tpm_handler.init(self._os_if)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700126
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800127 self._cgpt_handler = cgpt_handler.CgptHandler(self._os_if)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800128
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800129 self._rootfs_handler = rootfs_handler.RootfsHandler()
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800130 self._rootfs_handler.init(self._os_if)
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800131
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800132 self._updater = firmware_updater.FirmwareUpdater(self._os_if)
David Sodman3ad51642015-01-22 11:15:33 -0800133 self._check_keys = firmware_check_keys.firmwareCheckKeys()
Chun-ting Changcf924e92012-10-29 13:49:01 +0800134
ctchangc7e55ea2012-08-09 16:19:14 +0800135 # Initialize temporary directory path
136 self._temp_path = '/var/tmp/faft/autest'
137 self._keys_path = os.path.join(self._temp_path, 'keys')
138 self._work_path = os.path.join(self._temp_path, 'work')
139
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800140 def _dispatch(self, method, params):
141 """This _dispatch method handles string conversion especially.
142
143 Since we turn off allow_dotted_names option. So any string conversion,
144 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
145 via XML RPC call.
146 """
147 is_str = method.endswith('.__str__')
148 if is_str:
149 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800150
151 categories = ('system', 'bios', 'ec', 'kernel',
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800152 'tpm', 'cgpt', 'updater', 'rootfs')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800153 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800154 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800155 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
156 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800157 else:
158 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800159 except AttributeError:
160 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800161
162 if is_str:
163 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800164 else:
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800165 self._os_if.log('Dispatching method %s with args %s' %
danny chan6dc580a2015-08-08 00:14:02 +0000166 (str(func), str(params)))
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800167 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800168
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800169 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800170 """Function for polling the RPC server availability.
171
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800172 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800173 """
174 return True
175
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800176 def _system_dump_log(self, remove_log=False):
177 """Dump the log file.
178
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800179 @param remove_log: Remove the log file after dump.
180 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800181 """
182 log = open(self._log_file).read()
183 if remove_log:
184 os.remove(self._log_file)
185 return log
186
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800187 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700188 """Run shell command.
189
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800190 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700191 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800192 self._os_if.run_shell_command(command)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700193
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800194 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700195 """Run shell command and get its console output.
196
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800197 @param command: A shell command to be run.
198 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700199 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800200 return self._os_if.run_shell_command_get_output(command)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700201
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800202 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700203 """Request software reboot."""
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800204 self._os_if.run_shell_command('reboot')
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700205
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800206 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800207 """Get the platform name of the current system.
208
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800209 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800210 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800211 # 'mosys platform name' sometimes fails. Let's get the verbose output.
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800212 lines = self._os_if.run_shell_command_get_output(
Vic Yang2bbb8672012-11-12 12:14:53 +0800213 '(mosys -vvv platform name 2>&1) || echo Failed')
214 if lines[-1].strip() == 'Failed':
215 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
216 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800217
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800218 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700219 """Get crossystem value of the requested key.
220
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800221 @param key: A crossystem key.
222 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700223 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800224 return self._os_if.run_shell_command_get_output(
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700225 'crossystem %s' % key)[0]
226
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800227 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800228 """Get the name of root device without partition number.
229
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800230 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800231 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800232 return self._os_if.get_root_dev()
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800233
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800234 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800235 """Get the name of root device with partition number.
236
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800237 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800238 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800239 return self._os_if.get_root_part()
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800240
Shelley Chen3edea982014-12-30 14:54:21 -0800241 def _system_set_try_fw_b(self, count=1):
242 """Set 'Try Frimware B' flag in crossystem.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700243
Shelley Chen3edea982014-12-30 14:54:21 -0800244 @param count: # times to try booting into FW B
245 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800246 self._os_if.cs.fwb_tries = count
Shelley Chen3edea982014-12-30 14:54:21 -0800247
248 def _system_set_fw_try_next(self, next, count=0):
249 """Set fw_try_next to A or B
250
251 @param next: Next FW to reboot to (A or B)
252 @param count: # of times to try booting into FW <next>
253 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800254 self._os_if.cs.fw_try_next = next
Shelley Chen3edea982014-12-30 14:54:21 -0800255 if count:
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800256 self._os_if.cs.fw_try_count = count
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700257
258 def _system_get_fw_vboot2(self):
259 """Get fw_vboot2"""
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800260 try:
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800261 return self._os_if.cs.fw_vboot2 == '1'
262 except os_interface.OSInterfaceError:
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800263 return False
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700264
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800265 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800266 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800267 self._os_if.cs.request_recovery()
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800268
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800269 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800270 """Get dev_boot_usb value which controls developer mode boot from USB.
271
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800272 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800273 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800274 return self._os_if.cs.dev_boot_usb == '1'
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800275
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800276 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800277 """Set dev_boot_usb value which controls developer mode boot from USB.
278
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800279 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800280 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800281 self._os_if.cs.dev_boot_usb = 1 if value else 0
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800282
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800283 def _system_is_removable_device_boot(self):
284 """Check the current boot device is removable.
285
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800286 @return: True: if a removable device boots.
287 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800288 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800289 root_part = self._os_if.get_root_part()
290 return self._os_if.is_removable_device(root_part)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800291
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800292 def _system_create_temp_dir(self, prefix='backup_'):
293 """Create a temporary directory and return the path."""
294 return tempfile.mkdtemp(prefix=prefix)
295
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800296 def _bios_reload(self):
297 """Reload the firmware image that may be changed."""
298 self._bios_handler.reload()
299
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800300 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800301 """Get the GBB flags.
302
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800303 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800304 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800305 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800306
Tom Wai-Hong Tam0d2b8932015-08-27 06:22:50 +0800307 def _bios_set_gbb_flags(self, flags):
308 """Set the GBB flags.
309
310 @param flags: An integer of the GBB flags.
311 """
312 self._bios_handler.set_gbb_flags(flags, write_through=True)
313
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800314 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800315 """Get the preamble flags of a firmware section.
316
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800317 @param section: A firmware section, either 'a' or 'b'.
318 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800319 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800320 return self._bios_handler.get_section_flags(section)
321
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800322 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800323 """Set the preamble flags of a firmware section.
324
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800325 @param section: A firmware section, either 'a' or 'b'.
326 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800327 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800328 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800329 self._bios_handler.set_section_version(section, version, flags,
330 write_through=True)
331
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800332 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800333 """Get SHA1 hash of BIOS RW firmware section.
334
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800335 @param section: A firmware section, either 'a' or 'b'.
336 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800337 """
338 return self._bios_handler.get_section_sha(section)
339
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800340 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800341 """Get SHA1 hash of firmware vblock in section."""
342 return self._bios_handler.get_section_sig_sha(section)
343
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800344 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800345 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800346 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700347
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800348 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700349 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800350 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700351
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800352 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800353 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800354 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700355
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800356 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700357 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800358 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700359
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800360 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800361 def _bios_corrupt_body(self, section):
362 """Corrupt the requested firmware section body.
363
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800364 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800365 """
366 self._bios_handler.corrupt_firmware_body(section)
367
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800368 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800369 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800370 """Restore the previously corrupted firmware section body.
371
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800372 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800373 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800374 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800375
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800376 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800377 """Modify firmware version for the requested section, by adding delta.
378
379 The passed in delta, a positive or a negative number, is added to the
380 original firmware version.
381 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800382 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800383 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800384 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800385 self._os_if.log(
danny chan6dc580a2015-08-08 00:14:02 +0000386 'Setting firmware section %s version from %d to %d' % (
387 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800388 self._bios_handler.set_section_version(section, new_version, flags,
389 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800390
391 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800392 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800393 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800394 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800395
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800396 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800397 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800398 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800399 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800400
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800401 def _bios_get_version(self, section):
402 """Retrieve firmware version of a section."""
403 return self._bios_handler.get_section_version(section)
404
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800405 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800406 """Return firmware data key version."""
407 return self._bios_handler.get_section_datakey_version(section)
408
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800409 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800410 """Return kernel subkey version."""
411 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800412
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800413 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800414 """Dump the current BIOS firmware to a file, specified by bios_path.
415
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800416 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800417 """
418 self._bios_handler.dump_whole(bios_path)
419
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800420 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800421 """Dump the current BIOS firmware RW to dir_path.
422
423 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
424
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800425 @param dir_path: The path of directory which contains files to be
426 written.
ctchang38ae4922012-09-03 17:01:16 +0800427 """
428 if not os.path.isdir(dir_path):
429 raise Exception("%s doesn't exist" % dir_path)
430
431 VBOOTA_blob = self._bios_handler.get_section_sig('a')
432 VBOOTB_blob = self._bios_handler.get_section_sig('b')
433 FVMAIN_blob = self._bios_handler.get_section_body('a')
434 FVMAINB_blob = self._bios_handler.get_section_body('b')
435
436 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
437 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
438 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
439 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
440
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800441 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800442 """Write the firmware from bios_path to the current system.
443
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800444 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800445 """
446 self._bios_handler.new_image(bios_path)
447 self._bios_handler.write_whole()
448
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800449 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800450 """Write the firmware RW from dir_path to the current system.
451
452 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
453
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800454 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800455 """
456 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
457 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
458 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
459 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
460 raise Exception("Source firmware file(s) doesn't exist.")
461
462 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
463 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
464 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
465 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
466
467 self._bios_handler.set_section_sig('a', VBOOTA_blob,
468 write_through=True)
469 self._bios_handler.set_section_sig('b', VBOOTB_blob,
470 write_through=True)
471 self._bios_handler.set_section_body('a', FVMAIN_blob,
472 write_through=True)
473 self._bios_handler.set_section_body('b', FVMAINB_blob,
474 write_through=True)
475
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800476 def _ec_get_version(self):
477 """Get EC version via mosys.
478
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800479 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800480 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800481 return self._os_if.run_shell_command_get_output(
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800482 'mosys ec info | sed "s/.*| //"')[0]
483
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800484 def _ec_get_firmware_sha(self):
485 """Get SHA1 hash of EC RW firmware section."""
486 return self._ec_handler.get_section_sha('rw')
487
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800488 @allow_multiple_section_input
489 def _ec_corrupt_sig(self, section):
490 """Corrupt the requested EC section signature.
491
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800492 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800493 """
494 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
495
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800496 @allow_multiple_section_input
497 def _ec_restore_sig(self, section):
498 """Restore the previously corrupted EC section signature.
499
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800500 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800501 """
502 self._ec_handler.restore_firmware(section, restore_all=True)
503
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800504 @allow_multiple_section_input
505 def _ec_corrupt_body(self, section):
506 """Corrupt the requested EC section body.
507
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800508 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800509 """
510 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
511
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800512 @allow_multiple_section_input
513 def _ec_restore_body(self, section):
514 """Restore the previously corrupted EC section body.
515
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800516 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800517 """
518 self._ec_handler.restore_firmware_body(section, restore_all=True)
519
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800520 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800521 """Dump the current EC firmware to a file, specified by ec_path.
522
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800523 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800524 """
525 self._ec_handler.dump_whole(ec_path)
526
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800527 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800528 """Enable write protect of the EC flash chip.
529
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800530 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800531 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800532 if enable:
533 self._ec_handler.enable_write_protect()
534 else:
535 self._ec_handler.disable_write_protect()
536
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800537 @allow_multiple_section_input
538 def _kernel_corrupt_sig(self, section):
539 """Corrupt the requested kernel section.
540
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800541 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800542 """
543 self._kernel_handler.corrupt_kernel(section)
544
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800545 @allow_multiple_section_input
546 def _kernel_restore_sig(self, section):
547 """Restore the requested kernel section (previously corrupted).
548
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800549 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800550 """
551 self._kernel_handler.restore_kernel(section)
552
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800553 def __kernel_modify_version(self, section, delta):
554 """Modify kernel version for the requested section, by adding delta.
555
556 The passed in delta, a positive or a negative number, is added to the
557 original kernel version.
558 """
559 original_version = self._kernel_handler.get_version(section)
560 new_version = original_version + delta
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800561 self._os_if.log(
danny chan6dc580a2015-08-08 00:14:02 +0000562 'Setting kernel section %s version from %d to %d' % (
563 section, original_version, new_version))
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800564 self._kernel_handler.set_version(section, new_version)
565
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800566 @allow_multiple_section_input
567 def _kernel_move_version_backward(self, section):
568 """Decrement kernel version for the requested section."""
569 self.__kernel_modify_version(section, -1)
570
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800571 @allow_multiple_section_input
572 def _kernel_move_version_forward(self, section):
573 """Increase kernel version for the requested section."""
574 self.__kernel_modify_version(section, 1)
575
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800576 def _kernel_get_version(self, section):
577 """Return kernel version."""
578 return self._kernel_handler.get_version(section)
579
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800580 def _kernel_get_datakey_version(self, section):
581 """Return kernel datakey version."""
582 return self._kernel_handler.get_datakey_version(section)
583
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800584 def _kernel_diff_a_b(self):
585 """Compare kernel A with B.
586
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800587 @return: True: if kernel A is different with B.
588 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800589 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800590 rootdev = self._os_if.get_root_dev()
591 kernel_a = self._os_if.join_part(rootdev, '2')
592 kernel_b = self._os_if.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800593
594 # The signature (some kind of hash) for the kernel body is stored in
595 # the beginning. So compare the first 64KB (including header, preamble,
596 # and signature) should be enough to check them identical.
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800597 header_a = self._os_if.read_partition(kernel_a, 0x10000)
598 header_b = self._os_if.read_partition(kernel_b, 0x10000)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800599
600 return header_a != header_b
601
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800602 def _kernel_resign_with_keys(self, section, key_path=None):
603 """Resign kernel with temporary key."""
604 self._kernel_handler.resign_kernel(section, key_path)
605
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800606 def _kernel_dump(self, section, kernel_path):
607 """Dump the specified kernel to a file.
608
609 @param section: The kernel to dump. May be A or B.
610 @param kernel_path: The path to the kernel image to be written.
611 """
612 self._kernel_handler.dump_kernel(section, kernel_path)
613
614 def _kernel_write(self, section, kernel_path):
615 """Write a kernel image to the specified section.
616
617 @param section: The kernel to dump. May be A or B.
618 @param kernel_path: The path to the kernel image.
619 """
620 self._kernel_handler.write_kernel(section, kernel_path)
621
622 def _kernel_get_sha(self, section):
623 """Return the SHA1 hash of the specified kernel section."""
624 return self._kernel_handler.get_sha(section)
625
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800626 def _tpm_get_firmware_version(self):
627 """Retrieve tpm firmware body version."""
628 return self._tpm_handler.get_fw_version()
629
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800630 def _tpm_get_firmware_datakey_version(self):
631 """Retrieve tpm firmware data key version."""
632 return self._tpm_handler.get_fw_body_version()
633
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800634 def _cgpt_get_attributes(self):
635 """Get kernel attributes."""
636 rootdev = self._system_get_root_dev()
637 self._cgpt_handler.read_device_info(rootdev)
638 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
639 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
640
641 def _cgpt_set_attributes(self, attributes):
642 """Set kernel attributes."""
643 rootdev = self._system_get_root_dev()
644 allowed = ['priority', 'tries', 'successful']
645 for p in ('A', 'B'):
646 if p not in attributes:
647 continue
648 attr = dict()
649 for k in allowed:
650 if k in attributes[p]:
651 attr[k] = attributes[p][k]
652 if attr:
653 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
654
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800655 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800656 """Setup the updater.
657
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800658 @param shellball: Path of provided shellball. Use default shellball
659 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800660 """
Tom Wai-Hong Tamba5e3e52015-08-01 05:54:00 +0800661 self._updater.setup(self._os_if, shellball)
Chun-ting Changcf924e92012-10-29 13:49:01 +0800662
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800663 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800664 self._updater.cleanup_temp_dir()
665
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800666 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800667 """Retrieve shellball's fwid.
668
669 This method should be called after updater_setup.
670
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800671 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800672 """
673 return self._updater.retrieve_fwid()
674
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800675 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800676 """Resign firmware with version.
677
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800678 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800679 """
680 self._updater.resign_firmware(version)
681
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800682 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800683 """Repack shellball with new fwid.
684
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800685 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800686 """
687 self._updater.repack_shellball(append)
688
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800689 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800690 """Run chromeos-firmwareupdate with autoupdate mode."""
691 options = ['--noupdate_ec', '--nocheck_rw_compatible']
692 self._updater.run_firmwareupdate(mode='autoupdate',
693 updater_append=append,
694 options=options)
695
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800696 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800697 """Run chromeos-firmwareupdate with factory_install mode."""
698 options = ['--noupdate_ec']
699 self._updater.run_firmwareupdate(mode='factory_install',
700 options=options)
701
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800702 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800703 """Run chromeos-firmwareupdate with bootok mode."""
704 self._updater.run_firmwareupdate(mode='bootok',
705 updater_append=append)
706
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800707 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800708 """Run chromeos-firmwareupdate with recovery mode."""
709 options = ['--noupdate_ec', '--nocheck_rw_compatible']
710 self._updater.run_firmwareupdate(mode='recovery',
711 options=options)
712
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800713 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800714 """Get updater's temp directory path."""
715 return self._updater.get_temp_path()
716
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800717 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800718 """Get updater's keys directory path."""
719 return self._updater.get_keys_path()
720
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800721 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800722 """Get updater's work directory path."""
723 return self._updater.get_work_path()
724
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800725 def _rootfs_verify_rootfs(self, section):
726 """Verifies the integrity of the root FS.
727
728 @param section: The rootfs to verify. May be A or B.
729 """
730 return self._rootfs_handler.verify_rootfs(section)
731
David Sodman3ad51642015-01-22 11:15:33 -0800732 def _system_check_keys(self, expected_sequence):
733 """Check the keys sequence was as expected.
734
735 @param expected_sequence: A list of expected key sequences.
736 """
737 return self._check_keys.check_keys(expected_sequence)
738
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800739 def cleanup(self):
740 """Cleanup for the RPC server. Currently nothing."""
741 pass