blob: 05408c9cab2629a4b8c67ed092714aa427574fd3 [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 Tam144202a2013-07-18 13:59:29 +080010import functools, 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).
98 self._chromeos_interface = chromeos_interface.ChromeOSInterface(False)
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 Tam48ae2212013-06-26 10:37:40 +0800101 self._log_file = os.path.join(state_dir, 'faft_client.log')
102 self._chromeos_interface.init(state_dir, log_file=self._log_file)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +0800103 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800104
Vic Yang13d22ec2012-06-18 15:12:47 +0800105 self._bios_handler = LazyFlashromHandlerProxy(
106 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800107 self._chromeos_interface,
108 None,
109 '/usr/share/vboot/devkeys',
110 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800111
Todd Brochf2b1d012012-06-14 12:55:21 -0700112 self._ec_handler = None
113 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800114 self._ec_handler = LazyFlashromHandlerProxy(
115 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700116 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800117 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700118 '/usr/share/vboot/devkeys',
119 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700120
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800121 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700122
123 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800124 # TODO(waihong): The dev_key_path is a new argument. We do that in
125 # order not to break the old image and still be able to run.
126 try:
127 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800128 dev_key_path='/usr/share/vboot/devkeys',
129 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800130 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800131 # Copy the key to the current working directory.
132 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800133 self._kernel_handler.init(self._chromeos_interface,
134 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700135
136 self._tpm_handler = tpm_handler.TpmHandler()
137 self._tpm_handler.init(self._chromeos_interface)
138
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800139 self._cgpt_handler = cgpt_handler.CgptHandler(self._chromeos_interface)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800140 self._cgpt_state = cgpt_state.CgptState(
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800141 'SHORT', self._chromeos_interface, self._system_get_root_dev(),
142 self._cgpt_handler)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800143
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800144 self._rootfs_handler = rootfs_handler.RootfsHandler()
145 self._rootfs_handler.init(self._chromeos_interface)
146
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700147 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
David Sodman3ad51642015-01-22 11:15:33 -0800148 self._check_keys = firmware_check_keys.firmwareCheckKeys()
Chun-ting Changcf924e92012-10-29 13:49:01 +0800149
ctchangc7e55ea2012-08-09 16:19:14 +0800150 # Initialize temporary directory path
151 self._temp_path = '/var/tmp/faft/autest'
152 self._keys_path = os.path.join(self._temp_path, 'keys')
153 self._work_path = os.path.join(self._temp_path, 'work')
154
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800155 def _dispatch(self, method, params):
156 """This _dispatch method handles string conversion especially.
157
158 Since we turn off allow_dotted_names option. So any string conversion,
159 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
160 via XML RPC call.
161 """
162 is_str = method.endswith('.__str__')
163 if is_str:
164 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800165
166 categories = ('system', 'bios', 'ec', 'kernel',
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800167 'tpm', 'cgpt', 'updater', 'rootfs')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800168 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800169 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800170 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
171 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800172 else:
173 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800174 except AttributeError:
175 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800176
177 if is_str:
178 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800179 else:
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800180 self._chromeos_interface.log('Dispatching method %s with args %s' %
181 (str(func), str(params)))
182 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800183
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800184 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800185 """Function for polling the RPC server availability.
186
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800187 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800188 """
189 return True
190
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800191 def _system_dump_log(self, remove_log=False):
192 """Dump the log file.
193
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800194 @param remove_log: Remove the log file after dump.
195 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800196 """
197 log = open(self._log_file).read()
198 if remove_log:
199 os.remove(self._log_file)
200 return log
201
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800202 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700203 """Run shell command.
204
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800205 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700206 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700207 self._chromeos_interface.run_shell_command(command)
208
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800209 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700210 """Run shell command and get its console output.
211
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800212 @param command: A shell command to be run.
213 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700214 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700215 return self._chromeos_interface.run_shell_command_get_output(command)
216
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800217 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700218 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700219 self._chromeos_interface.run_shell_command('reboot')
220
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800221 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800222 """Get the platform name of the current system.
223
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800224 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800225 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800226 # 'mosys platform name' sometimes fails. Let's get the verbose output.
227 lines = self._chromeos_interface.run_shell_command_get_output(
228 '(mosys -vvv platform name 2>&1) || echo Failed')
229 if lines[-1].strip() == 'Failed':
230 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
231 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800232
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800233 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700234 """Get crossystem value of the requested key.
235
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800236 @param key: A crossystem key.
237 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700238 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700239 return self._chromeos_interface.run_shell_command_get_output(
240 'crossystem %s' % key)[0]
241
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800242 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800243 """Get the name of root device without partition number.
244
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800245 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800246 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800247 return self._chromeos_interface.get_root_dev()
248
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800249 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800250 """Get the name of root device with partition number.
251
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800252 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800253 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800254 return self._chromeos_interface.get_root_part()
255
Shelley Chen3edea982014-12-30 14:54:21 -0800256 def _system_set_try_fw_b(self, count=1):
257 """Set 'Try Frimware B' flag in crossystem.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700258
Shelley Chen3edea982014-12-30 14:54:21 -0800259 @param count: # times to try booting into FW B
260 """
261 self._chromeos_interface.cs.fwb_tries = count
262
263 def _system_set_fw_try_next(self, next, count=0):
264 """Set fw_try_next to A or B
265
266 @param next: Next FW to reboot to (A or B)
267 @param count: # of times to try booting into FW <next>
268 """
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700269 self._chromeos_interface.cs.fw_try_next = next
Shelley Chen3edea982014-12-30 14:54:21 -0800270 if count:
271 self._chromeos_interface.cs.fw_try_count = count
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700272
273 def _system_get_fw_vboot2(self):
274 """Get fw_vboot2"""
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800275 try:
276 return self._chromeos_interface.cs.fw_vboot2 == '1'
277 except chromeos_interface.ChromeOSInterfaceError:
278 return False
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700279
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800280 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800281 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800282 self._chromeos_interface.cs.request_recovery()
283
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800284 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800285 """Get dev_boot_usb value which controls developer mode boot from USB.
286
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800287 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800288 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800289 return self._chromeos_interface.cs.dev_boot_usb == '1'
290
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800291 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800292 """Set dev_boot_usb value which controls developer mode boot from USB.
293
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800294 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800295 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800296 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
297
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800298 def _system_is_removable_device_boot(self):
299 """Check the current boot device is removable.
300
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800301 @return: True: if a removable device boots.
302 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800303 """
304 root_part = self._chromeos_interface.get_root_part()
305 return self._chromeos_interface.is_removable_device(root_part)
306
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800307 def _system_create_temp_dir(self, prefix='backup_'):
308 """Create a temporary directory and return the path."""
309 return tempfile.mkdtemp(prefix=prefix)
310
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800311 def _bios_reload(self):
312 """Reload the firmware image that may be changed."""
313 self._bios_handler.reload()
314
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800315 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800316 """Get the GBB flags.
317
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800318 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800319 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800320 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800321
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800322 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800323 """Get 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 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800327 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800328 return self._bios_handler.get_section_flags(section)
329
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800330 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800331 """Set the preamble flags of a firmware section.
332
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800333 @param section: A firmware section, either 'a' or 'b'.
334 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800335 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800336 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800337 self._bios_handler.set_section_version(section, version, flags,
338 write_through=True)
339
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800340 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800341 """Get SHA1 hash of BIOS RW firmware section.
342
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800343 @param section: A firmware section, either 'a' or 'b'.
344 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800345 """
346 return self._bios_handler.get_section_sha(section)
347
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800348 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800349 """Get SHA1 hash of firmware vblock in section."""
350 return self._bios_handler.get_section_sig_sha(section)
351
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_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800354 """Corrupt the requested 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.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700359
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800360 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800361 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800362 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700363
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800364 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700365 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800366 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700367
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800368 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800369 def _bios_corrupt_body(self, section):
370 """Corrupt the requested 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 Tamc1a569f2012-12-04 15:07:25 +0800373 """
374 self._bios_handler.corrupt_firmware_body(section)
375
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800376 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800377 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800378 """Restore the previously corrupted firmware section body.
379
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800380 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800381 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800382 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800383
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800384 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800385 """Modify firmware version for the requested section, by adding delta.
386
387 The passed in delta, a positive or a negative number, is added to the
388 original firmware version.
389 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800390 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800391 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800392 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800393 self._chromeos_interface.log(
394 'Setting firmware section %s version from %d to %d' % (
395 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800396 self._bios_handler.set_section_version(section, new_version, flags,
397 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800398
399 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800400 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800401 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800402 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800403
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800404 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800405 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800406 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800407 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800408
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800409 def _bios_get_version(self, section):
410 """Retrieve firmware version of a section."""
411 return self._bios_handler.get_section_version(section)
412
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800413 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800414 """Return firmware data key version."""
415 return self._bios_handler.get_section_datakey_version(section)
416
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800417 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800418 """Return kernel subkey version."""
419 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800420
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800421 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800422 """Setup the new EC image for later update.
423
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800424 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800425 """
426 self._ec_image = flashrom_handler.FlashromHandler()
427 self._ec_image.init(saft_flashrom_util,
428 self._chromeos_interface,
429 'ec_root_key.vpubk',
430 '/usr/share/vboot/devkeys',
431 'ec')
432 self._ec_image.new_image(ec_path)
433
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800434 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800435 """Get SHA1 hash of RW firmware section of the EC autest image."""
436 return self._ec_image.get_section_sha('rw')
437
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800438 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800439 """Update EC via software sync design.
440
441 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800442 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800443 current AP firmware.
444
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800445 @param section: A firmware section on current BIOS, either 'a' or 'b'.
446 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800447 """
448 blob = self._ec_image.get_section_body('rw')
449 self._bios_handler.set_section_ecbin(section, blob,
450 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800451 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800452
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800453 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800454 """Dump the current BIOS firmware to a file, specified by bios_path.
455
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800456 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800457 """
458 self._bios_handler.dump_whole(bios_path)
459
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800460 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800461 """Dump the current BIOS firmware RW to dir_path.
462
463 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
464
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800465 @param dir_path: The path of directory which contains files to be
466 written.
ctchang38ae4922012-09-03 17:01:16 +0800467 """
468 if not os.path.isdir(dir_path):
469 raise Exception("%s doesn't exist" % dir_path)
470
471 VBOOTA_blob = self._bios_handler.get_section_sig('a')
472 VBOOTB_blob = self._bios_handler.get_section_sig('b')
473 FVMAIN_blob = self._bios_handler.get_section_body('a')
474 FVMAINB_blob = self._bios_handler.get_section_body('b')
475
476 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
477 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
478 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
479 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
480
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800481 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800482 """Write the firmware from bios_path to the current system.
483
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800484 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800485 """
486 self._bios_handler.new_image(bios_path)
487 self._bios_handler.write_whole()
488
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800489 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800490 """Write the firmware RW from dir_path to the current system.
491
492 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
493
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800494 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800495 """
496 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
497 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
498 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
499 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
500 raise Exception("Source firmware file(s) doesn't exist.")
501
502 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
503 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
504 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
505 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
506
507 self._bios_handler.set_section_sig('a', VBOOTA_blob,
508 write_through=True)
509 self._bios_handler.set_section_sig('b', VBOOTB_blob,
510 write_through=True)
511 self._bios_handler.set_section_body('a', FVMAIN_blob,
512 write_through=True)
513 self._bios_handler.set_section_body('b', FVMAINB_blob,
514 write_through=True)
515
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800516 def _ec_get_version(self):
517 """Get EC version via mosys.
518
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800519 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800520 """
521 return self._chromeos_interface.run_shell_command_get_output(
522 'mosys ec info | sed "s/.*| //"')[0]
523
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800524 def _ec_get_firmware_sha(self):
525 """Get SHA1 hash of EC RW firmware section."""
526 return self._ec_handler.get_section_sha('rw')
527
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800528 @allow_multiple_section_input
529 def _ec_corrupt_sig(self, section):
530 """Corrupt the requested EC section signature.
531
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800532 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800533 """
534 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
535
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800536 @allow_multiple_section_input
537 def _ec_restore_sig(self, section):
538 """Restore the previously corrupted EC section signature.
539
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800540 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800541 """
542 self._ec_handler.restore_firmware(section, restore_all=True)
543
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800544 @allow_multiple_section_input
545 def _ec_corrupt_body(self, section):
546 """Corrupt the requested EC section body.
547
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800548 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800549 """
550 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
551
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800552 @allow_multiple_section_input
553 def _ec_restore_body(self, section):
554 """Restore the previously corrupted EC section body.
555
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800556 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800557 """
558 self._ec_handler.restore_firmware_body(section, restore_all=True)
559
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800560 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800561 """Dump the current EC firmware to a file, specified by ec_path.
562
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800563 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800564 """
565 self._ec_handler.dump_whole(ec_path)
566
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800567 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800568 """Enable write protect of the EC flash chip.
569
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800570 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800571 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800572 if enable:
573 self._ec_handler.enable_write_protect()
574 else:
575 self._ec_handler.disable_write_protect()
576
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800577 @allow_multiple_section_input
578 def _kernel_corrupt_sig(self, section):
579 """Corrupt the requested kernel section.
580
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800581 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800582 """
583 self._kernel_handler.corrupt_kernel(section)
584
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800585 @allow_multiple_section_input
586 def _kernel_restore_sig(self, section):
587 """Restore the requested kernel section (previously corrupted).
588
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800589 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800590 """
591 self._kernel_handler.restore_kernel(section)
592
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800593 def __kernel_modify_version(self, section, delta):
594 """Modify kernel version for the requested section, by adding delta.
595
596 The passed in delta, a positive or a negative number, is added to the
597 original kernel version.
598 """
599 original_version = self._kernel_handler.get_version(section)
600 new_version = original_version + delta
601 self._chromeos_interface.log(
602 'Setting kernel section %s version from %d to %d' % (
603 section, original_version, new_version))
604 self._kernel_handler.set_version(section, new_version)
605
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800606 @allow_multiple_section_input
607 def _kernel_move_version_backward(self, section):
608 """Decrement kernel version for the requested section."""
609 self.__kernel_modify_version(section, -1)
610
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800611 @allow_multiple_section_input
612 def _kernel_move_version_forward(self, section):
613 """Increase kernel version for the requested section."""
614 self.__kernel_modify_version(section, 1)
615
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800616 def _kernel_get_version(self, section):
617 """Return kernel version."""
618 return self._kernel_handler.get_version(section)
619
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800620 def _kernel_get_datakey_version(self, section):
621 """Return kernel datakey version."""
622 return self._kernel_handler.get_datakey_version(section)
623
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800624 def _kernel_diff_a_b(self):
625 """Compare kernel A with B.
626
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800627 @return: True: if kernel A is different with B.
628 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800629 """
630 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800631 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
632 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800633
634 # The signature (some kind of hash) for the kernel body is stored in
635 # the beginning. So compare the first 64KB (including header, preamble,
636 # and signature) should be enough to check them identical.
637 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
638 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
639
640 return header_a != header_b
641
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800642 def _kernel_resign_with_keys(self, section, key_path=None):
643 """Resign kernel with temporary key."""
644 self._kernel_handler.resign_kernel(section, key_path)
645
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800646 def _kernel_dump(self, section, kernel_path):
647 """Dump the specified kernel to a file.
648
649 @param section: The kernel to dump. May be A or B.
650 @param kernel_path: The path to the kernel image to be written.
651 """
652 self._kernel_handler.dump_kernel(section, kernel_path)
653
654 def _kernel_write(self, section, kernel_path):
655 """Write a kernel image to the specified section.
656
657 @param section: The kernel to dump. May be A or B.
658 @param kernel_path: The path to the kernel image.
659 """
660 self._kernel_handler.write_kernel(section, kernel_path)
661
662 def _kernel_get_sha(self, section):
663 """Return the SHA1 hash of the specified kernel section."""
664 return self._kernel_handler.get_sha(section)
665
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800666 def _tpm_get_firmware_version(self):
667 """Retrieve tpm firmware body version."""
668 return self._tpm_handler.get_fw_version()
669
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800670 def _tpm_get_firmware_datakey_version(self):
671 """Retrieve tpm firmware data key version."""
672 return self._tpm_handler.get_fw_body_version()
673
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800674 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800675 """Run the CgptState test loop. The tst logic is handled in the client.
676
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800677 @return: 0: there are more cgpt tests to execute.
678 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800679 """
680 return self._cgpt_state.test_loop()
681
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800682 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800683 """Set the CgptState test step.
684
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800685 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800686 """
687 self._cgpt_state.set_step(step)
688
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800689 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800690 """Get the CgptState test step.
691
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800692 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800693 """
694 return self._cgpt_state.get_step()
695
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800696 def _cgpt_get_attributes(self):
697 """Get kernel attributes."""
698 rootdev = self._system_get_root_dev()
699 self._cgpt_handler.read_device_info(rootdev)
700 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
701 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
702
703 def _cgpt_set_attributes(self, attributes):
704 """Set kernel attributes."""
705 rootdev = self._system_get_root_dev()
706 allowed = ['priority', 'tries', 'successful']
707 for p in ('A', 'B'):
708 if p not in attributes:
709 continue
710 attr = dict()
711 for k in allowed:
712 if k in attributes[p]:
713 attr[k] = attributes[p][k]
714 if attr:
715 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
716
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800717 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800718 """Setup the updater.
719
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800720 @param shellball: Path of provided shellball. Use default shellball
721 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800722 """
723 self._updater.setup(self._chromeos_interface, shellball)
724
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800725 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800726 self._updater.cleanup_temp_dir()
727
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800728 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800729 """Retrieve shellball's fwid.
730
731 This method should be called after updater_setup.
732
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800733 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800734 """
735 return self._updater.retrieve_fwid()
736
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800737 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800738 """Resign firmware with version.
739
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800740 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800741 """
742 self._updater.resign_firmware(version)
743
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800744 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800745 """Repack shellball with new fwid.
746
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800747 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800748 """
749 self._updater.repack_shellball(append)
750
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800751 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800752 """Run chromeos-firmwareupdate with autoupdate mode."""
753 options = ['--noupdate_ec', '--nocheck_rw_compatible']
754 self._updater.run_firmwareupdate(mode='autoupdate',
755 updater_append=append,
756 options=options)
757
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800758 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800759 """Run chromeos-firmwareupdate with factory_install mode."""
760 options = ['--noupdate_ec']
761 self._updater.run_firmwareupdate(mode='factory_install',
762 options=options)
763
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800764 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800765 """Run chromeos-firmwareupdate with bootok mode."""
766 self._updater.run_firmwareupdate(mode='bootok',
767 updater_append=append)
768
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800769 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800770 """Run chromeos-firmwareupdate with recovery mode."""
771 options = ['--noupdate_ec', '--nocheck_rw_compatible']
772 self._updater.run_firmwareupdate(mode='recovery',
773 options=options)
774
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800775 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800776 """Get updater's temp directory path."""
777 return self._updater.get_temp_path()
778
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800779 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800780 """Get updater's keys directory path."""
781 return self._updater.get_keys_path()
782
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800783 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800784 """Get updater's work directory path."""
785 return self._updater.get_work_path()
786
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800787 def _rootfs_verify_rootfs(self, section):
788 """Verifies the integrity of the root FS.
789
790 @param section: The rootfs to verify. May be A or B.
791 """
792 return self._rootfs_handler.verify_rootfs(section)
793
David Sodman3ad51642015-01-22 11:15:33 -0800794 def _system_check_keys(self, expected_sequence):
795 """Check the keys sequence was as expected.
796
797 @param expected_sequence: A list of expected key sequences.
798 """
799 return self._check_keys.check_keys(expected_sequence)
800
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800801 def cleanup(self):
802 """Cleanup for the RPC server. Currently nothing."""
803 pass