Exemplo n.º 1
0
class Chipset:
    def __init__(self, helper=None):
        if logger().VERBOSE: logger().log("[Chipset] __init__")
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid = 0
        self.did = 0
        self.code = CHIPSET_CODE_UNKNOWN
        self.longname = "Unrecognized Platform"
        self.id = CHIPSET_ID_UNKNOWN
        self.Cfg = Cfg()

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci = Pci(self)
        self.mem = Memory(self)
        self.msr = Msr(self)
        self.ucode = Ucode(self)
        self.io = PortIO(self)
        self.cr = CrRegs(self)
        self.cpuid = CpuID(self)
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Examples:
        # - initializing SPI HAL component in a module:
        #   self.spi = SPI( self.cs )
        # - initializing second order UEFI HAL component in utilcmd extension:
        #   spi = SPI( chipsec_util._cs )
        #

    def init(self, platform_code, start_svc):

        _unknown_platform = False
        if start_svc: self.helper.start()

        if platform_code is None:
            vid_did = self.pci.read_dword(0, 0, 0, 0)
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid:
                _unknown_platform = True
        else:
            self.vid = VID_INTEL
            self.code = platform_code.lower()
            if Chipset_Code.has_key(platform_code):
                self.did = Chipset_Code[platform_code]
            else:
                _unknown_platform = True
                self.did = 0xFFFF

        if Chipset_Dictionary.has_key(self.did):
            data_dict = Chipset_Dictionary[self.did]
            self.code = data_dict['code'].lower()
            self.longname = data_dict['longname']
            self.id = data_dict['id']
        else:
            _unknown_platform = True
            self.longname = 'UnknownPlatform'

        self.init_cfg()
        if _unknown_platform:
            msg = 'Unsupported Platform: VID = 0x%04X, DID = 0x%04X' % (
                self.vid, self.did)
            logger().error(msg)
            raise UnknownChipsetError, msg

    def destroy(self, start_svc):
        self.stop(start_svc)
        #self.helper.destroy()

    def stop(self, start_svc):
        if start_svc: self.helper.stop()

    def get_chipset_id(self):
        return self.id

    def get_chipset_code(self):
        return self.code

    def get_chipset_name(self, id):
        return self.longname

    def print_chipset(self):
        logger().log(
            "[*] Platform: %s\n          VID: %04X\n          DID: %04X" %
            (self.longname, self.vid, self.did))

    ##################################################################################
    #
    # Loading platform configuration from XML files in chipsec/cfg/
    #
    ##################################################################################

    def init_xml_configuration(self):
        _cfg_path = os.path.join(chipsec.file.get_main_dir(), 'chipsec/cfg')
        # Load chipsec/cfg/common.xml configuration XML file common for all platforms if it exists
        self.init_cfg_xml(os.path.join(_cfg_path, 'common.xml'), self.code)
        # Load chipsec/cfg/<code>.xml configuration XML file if it exists for platform <code>
        if self.code and '' != self.code:
            self.init_cfg_xml(os.path.join(_cfg_path, ('%s.xml' % self.code)),
                              self.code)
        # Load configuration from all other XML files recursively (if any)
        for dirname, subdirs, xml_fnames in os.walk(_cfg_path):
            for _xml in xml_fnames:
                if fnmatch.fnmatch(_xml, '*.xml') and not fnmatch.fnmatch(
                        _xml, 'common.xml') and not (_xml in [
                            '%s.xml' % c.lower() for c in Chipset_Code
                        ]):
                    self.init_cfg_xml(os.path.join(dirname, _xml), self.code)
        self.Cfg.XML_CONFIG_LOADED = True

    def init_cfg_xml(self, fxml, code):
        import xml.etree.ElementTree as ET
        if not os.path.exists(fxml): return
        if logger().VERBOSE:
            logger().log("[*] looking for platform config in '%s'.." % fxml)
        tree = ET.parse(fxml)
        root = tree.getroot()
        for _cfg in root.iter('configuration'):
            if 'platform' not in _cfg.attrib:
                if logger().HAL:
                    logger().log(
                        "[*] loading common platform config from '%s'.." %
                        fxml)
            elif code == _cfg.attrib['platform'].lower():
                if logger().HAL:
                    logger().log(
                        "[*] loading '%s' platform config from '%s'.." %
                        (code, fxml))
            else:
                continue

            if logger().VERBOSE:
                logger().log("[*] loading integrated devices/controllers..")
            for _pci in _cfg.iter('pci'):
                for _device in _pci.iter('device'):
                    _name = _device.attrib['name']
                    del _device.attrib['name']
                    self.Cfg.CONFIG_PCI[_name] = _device.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" %
                                     (_name, _device.attrib))
            if logger().VERBOSE: logger().log("[*] loading MMIO BARs..")
            for _mmio in _cfg.iter('mmio'):
                for _bar in _mmio.iter('bar'):
                    _name = _bar.attrib['name']
                    del _bar.attrib['name']
                    self.Cfg.MMIO_BARS[_name] = _bar.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _bar.attrib))
            if logger().VERBOSE: logger().log("[*] loading I/O BARs..")
            for _io in _cfg.iter('io'):
                for _bar in _io.iter('bar'):
                    _name = _bar.attrib['name']
                    del _bar.attrib['name']
                    self.Cfg.IO_BARS[_name] = _bar.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _bar.attrib))
            if logger().VERBOSE: logger().log("[*] loading memory ranges..")
            for _memory in _cfg.iter('memory'):
                for _range in _memory.iter('range'):
                    _name = _range.attrib['name']
                    del _range.attrib['name']
                    self.Cfg.MEMORY_RANGES[_name] = _range.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" %
                                     (_name, _range.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading configuration registers..")
            for _registers in _cfg.iter('registers'):
                for _register in _registers.iter('register'):
                    _name = _register.attrib['name']
                    del _register.attrib['name']
                    if 'size' not in _register.attrib:
                        _register.attrib['size'] = "0x4"
                    if 'desc' not in _register.attrib:
                        _register.attrib['desc'] = ''
                    reg_fields = {}
                    if _register.find('field') is not None:
                        for _field in _register.iter('field'):
                            _field_name = _field.attrib['name']
                            del _field.attrib['name']
                            if 'desc' not in _field.attrib:
                                _field.attrib['desc'] = ''
                            reg_fields[_field_name] = _field.attrib
                        _register.attrib['FIELDS'] = reg_fields
                    self.Cfg.REGISTERS[_name] = _register.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" %
                                     (_name, _register.attrib))
            if logger().VERBOSE: logger().log("[*] loading controls..")
            for _controls in _cfg.iter('controls'):
                for _control in _controls.iter('control'):
                    _name = _control.attrib['name']
                    del _control.attrib['name']
                    self.Cfg.CONTROLS[_name] = _control.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" %
                                     (_name, _control.attrib))

    #
    # Load chipsec/cfg/<code>.py configuration file for platform <code>
    #
    def init_cfg(self):
        if self.code and '' != self.code:
            try:
                module_path = 'chipsec.cfg.' + self.code
                module = importlib.import_module(module_path)
                logger().log_good(
                    "imported platform specific configuration: chipsec.cfg.%s"
                    % self.code)
                self.Cfg = getattr(module, self.code)()
            except ImportError, msg:
                if logger().VERBOSE:
                    logger().log("[*] Couldn't import chipsec.cfg.%s\n%s" %
                                 (self.code, str(msg)))

        #
        # Initialize platform configuration from XML files
        #
        try:
            self.init_xml_configuration()
        except:
            if logger().VERBOSE: logger().log_bad(traceback.format_exc())
            pass
Exemplo n.º 2
0
class Chipset:

    def __init__(self, helper=None):
        if logger().VERBOSE: logger().log("[Chipset] __init__")
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid        = 0
        self.did        = 0
        self.code       = CHIPSET_CODE_UNKNOWN
        self.longname   = "Unrecognized Platform"
        self.id         = CHIPSET_ID_UNKNOWN
        self.Cfg        = Cfg()

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci        = Pci      ( self )
        self.mem        = Memory   ( self )
        self.msr        = Msr      ( self )
        self.ucode      = Ucode    ( self )
        self.io         = PortIO   ( self )
        self.cr         = CrRegs   ( self )
        self.cpuid      = CpuID    ( self )
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Examples:
        # - initializing SPI HAL component in a module:
        #   self.spi = SPI( self.cs )
        # - initializing second order UEFI HAL component in utilcmd extension:
        #   spi = SPI( chipsec_util._cs )
        #

    def init( self, platform_code, start_svc ):

        if start_svc: self.helper.start()

        if not platform_code:
            vid_did  = self.pci.read_dword( 0, 0, 0, 0 )
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid: raise UnknownChipsetError, ('UnsupportedPlatform: Vendor ID = 0x%04X' % self.vid)
        else:
            if Chipset_Code.has_key( platform_code ): self.code = platform_code.lower()
            else: raise UnknownChipsetError, ('UnsupportedPlatform: code: %s' % platform_code)
            self.vid      = VID_INTEL
            self.did      = Chipset_Code[ platform_code ]

        if Chipset_Dictionary.has_key( self.did ):
            data_dict       = Chipset_Dictionary[ self.did ]
            self.code       = data_dict['code'].lower()
            self.longname   = data_dict['longname']
            self.id         = data_dict['id']
        else:
            raise UnknownChipsetError, ('UnsupportedPlatform: Device ID = 0x%04X' % self.did)
        self.init_cfg()

    def destroy( self, start_svc ):
        self.stop( start_svc )
        #self.helper.destroy()

    def stop( self, start_svc ):
        if start_svc: self.helper.stop()

    def get_chipset_id(self):
        return self.id

    def get_chipset_code(self):
        return self.code

    def get_chipset_name(self, id ):
        return self.longname

    def print_chipset(self):
        logger().log( "Platform: %s\n          VID: %04X\n          DID: %04X" % (self.longname, self.vid, self.did))


    ##################################################################################
    #
    # Loading platform configuration from XML files in chipsec/cfg/
    #
    ##################################################################################

    def init_xml_configuration( self ):
        _cfg_path = os.path.join( chipsec.file.get_main_dir(), 'chipsec/cfg' )
        # Load chipsec/cfg/common.xml configuration XML file common for all platforms if it exists
        self.init_cfg_xml( os.path.join(_cfg_path,'common.xml'), self.code )
        # Load chipsec/cfg/<code>.xml configuration XML file if it exists for platform <code>
        if self.code and '' != self.code:
            self.init_cfg_xml( os.path.join(_cfg_path,('%s.xml'%self.code)), self.code )
        # Load configuration from all other XML files recursively (if any)
        for dirname, subdirs, xml_fnames in os.walk( _cfg_path ):
            for _xml in xml_fnames:
                if fnmatch.fnmatch( _xml, '*.xml' ) and not fnmatch.fnmatch( _xml, 'common.xml' ) and not (_xml in ['%s.xml' % c.lower() for c in Chipset_Code]):
                    self.init_cfg_xml( os.path.join(dirname,_xml), self.code )
        self.Cfg.XML_CONFIG_LOADED = True


    def init_cfg_xml(self, fxml, code):
        import xml.etree.ElementTree as ET
        if not os.path.exists( fxml ): return
        if logger().VERBOSE: logger().log( "[*] looking for platform config in '%s'.." % fxml )
        tree = ET.parse( fxml )
        root = tree.getroot()
        for _cfg in root.iter('configuration'):
            if 'platform' not in _cfg.attrib:
                logger().log( "[*] loading common platform config from '%s'.." % fxml )
            elif code == _cfg.attrib['platform'].lower():
                logger().log( "[*] loading '%s' platform config from '%s'.." % (code,fxml) )
            else: continue

            if logger().VERBOSE: logger().log( "[*] loading integrated devices/controllers.." )
            for _pci in _cfg.iter('pci'):
                for _device in _pci.iter('device'):
                    _name = _device.attrib['name']
                    del _device.attrib['name']
                    self.Cfg.CONFIG_PCI[ _name ] = _device.attrib
                    if logger().VERBOSE: logger().log( "    + %-16s: %s" % (_name, _device.attrib) )
            if logger().VERBOSE: logger().log( "[*] loading MMIO BARs.." )
            for _mmio in _cfg.iter('mmio'):
                for _bar in _mmio.iter('bar'):
                    _name = _bar.attrib['name']
                    del _bar.attrib['name']
                    self.Cfg.MMIO_BARS[ _name ] = _bar.attrib
                    if logger().VERBOSE: logger().log( "    + %-16s: %s" % (_name, _bar.attrib) )
            if logger().VERBOSE: logger().log( "[*] loading I/O BARs.." )
            for _io in _cfg.iter('io'):
                for _bar in _io.iter('bar'):
                    _name = _bar.attrib['name']
                    del _bar.attrib['name']
                    self.Cfg.IO_BARS[ _name ] = _bar.attrib
                    if logger().VERBOSE: logger().log( "    + %-16s: %s" % (_name, _bar.attrib) )
            if logger().VERBOSE: logger().log( "[*] loading memory ranges.." )
            for _memory in _cfg.iter('memory'):
                for _range in _memory.iter('range'):
                    _name = _range.attrib['name']
                    del _range.attrib['name']
                    self.Cfg.MEMORY_RANGES[ _name ] = _range.attrib
                    if logger().VERBOSE: logger().log( "    + %-16s: %s" % (_name, _range.attrib) )
            if logger().VERBOSE: logger().log( "[*] loading configuration registers.." )
            for _registers in _cfg.iter('registers'):
                for _register in _registers.iter('register'):
                    _name = _register.attrib['name']
                    del _register.attrib['name']
                    if 'size' not in _register.attrib: _register.attrib['size'] = "0x4"
                    if 'desc' not in _register.attrib: _register.attrib['desc'] = ''
                    reg_fields = {}
                    if _register.find('field') is not None:
                        for _field in _register.iter('field'):
                            _field_name = _field.attrib['name']
                            del _field.attrib['name']
                            if 'desc' not in _field.attrib: _field.attrib['desc'] = ''
                            reg_fields[ _field_name ] = _field.attrib
                        _register.attrib['FIELDS'] = reg_fields
                    self.Cfg.REGISTERS[ _name ] = _register.attrib
                    if logger().VERBOSE: logger().log( "    + %-16s: %s" % (_name, _register.attrib) )

    #
    # Load chipsec/cfg/<code>.py configuration file for platform <code>
    #
    def init_cfg(self):
        if self.code and '' != self.code:
            try:
                module_path = 'chipsec.cfg.' + self.code
                module = importlib.import_module( module_path )
                logger().log_good( "imported platform specific configuration: chipsec.cfg.%s" % self.code )
                self.Cfg = getattr( module, self.code )()
            except ImportError, msg:
                if logger().VERBOSE: logger().log( "[*] Couldn't import chipsec.cfg.%s\n%s" % ( self.code, str(msg) ) )

        #
        # Initialize platform configuration from XML files
        #
        try:
            self.init_xml_configuration()
        except:
            if logger().VERBOSE: logger().log_bad(traceback.format_exc())
            pass
Exemplo n.º 3
0
class Chipset:
    def __init__(self, helper=None):
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid = 0
        self.did = 0
        self.code = CHIPSET_CODE_UNKNOWN
        self.longname = "Unrecognized Platform"
        self.id = CHIPSET_ID_UNKNOWN
        self.Cfg = Cfg()

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci = Pci(self.helper)
        self.mem = Memory(self.helper)
        self.msr = Msr(self.helper)
        self.ucode = Ucode(self.helper)
        self.io = PortIO(self.helper)
        self.cpuid = CpuID(self.helper)
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Example of initializing second order HAL component (UEFI in uefi_cmd.py):
        # cs = cs()
        # self.uefi = UEFI( cs )
        #

    def init(self, platform_code, start_svc):

        if start_svc: self.helper.start()

        if not platform_code:
            vid_did = self.pci.read_dword(0, 0, 0, 0)
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid:
                raise UnknownChipsetError, (
                    'UnsupportedPlatform: Vendor ID = 0x%04X' % self.vid)
        else:
            if Chipset_Code.has_key(platform_code):
                self.code = platform_code.lower()
            else:
                raise UnknownChipsetError, ('UnsupportedPlatform: code: %s' %
                                            platform_code)
            self.vid = VID_INTEL
            self.did = Chipset_Code[platform_code]

        if Chipset_Dictionary.has_key(self.did):
            data_dict = Chipset_Dictionary[self.did]
            self.code = data_dict['code'].lower()
            self.longname = data_dict['longname']
            self.id = data_dict['id']
        else:
            raise UnknownChipsetError, (
                'UnsupportedPlatform: Device ID = 0x%04X' % self.did)
        self.init_cfg()

    def init_cfg(self):
        if self.code and '' != self.code:
            try:
                exec 'from chipsec.cfg.' + self.code + ' import *'
                logger().log_good(
                    "imported platform specific configuration: chipsec.cfg.%s"
                    % self.code)
                exec 'self.Cfg = ' + self.code + '()'
            except ImportError, msg:
                if logger().VERBOSE:
                    logger().log("[*] Couldn't import chipsec.cfg.%s\n%s" %
                                 (self.code, str(msg)))
Exemplo n.º 4
0
class Chipset:
    def __init__(self, helper=None):
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid = 0
        self.did = 0
        self.code = CHIPSET_CODE_UNKNOWN
        self.longname = "Unrecognized Platform"
        self.id = CHIPSET_ID_UNKNOWN
        self.Cfg = Cfg()

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci = Pci(self.helper)
        self.mem = Memory(self.helper)
        self.msr = Msr(self.helper)
        self.ucode = Ucode(self.helper)
        self.io = PortIO(self.helper)
        self.cpuid = CpuID(self.helper)
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Example of initializing second order HAL component (UEFI in uefi_cmd.py):
        # cs = cs()
        # self.uefi = UEFI( cs )
        #

    def init(self, platform_code, start_svc):

        if start_svc:
            self.helper.start()

        if not platform_code:
            vid_did = self.pci.read_dword(0, 0, 0, 0)
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid:
                raise UnknownChipsetError, ("UnsupportedPlatform: Vendor ID = 0x%04X" % self.vid)
        else:
            if Chipset_Code.has_key(platform_code):
                self.code = platform_code.lower()
            else:
                raise UnknownChipsetError, ("UnsupportedPlatform: code: %s" % platform_code)
            self.vid = VID_INTEL
            self.did = Chipset_Code[platform_code]

        if Chipset_Dictionary.has_key(self.did):
            data_dict = Chipset_Dictionary[self.did]
            self.code = data_dict["code"].lower()
            self.longname = data_dict["longname"]
            self.id = data_dict["id"]
        else:
            raise UnknownChipsetError, ("UnsupportedPlatform: Device ID = 0x%04X" % self.did)
        self.init_cfg()

    def init_cfg(self):
        if self.code and "" != self.code:
            try:
                exec "from chipsec.cfg." + self.code + " import *"
                logger().log_good("imported platform specific configuration: chipsec.cfg.%s" % self.code)
                exec "self.Cfg = " + self.code + "()"
            except ImportError, msg:
                if logger().VERBOSE:
                    logger().log("[*] Couldn't import chipsec.cfg.%s\n%s" % (self.code, str(msg)))
Exemplo n.º 5
0
class Chipset:

    def __init__(self, helper=None):
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid        = 0
        self.did        = 0
        self.code       = ""
        self.longname   = "Unrecognized Platform"
        self.id         = CHIPSET_ID_UNKNOWN

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci    	= Pci      ( self.helper )
        self.mem    	= Memory   ( self.helper )
        self.msr    	= Msr      ( self.helper )
        self.ucode  	= Ucode    ( self.helper )
        self.io     	= PortIO   ( self.helper )
        self.cpuid      = CpuID    ( self.helper )
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Example of initializing second order HAL component (UEFI in uefi_cmd.py):
        # cs = cs()
        # self.uefi = UEFI( cs )
        #

    def init( self, platform_code, start_svc ):

        if start_svc: self.helper.start()

        if not platform_code:
            vid_did  = self.pci.read_dword( 0, 0, 0, 0 )
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid: raise UnknownChipsetError, ('UnsupportedPlatform: Vendor ID = 0x%04X' % self.vid)
        else:
            if Chipset_Code.has_key( platform_code ): self.code = platform_code.lower()
            else: raise UnknownChipsetError, ('UnsupportedPlatform: code: %s' % platform_code)
            self.vid      = VID_INTEL
            self.did      = Chipset_Code[ platform_code ]

        if Chipset_Dictionary.has_key( self.did ):
            data_dict       = Chipset_Dictionary[ self.did ]
            self.code       = data_dict['code'].lower()
            self.longname   = data_dict['longname']
            self.id         = data_dict['id']
        else:
            raise UnknownChipsetError, ('UnsupportedPlatform: Device ID = 0x%04X' % self.did)



    def destroy( self, start_svc ):
        self.stop( start_svc )
        #self.helper.destroy()

    def stop( self, start_svc ):
        if start_svc:
            self.helper.stop()

    def get_chipset_id(self):
        return self.id

    def get_chipset_code(self):
        return self.code

    def get_chipset_name(self, id ):
        return self.longname


    def print_chipset(self):
        logger().log( "Platform: %s\n          VID: %04X\n          DID: %04X" % (self.longname, self.vid, self.did))
Exemplo n.º 6
0
class Chipset:
    def __init__(self, helper=None):
        if logger().VERBOSE:
            logger().log("[Chipset] __init__")
        if helper is None:
            self.helper = OsHelper()
        else:
            self.helper = helper

        self.vid = 0
        self.did = 0
        self.code = CHIPSET_CODE_UNKNOWN
        self.longname = "Unrecognized Platform"
        self.id = CHIPSET_ID_UNKNOWN
        self.Cfg = Cfg()

        #
        # Initializing 'basic primitive' HAL components
        # (HAL components directly using native OS helper functionality)
        #
        self.pci = Pci(self)
        self.mem = Memory(self)
        self.msr = Msr(self)
        self.ucode = Ucode(self)
        self.io = PortIO(self)
        self.cpu = chipsec.hal.cpu.CPU(self)
        # self.cr         = CrRegs   ( self )
        self.cpuid = CpuID(self)
        #
        # All HAL components which use above 'basic primitive' HAL components
        # should be instantiated in modules/utilcmd with an instance of chipset
        # Examples:
        # - initializing SPI HAL component in a module:
        #   self.spi = SPI( self.cs )
        # - initializing second order UEFI HAL component in utilcmd extension:
        #   spi = SPI( chipsec_util._cs )
        #

    def init(self, platform_code, start_svc):

        _unknown_platform = False
        if start_svc:
            self.helper.start()

        if platform_code is None:
            vid_did = self.pci.read_dword(0, 0, 0, 0)
            self.vid = vid_did & 0xFFFF
            self.did = (vid_did >> 16) & 0xFFFF
            if VID_INTEL != self.vid:
                _unknown_platform = True
        else:
            self.vid = VID_INTEL
            self.code = platform_code.lower()
            if Chipset_Code.has_key(platform_code):
                self.did = Chipset_Code[platform_code]
            else:
                _unknown_platform = True
                self.did = 0xFFFF

        if Chipset_Dictionary.has_key(self.did):
            data_dict = Chipset_Dictionary[self.did]
            self.code = data_dict["code"].lower()
            self.longname = data_dict["longname"]
            self.id = data_dict["id"]
        else:
            _unknown_platform = True
            self.longname = "UnknownPlatform"

        self.init_cfg()
        if _unknown_platform:
            msg = "Unsupported Platform: VID = 0x%04X, DID = 0x%04X" % (self.vid, self.did)
            logger().error(msg)
            raise UnknownChipsetError, msg

    def destroy(self, start_svc):
        self.stop(start_svc)
        # self.helper.destroy()

    def stop(self, start_svc):
        if start_svc:
            self.helper.stop()

    def get_chipset_id(self):
        return self.id

    def get_chipset_code(self):
        return self.code

    def get_chipset_name(self, id):
        return self.longname

    def print_chipset(self):
        logger().log("[*] Platform: %s\n          VID: %04X\n          DID: %04X" % (self.longname, self.vid, self.did))

    def is_core(self):
        return self.get_chipset_id() in CHIPSET_FAMILY_CORE

    def is_server(self):
        return self.get_chipset_id() in CHIPSET_FAMILY_XEON

    def is_atom(self):
        return self.get_chipset_id() in CHIPSET_FAMILY_ATOM

    ##################################################################################
    #
    # Loading platform configuration from XML files in chipsec/cfg/
    #
    ##################################################################################

    def init_xml_configuration(self):
        _cfg_path = os.path.join(chipsec.file.get_main_dir(), "chipsec/cfg")
        # Load chipsec/cfg/common.xml configuration XML file common for all platforms if it exists
        self.init_cfg_xml(os.path.join(_cfg_path, "common.xml"), self.code)
        # Load chipsec/cfg/<code>.xml configuration XML file if it exists for platform <code>
        if self.code and "" != self.code:
            self.init_cfg_xml(os.path.join(_cfg_path, ("%s.xml" % self.code)), self.code)
        # Load configuration from all other XML files recursively (if any)
        for dirname, subdirs, xml_fnames in os.walk(_cfg_path):
            for _xml in xml_fnames:
                if (
                    fnmatch.fnmatch(_xml, "*.xml")
                    and not fnmatch.fnmatch(_xml, "common.xml")
                    and not (_xml in ["%s.xml" % c.lower() for c in Chipset_Code])
                ):
                    self.init_cfg_xml(os.path.join(dirname, _xml), self.code)
        self.Cfg.XML_CONFIG_LOADED = True

    def init_cfg_xml(self, fxml, code):
        import xml.etree.ElementTree as ET

        if not os.path.exists(fxml):
            return
        if logger().VERBOSE:
            logger().log("[*] looking for platform config in '%s'.." % fxml)
        tree = ET.parse(fxml)
        root = tree.getroot()
        for _cfg in root.iter("configuration"):
            if "platform" not in _cfg.attrib:
                if logger().HAL:
                    logger().log("[*] loading common platform config from '%s'.." % fxml)
            elif code == _cfg.attrib["platform"].lower():
                if logger().HAL:
                    logger().log("[*] loading '%s' platform config from '%s'.." % (code, fxml))
            else:
                continue

            if logger().VERBOSE:
                logger().log("[*] loading integrated devices/controllers..")
            for _pci in _cfg.iter("pci"):
                for _device in _pci.iter("device"):
                    _name = _device.attrib["name"]
                    del _device.attrib["name"]
                    self.Cfg.CONFIG_PCI[_name] = _device.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _device.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading MMIO BARs..")
            for _mmio in _cfg.iter("mmio"):
                for _bar in _mmio.iter("bar"):
                    _name = _bar.attrib["name"]
                    del _bar.attrib["name"]
                    self.Cfg.MMIO_BARS[_name] = _bar.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _bar.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading I/O BARs..")
            for _io in _cfg.iter("io"):
                for _bar in _io.iter("bar"):
                    _name = _bar.attrib["name"]
                    del _bar.attrib["name"]
                    self.Cfg.IO_BARS[_name] = _bar.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _bar.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading memory ranges..")
            for _memory in _cfg.iter("memory"):
                for _range in _memory.iter("range"):
                    _name = _range.attrib["name"]
                    del _range.attrib["name"]
                    self.Cfg.MEMORY_RANGES[_name] = _range.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _range.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading configuration registers..")
            for _registers in _cfg.iter("registers"):
                for _register in _registers.iter("register"):
                    _name = _register.attrib["name"]
                    del _register.attrib["name"]
                    if "size" not in _register.attrib:
                        _register.attrib["size"] = "0x4"
                    if "desc" not in _register.attrib:
                        _register.attrib["desc"] = ""
                    reg_fields = {}
                    if _register.find("field") is not None:
                        for _field in _register.iter("field"):
                            _field_name = _field.attrib["name"]
                            del _field.attrib["name"]
                            if "desc" not in _field.attrib:
                                _field.attrib["desc"] = ""
                            reg_fields[_field_name] = _field.attrib
                        _register.attrib["FIELDS"] = reg_fields
                    self.Cfg.REGISTERS[_name] = _register.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _register.attrib))
            if logger().VERBOSE:
                logger().log("[*] loading controls..")
            for _controls in _cfg.iter("controls"):
                for _control in _controls.iter("control"):
                    _name = _control.attrib["name"]
                    del _control.attrib["name"]
                    self.Cfg.CONTROLS[_name] = _control.attrib
                    if logger().VERBOSE:
                        logger().log("    + %-16s: %s" % (_name, _control.attrib))

    #
    # Load chipsec/cfg/<code>.py configuration file for platform <code>
    #
    def init_cfg(self):
        if self.code and "" != self.code:
            try:
                module_path = "chipsec.cfg." + self.code
                module = importlib.import_module(module_path)
                logger().log_good("imported platform specific configuration: chipsec.cfg.%s" % self.code)
                self.Cfg = getattr(module, self.code)()
            except ImportError, msg:
                if logger().VERBOSE:
                    logger().log("[*] Couldn't import chipsec.cfg.%s\n%s" % (self.code, str(msg)))

        #
        # Initialize platform configuration from XML files
        #
        try:
            self.init_xml_configuration()
        except:
            if logger().VERBOSE:
                logger().log_bad(traceback.format_exc())
            pass