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, os | 5 import glob, os |
6 | 6 |
7 from autotest_lib.client.bin import factory | |
8 from autotest_lib.client.bin import test, utils | 7 from autotest_lib.client.bin import test, utils |
9 from autotest_lib.client.common_lib import error | 8 from autotest_lib.client.common_lib import error |
10 from autotest_lib.client.common_lib import flashrom_util | 9 from autotest_lib.client.common_lib import gbb_util |
11 | 10 |
12 | 11 |
13 class factory_WriteGBB(test.test): | 12 class factory_WriteGBB(test.test): |
14 version = 1 | 13 version = 2 |
15 | 14 |
16 def run_once(self, gbb_file='', shared_dict={}): | 15 def run_once(self, shared_dict={}): |
17 os.chdir(self.bindir) | 16 # More convenient to set the CWD to hardware_Components since a lot of |
17 # values in the component list are based on that directory. | |
18 os.chdir(os.path.join(self.bindir, '../hardware_Components')) | |
18 | 19 |
19 # If found the HwQual ID in shared_dict, use the GBB with the same ID. | 20 # If found the HwQual ID in shared_dict, identify the component files. |
20 if 'part_id_hwqual' in shared_dict: | 21 if 'part_id_hwqual' in shared_dict: |
21 id = shared_dict['part_id_hwqual'] | 22 id = shared_dict['part_id_hwqual'].replace(' ', '_') |
22 id = id.rpartition(' ')[0].replace(' ', '_') | 23 component_file = 'data_*/components_%s' % id |
23 gbb_file = 'gbb*%s' % id | |
24 | 24 |
25 gbb_files = glob.glob(gbb_file) | 25 component_files = glob.glob(component_file) |
26 if len(gbb_files) > 1: | 26 if len(component_files) != 1: |
27 raise error.TestError('More than one GBB file found') | 27 raise error.TestError( |
28 elif len(gbb_files) == 1: | 28 'Unable to find the component file: %s' % component_file) |
29 gbb_file = gbb_files[0] | 29 component_file = component_files[0] |
30 else: | 30 components = eval(utils.read_file(component_file)) |
31 raise error.TestError('Unable to find GBB file: %s' % gbb_file) | |
32 gbb_data = utils.read_file(gbb_file) | |
33 | 31 |
34 flashrom = flashrom_util.FlashromUtility() | 32 gbb = gbb_util.GBBUtility(temp_dir=self.resultsdir, |
35 flashrom.initialize(flashrom.TARGET_BIOS) | 33 keep_temp_files=True) |
Hung-Te
2010/09/13 08:09:05
any reason to force keeping temp files here?
Tom Wai-Hong Tam
2010/09/13 18:47:43
Since updating GBB is risky. So want to keep the t
| |
36 | 34 gbb.set_bmpfv(utils.read_file(components['data_bitmap_fv'][0])) |
37 gbb_section = 'FV_GBB' | 35 gbb.set_hwid(components['part_id_hwqual'][0]) |
38 original_data = flashrom.read_section(gbb_section) | 36 gbb.set_recoverykey(utils.read_file(components['key_recovery'][0])) |
39 # If no difference, no need to update. | 37 gbb.set_rootkey(utils.read_file(components['key_root'][0])) |
40 if gbb_data == original_data: | 38 gbb.commit() |
41 return | |
42 | |
43 original_file = os.path.join(self.resultsdir, 'original_gbb.bin') | |
44 utils.open_write_close(original_file, original_data) | |
45 | |
46 flashrom.write_section(gbb_section, gbb_data) | |
47 flashrom.commit() | |
OLD | NEW |