U-boot源码中的文档doc/README.enetaddr对mac地址的存储有详细的介绍。通常有三种情况:
MAC地址存储在EEPROM中
U-boot下可以用mac命令用来查看,EEPROM的MAC地址在U-boot启动时会被写入到环境变量。
=> help mac
mac - display and program the system ID and MAC addresses in EEPROM
Usage:
mac [read|save|id|num|errata|date|ports|port_number]
mac read
- read EEPROM content into memory data structure
mac save
- save memory data structure to the EEPROM
mac id
- program system id per hard coded value
mac num string
- program system serial number to value string
mac errata string
- program errata data to value string
mac date YYMMDDhhmmss
- program date to string value YYMMDDhhmmss
mac ports N
- program the number of network ports to integer N
mac X string
- program MAC addr for port X [X=0,1..] to colon separated string
=>
例如
=> mac
ID: NXID v1
SN: ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Errata: ▒▒▒▒▒▒▒▒▒▒▒▒
Build date: 20ff/ff/ff 7f:ff:ff PM
Eth0: 11:22:33:44:44:ff
Eth1: ff:ff:ff:ff:ff:ff
Eth2: ff:ff:ff:ff:ff:ff
Eth3: ff:ff:ff:ff:ff:ff
Eth4: ff:ff:ff:ff:ff:ff
Eth5: ff:ff:ff:ff:ff:ff
Eth6: ff:ff:ff:ff:ff:ff
Eth7: ff:ff:ff:ff:ff:ff
Eth8: ff:ff:ff:ff:ff:ff
Eth9: ff:ff:ff:ff:ff:ff
Eth10: ff:ff:ff:ff:ff:ff
Eth11: ff:ff:ff:ff:ff:ff
Eth12: ff:ff:ff:ff:ff:ff
Eth13: ff:ff:ff:ff:ff:ff
Eth14: ff:ff:ff:ff:ff:ff
Eth15: ff:ff:ff:ff:ff:ff
CRC: d0228164
=>
配置mac地址
=> mac id
=> mac 0 "11:22:33:44:44:55"
=> mac save
Programming passed.
=> mac
ID: NXID v1
SN: ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Errata: ▒▒▒▒▒▒▒▒▒▒▒▒
Build date: 20ff/ff/ff 7f:ff:ff PM
Eth0: 11:22:33:44:44:55
Eth1: ff:ff:ff:ff:ff:ff
Eth2: ff:ff:ff:ff:ff:ff
Eth3: ff:ff:ff:ff:ff:ff
Eth4: ff:ff:ff:ff:ff:ff
Eth5: ff:ff:ff:ff:ff:ff
Eth6: ff:ff:ff:ff:ff:ff
Eth7: ff:ff:ff:ff:ff:ff
Eth8: ff:ff:ff:ff:ff:ff
Eth9: ff:ff:ff:ff:ff:ff
Eth10: ff:ff:ff:ff:ff:ff
Eth11: ff:ff:ff:ff:ff:ff
Eth12: ff:ff:ff:ff:ff:ff
Eth13: ff:ff:ff:ff:ff:ff
Eth14: ff:ff:ff:ff:ff:ff
Eth15: ff:ff:ff:ff:ff:ff
CRC: 9c51e991
=>
MAC地址存储在环境变量中
如果环境变量中配置了与EEPROM不同的mac地址,则使用环境变量中的MAC地址。例如,
=> pri
...
eth1addr=00:04:9f:06:de:bd
eth2addr=00:04:9f:06:de:be
eth3addr=00:00:00:00:00:04
eth4addr=00:04:9f:06:de:bf
ethaddr=00:04:9f:06:de:ba
...
随机MAC地址
如果既没有在EEPROM中,也没有在环境变量中配置MAC地址,并且CONFIG_NET_RANDOM_ETHADDR是使能状态。U-boot在启动时随机生成MAC地址,供启动后使用,每次启动生成的MAC地址都是随机的。但是不会被写入环境变量,不能传递给linux kernel使用。