def __init__(self, helper=None): if helper is None: self.helper = OsHelper() else: self.helper = helper self.vid = 0xFFFF self.did = 0xFFFF self.code = CHIPSET_CODE_UNKNOWN self.longname = "Unrecognized Platform" self.id = CHIPSET_ID_UNKNOWN self.pch_vid = 0xFFFF self.pch_did = 0xFFFF self.pch_code = CHIPSET_CODE_UNKNOWN self.pch_longname = 'Unrecognized PCH' self.pch_id = CHIPSET_ID_UNKNOWN self.Cfg = Cfg() # # Initializing 'basic primitive' HAL components # (HAL components directly using native OS helper functionality) # self.pci = pci.Pci(self) self.mem = physmem.Memory(self) self.msr = msr.Msr(self) self.ucode = ucode.Ucode(self) self.io = io.PortIO(self) self.cpu = cpu.CPU(self) self.msgbus = msgbus.MsgBus(self) self.mmio = mmio.MMIO(self) self.iobar = iobar.IOBAR(self) self.igd = igd.IGD(self)
def run(self): t = time.time() _mmio = mmio.MMIO(self.cs) try: if self.width == 'byte': _width = 1 elif self.width == 'word': _width = 2 elif self.width == 'dword': _width = 4 else: _width = int(self.width) except ValueError: self.logger.error("ValueError: Invalid inputs.") return if self.value is not None: _mmio.write_mmcfg_reg(self.bus, self.device, self.function, self.offset, _width, self.value) self.logger.log( "[CHIPSEC] Writing MMCFG register ({:02d}:{:02d}.{:d} + 0x{:02X}): 0x{:X}" .format(self.bus, self.device, self.function, self.offset, self.value)) else: data = _mmio.read_mmcfg_reg(self.bus, self.device, self.function, self.offset, _width) self.logger.log( "[CHIPSEC] Reading MMCFG register ({:02d}:{:02d}.{:d} + 0x{:02X}): 0x{:X}" .format(self.bus, self.device, self.function, self.offset, data)) self.logger.log('') self.logger.log( "[CHIPSEC] (mmcfg) time elapsed {:.3f}".format(time.time() - t))
def __init__(self, cs): super(SPI, self).__init__(cs) self.mmio = mmio.MMIO(cs) self.rcba_spi_base = self.get_SPI_MMIO_base() # We try to map SPIBAR in the process memory, this will increase the # speed of MMIO access later on. try: self.cs.helper.map_io_space(self.rcba_spi_base, Cfg.SPI_MMIO_BASE_LENGTH, 0) except oshelper.UnimplementedAPIError: pass # Reading definitions of SPI flash controller registers # which are required to send SPI cycles once for performance reasons self.hsfs_off = int(self.cs.get_register_def("HSFS")['offset'], 16) self.hsfc_off = int(self.cs.get_register_def("HSFC")['offset'], 16) self.faddr_off = int(self.cs.get_register_def("FADDR")['offset'], 16) self.fdata0_off = int(self.cs.get_register_def("FDATA0")['offset'], 16) if logger().VERBOSE: logger().log( "[spi] Reading SPI flash controller registers definitions:") logger().log(" HSFC offset = 0x%04X" % self.hsfc_off) logger().log(" HSFS offset = 0x%04X" % self.hsfs_off) logger().log(" FADDR offset = 0x%04X" % self.faddr_off) logger().log(" FDATA0 offset = 0x%04X" % self.fdata0_off)
def run(self): self.mmio_ = mmio.MMIO(self.cs) t = time() self.func() self.logger.log("[CHIPSEC] (mmio) time elapsed {:.3f}".format(time() - t))
def run(self): t = time.time() _mmio = mmio.MMIO(self.cs) if 2 == len(self.argv): #pciexbar = _mmio.get_PCIEXBAR_base_address() pciexbar, pciexbar_sz = _mmio.get_MMCFG_base_address() self.logger.log("[CHIPSEC] Memory Mapped Config Base: 0x%016X" % pciexbar) if self.logger.VERBOSE: self.logger.log( "[CHIPSEC] Memory Mapped Config Size: {:016X}".format( pciebar_sz)) return elif 6 > len(self.argv): print MMCfgCommand.__doc__ return try: bus = int(self.argv[2], 16) device = int(self.argv[3], 16) function = int(self.argv[4], 16) offset = int(self.argv[5], 16) if 6 == len(self.argv): width = 1 else: if 'byte' == self.argv[6]: width = 1 elif 'word' == self.argv[6]: width = 2 elif 'dword' == self.argv[6]: width = 4 else: width = int(self.argv[6]) except Exception as e: print MMCfgCommand.__doc__ return if 8 == len(self.argv): value = int(self.argv[7], 16) _mmio.write_mmcfg_reg(bus, device, function, offset, width, value) #_cs.pci.write_mmcfg_reg( bus, device, function, offset, width, value ) self.logger.log( "[CHIPSEC] writing MMCFG register (%02d:%02d.%d + 0x%02X): 0x%X" % (bus, device, function, offset, value)) else: value = _mmio.read_mmcfg_reg(bus, device, function, offset, width) #value = _cs.pci.read_mmcfg_reg( bus, device, function, offset, width ) self.logger.log( "[CHIPSEC] reading MMCFG register (%02d:%02d.%d + 0x%02X): 0x%X" % (bus, device, function, offset, value)) self.logger.log("[CHIPSEC] (mmcfg) time elapsed %.3f" % (time.time() - t))
def __init__(self, cs): super(SPI, self).__init__(cs) self.mmio = mmio.MMIO(cs) self.rcba_spi_base = self.get_SPI_MMIO_base() # We try to map SPIBAR in the process memory, this will increase the # speed of MMIO access later on. try: self.cs.helper.map_io_space(self.rcba_spi_base, Cfg.SPI_MMIO_BASE_LENGTH, 0) except oshelper.UnimplementedAPIError: pass # Reading definitions of SPI flash controller registers # which are required to send SPI cycles once for performance reasons self.hsfs_off = int(self.cs.get_register_def("HSFS")['offset'], 16) self.hsfc_off = int(self.cs.get_register_def("HSFC")['offset'], 16) self.faddr_off = int(self.cs.get_register_def("FADDR")['offset'], 16) self.fdata0_off = int(self.cs.get_register_def("FDATA0")['offset'], 16) self.fdata1_off = int(self.cs.get_register_def("FDATA1")['offset'], 16) self.fdata2_off = int(self.cs.get_register_def("FDATA2")['offset'], 16) self.fdata3_off = int(self.cs.get_register_def("FDATA3")['offset'], 16) self.fdata4_off = int(self.cs.get_register_def("FDATA4")['offset'], 16) self.fdata5_off = int(self.cs.get_register_def("FDATA5")['offset'], 16) self.fdata6_off = int(self.cs.get_register_def("FDATA6")['offset'], 16) self.fdata7_off = int(self.cs.get_register_def("FDATA7")['offset'], 16) self.fdata8_off = int(self.cs.get_register_def("FDATA8")['offset'], 16) self.fdata9_off = int(self.cs.get_register_def("FDATA9")['offset'], 16) self.fdata10_off = int( self.cs.get_register_def("FDATA10")['offset'], 16) self.fdata11_off = int( self.cs.get_register_def("FDATA11")['offset'], 16) self.fdata12_off = int( self.cs.get_register_def("FDATA12")['offset'], 16) self.fdata13_off = int( self.cs.get_register_def("FDATA13")['offset'], 16) self.fdata14_off = int( self.cs.get_register_def("FDATA14")['offset'], 16) self.fdata15_off = int( self.cs.get_register_def("FDATA15")['offset'], 16) self.bios_ptinx = int( self.cs.get_register_def("BIOS_PTINX")['offset'], 16) self.bios_ptdata = int( self.cs.get_register_def("BIOS_PTDATA")['offset'], 16) if self.logger.HAL: self.logger.log( "[spi] Reading SPI flash controller registers definitions:") self.logger.log(" HSFC offset = 0x{:04X}".format( self.hsfc_off)) self.logger.log(" HSFS offset = 0x{:04X}".format( self.hsfs_off)) self.logger.log(" FADDR offset = 0x{:04X}".format( self.faddr_off)) self.logger.log(" FDATA0 offset = 0x{:04X}".format( self.fdata0_off))
def __init__(self, cs): super(SPI, self).__init__(cs) self.mmio = mmio.MMIO(cs) self.rcba_spi_base = self.get_SPI_MMIO_base() # Reading definitions of SPI flash controller registers # which are required to send SPI cycles once for performance reasons self.hsfs_off = int(self.cs.get_register_def("HSFS")['offset'], 16) self.hsfc_off = int(self.cs.get_register_def("HSFC")['offset'], 16) self.faddr_off = int(self.cs.get_register_def("FADDR")['offset'], 16) self.fdata0_off = int(self.cs.get_register_def("FDATA0")['offset'], 16) if logger().VERBOSE: logger().log( "[spi] Reading SPI flash controller registers definitions:") logger().log(" HSFC offset = 0x%04X" % self.hsfc_off) logger().log(" HSFS offset = 0x%04X" % self.hsfs_off) logger().log(" FADDR offset = 0x%04X" % self.faddr_off) logger().log(" FDATA0 offset = 0x%04X" % self.fdata0_off)
def run(self): t = time.time() _mmio = mmio.MMIO(self.cs) if len(self.argv) < 3: print MMIOCommand.__doc__ return op = self.argv[2] t = time.time() if ('list' == op): _mmio.list_MMIO_BARs() elif ('dump' == op): bar = self.argv[3].upper() self.logger.log("[CHIPSEC] Dumping %s MMIO space.." % bar) _mmio.dump_MMIO_BAR(bar) elif ('read' == op): bar = self.argv[3].upper() off = int(self.argv[4], 16) width = int(self.argv[5], 16) if len(self.argv) == 6 else 4 reg = _mmio.read_MMIO_BAR_reg(bar, off, width) self.logger.log("[CHIPSEC] Read %s + 0x%X: 0x%08X" % (bar, off, reg)) elif ('write' == op): bar = self.argv[3].upper() off = int(self.argv[4], 16) width = int(self.argv[5], 16) if len(self.argv) == 6 else 4 if len(self.argv) == 7: reg = int(self.argv[6], 16) self.logger.log("[CHIPSEC] Write %s + 0x%X: 0x%08X" % (bar, off, reg)) _mmio.write_MMIO_BAR_reg(bar, off, reg, width) else: print MMIOCommand.__doc__ return else: self.logger.error("unknown command-line option '%.32s'" % op) print MMIOCommand.__doc__ return self.logger.log("[CHIPSEC] (mmio) time elapsed %.3f" % (time.time() - t))
def run(self): t = time.time() _mmio = mmio.MMIO(self.cs) if len(self.argv) < 3: print(MMIOCommand.__doc__) return op = self.argv[2] t = time.time() if ('list' == op): _mmio.list_MMIO_BARs() elif ('dump' == op): bar = self.argv[3].upper() self.logger.log("[CHIPSEC] Dumping {} MMIO space..".format(bar)) _mmio.dump_MMIO_BAR(bar) elif ('read' == op): bar = self.argv[3].upper() off = int(self.argv[4], 16) width = int(self.argv[5], 16) if len(self.argv) == 6 else 4 reg = _mmio.read_MMIO_BAR_reg(bar, off, width) self.logger.log("[CHIPSEC] Read {} + 0x{:X}: 0x{:08X}".format( bar, off, reg)) elif ('write' == op): bar = self.argv[3].upper() off = int(self.argv[4], 16) width = int(self.argv[5], 16) if len(self.argv) == 6 else 4 if len(self.argv) == 7: reg = int(self.argv[6], 16) self.logger.log("[CHIPSEC] Write {} + 0x{:X}: 0x{:08X}".format( bar, off, reg)) _mmio.write_MMIO_BAR_reg(bar, off, reg, width) else: print(MMIOCommand.__doc__) return else: self.logger.error("unknown command-line option '{:32}'".format(op)) print(MMIOCommand.__doc__) return self.logger.log( "[CHIPSEC] (mmio) time elapsed {:.3f}".format(time.time() - t))
def run(self): _mmio = mmio.MMIO(self.cs) pciexbar, pciexbar_sz = _mmio.get_MMCFG_base_address() self.logger.log( "[CHIPSEC] Memory Mapped Config Base: 0x{:016X}".format(pciexbar) ) self.logger.log( "[CHIPSEC] Memory Mapped Config Size: 0x{:016X}".format(pciexbar_sz) ) self.logger.log( '' )
def __init__(self): BaseModule.__init__(self) self.mmio = mmio.MMIO(self.cs)
def __init__(self, cs): super(IOMMU, self).__init__(cs) self.mmio = mmio.MMIO(cs)