forked from chipsec/chipsec
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nathaniel Mitchell <[email protected]>
- Loading branch information
Showing
33 changed files
with
2,125 additions
and
10,384 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from collections import namedtuple | ||
from enum import Enum | ||
|
||
from chipsec.parsers import BaseConfigParser, BaseConfigHelper | ||
from chipsec.parsers import Stage | ||
|
||
|
||
range_entry = namedtuple('RangeEntry', ['name', 'group', 'access', 'start', 'end']) | ||
|
||
|
||
class Access(Enum): | ||
UNKNOWN = 0 | ||
NONE = 1 | ||
RO = 2 | ||
RW = 3 | ||
|
||
|
||
def _convert_range_data(xml_node): | ||
INT_KEYS = ['start', 'end'] | ||
ACCESS_KEYS = ['access'] | ||
ACCESS_CONVERT = {'unknown': Access.UNKNOWN, 'none': Access.NONE, 'ro': Access.RO, 'rw': Access.RW} | ||
node_data = {} | ||
for key in xml_node.attrib: | ||
if key in INT_KEYS: | ||
node_data[key] = int(xml_node.attrib[key], 0) | ||
elif key in ACCESS_KEYS: | ||
if xml_node.attrib[key].lower() in ACCESS_CONVERT: | ||
node_data[key] = ACCESS_CONVERT[xml_node.attrib[key].lower()] | ||
else: | ||
node_data[key] = Access.UNKNOWN | ||
else: | ||
node_data[key] = xml_node.attrib[key] | ||
return range_entry(node_data['name'], node_data['group'], node_data['access'], | ||
node_data['start'], node_data['end']) | ||
|
||
|
||
class CustomRangeParser(BaseConfigParser): | ||
def startup(self): | ||
if not hasattr(self.cfg, 'ACCESS_RANGES'): | ||
setattr(self.cfg, 'ACCESS_RANGES', {}) | ||
|
||
def get_metadata(self): | ||
return {'access_ranges': self.access_handler} | ||
|
||
def get_stage(self): | ||
return Stage.CUST_SUPPORT | ||
|
||
def parser_name(self): | ||
return 'ACCESS_RANGES' | ||
|
||
def access_handler(self, et_node, stage_data): | ||
if stage_data.vid_str not in self.cfg.ACCESS_RANGES: | ||
self.cfg.ACCESS_RANGES[stage_data.vid_str] = {} | ||
if stage_data.dev_name not in self.cfg.ACCESS_RANGES[stage_data.vid_str]: | ||
self.cfg.ACCESS_RANGES[stage_data.vid_str][stage_data.dev_name] = [] | ||
for range_node in et_node.iter('range'): | ||
node_data = _convert_range_data(range_node) | ||
self.logger.log_debug(f" + {node_data.name:16}: {node_data}") | ||
self.cfg.ACCESS_RANGES[stage_data.vid_str][stage_data.dev_name].append(node_data) | ||
|
||
|
||
class CustomRanges(BaseConfigHelper): | ||
def has_custom_ranges(self, vid_str, dev_name, group=None): | ||
if vid_str not in self.cfg.ACCESS_RANGES: | ||
return False | ||
if dev_name not in self.cfg.ACCESS_RANGES[vid_str]: | ||
return False | ||
if not group: | ||
return True | ||
for item in self.cfg.ACCESS_RANGES[vid_str][dev_name]: | ||
if item.group == group: | ||
return True | ||
return False | ||
|
||
def get_custom_ranges(self, vid_str, dev_name, group=None): | ||
ret_val = [] | ||
if vid_str not in self.cfg.ACCESS_RANGES or dev_name not in self.cfg.ACCESS_RANGES[vid_str]: | ||
return ret_val | ||
for item in self.cfg.ACCESS_RANGES[vid_str][dev_name]: | ||
if group and item.group != group: | ||
continue | ||
ret_val.append(item) | ||
return ret_val | ||
|
||
|
||
parsers = [CustomRangeParser] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from chipsec.parsers import BaseConfigParser, BaseConfigHelper | ||
from chipsec.parsers import Stage | ||
|
||
class GPIOParser(BaseConfigParser): | ||
def startup(self): | ||
if not hasattr(self.cfg, 'GPIO'): | ||
setattr(self.cfg, 'GPIO', {}) | ||
|
||
def parser_name(self): | ||
return 'GPIO' | ||
|
||
def get_metadata(self): | ||
return {'configuration': self.platform_handler, 'community': self.community_handler} | ||
|
||
def get_stage(self): | ||
return Stage.EXTRA | ||
|
||
def platform_handler(self, et_node, stage_data): | ||
self.pch_code = et_node.get('pch_code') | ||
self.cfg.GPIO[self.pch_code] = {} | ||
|
||
def community_handler(self, et_node, stage_data): | ||
community = {} | ||
port = et_node.get('port_id') | ||
for subtree in et_node.iter('group'): | ||
group = self._convert_group_data(subtree) | ||
community.update(group) | ||
self.cfg.GPIO[self.pch_code].update({port: community}) | ||
|
||
def _convert_group_data(self, et_node): | ||
group = {} | ||
group_name = et_node.get('name') | ||
if group_name in ['pad_ownership', 'config_lock', 'hostsoftware_ownership']: | ||
entries = ['name', 'offset', 'pad_cnt'] | ||
elif group_name == 'pad_config': | ||
entries = ['name', 'offset'] | ||
else: | ||
raise UnboundLocalError | ||
for subtree in et_node.iter('register'): | ||
register = self._convert_register(subtree, entries) | ||
group.update(register) | ||
return {group_name: group} | ||
|
||
def _convert_register(self, xml_node, entries): | ||
if set(entries) == set(xml_node.attrib): | ||
name = xml_node.attrib.pop('name') | ||
return {name: xml_node.attrib} | ||
|
||
|
||
class GPIOCommands(BaseConfigHelper): | ||
def __init__(self, cfg_obj): | ||
super().__init__(cfg_obj) | ||
self.regs = self.cfg.GPIO | ||
self.start_addrs = {} | ||
|
||
|
||
|
||
|
||
parsers = {GPIOParser} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from chipsec.parsers import BaseConfigHelper | ||
|
||
class GenericConfig(BaseConfigHelper): | ||
def __init__(self, cfg_obj): | ||
super(GenericConfig, self).__init__(cfg_obj) | ||
self.name = cfg_obj['name'] | ||
if 'config' in cfg_obj: | ||
self.config = cfg_obj['config'] | ||
else: | ||
self.config = [] | ||
|
||
def add_config(self, config): | ||
for cfg in config: | ||
if cfg not in self.config: | ||
self.config.append(cfg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from chipsec.cfg.parsers.ip.generic import GenericConfig | ||
|
||
|
||
class IOConfig(GenericConfig): | ||
def __init__(self, cfg_obj): | ||
super(IOConfig, self).__init__(cfg_obj) | ||
self.port = cfg_obj['port'] | ||
|
||
def __str__(self) -> str: | ||
ret = f'name: {self.name}, port: {self.port}' | ||
ret += f', config: {self.config}' | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from chipsec.cfg.parsers.ip.generic import GenericConfig | ||
|
||
|
||
class IOObj: | ||
def __init__(self, instance): | ||
self.base = None | ||
self.size = 0 | ||
self.instance = instance | ||
|
||
def __str__(self) -> str: | ||
return f'instance: {self.instance}, base: {self.base}' | ||
|
||
|
||
class IOBarConfig(GenericConfig): | ||
def __init__(self, cfg_obj): | ||
super(IOBarConfig, self).__init__(cfg_obj) | ||
self.device = cfg_obj['device'] | ||
self.register = cfg_obj['register'] | ||
self.base_field = cfg_obj['base_field'] | ||
self.fixed_address = cfg_obj['fixed_address'] if 'fixed_address' in cfg_obj else None | ||
self.mask = cfg_obj['mask'] if 'mask' in cfg_obj else None | ||
self.offset = cfg_obj['offset'] if 'offset' in cfg_obj else None | ||
self.size = cfg_obj['size'] if 'did' in cfg_obj else None | ||
self.enable_field = cfg_obj['enable_field'] if 'enable_field' in cfg_obj else None | ||
self.desc = cfg_obj['desc'] | ||
self.instances = {} | ||
for key in cfg_obj['ids']: | ||
self.add_obj(key) | ||
|
||
def add_obj(self, key): | ||
self.instances[key] = IOObj(key) | ||
|
||
def update_base_address(self, base, instance): | ||
if instance in self.instances: | ||
self.instances[instance].base = base | ||
|
||
def get_base(self, instance): | ||
if instance in self.instances: | ||
return self.instances[instance].base, self.instances[instance].size | ||
else: | ||
return (None, 0) | ||
|
||
def __str__(self) -> str: | ||
ret = f'name: {self.name}, device: {self.device}' | ||
ret += f', register:{self.register}, base_field:{self.base_field}' | ||
ret += f', size:{self.size}' | ||
if self.enable_field: | ||
ret += f', enable_field:{self.enable_field}' | ||
ret += f', config: {self.config}' | ||
if self.fixed_address: | ||
ret += f', fixed_address:{self.fixed_address}' | ||
ret += f', desc:{self.desc}' | ||
ret += ', instances: [' | ||
ret += ' '.join(f'{{{str(inst)}}}' for (_, inst) in self.instances.items()) | ||
ret += ']' | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from chipsec.cfg.parsers.ip.generic import GenericConfig | ||
|
||
|
||
class MemoryConfig(GenericConfig): | ||
def __init__(self, cfg_obj): | ||
super(MemoryConfig, self).__init__(cfg_obj) | ||
self.access = cfg_obj['access'] | ||
self.address = cfg_obj['address'] | ||
self.size = cfg_obj['limit'] | ||
|
||
def __str__(self) -> str: | ||
ret = f'name: {self.name}, access: {self.access}' | ||
ret += f', address: {self.address}, limit: {self.size}' | ||
ret += f', config: {self.config}' | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from chipsec.cfg.parsers.ip.generic import GenericConfig | ||
|
||
|
||
class MM_MSGBUSConfig(GenericConfig): | ||
def __init__(self, cfg_obj): | ||
super(MM_MSGBUSConfig, self).__init__(cfg_obj) | ||
self.port = cfg_obj['port'] | ||
|
||
def __str__(self) -> str: | ||
ret = f'name: {self.name}, port: {self.port}' | ||
ret += f', config: {self.config}' | ||
return ret |
Oops, something went wrong.