blob: 1146f841b34a3c862c581274c2b002e8f671b15a [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,
16 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:
80 _chromeos_interface: 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 Tam23870e02012-08-24 16:15:34 +080083 _ec_image: An object to automate EC image for autest.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070084 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080085 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070086 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080087 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080088 _temp_path: Path of a temp directory.
89 _keys_path: Path of a directory, keys/, in temp directory.
90 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070091 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070092 def __init__(self):
93 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070094 # TODO(waihong): Move the explicit object.init() methods to the
95 # objects' constructors (ChromeOSInterface, FlashromHandler,
96 # KernelHandler, and TpmHandler).
97 self._chromeos_interface = chromeos_interface.ChromeOSInterface(False)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +080098 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +080099 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800100 self._log_file = os.path.join(state_dir, 'faft_client.log')
101 self._chromeos_interface.init(state_dir, log_file=self._log_file)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +0800102 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800103
Vic Yang13d22ec2012-06-18 15:12:47 +0800104 self._bios_handler = LazyFlashromHandlerProxy(
105 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800106 self._chromeos_interface,
107 None,
108 '/usr/share/vboot/devkeys',
109 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800110
Todd Brochf2b1d012012-06-14 12:55:21 -0700111 self._ec_handler = None
112 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800113 self._ec_handler = LazyFlashromHandlerProxy(
114 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700115 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800116 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700117 '/usr/share/vboot/devkeys',
118 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700119
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800120 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700121
122 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800123 # TODO(waihong): The dev_key_path is a new argument. We do that in
124 # order not to break the old image and still be able to run.
125 try:
126 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800127 dev_key_path='/usr/share/vboot/devkeys',
128 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800129 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800130 # Copy the key to the current working directory.
131 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800132 self._kernel_handler.init(self._chromeos_interface,
133 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700134
135 self._tpm_handler = tpm_handler.TpmHandler()
136 self._tpm_handler.init(self._chromeos_interface)
137
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800138 self._cgpt_handler = cgpt_handler.CgptHandler(self._chromeos_interface)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800139 self._cgpt_state = cgpt_state.CgptState(
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800140 'SHORT', self._chromeos_interface, self._system_get_root_dev(),
141 self._cgpt_handler)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800142
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800143 self._rootfs_handler = rootfs_handler.RootfsHandler()
144 self._rootfs_handler.init(self._chromeos_interface)
145
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700146 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
Chun-ting Changcf924e92012-10-29 13:49:01 +0800147
ctchangc7e55ea2012-08-09 16:19:14 +0800148 # Initialize temporary directory path
149 self._temp_path = '/var/tmp/faft/autest'
150 self._keys_path = os.path.join(self._temp_path, 'keys')
151 self._work_path = os.path.join(self._temp_path, 'work')
152
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800153 def _dispatch(self, method, params):
154 """This _dispatch method handles string conversion especially.
155
156 Since we turn off allow_dotted_names option. So any string conversion,
157 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
158 via XML RPC call.
159 """
160 is_str = method.endswith('.__str__')
161 if is_str:
162 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800163
164 categories = ('system', 'bios', 'ec', 'kernel',
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800165 'tpm', 'cgpt', 'updater', 'rootfs')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800166 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800167 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800168 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
169 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800170 else:
171 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800172 except AttributeError:
173 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800174
175 if is_str:
176 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800177 else:
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800178 self._chromeos_interface.log('Dispatching method %s with args %s' %
179 (str(func), str(params)))
180 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800181
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800182 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800183 """Function for polling the RPC server availability.
184
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800185 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800186 """
187 return True
188
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800189 def _system_dump_log(self, remove_log=False):
190 """Dump the log file.
191
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800192 @param remove_log: Remove the log file after dump.
193 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800194 """
195 log = open(self._log_file).read()
196 if remove_log:
197 os.remove(self._log_file)
198 return log
199
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800200 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700201 """Run shell command.
202
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800203 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700204 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700205 self._chromeos_interface.run_shell_command(command)
206
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800207 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700208 """Run shell command and get its console output.
209
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800210 @param command: A shell command to be run.
211 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700212 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700213 return self._chromeos_interface.run_shell_command_get_output(command)
214
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800215 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700216 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700217 self._chromeos_interface.run_shell_command('reboot')
218
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800219 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800220 """Get the platform name of the current system.
221
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800222 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800223 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800224 # 'mosys platform name' sometimes fails. Let's get the verbose output.
225 lines = self._chromeos_interface.run_shell_command_get_output(
226 '(mosys -vvv platform name 2>&1) || echo Failed')
227 if lines[-1].strip() == 'Failed':
228 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
229 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800230
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800231 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700232 """Get crossystem value of the requested key.
233
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800234 @param key: A crossystem key.
235 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700236 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700237 return self._chromeos_interface.run_shell_command_get_output(
238 'crossystem %s' % key)[0]
239
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800240 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800241 """Get the name of root device without partition number.
242
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800243 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800244 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800245 return self._chromeos_interface.get_root_dev()
246
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800247 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800248 """Get the name of root device with partition number.
249
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800250 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800251 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800252 return self._chromeos_interface.get_root_part()
253
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800254 def _system_set_try_fw_b(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700255 """Set 'Try Frimware B' flag in crossystem."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700256 self._chromeos_interface.cs.fwb_tries = 1
257
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800258 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800259 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800260 self._chromeos_interface.cs.request_recovery()
261
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800262 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800263 """Get dev_boot_usb value which controls developer mode boot from USB.
264
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800265 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800266 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800267 return self._chromeos_interface.cs.dev_boot_usb == '1'
268
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800269 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800270 """Set dev_boot_usb value which controls developer mode boot from USB.
271
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800272 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800273 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800274 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
275
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800276 def _system_is_removable_device_boot(self):
277 """Check the current boot device is removable.
278
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800279 @return: True: if a removable device boots.
280 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800281 """
282 root_part = self._chromeos_interface.get_root_part()
283 return self._chromeos_interface.is_removable_device(root_part)
284
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800285 def _system_create_temp_dir(self, prefix='backup_'):
286 """Create a temporary directory and return the path."""
287 return tempfile.mkdtemp(prefix=prefix)
288
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800289 def _bios_reload(self):
290 """Reload the firmware image that may be changed."""
291 self._bios_handler.reload()
292
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800293 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800294 """Get the GBB flags.
295
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800296 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800297 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800298 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800299
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800300 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800301 """Get the preamble flags of a firmware section.
302
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800303 @param section: A firmware section, either 'a' or 'b'.
304 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800305 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800306 return self._bios_handler.get_section_flags(section)
307
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800308 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800309 """Set the preamble flags of a firmware section.
310
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800311 @param section: A firmware section, either 'a' or 'b'.
312 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800313 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800314 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800315 self._bios_handler.set_section_version(section, version, flags,
316 write_through=True)
317
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800318 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800319 """Get SHA1 hash of BIOS RW firmware section.
320
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800321 @param section: A firmware section, either 'a' or 'b'.
322 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800323 """
324 return self._bios_handler.get_section_sha(section)
325
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800326 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800327 """Get SHA1 hash of firmware vblock in section."""
328 return self._bios_handler.get_section_sig_sha(section)
329
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800330 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800331 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800332 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700333
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800334 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700335 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800336 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700337
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800338 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800339 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800340 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700341
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800342 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700343 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800344 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700345
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800346 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800347 def _bios_corrupt_body(self, section):
348 """Corrupt the requested firmware section body.
349
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800350 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800351 """
352 self._bios_handler.corrupt_firmware_body(section)
353
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800354 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800355 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800356 """Restore the previously corrupted firmware section body.
357
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800358 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800359 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800360 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800361
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800362 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800363 """Modify firmware version for the requested section, by adding delta.
364
365 The passed in delta, a positive or a negative number, is added to the
366 original firmware version.
367 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800368 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800369 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800370 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800371 self._chromeos_interface.log(
372 'Setting firmware section %s version from %d to %d' % (
373 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800374 self._bios_handler.set_section_version(section, new_version, flags,
375 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800376
377 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800378 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800379 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800380 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800381
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800382 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800383 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800384 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800385 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800386
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800387 def _bios_get_version(self, section):
388 """Retrieve firmware version of a section."""
389 return self._bios_handler.get_section_version(section)
390
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800391 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800392 """Return firmware data key version."""
393 return self._bios_handler.get_section_datakey_version(section)
394
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800395 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800396 """Return kernel subkey version."""
397 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800398
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800399 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800400 """Setup the new EC image for later update.
401
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800402 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800403 """
404 self._ec_image = flashrom_handler.FlashromHandler()
405 self._ec_image.init(saft_flashrom_util,
406 self._chromeos_interface,
407 'ec_root_key.vpubk',
408 '/usr/share/vboot/devkeys',
409 'ec')
410 self._ec_image.new_image(ec_path)
411
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800412 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800413 """Get SHA1 hash of RW firmware section of the EC autest image."""
414 return self._ec_image.get_section_sha('rw')
415
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800416 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800417 """Update EC via software sync design.
418
419 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800420 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800421 current AP firmware.
422
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800423 @param section: A firmware section on current BIOS, either 'a' or 'b'.
424 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800425 """
426 blob = self._ec_image.get_section_body('rw')
427 self._bios_handler.set_section_ecbin(section, blob,
428 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800429 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800430
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800431 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800432 """Dump the current BIOS firmware to a file, specified by bios_path.
433
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800434 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800435 """
436 self._bios_handler.dump_whole(bios_path)
437
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800438 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800439 """Dump the current BIOS firmware RW to dir_path.
440
441 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
442
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800443 @param dir_path: The path of directory which contains files to be
444 written.
ctchang38ae4922012-09-03 17:01:16 +0800445 """
446 if not os.path.isdir(dir_path):
447 raise Exception("%s doesn't exist" % dir_path)
448
449 VBOOTA_blob = self._bios_handler.get_section_sig('a')
450 VBOOTB_blob = self._bios_handler.get_section_sig('b')
451 FVMAIN_blob = self._bios_handler.get_section_body('a')
452 FVMAINB_blob = self._bios_handler.get_section_body('b')
453
454 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
455 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
456 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
457 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
458
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800459 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800460 """Write the firmware from bios_path to the current system.
461
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800462 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800463 """
464 self._bios_handler.new_image(bios_path)
465 self._bios_handler.write_whole()
466
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800467 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800468 """Write the firmware RW from dir_path to the current system.
469
470 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
471
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800472 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800473 """
474 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
475 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
476 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
477 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
478 raise Exception("Source firmware file(s) doesn't exist.")
479
480 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
481 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
482 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
483 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
484
485 self._bios_handler.set_section_sig('a', VBOOTA_blob,
486 write_through=True)
487 self._bios_handler.set_section_sig('b', VBOOTB_blob,
488 write_through=True)
489 self._bios_handler.set_section_body('a', FVMAIN_blob,
490 write_through=True)
491 self._bios_handler.set_section_body('b', FVMAINB_blob,
492 write_through=True)
493
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800494 def _ec_get_version(self):
495 """Get EC version via mosys.
496
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800497 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800498 """
499 return self._chromeos_interface.run_shell_command_get_output(
500 'mosys ec info | sed "s/.*| //"')[0]
501
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800502 def _ec_get_firmware_sha(self):
503 """Get SHA1 hash of EC RW firmware section."""
504 return self._ec_handler.get_section_sha('rw')
505
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800506 @allow_multiple_section_input
507 def _ec_corrupt_sig(self, section):
508 """Corrupt the requested EC section signature.
509
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800510 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800511 """
512 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
513
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800514 @allow_multiple_section_input
515 def _ec_restore_sig(self, section):
516 """Restore the previously corrupted EC section signature.
517
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800518 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800519 """
520 self._ec_handler.restore_firmware(section, restore_all=True)
521
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800522 @allow_multiple_section_input
523 def _ec_corrupt_body(self, section):
524 """Corrupt the requested EC section body.
525
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800526 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800527 """
528 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
529
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800530 @allow_multiple_section_input
531 def _ec_restore_body(self, section):
532 """Restore the previously corrupted EC section body.
533
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800534 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800535 """
536 self._ec_handler.restore_firmware_body(section, restore_all=True)
537
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800538 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800539 """Dump the current EC firmware to a file, specified by ec_path.
540
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800541 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800542 """
543 self._ec_handler.dump_whole(ec_path)
544
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800545 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800546 """Enable write protect of the EC flash chip.
547
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800548 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800549 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800550 if enable:
551 self._ec_handler.enable_write_protect()
552 else:
553 self._ec_handler.disable_write_protect()
554
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800555 @allow_multiple_section_input
556 def _kernel_corrupt_sig(self, section):
557 """Corrupt the requested kernel section.
558
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800559 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800560 """
561 self._kernel_handler.corrupt_kernel(section)
562
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800563 @allow_multiple_section_input
564 def _kernel_restore_sig(self, section):
565 """Restore the requested kernel section (previously corrupted).
566
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800567 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800568 """
569 self._kernel_handler.restore_kernel(section)
570
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800571 def __kernel_modify_version(self, section, delta):
572 """Modify kernel version for the requested section, by adding delta.
573
574 The passed in delta, a positive or a negative number, is added to the
575 original kernel version.
576 """
577 original_version = self._kernel_handler.get_version(section)
578 new_version = original_version + delta
579 self._chromeos_interface.log(
580 'Setting kernel section %s version from %d to %d' % (
581 section, original_version, new_version))
582 self._kernel_handler.set_version(section, new_version)
583
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800584 @allow_multiple_section_input
585 def _kernel_move_version_backward(self, section):
586 """Decrement kernel version for the requested section."""
587 self.__kernel_modify_version(section, -1)
588
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800589 @allow_multiple_section_input
590 def _kernel_move_version_forward(self, section):
591 """Increase kernel version for the requested section."""
592 self.__kernel_modify_version(section, 1)
593
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800594 def _kernel_get_version(self, section):
595 """Return kernel version."""
596 return self._kernel_handler.get_version(section)
597
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800598 def _kernel_get_datakey_version(self, section):
599 """Return kernel datakey version."""
600 return self._kernel_handler.get_datakey_version(section)
601
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800602 def _kernel_diff_a_b(self):
603 """Compare kernel A with B.
604
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800605 @return: True: if kernel A is different with B.
606 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800607 """
608 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800609 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
610 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800611
612 # The signature (some kind of hash) for the kernel body is stored in
613 # the beginning. So compare the first 64KB (including header, preamble,
614 # and signature) should be enough to check them identical.
615 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
616 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
617
618 return header_a != header_b
619
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800620 def _kernel_resign_with_keys(self, section, key_path=None):
621 """Resign kernel with temporary key."""
622 self._kernel_handler.resign_kernel(section, key_path)
623
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800624 def _kernel_dump(self, section, kernel_path):
625 """Dump the specified kernel to a file.
626
627 @param section: The kernel to dump. May be A or B.
628 @param kernel_path: The path to the kernel image to be written.
629 """
630 self._kernel_handler.dump_kernel(section, kernel_path)
631
632 def _kernel_write(self, section, kernel_path):
633 """Write a kernel image to the specified section.
634
635 @param section: The kernel to dump. May be A or B.
636 @param kernel_path: The path to the kernel image.
637 """
638 self._kernel_handler.write_kernel(section, kernel_path)
639
640 def _kernel_get_sha(self, section):
641 """Return the SHA1 hash of the specified kernel section."""
642 return self._kernel_handler.get_sha(section)
643
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800644 def _tpm_get_firmware_version(self):
645 """Retrieve tpm firmware body version."""
646 return self._tpm_handler.get_fw_version()
647
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800648 def _tpm_get_firmware_datakey_version(self):
649 """Retrieve tpm firmware data key version."""
650 return self._tpm_handler.get_fw_body_version()
651
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800652 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800653 """Run the CgptState test loop. The tst logic is handled in the client.
654
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800655 @return: 0: there are more cgpt tests to execute.
656 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800657 """
658 return self._cgpt_state.test_loop()
659
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800660 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800661 """Set the CgptState test step.
662
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800663 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800664 """
665 self._cgpt_state.set_step(step)
666
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800667 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800668 """Get the CgptState test step.
669
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800670 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800671 """
672 return self._cgpt_state.get_step()
673
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800674 def _cgpt_get_attributes(self):
675 """Get kernel attributes."""
676 rootdev = self._system_get_root_dev()
677 self._cgpt_handler.read_device_info(rootdev)
678 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
679 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
680
681 def _cgpt_set_attributes(self, attributes):
682 """Set kernel attributes."""
683 rootdev = self._system_get_root_dev()
684 allowed = ['priority', 'tries', 'successful']
685 for p in ('A', 'B'):
686 if p not in attributes:
687 continue
688 attr = dict()
689 for k in allowed:
690 if k in attributes[p]:
691 attr[k] = attributes[p][k]
692 if attr:
693 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
694
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800695 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800696 """Setup the updater.
697
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800698 @param shellball: Path of provided shellball. Use default shellball
699 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800700 """
701 self._updater.setup(self._chromeos_interface, shellball)
702
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800703 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800704 self._updater.cleanup_temp_dir()
705
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800706 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800707 """Retrieve shellball's fwid.
708
709 This method should be called after updater_setup.
710
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800711 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800712 """
713 return self._updater.retrieve_fwid()
714
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800715 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800716 """Resign firmware with version.
717
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800718 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800719 """
720 self._updater.resign_firmware(version)
721
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800722 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800723 """Repack shellball with new fwid.
724
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800725 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800726 """
727 self._updater.repack_shellball(append)
728
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800729 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800730 """Run chromeos-firmwareupdate with autoupdate mode."""
731 options = ['--noupdate_ec', '--nocheck_rw_compatible']
732 self._updater.run_firmwareupdate(mode='autoupdate',
733 updater_append=append,
734 options=options)
735
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800736 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800737 """Run chromeos-firmwareupdate with factory_install mode."""
738 options = ['--noupdate_ec']
739 self._updater.run_firmwareupdate(mode='factory_install',
740 options=options)
741
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800742 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800743 """Run chromeos-firmwareupdate with bootok mode."""
744 self._updater.run_firmwareupdate(mode='bootok',
745 updater_append=append)
746
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800747 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800748 """Run chromeos-firmwareupdate with recovery mode."""
749 options = ['--noupdate_ec', '--nocheck_rw_compatible']
750 self._updater.run_firmwareupdate(mode='recovery',
751 options=options)
752
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800753 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800754 """Get updater's temp directory path."""
755 return self._updater.get_temp_path()
756
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800757 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800758 """Get updater's keys directory path."""
759 return self._updater.get_keys_path()
760
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800761 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800762 """Get updater's work directory path."""
763 return self._updater.get_work_path()
764
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800765 def _rootfs_verify_rootfs(self, section):
766 """Verifies the integrity of the root FS.
767
768 @param section: The rootfs to verify. May be A or B.
769 """
770 return self._rootfs_handler.verify_rootfs(section)
771
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800772 def cleanup(self):
773 """Cleanup for the RPC server. Currently nothing."""
774 pass