我想从Beaglebone Black中获取唯一的序列号。 AM335X参考手册9.3.1.25告诉我,我应该能够从mac_id0_lo和mac_id0_hi寄存器中获得唯一的序列号。这些寄存器的偏移量为630h和634h。如何读取AM335X上的特定寄存器值
如何读取这些寄存器的值?我在stackoverflow上找到this post,但它不是很有帮助。
UPDATE
我终于得到了一个Python代码的工作来读取beaglebone黑色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()
@AlexZielenski这不是那种注册OP是要求baout。 –
什么操作系统,如果你有使用? – doron
@doron,我使用的是debian wheezy。 – DXM