blob: 166af86989024baed2f2b4ef751810d7e836ed51 [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,
19 saft_flashrom_util,
20 tpm_handler,
21 )
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070022
23
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080024def allow_multiple_section_input(image_operator):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080025 """Decorate a method to support multiple sections.
26
27 @param image_operator: Method accepting one section as its argument.
28 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080029 @functools.wraps(image_operator)
30 def wrapper(self, section):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080031 """Wrapper method to support multiple sections.
32
33 @param section: A list of sections of just a section.
34 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080035 if type(section) in (tuple, list):
36 for sec in section:
37 image_operator(self, sec)
38 else:
39 image_operator(self, section)
40 return wrapper
41
42
Vic Yang13d22ec2012-06-18 15:12:47 +080043class LazyFlashromHandlerProxy:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080044 """Proxy of FlashromHandler for lazy initialization."""
Vic Yang13d22ec2012-06-18 15:12:47 +080045 _loaded = False
46 _obj = None
47
48 def __init__(self, *args, **kargs):
49 self._args = args
50 self._kargs = kargs
51
52 def _load(self):
53 self._obj = flashrom_handler.FlashromHandler()
54 self._obj.init(*self._args, **self._kargs)
55 self._obj.new_image()
56 self._loaded = True
57
58 def __getattr__(self, name):
59 if not self._loaded:
60 self._load()
61 return getattr(self._obj, name)
62
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080063 def reload(self):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080064 """Reload the FlashromHandler class."""
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080065 self._loaded = False
66
Vic Yang13d22ec2012-06-18 15:12:47 +080067
Yusuf Mohsinallyf4664222013-08-14 12:59:16 -070068class RPCFunctions(object):
69 """A class which aggregates some useful functions for firmware testing.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070070
71 This class can be exposed via a XMLRPC server such that its functions can
Chun-ting Changd43aa9b2012-11-16 10:12:05 +080072 be accessed remotely. Method naming should fit the naming rule
73 '_[categories]_[method_name]' where categories contains system, ec, bios,
74 kernel, cgpt, tpm, updater, etc. Methods should be called by
75 'FAFTClient.[categories].[method_name]', because _dispatch will rename
76 this name to '_[categories]_[method_name]'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070077
78 Attributes:
79 _chromeos_interface: An object to encapsulate OS services functions.
Vic Yang59cac9c2012-05-21 15:28:42 +080080 _bios_handler: An object to automate BIOS flashrom testing.
81 _ec_handler: An object to automate EC flashrom testing.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +080082 _ec_image: An object to automate EC image for autest.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070083 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080084 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070085 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080086 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080087 _temp_path: Path of a temp directory.
88 _keys_path: Path of a directory, keys/, in temp directory.
89 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070090 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070091 def __init__(self):
92 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070093 # TODO(waihong): Move the explicit object.init() methods to the
94 # objects' constructors (ChromeOSInterface, FlashromHandler,
95 # KernelHandler, and TpmHandler).
96 self._chromeos_interface = chromeos_interface.ChromeOSInterface(False)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +080097 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +080098 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080099 self._log_file = os.path.join(state_dir, 'faft_client.log')
100 self._chromeos_interface.init(state_dir, log_file=self._log_file)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +0800101 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800102
Vic Yang13d22ec2012-06-18 15:12:47 +0800103 self._bios_handler = LazyFlashromHandlerProxy(
104 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800105 self._chromeos_interface,
106 None,
107 '/usr/share/vboot/devkeys',
108 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800109
Todd Brochf2b1d012012-06-14 12:55:21 -0700110 self._ec_handler = None
111 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800112 self._ec_handler = LazyFlashromHandlerProxy(
113 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700114 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800115 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700116 '/usr/share/vboot/devkeys',
117 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700118
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800119 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700120
121 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800122 # TODO(waihong): The dev_key_path is a new argument. We do that in
123 # order not to break the old image and still be able to run.
124 try:
125 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800126 dev_key_path='/usr/share/vboot/devkeys',
127 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800128 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800129 # Copy the key to the current working directory.
130 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800131 self._kernel_handler.init(self._chromeos_interface,
132 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700133
134 self._tpm_handler = tpm_handler.TpmHandler()
135 self._tpm_handler.init(self._chromeos_interface)
136
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800137 self._cgpt_handler = cgpt_handler.CgptHandler(self._chromeos_interface)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800138 self._cgpt_state = cgpt_state.CgptState(
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800139 'SHORT', self._chromeos_interface, self._system_get_root_dev(),
140 self._cgpt_handler)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800141
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700142 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
Chun-ting Changcf924e92012-10-29 13:49:01 +0800143
ctchangc7e55ea2012-08-09 16:19:14 +0800144 # Initialize temporary directory path
145 self._temp_path = '/var/tmp/faft/autest'
146 self._keys_path = os.path.join(self._temp_path, 'keys')
147 self._work_path = os.path.join(self._temp_path, 'work')
148
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800149 def _dispatch(self, method, params):
150 """This _dispatch method handles string conversion especially.
151
152 Since we turn off allow_dotted_names option. So any string conversion,
153 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
154 via XML RPC call.
155 """
156 is_str = method.endswith('.__str__')
157 if is_str:
158 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800159
160 categories = ('system', 'bios', 'ec', 'kernel',
161 'tpm', 'cgpt', 'updater')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800162 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800163 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800164 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
165 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800166 else:
167 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800168 except AttributeError:
169 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800170
171 if is_str:
172 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800173 else:
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800174 self._chromeos_interface.log('Dispatching method %s with args %s' %
175 (str(func), str(params)))
176 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800177
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800178 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800179 """Function for polling the RPC server availability.
180
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800181 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800182 """
183 return True
184
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800185 def _system_dump_log(self, remove_log=False):
186 """Dump the log file.
187
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800188 @param remove_log: Remove the log file after dump.
189 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800190 """
191 log = open(self._log_file).read()
192 if remove_log:
193 os.remove(self._log_file)
194 return log
195
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800196 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700197 """Run shell command.
198
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800199 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700200 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700201 self._chromeos_interface.run_shell_command(command)
202
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800203 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700204 """Run shell command and get its console output.
205
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800206 @param command: A shell command to be run.
207 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700208 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700209 return self._chromeos_interface.run_shell_command_get_output(command)
210
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800211 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700212 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700213 self._chromeos_interface.run_shell_command('reboot')
214
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800215 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800216 """Get the platform name of the current system.
217
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800218 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800219 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800220 # 'mosys platform name' sometimes fails. Let's get the verbose output.
221 lines = self._chromeos_interface.run_shell_command_get_output(
222 '(mosys -vvv platform name 2>&1) || echo Failed')
223 if lines[-1].strip() == 'Failed':
224 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
225 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800226
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800227 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700228 """Get crossystem value of the requested key.
229
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800230 @param key: A crossystem key.
231 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700232 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700233 return self._chromeos_interface.run_shell_command_get_output(
234 'crossystem %s' % key)[0]
235
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800236 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800237 """Get the name of root device without partition number.
238
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800239 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800240 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800241 return self._chromeos_interface.get_root_dev()
242
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800243 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800244 """Get the name of root device with partition number.
245
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800246 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800247 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800248 return self._chromeos_interface.get_root_part()
249
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800250 def _system_set_try_fw_b(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700251 """Set 'Try Frimware B' flag in crossystem."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700252 self._chromeos_interface.cs.fwb_tries = 1
253
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800254 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800255 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800256 self._chromeos_interface.cs.request_recovery()
257
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800258 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800259 """Get dev_boot_usb value which controls developer mode boot from USB.
260
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800261 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800262 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800263 return self._chromeos_interface.cs.dev_boot_usb == '1'
264
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800265 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800266 """Set dev_boot_usb value which controls developer mode boot from USB.
267
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800268 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800269 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800270 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
271
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800272 def _system_is_removable_device_boot(self):
273 """Check the current boot device is removable.
274
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800275 @return: True: if a removable device boots.
276 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800277 """
278 root_part = self._chromeos_interface.get_root_part()
279 return self._chromeos_interface.is_removable_device(root_part)
280
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800281 def _system_create_temp_dir(self, prefix='backup_'):
282 """Create a temporary directory and return the path."""
283 return tempfile.mkdtemp(prefix=prefix)
284
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800285 def _bios_reload(self):
286 """Reload the firmware image that may be changed."""
287 self._bios_handler.reload()
288
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800289 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800290 """Get the GBB flags.
291
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800292 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800293 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800294 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800295
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800296 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800297 """Get the preamble flags of a firmware section.
298
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800299 @param section: A firmware section, either 'a' or 'b'.
300 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800301 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800302 return self._bios_handler.get_section_flags(section)
303
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800304 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800305 """Set the preamble flags of a firmware section.
306
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800307 @param section: A firmware section, either 'a' or 'b'.
308 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800309 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800310 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800311 self._bios_handler.set_section_version(section, version, flags,
312 write_through=True)
313
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800314 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800315 """Get SHA1 hash of BIOS RW firmware section.
316
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800317 @param section: A firmware section, either 'a' or 'b'.
318 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800319 """
320 return self._bios_handler.get_section_sha(section)
321
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800322 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800323 """Get SHA1 hash of firmware vblock in section."""
324 return self._bios_handler.get_section_sig_sha(section)
325
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800326 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800327 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800328 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700329
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800330 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700331 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800332 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700333
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800334 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800335 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800336 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700337
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800338 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700339 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800340 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700341
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800342 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800343 def _bios_corrupt_body(self, section):
344 """Corrupt the requested firmware section body.
345
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800346 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800347 """
348 self._bios_handler.corrupt_firmware_body(section)
349
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800350 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800351 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800352 """Restore the previously corrupted firmware section body.
353
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800354 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800355 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800356 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800357
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800358 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800359 """Modify firmware version for the requested section, by adding delta.
360
361 The passed in delta, a positive or a negative number, is added to the
362 original firmware version.
363 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800364 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800365 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800366 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800367 self._chromeos_interface.log(
368 'Setting firmware section %s version from %d to %d' % (
369 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800370 self._bios_handler.set_section_version(section, new_version, flags,
371 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800372
373 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800374 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800375 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800376 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800377
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800378 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800379 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800380 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800381 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800382
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800383 def _bios_get_version(self, section):
384 """Retrieve firmware version of a section."""
385 return self._bios_handler.get_section_version(section)
386
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800387 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800388 """Return firmware data key version."""
389 return self._bios_handler.get_section_datakey_version(section)
390
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800391 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800392 """Return kernel subkey version."""
393 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800394
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800395 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800396 """Setup the new EC image for later update.
397
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800398 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800399 """
400 self._ec_image = flashrom_handler.FlashromHandler()
401 self._ec_image.init(saft_flashrom_util,
402 self._chromeos_interface,
403 'ec_root_key.vpubk',
404 '/usr/share/vboot/devkeys',
405 'ec')
406 self._ec_image.new_image(ec_path)
407
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800408 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800409 """Get SHA1 hash of RW firmware section of the EC autest image."""
410 return self._ec_image.get_section_sha('rw')
411
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800412 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800413 """Update EC via software sync design.
414
415 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800416 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800417 current AP firmware.
418
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800419 @param section: A firmware section on current BIOS, either 'a' or 'b'.
420 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800421 """
422 blob = self._ec_image.get_section_body('rw')
423 self._bios_handler.set_section_ecbin(section, blob,
424 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800425 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800426
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800427 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800428 """Dump the current BIOS firmware to a file, specified by bios_path.
429
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800430 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800431 """
432 self._bios_handler.dump_whole(bios_path)
433
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800434 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800435 """Dump the current BIOS firmware RW to dir_path.
436
437 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
438
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800439 @param dir_path: The path of directory which contains files to be
440 written.
ctchang38ae4922012-09-03 17:01:16 +0800441 """
442 if not os.path.isdir(dir_path):
443 raise Exception("%s doesn't exist" % dir_path)
444
445 VBOOTA_blob = self._bios_handler.get_section_sig('a')
446 VBOOTB_blob = self._bios_handler.get_section_sig('b')
447 FVMAIN_blob = self._bios_handler.get_section_body('a')
448 FVMAINB_blob = self._bios_handler.get_section_body('b')
449
450 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
451 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
452 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
453 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
454
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800455 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800456 """Write the firmware from bios_path to the current system.
457
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800458 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800459 """
460 self._bios_handler.new_image(bios_path)
461 self._bios_handler.write_whole()
462
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800463 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800464 """Write the firmware RW from dir_path to the current system.
465
466 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
467
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800468 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800469 """
470 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
471 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
472 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
473 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
474 raise Exception("Source firmware file(s) doesn't exist.")
475
476 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
477 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
478 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
479 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
480
481 self._bios_handler.set_section_sig('a', VBOOTA_blob,
482 write_through=True)
483 self._bios_handler.set_section_sig('b', VBOOTB_blob,
484 write_through=True)
485 self._bios_handler.set_section_body('a', FVMAIN_blob,
486 write_through=True)
487 self._bios_handler.set_section_body('b', FVMAINB_blob,
488 write_through=True)
489
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800490 def _ec_get_version(self):
491 """Get EC version via mosys.
492
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800493 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800494 """
495 return self._chromeos_interface.run_shell_command_get_output(
496 'mosys ec info | sed "s/.*| //"')[0]
497
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800498 def _ec_get_firmware_sha(self):
499 """Get SHA1 hash of EC RW firmware section."""
500 return self._ec_handler.get_section_sha('rw')
501
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800502 @allow_multiple_section_input
503 def _ec_corrupt_sig(self, section):
504 """Corrupt the requested EC section signature.
505
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800506 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800507 """
508 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
509
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800510 @allow_multiple_section_input
511 def _ec_restore_sig(self, section):
512 """Restore the previously corrupted EC section signature.
513
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800514 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800515 """
516 self._ec_handler.restore_firmware(section, restore_all=True)
517
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800518 @allow_multiple_section_input
519 def _ec_corrupt_body(self, section):
520 """Corrupt the requested EC section body.
521
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800522 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800523 """
524 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
525
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800526 @allow_multiple_section_input
527 def _ec_restore_body(self, section):
528 """Restore the previously corrupted EC section body.
529
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800530 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800531 """
532 self._ec_handler.restore_firmware_body(section, restore_all=True)
533
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800534 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800535 """Dump the current EC firmware to a file, specified by ec_path.
536
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800537 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800538 """
539 self._ec_handler.dump_whole(ec_path)
540
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800541 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800542 """Enable write protect of the EC flash chip.
543
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800544 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800545 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800546 if enable:
547 self._ec_handler.enable_write_protect()
548 else:
549 self._ec_handler.disable_write_protect()
550
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800551 @allow_multiple_section_input
552 def _kernel_corrupt_sig(self, section):
553 """Corrupt the requested kernel section.
554
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800555 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800556 """
557 self._kernel_handler.corrupt_kernel(section)
558
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800559 @allow_multiple_section_input
560 def _kernel_restore_sig(self, section):
561 """Restore the requested kernel section (previously corrupted).
562
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800563 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800564 """
565 self._kernel_handler.restore_kernel(section)
566
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800567 def __kernel_modify_version(self, section, delta):
568 """Modify kernel version for the requested section, by adding delta.
569
570 The passed in delta, a positive or a negative number, is added to the
571 original kernel version.
572 """
573 original_version = self._kernel_handler.get_version(section)
574 new_version = original_version + delta
575 self._chromeos_interface.log(
576 'Setting kernel section %s version from %d to %d' % (
577 section, original_version, new_version))
578 self._kernel_handler.set_version(section, new_version)
579
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800580 @allow_multiple_section_input
581 def _kernel_move_version_backward(self, section):
582 """Decrement kernel version for the requested section."""
583 self.__kernel_modify_version(section, -1)
584
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800585 @allow_multiple_section_input
586 def _kernel_move_version_forward(self, section):
587 """Increase kernel version for the requested section."""
588 self.__kernel_modify_version(section, 1)
589
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800590 def _kernel_get_version(self, section):
591 """Return kernel version."""
592 return self._kernel_handler.get_version(section)
593
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800594 def _kernel_get_datakey_version(self, section):
595 """Return kernel datakey version."""
596 return self._kernel_handler.get_datakey_version(section)
597
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800598 def _kernel_diff_a_b(self):
599 """Compare kernel A with B.
600
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800601 @return: True: if kernel A is different with B.
602 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800603 """
604 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800605 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
606 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800607
608 # The signature (some kind of hash) for the kernel body is stored in
609 # the beginning. So compare the first 64KB (including header, preamble,
610 # and signature) should be enough to check them identical.
611 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
612 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
613
614 return header_a != header_b
615
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800616 def _kernel_resign_with_keys(self, section, key_path=None):
617 """Resign kernel with temporary key."""
618 self._kernel_handler.resign_kernel(section, key_path)
619
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800620 def _kernel_dump(self, section, kernel_path):
621 """Dump the specified kernel to a file.
622
623 @param section: The kernel to dump. May be A or B.
624 @param kernel_path: The path to the kernel image to be written.
625 """
626 self._kernel_handler.dump_kernel(section, kernel_path)
627
628 def _kernel_write(self, section, kernel_path):
629 """Write a kernel image to the specified section.
630
631 @param section: The kernel to dump. May be A or B.
632 @param kernel_path: The path to the kernel image.
633 """
634 self._kernel_handler.write_kernel(section, kernel_path)
635
636 def _kernel_get_sha(self, section):
637 """Return the SHA1 hash of the specified kernel section."""
638 return self._kernel_handler.get_sha(section)
639
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800640 def _tpm_get_firmware_version(self):
641 """Retrieve tpm firmware body version."""
642 return self._tpm_handler.get_fw_version()
643
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800644 def _tpm_get_firmware_datakey_version(self):
645 """Retrieve tpm firmware data key version."""
646 return self._tpm_handler.get_fw_body_version()
647
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800648 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800649 """Run the CgptState test loop. The tst logic is handled in the client.
650
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800651 @return: 0: there are more cgpt tests to execute.
652 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800653 """
654 return self._cgpt_state.test_loop()
655
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800656 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800657 """Set the CgptState test step.
658
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800659 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800660 """
661 self._cgpt_state.set_step(step)
662
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800663 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800664 """Get the CgptState test step.
665
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800666 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800667 """
668 return self._cgpt_state.get_step()
669
Vic (Chun-Ju) Yang93932842014-02-07 20:01:28 +0800670 def _cgpt_get_attributes(self):
671 """Get kernel attributes."""
672 rootdev = self._system_get_root_dev()
673 self._cgpt_handler.read_device_info(rootdev)
674 return {'A': self._cgpt_handler.get_partition(rootdev, 'KERN-A'),
675 'B': self._cgpt_handler.get_partition(rootdev, 'KERN-B')}
676
677 def _cgpt_set_attributes(self, attributes):
678 """Set kernel attributes."""
679 rootdev = self._system_get_root_dev()
680 allowed = ['priority', 'tries', 'successful']
681 for p in ('A', 'B'):
682 if p not in attributes:
683 continue
684 attr = dict()
685 for k in allowed:
686 if k in attributes[p]:
687 attr[k] = attributes[p][k]
688 if attr:
689 self._cgpt_handler.set_partition(rootdev, 'KERN-%s' % p, attr)
690
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800691 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800692 """Setup the updater.
693
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800694 @param shellball: Path of provided shellball. Use default shellball
695 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800696 """
697 self._updater.setup(self._chromeos_interface, shellball)
698
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800699 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800700 self._updater.cleanup_temp_dir()
701
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800702 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800703 """Retrieve shellball's fwid.
704
705 This method should be called after updater_setup.
706
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800707 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800708 """
709 return self._updater.retrieve_fwid()
710
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800711 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800712 """Resign firmware with version.
713
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800714 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800715 """
716 self._updater.resign_firmware(version)
717
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800718 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800719 """Repack shellball with new fwid.
720
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800721 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800722 """
723 self._updater.repack_shellball(append)
724
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800725 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800726 """Run chromeos-firmwareupdate with autoupdate mode."""
727 options = ['--noupdate_ec', '--nocheck_rw_compatible']
728 self._updater.run_firmwareupdate(mode='autoupdate',
729 updater_append=append,
730 options=options)
731
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800732 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800733 """Run chromeos-firmwareupdate with factory_install mode."""
734 options = ['--noupdate_ec']
735 self._updater.run_firmwareupdate(mode='factory_install',
736 options=options)
737
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800738 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800739 """Run chromeos-firmwareupdate with bootok mode."""
740 self._updater.run_firmwareupdate(mode='bootok',
741 updater_append=append)
742
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800743 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800744 """Run chromeos-firmwareupdate with recovery mode."""
745 options = ['--noupdate_ec', '--nocheck_rw_compatible']
746 self._updater.run_firmwareupdate(mode='recovery',
747 options=options)
748
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800749 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800750 """Get updater's temp directory path."""
751 return self._updater.get_temp_path()
752
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800753 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800754 """Get updater's keys directory path."""
755 return self._updater.get_keys_path()
756
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800757 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800758 """Get updater's work directory path."""
759 return self._updater.get_work_path()
760
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800761 def cleanup(self):
762 """Cleanup for the RPC server. Currently nothing."""
763 pass