blob: 946edd098cfbd6cd710ee49667a90647fe5438fd [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
danny chan6dc580a2015-08-08 00:14:02 +000010import functools, os, shutil, tempfile
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070011
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070012import common
Tom Wai-Hong Tam533eed72015-07-31 07:37:27 +080013from autotest_lib.client.cros.faft.utils import (cgpt_handler,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070014 chromeos_interface,
David Sodman3ad51642015-01-22 11:15:33 -080015 firmware_check_keys,
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070016 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).
danny chan6dc580a2015-08-08 00:14:02 +000097 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 Tam6db59cb2015-07-21 08:11:23 +0800100 self._log_file = os.path.join(state_dir, 'faft_client.log')
danny chan6dc580a2015-08-08 00:14:02 +0000101 self._chromeos_interface.init(state_dir, log_file=self._log_file)
102 os.chdir(state_dir)
Tom Wai-Hong Tam6db59cb2015-07-21 08:11:23 +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
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800140 self._rootfs_handler = rootfs_handler.RootfsHandler()
141 self._rootfs_handler.init(self._chromeos_interface)
142
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700143 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
David Sodman3ad51642015-01-22 11:15:33 -0800144 self._check_keys = firmware_check_keys.firmwareCheckKeys()
Chun-ting Changcf924e92012-10-29 13:49:01 +0800145
ctchangc7e55ea2012-08-09 16:19:14 +0800146 # Initialize temporary directory path
147 self._temp_path = '/var/tmp/faft/autest'
148 self._keys_path = os.path.join(self._temp_path, 'keys')
149 self._work_path = os.path.join(self._temp_path, 'work')
150
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800151 def _dispatch(self, method, params):
152 """This _dispatch method handles string conversion especially.
153
154 Since we turn off allow_dotted_names option. So any string conversion,
155 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
156 via XML RPC call.
157 """
158 is_str = method.endswith('.__str__')
159 if is_str:
160 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800161
162 categories = ('system', 'bios', 'ec', 'kernel',
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800163 'tpm', 'cgpt', 'updater', 'rootfs')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800164 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800165 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800166 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
167 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800168 else:
169 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800170 except AttributeError:
171 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800172
173 if is_str:
174 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800175 else:
danny chan6dc580a2015-08-08 00:14:02 +0000176 self._chromeos_interface.log('Dispatching method %s with args %s' %
177 (str(func), str(params)))
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800178 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800179
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800180 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800181 """Function for polling the RPC server availability.
182
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800183 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800184 """
185 return True
186
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800187 def _system_dump_log(self, remove_log=False):
188 """Dump the log file.
189
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800190 @param remove_log: Remove the log file after dump.
191 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800192 """
193 log = open(self._log_file).read()
194 if remove_log:
195 os.remove(self._log_file)
196 return log
197
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800198 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700199 """Run shell command.
200
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800201 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700202 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700203 self._chromeos_interface.run_shell_command(command)
204
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800205 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700206 """Run shell command and get its console output.
207
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800208 @param command: A shell command to be run.
209 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700210 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700211 return self._chromeos_interface.run_shell_command_get_output(command)
212
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800213 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700214 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700215 self._chromeos_interface.run_shell_command('reboot')
216
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800217 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800218 """Get the platform name of the current system.
219
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800220 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800221 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800222 # 'mosys platform name' sometimes fails. Let's get the verbose output.
223 lines = self._chromeos_interface.run_shell_command_get_output(
224 '(mosys -vvv platform name 2>&1) || echo Failed')
225 if lines[-1].strip() == 'Failed':
226 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
227 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800228
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800229 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700230 """Get crossystem value of the requested key.
231
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800232 @param key: A crossystem key.
233 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700234 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700235 return self._chromeos_interface.run_shell_command_get_output(
236 'crossystem %s' % key)[0]
237
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800238 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800239 """Get the name of root device without partition number.
240
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800241 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800242 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800243 return self._chromeos_interface.get_root_dev()
244
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800245 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800246 """Get the name of root device with partition number.
247
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800248 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800249 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800250 return self._chromeos_interface.get_root_part()
251
Shelley Chen3edea982014-12-30 14:54:21 -0800252 def _system_set_try_fw_b(self, count=1):
253 """Set 'Try Frimware B' flag in crossystem.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700254
Shelley Chen3edea982014-12-30 14:54:21 -0800255 @param count: # times to try booting into FW B
256 """
257 self._chromeos_interface.cs.fwb_tries = count
258
259 def _system_set_fw_try_next(self, next, count=0):
260 """Set fw_try_next to A or B
261
262 @param next: Next FW to reboot to (A or B)
263 @param count: # of times to try booting into FW <next>
264 """
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700265 self._chromeos_interface.cs.fw_try_next = next
Shelley Chen3edea982014-12-30 14:54:21 -0800266 if count:
267 self._chromeos_interface.cs.fw_try_count = count
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700268
269 def _system_get_fw_vboot2(self):
270 """Get fw_vboot2"""
Tom Wai-Hong Tam94886f92014-07-10 07:01:43 +0800271 try:
272 return self._chromeos_interface.cs.fw_vboot2 == '1'
273 except chromeos_interface.ChromeOSInterfaceError:
274 return False
Daisuke Nojiri57c05982014-06-25 15:28:35 -0700275
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800276 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800277 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800278 self._chromeos_interface.cs.request_recovery()
279
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800280 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800281 """Get dev_boot_usb value which controls developer mode boot from USB.
282
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800283 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800284 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800285 return self._chromeos_interface.cs.dev_boot_usb == '1'
286
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800287 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800288 """Set dev_boot_usb value which controls developer mode boot from USB.
289
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800290 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800291 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800292 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
293
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800294 def _system_is_removable_device_boot(self):
295 """Check the current boot device is removable.
296
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800297 @return: True: if a removable device boots.
298 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800299 """
300 root_part = self._chromeos_interface.get_root_part()
301 return self._chromeos_interface.is_removable_device(root_part)
302
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800303 def _system_create_temp_dir(self, prefix='backup_'):
304 """Create a temporary directory and return the path."""
305 return tempfile.mkdtemp(prefix=prefix)
306
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800307 def _bios_reload(self):
308 """Reload the firmware image that may be changed."""
309 self._bios_handler.reload()
310
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800311 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800312 """Get the GBB flags.
313
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800314 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800315 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800316 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800317
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800318 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800319 """Get the preamble flags of a firmware section.
320
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800321 @param section: A firmware section, either 'a' or 'b'.
322 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800323 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800324 return self._bios_handler.get_section_flags(section)
325
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800326 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800327 """Set the preamble flags of a 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.
Vic Yang91b73cf2012-07-31 17:18:11 +0800331 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800332 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800333 self._bios_handler.set_section_version(section, version, flags,
334 write_through=True)
335
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800336 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800337 """Get SHA1 hash of BIOS RW firmware section.
338
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800339 @param section: A firmware section, either 'a' or 'b'.
340 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800341 """
342 return self._bios_handler.get_section_sha(section)
343
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800344 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800345 """Get SHA1 hash of firmware vblock in section."""
346 return self._bios_handler.get_section_sig_sha(section)
347
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800348 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800349 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800350 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700351
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800352 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700353 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800354 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700355
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800356 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800357 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800358 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700359
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800360 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700361 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800362 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700363
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800364 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800365 def _bios_corrupt_body(self, section):
366 """Corrupt the requested firmware section body.
367
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800368 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800369 """
370 self._bios_handler.corrupt_firmware_body(section)
371
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800372 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800373 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800374 """Restore the previously corrupted firmware section body.
375
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800376 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800377 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800378 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800379
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800380 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800381 """Modify firmware version for the requested section, by adding delta.
382
383 The passed in delta, a positive or a negative number, is added to the
384 original firmware version.
385 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800386 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800387 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800388 flags = self._bios_handler.get_section_flags(section)
danny chan6dc580a2015-08-08 00:14:02 +0000389 self._chromeos_interface.log(
390 'Setting firmware section %s version from %d to %d' % (
391 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800392 self._bios_handler.set_section_version(section, new_version, flags,
393 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800394
395 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800396 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800397 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800398 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800399
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800400 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800401 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800402 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800403 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800404
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800405 def _bios_get_version(self, section):
406 """Retrieve firmware version of a section."""
407 return self._bios_handler.get_section_version(section)
408
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800409 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800410 """Return firmware data key version."""
411 return self._bios_handler.get_section_datakey_version(section)
412
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800413 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800414 """Return kernel subkey version."""
415 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800416
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800417 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800418 """Setup the new EC image for later update.
419
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800420 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800421 """
422 self._ec_image = flashrom_handler.FlashromHandler()
423 self._ec_image.init(saft_flashrom_util,
424 self._chromeos_interface,
425 'ec_root_key.vpubk',
426 '/usr/share/vboot/devkeys',
427 'ec')
428 self._ec_image.new_image(ec_path)
429
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800430 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800431 """Get SHA1 hash of RW firmware section of the EC autest image."""
432 return self._ec_image.get_section_sha('rw')
433
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800434 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800435 """Update EC via software sync design.
436
437 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800438 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800439 current AP firmware.
440
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800441 @param section: A firmware section on current BIOS, either 'a' or 'b'.
442 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800443 """
444 blob = self._ec_image.get_section_body('rw')
445 self._bios_handler.set_section_ecbin(section, blob,
446 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800447 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800448
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800449 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800450 """Dump the current BIOS firmware to a file, specified by bios_path.
451
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800452 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800453 """
454 self._bios_handler.dump_whole(bios_path)
455
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800456 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800457 """Dump the current BIOS firmware RW to dir_path.
458
459 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
460
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800461 @param dir_path: The path of directory which contains files to be
462 written.
ctchang38ae4922012-09-03 17:01:16 +0800463 """
464 if not os.path.isdir(dir_path):
465 raise Exception("%s doesn't exist" % dir_path)
466
467 VBOOTA_blob = self._bios_handler.get_section_sig('a')
468 VBOOTB_blob = self._bios_handler.get_section_sig('b')
469 FVMAIN_blob = self._bios_handler.get_section_body('a')
470 FVMAINB_blob = self._bios_handler.get_section_body('b')
471
472 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
473 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
474 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
475 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
476
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800477 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800478 """Write the firmware from bios_path to the current system.
479
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800480 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800481 """
482 self._bios_handler.new_image(bios_path)
483 self._bios_handler.write_whole()
484
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800485 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800486 """Write the firmware RW from dir_path to the current system.
487
488 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
489
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800490 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800491 """
492 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
493 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
494 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
495 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
496 raise Exception("Source firmware file(s) doesn't exist.")
497
498 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
499 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
500 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
501 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
502
503 self._bios_handler.set_section_sig('a', VBOOTA_blob,
504 write_through=True)
505 self._bios_handler.set_section_sig('b', VBOOTB_blob,
506 write_through=True)
507 self._bios_handler.set_section_body('a', FVMAIN_blob,
508 write_through=True)
509 self._bios_handler.set_section_body('b', FVMAINB_blob,
510 write_through=True)
511
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800512 def _ec_get_version(self):
513 """Get EC version via mosys.
514
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800515 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800516 """
517 return self._chromeos_interface.run_shell_command_get_output(
518 'mosys ec info | sed "s/.*| //"')[0]
519
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800520 def _ec_get_firmware_sha(self):
521 """Get SHA1 hash of EC RW firmware section."""
522 return self._ec_handler.get_section_sha('rw')
523
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800524 @allow_multiple_section_input
525 def _ec_corrupt_sig(self, section):
526 """Corrupt the requested EC section signature.
527
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800528 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800529 """
530 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
531
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800532 @allow_multiple_section_input
533 def _ec_restore_sig(self, section):
534 """Restore the previously corrupted EC section signature.
535
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800536 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800537 """
538 self._ec_handler.restore_firmware(section, restore_all=True)
539
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800540 @allow_multiple_section_input
541 def _ec_corrupt_body(self, section):
542 """Corrupt the requested EC section body.
543
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800544 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800545 """
546 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
547
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800548 @allow_multiple_section_input
549 def _ec_restore_body(self, section):
550 """Restore the previously corrupted EC section body.
551
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800552 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800553 """
554 self._ec_handler.restore_firmware_body(section, restore_all=True)
555
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800556 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800557 """Dump the current EC firmware to a file, specified by ec_path.
558
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800559 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800560 """
561 self._ec_handler.dump_whole(ec_path)
562
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800563 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800564 """Enable write protect of the EC flash chip.
565
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800566 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800567 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800568 if enable:
569 self._ec_handler.enable_write_protect()
570 else:
571 self._ec_handler.disable_write_protect()
572
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800573 @allow_multiple_section_input
574 def _kernel_corrupt_sig(self, section):
575 """Corrupt the requested kernel section.
576
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800577 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800578 """
579 self._kernel_handler.corrupt_kernel(section)
580
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800581 @allow_multiple_section_input
582 def _kernel_restore_sig(self, section):
583 """Restore the requested kernel section (previously corrupted).
584
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800585 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800586 """
587 self._kernel_handler.restore_kernel(section)
588
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800589 def __kernel_modify_version(self, section, delta):
590 """Modify kernel version for the requested section, by adding delta.
591
592 The passed in delta, a positive or a negative number, is added to the
593 original kernel version.
594 """
595 original_version = self._kernel_handler.get_version(section)
596 new_version = original_version + delta
danny chan6dc580a2015-08-08 00:14:02 +0000597 self._chromeos_interface.log(
598 'Setting kernel section %s version from %d to %d' % (
599 section, original_version, new_version))
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800600 self._kernel_handler.set_version(section, new_version)
601
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800602 @allow_multiple_section_input
603 def _kernel_move_version_backward(self, section):
604 """Decrement kernel version for the requested section."""
605 self.__kernel_modify_version(section, -1)
606
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800607 @allow_multiple_section_input
608 def _kernel_move_version_forward(self, section):
609 """Increase kernel version for the requested section."""
610 self.__kernel_modify_version(section, 1)
611
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800612 def _kernel_get_version(self, section):
613 """Return kernel version."""
614 return self._kernel_handler.get_version(section)
615
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800616 def _kernel_get_datakey_version(self, section):
617 """Return kernel datakey version."""
618 return self._kernel_handler.get_datakey_version(section)
619
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800620 def _kernel_diff_a_b(self):
621 """Compare kernel A with B.
622
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800623 @return: True: if kernel A is different with B.
624 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800625 """
626 rootdev = self._chromeos_interface.get_root_dev()
Vic (Chun-Ju) Yanga1eff6b2014-01-28 16:34:03 +0800627 kernel_a = self._chromeos_interface.join_part(rootdev, '2')
628 kernel_b = self._chromeos_interface.join_part(rootdev, '4')
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800629
630 # The signature (some kind of hash) for the kernel body is stored in
631 # the beginning. So compare the first 64KB (including header, preamble,
632 # and signature) should be enough to check them identical.
633 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
634 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
635
636 return header_a != header_b
637
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800638 def _kernel_resign_with_keys(self, section, key_path=None):
639 """Resign kernel with temporary key."""
640 self._kernel_handler.resign_kernel(section, key_path)
641
Vic (Chun-Ju) Yang33ef9e02014-02-07 14:30:19 +0800642 def _kernel_dump(self, section, kernel_path):
643 """Dump the specified kernel to a file.
644
645 @param section: The kernel to dump. May be A or B.
646 @param kernel_path: The path to the kernel image to be written.
647 """
648 self._kernel_handler.dump_kernel(section, kernel_path)
649
650 def _kernel_write(self, section, kernel_path):
651 """Write a kernel image to the specified section.
652
653 @param section: The kernel to dump. May be A or B.
654 @param kernel_path: The path to the kernel image.
655 """
656 self._kernel_handler.write_kernel(section, kernel_path)
657
658 def _kernel_get_sha(self, section):
659 """Return the SHA1 hash of the specified kernel section."""
660 return self._kernel_handler.get_sha(section)
661
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800662 def _tpm_get_firmware_version(self):
663 """Retrieve tpm firmware body version."""
664 return self._tpm_handler.get_fw_version()
665
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800666 def _tpm_get_firmware_datakey_version(self):
667 """Retrieve tpm firmware data key version."""
668 return self._tpm_handler.get_fw_body_version()
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
Vic (Chun-Ju) Yang4edbc072014-02-11 14:40:57 +0800761 def _rootfs_verify_rootfs(self, section):
762 """Verifies the integrity of the root FS.
763
764 @param section: The rootfs to verify. May be A or B.
765 """
766 return self._rootfs_handler.verify_rootfs(section)
767
David Sodman3ad51642015-01-22 11:15:33 -0800768 def _system_check_keys(self, expected_sequence):
769 """Check the keys sequence was as expected.
770
771 @param expected_sequence: A list of expected key sequences.
772 """
773 return self._check_keys.check_keys(expected_sequence)
774
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800775 def cleanup(self):
776 """Cleanup for the RPC server. Currently nothing."""
777 pass