[U-Boot] [PATCH 0/2] 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(+)

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.
Signed-off-by: Roger Quadros rogerq@ti.com --- include/net.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/include/net.h b/include/net.h index a739f45..03ae232 100644 --- a/include/net.h +++ b/include/net.h @@ -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:

On Fri, Mar 18, 2016 at 01:18:11PM +0200, Roger Quadros wrote:
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.
Signed-off-by: Roger Quadros rogerq@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

On Fri, Mar 18, 2016 at 01:18:11PM +0200, Roger Quadros wrote:
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.
Signed-off-by: Roger Quadros rogerq@ti.com Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

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 rogerq@ti.com --- board/ti/am57xx/board.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 67191af..18416ef 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -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

On Fri, Mar 18, 2016 at 01:18:12PM +0200, Roger Quadros wrote:
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 rogerq@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

On Fri, Mar 18, 2016 at 01:18:12PM +0200, Roger Quadros wrote:
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 rogerq@ti.com Reviewed-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (2)
-
Roger Quadros
-
Tom Rini