blob: fe7000130d7165ce5cf356fbe8b7fb83592c1e58 [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"""
264 return self._chromeos_interface.cs.fw_vboot2 == '1'
265
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800266 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800267 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800268 self._chromeos_interface.cs.request_recovery()
269
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800270 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800271 """Get dev_boot_usb value which controls developer mode boot from USB.
272
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800273 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800274 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800275 return self._chromeos_interface.cs.dev_boot_usb == '1'
276
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800277 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800278 """Set dev_boot_usb value which controls developer mode boot from USB.
279
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800280 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800281 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800282 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
283
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800284 def _system_is_removable_device_boot(self):
285 """Check the current boot device is removable.
286
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800287 @return: True: if a removable device boots.
288 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800289 """
290 root_part = self._chromeos_interface.get_root_part()
291 return self._chromeos_interface.is_removable_device(root_part)
292
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800293 def _system_create_temp_dir(self, prefix='backup_'):
294 """Create a temporary directory and return the path."""
295 return tempfile.mkdtemp(prefix=prefix)
296
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800297 def _bios_reload(self):
298 """Reload the firmware image that may be changed."""
299 self._bios_handler.reload()
300
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800301 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800302 """Get the GBB flags.
303
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800304 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800305 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800306 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800307
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800308 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800309 """Get 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 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800313 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800314 return self._bios_handler.get_section_flags(section)
315
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800316 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800317 """Set the preamble flags of a firmware section.
318
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800319 @param section: A firmware section, either 'a' or 'b'.
320 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800321 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800322 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800323 self._bios_handler.set_section_version(section, version, flags,
324 write_through=True)
325
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800326 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800327 """Get SHA1 hash of BIOS RW firmware section.
328
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800329 @param section: A firmware section, either 'a' or 'b'.
330 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800331 """
332 return self._bios_handler.get_section_sha(section)
333
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800334 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800335 """Get SHA1 hash of firmware vblock in section."""
336 return self._bios_handler.get_section_sig_sha(section)
337
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_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800340 """Corrupt the requested 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.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700345
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800346 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800347 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800348 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700349
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800350 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700351 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800352 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700353
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800354 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800355 def _bios_corrupt_body(self, section):
356 """Corrupt the requested 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 Tamc1a569f2012-12-04 15:07:25 +0800359 """
360 self._bios_handler.corrupt_firmware_body(section)
361
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800362 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800363 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800364 """Restore the previously corrupted firmware section body.
365
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800366 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800367 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800368 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800369
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800370 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800371 """Modify firmware version for the requested section, by adding delta.
372
373 The passed in delta, a positive or a negative number, is added to the
374 original firmware version.
375 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800376 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800377 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800378 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800379 self._chromeos_interface.log(
380 'Setting firmware section %s version from %d to %d' % (
381 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800382 self._bios_handler.set_section_version(section, new_version, flags,
383 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800384
385 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800386 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800387 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800388 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800389
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800390 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800391 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800392 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800393 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800394
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800395 def _bios_get_version(self, section):
396 """Retrieve firmware version of a section."""
397 return self._bios_handler.get_section_version(section)
398
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800399 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800400 """Return firmware data key version."""
401 return self._bios_handler.get_section_datakey_version(section)
402
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800403 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800404 """Return kernel subkey version."""
405 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800406
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800407 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800408 """Setup the new EC image for later update.
409
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800410 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800411 """
412 self._ec_image = flashrom_handler.FlashromHandler()
413 self._ec_image.init(saft_flashrom_util,
414 self._chromeos_interface,
415 'ec_root_key.vpubk',
416 '/usr/share/vboot/devkeys',
417 'ec')
418 self._ec_image.new_image(ec_path)
419
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800420 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800421 """Get SHA1 hash of RW firmware section of the EC autest image."""
422 return self._ec_image.get_section_sha('rw')
423
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800424 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800425 """Update EC via software sync design.
426
427 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800428 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800429 current AP firmware.
430
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800431 @param section: A firmware section on current BIOS, either 'a' or 'b'.
432 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800433 """
434 blob = self._ec_image.get_section_body('rw')
435 self._bios_handler.set_section_ecbin(section, blob,
436 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800437 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800438
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800439 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800440 """Dump the current BIOS firmware to a file, specified by bios_path.
441
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800442 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800443 """
444 self._bios_handler.dump_whole(bios_path)
445
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800446 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800447 """Dump the current BIOS firmware RW to dir_path.
448
449 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
450
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800451 @param dir_path: The path of directory which contains files to be
452 written.
ctchang38ae4922012-09-03 17:01:16 +0800453 """
454 if not os.path.isdir(dir_path):
455 raise Exception("%s doesn't exist" % dir_path)
456
457 VBOOTA_blob = self._bios_handler.get_section_sig('a')
458 VBOOTB_blob = self._bios_handler.get_section_sig('b')
459 FVMAIN_blob = self._bios_handler.get_section_body('a')
460 FVMAINB_blob = self._bios_handler.get_section_body('b')
461
462 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
463 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
464 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
465 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
466
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800467 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800468 """Write the firmware from bios_path to the current system.
469
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800470 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800471 """
472 self._bios_handler.new_image(bios_path)
473 self._bios_handler.write_whole()
474
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800475 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800476 """Write the firmware RW from dir_path to the current system.
477
478 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
479
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800480 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800481 """
482 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
483 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
484 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
485 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
486 raise Exception("Source firmware file(s) doesn't exist.")
487
488 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
489 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
490 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
491 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
492
493 self._bios_handler.set_section_sig('a', VBOOTA_blob,
494 write_through=True)
495 self._bios_handler.set_section_sig('b', VBOOTB_blob,
496 write_through=True)
497 self._bios_handler.set_section_body('a', FVMAIN_blob,
498 write_through=True)
499 self._bios_handler.set_section_body('b', FVMAINB_blob,
500 write_through=True)
501
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800502 def _ec_get_version(self):
503 """Get EC version via mosys.
504
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800505 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800506 """
507 return self._chromeos_interface.run_shell_command_get_output(
508 'mosys ec info | sed "s/.*| //"')[0]
509
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800510 def _ec_get_firmware_sha(self):
511 """Get SHA1 hash of EC RW firmware section."""
512 return self._ec_handler.get_section_sha('rw')
513
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800514 @allow_multiple_section_input
515 def _ec_corrupt_sig(self, section):
516 """Corrupt the requested EC section signature.
517
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800518 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800519 """
520 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
521
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800522 @allow_multiple_section_input
523 def _ec_restore_sig(self, section):
524 """Restore the previously corrupted EC section signature.
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.restore_firmware(section, restore_all=True)
529
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800530 @allow_multiple_section_input
531 def _ec_corrupt_body(self, section):
532 """Corrupt the requested 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.corrupt_firmware_body(section, corrupt_all=True)
537
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800538 @allow_multiple_section_input
539 def _ec_restore_body(self, section):
540 """Restore the previously corrupted EC section body.
541
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800542 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800543 """
544 self._ec_handler.restore_firmware_body(section, restore_all=True)
545
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800546 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800547 """Dump the current EC firmware to a file, specified by ec_path.
548
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800549 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800550 """
551 self._ec_handler.dump_whole(ec_path)
552
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800553 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800554 """Enable write protect of the EC flash chip.
555
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800556 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800557 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800558 if enable:
559 self._ec_handler.enable_write_protect()
560 else:
561 self._ec_handler.disable_write_protect()
562
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800563 @allow_multiple_section_input
564 def _kernel_corrupt_sig(self, section):
565 """Corrupt the requested kernel section.
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.corrupt_kernel(section)
570
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800571 @allow_multiple_section_input
572 def _kernel_restore_sig(self, section):
573 """Restore the requested kernel section (previously corrupted).
574
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800575 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800576 """
577 self._kernel_handler.restore_kernel(section)
578
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800579 def __kernel_modify_version(self, section, delta):
580 """Modify kernel version for the requested section, by adding delta.
581
582 The passed in delta, a positive or a negative number, is added to the
583 original kernel version.
584 """
585 original_version = self._kernel_handler.get_version(section)
586 new_version = original_version + delta
587 self._chromeos_interface.log(
588 'Setting kernel section %s version from %d to %d' % (
589 section, original_version, new_version))
590 self._kernel_handler.set_version(section, new_version)
591
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800592 @allow_multiple_section_input
593 def _kernel_move_version_backward(self, section):
594 """Decrement kernel version for the requested section."""
595 self.__kernel_modify_version(section, -1)
596
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800597 @allow_multiple_section_input
598 def _kernel_move_version_forward(self, section):
599 """Increase kernel version for the requested section."""
600 self.__kernel_modify_version(section, 1)
601
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800602 def _kernel_get_version(self, section):
603 """Return kernel version."""
604 return self._kernel_handler.get_version(section)
605
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800606 def _kernel_get_datakey_version(self, section):
607 """Return kernel datakey version."""
608 return self._kernel_handler.get_datakey_version(section)
609
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800610 def _kernel_diff_a_b(self):
611 """Compare kernel A with B.
612
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800613 @return: True: if kernel A is different with B.
614 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800615 """
616 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800617 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
618 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800619
620 # The signature (some kind of hash) for the kernel body is stored in
621 # the beginning. So compare the first 64KB (including header, preamble,
622 # and signature) should be enough to check them identical.
623 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
624 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
625
626 return header_a != header_b
627
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800628 def _kernel_resign_with_keys(self, section, key_path=None):
629 """Resign kernel with temporary key."""
630 self._kernel_handler.resign_kernel(section, key_path)
631
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800632 def _kernel_dump(self, section, kernel_path):
633 """Dump the specified kernel to a file.
634
635 @param section: The kernel to dump. May be A or B.
636 @param kernel_path: The path to the kernel image to be written.
637 """
638 self._kernel_handler.dump_kernel(section, kernel_path)
639
640 def _kernel_write(self, section, kernel_path):
641 """Write a kernel image to the specified section.
642
643 @param section: The kernel to dump. May be A or B.
644 @param kernel_path: The path to the kernel image.
645 """
646 self._kernel_handler.write_kernel(section, kernel_path)
647
648 def _kernel_get_sha(self, section):
649 """Return the SHA1 hash of the specified kernel section."""
650 return self._kernel_handler.get_sha(section)
651
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800652 def _tpm_get_firmware_version(self):
653 """Retrieve tpm firmware body version."""
654 return self._tpm_handler.get_fw_version()
655
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800656 def _tpm_get_firmware_datakey_version(self):
657 """Retrieve tpm firmware data key version."""
658 return self._tpm_handler.get_fw_body_version()
659
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800660 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800661 """Run the CgptState test loop. The tst logic is handled in the client.
662
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800663 @return: 0: there are more cgpt tests to execute.
664 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800665 """
666 return self._cgpt_state.test_loop()
667
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800668 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800669 """Set the CgptState test step.
670
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800671 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800672 """
673 self._cgpt_state.set_step(step)
674
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800675 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800676 """Get the CgptState test step.
677
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800678 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800679 """
680 return self._cgpt_state.get_step()
681
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800682 def _cgpt_get_attributes(self):
683 """Get kernel attributes."""
684 rootdev = self._system_get_root_dev()
685 self._cgpt_handler.read_device_info(rootdev)
686 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
687 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
688
689 def _cgpt_set_attributes(self, attributes):
690 """Set kernel attributes."""
691 rootdev = self._system_get_root_dev()
692 allowed = ['priority', 'tries', 'successful']
693 for p in ('A', 'B'):
694 if p not in attributes:
695 continue
696 attr = dict()
697 for k in allowed:
698 if k in attributes[p]:
699 attr[k] = attributes[p][k]
700 if attr:
701 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
702
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800703 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800704 """Setup the updater.
705
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800706 @param shellball: Path of provided shellball. Use default shellball
707 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800708 """
709 self._updater.setup(self._chromeos_interface, shellball)
710
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800711 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800712 self._updater.cleanup_temp_dir()
713
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800714 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800715 """Retrieve shellball's fwid.
716
717 This method should be called after updater_setup.
718
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800719 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800720 """
721 return self._updater.retrieve_fwid()
722
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800723 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800724 """Resign firmware with version.
725
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800726 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800727 """
728 self._updater.resign_firmware(version)
729
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800730 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800731 """Repack shellball with new fwid.
732
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800733 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800734 """
735 self._updater.repack_shellball(append)
736
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800737 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800738 """Run chromeos-firmwareupdate with autoupdate mode."""
739 options = ['--noupdate_ec', '--nocheck_rw_compatible']
740 self._updater.run_firmwareupdate(mode='autoupdate',
741 updater_append=append,
742 options=options)
743
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800744 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800745 """Run chromeos-firmwareupdate with factory_install mode."""
746 options = ['--noupdate_ec']
747 self._updater.run_firmwareupdate(mode='factory_install',
748 options=options)
749
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800750 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800751 """Run chromeos-firmwareupdate with bootok mode."""
752 self._updater.run_firmwareupdate(mode='bootok',
753 updater_append=append)
754
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800755 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800756 """Run chromeos-firmwareupdate with recovery mode."""
757 options = ['--noupdate_ec', '--nocheck_rw_compatible']
758 self._updater.run_firmwareupdate(mode='recovery',
759 options=options)
760
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800761 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800762 """Get updater's temp directory path."""
763 return self._updater.get_temp_path()
764
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800765 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800766 """Get updater's keys directory path."""
767 return self._updater.get_keys_path()
768
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800769 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800770 """Get updater's work directory path."""
771 return self._updater.get_work_path()
772
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800773 def _rootfs_verify_rootfs(self, section):
774 """Verifies the integrity of the root FS.
775
776 @param section: The rootfs to verify. May be A or B.
777 """
778 return self._rootfs_handler.verify_rootfs(section)
779
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800780 def cleanup(self):
781 """Cleanup for the RPC server. Currently nothing."""
782 pass