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

Side by Side Diff: client/common_lib/flashrom_util.py

Issue 3343003: Add components which is requried to generate a GBB during factory. (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: fix bugs Created 10 years, 3 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 | client/common_lib/gbb_util.py » ('j') | 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 # 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 """ 6 """
7 This module provides convenience routines to access Flash ROM (EEPROM). 7 This module provides convenience routines to access Flash ROM (EEPROM).
8 - flashrom_util is a low level wrapper of flashrom(8) program. 8 - flashrom_util is a low level wrapper of flashrom(8) program.
9 - FlashromUtility is a high level object which provides more advanced 9 - FlashromUtility is a high level object which provides more advanced
10 features like journaling-alike (log-based) changing. 10 features like journaling-alike (log-based) changing.
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 def detect_chromeos_bios_layout(self, size, image): 481 def detect_chromeos_bios_layout(self, size, image):
482 """ Detects standard ChromeOS BIOS layout. 482 """ Detects standard ChromeOS BIOS layout.
483 A short cut to detect_chromeos_layout(TARGET_BIOS, size, image). """ 483 A short cut to detect_chromeos_layout(TARGET_BIOS, size, image). """
484 return self.detect_chromeos_layout(self.TARGET_BIOS, size, image) 484 return self.detect_chromeos_layout(self.TARGET_BIOS, size, image)
485 485
486 def detect_chromeos_ec_layout(self, size, image): 486 def detect_chromeos_ec_layout(self, size, image):
487 """ Detects standard ChromeOS Embedded Controller layout. 487 """ Detects standard ChromeOS Embedded Controller layout.
488 A short cut to detect_chromeos_layout(TARGET_EC, size, image). """ 488 A short cut to detect_chromeos_layout(TARGET_EC, size, image). """
489 return self.detect_chromeos_layout(self.TARGET_EC, size, image) 489 return self.detect_chromeos_layout(self.TARGET_EC, size, image)
490 490
491 def read_whole_to_file(self, output_file):
492 '''
493 Reads whole flash ROM data to a file.
494 Returns True on success, otherwise False.
495 '''
496 cmd = '%s"%s" -r "%s"' % (self.cmd_prefix, self.tool_path,
497 output_file)
498 if self.verbose:
499 print 'flashrom_util.read_whole_to_file(): ', cmd
500 return utils.system(cmd, ignore_status=True) == 0
501
491 def read_whole(self): 502 def read_whole(self):
492 ''' 503 '''
493 Reads whole flash ROM data. 504 Reads whole flash ROM data.
494 Returns the data read from flash ROM, or empty string for other error. 505 Returns the data read from flash ROM, or empty string for other error.
495 ''' 506 '''
507 result = ''
496 tmpfn = self._get_temp_filename('rd_') 508 tmpfn = self._get_temp_filename('rd_')
497 cmd = '%s"%s" -r "%s"' % (self.cmd_prefix, self.tool_path, tmpfn) 509 if self.read_whole_to_file(tmpfn):
498 if self.verbose:
499 print 'flashrom_util.read_whole(): ', cmd
500 result = ''
501
502 if utils.system(cmd, ignore_status=True) == 0: # failure for non-zero
503 try: 510 try:
504 result = open(tmpfn, 'rb').read() 511 result = open(tmpfn, 'rb').read()
505 except IOError: 512 except IOError:
506 result = '' 513 result = ''
507 514
508 # clean temporary resources 515 # clean temporary resources
509 self._remove_temp_file(tmpfn) 516 self._remove_temp_file(tmpfn)
510 return result 517 return result
511 518
512 def _write_flashrom(self, base_image, layout_map, write_list): 519 def _write_flashrom(self, base_image, layout_map, write_list):
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 def get_arch(self): 895 def get_arch(self):
889 arch = os.popen('uname -m').read().rstrip() 896 arch = os.popen('uname -m').read().rstrip()
890 arch = re.sub(r"i\d86", r"i386", arch, 1) 897 arch = re.sub(r"i\d86", r"i386", arch, 1)
891 return arch 898 return arch
892 899
893 def run_command(self, cmd, ignore_status=False): 900 def run_command(self, cmd, ignore_status=False):
894 p = subprocess.Popen(cmd, shell=True, 901 p = subprocess.Popen(cmd, shell=True,
895 stdout=subprocess.PIPE, 902 stdout=subprocess.PIPE,
896 stderr=subprocess.PIPE) 903 stderr=subprocess.PIPE)
897 p.wait() 904 p.wait()
898 if p.returncode and not ignore_status: 905 if p.returncode:
899 raise TestError("failed to execute: %s\nError messages: %s" % ( 906 err_msg = p.stderr.read()
900 cmd, p.stderr.read())) 907 print p.stdout.read()
908 print err_msg
909 if not ignore_status:
910 raise TestError("failed to execute: %s\nError messages: %s" % (
911 cmd, err_msg))
901 return (p.returncode, p.stdout.read()) 912 return (p.returncode, p.stdout.read())
902 913
903 def system(self, cmd, ignore_status=False): 914 def system(self, cmd, ignore_status=False):
904 (returncode, output) = self.run_command(cmd, ignore_status) 915 (returncode, output) = self.run_command(cmd, ignore_status)
905 return returncode 916 return returncode
906 917
907 def system_output(self, cmd, ignore_status=False): 918 def system_output(self, cmd, ignore_status=False):
908 (returncode, output) = self.run_command(cmd, ignore_status) 919 (returncode, output) = self.run_command(cmd, ignore_status)
909 return output 920 return output
910 921
911 922
912 # import autotest or mock utilities 923 # import autotest or mock utilities
913 try: 924 try:
914 # print 'using autotest' 925 # print 'using autotest'
915 from autotest_lib.client.bin import test, utils 926 from autotest_lib.client.bin import test, utils
916 from autotest_lib.client.common_lib.error import TestError 927 from autotest_lib.client.common_lib.error import TestError
917 except ImportError: 928 except ImportError:
918 # print 'using mocks' 929 # print 'using mocks'
919 utils = mock_utils() 930 utils = mock_utils()
920 TestError = mock_TestError 931 TestError = mock_TestError
921 932
922 933
923 # main stub 934 # main stub
924 if __name__ == "__main__": 935 if __name__ == "__main__":
925 # TODO(hungte) provide unit tests or command line usage 936 # TODO(hungte) provide unit tests or command line usage
926 pass 937 pass
OLDNEW
« no previous file with comments | « no previous file | client/common_lib/gbb_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698