1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2010-2016, NVIDIA CORPORATION.
9 #include <asm/arch-tegra/cboot.h>
10 #include <asm/arch-tegra/gpu.h>
13 * This function is called right before the kernel is booted. "blob" is the
14 * device tree that will be passed to the kernel.
16 int ft_system_setup(void *blob, struct bd_info *bd)
18 const char *gpu_compats[] = {
19 #if defined(CONFIG_TEGRA124)
22 #if defined(CONFIG_TEGRA210)
28 /* Enable GPU node if GPU setup has been performed */
29 for (i = 0; i < ARRAY_SIZE(gpu_compats); i++) {
30 ret = tegra_gpu_enable_node(blob, gpu_compats[i]);
38 #if defined(CONFIG_ARM64)
39 void ft_mac_address_setup(void *fdt)
41 const void *cboot_fdt = (const void *)cboot_boot_x0;
42 uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN];
46 err = cboot_get_ethaddr(cboot_fdt, local_mac);
48 memset(local_mac, 0, ETH_ALEN);
50 path = fdt_get_alias(fdt, "ethernet");
54 debug("ethernet alias found: %s\n", path);
56 offset = fdt_path_offset(fdt, path);
58 printf("ethernet alias points to absent node %s\n", path);
62 if (is_valid_ethaddr(local_mac)) {
63 err = fdt_setprop(fdt, offset, "local-mac-address", local_mac,
66 debug("Local MAC address set: %pM\n", local_mac);
69 if (eth_env_get_enetaddr("ethaddr", mac)) {
70 if (memcmp(local_mac, mac, ETH_ALEN) != 0) {
71 err = fdt_setprop(fdt, offset, "mac-address", mac,
74 debug("MAC address set: %pM\n", mac);
79 static int ft_copy_carveout(void *dst, const void *src, const char *node)
81 const char *names = "memory-region-names";
82 struct fdt_memory carveout;
83 unsigned int index = 0;
88 const char **compatibles = NULL;
89 unsigned int num_compatibles;
94 err = fdtdec_get_carveout(src, node, "memory-region", index,
95 &carveout, &name, &compatibles,
96 &num_compatibles, &flags);
98 if (err != -FDT_ERR_NOTFOUND)
99 printf("failed to get carveout for %s: %d\n",
108 const char *ptr = strchr(name, '@');
111 copy = strndup(name, ptr - name);
118 err = fdtdec_set_carveout(dst, node, "memory-region", index,
119 &carveout, name, compatibles,
120 num_compatibles, flags);
122 printf("failed to set carveout for %s: %d\n", node,
133 offset = fdt_path_offset(src, node);
135 debug("failed to find source offset for %s: %s\n", node,
140 prop = fdt_getprop(src, offset, names, &len);
142 offset = fdt_path_offset(dst, node);
144 debug("failed to find destination offset for %s: %s\n",
145 node, fdt_strerror(err));
149 err = fdt_setprop(dst, offset, "memory-region-names", prop,
152 debug("failed to copy \"%s\" property: %s\n", names,
161 void ft_carveout_setup(void *fdt, const char * const *nodes, unsigned int count)
163 const void *cboot_fdt = (const void *)cboot_boot_x0;
167 for (i = 0; i < count; i++) {
168 printf("copying carveout for %s...\n", nodes[i]);
170 err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]);
172 if (err != -FDT_ERR_NOTFOUND)
173 printf("failed to copy carveout for %s: %d\n",