summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/int_registers.py
blob: cf2e35ba5ef1db381eae773a932076e2d9bc688f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
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 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:
        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_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)

    return mac