diff options
author | Tom Rini <trini@konsulko.com> | 2019-06-08 09:10:31 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-06-08 09:10:31 -0400 |
commit | 5973901826c73462306fbe4051bc3643dca6b88f (patch) | |
tree | 0135545945d4eabd2e2ba873a79f1f57a8e13c33 /lib | |
parent | 6d277fb0ed145f82dd50cc6e99d2fa553a588c3b (diff) | |
parent | 879a3bc1c2f3e2aadd6f05e6427cf4d97a272f9a (diff) | |
download | u-boot-5973901826c73462306fbe4051bc3643dca6b88f.tar.gz |
Merge branch 'master' of git://git.denx.de/u-boot-tegra
The bulk of these changes are an effort to unify Tegra186 builds with
builds of prior 64-bit Tegra generations. On top of that there are
various improvements that allow data (such as the MAC address and boot
arguments) to be passed through from early firmware to the kernel on
boot.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fdtdec.c | 29 | ||||
-rw-r--r-- | lib/string.c | 23 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index d0ba888973..3ee786b579 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1261,6 +1261,35 @@ __weak void *board_fdt_blob_setup(void) } #endif +int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size) +{ + const char *path; + int offset, err; + + if (!is_valid_ethaddr(mac)) + return -EINVAL; + + path = fdt_get_alias(fdt, "ethernet"); + if (!path) + return 0; + + debug("ethernet alias found: %s\n", path); + + offset = fdt_path_offset(fdt, path); + if (offset < 0) { + debug("ethernet alias points to absent node %s\n", path); + return -ENOENT; + } + + err = fdt_setprop_inplace(fdt, offset, "local-mac-address", mac, size); + if (err < 0) + return err; + + debug("MAC address: %pM\n", mac); + + return 0; +} + static int fdtdec_init_reserved_memory(void *blob) { int na, ns, node, err; diff --git a/lib/string.c b/lib/string.c index af17c16f61..9b779ddc3b 100644 --- a/lib/string.c +++ b/lib/string.c @@ -326,6 +326,29 @@ char * strdup(const char *s) } #endif +char * strndup(const char *s, size_t n) +{ + size_t len; + char *new; + + if (s == NULL) + return NULL; + + len = strlen(s); + + if (n < len) + len = n; + + new = malloc(len + 1); + if (new == NULL) + return NULL; + + strncpy(new, s, len); + new[len] = '\0'; + + return new; +} + #ifndef __HAVE_ARCH_STRSPN /** * strspn - Calculate the length of the initial substring of @s which only |