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

Side by Side Diff: utility/pack_firmware_image

Issue 6677040: Allow overlap between "pure" fmap areas (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 9 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 python2.6 1 #!/usr/bin/env python2.6
2 2
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2011 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 import os 7 import os
8 import re 8 import re
9 import struct 9 import struct
10 import subprocess 10 import subprocess
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 firmware_image.seek(self.offset) 113 firmware_image.seek(self.offset)
114 firmware_image.write(blob) 114 firmware_image.write(blob)
115 115
116 116
117 class EntryFmapArea(Entry): 117 class EntryFmapArea(Entry):
118 118
119 def __init__(self, **kwargs): 119 def __init__(self, **kwargs):
120 Entry._CheckFields(kwargs, ('flags',)) 120 Entry._CheckFields(kwargs, ('flags',))
121 super(EntryFmapArea, self).__init__(**kwargs) 121 super(EntryFmapArea, self).__init__(**kwargs)
122 122
123 def Pack(self, firmware_image, entries):
124 pass
125
123 126
124 class EntryBlob(EntryFmapArea): 127 class EntryBlob(EntryFmapArea):
125 128
126 def __init__(self, **kwargs): 129 def __init__(self, **kwargs):
127 Entry._CheckFields(kwargs, ('path',)) 130 Entry._CheckFields(kwargs, ('path',))
128 super(EntryBlob, self).__init__(**kwargs) 131 super(EntryBlob, self).__init__(**kwargs)
129 132
130 def Pack(self, firmware_image, entries): 133 def Pack(self, firmware_image, entries):
131 size = os.stat(self.path).st_size 134 size = os.stat(self.path).st_size
132 if size > self.length: 135 if size > self.length:
133 raise PackError('blob too large: %d > %d' % (size, self.length)) 136 raise PackError('blob too large: %s: %d > %d' %
137 (self.path, size, self.length))
134 if size == 0: # special case for files like /dev/zero 138 if size == 0: # special case for files like /dev/zero
135 size = self.length 139 size = self.length
136 with open(self.path, 'rb') as blob_image: 140 with open(self.path, 'rb') as blob_image:
137 firmware_image.seek(self.offset) 141 firmware_image.seek(self.offset)
138 firmware_image.write(blob_image.read(size)) 142 firmware_image.write(blob_image.read(size))
139 143
140 144
141 class EntryKeyBlock(EntryFmapArea): 145 class EntryKeyBlock(EntryFmapArea):
142 146
143 stdout = None 147 stdout = None
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return expr[1:-1] # if it is quoted, always interpreted as string literals 211 return expr[1:-1] # if it is quoted, always interpreted as string literals
208 try: 212 try:
209 return int(expr, 0) 213 return int(expr, 0)
210 except ValueError: 214 except ValueError:
211 return expr # if not a number, interpret as string literals 215 return expr # if not a number, interpret as string literals
212 216
213 217
214 def pack_firmware_image(entries, output_path, image_size): 218 def pack_firmware_image(entries, output_path, image_size):
215 entries = sorted(entries, key=lambda e: e.offset) 219 entries = sorted(entries, key=lambda e: e.offset)
216 for e1, e2 in zip(entries, entries[1:]): 220 for e1, e2 in zip(entries, entries[1:]):
217 if e1.IsOverlapped(e2): 221 # Allow overlap between "pure" fmap areas, but not any of its subclasses
222 # Here we exploit the fact that Entry is a new-style class
223 if (e1.IsOverlapped(e2) and
224 type(e1) is not EntryFmapArea and type(e2) is not EntryFmapArea):
218 raise PackError('overlapped entries: [%08x:%08x], [%08x:%08x]' % 225 raise PackError('overlapped entries: [%08x:%08x], [%08x:%08x]' %
219 (e1.offset, e1.offset + e1.length, e2.offset, e2.offset + e2.length)) 226 (e1.offset, e1.offset + e1.length, e2.offset, e2.offset + e2.length))
220 227
221 with open(output_path, 'wb') as firmware_image: 228 with open(output_path, 'wb') as firmware_image:
222 # resize firmware image file 229 # resize firmware image file
223 firmware_image.seek(0) 230 firmware_image.seek(0)
224 firmware_image.write('\0' * image_size) 231 firmware_image.write('\0' * image_size)
225 232
226 for entry in entries: 233 for entry in entries:
227 entry.Pack(firmware_image, entries) 234 entry.Pack(firmware_image, entries)
(...skipping 29 matching lines...) Expand all
257 raise ConfigError('undefined variable: %s' % varname) 264 raise ConfigError('undefined variable: %s' % varname)
258 _Info('%s = %s' % (varname, repr(env[varname]))) 265 _Info('%s = %s' % (varname, repr(env[varname])))
259 266
260 pack_firmware_image(env['ENTRIES'], env['OUTPUT'], env['SIZE']) 267 pack_firmware_image(env['ENTRIES'], env['OUTPUT'], env['SIZE'])
261 268
262 sys.exit(0) 269 sys.exit(0)
263 270
264 271
265 if __name__ == '__main__': 272 if __name__ == '__main__':
266 main() 273 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