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

Side by Side Diff: kernel_handler.py

Issue 3781016: Introduce SAFT TPM testing support. (Closed) Base URL: http://git.chromium.org/git/saft.git
Patch Set: Addressed review comments. 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 | runtests.sh » ('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/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 containing kernel handler class used by SAFT.''' 6 '''A module containing kernel handler class used by SAFT.'''
7 7
8 import re 8 import re
9 9
10 TMP_FILE_NAME = 'kernel_header_dump' 10 TMP_FILE_NAME = 'kernel_header_dump'
11 MAIN_STORAGE_DEVICE = '/dev/sda' 11 MAIN_STORAGE_DEVICE = '/dev/sda'
12 12
13 # Types of kernel modifications. 13 # Types of kernel modifications.
14 KERNEL_BODY_MOD = 1 14 KERNEL_BODY_MOD = 1
15 KERNEL_VERSION_MOD = 2 15 KERNEL_VERSION_MOD = 2
16 16
17
18 class KernelHandlerError(Exception):
19 pass
20
21
17 class KernelHandler(object): 22 class KernelHandler(object):
18 '''An object to provide ChromeOS kernel related actions. 23 '''An object to provide ChromeOS kernel related actions.
19 24
20 Mostly it allows to corrupt and restore a particular kernel partition 25 Mostly it allows to corrupt and restore a particular kernel partition
21 (designated by the partition name, A or B. 26 (designated by the partition name, A or B.
22 ''' 27 '''
23 28
24 # This value is used to alter contents of a byte in the appropriate kernel 29 # This value is used to alter contents of a byte in the appropriate kernel
25 # image. First added to corrupt the image, then subtracted to restore the 30 # image. First added to corrupt the image, then subtracted to restore the
26 # image. 31 # image.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 def restore_kernel(self, section): 104 def restore_kernel(self, section):
100 '''Restore the previously corrupted kernel.''' 105 '''Restore the previously corrupted kernel.'''
101 self._modify_kernel(section.upper(), -self.DELTA) 106 self._modify_kernel(section.upper(), -self.DELTA)
102 107
103 def get_version(self, section): 108 def get_version(self, section):
104 '''Return version read from this section blob's header.''' 109 '''Return version read from this section blob's header.'''
105 return self.partition_map[section.upper()]['version'] 110 return self.partition_map[section.upper()]['version']
106 111
107 def set_version(self, section, version): 112 def set_version(self, section, version):
108 '''Set version of this kernel blob and re-sign it.''' 113 '''Set version of this kernel blob and re-sign it.'''
114 if version < 0:
115 raise KernelHandlerError('Bad version value %d' % version)
109 self._modify_kernel(section.upper(), version, KERNEL_VERSION_MOD) 116 self._modify_kernel(section.upper(), version, KERNEL_VERSION_MOD)
110 117
111 def init (self, chros_if): 118 def init (self, chros_if):
112 '''Initialize the kernel handler object. 119 '''Initialize the kernel handler object.
113 120
114 Input argument is a ChromeOS interface object reference. 121 Input argument is a ChromeOS interface object reference.
115 ''' 122 '''
116 self.chros_if = chros_if 123 self.chros_if = chros_if
117 self.dump_file_name = chros_if.state_dir_file(TMP_FILE_NAME) 124 self.dump_file_name = chros_if.state_dir_file(TMP_FILE_NAME)
118 self._get_partition_map() 125 self._get_partition_map()
OLDNEW
« no previous file with comments | « no previous file | runtests.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698