Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: gft_wpfw.py

Issue 6788005: factory_test_tools: support write protection for ARM (Closed) Base URL: ssh://gitrw.chromium.org:9222/factory_test_tools.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Google Factory Tool: Write Protection for Firmware 7 """Google Factory Tool: Write Protection for Firmware
8 8
9 This module enables or verifies that firmware write protection is properly 9 This module enables or verifies that firmware write protection is properly
10 activated. 10 activated.
(...skipping 14 matching lines...) Expand all
25 ARGS 25 ARGS
26 target: the flashrom_util target code, 'bios' or 'ec'. 26 target: the flashrom_util target code, 'bios' or 'ec'.
27 verbose: verbosity for flashrom_util. 27 verbose: verbosity for flashrom_util.
28 """ 28 """
29 29
30 flashrom = flashrom_util.flashrom_util(verbose_msg=VerboseMsg, 30 flashrom = flashrom_util.flashrom_util(verbose_msg=VerboseMsg,
31 exception_type=gft_common.GFTError, 31 exception_type=gft_common.GFTError,
32 system_output=gft_common.SystemOutput) 32 system_output=gft_common.SystemOutput)
33 33
34 # The EEPROM should be programmed as: 34 # The EEPROM should be programmed as:
35 # x86:
35 # (BIOS) LSB [ RW | RO ] MSB 36 # (BIOS) LSB [ RW | RO ] MSB
36 # (EC) LSB [ RO | RW ] MSB 37 # (EC) LSB [ RO | RW ] MSB
38 # arm:
39 # (BIOS) LSB [ RO | RW ] MSB
37 # Each part of RW/RO section occupies half of the EEPROM. 40 # Each part of RW/RO section occupies half of the EEPROM.
41 # To simplify the arch detection, we trust the FMAP.
42
43 layout_rw_ro = 'rw|ro'
44 layout_ro_rw = 'ro|rw'
38 45
39 eeprom_sets = ({ # BIOS 46 eeprom_sets = ({ # BIOS
40 'name': 'BIOS', 47 'name': 'BIOS',
41 'layout': 'rw|ro', 48 'layout': layout_rw_ro,
42 'target': 'bios', 49 'target': 'bios',
43 'trust_fmap': False, 50 'fmap_conversion': {'RO_SECTION': 'ro'},
44 }, { # Embedded Controller 51 }, { # Embedded Controller
45 'name': 'EC', 52 'name': 'EC',
46 'layout': 'ro|rw', 53 'layout': layout_ro_rw,
47 'target': 'ec', 54 'target': 'ec',
48 'trust_fmap': True, 55 'fmap_conversion': {'EC_RO': 'ro'},
49 'fmap_conversion': {'EC_RO': 'ro', 'EC_RW': 'rw'},
50 }) 56 })
51 57
52 # TODO(hungte) BIOS on ARM is using different layout,
53 # so we must also trust fmap for BIOS in the future.
54 matched = [eeprom for eeprom in eeprom_sets 58 matched = [eeprom for eeprom in eeprom_sets
55 if eeprom['target'] == target] 59 if eeprom['target'] == target]
56 if not matched: 60 if not matched:
57 ErrorDie('enable_write_protect: unknown target: ' + target) 61 ErrorDie('enable_write_protect: unknown target: ' + target)
58 conf = matched[0] 62 conf = matched[0]
59 name = conf['name'] 63 name = conf['name']
60 64
61 # select target 65 # select target
62 if not flashrom.select_target(target): 66 if not flashrom.select_target(target):
63 ErrorDie('wpfw: Cannot select target ' + name) 67 ErrorDie('wpfw: Cannot select target ' + name)
64 eeprom_size = flashrom.get_size() 68 eeprom_size = flashrom.get_size()
65 69
66 # build layout 70 # build layout
67 if not eeprom_size: 71 if not eeprom_size:
68 ErrorDie('wpfw: cannot get size for ' + name) 72 ErrorDie('wpfw: cannot get size for ' + name)
69 layout = None 73 layout = None
70 if conf['trust_fmap']: 74 layout_desc = conf['layout']
71 DebugMsg(' - Trying to use FMAP layout for %s' % name) 75 DebugMsg(' - Trying to use FMAP layout for %s' % name)
72 image = flashrom.read_whole() 76 image = flashrom.read_whole()
73 assert eeprom_size == len(image) 77 assert eeprom_size == len(image)
74 layout = flashrom_util.decode_fmap_layout(conf['fmap_conversion'], image) 78 fmap_layout = flashrom_util.decode_fmap_layout(conf['fmap_conversion'], image)
75 if 'ro' not in layout: 79
76 layout = None 80 if 'ro' in fmap_layout:
81 # verify if the layout is in valid size.
82 slot_size = int(eeprom_size / 2)
Che-Liang Chiou 2011/04/01 12:22:01 Are you assuming that RO and RW takes exactly half
83 ro_begin_offset = fmap_layout['ro'][0]
84 ro_end_offset = fmap_layout['ro'][1]
85 ro_begin_slot = int(ro_begin_offset / slot_size)
86 ro_end_slot = int(ro_end_offset / slot_size)
Che-Liang Chiou 2011/04/01 12:22:01 I could be wrong about this. It looks like it is a
87 error_reason = None
88 if ro_begin_slot != ro_end_slot:
89 error_reason = 'section accross valid slot range'
90 if ro_begin_offset == ro_end_offset:
91 error_reason = 'invalid section size'
92 if error_reason:
93 ErrorDie('Invalid RO section in layout: %s (%s,%s)' % error_reason)
Che-Liang Chiou 2011/04/01 12:22:01 error_reason is a one single string, but your form
94 assert ro_begin_slot == 0 or ro_begin_slot == 1
95
96 # decide ro, rw according to the offset of 'ro'.
97 if ro_begin_slot == 0:
98 layout_desc = layout_ro_rw
77 else: 99 else:
78 VerboseMsg(' - Using layout by FMAP in %s' % name) 100 layout_desc = layout_rw_ro
79 101
80 if not layout: 102 VerboseMsg(' - Using layout by FMAP in %s: %s' % (name, layout_desc))
81 # do not trust current image when detecting layout. 103 else:
82 layout = flashrom.detect_layout(conf['layout'], eeprom_size, None) 104 VerboseMsg(' - Using hard-coded layout for %s: %s' % name, layout_desc)
83 VerboseMsg(' - Using hard-coded layout for %s' % name) 105
106 layout = flashrom.detect_layout(layout_desc, eeprom_size, None)
84 if not layout: 107 if not layout:
85 ErrorDie('wpfw: cannot detect %s layout' % name) 108 ErrorDie('wpfw: cannot detect %s layout' % name)
86 109
87 # verify if the layout is half of firmware.
88 if layout['ro'][1] - layout['ro'][0] + 1 != eeprom_size / 2:
89 ErrorDie('Invalid RO section in flash rom layout.')
90
91 VerboseMsg(' - Enable Write Protection for ' + name) 110 VerboseMsg(' - Enable Write Protection for ' + name)
92 # only configure (enable) write protection if current status is not 111 # only configure (enable) write protection if current status is not
93 # correct, because sometimes the factory test is executed several 112 # correct, because sometimes the factory test is executed several
94 # times without resetting WP status. 113 # times without resetting WP status.
95 if not flashrom.verify_write_protect(layout, 'ro'): 114 if not flashrom.verify_write_protect(layout, 'ro'):
96 if not (flashrom.enable_write_protect(layout, 'ro') 115 if not (flashrom.enable_write_protect(layout, 'ro')
97 and flashrom.verify_write_protect(layout, 'ro')): 116 and flashrom.verify_write_protect(layout, 'ro')):
98 ErrorDie('wpfw: cannot enable write protection for ' + name) 117 ErrorDie('wpfw: cannot enable write protection for ' + name)
99 VerboseMsg(' - Check Write Protection for ' + name) 118 VerboseMsg(' - Check Write Protection for ' + name)
100 flashrom.disable_write_protect() 119 flashrom.disable_write_protect()
(...skipping 16 matching lines...) Expand all
117 print 'Usage: %s target_code(bios/ec)\n' % sys.argv[0] 136 print 'Usage: %s target_code(bios/ec)\n' % sys.argv[0]
118 sys.exit(1) 137 sys.exit(1)
119 138
120 gft_common.SetDebugLevel(True) 139 gft_common.SetDebugLevel(True)
121 gft_common.SetVerboseLevel(True) 140 gft_common.SetVerboseLevel(True)
122 EnableWriteProtect(sys.argv[1]) 141 EnableWriteProtect(sys.argv[1])
123 142
124 143
125 if __name__ == '__main__': 144 if __name__ == '__main__':
126 _main() 145 _main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698