blob: 9cd3fe2f305d61f2e84916a0c65f374eec3fd83b [file] [log] [blame]
Stephen Warrenfdb32692016-09-12 11:51:13 -06001/*
2 * Copyright (c) 2016, NVIDIA CORPORATION.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <fdt_support.h>
9#include <fdtdec.h>
10#include <asm/arch/tegra.h>
11
12extern unsigned long nvtboot_boot_x0;
13
Stephen Warren66c3e192016-12-02 12:26:42 -070014static int set_fdt_addr(void)
15{
16 int ret;
17
Simon Glass4d949a22017-08-03 12:22:10 -060018 ret = env_set_hex("fdt_addr", nvtboot_boot_x0);
Stephen Warren66c3e192016-12-02 12:26:42 -070019 if (ret) {
20 printf("Failed to set fdt_addr to point at DTB: %d\n", ret);
21 return ret;
22 }
23
24 return 0;
25}
26
Stephen Warrenfdb32692016-09-12 11:51:13 -060027/*
28 * Attempt to use /chosen/nvidia,ether-mac in the nvtboot DTB to U-Boot's
29 * ethaddr environment variable if possible.
30 */
31static int set_ethaddr_from_nvtboot(void)
32{
33 const void *nvtboot_blob = (void *)nvtboot_boot_x0;
34 int ret, node, len;
35 const u32 *prop;
36
37 /* Already a valid address in the environment? If so, keep it */
38 if (getenv("ethaddr"))
39 return 0;
40
41 node = fdt_path_offset(nvtboot_blob, "/chosen");
42 if (node < 0) {
43 printf("Can't find /chosen node in nvtboot DTB\n");
44 return node;
45 }
46 prop = fdt_getprop(nvtboot_blob, node, "nvidia,ether-mac", &len);
47 if (!prop) {
48 printf("Can't find nvidia,ether-mac property in nvtboot DTB\n");
49 return -ENOENT;
50 }
51
Simon Glass6a38e412017-08-03 12:22:09 -060052 ret = env_set("ethaddr", (void *)prop);
Stephen Warrenfdb32692016-09-12 11:51:13 -060053 if (ret) {
54 printf("Failed to set ethaddr from nvtboot DTB: %d\n", ret);
55 return ret;
56 }
57
58 return 0;
59}
60
61int tegra_soc_board_init_late(void)
62{
Stephen Warren66c3e192016-12-02 12:26:42 -070063 /*
64 * Ignore errors here; the value may not be used depending on
65 * extlinux.conf or boot script content.
66 */
67 set_fdt_addr();
Stephen Warrenfdb32692016-09-12 11:51:13 -060068 /* Ignore errors here; not all cases care about Ethernet addresses */
69 set_ethaddr_from_nvtboot();
70
71 return 0;
72}