1 /*
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 
12 extern unsigned long nvtboot_boot_x0;
13 
14 /*
15  * Attempt to use /chosen/nvidia,ether-mac in the nvtboot DTB to U-Boot's
16  * ethaddr environment variable if possible.
17  */
18 static int set_ethaddr_from_nvtboot(void)
19 {
20 	const void *nvtboot_blob = (void *)nvtboot_boot_x0;
21 	int ret, node, len;
22 	const u32 *prop;
23 
24 	/* Already a valid address in the environment? If so, keep it */
25 	if (getenv("ethaddr"))
26 		return 0;
27 
28 	node = fdt_path_offset(nvtboot_blob, "/chosen");
29 	if (node < 0) {
30 		printf("Can't find /chosen node in nvtboot DTB\n");
31 		return node;
32 	}
33 	prop = fdt_getprop(nvtboot_blob, node, "nvidia,ether-mac", &len);
34 	if (!prop) {
35 		printf("Can't find nvidia,ether-mac property in nvtboot DTB\n");
36 		return -ENOENT;
37 	}
38 
39 	ret = setenv("ethaddr", (void *)prop);
40 	if (ret) {
41 		printf("Failed to set ethaddr from nvtboot DTB: %d\n", ret);
42 		return ret;
43 	}
44 
45 	return 0;
46 }
47 
48 int tegra_soc_board_init_late(void)
49 {
50 	/* Ignore errors here; not all cases care about Ethernet addresses */
51 	set_ethaddr_from_nvtboot();
52 
53 	return 0;
54 }
55