diff options
author | Roger Quadros <rogerq@ti.com> | 2017-03-14 15:04:19 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-03-20 17:56:22 -0400 |
commit | 38f719ea5e9d69e69c56b92fc723564194b755e6 (patch) | |
tree | ccc6379bdfef6dfcc06423f9a2cb488c682a58b6 /board/ti/common/board_detect.c | |
parent | a4562d0640264eac8ebca544be777ed125b260d7 (diff) | |
download | u-boot-38f719ea5e9d69e69c56b92fc723564194b755e6.tar.gz |
ti: common: board_detect: commodify ethaddr environment setting code
Keystone and OMAP platforms will need this to set ethernet
MAC addresses from board EEPROM.
Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'board/ti/common/board_detect.c')
-rw-r--r-- | board/ti/common/board_detect.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index a5dba94e5e0..c55e24e3215 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -314,3 +314,65 @@ void __maybe_unused set_board_info_env(char *name) else setenv("board_serial", unknown); } + +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; +} + +void board_ti_set_ethaddr(int index) +{ + uint8_t mac_addr[6]; + int i; + u64 mac1, mac2; + u8 mac_addr1[6], mac_addr2[6]; + int num_macs; + /* + * Export any Ethernet MAC addresses from EEPROM. + * The 2 MAC addresses in EEPROM 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; + if (num_macs <= 0) + return; + + if (num_macs > 50) { + printf("%s: Too many MAC addresses: %d. Limiting to 50\n", + __func__, num_macs); + 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 + index, + mac_addr); + } + } + } +} |