def getSerialAddresses(self, ioportspath): "Gets serial addresses in form (startaddr, endaddr)" serialAddresses = [] KEYWORD = "serial" # Get all lines which include KEYWORD try: ioportdata = extractor.extractData(ioportspath) except IOError: message.addError("Could not access location: %s\n" % ioportspath + "Serial device addresses not found.", False) else: try: lines = parseutil.findLines(ioportdata, KEYWORD) except customExceptions.KeyNotFound: message.addMessage( "No serial devices found from file: %s" % ioportspath) else: # Retrieve (start,end) data for serial devices for line in lines: serialAddresses.append(self.getAddressFromLine(line)) print "Serial devices found: %d\n------------------" % len(serialAddresses) for addr in serialAddresses: print " Start: ", "0x" + addr.start, " End: ", "0x" + addr.end return serialAddresses
def getDeviceMemoryBlocks(self, devicepath, minsize=PAGE_MIN_SIZE): devmemblocks = [] try: resourceData = extractor.extractData( os.path.join(devicepath, "resource")) except IOError: message.addError("Could not obtain memory information for device: " "%s" % os.path.basename( devicepath), False) else: memcount = 0 for line in resourceData.splitlines(): tokens = line.split(' ') if tokens[2][-3] == '2': # if line represents a memory block memory = Element("memory", "deviceMemoryType") memory["name"] = "mem%d" % memcount memory["physicalAddress"] = util.toWord64(tokens[0]) # Rounds memsize up to minsize memsize = util.sizeOf(tokens[1], tokens[0]) if int(memsize, 16) < int(minsize, 16): memrounded = util.hexFloor(memsize, minsize) print ("Mem size %s for device %s rounded to: %s" % (memsize, os.path.basename(devicepath), memrounded)) memsize = memrounded memory["size"] = util.toWord64(memsize) memory["caching"] = "UC" # TODO devmemblocks.append(memory) memcount += 1 return devmemblocks
def getIoports(self, devicepath): ioports = [] try: resourceData = extractor.extractData( os.path.join(devicepath, "resource")) except IOError: message.addError("Could not obtain ioport information for device: " "%s" % os.path.basename( devicepath), False) else: ioportcount = 0 for line in resourceData.splitlines(): tokens = line.split(' ') if tokens[2][-3] == '1': # if line represents ioport information ioPort = Element("ioPort", "ioPortType") ioPort["name"] = "ioport%d" % ioportcount ioPort["start"] = util.toWord64(tokens[0]) ioPort["end"] = util.toWord64(tokens[1]) ioportcount += 1 ioports.append(ioPort) return ioports
def isBridge(self, devicepath): isBridge = False PCI_BRIDGE = "0x0604" if extractor.extractData(os.path.join(devicepath, "class"))[0:6] == PCI_BRIDGE: isBridge = True return isBridge
def getIrq(self, devicepath): irq = None try: irqNo = extractor.extractData(os.path.join(devicepath, "irq")) except IOError: message.addError("Could not obtain irq number for device: %s" % os.path.basename(devicepath), False) else: if irqNo is not "0": irq = Element("irq", "irqType") irq["name", "number"] = "irq", irqNo return irq
def getPciConfigAddress(self, path): pciconfigaddr = "" key = "PCI MMCONFIG" try: iomemdata = extractor.extractData(path) keyline = parseutil.findLines(iomemdata, key)[0] pciconfigaddr = keyline.split("-")[0].lstrip() except (customExceptions.KeyNotFound, IOError): message.addWarning( "Could not obtain pciConfigAddress from %s." % path) return pciconfigaddr
def generateMemoryBlock(self, endfile, typefile, startfile): memoryBlock = Element("memoryBlock", "memoryBlockType") memoryBlock["name"] = extractor.extractData(typefile) memaddr = extractor.extractData(startfile) memoryBlock["physicalAddress"] = util.toWord64(memaddr) memsize = util.sizeOf(extractor.extractData(endfile), extractor.extractData(startfile)) # Round memsize down to multiple of PAGE_SIZE if int(memsize, 16) % int(PAGE_SIZE, 16) != 0: memrounded = util.hexRoundToMultiple( memsize, PAGE_SIZE, rounddown=True) print "Mem size %s for memoryBlock %s rounded down to: %s" % ( memsize, memaddr, memrounded) memsize = memrounded memoryBlock["size"] = util.toWord64(memsize) if self.isAllocatable(memoryBlock): memoryBlock["allocatable"] = "true" else: memoryBlock["allocatable"] = "false" return memoryBlock
def getClassName(self, devicepath, pciIdsParser): "Checks the pciIdsParser object and gets the class name for the device" # Get class code from "class" file" classcode = extractor.extractData( os.path.join(devicepath, "class"))[0:8] classname = classcode try: classname = pciIdsParser.getClassName(classcode[0:6]) classname = util.spacesToUnderscores(classname.lower()) except (customExceptions.PciIdsFailedSearch, customExceptions.PciIdsSubclassNotFound): message.addWarning(("Name for Device at: %s " % devicepath + "could not be found. It would " + "be a good idea to update pci.ids " + "(try '-update' or '-u')")) return classname
def init(self, pciIdsLoc): "Fills up database from pci.ids at pciIdsLoc" try: data = extractor.extractData(pciIdsLoc) lastVendor = "" lastClass = "" for line in data.splitlines(): # find Vendor if self.isVendor(line): tokens = line.partition(" ") vendorcode = tokens[0].strip() if vendorcode not in self.vendorData: self.vendorData[vendorcode] = tokens[2].strip() lastVendor = vendorcode else: self.vendorData[vendorcode] = tokens[2].strip() lastVendor = vendorcode raise customExceptions.PciIdsMultipleEntries( "Multiple instances of vendor with the same id " "detected") # if find Device, refer to last Vendor if self.isDevice(line): tokens = line.lstrip("\t").partition(" ") devicecode = tokens[0].strip() if (lastVendor, devicecode) not in self.deviceData: self.deviceData[ (lastVendor, devicecode)] = tokens[2].strip() # find Class if self.isClass(line): lastClass = line.split(" ")[1] # gets class code self.classData["%s" % lastClass] = line.split( " ")[1] # gets class name # if find Subclass, refer to last Class if self.isSubclass(line): tokens = line.lstrip().partition(" ") subclassname = tokens[2] self.classData[ "%s%s" % (lastClass, tokens[0])] = subclassname except IOError: raise customExceptions.PciIdsFileNotFound("pci.ids file could not be " "located in directory")
def getSpeed(self, dmesgpath): "Gets speed value from dmesg" PARSE_KEYWORD = "Refined TSC clocksource calibration" result = 0 try: data = extractor.extractData(dmesgpath) speedstr = parseutil.parseData_Sep(data, PARSE_KEYWORD, ":") result = util.getSpeedValue(speedstr, PROCESSOR_SPEED_KEYWORDS) except IOError: errstr = ("Could not read file: %s\n" % dmesgpath + "Processor speed not found.") message.addError(errstr) except customExceptions.KeyNotFound: errstr = ("Could not read find refined TSC clocksource calibration " "results in: %s\n" % dmesgpath + "Processor speed not found.") message.addError(errstr) else: return result
def getIommuAddrs(self, parsedDMAR=None): "Retrieves Register Base Addresses of IOMMUs from parsed DMAR" iommuaddrs = [] KEY = "Register Base Address" if parsedDMAR is None: parsedDMAR = self.getParsedDmarPath() try: dmardata = extractor.extractData(parsedDMAR) except IOError: message.addError("Could not find parsed DMAR file in location: %s." % parsedDMAR, False) else: for line in dmardata.splitlines(): try: addr = parseLine_Sep(line, KEY, ":") addr = addr.lstrip("0") addr = "0x" + addr addr = addr.lower() iommuaddrs.append(addr) except customExceptions.KeyNotFound: pass return iommuaddrs
def getLogicalCpus(self, cpuinfopath): cpuinfo = extractor.extractData(cpuinfopath) return parseutil.count(cpuinfo, "processor")