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

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

Issue 3493016: Add EC hash in hardware_Components database (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git
Patch Set: change field ordering by alphabet Created 10 years, 2 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/site_tests/hardware_Components/approved_components » ('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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 from_image = self.get_latest_changed_image() 779 from_image = self.get_latest_changed_image()
780 return self.flashrom.get_section(from_image, self.layout, section) 780 return self.flashrom.get_section(from_image, self.layout, section)
781 781
782 def write_section(self, section, data): 782 def write_section(self, section, data):
783 """ Change the section data of latest changed image. """ 783 """ Change the section data of latest changed image. """
784 new_image = self.get_latest_changed_image() 784 new_image = self.get_latest_changed_image()
785 new_image = self.flashrom.put_section(new_image, self.layout, section, \ 785 new_image = self.flashrom.put_section(new_image, self.layout, section, \
786 data) 786 data)
787 return self.image_copy(section, section, new_image) 787 return self.image_copy(section, section, new_image)
788 788
789 def verify_sections(self, from_list, to_list, from_image, to_image): 789 def get_verification_image(self, from_image, pad_value=chr(0)):
790 """ 790 """
791 Compares if sections in from_list and to_list are the same, skipping 791 Returns an image derived from from_image with "skip verification"
792 by self.skip_verify description. 792 regions padded by pad_value.
793
794 If from_list and to_list are both empty list ([]), compare whole image
795 """ 793 """
796 # simplify arguments and local variables
797 from_list = csv_to_list(from_list)
798 to_list = csv_to_list(to_list)
799 flashrom = self.flashrom
800 layout = self.layout 794 layout = self.layout
801 795
802 # decode skip_verify with layout, and then modify images 796 # decode skip_verify with layout, and then modify images
803 for verify_tuple in csv_to_list(self.skip_verify): 797 for verify_tuple in csv_to_list(self.skip_verify):
804 (name, offset, size) = verify_tuple.split(':') 798 (name, offset, size) = verify_tuple.split(':')
805 name = name.strip() 799 name = name.strip()
806 offset = int(offset.strip(), 0) 800 offset = int(offset.strip(), 0)
807 size = int(size.strip(), 0) 801 size = int(size.strip(), 0)
808 assert name in layout, "(verify_sec) Unknown section name: " + name 802 assert name in layout, "(make_verify) Unknown section name: " + name
809 if self.is_debug: 803 if self.is_debug:
810 print " ** skipping range: %s +%d [%d]" % (name, offset, size) 804 print " ** skipping range: %s +%d [%d]" % (name, offset, size)
811 # XXX we use the layout's internal structure here... 805 # XXX we use the layout's internal structure here...
812 offset = layout[name][0] + offset 806 offset = layout[name][0] + offset
813 from_image = from_image[:offset] + (chr(0)*size) + \ 807 from_image = from_image[:offset] + (pad_value * size) + \
814 from_image[(offset + size):] 808 from_image[(offset + size):]
815 to_image = to_image[:offset] + (chr(0) * size) + \ 809 return from_image
816 to_image[(offset + size):] 810
811 def verify_sections(self, from_list, to_list, from_image, to_image):
812 """
813 Compares if sections in from_list and to_list are the same, skipping
814 by self.skip_verify description.
815
816 If from_list and to_list are both empty list ([]), compare whole image
817 """
818 # simplify arguments and local variables
819 from_list = csv_to_list(from_list)
820 to_list = csv_to_list(to_list)
821 flashrom = self.flashrom
822
823 # prepare verification image
824 if self.skip_verify:
825 from_image = self.get_verification_image(from_image)
826 to_image = self.get_verification_image(to_image)
817 827
818 # compare sections in image 828 # compare sections in image
819 if not (from_list or to_list): 829 if not (from_list or to_list):
820 return from_image == to_image 830 return from_image == to_image
821 for (f, t) in zip(from_list, to_list): 831 for (f, t) in zip(from_list, to_list):
822 data_f = flashrom.get_section(from_image, layout, f) 832 data_f = flashrom.get_section(from_image, layout, f)
823 data_t = flashrom.get_section(to_image, layout, t) 833 data_t = flashrom.get_section(to_image, layout, t)
824 if data_f != data_t: 834 if data_f != data_t:
825 return False 835 return False
826 return True 836 return True
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 except ImportError: 927 except ImportError:
918 # print 'using mocks' 928 # print 'using mocks'
919 utils = mock_utils() 929 utils = mock_utils()
920 TestError = mock_TestError 930 TestError = mock_TestError
921 931
922 932
923 # main stub 933 # main stub
924 if __name__ == "__main__": 934 if __name__ == "__main__":
925 # TODO(hungte) provide unit tests or command line usage 935 # TODO(hungte) provide unit tests or command line usage
926 pass 936 pass
OLDNEW
« no previous file with comments | « no previous file | client/site_tests/hardware_Components/approved_components » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698