OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import glob, hashlib, logging, os, pprint, re, sys | 5 import glob, hashlib, logging, os, pprint, re, sys |
6 from autotest_lib.client.bin import factory | 6 from autotest_lib.client.bin import factory |
7 from autotest_lib.client.bin import test, utils | 7 from autotest_lib.client.bin import test, utils |
8 from autotest_lib.client.common_lib import error | 8 from autotest_lib.client.common_lib import error |
9 from autotest_lib.client.common_lib import flashrom_util | 9 from autotest_lib.client.common_lib import flashrom_util |
| 10 from autotest_lib.client.common_lib import gbb_util |
10 from autotest_lib.client.common_lib import site_vblock | 11 from autotest_lib.client.common_lib import site_vblock |
11 | 12 |
12 | 13 |
13 class hardware_Components(test.test): | 14 class hardware_Components(test.test): |
14 version = 1 | 15 version = 1 |
15 _cids = [ | 16 _cids = [ |
16 'hash_ro_firmware', | 17 'hash_ro_firmware', |
17 'part_id_audio_codec', | 18 'part_id_audio_codec', |
18 'part_id_cpu', | 19 'part_id_cpu', |
19 'part_id_display_panel', | 20 'part_id_display_panel', |
(...skipping 12 matching lines...) Expand all Loading... |
32 'part_id_vga', | 33 'part_id_vga', |
33 ] | 34 ] |
34 _usb_cids = [ | 35 _usb_cids = [ |
35 'part_id_bluetooth', | 36 'part_id_bluetooth', |
36 'part_id_cardreader', | 37 'part_id_cardreader', |
37 'part_id_webcam', | 38 'part_id_webcam', |
38 'part_id_3g', | 39 'part_id_3g', |
39 'part_id_gps', | 40 'part_id_gps', |
40 ] | 41 ] |
41 _check_existence_cids = [ | 42 _check_existence_cids = [ |
| 43 'key_recovery', |
| 44 'key_root', |
42 'part_id_chrontel', | 45 'part_id_chrontel', |
43 ] | 46 ] |
| 47 _non_check_cids = [ |
| 48 'data_bitmap_fv', |
| 49 'data_display_geometry', |
| 50 'data_recovery_url', |
| 51 ] |
44 _not_present = 'Not Present' | 52 _not_present = 'Not Present' |
45 | 53 |
46 | 54 |
47 def check_component(self, comp_key, comp_id): | 55 def check_component(self, comp_key, comp_id): |
48 if comp_key in self._ignored: | 56 if comp_key in self._ignored: |
49 return | 57 return |
50 | 58 |
51 self._system[comp_key] = [ comp_id ] | 59 self._system[comp_key] = [ comp_id ] |
52 | 60 |
53 if not self._approved.has_key(comp_key): | 61 if not self._approved.has_key(comp_key): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 elif type == 'others': | 100 elif type == 'others': |
93 present = getattr(self, 'check_existence_' + cid)(device) | 101 present = getattr(self, 'check_existence_' + cid)(device) |
94 | 102 |
95 if present: | 103 if present: |
96 self._system[cid] = [ device ] | 104 self._system[cid] = [ device ] |
97 return | 105 return |
98 | 106 |
99 self._failures[cid] = [ 'No match' ] | 107 self._failures[cid] = [ 'No match' ] |
100 | 108 |
101 | 109 |
| 110 def check_existence_key_recovery(self, part_id): |
| 111 current_key = self._gbb.get_recoverykey() |
| 112 target_key = utils.read_file(part_id) |
| 113 return current_key == target_key |
| 114 |
| 115 |
| 116 def check_existence_key_root(self, part_id): |
| 117 current_key = self._gbb.get_rootkey() |
| 118 target_key = utils.read_file(part_id) |
| 119 return current_key == target_key |
| 120 |
| 121 |
102 def check_existence_part_id_chrontel(self, part_id): | 122 def check_existence_part_id_chrontel(self, part_id): |
103 if part_id == self._not_present: | 123 if part_id == self._not_present: |
104 return True | 124 return True |
105 | 125 |
106 if part_id == 'ch7036': | 126 if part_id == 'ch7036': |
107 grep_cmd = 'grep i2c_dev /proc/modules' | 127 grep_cmd = 'grep i2c_dev /proc/modules' |
108 i2c_loaded = (utils.system(grep_cmd, ignore_status=True) == 0) | 128 i2c_loaded = (utils.system(grep_cmd, ignore_status=True) == 0) |
109 if not i2c_loaded: | 129 if not i2c_loaded: |
110 utils.system('modprobe i2c_dev') | 130 utils.system('modprobe i2c_dev') |
111 | 131 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 hash_ro_list = ['FV_BSTUB', 'FV_GBB', 'FVDEV'] | 249 hash_ro_list = ['FV_BSTUB', 'FV_GBB', 'FVDEV'] |
230 flashrom = flashrom_util.flashrom_util() | 250 flashrom = flashrom_util.flashrom_util() |
231 if not flashrom.select_bios_flashrom(): | 251 if not flashrom.select_bios_flashrom(): |
232 raise error.TestError('Cannot select BIOS flashrom') | 252 raise error.TestError('Cannot select BIOS flashrom') |
233 base_img = flashrom.read_whole() | 253 base_img = flashrom.read_whole() |
234 flashrom_size = len(base_img) | 254 flashrom_size = len(base_img) |
235 # XXX we can NOT trust base image here for layout, otherwise firmware | 255 # XXX we can NOT trust base image here for layout, otherwise firmware |
236 # can provide fake (non-used) GBB/BSTUB in garbage area. | 256 # can provide fake (non-used) GBB/BSTUB in garbage area. |
237 layout = flashrom.detect_chromeos_bios_layout(flashrom_size, None) | 257 layout = flashrom.detect_chromeos_bios_layout(flashrom_size, None) |
238 if not layout: | 258 if not layout: |
239 raise error.TestError('Cannot detect ChromeOS flashrom laout') | 259 raise error.TestError('Cannot detect ChromeOS flashrom layout') |
240 hash_src = '' | 260 hash_src = '' |
241 for section in hash_ro_list: | 261 for section in hash_ro_list: |
242 src = flashrom.get_section(base_img, layout, section) | 262 src = flashrom.get_section(base_img, layout, section) |
243 if not src: | 263 if not src: |
244 raise error.TestError('Cannot get section [%s] from flashrom' % | 264 raise error.TestError('Cannot get section [%s] from flashrom' % |
245 section) | 265 section) |
246 hash_src = hash_src + src | 266 hash_src = hash_src + src |
247 if not hash_src: | 267 if not hash_src: |
248 raise error.TestError('Invalid hash source from flashrom.') | 268 raise error.TestError('Invalid hash source from flashrom.') |
249 return hashlib.sha256(hash_src).hexdigest() | 269 return hashlib.sha256(hash_src).hexdigest() |
250 | 270 |
251 | 271 |
252 def get_version_rw_firmware(self): | 272 def get_version_rw_firmware(self): |
253 """ | 273 """ |
254 Returns the version of Read-Write (writable) firmware from VBOOT | 274 Returns the version of Read-Write (writable) firmware from VBOOT |
255 section. If A/B has different version, that means this system | 275 section. If A/B has different version, that means this system |
256 needs a reboot + firmwar update so return value is a "error report" | 276 needs a reboot + firmwar update so return value is a "error report" |
257 in the form "A=x, B=y". | 277 in the form "A=x, B=y". |
258 """ | 278 """ |
259 versions = [None, None] | 279 versions = [None, None] |
260 section_names = ['VBOOTA', 'VBOOTB'] | 280 section_names = ['VBOOTA', 'VBOOTB'] |
261 flashrom = flashrom_util.flashrom_util() | 281 flashrom = flashrom_util.flashrom_util() |
262 if not flashrom.select_bios_flashrom(): | 282 if not flashrom.select_bios_flashrom(): |
263 raise error.TestError('Cannot select BIOS flashrom') | 283 raise error.TestError('Cannot select BIOS flashrom') |
264 base_img = flashrom.read_whole() | 284 base_img = flashrom.read_whole() |
265 flashrom_size = len(base_img) | 285 flashrom_size = len(base_img) |
266 # we can trust base image for layout, since it's only RW. | 286 # we can trust base image for layout, since it's only RW. |
267 layout = flashrom.detect_chromeos_bios_layout(flashrom_size, base_imge) | 287 layout = flashrom.detect_chromeos_bios_layout(flashrom_size, base_img) |
268 if not layout: | 288 if not layout: |
269 raise error.TestError('Cannot detect ChromeOS flashrom laout') | 289 raise error.TestError('Cannot detect ChromeOS flashrom layout') |
270 for index, name in enumerate(section_names): | 290 for index, name in enumerate(section_names): |
271 data = flashrom.get_section(base_img, layout, name) | 291 data = flashrom.get_section(base_img, layout, name) |
272 block = site_vblock.unpack_verification_block(data) | 292 block = site_vblock.unpack_verification_block(data) |
273 ver = block['VbFirmwarePreambleHeader']['firmware_version'] | 293 ver = block['VbFirmwarePreambleHeader']['firmware_version'] |
274 versions[index] = ver | 294 versions[index] = ver |
275 # we embed error reports in return value. | 295 # we embed error reports in return value. |
276 assert len(versions) == 2 | 296 assert len(versions) == 2 |
277 if versions[0] != versions[1]: | 297 if versions[0] != versions[1]: |
278 return 'A=%d, B=%d' % (versions[0], versions[1]) | 298 return 'A=%d, B=%d' % (versions[0], versions[1]) |
279 return '%d' % (versions[0]) | 299 return '%d' % (versions[0]) |
(...skipping 11 matching lines...) Expand all Loading... |
291 logging.error("Exception getting property %s", property_name, | 311 logging.error("Exception getting property %s", property_name, |
292 exc_info=1) | 312 exc_info=1) |
293 return '' | 313 return '' |
294 | 314 |
295 | 315 |
296 def pformat(self, obj): | 316 def pformat(self, obj): |
297 return "\n" + self._pp.pformat(obj) + "\n" | 317 return "\n" + self._pp.pformat(obj) + "\n" |
298 | 318 |
299 | 319 |
300 def initialize(self): | 320 def initialize(self): |
| 321 self._gbb = gbb_util.GBBUtility() |
301 self._pp = pprint.PrettyPrinter() | 322 self._pp = pprint.PrettyPrinter() |
302 | 323 |
303 | 324 |
304 def run_once(self, approved_dbs='approved_components', ignored_cids=[], | 325 def run_once(self, approved_dbs='approved_components', ignored_cids=[], |
305 shared_dict={}): | 326 shared_dict={}): |
306 self._ignored = ignored_cids | 327 self._ignored = ignored_cids |
307 all_failures = '' | 328 all_failures = '' |
308 os.chdir(self.bindir) | 329 os.chdir(self.bindir) |
309 | 330 |
310 # If found the HwQual ID in shared_dict, use the list with the same ID. | 331 # If found the HwQual ID in shared_dict, use the list with the same ID. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 all_failures += 'Approved DB: %s' % db | 366 all_failures += 'Approved DB: %s' % db |
346 all_failures += self.pformat(self._failures) | 367 all_failures += self.pformat(self._failures) |
347 else: | 368 else: |
348 # If one of DBs is matched, record some data in shared_dict. | 369 # If one of DBs is matched, record some data in shared_dict. |
349 cids_need_to_be_record = ['part_id_hwqual'] | 370 cids_need_to_be_record = ['part_id_hwqual'] |
350 for cid in cids_need_to_be_record: | 371 for cid in cids_need_to_be_record: |
351 factory.log_shared_data(cid, self._approved[cid][0]) | 372 factory.log_shared_data(cid, self._approved[cid][0]) |
352 return | 373 return |
353 | 374 |
354 raise error.TestFail(all_failures) | 375 raise error.TestFail(all_failures) |
OLD | NEW |