blob: 4324dce907e10957c46a781d54a46e455bebd1f1 [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
Tom Wai-Hong Tamc0168912012-09-13 13:24:02 +080017from saft import cgpt_state, chromeos_interface, flashrom_handler
18from saft import kernel_handler, saft_flashrom_util, tpm_handler
Chun-ting Changcf924e92012-10-29 13:49:01 +080019from firmware_updater import FirmwareUpdater
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070020
21
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080022def allow_multiple_section_input(image_operator):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080023 """Decorate a method to support multiple sections.
24
25 @param image_operator: Method accepting one section as its argument.
26 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080027 @functools.wraps(image_operator)
28 def wrapper(self, section):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080029 """Wrapper method to support multiple sections.
30
31 @param section: A list of sections of just a section.
32 """
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +080033 if type(section) in (tuple, list):
34 for sec in section:
35 image_operator(self, sec)
36 else:
37 image_operator(self, section)
38 return wrapper
39
40
Vic Yang13d22ec2012-06-18 15:12:47 +080041class LazyFlashromHandlerProxy:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080042 """Proxy of FlashromHandler for lazy initialization."""
Vic Yang13d22ec2012-06-18 15:12:47 +080043 _loaded = False
44 _obj = None
45
46 def __init__(self, *args, **kargs):
47 self._args = args
48 self._kargs = kargs
49
50 def _load(self):
51 self._obj = flashrom_handler.FlashromHandler()
52 self._obj.init(*self._args, **self._kargs)
53 self._obj.new_image()
54 self._loaded = True
55
56 def __getattr__(self, name):
57 if not self._loaded:
58 self._load()
59 return getattr(self._obj, name)
60
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080061 def reload(self):
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +080062 """Reload the FlashromHandler class."""
Tom Wai-Hong Tamc1c4deb2012-07-26 14:28:11 +080063 self._loaded = False
64
Vic Yang13d22ec2012-06-18 15:12:47 +080065
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070066class FAFTClient(object):
67 """A class of FAFT client which aggregates some useful functions of SAFT.
68
69 This class can be exposed via a XMLRPC server such that its functions can
Chun-ting Changd43aa9b2012-11-16 10:12:05 +080070 be accessed remotely. Method naming should fit the naming rule
71 '_[categories]_[method_name]' where categories contains system, ec, bios,
72 kernel, cgpt, tpm, updater, etc. Methods should be called by
73 'FAFTClient.[categories].[method_name]', because _dispatch will rename
74 this name to '_[categories]_[method_name]'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070075
76 Attributes:
77 _chromeos_interface: An object to encapsulate OS services functions.
Vic Yang59cac9c2012-05-21 15:28:42 +080078 _bios_handler: An object to automate BIOS flashrom testing.
79 _ec_handler: An object to automate EC flashrom testing.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +080080 _ec_image: An object to automate EC image for autest.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070081 _kernel_handler: An object to provide kernel related actions.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080082 _log_file: Path of the log file.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070083 _tpm_handler: An object to control TPM device.
Chun-ting Changcf924e92012-10-29 13:49:01 +080084 _updater: An object to update firmware.
ctchangc7e55ea2012-08-09 16:19:14 +080085 _temp_path: Path of a temp directory.
86 _keys_path: Path of a directory, keys/, in temp directory.
87 _work_path: Path of a directory, work/, in temp directory.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070088 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070089 def __init__(self):
90 """Initialize the data attributes of this class."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -070091 # TODO(waihong): Move the explicit object.init() methods to the
92 # objects' constructors (ChromeOSInterface, FlashromHandler,
93 # KernelHandler, and TpmHandler).
94 self._chromeos_interface = chromeos_interface.ChromeOSInterface(False)
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +080095 # We keep the state of FAFT test in a permanent directory over reboots.
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +080096 state_dir = '/var/tmp/faft'
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +080097 self._log_file = os.path.join(state_dir, 'faft_client.log')
98 self._chromeos_interface.init(state_dir, log_file=self._log_file)
Tom Wai-Hong Tam46d2ca72013-07-01 09:50:55 +080099 os.chdir(state_dir)
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800100
Vic Yang13d22ec2012-06-18 15:12:47 +0800101 self._bios_handler = LazyFlashromHandlerProxy(
102 saft_flashrom_util,
Vic Yang59cac9c2012-05-21 15:28:42 +0800103 self._chromeos_interface,
104 None,
105 '/usr/share/vboot/devkeys',
106 'bios')
Vic Yang59cac9c2012-05-21 15:28:42 +0800107
Todd Brochf2b1d012012-06-14 12:55:21 -0700108 self._ec_handler = None
109 if not os.system("mosys ec info"):
Vic Yang13d22ec2012-06-18 15:12:47 +0800110 self._ec_handler = LazyFlashromHandlerProxy(
111 saft_flashrom_util,
Todd Brochf2b1d012012-06-14 12:55:21 -0700112 self._chromeos_interface,
Vic Yang13d22ec2012-06-18 15:12:47 +0800113 'ec_root_key.vpubk',
Todd Brochf2b1d012012-06-14 12:55:21 -0700114 '/usr/share/vboot/devkeys',
115 'ec')
Todd Brochf2b1d012012-06-14 12:55:21 -0700116
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800117 self._ec_image = None
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700118
119 self._kernel_handler = kernel_handler.KernelHandler()
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800120 # TODO(waihong): The dev_key_path is a new argument. We do that in
121 # order not to break the old image and still be able to run.
122 try:
123 self._kernel_handler.init(self._chromeos_interface,
ctchangd60030f2012-08-29 15:39:56 +0800124 dev_key_path='/usr/share/vboot/devkeys',
125 internal_disk=True)
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800126 except TypeError:
Tom Wai-Hong Tam07278c22012-02-08 16:53:00 +0800127 # Copy the key to the current working directory.
128 shutil.copy('/usr/share/vboot/devkeys/kernel_data_key.vbprivk', '.')
ctchangd60030f2012-08-29 15:39:56 +0800129 self._kernel_handler.init(self._chromeos_interface,
130 internal_disk=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700131
132 self._tpm_handler = tpm_handler.TpmHandler()
133 self._tpm_handler.init(self._chromeos_interface)
134
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800135 self._cgpt_state = cgpt_state.CgptState(
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800136 'SHORT', self._chromeos_interface, self._system_get_root_dev())
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800137
Chun-ting Changcf924e92012-10-29 13:49:01 +0800138 self._updater = FirmwareUpdater(self._chromeos_interface)
139
ctchangc7e55ea2012-08-09 16:19:14 +0800140 # Initialize temporary directory path
141 self._temp_path = '/var/tmp/faft/autest'
142 self._keys_path = os.path.join(self._temp_path, 'keys')
143 self._work_path = os.path.join(self._temp_path, 'work')
144
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800145 def _dispatch(self, method, params):
146 """This _dispatch method handles string conversion especially.
147
148 Since we turn off allow_dotted_names option. So any string conversion,
149 like str(FAFTClient.method), i.e. FAFTClient.method.__str__, failed
150 via XML RPC call.
151 """
152 is_str = method.endswith('.__str__')
153 if is_str:
154 method = method.rsplit('.', 1)[0]
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800155
156 categories = ('system', 'bios', 'ec', 'kernel',
157 'tpm', 'cgpt', 'updater')
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800158 try:
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800159 if method.split('.', 1)[0] in categories:
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800160 func = getattr(self, '_%s_%s' % (method.split('.', 1)[0],
161 method.split('.', 1)[1]))
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800162 else:
163 func = getattr(self, method)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800164 except AttributeError:
165 raise Exception('method "%s" is not supported' % method)
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800166
167 if is_str:
168 return str(func)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800169 else:
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800170 self._chromeos_interface.log('Dispatching method %s with args %s' %
171 (str(func), str(params)))
172 return func(*params)
Tom Wai-Hong Tame8f291a2011-12-08 22:03:53 +0800173
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800174 def _system_is_available(self):
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800175 """Function for polling the RPC server availability.
176
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800177 @return: Always True.
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800178 """
179 return True
180
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800181 def _system_dump_log(self, remove_log=False):
182 """Dump the log file.
183
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800184 @param remove_log: Remove the log file after dump.
185 @return: String of the log file content.
Tom Wai-Hong Tam48ae2212013-06-26 10:37:40 +0800186 """
187 log = open(self._log_file).read()
188 if remove_log:
189 os.remove(self._log_file)
190 return log
191
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800192 def _system_run_shell_command(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700193 """Run shell command.
194
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800195 @param command: A shell command to be run.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700196 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700197 self._chromeos_interface.run_shell_command(command)
198
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800199 def _system_run_shell_command_get_output(self, command):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700200 """Run shell command and get its console output.
201
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800202 @param command: A shell command to be run.
203 @return: A list of strings stripped of the newline characters.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700204 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700205 return self._chromeos_interface.run_shell_command_get_output(command)
206
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800207 def _system_software_reboot(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700208 """Request software reboot."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700209 self._chromeos_interface.run_shell_command('reboot')
210
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800211 def _system_get_platform_name(self):
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800212 """Get the platform name of the current system.
213
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800214 @return: A string of the platform name.
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800215 """
Vic Yang2bbb8672012-11-12 12:14:53 +0800216 # 'mosys platform name' sometimes fails. Let's get the verbose output.
217 lines = self._chromeos_interface.run_shell_command_get_output(
218 '(mosys -vvv platform name 2>&1) || echo Failed')
219 if lines[-1].strip() == 'Failed':
220 raise Exception('Failed getting platform name: ' + '\n'.join(lines))
221 return lines[-1]
Tom Wai-Hong Tam678ab152011-12-14 15:27:24 +0800222
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800223 def _system_get_crossystem_value(self, key):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700224 """Get crossystem value of the requested key.
225
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800226 @param key: A crossystem key.
227 @return: A string of the requested crossystem value.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700228 """
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700229 return self._chromeos_interface.run_shell_command_get_output(
230 'crossystem %s' % key)[0]
231
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800232 def _system_get_root_dev(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800233 """Get the name of root device without partition number.
234
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800235 @return: A string of the root device without partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800236 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800237 return self._chromeos_interface.get_root_dev()
238
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800239 def _system_get_root_part(self):
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800240 """Get the name of root device with partition number.
241
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800242 @return: A string of the root device with partition number.
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800243 """
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800244 return self._chromeos_interface.get_root_part()
245
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800246 def _system_set_try_fw_b(self):
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700247 """Set 'Try Frimware B' flag in crossystem."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700248 self._chromeos_interface.cs.fwb_tries = 1
249
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800250 def _system_request_recovery_boot(self):
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800251 """Request running in recovery mode on the restart."""
Tom Wai-Hong Tam76c75072011-10-25 18:00:12 +0800252 self._chromeos_interface.cs.request_recovery()
253
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800254 def _system_get_dev_boot_usb(self):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800255 """Get dev_boot_usb value which controls developer mode boot from USB.
256
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800257 @return: True if enable, False if disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800258 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800259 return self._chromeos_interface.cs.dev_boot_usb == '1'
260
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800261 def _system_set_dev_boot_usb(self, value):
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800262 """Set dev_boot_usb value which controls developer mode boot from USB.
263
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800264 @param value: True to enable, False to disable.
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800265 """
Tom Wai-Hong Tam0a7b2be2012-10-15 16:44:12 +0800266 self._chromeos_interface.cs.dev_boot_usb = 1 if value else 0
267
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800268 def _system_is_removable_device_boot(self):
269 """Check the current boot device is removable.
270
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800271 @return: True: if a removable device boots.
272 False: if a non-removable device boots.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800273 """
274 root_part = self._chromeos_interface.get_root_part()
275 return self._chromeos_interface.is_removable_device(root_part)
276
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800277 def _system_create_temp_dir(self, prefix='backup_'):
278 """Create a temporary directory and return the path."""
279 return tempfile.mkdtemp(prefix=prefix)
280
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800281 def _bios_reload(self):
282 """Reload the firmware image that may be changed."""
283 self._bios_handler.reload()
284
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800285 def _bios_get_gbb_flags(self):
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800286 """Get the GBB flags.
287
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800288 @return: An integer of the GBB flags.
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800289 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800290 return self._bios_handler.get_gbb_flags()
Tom Wai-Hong Tam8c9eed62011-12-28 15:05:05 +0800291
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800292 def _bios_get_preamble_flags(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800293 """Get the preamble flags of a firmware section.
294
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800295 @param section: A firmware section, either 'a' or 'b'.
296 @return: An integer of the preamble flags.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800297 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800298 return self._bios_handler.get_section_flags(section)
299
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800300 def _bios_set_preamble_flags(self, section, flags):
Vic Yang91b73cf2012-07-31 17:18:11 +0800301 """Set the preamble flags of a firmware section.
302
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800303 @param section: A firmware section, either 'a' or 'b'.
304 @param flags: An integer of preamble flags.
Vic Yang91b73cf2012-07-31 17:18:11 +0800305 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800306 version = self._bios_get_version(section)
Vic Yang91b73cf2012-07-31 17:18:11 +0800307 self._bios_handler.set_section_version(section, version, flags,
308 write_through=True)
309
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800310 def _bios_get_body_sha(self, section):
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800311 """Get SHA1 hash of BIOS RW firmware section.
312
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800313 @param section: A firmware section, either 'a' or 'b'.
314 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam4e10b9f2012-09-06 16:23:02 +0800315 """
316 return self._bios_handler.get_section_sha(section)
317
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800318 def _bios_get_sig_sha(self, section):
ctchang38ae4922012-09-03 17:01:16 +0800319 """Get SHA1 hash of firmware vblock in section."""
320 return self._bios_handler.get_section_sig_sha(section)
321
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800322 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800323 def _bios_corrupt_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800324 """Corrupt the requested firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700325
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800326 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700327 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800328 self._bios_handler.corrupt_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700329
Tom Wai-Hong Tam0e680af2011-10-26 14:32:55 +0800330 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800331 def _bios_restore_sig(self, section):
Tom Wai-Hong Tam9aea8212011-12-12 15:08:45 +0800332 """Restore the previously corrupted firmware section signature.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700333
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800334 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700335 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800336 self._bios_handler.restore_firmware(section)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700337
Tom Wai-Hong Tamcfda61f2011-11-02 17:41:01 +0800338 @allow_multiple_section_input
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800339 def _bios_corrupt_body(self, section):
340 """Corrupt the requested firmware section body.
341
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800342 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800343 """
344 self._bios_handler.corrupt_firmware_body(section)
345
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800346 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800347 def _bios_restore_body(self, section):
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800348 """Restore the previously corrupted firmware section body.
349
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800350 @param section: A firmware section, either 'a' or 'b'.
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800351 """
Vic Yang59cac9c2012-05-21 15:28:42 +0800352 self._bios_handler.restore_firmware_body(section)
Tom Wai-Hong Tam81f70002011-12-13 12:29:46 +0800353
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800354 def __bios_modify_version(self, section, delta):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800355 """Modify firmware version for the requested section, by adding delta.
356
357 The passed in delta, a positive or a negative number, is added to the
358 original firmware version.
359 """
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800360 original_version = self._bios_get_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800361 new_version = original_version + delta
Vic Yang59cac9c2012-05-21 15:28:42 +0800362 flags = self._bios_handler.get_section_flags(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800363 self._chromeos_interface.log(
364 'Setting firmware section %s version from %d to %d' % (
365 section, original_version, new_version))
Vic Yang59cac9c2012-05-21 15:28:42 +0800366 self._bios_handler.set_section_version(section, new_version, flags,
367 write_through=True)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800368
369 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800370 def _bios_move_version_backward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800371 """Decrement firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800372 self.__bios_modify_version(section, -1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800373
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800374 @allow_multiple_section_input
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800375 def _bios_move_version_forward(self, section):
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800376 """Increase firmware version for the requested section."""
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800377 self.__bios_modify_version(section, 1)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800378
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800379 def _bios_get_version(self, section):
380 """Retrieve firmware version of a section."""
381 return self._bios_handler.get_section_version(section)
382
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800383 def _bios_get_datakey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800384 """Return firmware data key version."""
385 return self._bios_handler.get_section_datakey_version(section)
386
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800387 def _bios_get_kernel_subkey_version(self, section):
ctchangc7e55ea2012-08-09 16:19:14 +0800388 """Return kernel subkey version."""
389 return self._bios_handler.get_section_kernel_subkey_version(section)
Tom Wai-Hong Tam46d03b12012-02-08 12:02:17 +0800390
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800391 def _bios_setup_EC_image(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800392 """Setup the new EC image for later update.
393
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800394 @param ec_path: The path of the EC image to be updated.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800395 """
396 self._ec_image = flashrom_handler.FlashromHandler()
397 self._ec_image.init(saft_flashrom_util,
398 self._chromeos_interface,
399 'ec_root_key.vpubk',
400 '/usr/share/vboot/devkeys',
401 'ec')
402 self._ec_image.new_image(ec_path)
403
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800404 def _bios_get_EC_image_sha(self):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800405 """Get SHA1 hash of RW firmware section of the EC autest image."""
406 return self._ec_image.get_section_sha('rw')
407
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800408 def _bios_update_EC_from_image(self, section, flags):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800409 """Update EC via software sync design.
410
411 It copys the RW section from the EC image, which is loaded by calling
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800412 bios_setup_EC_image(), to the EC area of the specified RW section on the
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800413 current AP firmware.
414
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800415 @param section: A firmware section on current BIOS, either 'a' or 'b'.
416 @param flags: An integer of preamble flags.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800417 """
418 blob = self._ec_image.get_section_body('rw')
419 self._bios_handler.set_section_ecbin(section, blob,
420 write_through=True)
Chun-ting Chang708a2762012-12-10 12:25:13 +0800421 self._bios_set_preamble_flags(section, flags)
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800422
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800423 def _bios_dump_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800424 """Dump the current BIOS firmware to a file, specified by bios_path.
425
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800426 @param bios_path: The path of the BIOS image to be written.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800427 """
428 self._bios_handler.dump_whole(bios_path)
429
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800430 def _bios_dump_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800431 """Dump the current BIOS firmware RW to dir_path.
432
433 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be dumped.
434
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800435 @param dir_path: The path of directory which contains files to be
436 written.
ctchang38ae4922012-09-03 17:01:16 +0800437 """
438 if not os.path.isdir(dir_path):
439 raise Exception("%s doesn't exist" % dir_path)
440
441 VBOOTA_blob = self._bios_handler.get_section_sig('a')
442 VBOOTB_blob = self._bios_handler.get_section_sig('b')
443 FVMAIN_blob = self._bios_handler.get_section_body('a')
444 FVMAINB_blob = self._bios_handler.get_section_body('b')
445
446 open(os.path.join(dir_path, 'VBOOTA'), 'w').write(VBOOTA_blob)
447 open(os.path.join(dir_path, 'VBOOTB'), 'w').write(VBOOTB_blob)
448 open(os.path.join(dir_path, 'FVMAIN'), 'w').write(FVMAIN_blob)
449 open(os.path.join(dir_path, 'FVMAINB'), 'w').write(FVMAINB_blob)
450
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800451 def _bios_write_whole(self, bios_path):
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800452 """Write the firmware from bios_path to the current system.
453
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800454 @param bios_path: The path of the source BIOS image.
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800455 """
456 self._bios_handler.new_image(bios_path)
457 self._bios_handler.write_whole()
458
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800459 def _bios_write_rw(self, dir_path):
ctchang38ae4922012-09-03 17:01:16 +0800460 """Write the firmware RW from dir_path to the current system.
461
462 VBOOTA, VBOOTB, FVMAIN, FVMAINB need to be written.
463
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800464 @param dir_path: The path of directory which contains the source files.
ctchang38ae4922012-09-03 17:01:16 +0800465 """
466 if not os.path.exists(os.path.join(dir_path, 'VBOOTA')) or \
467 not os.path.exists(os.path.join(dir_path, 'VBOOTB')) or \
468 not os.path.exists(os.path.join(dir_path, 'FVMAIN')) or \
469 not os.path.exists(os.path.join(dir_path, 'FVMAINB')):
470 raise Exception("Source firmware file(s) doesn't exist.")
471
472 VBOOTA_blob = open(os.path.join(dir_path, 'VBOOTA'), 'rb').read()
473 VBOOTB_blob = open(os.path.join(dir_path, 'VBOOTB'), 'rb').read()
474 FVMAIN_blob = open(os.path.join(dir_path, 'FVMAIN'), 'rb').read()
475 FVMAINB_blob = open(os.path.join(dir_path, 'FVMAINB'), 'rb').read()
476
477 self._bios_handler.set_section_sig('a', VBOOTA_blob,
478 write_through=True)
479 self._bios_handler.set_section_sig('b', VBOOTB_blob,
480 write_through=True)
481 self._bios_handler.set_section_body('a', FVMAIN_blob,
482 write_through=True)
483 self._bios_handler.set_section_body('b', FVMAINB_blob,
484 write_through=True)
485
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800486 def _ec_get_version(self):
487 """Get EC version via mosys.
488
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800489 @return: A string of the EC version.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800490 """
491 return self._chromeos_interface.run_shell_command_get_output(
492 'mosys ec info | sed "s/.*| //"')[0]
493
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800494 def _ec_get_firmware_sha(self):
495 """Get SHA1 hash of EC RW firmware section."""
496 return self._ec_handler.get_section_sha('rw')
497
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800498 @allow_multiple_section_input
499 def _ec_corrupt_sig(self, section):
500 """Corrupt the requested EC section signature.
501
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800502 @param section: A EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800503 """
504 self._ec_handler.corrupt_firmware(section, corrupt_all=True)
505
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800506 @allow_multiple_section_input
507 def _ec_restore_sig(self, section):
508 """Restore the previously corrupted EC section signature.
509
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800510 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800511 """
512 self._ec_handler.restore_firmware(section, restore_all=True)
513
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800514 @allow_multiple_section_input
515 def _ec_corrupt_body(self, section):
516 """Corrupt the requested EC section body.
517
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800518 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800519 """
520 self._ec_handler.corrupt_firmware_body(section, corrupt_all=True)
521
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800522 @allow_multiple_section_input
523 def _ec_restore_body(self, section):
524 """Restore the previously corrupted EC section body.
525
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800526 @param section: An EC section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800527 """
528 self._ec_handler.restore_firmware_body(section, restore_all=True)
529
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800530 def _ec_dump_firmware(self, ec_path):
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800531 """Dump the current EC firmware to a file, specified by ec_path.
532
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800533 @param ec_path: The path of the EC image to be written.
Tom Wai-Hong Tam23870e02012-08-24 16:15:34 +0800534 """
535 self._ec_handler.dump_whole(ec_path)
536
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800537 def _ec_set_write_protect(self, enable):
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800538 """Enable write protect of the EC flash chip.
539
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800540 @param enable: True if activating EC write protect. Otherwise, False.
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800541 """
Tom Wai-Hong Tam44204b32012-11-20 13:55:40 +0800542 if enable:
543 self._ec_handler.enable_write_protect()
544 else:
545 self._ec_handler.disable_write_protect()
546
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800547 @allow_multiple_section_input
548 def _kernel_corrupt_sig(self, section):
549 """Corrupt the requested kernel section.
550
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800551 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800552 """
553 self._kernel_handler.corrupt_kernel(section)
554
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800555 @allow_multiple_section_input
556 def _kernel_restore_sig(self, section):
557 """Restore the requested kernel section (previously corrupted).
558
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800559 @param section: A kernel section, either 'a' or 'b'.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800560 """
561 self._kernel_handler.restore_kernel(section)
562
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800563 def __kernel_modify_version(self, section, delta):
564 """Modify kernel version for the requested section, by adding delta.
565
566 The passed in delta, a positive or a negative number, is added to the
567 original kernel version.
568 """
569 original_version = self._kernel_handler.get_version(section)
570 new_version = original_version + delta
571 self._chromeos_interface.log(
572 'Setting kernel section %s version from %d to %d' % (
573 section, original_version, new_version))
574 self._kernel_handler.set_version(section, new_version)
575
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800576 @allow_multiple_section_input
577 def _kernel_move_version_backward(self, section):
578 """Decrement kernel version for the requested section."""
579 self.__kernel_modify_version(section, -1)
580
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800581 @allow_multiple_section_input
582 def _kernel_move_version_forward(self, section):
583 """Increase kernel version for the requested section."""
584 self.__kernel_modify_version(section, 1)
585
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800586 def _kernel_get_version(self, section):
587 """Return kernel version."""
588 return self._kernel_handler.get_version(section)
589
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800590 def _kernel_get_datakey_version(self, section):
591 """Return kernel datakey version."""
592 return self._kernel_handler.get_datakey_version(section)
593
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800594 def _kernel_diff_a_b(self):
595 """Compare kernel A with B.
596
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800597 @return: True: if kernel A is different with B.
598 False: if kernel A is the same as B.
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800599 """
600 rootdev = self._chromeos_interface.get_root_dev()
601 kernel_a = self._chromeos_interface.join_part(rootdev, '3')
602 kernel_b = self._chromeos_interface.join_part(rootdev, '5')
603
604 # The signature (some kind of hash) for the kernel body is stored in
605 # the beginning. So compare the first 64KB (including header, preamble,
606 # and signature) should be enough to check them identical.
607 header_a = self._chromeos_interface.read_partition(kernel_a, 0x10000)
608 header_b = self._chromeos_interface.read_partition(kernel_b, 0x10000)
609
610 return header_a != header_b
611
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800612 def _kernel_resign_with_keys(self, section, key_path=None):
613 """Resign kernel with temporary key."""
614 self._kernel_handler.resign_kernel(section, key_path)
615
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800616 def _tpm_get_firmware_version(self):
617 """Retrieve tpm firmware body version."""
618 return self._tpm_handler.get_fw_version()
619
Tom Wai-Hong Tamc1a569f2012-12-04 15:07:25 +0800620 def _tpm_get_firmware_datakey_version(self):
621 """Retrieve tpm firmware data key version."""
622 return self._tpm_handler.get_fw_body_version()
623
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800624 def _cgpt_run_test_loop(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800625 """Run the CgptState test loop. The tst logic is handled in the client.
626
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800627 @return: 0: there are more cgpt tests to execute.
628 1: no more CgptState test, finished.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800629 """
630 return self._cgpt_state.test_loop()
631
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800632 def _cgpt_set_test_step(self, step):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800633 """Set the CgptState test step.
634
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800635 @param step: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800636 """
637 self._cgpt_state.set_step(step)
638
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800639 def _cgpt_get_test_step(self):
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800640 """Get the CgptState test step.
641
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800642 @return: A test step number.
Tom Wai-Hong Tam48958832011-12-30 10:16:57 +0800643 """
644 return self._cgpt_state.get_step()
645
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800646 def _updater_setup(self, shellball=None):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800647 """Setup the updater.
648
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800649 @param shellball: Path of provided shellball. Use default shellball
650 if None,
Chun-ting Changcf924e92012-10-29 13:49:01 +0800651 """
652 self._updater.setup(self._chromeos_interface, shellball)
653
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800654 def _updater_cleanup(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800655 self._updater.cleanup_temp_dir()
656
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800657 def _updater_get_fwid(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800658 """Retrieve shellball's fwid.
659
660 This method should be called after updater_setup.
661
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800662 @return: Shellball's fwid.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800663 """
664 return self._updater.retrieve_fwid()
665
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800666 def _updater_resign_firmware(self, version):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800667 """Resign firmware with version.
668
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800669 @param version: new version number.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800670 """
671 self._updater.resign_firmware(version)
672
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800673 def _updater_repack_shellball(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800674 """Repack shellball with new fwid.
675
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800676 @param append: use for new fwid naming.
Chun-ting Changcf924e92012-10-29 13:49:01 +0800677 """
678 self._updater.repack_shellball(append)
679
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800680 def _updater_run_autoupdate(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800681 """Run chromeos-firmwareupdate with autoupdate mode."""
682 options = ['--noupdate_ec', '--nocheck_rw_compatible']
683 self._updater.run_firmwareupdate(mode='autoupdate',
684 updater_append=append,
685 options=options)
686
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800687 def _updater_run_factory_install(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800688 """Run chromeos-firmwareupdate with factory_install mode."""
689 options = ['--noupdate_ec']
690 self._updater.run_firmwareupdate(mode='factory_install',
691 options=options)
692
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800693 def _updater_run_bootok(self, append):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800694 """Run chromeos-firmwareupdate with bootok mode."""
695 self._updater.run_firmwareupdate(mode='bootok',
696 updater_append=append)
697
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800698 def _updater_run_recovery(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800699 """Run chromeos-firmwareupdate with recovery mode."""
700 options = ['--noupdate_ec', '--nocheck_rw_compatible']
701 self._updater.run_firmwareupdate(mode='recovery',
702 options=options)
703
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800704 def _updater_get_temp_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800705 """Get updater's temp directory path."""
706 return self._updater.get_temp_path()
707
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800708 def _updater_get_keys_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800709 """Get updater's keys directory path."""
710 return self._updater.get_keys_path()
711
Chun-ting Changd43aa9b2012-11-16 10:12:05 +0800712 def _updater_get_work_path(self):
Chun-ting Changcf924e92012-10-29 13:49:01 +0800713 """Get updater's work directory path."""
714 return self._updater.get_work_path()
715
Tom Wai-Hong Tambea57b32011-09-02 18:27:47 +0800716 def cleanup(self):
717 """Cleanup for the RPC server. Currently nothing."""
718 pass
719
720
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700721def main():
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800722 """The Main program, to run the XMLRPC server."""
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700723 parser = OptionParser(usage='Usage: %prog [options]')
724 parser.add_option('--port', type='int', dest='port', default=9990,
725 help='port number of XMLRPC server')
Tom Wai-Hong Tam144202a2013-07-18 13:59:29 +0800726 (options, _) = parser.parse_args()
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700727
728 faft_client = FAFTClient()
729
730 # Launch the XMLRPC server to provide FAFTClient commands.
Tom Wai-Hong Tam4a257e52011-11-12 08:36:22 +0800731 server = SimpleXMLRPCServer(('localhost', options.port), allow_none=True,
Tom Wai-Hong Tamc1e0b9a2012-11-01 13:52:39 +0800732 logRequests=True)
Tom Wai-Hong Tamb8a58ef2011-10-11 23:53:10 -0700733 server.register_introspection_functions()
734 server.register_instance(faft_client)
735 print 'XMLRPC Server: Serving FAFTClient on port %s' % options.port
736 server.serve_forever()
737
738
739if __name__ == '__main__':
740 main()