From 9925f1dbc38c0ef7220c6fca5968c708b8e48764 Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Sun, 1 Apr 2018 09:22:38 +0000 Subject: net: Move enetaddr env access code to env config instead of net config In order that we can use eth_env_* even when CONFIG_NET isn't set, move these functions to environment code from net code. This fixes failures such as: board/ti/am335x/built-in.o: In function `board_late_init': board/ti/am335x/board.c:752: undefined reference to `eth_env_set_enetaddr' u-boot/board/ti/am335x/board.c:766: undefined reference to `eth_env_set_enetaddr' which caters for use cases such as: commit f411b5cca48f ("board: am335x: Always set eth/eth1addr environment variable") when Ethernet is required in Linux, but not U-Boot. Signed-off-by: Alex Kiernan --- cmd/elf.c | 1 + cmd/ethsw.c | 1 + cmd/nvedit.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) (limited to 'cmd') diff --git a/cmd/elf.c b/cmd/elf.c index f874073..0387964 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_X86 diff --git a/cmd/ethsw.c b/cmd/ethsw.c index b600965..92a60b4 100644 --- a/cmd/ethsw.c +++ b/cmd/ethsw.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 4cb25b8..9838678 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -341,6 +341,36 @@ ulong env_get_hex(const char *varname, ulong default_val) return value; } +void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr) +{ + char *end; + int i; + + for (i = 0; i < 6; ++i) { + enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; + if (addr) + addr = (*end) ? end + 1 : end; + } +} + +int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr) +{ + eth_parse_enetaddr(env_get(name), enetaddr); + return is_valid_ethaddr(enetaddr); +} + +int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr) +{ + char buf[ARP_HLEN_ASCII + 1]; + + if (eth_env_get_enetaddr(name, (uint8_t *)buf)) + return -EEXIST; + + sprintf(buf, "%pM", enetaddr); + + return env_set(name, buf); +} + #ifndef CONFIG_SPL_BUILD static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { -- cgit v1.1