blob: bef256e608efaa5779096379bb680cd043e63dd1 [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
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700258 def _system_set_fw_try_next(self, next):
259 """Set fw_try_next to A or B"""
260 self._chromeos_interface.cs.fw_try_next = next
261
262 def _system_get_fw_vboot2(self):
263 """Get fw_vboot2"""
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800264 try:
265 return self._chromeos_interface.cs.fw_vboot2 == '1'
266 except chromeos_interface.ChromeOSInterfaceError:
267 return False
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700268
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800269 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800270 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800271 self._chromeos_interface.cs.request_recovery()
272
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800273 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800274 """Get dev_boot_usb value which controls developer mode boot from USB.
275
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800276 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800277 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800278 return self._chromeos_interface.cs.dev_boot_usb == '1'
279
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800280 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800281 """Set dev_boot_usb value which controls developer mode boot from USB.
282
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800283 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800284 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800285 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
286
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800287 def _system_is_removable_device_boot(self):
288 """Check the current boot device is removable.
289
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800290 @return: True: if a removable device boots.
291 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800292 """
293 root_part = self._chromeos_interface.get_root_part()
294 return self._chromeos_interface.is_removable_device(root_part)
295
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800296 def _system_create_temp_dir(self, prefix='backup_'):
297 """Create a temporary directory and return the path."""
298 return tempfile.mkdtemp(prefix=prefix)
299
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800300 def _bios_reload(self):
301 """Reload the firmware image that may be changed."""
302 self._bios_handler.reload()
303
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800304 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800305 """Get the GBB flags.
306
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800307 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800308 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800309 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800310
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800311 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800312 """Get the preamble flags of a firmware section.
313
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800314 @param section: A firmware section, either 'a' or 'b'.
315 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800316 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800317 return self._bios_handler.get_section_flags(section)
318
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800319 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800320 """Set the preamble flags of a firmware section.
321
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800322 @param section: A firmware section, either 'a' or 'b'.
323 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800324 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800325 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800326 self._bios_handler.set_section_version(section, version, flags,
327 write_through=True)
328
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800329 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800330 """Get SHA1 hash of BIOS RW firmware section.
331
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800332 @param section: A firmware section, either 'a' or 'b'.
333 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800334 """
335 return self._bios_handler.get_section_sha(section)
336
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800337 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800338 """Get SHA1 hash of firmware vblock in section."""
339 return self._bios_handler.get_section_sig_sha(section)
340
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800341 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800342 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800343 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700344
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800345 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700346 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800347 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700348
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800349 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800350 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800351 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700352
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800353 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700354 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800355 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700356
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800357 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800358 def _bios_corrupt_body(self, section):
359 """Corrupt the requested firmware section body.
360
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800361 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800362 """
363 self._bios_handler.corrupt_firmware_body(section)
364
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800365 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800366 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800367 """Restore the previously corrupted firmware section body.
368
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800369 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800370 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800371 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800372
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800373 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800374 """Modify firmware version for the requested section, by adding delta.
375
376 The passed in delta, a positive or a negative number, is added to the
377 original firmware version.
378 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800379 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800380 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800381 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800382 self._chromeos_interface.log(
383 'Setting firmware section %s version from %d to %d' % (
384 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800385 self._bios_handler.set_section_version(section, new_version, flags,
386 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800387
388 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800389 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800390 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800391 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800392
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800393 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800394 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800395 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800396 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800397
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800398 def _bios_get_version(self, section):
399 """Retrieve firmware version of a section."""
400 return self._bios_handler.get_section_version(section)
401
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800402 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800403 """Return firmware data key version."""
404 return self._bios_handler.get_section_datakey_version(section)
405
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800406 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800407 """Return kernel subkey version."""
408 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800409
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800410 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800411 """Setup the new EC image for later update.
412
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800413 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800414 """
415 self._ec_image = flashrom_handler.FlashromHandler()
416 self._ec_image.init(saft_flashrom_util,
417 self._chromeos_interface,
418 'ec_root_key.vpubk',
419 '/usr/share/vboot/devkeys',
420 'ec')
421 self._ec_image.new_image(ec_path)
422
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800423 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800424 """Get SHA1 hash of RW firmware section of the EC autest image."""
425 return self._ec_image.get_section_sha('rw')
426
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800427 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800428 """Update EC via software sync design.
429
430 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800431 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800432 current AP firmware.
433
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800434 @param section: A firmware section on current BIOS, either 'a' or 'b'.
435 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800436 """
437 blob = self._ec_image.get_section_body('rw')
438 self._bios_handler.set_section_ecbin(section, blob,
439 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800440 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800441
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800442 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800443 """Dump the current BIOS firmware to a file, specified by bios_path.
444
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800445 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800446 """
447 self._bios_handler.dump_whole(bios_path)
448
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800449 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800450 """Dump the current BIOS firmware RW to dir_path.
451
452 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
453
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800454 @param dir_path: The path of directory which contains files to be
455 written.
ctchang38ae4922012-09-03 17:01:16 +0800456 """
457 if not os.path.isdir(dir_path):
458 raise Exception("%s doesn't exist" % dir_path)
459
460 VBOOTA_blob = self._bios_handler.get_section_sig('a')
461 VBOOTB_blob = self._bios_handler.get_section_sig('b')
462 FVMAIN_blob = self._bios_handler.get_section_body('a')
463 FVMAINB_blob = self._bios_handler.get_section_body('b')
464
465 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
466 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
467 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
468 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
469
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800470 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800471 """Write the firmware from bios_path to the current system.
472
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800473 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800474 """
475 self._bios_handler.new_image(bios_path)
476 self._bios_handler.write_whole()
477
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800478 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800479 """Write the firmware RW from dir_path to the current system.
480
481 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
482
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800483 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800484 """
485 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
486 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
487 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
488 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
489 raise Exception("Source firmware file(s) doesn't exist.")
490
491 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
492 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
493 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
494 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
495
496 self._bios_handler.set_section_sig('a', VBOOTA_blob,
497 write_through=True)
498 self._bios_handler.set_section_sig('b', VBOOTB_blob,
499 write_through=True)
500 self._bios_handler.set_section_body('a', FVMAIN_blob,
501 write_through=True)
502 self._bios_handler.set_section_body('b', FVMAINB_blob,
503 write_through=True)
504
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800505 def _ec_get_version(self):
506 """Get EC version via mosys.
507
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800508 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800509 """
510 return self._chromeos_interface.run_shell_command_get_output(
511 'mosys ec info | sed "s/.*| //"')[0]
512
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800513 def _ec_get_firmware_sha(self):
514 """Get SHA1 hash of EC RW firmware section."""
515 return self._ec_handler.get_section_sha('rw')
516
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800517 @allow_multiple_section_input
518 def _ec_corrupt_sig(self, section):
519 """Corrupt the requested EC section signature.
520
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800521 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800522 """
523 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
524
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800525 @allow_multiple_section_input
526 def _ec_restore_sig(self, section):
527 """Restore the previously corrupted EC section signature.
528
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800529 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800530 """
531 self._ec_handler.restore_firmware(section, restore_all=True)
532
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800533 @allow_multiple_section_input
534 def _ec_corrupt_body(self, section):
535 """Corrupt the requested EC section body.
536
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800537 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800538 """
539 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
540
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800541 @allow_multiple_section_input
542 def _ec_restore_body(self, section):
543 """Restore the previously corrupted EC section body.
544
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800545 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800546 """
547 self._ec_handler.restore_firmware_body(section, restore_all=True)
548
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800549 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800550 """Dump the current EC firmware to a file, specified by ec_path.
551
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800552 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800553 """
554 self._ec_handler.dump_whole(ec_path)
555
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800556 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800557 """Enable write protect of the EC flash chip.
558
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800559 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800560 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800561 if enable:
562 self._ec_handler.enable_write_protect()
563 else:
564 self._ec_handler.disable_write_protect()
565
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800566 @allow_multiple_section_input
567 def _kernel_corrupt_sig(self, section):
568 """Corrupt the requested kernel section.
569
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800570 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800571 """
572 self._kernel_handler.corrupt_kernel(section)
573
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800574 @allow_multiple_section_input
575 def _kernel_restore_sig(self, section):
576 """Restore the requested kernel section (previously corrupted).
577
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800578 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800579 """
580 self._kernel_handler.restore_kernel(section)
581
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800582 def __kernel_modify_version(self, section, delta):
583 """Modify kernel version for the requested section, by adding delta.
584
585 The passed in delta, a positive or a negative number, is added to the
586 original kernel version.
587 """
588 original_version = self._kernel_handler.get_version(section)
589 new_version = original_version + delta
590 self._chromeos_interface.log(
591 'Setting kernel section %s version from %d to %d' % (
592 section, original_version, new_version))
593 self._kernel_handler.set_version(section, new_version)
594
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800595 @allow_multiple_section_input
596 def _kernel_move_version_backward(self, section):
597 """Decrement kernel version for the requested section."""
598 self.__kernel_modify_version(section, -1)
599
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800600 @allow_multiple_section_input
601 def _kernel_move_version_forward(self, section):
602 """Increase kernel version for the requested section."""
603 self.__kernel_modify_version(section, 1)
604
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800605 def _kernel_get_version(self, section):
606 """Return kernel version."""
607 return self._kernel_handler.get_version(section)
608
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800609 def _kernel_get_datakey_version(self, section):
610 """Return kernel datakey version."""
611 return self._kernel_handler.get_datakey_version(section)
612
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800613 def _kernel_diff_a_b(self):
614 """Compare kernel A with B.
615
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800616 @return: True: if kernel A is different with B.
617 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800618 """
619 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800620 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
621 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800622
623 # The signature (some kind of hash) for the kernel body is stored in
624 # the beginning. So compare the first 64KB (including header, preamble,
625 # and signature) should be enough to check them identical.
626 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
627 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
628
629 return header_a != header_b
630
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800631 def _kernel_resign_with_keys(self, section, key_path=None):
632 """Resign kernel with temporary key."""
633 self._kernel_handler.resign_kernel(section, key_path)
634
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800635 def _kernel_dump(self, section, kernel_path):
636 """Dump the specified kernel to a file.
637
638 @param section: The kernel to dump. May be A or B.
639 @param kernel_path: The path to the kernel image to be written.
640 """
641 self._kernel_handler.dump_kernel(section, kernel_path)
642
643 def _kernel_write(self, section, kernel_path):
644 """Write a kernel image to the specified section.
645
646 @param section: The kernel to dump. May be A or B.
647 @param kernel_path: The path to the kernel image.
648 """
649 self._kernel_handler.write_kernel(section, kernel_path)
650
651 def _kernel_get_sha(self, section):
652 """Return the SHA1 hash of the specified kernel section."""
653 return self._kernel_handler.get_sha(section)
654
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800655 def _tpm_get_firmware_version(self):
656 """Retrieve tpm firmware body version."""
657 return self._tpm_handler.get_fw_version()
658
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800659 def _tpm_get_firmware_datakey_version(self):
660 """Retrieve tpm firmware data key version."""
661 return self._tpm_handler.get_fw_body_version()
662
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800663 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800664 """Run the CgptState test loop. The tst logic is handled in the client.
665
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800666 @return: 0: there are more cgpt tests to execute.
667 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800668 """
669 return self._cgpt_state.test_loop()
670
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800671 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800672 """Set the CgptState test step.
673
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800674 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800675 """
676 self._cgpt_state.set_step(step)
677
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800678 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800679 """Get the CgptState test step.
680
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800681 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800682 """
683 return self._cgpt_state.get_step()
684
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800685 def _cgpt_get_attributes(self):
686 """Get kernel attributes."""
687 rootdev = self._system_get_root_dev()
688 self._cgpt_handler.read_device_info(rootdev)
689 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
690 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
691
692 def _cgpt_set_attributes(self, attributes):
693 """Set kernel attributes."""
694 rootdev = self._system_get_root_dev()
695 allowed = ['priority', 'tries', 'successful']
696 for p in ('A', 'B'):
697 if p not in attributes:
698 continue
699 attr = dict()
700 for k in allowed:
701 if k in attributes[p]:
702 attr[k] = attributes[p][k]
703 if attr:
704 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
705
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800706 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800707 """Setup the updater.
708
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800709 @param shellball: Path of provided shellball. Use default shellball
710 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800711 """
712 self._updater.setup(self._chromeos_interface, shellball)
713
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800714 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800715 self._updater.cleanup_temp_dir()
716
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800717 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800718 """Retrieve shellball's fwid.
719
720 This method should be called after updater_setup.
721
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800722 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800723 """
724 return self._updater.retrieve_fwid()
725
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800726 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800727 """Resign firmware with version.
728
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800729 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800730 """
731 self._updater.resign_firmware(version)
732
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800733 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800734 """Repack shellball with new fwid.
735
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800736 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800737 """
738 self._updater.repack_shellball(append)
739
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800740 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800741 """Run chromeos-firmwareupdate with autoupdate mode."""
742 options = ['--noupdate_ec', '--nocheck_rw_compatible']
743 self._updater.run_firmwareupdate(mode='autoupdate',
744 updater_append=append,
745 options=options)
746
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800747 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800748 """Run chromeos-firmwareupdate with factory_install mode."""
749 options = ['--noupdate_ec']
750 self._updater.run_firmwareupdate(mode='factory_install',
751 options=options)
752
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800753 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800754 """Run chromeos-firmwareupdate with bootok mode."""
755 self._updater.run_firmwareupdate(mode='bootok',
756 updater_append=append)
757
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800758 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800759 """Run chromeos-firmwareupdate with recovery mode."""
760 options = ['--noupdate_ec', '--nocheck_rw_compatible']
761 self._updater.run_firmwareupdate(mode='recovery',
762 options=options)
763
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800764 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800765 """Get updater's temp directory path."""
766 return self._updater.get_temp_path()
767
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800768 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800769 """Get updater's keys directory path."""
770 return self._updater.get_keys_path()
771
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800772 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800773 """Get updater's work directory path."""
774 return self._updater.get_work_path()
775
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800776 def _rootfs_verify_rootfs(self, section):
777 """Verifies the integrity of the root FS.
778
779 @param section: The rootfs to verify. May be A or B.
780 """
781 return self._rootfs_handler.verify_rootfs(section)
782
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800783 def cleanup(self):
784 """Cleanup for the RPC server. Currently nothing."""
785 pass