Use ethernet MAC programmed in imxrt OCOTP MAC0/MAC1 (teemsy board has this)

This commit is contained in:
P.Brier 2021-09-29 20:40:15 +02:00 committed by Xiang Xiao
parent dfc08a0b66
commit b9d1fcb232
2 changed files with 34 additions and 0 deletions

View File

@ -2560,6 +2560,28 @@ int imxrt_netinitialize(int intf)
priv->dev.d_private = g_enet; /* Used to recover private state from dev */ priv->dev.d_private = g_enet; /* Used to recover private state from dev */
#ifdef CONFIG_NET_ETHERNET #ifdef CONFIG_NET_ETHERNET
#ifdef CONFIG_NET_USE_OTP_ETHERNET_MAC
/* Boards like the teensy have a unique (official)
* MAC address stored in OTP.
* TODO: hardcoded mem locations: use proper registers and header file
* offsets: 0x620: MAC0, 0x630: MAC1
*/
uidl = getreg32(IMXRT_OCOTP_BASE + 0x620);
uidml = getreg32(IMXRT_OCOTP_BASE + 0x630);
mac = priv->dev.d_mac.ether.ether_addr_octet;
mac[0] = (uidml & 0x0000ff00) >> 8;
mac[1] = (uidml & 0x000000ff) >> 0;
mac[2] = (uidl & 0xff000000) >> 24;
mac[3] = (uidl & 0x00ff0000) >> 16;
mac[4] = (uidl & 0x0000ff00) >> 8;
mac[5] = (uidl & 0x000000ff) >> 0;
#else
/* Determine a semi-unique MAC address from MCU UID /* Determine a semi-unique MAC address from MCU UID
* We use UID Low and Mid Low registers to get 64 bits, from which we keep * We use UID Low and Mid Low registers to get 64 bits, from which we keep
* 48 bits. We then force unicast and locally administered bits * 48 bits. We then force unicast and locally administered bits
@ -2581,6 +2603,9 @@ int imxrt_netinitialize(int intf)
mac[3] = (uidl & 0x00ff0000) >> 16; mac[3] = (uidl & 0x00ff0000) >> 16;
mac[4] = (uidl & 0x0000ff00) >> 8; mac[4] = (uidl & 0x0000ff00) >> 8;
mac[5] = (uidl & 0x000000ff); mac[5] = (uidl & 0x000000ff);
#endif
#endif #endif
#ifdef CONFIG_IMXRT_ENET_PHYINIT #ifdef CONFIG_IMXRT_ENET_PHYINIT

View File

@ -30,4 +30,13 @@ config IMXRT_FLEXCAN3_AS_CAN0
This configuration option ensures that if more that one CAN bus is set on This configuration option ensures that if more that one CAN bus is set on
that CAN 3 (with FD capability) will be initialized as can0. that CAN 3 (with FD capability) will be initialized as can0.
config NET_USE_OTP_ETHERNET_MAC
bool "Use Ethernet MAC address stored in OCOTP_MAC0 and OCOTP_MAC1"
---help---
The teensy 4.1 board has an "offical" unique MAC address stored in OCOTP (One-Time-Programmable) memory.
When enabling this option, it is read and used when the ethernet peripheral is initialized.
If so, the 'ifconfig eth0' HWaddr should start with 04:e9:e5:...
(the vendor ID of 'PJRC.COM, LLC') when this feature is enabled.
It may also be used with other boards that have the OCOTP programmed with a valid MAC.
endif endif