summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/get_dieid.py
blob: b20f143ea0285f4f669df03c90b93a631ef0c51a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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))