import mmap import os import struct MAP_MASK = mmap.PAGESIZE - 1 WORD = 4 def read(addr): """ Read from any location in memory Returns the readed value in hexadecimal format Keyword arguments: - addr: The memory address to be readed. """ fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC) # Map one page mm = mmap.mmap(fd, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ, offset=addr & ~MAP_MASK) mm.seek(addr & MAP_MASK) retval = struct.unpack('I', mm.read(WORD)) mm.close() os.close(fd) return "%08X" % retval[0] def getRegisters(model): if model.find("IGEP0046") == 0: registers = [0x021BC420, 0x021BC410] elif model.find("IGEP0000") == 0: registers = [0x021BC420, 0x021BC410] elif model.find("IGEP0034") == 0 or model.find("SOPA0000") == 0: registers = [0x44e10630, 0x44e10634, 0x44e10638, 0x44e1063C] elif model.find("OMAP3") == 0: registers = [0x4830A224, 0x4830A220, 0x4830A21C, 0x4830A218] elif model.find("OMAP5") == 0: registers = [0x4A002210, 0x4A00220C, 0x4A002208, 0x4A002200] return registers def genDieid(modelid): registers=getRegisters(modelid) id="" for i in range(len(registers)): id=id+(read(registers[i])) return id #if __name__ == "__main__": #registers = [0x021BC420, 0x021BC410] #print(main(registers))