blob: 2f6a545ab6fd7066035495ac095607acbee0cd56 [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 Tam6db59cb2015-07-21 08:11:23 +080010import functools, logging, os, shutil, tempfile
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070011
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070012import common
13from autotest_lib.client.cros.faft.utils import (cgpt_state,
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +080014 cgpt_handler,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070015 chromeos_interface,
David Sodman3ad51642015-01-22 11:15:33 -080016 firmware_check_keys,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070017 firmware_updater,
18 flashrom_handler,
19 kernel_handler,
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +080020 rootfs_handler,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070021 saft_flashrom_util,
22 tpm_handler,
23 )
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070024
25
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080026def allow_multiple_section_input(image_operator):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080027 """Decorate a method to support multiple sections.
28
29 @param image_operator: Method accepting one section as its argument.
30 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080031 @functools.wraps(image_operator)
32 def wrapper(self, section):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080033 """Wrapper method to support multiple sections.
34
35 @param section: A list of sections of just a section.
36 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080037 if type(section) in (tuple, list):
38 for sec in section:
39 image_operator(self, sec)
40 else:
41 image_operator(self, section)
42 return wrapper
43
44
Vic Yang13d22ec2012-06-18 15:12:47 +080045class LazyFlashromHandlerProxy:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080046 """Proxy of FlashromHandler for lazy initialization."""
Vic Yang13d22ec2012-06-18 15:12:47 +080047 _loaded = False
48 _obj = None
49
50 def __init__(self, *args, **kargs):
51 self._args = args
52 self._kargs = kargs
53
54 def _load(self):
55 self._obj = flashrom_handler.FlashromHandler()
56 self._obj.init(*self._args, **self._kargs)
57 self._obj.new_image()
58 self._loaded = True
59
60 def __getattr__(self, name):
61 if not self._loaded:
62 self._load()
63 return getattr(self._obj, name)
64
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080065 def reload(self):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080066 """Reload the FlashromHandler class."""
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080067 self._loaded = False
68
Vic Yang13d22ec2012-06-18 15:12:47 +080069
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -070070class RPCFunctions(object):
71 """A class which aggregates some useful functions for firmware testing.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070072
73 This class can be exposed via a XMLRPC server such that its functions can
Chun-ting Changd43aa9b2012-11-16 10:12:05 +080074 be accessed remotely. Method naming should fit the naming rule
75 '_[categories]_[method_name]' where categories contains system, ec, bios,
76 kernel, cgpt, tpm, updater, etc. Methods should be called by
77 'FAFTClient.[categories].[method_name]', because _dispatch will rename
78 this name to '_[categories]_[method_name]'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070079
80 Attributes:
81 _chromeos_interface: An object to encapsulate OS services functions.
Vic Yang59cac9c2012-05-21 15:28:42 +080082 _bios_handler: An object to automate BIOS flashrom testing.
83 _ec_handler: An object to automate EC flashrom testing.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +080084 _ec_image: An object to automate EC image for autest.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070085 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080086 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070087 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080088 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080089 _temp_path: Path of a temp directory.
90 _keys_path: Path of a directory, keys/, in temp directory.
91 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070092 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070093 def __init__(self):
94 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070095 # TODO(waihong): Move the explicit object.init() methods to the
96 # objects' constructors (ChromeOSInterface, FlashromHandler,
97 # KernelHandler, and TpmHandler).
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +080098 self._chromeos_interface = chromeos_interface.ChromeOSInterface()
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +080099 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800100 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800101 self._chromeos_interface.init(state_dir)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +0800102 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800103
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800104 self._log_file = os.path.join(state_dir, 'faft_client.log')
105 logging.basicConfig(level=logging.DEBUG,
106 format='%(asctime)s %(levelname)s %(message)s',
107 filename=self._log_file)
108
Vic Yang13d22ec2012-06-18 15:12:47 +0800109 self._bios_handler = LazyFlashromHandlerProxy(
110 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800111 self._chromeos_interface,
112 None,
113 '/usr/share/vboot/devkeys',
114 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800115
Todd Brochf2b1d012012-06-14 12:55:21 -0700116 self._ec_handler = None
117 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800118 self._ec_handler = LazyFlashromHandlerProxy(
119 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700120 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800121 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700122 '/usr/share/vboot/devkeys',
123 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700124
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800125 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700126
127 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800128 # TODO(waihong): The dev_key_path is a new argument. We do that in
129 # order not to break the old image and still be able to run.
130 try:
131 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800132 dev_key_path='/usr/share/vboot/devkeys',
133 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800134 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800135 # Copy the key to the current working directory.
136 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800137 self._kernel_handler.init(self._chromeos_interface,
138 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700139
140 self._tpm_handler = tpm_handler.TpmHandler()
141 self._tpm_handler.init(self._chromeos_interface)
142
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800143 self._cgpt_handler = cgpt_handler.CgptHandler(self._chromeos_interface)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800144 self._cgpt_state = cgpt_state.CgptState(
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800145 'SHORT', self._chromeos_interface, self._system_get_root_dev(),
146 self._cgpt_handler)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800147
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800148 self._rootfs_handler = rootfs_handler.RootfsHandler()
149 self._rootfs_handler.init(self._chromeos_interface)
150
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700151 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
David Sodman3ad51642015-01-22 11:15:33 -0800152 self._check_keys = firmware_check_keys.firmwareCheckKeys()
Chun-ting Changcf924e92012-10-29 13:49:01 +0800153
ctchangc7e55ea2012-08-09 16:19:14 +0800154 # Initialize temporary directory path
155 self._temp_path = '/var/tmp/faft/autest'
156 self._keys_path = os.path.join(self._temp_path, 'keys')
157 self._work_path = os.path.join(self._temp_path, 'work')
158
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800159 def _dispatch(self, method, params):
160 """This _dispatch method handles string conversion especially.
161
162 Since we turn off allow_dotted_names option. So any string conversion,
163 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
164 via XML RPC call.
165 """
166 is_str = method.endswith('.__str__')
167 if is_str:
168 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800169
170 categories = ('system', 'bios', 'ec', 'kernel',
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800171 'tpm', 'cgpt', 'updater', 'rootfs')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800172 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800173 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800174 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
175 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800176 else:
177 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800178 except AttributeError:
179 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800180
181 if is_str:
182 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800183 else:
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800184 logging.debug('Dispatching method %s with args %s',
185 func.__name__, str(params))
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800186 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800187
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800188 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800189 """Function for polling the RPC server availability.
190
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800191 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800192 """
193 return True
194
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800195 def _system_dump_log(self, remove_log=False):
196 """Dump the log file.
197
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800198 @param remove_log: Remove the log file after dump.
199 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800200 """
201 log = open(self._log_file).read()
202 if remove_log:
203 os.remove(self._log_file)
204 return log
205
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800206 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700207 """Run shell command.
208
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800209 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700210 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700211 self._chromeos_interface.run_shell_command(command)
212
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800213 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700214 """Run shell command and get its console output.
215
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800216 @param command: A shell command to be run.
217 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700218 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700219 return self._chromeos_interface.run_shell_command_get_output(command)
220
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800221 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700222 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700223 self._chromeos_interface.run_shell_command('reboot')
224
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800225 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800226 """Get the platform name of the current system.
227
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800228 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800229 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800230 # 'mosys platform name' sometimes fails. Let's get the verbose output.
231 lines = self._chromeos_interface.run_shell_command_get_output(
232 '(mosys -vvv platform name 2>&1) || echo Failed')
233 if lines[-1].strip() == 'Failed':
234 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
235 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800236
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800237 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700238 """Get crossystem value of the requested key.
239
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800240 @param key: A crossystem key.
241 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700242 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700243 return self._chromeos_interface.run_shell_command_get_output(
244 'crossystem %s' % key)[0]
245
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800246 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800247 """Get the name of root device without partition number.
248
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800249 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800250 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800251 return self._chromeos_interface.get_root_dev()
252
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800253 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800254 """Get the name of root device with partition number.
255
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800256 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800257 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800258 return self._chromeos_interface.get_root_part()
259
Shelley Chen3edea982014-12-30 14:54:21 -0800260 def _system_set_try_fw_b(self, count=1):
261 """Set 'Try Frimware B' flag in crossystem.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700262
Shelley Chen3edea982014-12-30 14:54:21 -0800263 @param count: # times to try booting into FW B
264 """
265 self._chromeos_interface.cs.fwb_tries = count
266
267 def _system_set_fw_try_next(self, next, count=0):
268 """Set fw_try_next to A or B
269
270 @param next: Next FW to reboot to (A or B)
271 @param count: # of times to try booting into FW <next>
272 """
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700273 self._chromeos_interface.cs.fw_try_next = next
Shelley Chen3edea982014-12-30 14:54:21 -0800274 if count:
275 self._chromeos_interface.cs.fw_try_count = count
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700276
277 def _system_get_fw_vboot2(self):
278 """Get fw_vboot2"""
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800279 try:
280 return self._chromeos_interface.cs.fw_vboot2 == '1'
281 except chromeos_interface.ChromeOSInterfaceError:
282 return False
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700283
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800284 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800285 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800286 self._chromeos_interface.cs.request_recovery()
287
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800288 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800289 """Get dev_boot_usb value which controls developer mode boot from USB.
290
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800291 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800292 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800293 return self._chromeos_interface.cs.dev_boot_usb == '1'
294
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800295 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800296 """Set dev_boot_usb value which controls developer mode boot from USB.
297
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800298 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800299 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800300 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
301
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800302 def _system_is_removable_device_boot(self):
303 """Check the current boot device is removable.
304
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800305 @return: True: if a removable device boots.
306 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800307 """
308 root_part = self._chromeos_interface.get_root_part()
309 return self._chromeos_interface.is_removable_device(root_part)
310
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800311 def _system_create_temp_dir(self, prefix='backup_'):
312 """Create a temporary directory and return the path."""
313 return tempfile.mkdtemp(prefix=prefix)
314
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800315 def _bios_reload(self):
316 """Reload the firmware image that may be changed."""
317 self._bios_handler.reload()
318
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800319 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800320 """Get the GBB flags.
321
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800322 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800323 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800324 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800325
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800326 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800327 """Get the preamble flags of a firmware section.
328
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800329 @param section: A firmware section, either 'a' or 'b'.
330 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800331 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800332 return self._bios_handler.get_section_flags(section)
333
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800334 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800335 """Set the preamble flags of a firmware section.
336
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800337 @param section: A firmware section, either 'a' or 'b'.
338 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800339 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800340 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800341 self._bios_handler.set_section_version(section, version, flags,
342 write_through=True)
343
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800344 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800345 """Get SHA1 hash of BIOS RW firmware section.
346
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800347 @param section: A firmware section, either 'a' or 'b'.
348 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800349 """
350 return self._bios_handler.get_section_sha(section)
351
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800352 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800353 """Get SHA1 hash of firmware vblock in section."""
354 return self._bios_handler.get_section_sig_sha(section)
355
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800356 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800357 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800358 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700359
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800360 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700361 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800362 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700363
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800364 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800365 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800366 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700367
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800368 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700369 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800370 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700371
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800372 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800373 def _bios_corrupt_body(self, section):
374 """Corrupt the requested firmware section body.
375
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800376 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800377 """
378 self._bios_handler.corrupt_firmware_body(section)
379
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800380 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800381 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800382 """Restore the previously corrupted firmware section body.
383
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800384 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800385 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800386 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800387
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800388 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800389 """Modify firmware version for the requested section, by adding delta.
390
391 The passed in delta, a positive or a negative number, is added to the
392 original firmware version.
393 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800394 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800395 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800396 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800397 logging.info('Setting firmware section %s version from %d to %d',
398 section, original_version, new_version)
Vic Yang59cac9c2012-05-21 15:28:42 +0800399 self._bios_handler.set_section_version(section, new_version, flags,
400 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800401
402 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800403 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800404 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800405 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800406
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800407 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800408 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800409 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800410 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800411
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800412 def _bios_get_version(self, section):
413 """Retrieve firmware version of a section."""
414 return self._bios_handler.get_section_version(section)
415
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800416 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800417 """Return firmware data key version."""
418 return self._bios_handler.get_section_datakey_version(section)
419
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800420 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800421 """Return kernel subkey version."""
422 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800423
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800424 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800425 """Setup the new EC image for later update.
426
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800427 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800428 """
429 self._ec_image = flashrom_handler.FlashromHandler()
430 self._ec_image.init(saft_flashrom_util,
431 self._chromeos_interface,
432 'ec_root_key.vpubk',
433 '/usr/share/vboot/devkeys',
434 'ec')
435 self._ec_image.new_image(ec_path)
436
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800437 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800438 """Get SHA1 hash of RW firmware section of the EC autest image."""
439 return self._ec_image.get_section_sha('rw')
440
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800441 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800442 """Update EC via software sync design.
443
444 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800445 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800446 current AP firmware.
447
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800448 @param section: A firmware section on current BIOS, either 'a' or 'b'.
449 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800450 """
451 blob = self._ec_image.get_section_body('rw')
452 self._bios_handler.set_section_ecbin(section, blob,
453 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800454 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800455
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800456 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800457 """Dump the current BIOS firmware to a file, specified by bios_path.
458
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800459 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800460 """
461 self._bios_handler.dump_whole(bios_path)
462
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800463 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800464 """Dump the current BIOS firmware RW to dir_path.
465
466 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
467
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800468 @param dir_path: The path of directory which contains files to be
469 written.
ctchang38ae4922012-09-03 17:01:16 +0800470 """
471 if not os.path.isdir(dir_path):
472 raise Exception("%s doesn't exist" % dir_path)
473
474 VBOOTA_blob = self._bios_handler.get_section_sig('a')
475 VBOOTB_blob = self._bios_handler.get_section_sig('b')
476 FVMAIN_blob = self._bios_handler.get_section_body('a')
477 FVMAINB_blob = self._bios_handler.get_section_body('b')
478
479 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
480 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
481 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
482 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
483
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800484 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800485 """Write the firmware from bios_path to the current system.
486
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800487 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800488 """
489 self._bios_handler.new_image(bios_path)
490 self._bios_handler.write_whole()
491
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800492 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800493 """Write the firmware RW from dir_path to the current system.
494
495 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
496
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800497 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800498 """
499 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
500 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
501 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
502 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
503 raise Exception("Source firmware file(s) doesn't exist.")
504
505 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
506 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
507 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
508 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
509
510 self._bios_handler.set_section_sig('a', VBOOTA_blob,
511 write_through=True)
512 self._bios_handler.set_section_sig('b', VBOOTB_blob,
513 write_through=True)
514 self._bios_handler.set_section_body('a', FVMAIN_blob,
515 write_through=True)
516 self._bios_handler.set_section_body('b', FVMAINB_blob,
517 write_through=True)
518
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800519 def _ec_get_version(self):
520 """Get EC version via mosys.
521
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800522 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800523 """
524 return self._chromeos_interface.run_shell_command_get_output(
525 'mosys ec info | sed "s/.*| //"')[0]
526
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800527 def _ec_get_firmware_sha(self):
528 """Get SHA1 hash of EC RW firmware section."""
529 return self._ec_handler.get_section_sha('rw')
530
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800531 @allow_multiple_section_input
532 def _ec_corrupt_sig(self, section):
533 """Corrupt the requested EC section signature.
534
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800535 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800536 """
537 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
538
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800539 @allow_multiple_section_input
540 def _ec_restore_sig(self, section):
541 """Restore the previously corrupted EC section signature.
542
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800543 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800544 """
545 self._ec_handler.restore_firmware(section, restore_all=True)
546
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800547 @allow_multiple_section_input
548 def _ec_corrupt_body(self, section):
549 """Corrupt the requested EC section body.
550
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800551 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800552 """
553 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
554
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800555 @allow_multiple_section_input
556 def _ec_restore_body(self, section):
557 """Restore the previously corrupted EC section body.
558
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800559 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800560 """
561 self._ec_handler.restore_firmware_body(section, restore_all=True)
562
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800563 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800564 """Dump the current EC firmware to a file, specified by ec_path.
565
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800566 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800567 """
568 self._ec_handler.dump_whole(ec_path)
569
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800570 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800571 """Enable write protect of the EC flash chip.
572
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800573 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800574 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800575 if enable:
576 self._ec_handler.enable_write_protect()
577 else:
578 self._ec_handler.disable_write_protect()
579
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800580 @allow_multiple_section_input
581 def _kernel_corrupt_sig(self, section):
582 """Corrupt the requested kernel section.
583
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800584 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800585 """
586 self._kernel_handler.corrupt_kernel(section)
587
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800588 @allow_multiple_section_input
589 def _kernel_restore_sig(self, section):
590 """Restore the requested kernel section (previously corrupted).
591
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800592 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800593 """
594 self._kernel_handler.restore_kernel(section)
595
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800596 def __kernel_modify_version(self, section, delta):
597 """Modify kernel version for the requested section, by adding delta.
598
599 The passed in delta, a positive or a negative number, is added to the
600 original kernel version.
601 """
602 original_version = self._kernel_handler.get_version(section)
603 new_version = original_version + delta
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +0800604 logging.info('Setting kernel section %s version from %d to %d',
605 section, original_version, new_version)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800606 self._kernel_handler.set_version(section, new_version)
607
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800608 @allow_multiple_section_input
609 def _kernel_move_version_backward(self, section):
610 """Decrement kernel version for the requested section."""
611 self.__kernel_modify_version(section, -1)
612
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800613 @allow_multiple_section_input
614 def _kernel_move_version_forward(self, section):
615 """Increase kernel version for the requested section."""
616 self.__kernel_modify_version(section, 1)
617
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800618 def _kernel_get_version(self, section):
619 """Return kernel version."""
620 return self._kernel_handler.get_version(section)
621
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800622 def _kernel_get_datakey_version(self, section):
623 """Return kernel datakey version."""
624 return self._kernel_handler.get_datakey_version(section)
625
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800626 def _kernel_diff_a_b(self):
627 """Compare kernel A with B.
628
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800629 @return: True: if kernel A is different with B.
630 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800631 """
632 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800633 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
634 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800635
636 # The signature (some kind of hash) for the kernel body is stored in
637 # the beginning. So compare the first 64KB (including header, preamble,
638 # and signature) should be enough to check them identical.
639 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
640 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
641
642 return header_a != header_b
643
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800644 def _kernel_resign_with_keys(self, section, key_path=None):
645 """Resign kernel with temporary key."""
646 self._kernel_handler.resign_kernel(section, key_path)
647
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800648 def _kernel_dump(self, section, kernel_path):
649 """Dump the specified kernel to a file.
650
651 @param section: The kernel to dump. May be A or B.
652 @param kernel_path: The path to the kernel image to be written.
653 """
654 self._kernel_handler.dump_kernel(section, kernel_path)
655
656 def _kernel_write(self, section, kernel_path):
657 """Write a kernel image to the specified section.
658
659 @param section: The kernel to dump. May be A or B.
660 @param kernel_path: The path to the kernel image.
661 """
662 self._kernel_handler.write_kernel(section, kernel_path)
663
664 def _kernel_get_sha(self, section):
665 """Return the SHA1 hash of the specified kernel section."""
666 return self._kernel_handler.get_sha(section)
667
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800668 def _tpm_get_firmware_version(self):
669 """Retrieve tpm firmware body version."""
670 return self._tpm_handler.get_fw_version()
671
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800672 def _tpm_get_firmware_datakey_version(self):
673 """Retrieve tpm firmware data key version."""
674 return self._tpm_handler.get_fw_body_version()
675
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800676 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800677 """Run the CgptState test loop. The tst logic is handled in the client.
678
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800679 @return: 0: there are more cgpt tests to execute.
680 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800681 """
682 return self._cgpt_state.test_loop()
683
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800684 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800685 """Set the CgptState test step.
686
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800687 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800688 """
689 self._cgpt_state.set_step(step)
690
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800691 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800692 """Get the CgptState test step.
693
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800694 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800695 """
696 return self._cgpt_state.get_step()
697
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800698 def _cgpt_get_attributes(self):
699 """Get kernel attributes."""
700 rootdev = self._system_get_root_dev()
701 self._cgpt_handler.read_device_info(rootdev)
702 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
703 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
704
705 def _cgpt_set_attributes(self, attributes):
706 """Set kernel attributes."""
707 rootdev = self._system_get_root_dev()
708 allowed = ['priority', 'tries', 'successful']
709 for p in ('A', 'B'):
710 if p not in attributes:
711 continue
712 attr = dict()
713 for k in allowed:
714 if k in attributes[p]:
715 attr[k] = attributes[p][k]
716 if attr:
717 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
718
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800719 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800720 """Setup the updater.
721
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800722 @param shellball: Path of provided shellball. Use default shellball
723 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800724 """
725 self._updater.setup(self._chromeos_interface, shellball)
726
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800727 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800728 self._updater.cleanup_temp_dir()
729
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800730 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800731 """Retrieve shellball's fwid.
732
733 This method should be called after updater_setup.
734
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800735 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800736 """
737 return self._updater.retrieve_fwid()
738
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800739 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800740 """Resign firmware with version.
741
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800742 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800743 """
744 self._updater.resign_firmware(version)
745
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800746 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800747 """Repack shellball with new fwid.
748
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800749 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800750 """
751 self._updater.repack_shellball(append)
752
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800753 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800754 """Run chromeos-firmwareupdate with autoupdate mode."""
755 options = ['--noupdate_ec', '--nocheck_rw_compatible']
756 self._updater.run_firmwareupdate(mode='autoupdate',
757 updater_append=append,
758 options=options)
759
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800760 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800761 """Run chromeos-firmwareupdate with factory_install mode."""
762 options = ['--noupdate_ec']
763 self._updater.run_firmwareupdate(mode='factory_install',
764 options=options)
765
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800766 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800767 """Run chromeos-firmwareupdate with bootok mode."""
768 self._updater.run_firmwareupdate(mode='bootok',
769 updater_append=append)
770
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800771 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800772 """Run chromeos-firmwareupdate with recovery mode."""
773 options = ['--noupdate_ec', '--nocheck_rw_compatible']
774 self._updater.run_firmwareupdate(mode='recovery',
775 options=options)
776
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800777 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800778 """Get updater's temp directory path."""
779 return self._updater.get_temp_path()
780
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800781 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800782 """Get updater's keys directory path."""
783 return self._updater.get_keys_path()
784
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800785 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800786 """Get updater's work directory path."""
787 return self._updater.get_work_path()
788
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800789 def _rootfs_verify_rootfs(self, section):
790 """Verifies the integrity of the root FS.
791
792 @param section: The rootfs to verify. May be A or B.
793 """
794 return self._rootfs_handler.verify_rootfs(section)
795
David Sodman3ad51642015-01-22 11:15:33 -0800796 def _system_check_keys(self, expected_sequence):
797 """Check the keys sequence was as expected.
798
799 @param expected_sequence: A list of expected key sequences.
800 """
801 return self._check_keys.check_keys(expected_sequence)
802
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800803 def cleanup(self):
804 """Cleanup for the RPC server. Currently nothing."""
805 pass