Simon Glass | 0a9bde1 | 2016-01-17 14:51:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001-2015 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * Joe Hershberger, National Instruments |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <miiphy.h> |
| 11 | #include "eth_internal.h" |
| 12 | |
Simon Glass | ce63f89 | 2016-01-17 14:51:58 -0700 | [diff] [blame^] | 13 | void eth_parse_enetaddr(const char *addr, uchar *enetaddr) |
| 14 | { |
| 15 | char *end; |
| 16 | int i; |
| 17 | |
| 18 | for (i = 0; i < 6; ++i) { |
| 19 | enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; |
| 20 | if (addr) |
| 21 | addr = (*end) ? end + 1 : end; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | int eth_getenv_enetaddr(const char *name, uchar *enetaddr) |
| 26 | { |
| 27 | eth_parse_enetaddr(getenv(name), enetaddr); |
| 28 | return is_valid_ethaddr(enetaddr); |
| 29 | } |
| 30 | |
| 31 | int eth_setenv_enetaddr(const char *name, const uchar *enetaddr) |
| 32 | { |
| 33 | char buf[20]; |
| 34 | |
| 35 | sprintf(buf, "%pM", enetaddr); |
| 36 | |
| 37 | return setenv(name, buf); |
| 38 | } |
| 39 | |
| 40 | int eth_getenv_enetaddr_by_index(const char *base_name, int index, |
| 41 | uchar *enetaddr) |
| 42 | { |
| 43 | char enetvar[32]; |
| 44 | sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index); |
| 45 | return eth_getenv_enetaddr(enetvar, enetaddr); |
| 46 | } |
| 47 | |
| 48 | int eth_setenv_enetaddr_by_index(const char *base_name, int index, |
| 49 | uchar *enetaddr) |
| 50 | { |
| 51 | char enetvar[32]; |
| 52 | sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index); |
| 53 | return eth_setenv_enetaddr(enetvar, enetaddr); |
| 54 | } |
| 55 | |
Simon Glass | 0a9bde1 | 2016-01-17 14:51:57 -0700 | [diff] [blame] | 56 | void eth_common_init(void) |
| 57 | { |
| 58 | bootstage_mark(BOOTSTAGE_ID_NET_ETH_START); |
| 59 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) |
| 60 | miiphy_init(); |
| 61 | #endif |
| 62 | |
| 63 | #ifdef CONFIG_PHYLIB |
| 64 | phy_init(); |
| 65 | #endif |
| 66 | } |