OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''A module to support automated testing of ChromeOS firmware. | 6 '''A module to support automated testing of ChromeOS firmware. |
7 | 7 |
8 Utilizes services provided by saft_flashrom_util.py read/write the | 8 Utilizes services provided by saft_flashrom_util.py read/write the |
9 flashrom chip and to parse the flash rom image. | 9 flashrom chip and to parse the flash rom image. |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 subsection_name = self.corrupt_section(section) | 221 subsection_name = self.corrupt_section(section) |
222 self.fum.write_partial(self.image, (subsection_name, )) | 222 self.fum.write_partial(self.image, (subsection_name, )) |
223 | 223 |
224 def restore_firmware(self, section): | 224 def restore_firmware(self, section): |
225 '''Restore the previously corrupted section in the FLASHROM!!!''' | 225 '''Restore the previously corrupted section in the FLASHROM!!!''' |
226 | 226 |
227 subsection_name = self.restore_section(section) | 227 subsection_name = self.restore_section(section) |
228 self.fum.write_partial(self.image, (subsection_name, )) | 228 self.fum.write_partial(self.image, (subsection_name, )) |
229 | 229 |
| 230 def firmware_sections_equal(self): |
| 231 '''Check if firmware sections A and B are equal. |
| 232 |
| 233 This function presumes that the entire BIOS image integrity has been |
| 234 verified, so different signature sections mean different images and |
| 235 vice versa. |
| 236 ''' |
| 237 sig_a = self.fum.get_section(self.image, |
| 238 self.fv_sections['a'].get_sig_name()) |
| 239 sig_b = self.fum.get_section(self.image, |
| 240 self.fv_sections['b'].get_sig_name()) |
| 241 return sig_a == sig_b |
| 242 |
| 243 def copy_from_to(self, src, dst): |
| 244 '''Copy one firmware image section to another. |
| 245 |
| 246 This function copies both signature and body of one firmware section |
| 247 into another. After this function runs both sections are identical. |
| 248 ''' |
| 249 src_sect = self.fv_sections[src] |
| 250 dst_sect = self.fv_sections[dst] |
| 251 self.image = self.fum.put_section( |
| 252 self.image, |
| 253 dst_sect.get_body_name(), |
| 254 self.fum.get_section(self.image, src_sect.get_body_name())) |
| 255 self.image = self.fum.put_section( |
| 256 self.image, |
| 257 dst_sect.get_sig_name(), |
| 258 self.fum.get_section(self.image, src_sect.get_sig_name())) |
| 259 |
230 def write_whole(self): | 260 def write_whole(self): |
231 '''Write the whole image into the flashrom.''' | 261 '''Write the whole image into the flashrom.''' |
232 | 262 |
233 if not self.image: | 263 if not self.image: |
234 raise FlashromHandlerError( | 264 raise FlashromHandlerError( |
235 'Attempt at using an uninitialized object') | 265 'Attempt at using an uninitialized object') |
236 self.fum.write_whole(self.image) | 266 self.fum.write_whole(self.image) |
237 | 267 |
238 def dump_whole(self, filename): | 268 def dump_whole(self, filename): |
239 '''Write the whole image into a file.''' | 269 '''Write the whole image into a file.''' |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 pad = ('%c' % 0xff) * (sig_size - os.path.getsize(sig_name)) | 307 pad = ('%c' % 0xff) * (sig_size - os.path.getsize(sig_name)) |
278 new_sig.write(pad) | 308 new_sig.write(pad) |
279 new_sig.close() | 309 new_sig.close() |
280 | 310 |
281 # Inject the new signature block into the image | 311 # Inject the new signature block into the image |
282 new_sig = open(sig_name, 'r').read() | 312 new_sig = open(sig_name, 'r').read() |
283 self.image = self.fum.put_section( | 313 self.image = self.fum.put_section( |
284 self.image, fv_section.get_sig_name(), new_sig) | 314 self.image, fv_section.get_sig_name(), new_sig) |
285 if write_through: | 315 if write_through: |
286 self.fum.write_partial(self.image, (fv_section.get_sig_name(), )) | 316 self.fum.write_partial(self.image, (fv_section.get_sig_name(), )) |
OLD | NEW |