board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
cover board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
Hi,
The MAC addresses for the PRU Ethernet ports will be available in the board EEPROM as an address range. Populate those MAC addresses (if valid) into the u-boot environment so that they can be passed on to the device tree during fdt_fixup_ethernet().
cheers,
-roger
Roger Quadros (2):
net: export eth_setenv_enetaddr_by_index() to net.h
board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
board/ti/am57xx/board.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ include/net.h | 17 ++++++++++++++++ 2 files changed, 70 insertions(+)
Signature · 1 line
2.5.0
PATCH 1/2 net: export eth_setenv_enetaddr_by_index() to net.h
Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and this function is handy at board.c to configure the MAC address of the ports.
--- include/net.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/net.h +17 -0
@@ -237,6 +237,23 @@ void eth_parse_enetaddr(const char *addr, uchar *enetaddr);int eth_getenv_enetaddr (const char *name,uchar *enetaddr);int eth_setenv_enetaddr (const char *name,const uchar *enetaddr); +/** +* eth_setenv_enetaddr_by_index() - set the MAC address envrionment variable +* +* This sets up an environment variable with the given MAC address (@enetaddr). +* The environment variable to be set is defined by <@base_name><@index>addr. +* If @index is 0 it is omitted. For common Ethernet this means ethaddr, +* eth1addr, etc. +* +* @base_name: Base name for variable, typically "eth" +* @index: Index of interface being updated (>=0) +* @enetaddr: Pointer to MAC address to put into the variable +* @return 0 if OK, other value on error +*/ +int eth_setenv_enetaddr_by_index (const char *base_name,int index, +uchar *enetaddr); + +/* * Get the hardware address for an ethernet interface . * Args:
Signature · 1 line
2.5.0
PATCH 2/2 board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
In reply to Roger QuadrosThe MAC addresses for the PRU Ethernet ports will be available in the board EEPROM as an address range. Populate those MAC addresses (if valid) into the u-boot environment so that they can be passed on to the device tree during fdt_fixup_ethernet().
--- board/ti/am57xx/board.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
board/ti/am57xx/board.c +53 -0
@@ -537,12 +537,39 @@ static struct cpsw_platform_data cpsw_data = { .version = CPSW_CTRL_VERSION_2, }; +static u64 mac_to_u64 (u8 mac[6 ]) +{ +int i; +u64 addr =0 ; + +for (i =0 ; i <6 ; i++) { + addr <<=8 ; + addr |= mac[i]; + } + +return addr; +} + +static void u64_to_mac (u64 addr,u8 mac[6 ]) +{ + mac[5 ] = addr; + mac[4 ] = addr >>8 ; + mac[3 ] = addr >>16 ; + mac[2 ] = addr >>24 ; + mac[1 ] = addr >>32 ; + mac[0 ] = addr >>40 ; +} +int board_eth_init (bd_t *bis) {int ret;uint8_t mac_addr[6 ];uint32_t mac_hi, mac_lo;uint32_t ctrl_val; +int i; +u64 mac1, mac2; +u8 mac_addr1[6 ], mac_addr2[6 ]; +int num_macs;/* try reading mac address from efuse */ mac_lo =readl ((*ctrl)->control_core_mac_id_0_lo);
@@ -583,6 +610,32 @@ int board_eth_init(bd_t *bis)if (ret <0 )printf ("Error %d registering CPSW switch\n" , ret); +/* +* Export any Ethernet MAC addresses from EEPROM. +* On AM57xx the 2 MAC addresses define the address range +*/ +board_ti_get_eth_mac_addr (0 , mac_addr1); +board_ti_get_eth_mac_addr (1 , mac_addr2); + +if (is_valid_ethaddr (mac_addr1) &&is_valid_ethaddr (mac_addr2)) { + mac1 =mac_to_u64 (mac_addr1); + mac2 =mac_to_u64 (mac_addr2); + +/* must contain an address range */ + num_macs = mac2 - mac1 +1 ; +/* <= 50 to protect against user programming error */ +if (num_macs >0 && num_macs <=50 ) { +for (i =0 ; i < num_macs; i++) { +u64_to_mac (mac1 + i, mac_addr); +if (is_valid_ethaddr (mac_addr)) { +eth_setenv_enetaddr_by_index ("eth" , + i +2 , + mac_addr); + } + } + } + } + return ret; }#endif
Signature · 1 line
2.5.0
PATCH 1/2 net: export eth_setenv_enetaddr_by_index() to net.h
In reply to Roger QuadrosQuoted 5 lines · Roger Quadros
Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and this function is handy at
board.cto configure the MAC address of the ports.Signed-off-by Roger Quadros <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160318/83a5a96a/attachment.sig>
PATCH 2/2 board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
In reply to Roger QuadrosQuoted 6 lines · Roger Quadros
The MAC addresses for the PRU Ethernet ports will be available in the board EEPROM as an address range. Populate those MAC addresses (if valid) into the u-boot environment so that they can be passed on to the device tree during
fdt_fixup_ethernet().Signed-off-by Roger Quadros <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160318/2263b2dc/attachment.sig>
PATCH 1/2 net: export eth_setenv_enetaddr_by_index() to net.h
In reply to Roger QuadrosQuoted 6 lines · Roger Quadros
Some TI boards (e.g. IDK) have 4 to 6 ethernet ports and this function is handy at
board.cto configure the MAC address of the ports.Signed-off-by Roger Quadros <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/435b7eb6/attachment.sig>
PATCH 2/2 board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
In reply to Roger QuadrosQuoted 7 lines · Roger Quadros
The MAC addresses for the PRU Ethernet ports will be available in the board EEPROM as an address range. Populate those MAC addresses (if valid) into the u-boot environment so that they can be passed on to the device tree during
fdt_fixup_ethernet().Signed-off-by Roger Quadros <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160327/37a4e9d8/attachment.sig>