blob: 96d3bc283ff25dae5fbb7d7df61a7767a3b96b99 [file] [log] [blame]
Tammo Spalink9a96b8a2012-04-03 11:10:41 +08001#!/usr/bin/python
Tammo Spalink01e11722012-07-24 10:17:54 -07002# pylint: disable=E1101
Tammo Spalink9a96b8a2012-04-03 11:10:41 +08003#
4# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Google Factory Tool.
9
10This tool is indended to be used on factory assembly lines. It
11provides all of the Google required test functionality and must be run
12on each device as part of the assembly process.
13"""
14
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080015import logging
16import os
Jon Salz65266432012-07-30 19:02:49 +080017import pipes
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080018import re
19import sys
Hung-Te Lin6bd16472012-06-20 16:26:47 +080020import time
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080021
Andy Cheng2582d292012-12-04 17:38:28 +080022from tempfile import gettempdir
Tammo Spalink86a61c62012-05-25 15:10:35 +080023
Tammo Spalinka40293e2012-07-04 14:58:56 +080024import factory_common # pylint: disable=W0611
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080025
Jon Salz0f8a6842012-09-25 11:28:22 +080026from cros.factory.common import Error, SetupLogging, Shell
Tammo Spalink394e4492012-08-01 10:20:30 -070027from cros.factory.common import YamlWrite
Tammo Spalink01e11722012-07-24 10:17:54 -070028from cros.factory.gooftool import crosfw
Andy Chengc531e2f2012-10-15 19:09:17 +080029from cros.factory.gooftool import Gooftool
Tammo Spalink01e11722012-07-24 10:17:54 -070030from cros.factory.gooftool import report_upload
Andy Cheng8ece7382012-08-22 16:25:42 +080031from cros.factory.gooftool.probe import Probe, PROBEABLE_COMPONENT_CLASSES
Jon Salz0f8a6842012-09-25 11:28:22 +080032from cros.factory.gooftool.probe import ReadRoVpd, ReadRwVpd
Jon Salz193d7c62013-03-07 13:40:19 +080033from cros.factory.gooftool.vpd_data import KNOWN_VPD_FIELD_DATA
Tammo Spalinka40293e2012-07-04 14:58:56 +080034from cros.factory.hacked_argparse import CmdArg, Command, ParseCmdline
35from cros.factory.hacked_argparse import verbosity_cmd_arg
Tammo Spalink01e11722012-07-24 10:17:54 -070036from cros.factory.hwdb import hwid_tool
Jon Salz83591782012-06-26 11:09:58 +080037from cros.factory.event_log import EventLog, EVENT_LOG_DIR
38from cros.factory.event_log import TimedUuid
cychiang7fe09372012-07-04 14:31:23 +080039from cros.factory.test.factory import FACTORY_LOG_PATH
Jon Salzff88c022012-11-03 12:19:58 +080040from cros.factory.utils.process_utils import Spawn
Jon Salz193d7c62013-03-07 13:40:19 +080041from cros.factory.system.vpd import FilterVPD
Tammo Spalink86a61c62012-05-25 15:10:35 +080042
Tammo Spalink5c699832012-07-03 17:50:39 +080043
Tammo Spalink86a61c62012-05-25 15:10:35 +080044# Use a global event log, so that only a single log is created when
45# gooftool is called programmatically.
46_event_log = EventLog('gooftool')
47
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080048
Tammo Spalink5c699832012-07-03 17:50:39 +080049# TODO(tammo): Replace calls to sys.exit with raise Exit, and maybe
50# treat that specially (as a smoot exit, as opposed to the more
51# verbose output for generic Error).
52
53
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080054@Command('write_hwid',
55 CmdArg('hwid', metavar='HWID', help='HWID string'))
Andy Chengc92e6f92012-11-20 16:55:53 +080056def WriteHWID(options):
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080057 """Write specified HWID value into the system BB."""
Andy Cheng7a76cb82012-11-19 18:08:19 +080058
Tammo Spalink95c43732012-07-25 15:57:14 -070059 logging.info('writing hwid string %r', options.hwid)
Andy Chengc92e6f92012-11-20 16:55:53 +080060 Gooftool().WriteHWID(options.hwid)
Tammo Spalink86a61c62012-05-25 15:10:35 +080061 _event_log.Log('write_hwid', hwid=options.hwid)
Tammo Spalink95c43732012-07-25 15:57:14 -070062 print 'Wrote HWID: %r' % options.hwid
Tammo Spalink9a96b8a2012-04-03 11:10:41 +080063
64
Tammo Spalink8fab5312012-05-28 18:33:30 +080065_hwdb_path_cmd_arg = CmdArg(
66 '--hwdb_path', metavar='PATH',
67 default=hwid_tool.DEFAULT_HWID_DATA_PATH,
68 help='Path to the HWID database.')
69
Tammo Spalink95c43732012-07-25 15:57:14 -070070_hwid_status_list_cmd_arg = CmdArg(
71 '--status', nargs='*', default=['supported'],
72 help='allow only HWIDs with these status values')
73
Jon Salzce124fb2012-10-02 17:42:03 +080074_probe_results_cmd_arg = CmdArg(
75 '--probe_results', metavar='RESULTS.yaml',
76 help=('Output from "gooftool probe" (used instead of '
77 'probing this system).'))
78
79_hwid_cmd_arg = CmdArg(
80 '--hwid', metavar='HWID',
81 help=('HWID to verify (instead of the currently set HWID of '
82 'this system)'))
83
Tammo Spalink95c43732012-07-25 15:57:14 -070084
85@Command('best_match_hwids',
Tammo Spalink8fab5312012-05-28 18:33:30 +080086 _hwdb_path_cmd_arg,
87 CmdArg('-b', '--board', metavar='BOARD',
Tammo Spalink95c43732012-07-25 15:57:14 -070088 help='optional BOARD name, needed only if data is present '
89 'for more than one'),
Tammo Spalink8fab5312012-05-28 18:33:30 +080090 CmdArg('--bom', metavar='BOM', help='BOM name'),
91 CmdArg('--variant', metavar='VARIANT', help='VARIANT code'),
Tammo Spalink5c699832012-07-03 17:50:39 +080092 CmdArg('--optimistic', action='store_true',
93 help='do not probe; assume singletons match'),
Tammo Spalink95c43732012-07-25 15:57:14 -070094 CmdArg('--comps', nargs='*', default=[],
95 help='list of canonical component names'),
96 CmdArg('--missing', nargs='*', default=[],
97 help='list component classes to be assumed missing'),
Tammo Spalink5c699832012-07-03 17:50:39 +080098 CmdArg('--status', nargs='*', default=['supported'],
Tammo Spalink95c43732012-07-25 15:57:14 -070099 help='consider only HWIDs within this list of status values'))
100def BestMatchHwids(options):
Tammo Spalink8fab5312012-05-28 18:33:30 +0800101 """Determine a list of possible HWIDs using provided args and probeing.
102
103 VOLATILE can always be determined by probing. To get a unique
104 result, VARIANT must be specified for all cases where the matching
105 BOM has more than one associated variant code, otherwise all HWID
106 variants will be returned. Both VARIANT and BOM information can
Tammo Spalink95c43732012-07-25 15:57:14 -0700107 alternatively be specified using the --stdin_comps argument, which
108 allows specifying a list of canonical names (one per line) on stdin,
109 one per line. Based on what is known from BOM and stdin_comps,
110 determine a list of components to probe for, and use those probe
111 results to resolve a list of matching HWIDs. If no boms,
112 components, or variant codes are specified, then a list of all HWIDs
Andy Cheng8ece7382012-08-22 16:25:42 +0800113 that match probeable components will be returned.
Tammo Spalink8fab5312012-05-28 18:33:30 +0800114
115 Returns (on stdout): A list of HWIDs that match the available probe
116 results and argument contraints, one per line.
Tammo Spalink70b48a52012-08-08 16:54:51 -0700117
118 Example:
119
120 // Three ways to specify a keyboard (assuming it is a variant component)
121 gooftool best_match_hwids --missing keyboard
122 gooftool best_match_hwids --variant A or
123 gooftool best_match_hwids --comps us_kbd
Tammo Spalink8fab5312012-05-28 18:33:30 +0800124 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800125
Tammo Spalink5c699832012-07-03 17:50:39 +0800126 map(hwid_tool.Validate.Status, options.status)
Tammo Spalink95c43732012-07-25 15:57:14 -0700127 hw_db = hwid_tool.HardwareDb(options.hwdb_path)
Tammo Spalink5c699832012-07-03 17:50:39 +0800128 comp_db = hw_db.comp_db
Tammo Spalink3a7e9022012-06-27 14:08:40 +0800129 device = hw_db.GetDevice(options.board)
Tammo Spalink5c699832012-07-03 17:50:39 +0800130 component_spec = hwid_tool.ComponentSpec.New()
Tammo Spalink8fab5312012-05-28 18:33:30 +0800131 if options.bom:
Tammo Spalink5c699832012-07-03 17:50:39 +0800132 device.BomExists(options.bom)
Tammo Spalink01e11722012-07-24 10:17:54 -0700133 component_spec = hwid_tool.CombineComponentSpecs(
Tammo Spalink5c699832012-07-03 17:50:39 +0800134 component_spec, device.boms[options.bom].primary)
Tammo Spalink8fab5312012-05-28 18:33:30 +0800135 if options.variant:
Tammo Spalink5c699832012-07-03 17:50:39 +0800136 device.VariantExists(options.variant)
137 variant_spec = device.variants[options.variant]
Tammo Spalink01e11722012-07-24 10:17:54 -0700138 if hwid_tool.ComponentSpecsConflict(component_spec, variant_spec):
Tammo Spalink95c43732012-07-25 15:57:14 -0700139 sys.exit('ERROR: multiple specifications for these components:\n%s'
Tammo Spalink394e4492012-08-01 10:20:30 -0700140 % YamlWrite(sorted(
141 hwid_tool.ComponentSpecClasses(component_spec) &
142 hwid_tool.ComponentSpecClasses(variant_spec))))
Tammo Spalink01e11722012-07-24 10:17:54 -0700143 component_spec = hwid_tool.CombineComponentSpecs(
144 component_spec, variant_spec)
Tammo Spalink95c43732012-07-25 15:57:14 -0700145 if options.comps or options.missing:
146 map(comp_db.CompExists, options.comps)
147 map(comp_db.CompClassExists, options.missing)
148 extra_comp_spec = comp_db.CreateComponentSpec(
149 components=options.comps,
150 missing=options.missing)
151 print 'cmdline asserted components:\n%s' % extra_comp_spec.Encode()
152 if hwid_tool.ComponentSpecsConflict(component_spec, extra_comp_spec):
153 sys.exit('ERROR: multiple specifications for these components:\n%s'
Tammo Spalink394e4492012-08-01 10:20:30 -0700154 % YamlWrite(sorted(
155 hwid_tool.ComponentSpecClasses(component_spec) &
156 hwid_tool.ComponentSpecClasses(extra_comp_spec))))
Tammo Spalink95c43732012-07-25 15:57:14 -0700157 component_spec = hwid_tool.CombineComponentSpecs(
158 component_spec, extra_comp_spec)
Tammo Spalink01e11722012-07-24 10:17:54 -0700159 spec_classes = hwid_tool.ComponentSpecClasses(component_spec)
Tammo Spalink95c43732012-07-25 15:57:14 -0700160 missing_classes = set(comp_db.all_comp_classes) - spec_classes
Tammo Spalink5c699832012-07-03 17:50:39 +0800161 if missing_classes and not options.optimistic:
Andy Cheng8ece7382012-08-22 16:25:42 +0800162 non_probeable_missing = missing_classes - PROBEABLE_COMPONENT_CLASSES
163 if non_probeable_missing:
Tammo Spalink95c43732012-07-25 15:57:14 -0700164 sys.exit('FAILURE: these classes are necessary, were not specified '
Tammo Spalink70b48a52012-08-08 16:54:51 -0700165 'as inputs, and cannot be probed for:\n%s'
166 'This problem can often be addressed by specifying all of '
167 'the missing components on the command line (see the command '
Andy Cheng8ece7382012-08-22 16:25:42 +0800168 'help).' % YamlWrite(list(non_probeable_missing)))
Tammo Spalink95c43732012-07-25 15:57:14 -0700169 print 'probing for missing classes:'
170 print YamlWrite(list(missing_classes))
171 probe_results = Probe(target_comp_classes=list(missing_classes),
172 probe_volatile=False, probe_initial_config=False)
173 cooked_components = comp_db.MatchComponentProbeValues(
174 probe_results.found_probe_value_map)
175 if cooked_components.unmatched:
176 sys.exit('ERROR: some probed components are unrecognized:\n%s'
177 % YamlWrite(cooked_components.unmatched))
178 probed_comp_spec = comp_db.CreateComponentSpec(
179 components=cooked_components.matched,
180 missing=probe_results.missing_component_classes)
181 component_spec = hwid_tool.CombineComponentSpecs(
182 component_spec, probed_comp_spec)
183 print YamlWrite({'component data used for matching': {
184 'missing component classes': component_spec.classes_missing,
185 'found components': component_spec.components}})
186 component_data = hwid_tool.ComponentData(
187 extant_components=hwid_tool.ComponentSpecCompClassMap(
188 component_spec).keys(),
189 classes_missing=component_spec.classes_missing)
190 match_tree = device.BuildMatchTree(component_data)
191 if not match_tree:
192 sys.exit('FAILURE: NO matching BOMs found')
193 print 'potential BOMs/VARIANTs:'
194 potential_variants = set()
195 potential_volatiles = set()
196 for bom_name, variant_tree in match_tree.items():
197 print ' BOM: %-8s VARIANTS: %s' % (
198 bom_name, ', '.join(sorted(variant_tree)))
199 for variant_code in variant_tree:
200 potential_variants.add(variant_code)
201 for volatile_code in device.volatiles:
202 status = device.GetHwidStatus(bom_name, variant_code, volatile_code)
203 if status in options.status:
204 potential_volatiles.add(volatile_code)
205 print ''
206 if len(potential_variants) == 0:
207 sys.exit('FAILURE: no matching VARIANTs found')
208 if len(potential_volatiles) == 0:
209 sys.exit('FAILURE: no VOLATILEs found for potential matching BOMs/VARIANTS '
210 '(with specified status)')
Tammo Spalink394e4492012-08-01 10:20:30 -0700211 if (options.optimistic and
212 len(match_tree) == 1 and
213 len(potential_variants) == 1 and
214 len(potential_volatiles) == 1):
215 print ('MATCHING HWID: %s' % device.FmtHwid(match_tree.keys().pop(),
216 potential_variants.pop(),
217 potential_volatiles.pop()))
Tammo Spalink5c699832012-07-03 17:50:39 +0800218 return
Tammo Spalink95c43732012-07-25 15:57:14 -0700219 print ('probing VOLATILEs to resolve potential matches: %s\n' %
220 ', '.join(sorted(potential_volatiles)))
221 vol_probe_results = Probe(
222 target_comp_classes=[],
223 probe_volatile=True,
224 probe_initial_config=False)
225 cooked_volatiles = device.MatchVolatileValues(
226 vol_probe_results.found_volatile_values)
227 match_tree = device.BuildMatchTree(
228 component_data, cooked_volatiles.matched_tags)
229 matched_hwids = device.GetMatchTreeHwids(match_tree)
230 if matched_hwids:
231 for hwid in matched_hwids:
Ricky Liang02f3bd72012-09-21 14:33:01 +0800232 if matched_hwids[hwid] in options.status:
233 print 'MATCHING HWID: %s' % hwid
Tammo Spalink95c43732012-07-25 15:57:14 -0700234 return
235 print 'exact HWID matching failed, but the following BOMs match: %s' % (
236 ', '.join(sorted(match_tree)))
237 if options.optimistic and len(match_tree) == 1:
238 bom_name = set(match_tree).pop()
Tammo Spalink5c699832012-07-03 17:50:39 +0800239 bom = device.boms[bom_name]
Tammo Spalink95c43732012-07-25 15:57:14 -0700240 variant_matches = match_tree[bom_name]
Tammo Spalink5c699832012-07-03 17:50:39 +0800241 if len(variant_matches) == 1:
242 var_code = set(variant_matches).pop()
243 elif len(bom.variants) == 1:
244 var_code = set(bom.variants).pop()
245 else:
Tammo Spalink95c43732012-07-25 15:57:14 -0700246 sys.exit('FAILURE: NO matching HWIDs found; optimistic matching failed '
247 'because there were too many variants to choose from for BOM %r'
248 % bom_name)
249 hwids = [device.FmtHwid(bom_name, var_code, vol_code)
250 for vol_code in device.volatiles
251 if device.GetHwidStatus(bom_name, var_code, vol_code)
252 in options.status]
253 for hwid in hwids:
254 print 'MATCHING HWID: %s' % hwid
Tammo Spalink5c699832012-07-03 17:50:39 +0800255 return
256 else:
Tammo Spalink95c43732012-07-25 15:57:14 -0700257 print ('optimistic matching not attempted because either it was '
258 'not requested, or because the number of BOMs was <> 1\n')
259 sys.exit('FAILURE: NO matching HWIDs found')
Tammo Spalink8fab5312012-05-28 18:33:30 +0800260
261
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800262@Command('probe',
263 CmdArg('--comps', nargs='*',
264 help='List of keys from the component_db registry.'),
265 CmdArg('--no_vol', action='store_true',
266 help='Do not probe volatile data.'),
267 CmdArg('--no_ic', action='store_true',
Jon Salz0f8a6842012-09-25 11:28:22 +0800268 help='Do not probe initial_config data.'),
269 CmdArg('--include_vpd', action='store_true',
270 help='Include VPD data in volatiles.'))
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800271def RunProbe(options):
272 """Print yaml-formatted breakdown of probed device properties."""
Andy Chengc92e6f92012-11-20 16:55:53 +0800273 print Gooftool().Probe(target_comp_classes=options.comps,
274 probe_volatile=not options.no_vol,
275 probe_initial_config=not options.no_ic,
276 probe_vpd=options.include_vpd).Encode()
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800277
Tammo Spalink214caf42012-05-28 10:45:00 +0800278@Command('verify_components',
279 _hwdb_path_cmd_arg,
Tammo Spalink5c699832012-07-03 17:50:39 +0800280 CmdArg('target_comps', nargs='*'))
Tammo Spalink214caf42012-05-28 10:45:00 +0800281def VerifyComponents(options):
Andy Cheng8ece7382012-08-22 16:25:42 +0800282 """Verify that probeable components all match entries in the component_db.
Tammo Spalink214caf42012-05-28 10:45:00 +0800283
Tammo Spalink5c699832012-07-03 17:50:39 +0800284 Probe for each component class in the target_comps and verify
Tammo Spalink214caf42012-05-28 10:45:00 +0800285 that a corresponding match exists in the component_db -- make sure
286 that these components are present, that they have been approved, but
287 do not check against any specific BOM/HWID configurations.
288 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800289
Tammo Spalink5c699832012-07-03 17:50:39 +0800290 comp_db = hwid_tool.HardwareDb(options.hwdb_path).comp_db
Andy Chengc531e2f2012-10-15 19:09:17 +0800291 try:
292 result = Gooftool(component_db=comp_db).VerifyComponents(
293 options.target_comps)
294 except ValueError, e:
295 sys.exit(e)
296
297 # group by matches and errors
Tammo Spalink214caf42012-05-28 10:45:00 +0800298 matches = []
Andy Chengc531e2f2012-10-15 19:09:17 +0800299 errors = []
300 for result_list in result.values():
301 for component_name, _, error in result_list:
302 if component_name:
303 matches.append(component_name)
Tammo Spalink214caf42012-05-28 10:45:00 +0800304 else:
Andy Chengc531e2f2012-10-15 19:09:17 +0800305 errors.append(error)
306
Andy Cheng228a8c92012-08-27 10:53:57 +0800307 if matches:
308 print 'found probeable components:\n %s' % '\n '.join(matches)
Tammo Spalink214caf42012-05-28 10:45:00 +0800309 if errors:
Andy Cheng228a8c92012-08-27 10:53:57 +0800310 print '\nerrors:\n %s' % '\n '.join(errors)
311 sys.exit('\ncomponent verification FAILURE')
Tammo Spalink214caf42012-05-28 10:45:00 +0800312 else:
Andy Cheng228a8c92012-08-27 10:53:57 +0800313 print "\ncomponent verification SUCCESS"
Tammo Spalink214caf42012-05-28 10:45:00 +0800314
315
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800316@Command('verify_hwid',
Tammo Spalink95c43732012-07-25 15:57:14 -0700317 _hwid_status_list_cmd_arg,
Jon Salz0f8a6842012-09-25 11:28:22 +0800318 _hwdb_path_cmd_arg,
Jon Salzce124fb2012-10-02 17:42:03 +0800319 _probe_results_cmd_arg,
320 _hwid_cmd_arg)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800321def VerifyHwid(options):
322 """Verify system HWID properties match probed device properties.
323
324 First probe components, volatile and initial_config parameters for
325 the DUT. Then use the available device data to produce a list of
326 candidate HWIDs. Then verify the HWID from the DUT is present in
327 that list. Then verify that the DUT initial config values match
328 those specified for its HWID. Finally, verify that VPD contains all
329 the necessary fields as specified by the board data, and when
330 possible verify that values are legitimate.
331 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800332
Ricky Liangf7857c12012-09-17 13:34:41 +0800333 def VerifyVpd(ro_vpd_keys, rw_vpd_keys):
Tammo Spalink5c699832012-07-03 17:50:39 +0800334 for key in ro_vpd_keys:
335 if key not in ro_vpd:
Ricky Liangf7857c12012-09-17 13:34:41 +0800336 sys.exit('Missing required RO VPD field: %s' % key)
Tammo Spalink01e11722012-07-24 10:17:54 -0700337 known_valid_values = KNOWN_VPD_FIELD_DATA.get(key, None)
Tammo Spalink5c699832012-07-03 17:50:39 +0800338 value = ro_vpd[key]
Ricky Liangf7857c12012-09-17 13:34:41 +0800339 if (known_valid_values is not None) and (value not in known_valid_values):
340 sys.exit('Invalid RO VPD entry : key %r, value %r' % (key, value))
Ricky Liangf7857c12012-09-17 13:34:41 +0800341 for key in rw_vpd_keys:
342 if key not in rw_vpd:
343 sys.exit('Missing required RW VPD field: %s' % key)
344 known_valid_values = KNOWN_VPD_FIELD_DATA.get(key, None)
345 value = rw_vpd[key]
346 if (known_valid_values is not None) and (value not in known_valid_values):
347 sys.exit('Invalid RW VPD entry : key %r, value %r' % (key, value))
Jon Salz05aba9d2012-10-05 17:25:38 +0800348 _event_log.Log('vpd', ro_vpd=FilterVPD(ro_vpd), rw_vpd=FilterVPD(rw_vpd))
Tammo Spalink5c699832012-07-03 17:50:39 +0800349 map(hwid_tool.Validate.Status, options.status)
Jon Salz0f8a6842012-09-25 11:28:22 +0800350
Jon Salz81350812012-10-11 16:13:22 +0800351 if not options.hwid or not options.probe_results:
352 main_fw_file = crosfw.LoadMainFirmware().GetFileName()
Jon Salz0f8a6842012-09-25 11:28:22 +0800353
354 if options.hwid:
355 hwid_str = options.hwid
356 else:
357 gbb_result = Shell('gbb_utility -g --hwid %s' % main_fw_file).stdout
358 hwid_str = re.findall(r'hardware_id:(.*)', gbb_result)[0].strip()
Tammo Spalink95c43732012-07-25 15:57:14 -0700359 hwid = hwid_tool.ParseHwid(hwid_str)
Tammo Spalink5c699832012-07-03 17:50:39 +0800360 hw_db = hwid_tool.HardwareDb(options.hwdb_path)
Jon Salz0f8a6842012-09-25 11:28:22 +0800361 print 'Verifying HWID: %r\n' % hwid.hwid
Tammo Spalink95c43732012-07-25 15:57:14 -0700362 device = hw_db.GetDevice(hwid.board)
363 hwid_status = device.GetHwidStatus(hwid.bom, hwid.variant, hwid.volatile)
364 if hwid_status not in options.status:
Tammo Spalink5c699832012-07-03 17:50:39 +0800365 sys.exit('HWID status must be one of [%s], found %r' %
Hung-Te Lin4f5beb12012-08-20 14:48:06 +0800366 (', '.join(options.status), hwid_status))
Jon Salz0f8a6842012-09-25 11:28:22 +0800367 if options.probe_results:
368 # Pull in probe results (including VPD data) from the given file
369 # rather than probing the current system.
370 probe_results = hwid_tool.ProbeResults.Decode(
371 open(options.probe_results).read())
372 ro_vpd = {}
373 rw_vpd = {}
374 for k, v in probe_results.found_volatile_values.items():
375 match = re.match('^vpd\.(ro|rw)\.(\w+)$', k)
376 if match:
377 del probe_results.found_volatile_values[k]
378 (ro_vpd if match.group(1) == 'ro' else rw_vpd)[match.group(2)] = v
379 else:
380 probe_results = Probe()
381 ro_vpd = ReadRoVpd(main_fw_file)
382 rw_vpd = ReadRwVpd(main_fw_file)
Tammo Spalink95c43732012-07-25 15:57:14 -0700383 cooked_components = hw_db.comp_db.MatchComponentProbeValues(
384 probe_results.found_probe_value_map)
385 cooked_volatiles = device.MatchVolatileValues(
386 probe_results.found_volatile_values)
387 cooked_initial_configs = device.MatchInitialConfigValues(
388 probe_results.initial_configs)
389 component_data = hwid_tool.ComponentData(
390 extant_components=cooked_components.matched,
391 classes_missing=probe_results.missing_component_classes)
392 match_tree = device.BuildMatchTree(
393 component_data, cooked_volatiles.matched_tags)
394 matched_hwids = device.GetMatchTreeHwids(match_tree)
395 print 'HWID status: %s\n' % hwid_status
396 print 'probed system components:'
397 print YamlWrite(cooked_components.__dict__)
398 print 'missing component classes:'
399 print YamlWrite(probe_results.missing_component_classes)
400 print 'probed volatiles:'
401 print YamlWrite(cooked_volatiles.__dict__)
402 print 'probed initial_configs:'
403 print YamlWrite(cooked_initial_configs)
404 print 'hwid match tree:'
405 print YamlWrite(match_tree)
Tammo Spalink86a61c62012-05-25 15:10:35 +0800406 _event_log.Log(
Tammo Spalink5c699832012-07-03 17:50:39 +0800407 'probe',
Tammo Spalink95c43732012-07-25 15:57:14 -0700408 found_components=cooked_components.__dict__,
409 missing_component_classes=probe_results.missing_component_classes,
410 volatiles=cooked_volatiles.__dict__,
411 initial_configs=cooked_initial_configs)
412 if hwid.hwid not in matched_hwids:
Tammo Spalink5c699832012-07-03 17:50:39 +0800413 err_msg = 'HWID verification FAILED.\n'
Tammo Spalink95c43732012-07-25 15:57:14 -0700414 if cooked_components.unmatched:
Tammo Spalink5c699832012-07-03 17:50:39 +0800415 sys.exit(err_msg + 'some components could not be indentified:\n%s' %
Tammo Spalink95c43732012-07-25 15:57:14 -0700416 YamlWrite(cooked_components.unmatched))
417 if not match_tree:
Tammo Spalink5c699832012-07-03 17:50:39 +0800418 sys.exit(err_msg + 'no matching boms were found for components:\n%s' %
Tammo Spalink95c43732012-07-25 15:57:14 -0700419 component_data.Encode())
420 if hwid.bom not in match_tree:
Tammo Spalink5c699832012-07-03 17:50:39 +0800421 sys.exit(err_msg + 'matching boms [%s] do not include target bom %r' %
Tammo Spalink95c43732012-07-25 15:57:14 -0700422 (', '.join(sorted(match_tree)), hwid.bom))
423 err_msg += 'target bom %r matches components' % hwid.bom
424 if hwid.bom not in device.IntersectBomsAndInitialConfigs(
425 cooked_initial_configs):
Tammo Spalink5c699832012-07-03 17:50:39 +0800426 sys.exit(err_msg + ', but failed initial config verification')
Tammo Spalink95c43732012-07-25 15:57:14 -0700427 matched_variants = match_tree.get(hwid.bom, {})
428 if hwid.variant not in matched_variants:
Tammo Spalink5c699832012-07-03 17:50:39 +0800429 sys.exit(err_msg + ', but target variant_code %r did not match' %
Tammo Spalink95c43732012-07-25 15:57:14 -0700430 hwid.variant)
431 matched_volatiles = matched_variants.get(hwid.variant, {})
432 if hwid.volatile not in matched_volatiles:
Tammo Spalink5c699832012-07-03 17:50:39 +0800433 sys.exit(err_msg + ', but target volatile_code %r did not match' %
Tammo Spalink95c43732012-07-25 15:57:14 -0700434 hwid.volatile)
435 found_status = matched_volatiles.get(hwid.volatile, None)
Tammo Spalink5c699832012-07-03 17:50:39 +0800436 sys.exit(err_msg + ', but hwid status %r was unacceptable' % found_status)
Ricky Liangf7857c12012-09-17 13:34:41 +0800437 VerifyVpd(device.vpd_ro_fields, device.vpd_rw_fields)
Tammo Spalink5c699832012-07-03 17:50:39 +0800438 _event_log.Log('verified_hwid', hwid=hwid)
Tammo Spalink95c43732012-07-25 15:57:14 -0700439 print 'Verification SUCCESS!'
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800440
441
442@Command('verify_keys')
Tammo Spalink01e11722012-07-24 10:17:54 -0700443def VerifyKeys(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800444 """Verify keys in firmware and SSD match."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800445
446 return Gooftool().VerifyKeys()
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800447
448
449@Command('set_fw_bitmap_locale')
Tammo Spalink01e11722012-07-24 10:17:54 -0700450def SetFirmwareBitmapLocale(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800451 """Use VPD locale value to set firmware bitmap default language."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800452
Andy Cheng2582d292012-12-04 17:38:28 +0800453 (index, locale) = Gooftool().SetFirmwareBitmapLocale()
454 logging.info('Firmware bitmap initial locale set to %d (%s).',
455 index, locale)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800456
457
458@Command('verify_system_time')
Tammo Spalink01e11722012-07-24 10:17:54 -0700459def VerifySystemTime(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800460 """Verify system time is later than release filesystem creation time."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800461
462 return Gooftool().VerifySystemTime()
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800463
464
465@Command('verify_rootfs')
Tammo Spalink01e11722012-07-24 10:17:54 -0700466def VerifyRootFs(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800467 """Verify rootfs on SSD is valid by checking hash."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800468
469 return Gooftool().VerifyRootFs()
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800470
471
472@Command('verify_switch_wp')
Andy Chengc92e6f92012-11-20 16:55:53 +0800473def VerifyWPSwitch(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800474 """Verify hardware write protection switch is enabled."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800475
Andy Chengc92e6f92012-11-20 16:55:53 +0800476 Gooftool().VerifyWPSwitch()
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800477
478
479@Command('verify_switch_dev')
Tammo Spalink01e11722012-07-24 10:17:54 -0700480def VerifyDevSwitch(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800481 """Verify developer switch is disabled."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800482
Andy Chengaf30a1b2012-12-03 16:50:09 +0800483 if Gooftool().CheckDevSwitchForDisabling():
Hung-Te Lind7d34722012-07-26 16:48:35 +0800484 logging.warn('VerifyDevSwitch: No physical switch.')
485 _event_log.Log('switch_dev', type='virtual switch')
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800486
487
488@Command('write_protect')
Tammo Spalink01e11722012-07-24 10:17:54 -0700489def EnableFwWp(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800490 """Enable then verify firmware write protection."""
491
Hung-Te Linb21c6682012-08-01 13:53:57 +0800492 def CalculateLegacyRange(fw_type, length, section_data,
493 section_name):
Hung-Te Lin7ea39e82012-07-31 18:39:33 +0800494 ro_size = length / 2
495 ro_a = int(section_data[0] / ro_size)
496 ro_b = int((section_data[0] + section_data[1] - 1) / ro_size)
497 if ro_a != ro_b:
498 raise Error("%s firmware section %s has illegal size" %
Hung-Te Linb21c6682012-08-01 13:53:57 +0800499 (fw_type, section_name))
Hung-Te Lin7ea39e82012-07-31 18:39:33 +0800500 ro_offset = ro_a * ro_size
501 return (ro_offset, ro_size)
502
503 def WriteProtect(fw_file_path, fw_type, legacy_section):
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800504 """Calculate protection size, then invoke flashrom.
505
506 Our supported chips only allow write protecting half their total
507 size, so we parition the flash chipset space accordingly.
508 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800509
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800510 raw_image = open(fw_file_path, 'rb').read()
Hung-Te Lin7ea39e82012-07-31 18:39:33 +0800511 wp_section = 'WP_RO'
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800512 image = crosfw.FirmwareImage(raw_image)
Hung-Te Lin7ea39e82012-07-31 18:39:33 +0800513 if image.has_section(wp_section):
514 section_data = image.get_section_area(wp_section)
515 ro_offset = section_data[0]
516 ro_size = section_data[1]
517 elif image.has_section(legacy_section):
518 section_data = image.get_section_area(legacy_section)
519 (ro_offset, ro_size) = CalculateLegacyRange(
Hung-Te Linb21c6682012-08-01 13:53:57 +0800520 fw_type, len(raw_image), section_data, legacy_section)
Hung-Te Lin7ea39e82012-07-31 18:39:33 +0800521 else:
522 raise Error('could not find %s firmware section %s or %s' %
523 (fw_type, wp_section, legacy_section))
524
525 logging.debug('write protecting %s [off=%x size=%x]', fw_type,
526 ro_offset, ro_size)
527 crosfw.Flashrom(fw_type).EnableWriteProtection(ro_offset, ro_size)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800528
529 WriteProtect(crosfw.LoadMainFirmware().GetFileName(), 'main', 'RO_SECTION')
Tammo Spalink86a61c62012-05-25 15:10:35 +0800530 _event_log.Log('wp', fw='main')
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800531 ec_fw_file = crosfw.LoadEcFirmware().GetFileName()
532 if ec_fw_file is not None:
533 WriteProtect(ec_fw_file, 'ec', 'EC_RO')
Tammo Spalink86a61c62012-05-25 15:10:35 +0800534 _event_log.Log('wp', fw='ec')
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800535 else:
536 logging.warning('EC not write protected (seems there is no EC flash).')
537
538
539@Command('clear_gbb_flags')
Andy Chengc92e6f92012-11-20 16:55:53 +0800540def ClearGBBFlags(options): # pylint: disable=W0613
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800541 """Zero out the GBB flags, in preparation for transition to release state.
542
543 No GBB flags are set in release/shipping state, but they are useful
544 for factory/development. See "gbb_utility --flags" for details.
545 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800546
Andy Chengc92e6f92012-11-20 16:55:53 +0800547 Gooftool().ClearGBBFlags()
Tammo Spalink86a61c62012-05-25 15:10:35 +0800548 _event_log.Log('clear_gbb_flags')
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800549
550
551@Command('prepare_wipe',
552 CmdArg('--fast', action='store_true',
553 help='use non-secure but faster wipe method.'))
554def PrepareWipe(options):
555 """Prepare system for transition to release state in next reboot."""
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800556
Andy Cheng7a76cb82012-11-19 18:08:19 +0800557 Gooftool().PrepareWipe(options.fast)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800558
559@Command('verify',
Hung-Te Lin6d827542012-07-19 11:50:41 +0800560 CmdArg('--no_write_protect', action='store_true',
561 help='Do not check write protection switch state.'),
Tammo Spalink95c43732012-07-25 15:57:14 -0700562 _hwid_status_list_cmd_arg,
Jon Salzce124fb2012-10-02 17:42:03 +0800563 _hwdb_path_cmd_arg,
564 _probe_results_cmd_arg,
565 _hwid_cmd_arg)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800566def Verify(options):
567 """Verifies if whole factory process is ready for finalization.
568
569 This routine performs all the necessary checks to make sure the
570 device is ready to be finalized, but does not modify state. These
571 checks include dev switch, firmware write protection switch, hwid,
572 system time, keys, and root file system.
573 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800574
Hung-Te Lin6d827542012-07-19 11:50:41 +0800575 if not options.no_write_protect:
Andy Chengc92e6f92012-11-20 16:55:53 +0800576 VerifyWPSwitch({})
Hung-Te Lin6d827542012-07-19 11:50:41 +0800577 VerifyDevSwitch({})
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800578 VerifyHwid(options)
579 VerifySystemTime({})
580 VerifyKeys({})
581 VerifyRootFs({})
582
583
Tammo Spalink86a61c62012-05-25 15:10:35 +0800584@Command('log_system_details')
Tammo Spalink01e11722012-07-24 10:17:54 -0700585def LogSystemDetails(options): # pylint: disable=W0613
Tammo Spalink86a61c62012-05-25 15:10:35 +0800586 """Write miscellaneous system details to the event log."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800587
Andy Cheng5b0e9882012-12-10 12:43:18 +0800588 _event_log.Log('system_details', **Gooftool().GetSystemDetails())
Tammo Spalink86a61c62012-05-25 15:10:35 +0800589
590
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800591_upload_method_cmd_arg = CmdArg(
592 '--upload_method', metavar='METHOD:PARAM',
593 help=('How to perform the upload. METHOD should be one of '
cychiang3b15bd52012-09-08 13:58:18 +0800594 '{ftp, shopfloor, ftps, cpfe}.'))
Jon Salz65266432012-07-30 19:02:49 +0800595_add_file_cmd_arg = CmdArg(
596 '--add_file', metavar='FILE', action='append',
597 help='Extra file to include in report (must be an absolute path)')
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800598
599@Command('upload_report',
Jon Salz65266432012-07-30 19:02:49 +0800600 _upload_method_cmd_arg,
601 _add_file_cmd_arg)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800602def UploadReport(options):
603 """Create and a report containing key device details."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800604
Hung-Te Lin6bd16472012-06-20 16:26:47 +0800605 def NormalizeAsFileName(token):
606 return re.sub(r'\W+', '', token).strip()
Tammo Spalink86a61c62012-05-25 15:10:35 +0800607 ro_vpd = ReadRoVpd(crosfw.LoadMainFirmware().GetFileName())
608 device_sn = ro_vpd.get('serial_number', None)
609 if device_sn is None:
610 logging.warning('RO_VPD missing device serial number')
611 device_sn = 'MISSING_SN_' + TimedUuid()
Vic Yang85199e72013-01-28 14:33:11 +0800612 target_name = '%s_%s.tar.xz' % (time.strftime('%Y%m%dT%H%M%SZ',
613 time.gmtime()),
614 NormalizeAsFileName(device_sn))
Tammo Spalink86a61c62012-05-25 15:10:35 +0800615 target_path = os.path.join(gettempdir(), target_name)
616 # Intentionally ignoring dotfiles in EVENT_LOG_DIR.
Vic Yang85199e72013-01-28 14:33:11 +0800617 tar_cmd = 'cd %s ; tar cJf %s *' % (EVENT_LOG_DIR, target_path)
Tammo Spalink86a61c62012-05-25 15:10:35 +0800618 tar_cmd += ' --add-file %s' % FACTORY_LOG_PATH
Jon Salz65266432012-07-30 19:02:49 +0800619 if options.add_file:
620 for f in options.add_file:
621 # Require absolute paths since the tar command may change the
622 # directory.
623 if not f.startswith('/'):
624 raise Error('Not an absolute path: %s' % f)
625 if not os.path.exists(f):
626 raise Error('File does not exist: %s' % f)
627 tar_cmd += ' --add-file %s' % pipes.quote(f)
Tammo Spalink86a61c62012-05-25 15:10:35 +0800628 cmd_result = Shell(tar_cmd)
Jon Salzff88c022012-11-03 12:19:58 +0800629
630 if ((cmd_result.status == 1) and
631 all((x == '' or
632 'file changed as we read it' in x or
633 "Removing leading `/' from member names" in x)
634 for x in cmd_result.stderr.split('\n'))):
635 # That's OK. Make sure it's valid though.
Vic Yang85199e72013-01-28 14:33:11 +0800636 Spawn(['tar', 'tfJ', target_path], check_call=True, log=True,
Jon Salzff88c022012-11-03 12:19:58 +0800637 ignore_stdout=True)
638 elif not cmd_result.success:
Tammo Spalink86a61c62012-05-25 15:10:35 +0800639 raise Error('unable to tar event logs, cmd %r failed, stderr: %r' %
640 (tar_cmd, cmd_result.stderr))
Jon Salzff88c022012-11-03 12:19:58 +0800641
Tammo Spalink86a61c62012-05-25 15:10:35 +0800642 if options.upload_method is None or options.upload_method == 'none':
643 logging.warning('REPORT UPLOAD SKIPPED (report left at %s)', target_path)
644 return
645 method, param = options.upload_method.split(':', 1)
646 if method == 'shopfloor':
647 report_upload.ShopFloorUpload(target_path, param)
648 elif method == 'ftp':
Jay Kim360c1dd2012-06-25 10:58:11 -0700649 report_upload.FtpUpload(target_path, 'ftp:' + param)
Tammo Spalink86a61c62012-05-25 15:10:35 +0800650 elif method == 'ftps':
651 report_upload.CurlUrlUpload(target_path, '--ftp-ssl-reqd ftp:%s' % param)
652 elif method == 'cpfe':
Shawn Nematbakhsh3404a092013-01-28 16:49:09 -0800653 report_upload.CpfeUpload(target_path, pipes.quote(param))
Tammo Spalink86a61c62012-05-25 15:10:35 +0800654 else:
655 raise Error('unknown report upload method %r', method)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800656
657
658@Command('finalize',
Hung-Te Lin6d827542012-07-19 11:50:41 +0800659 CmdArg('--no_write_protect', action='store_true',
660 help='Do not enable firmware write protection.'),
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800661 CmdArg('--fast', action='store_true',
662 help='use non-secure but faster wipe method.'),
663 _hwdb_path_cmd_arg,
Tammo Spalink95c43732012-07-25 15:57:14 -0700664 _hwid_status_list_cmd_arg,
Jon Salz65266432012-07-30 19:02:49 +0800665 _upload_method_cmd_arg,
Jon Salzce124fb2012-10-02 17:42:03 +0800666 _add_file_cmd_arg,
667 _probe_results_cmd_arg,
668 _hwid_cmd_arg)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800669def Finalize(options):
670 """Verify system readiness and trigger transition into release state.
671
Hung-Te Lin6d827542012-07-19 11:50:41 +0800672 This routine first verifies system state (see verify command), modifies
673 firmware bitmaps to match locale, and then clears all of the factory-friendly
674 flags from the GBB. If everything is fine, it enables firmware write
675 protection (cannot rollback after this stage), uploads system logs & reports,
676 and sets the necessary boot flags to cause wipe of the factory image on the
677 next boot.
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800678 """
Andy Cheng7a76cb82012-11-19 18:08:19 +0800679
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800680 Verify(options)
681 SetFirmwareBitmapLocale({})
Andy Chengc92e6f92012-11-20 16:55:53 +0800682 ClearGBBFlags({})
Hung-Te Lin6d827542012-07-19 11:50:41 +0800683 if options.no_write_protect:
684 logging.warn('WARNING: Firmware Write Protection is SKIPPED.')
685 _event_log.Log('wp', fw='both', status='skipped')
686 else:
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800687 EnableFwWp({})
Jon Salza0f58e02012-05-29 19:33:39 +0800688 LogSystemDetails(options)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800689 UploadReport(options)
690 PrepareWipe(options)
691
692
693def Main():
694 """Run sub-command specified by the command line args."""
Andy Cheng7a76cb82012-11-19 18:08:19 +0800695
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800696 options = ParseCmdline(
697 'Perform Google required factory tests.',
698 CmdArg('-l', '--log', metavar='PATH',
699 help='Write logs to this file.'),
Jon Salza4bea382012-10-29 13:00:34 +0800700 CmdArg('--suppress-event-logs', action='store_true',
701 help='Suppress event logging.'),
Tammo Spalink8fab5312012-05-28 18:33:30 +0800702 verbosity_cmd_arg)
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800703 SetupLogging(options.verbosity, options.log)
Jon Salza4bea382012-10-29 13:00:34 +0800704 _event_log.suppress = options.suppress_event_logs
Tammo Spalink9a96b8a2012-04-03 11:10:41 +0800705 logging.debug('gooftool options: %s', repr(options))
706 try:
707 logging.debug('GOOFTOOL command %r', options.command_name)
708 options.command(options)
709 logging.info('GOOFTOOL command %r SUCCESS', options.command_name)
710 except Error, e:
711 logging.exception(e)
712 sys.exit('GOOFTOOL command %r ERROR: %s' % (options.command_name, e))
713 except Exception, e:
714 logging.exception(e)
715 sys.exit('UNCAUGHT RUNTIME EXCEPTION %s' % e)
716
717
718if __name__ == '__main__':
719 Main()