import mmap import os import struct import sh 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 get_die_id(modelid): dieid = "" # get registers if modelid.find("IGEP0046") == 0: registers = [0x021BC420, 0x021BC410] elif modelid.find("IGEP0034") == 0 or modelid.find("SOPA0000") == 0: # registers: mac_id0_lo, mac_id0_hi, mac_id1_lo, mac_id1_hi registers = [0x44e10630, 0x44e10634, 0x44e10638, 0x44e1063C] elif modelid.find("OMAP3") == 0 or modelid.find("IGEP0020") == 0 or modelid.find("IGEP0030") == 0: registers = [0x4830A224, 0x4830A220, 0x4830A21C, 0x4830A218] elif modelid.find("OMAP5") == 0: registers = [0x4A002210, 0x4A00220C, 0x4A002208, 0x4A002200] else: raise Exception('modelid not defined') for rg in registers: dieid = dieid + read(rg) return dieid def get_internal_mac(modelid): mac = None if modelid.find("IGEP0034") == 0 or modelid.find("SOPA0000") == 0: # # registers: mac_id0_lo, mac_id0_hi # registers = [0x44e10630, 0x44e10634] # mac = "" # for rg in registers: # mac = mac + read(rg) # #erase trailing zeros # mac = mac[4::1] # # To be finished... mac = sh.cat("/sys/class/net/eth0/address").strip() return mac