blob: e43bbb443cc45f180e9345f6cdcacec441e40a99 [file] [log] [blame]
Tom Wai-Hong Tamc1e0b9a2012-11-01 13:52:39 +08001#!/usr/bin/python -u
barfab@chromium.orgb6d29932012-04-11 09:46:43 +02002# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -07003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Exposes the FAFTClient interface over XMLRPC.
7
8It launches a XMLRPC server and exposes the interface of FAFTClient object.
9The FAFTClient object aggreates some useful functions of exisintg SAFT
10libraries.
11"""
12
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080013import functools, os, shutil, tempfile
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070014from optparse import OptionParser
15from SimpleXMLRPCServer import SimpleXMLRPCServer
16
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -070017import common
18from autotest_lib.client.cros.faft.utils import (cgpt_state,
19 chromeos_interface,
20 firmware_updater,
21 flashrom_handler,
22 kernel_handler,
23 saft_flashrom_util,
24 tpm_handler,
25 )
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070026
27
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080028def allow_multiple_section_input(image_operator):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080029 """Decorate a method to support multiple sections.
30
31 @param image_operator: Method accepting one section as its argument.
32 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080033 @functools.wraps(image_operator)
34 def wrapper(self, section):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080035 """Wrapper method to support multiple sections.
36
37 @param section: A list of sections of just a section.
38 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080039 if type(section) in (tuple, list):
40 for sec in section:
41 image_operator(self, sec)
42 else:
43 image_operator(self, section)
44 return wrapper
45
46
Vic Yang13d22ec2012-06-18 15:12:47 +080047class LazyFlashromHandlerProxy:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080048 """Proxy of FlashromHandler for lazy initialization."""
Vic Yang13d22ec2012-06-18 15:12:47 +080049 _loaded = False
50 _obj = None
51
52 def __init__(self, *args, **kargs):
53 self._args = args
54 self._kargs = kargs
55
56 def _load(self):
57 self._obj = flashrom_handler.FlashromHandler()
58 self._obj.init(*self._args, **self._kargs)
59 self._obj.new_image()
60 self._loaded = True
61
62 def __getattr__(self, name):
63 if not self._loaded:
64 self._load()
65 return getattr(self._obj, name)
66
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080067 def reload(self):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080068 """Reload the FlashromHandler class."""
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080069 self._loaded = False
70
Vic Yang13d22ec2012-06-18 15:12:47 +080071
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070072class FAFTClient(object):
73 """A class of FAFT client which aggregates some useful functions of SAFT.
74
75 This class can be exposed via a XMLRPC server such that its functions can
Chun-ting Changd43aa9b2012-11-16 10:12:05 +080076 be accessed remotely. Method naming should fit the naming rule
77 '_[categories]_[method_name]' where categories contains system, ec, bios,
78 kernel, cgpt, tpm, updater, etc. Methods should be called by
79 'FAFTClient.[categories].[method_name]', because _dispatch will rename
80 this name to '_[categories]_[method_name]'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070081
82 Attributes:
83 _chromeos_interface: An object to encapsulate OS services functions.
Vic Yang59cac9c2012-05-21 15:28:42 +080084 _bios_handler: An object to automate BIOS flashrom testing.
85 _ec_handler: An object to automate EC flashrom testing.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +080086 _ec_image: An object to automate EC image for autest.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070087 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080088 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070089 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080090 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080091 _temp_path: Path of a temp directory.
92 _keys_path: Path of a directory, keys/, in temp directory.
93 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070094 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070095 def __init__(self):
96 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070097 # TODO(waihong): Move the explicit object.init() methods to the
98 # objects' constructors (ChromeOSInterface, FlashromHandler,
99 # KernelHandler, and TpmHandler).
100 self._chromeos_interface = chromeos_interface.ChromeOSInterface(False)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800101 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800102 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800103 self._log_file = os.path.join(state_dir, 'faft_client.log')
104 self._chromeos_interface.init(state_dir, log_file=self._log_file)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +0800105 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800106
Vic Yang13d22ec2012-06-18 15:12:47 +0800107 self._bios_handler = LazyFlashromHandlerProxy(
108 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800109 self._chromeos_interface,
110 None,
111 '/usr/share/vboot/devkeys',
112 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800113
Todd Brochf2b1d012012-06-14 12:55:21 -0700114 self._ec_handler = None
115 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800116 self._ec_handler = LazyFlashromHandlerProxy(
117 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700118 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800119 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700120 '/usr/share/vboot/devkeys',
121 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700122
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800123 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700124
125 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800126 # TODO(waihong): The dev_key_path is a new argument. We do that in
127 # order not to break the old image and still be able to run.
128 try:
129 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800130 dev_key_path='/usr/share/vboot/devkeys',
131 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800132 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800133 # Copy the key to the current working directory.
134 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800135 self._kernel_handler.init(self._chromeos_interface,
136 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700137
138 self._tpm_handler = tpm_handler.TpmHandler()
139 self._tpm_handler.init(self._chromeos_interface)
140
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800141 self._cgpt_state = cgpt_state.CgptState(
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800142 'SHORT', self._chromeos_interface, self._system_get_root_dev())
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800143
Yusuf Mohsinallycd108da2013-08-12 14:06:12 -0700144 self._updater = firmware_updater.FirmwareUpdater(self._chromeos_interface)
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',
163 'tpm', 'cgpt', 'updater')
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:
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800176 self._chromeos_interface.log('Dispatching method %s with args %s' %
177 (str(func), str(params)))
178 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
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800252 def _system_set_try_fw_b(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700253 """Set 'Try Frimware B' flag in crossystem."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700254 self._chromeos_interface.cs.fwb_tries = 1
255
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800256 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800257 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800258 self._chromeos_interface.cs.request_recovery()
259
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800260 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800261 """Get dev_boot_usb value which controls developer mode boot from USB.
262
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800263 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800264 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800265 return self._chromeos_interface.cs.dev_boot_usb == '1'
266
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800267 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800268 """Set dev_boot_usb value which controls developer mode boot from USB.
269
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800270 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800271 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800272 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
273
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800274 def _system_is_removable_device_boot(self):
275 """Check the current boot device is removable.
276
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800277 @return: True: if a removable device boots.
278 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800279 """
280 root_part = self._chromeos_interface.get_root_part()
281 return self._chromeos_interface.is_removable_device(root_part)
282
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800283 def _system_create_temp_dir(self, prefix='backup_'):
284 """Create a temporary directory and return the path."""
285 return tempfile.mkdtemp(prefix=prefix)
286
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800287 def _bios_reload(self):
288 """Reload the firmware image that may be changed."""
289 self._bios_handler.reload()
290
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800291 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800292 """Get the GBB flags.
293
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800294 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800295 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800296 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800297
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800298 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800299 """Get the preamble flags of a firmware section.
300
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800301 @param section: A firmware section, either 'a' or 'b'.
302 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800303 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800304 return self._bios_handler.get_section_flags(section)
305
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800306 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800307 """Set the preamble flags of a firmware section.
308
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800309 @param section: A firmware section, either 'a' or 'b'.
310 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800311 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800312 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800313 self._bios_handler.set_section_version(section, version, flags,
314 write_through=True)
315
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800316 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800317 """Get SHA1 hash of BIOS RW 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.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800321 """
322 return self._bios_handler.get_section_sha(section)
323
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800324 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800325 """Get SHA1 hash of firmware vblock in section."""
326 return self._bios_handler.get_section_sig_sha(section)
327
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800328 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800329 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800330 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700331
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800332 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700333 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800334 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700335
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800336 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800337 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800338 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700339
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800340 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700341 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800342 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700343
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800344 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800345 def _bios_corrupt_body(self, section):
346 """Corrupt the requested firmware section body.
347
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800348 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800349 """
350 self._bios_handler.corrupt_firmware_body(section)
351
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800352 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800353 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800354 """Restore the previously corrupted firmware section body.
355
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800356 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800357 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800358 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800359
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800360 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800361 """Modify firmware version for the requested section, by adding delta.
362
363 The passed in delta, a positive or a negative number, is added to the
364 original firmware version.
365 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800366 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800367 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800368 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800369 self._chromeos_interface.log(
370 'Setting firmware section %s version from %d to %d' % (
371 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800372 self._bios_handler.set_section_version(section, new_version, flags,
373 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800374
375 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800376 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800377 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800378 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800379
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800380 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800381 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800382 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800383 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800384
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800385 def _bios_get_version(self, section):
386 """Retrieve firmware version of a section."""
387 return self._bios_handler.get_section_version(section)
388
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800389 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800390 """Return firmware data key version."""
391 return self._bios_handler.get_section_datakey_version(section)
392
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800393 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800394 """Return kernel subkey version."""
395 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800396
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800397 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800398 """Setup the new EC image for later update.
399
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800400 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800401 """
402 self._ec_image = flashrom_handler.FlashromHandler()
403 self._ec_image.init(saft_flashrom_util,
404 self._chromeos_interface,
405 'ec_root_key.vpubk',
406 '/usr/share/vboot/devkeys',
407 'ec')
408 self._ec_image.new_image(ec_path)
409
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800410 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800411 """Get SHA1 hash of RW firmware section of the EC autest image."""
412 return self._ec_image.get_section_sha('rw')
413
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800414 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800415 """Update EC via software sync design.
416
417 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800418 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800419 current AP firmware.
420
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800421 @param section: A firmware section on current BIOS, either 'a' or 'b'.
422 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800423 """
424 blob = self._ec_image.get_section_body('rw')
425 self._bios_handler.set_section_ecbin(section, blob,
426 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800427 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800428
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800429 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800430 """Dump the current BIOS firmware to a file, specified by bios_path.
431
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800432 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800433 """
434 self._bios_handler.dump_whole(bios_path)
435
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800436 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800437 """Dump the current BIOS firmware RW to dir_path.
438
439 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
440
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800441 @param dir_path: The path of directory which contains files to be
442 written.
ctchang38ae4922012-09-03 17:01:16 +0800443 """
444 if not os.path.isdir(dir_path):
445 raise Exception("%s doesn't exist" % dir_path)
446
447 VBOOTA_blob = self._bios_handler.get_section_sig('a')
448 VBOOTB_blob = self._bios_handler.get_section_sig('b')
449 FVMAIN_blob = self._bios_handler.get_section_body('a')
450 FVMAINB_blob = self._bios_handler.get_section_body('b')
451
452 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
453 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
454 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
455 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
456
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800457 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800458 """Write the firmware from bios_path to the current system.
459
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800460 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800461 """
462 self._bios_handler.new_image(bios_path)
463 self._bios_handler.write_whole()
464
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800465 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800466 """Write the firmware RW from dir_path to the current system.
467
468 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
469
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800470 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800471 """
472 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
473 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
474 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
475 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
476 raise Exception("Source firmware file(s) doesn't exist.")
477
478 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
479 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
480 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
481 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
482
483 self._bios_handler.set_section_sig('a', VBOOTA_blob,
484 write_through=True)
485 self._bios_handler.set_section_sig('b', VBOOTB_blob,
486 write_through=True)
487 self._bios_handler.set_section_body('a', FVMAIN_blob,
488 write_through=True)
489 self._bios_handler.set_section_body('b', FVMAINB_blob,
490 write_through=True)
491
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800492 def _ec_get_version(self):
493 """Get EC version via mosys.
494
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800495 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800496 """
497 return self._chromeos_interface.run_shell_command_get_output(
498 'mosys ec info | sed "s/.*| //"')[0]
499
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800500 def _ec_get_firmware_sha(self):
501 """Get SHA1 hash of EC RW firmware section."""
502 return self._ec_handler.get_section_sha('rw')
503
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800504 @allow_multiple_section_input
505 def _ec_corrupt_sig(self, section):
506 """Corrupt the requested EC section signature.
507
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800508 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800509 """
510 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
511
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800512 @allow_multiple_section_input
513 def _ec_restore_sig(self, section):
514 """Restore the previously corrupted EC section signature.
515
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800516 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800517 """
518 self._ec_handler.restore_firmware(section, restore_all=True)
519
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800520 @allow_multiple_section_input
521 def _ec_corrupt_body(self, section):
522 """Corrupt the requested EC section body.
523
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800524 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800525 """
526 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
527
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800528 @allow_multiple_section_input
529 def _ec_restore_body(self, section):
530 """Restore the previously corrupted EC section body.
531
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800532 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800533 """
534 self._ec_handler.restore_firmware_body(section, restore_all=True)
535
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800536 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800537 """Dump the current EC firmware to a file, specified by ec_path.
538
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800539 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800540 """
541 self._ec_handler.dump_whole(ec_path)
542
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800543 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800544 """Enable write protect of the EC flash chip.
545
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800546 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800547 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800548 if enable:
549 self._ec_handler.enable_write_protect()
550 else:
551 self._ec_handler.disable_write_protect()
552
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800553 @allow_multiple_section_input
554 def _kernel_corrupt_sig(self, section):
555 """Corrupt the requested kernel section.
556
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800557 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800558 """
559 self._kernel_handler.corrupt_kernel(section)
560
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800561 @allow_multiple_section_input
562 def _kernel_restore_sig(self, section):
563 """Restore the requested kernel section (previously corrupted).
564
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800565 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800566 """
567 self._kernel_handler.restore_kernel(section)
568
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800569 def __kernel_modify_version(self, section, delta):
570 """Modify kernel version for the requested section, by adding delta.
571
572 The passed in delta, a positive or a negative number, is added to the
573 original kernel version.
574 """
575 original_version = self._kernel_handler.get_version(section)
576 new_version = original_version + delta
577 self._chromeos_interface.log(
578 'Setting kernel section %s version from %d to %d' % (
579 section, original_version, new_version))
580 self._kernel_handler.set_version(section, new_version)
581
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800582 @allow_multiple_section_input
583 def _kernel_move_version_backward(self, section):
584 """Decrement kernel version for the requested section."""
585 self.__kernel_modify_version(section, -1)
586
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800587 @allow_multiple_section_input
588 def _kernel_move_version_forward(self, section):
589 """Increase kernel version for the requested section."""
590 self.__kernel_modify_version(section, 1)
591
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800592 def _kernel_get_version(self, section):
593 """Return kernel version."""
594 return self._kernel_handler.get_version(section)
595
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800596 def _kernel_get_datakey_version(self, section):
597 """Return kernel datakey version."""
598 return self._kernel_handler.get_datakey_version(section)
599
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800600 def _kernel_diff_a_b(self):
601 """Compare kernel A with B.
602
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800603 @return: True: if kernel A is different with B.
604 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800605 """
606 rootdev = self._chromeos_interface.get_root_dev()
607 kernel_a = self._chromeos_interface.join_part(rootdev, '3')
608 kernel_b = self._chromeos_interface.join_part(rootdev, '5')
609
610 # The signature (some kind of hash) for the kernel body is stored in
611 # the beginning. So compare the first 64KB (including header, preamble,
612 # and signature) should be enough to check them identical.
613 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
614 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
615
616 return header_a != header_b
617
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800618 def _kernel_resign_with_keys(self, section, key_path=None):
619 """Resign kernel with temporary key."""
620 self._kernel_handler.resign_kernel(section, key_path)
621
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800622 def _tpm_get_firmware_version(self):
623 """Retrieve tpm firmware body version."""
624 return self._tpm_handler.get_fw_version()
625
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800626 def _tpm_get_firmware_datakey_version(self):
627 """Retrieve tpm firmware data key version."""
628 return self._tpm_handler.get_fw_body_version()
629
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800630 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800631 """Run the CgptState test loop. The tst logic is handled in the client.
632
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800633 @return: 0: there are more cgpt tests to execute.
634 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800635 """
636 return self._cgpt_state.test_loop()
637
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800638 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800639 """Set the CgptState test step.
640
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800641 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800642 """
643 self._cgpt_state.set_step(step)
644
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800645 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800646 """Get the CgptState test step.
647
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800648 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800649 """
650 return self._cgpt_state.get_step()
651
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800652 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800653 """Setup the updater.
654
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800655 @param shellball: Path of provided shellball. Use default shellball
656 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800657 """
658 self._updater.setup(self._chromeos_interface, shellball)
659
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800660 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800661 self._updater.cleanup_temp_dir()
662
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800663 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800664 """Retrieve shellball's fwid.
665
666 This method should be called after updater_setup.
667
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800668 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800669 """
670 return self._updater.retrieve_fwid()
671
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800672 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800673 """Resign firmware with version.
674
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800675 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800676 """
677 self._updater.resign_firmware(version)
678
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800679 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800680 """Repack shellball with new fwid.
681
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800682 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800683 """
684 self._updater.repack_shellball(append)
685
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800686 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800687 """Run chromeos-firmwareupdate with autoupdate mode."""
688 options = ['--noupdate_ec', '--nocheck_rw_compatible']
689 self._updater.run_firmwareupdate(mode='autoupdate',
690 updater_append=append,
691 options=options)
692
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800693 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800694 """Run chromeos-firmwareupdate with factory_install mode."""
695 options = ['--noupdate_ec']
696 self._updater.run_firmwareupdate(mode='factory_install',
697 options=options)
698
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800699 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800700 """Run chromeos-firmwareupdate with bootok mode."""
701 self._updater.run_firmwareupdate(mode='bootok',
702 updater_append=append)
703
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800704 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800705 """Run chromeos-firmwareupdate with recovery mode."""
706 options = ['--noupdate_ec', '--nocheck_rw_compatible']
707 self._updater.run_firmwareupdate(mode='recovery',
708 options=options)
709
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800710 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800711 """Get updater's temp directory path."""
712 return self._updater.get_temp_path()
713
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800714 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800715 """Get updater's keys directory path."""
716 return self._updater.get_keys_path()
717
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800718 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800719 """Get updater's work directory path."""
720 return self._updater.get_work_path()
721
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800722 def cleanup(self):
723 """Cleanup for the RPC server. Currently nothing."""
724 pass
725
726
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700727def main():
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800728 """The Main program, to run the XMLRPC server."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700729 parser = OptionParser(usage='Usage: %prog [options]')
730 parser.add_option('--port', type='int', dest='port', default=9990,
731 help='port number of XMLRPC server')
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800732 (options, _) = parser.parse_args()
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700733
734 faft_client = FAFTClient()
735
736 # Launch the XMLRPC server to provide FAFTClient commands.
Tom Wai-Hong Tam4a257e52011-11-12 08:36:22 +0800737 server = SimpleXMLRPCServer(('localhost', options.port), allow_none=True,
Tom Wai-Hong Tamc1e0b9a2012-11-01 13:52:39 +0800738 logRequests=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700739 server.register_introspection_functions()
740 server.register_instance(faft_client)
741 print 'XMLRPC Server: Serving FAFTClient on port %s' % options.port
742 server.serve_forever()
743
744
745if __name__ == '__main__':
746 main()