如何读取AM335X上的特定寄存器值
How to read a specific register value on AM335X
我想获得 Beaglebone Black 的唯一序列号。 AM335X 参考手册 9.3.1.25 告诉我,我应该能够从 mac_id0_lo 和 mac_id0_hi 寄存器中获取唯一的序列号。这些寄存器的偏移量是 630h 和 634h。
如何读取这些寄存器的值?我在 Whosebug 上找到了 this post,但它不是很有帮助。
更新
我终于得到了一个 python 代码,可以从 beaglebone black 中读取 mac_id0 和 mac_id1。
from mmap import mmap
import struct
CONTROL_MODULE_OFFSET = 0x44E10000
CONTROL_MODULE_SIZE = 0x44E11FFF-CONTROL_MODULE_OFFSET
MAC_ID0_LO_OFFSET = 0x630
MAC_ID0_HI_OFFSET = 0x634
MAC_ID1_LO_OFFSET = 0x638
MAC_ID1_HI_OFFSET = 0x63C
def print_mac():
file_handler = open("/dev/mem", "r+b")
mem = mmap(file_handler.fileno(), CONTROL_MODULE_SIZE, offset=CONTROL_MODULE_OFFSET)
mac_id0_lo_packed_reg = mem[MAC_ID0_LO_OFFSET:MAC_ID0_LO_OFFSET+4]
mac_id0_hi_packed_reg = mem[MAC_ID0_HI_OFFSET:MAC_ID0_HI_OFFSET+4]
mac_id1_lo_packed_reg = mem[MAC_ID1_LO_OFFSET:MAC_ID1_LO_OFFSET+4]
mac_id1_hi_packed_reg = mem[MAC_ID1_HI_OFFSET:MAC_ID1_HI_OFFSET+4]
mac_id0_lo = struct.unpack('<L', mac_id0_lo_packed_reg)[0]
mac_id0_hi = struct.unpack('<L', mac_id0_hi_packed_reg)[0]
mac_id0_bytes = [None]*6
mac_id0_bytes[0] = (mac_id0_lo & 0xff00) >> 8 #byte 0
mac_id0_bytes[1] = (mac_id0_lo & 0x00ff) #byte 1
mac_id0_bytes[2] = (mac_id0_hi & 0xff000000) >> 24 #byte 2
mac_id0_bytes[3] = (mac_id0_hi & 0x00ff0000) >> 16 #byte 3
mac_id0_bytes[4] = (mac_id0_hi & 0x0000ff00) >> 8 #byte 4
mac_id0_bytes[5] = (mac_id0_hi & 0x000000ff) #byte 4
mac_address_id0 = 0
for i, byte in enumerate(mac_id0_bytes):
mac_address_id0 |= ((byte & 0xff) << (i*8))
mac_id1_lo = struct.unpack('<L', mac_id1_lo_packed_reg)[0]
mac_id1_hi = struct.unpack('<L', mac_id1_hi_packed_reg)[0]
mac_id1_bytes = [None]*6
mac_id1_bytes[0] = (mac_id1_lo & 0xff00) >> 8 #byte 0
mac_id1_bytes[1] = (mac_id1_lo & 0x00ff) #byte 1
mac_id1_bytes[2] = (mac_id1_hi & 0xff000000) >> 24 #byte 2
mac_id1_bytes[3] = (mac_id1_hi & 0x00ff0000) >> 16 #byte 3
mac_id1_bytes[4] = (mac_id1_hi & 0x0000ff00) >> 8 #byte 4
mac_id1_bytes[5] = (mac_id1_hi & 0x000000ff) #byte 4
mac_address_id1 = 0
for i, byte in enumerate(mac_id1_bytes):
mac_address_id1 |= ((byte & 0xff) << (i*8))
print 'mac id0'
print format(mac_address_id0, '08x')
print 'mac id1'
print format(mac_address_id1, '08x')
if not file_handler.closed:
file_handler.close()
mem.close()
print_mac()
这些寄存器必须是内存映射的,所以问题是如何找出完整的物理地址并找到访问该物理地址的方法。
来自 TRM:
The values read from Control Module (Base address 0x44E1_0000)
MAC_ID0_LO register (Offset 0x630), MAC_ID0_HI register (Offset
0x634), MAC_ID1_LO register (Offset 0x638), and MAC_ID1_HI register
(Offset 0x63C) represent unique MAC addresses assigned to each AM335x
device. The values in these registers are programmed into each AM335x
device by TI and can not be changed.
也许您可以像 devmem2 0x44e10630
一样使用 devmem2,但这可能取决于 Linux 没有 CONFIG_STRICT_DEVMEM
。更糟糕的是,您可能需要编写一个小的内核驱动程序来访问这些内存区域。
正如 auselen 所提到的,我只是尝试通过执行 devmem2 0xfed000f0
来读取高精度定时器芯片的主计数器寄存器中的值,尽管设置了 CONFIG_STRICT_DEVMEM
但它仍然有效,因为事实上它是非 RAM,因此在用户空间中 readable/writable。
我想获得 Beaglebone Black 的唯一序列号。 AM335X 参考手册 9.3.1.25 告诉我,我应该能够从 mac_id0_lo 和 mac_id0_hi 寄存器中获取唯一的序列号。这些寄存器的偏移量是 630h 和 634h。
如何读取这些寄存器的值?我在 Whosebug 上找到了 this post,但它不是很有帮助。
更新
我终于得到了一个 python 代码,可以从 beaglebone black 中读取 mac_id0 和 mac_id1。
from mmap import mmap
import struct
CONTROL_MODULE_OFFSET = 0x44E10000
CONTROL_MODULE_SIZE = 0x44E11FFF-CONTROL_MODULE_OFFSET
MAC_ID0_LO_OFFSET = 0x630
MAC_ID0_HI_OFFSET = 0x634
MAC_ID1_LO_OFFSET = 0x638
MAC_ID1_HI_OFFSET = 0x63C
def print_mac():
file_handler = open("/dev/mem", "r+b")
mem = mmap(file_handler.fileno(), CONTROL_MODULE_SIZE, offset=CONTROL_MODULE_OFFSET)
mac_id0_lo_packed_reg = mem[MAC_ID0_LO_OFFSET:MAC_ID0_LO_OFFSET+4]
mac_id0_hi_packed_reg = mem[MAC_ID0_HI_OFFSET:MAC_ID0_HI_OFFSET+4]
mac_id1_lo_packed_reg = mem[MAC_ID1_LO_OFFSET:MAC_ID1_LO_OFFSET+4]
mac_id1_hi_packed_reg = mem[MAC_ID1_HI_OFFSET:MAC_ID1_HI_OFFSET+4]
mac_id0_lo = struct.unpack('<L', mac_id0_lo_packed_reg)[0]
mac_id0_hi = struct.unpack('<L', mac_id0_hi_packed_reg)[0]
mac_id0_bytes = [None]*6
mac_id0_bytes[0] = (mac_id0_lo & 0xff00) >> 8 #byte 0
mac_id0_bytes[1] = (mac_id0_lo & 0x00ff) #byte 1
mac_id0_bytes[2] = (mac_id0_hi & 0xff000000) >> 24 #byte 2
mac_id0_bytes[3] = (mac_id0_hi & 0x00ff0000) >> 16 #byte 3
mac_id0_bytes[4] = (mac_id0_hi & 0x0000ff00) >> 8 #byte 4
mac_id0_bytes[5] = (mac_id0_hi & 0x000000ff) #byte 4
mac_address_id0 = 0
for i, byte in enumerate(mac_id0_bytes):
mac_address_id0 |= ((byte & 0xff) << (i*8))
mac_id1_lo = struct.unpack('<L', mac_id1_lo_packed_reg)[0]
mac_id1_hi = struct.unpack('<L', mac_id1_hi_packed_reg)[0]
mac_id1_bytes = [None]*6
mac_id1_bytes[0] = (mac_id1_lo & 0xff00) >> 8 #byte 0
mac_id1_bytes[1] = (mac_id1_lo & 0x00ff) #byte 1
mac_id1_bytes[2] = (mac_id1_hi & 0xff000000) >> 24 #byte 2
mac_id1_bytes[3] = (mac_id1_hi & 0x00ff0000) >> 16 #byte 3
mac_id1_bytes[4] = (mac_id1_hi & 0x0000ff00) >> 8 #byte 4
mac_id1_bytes[5] = (mac_id1_hi & 0x000000ff) #byte 4
mac_address_id1 = 0
for i, byte in enumerate(mac_id1_bytes):
mac_address_id1 |= ((byte & 0xff) << (i*8))
print 'mac id0'
print format(mac_address_id0, '08x')
print 'mac id1'
print format(mac_address_id1, '08x')
if not file_handler.closed:
file_handler.close()
mem.close()
print_mac()
这些寄存器必须是内存映射的,所以问题是如何找出完整的物理地址并找到访问该物理地址的方法。
来自 TRM:
The values read from Control Module (Base address 0x44E1_0000) MAC_ID0_LO register (Offset 0x630), MAC_ID0_HI register (Offset 0x634), MAC_ID1_LO register (Offset 0x638), and MAC_ID1_HI register (Offset 0x63C) represent unique MAC addresses assigned to each AM335x device. The values in these registers are programmed into each AM335x device by TI and can not be changed.
也许您可以像 devmem2 0x44e10630
一样使用 devmem2,但这可能取决于 Linux 没有 CONFIG_STRICT_DEVMEM
。更糟糕的是,您可能需要编写一个小的内核驱动程序来访问这些内存区域。
正如 auselen 所提到的,我只是尝试通过执行 devmem2 0xfed000f0
来读取高精度定时器芯片的主计数器寄存器中的值,尽管设置了 CONFIG_STRICT_DEVMEM
但它仍然有效,因为事实上它是非 RAM,因此在用户空间中 readable/writable。