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 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