+// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2007
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
* Based on code written by:
* Pantelis Antoniou <pantelis.antoniou@gmail.com> and
* Matthew McClintock <msm@freescale.com>
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <linux/ctype.h>
#include <linux/types.h>
#include <asm/global_data.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
#include <fdt_support.h>
#include <mapmem.h>
#include <asm/io.h>
buf = map_sysmem(addr, 0);
working_fdt = buf;
- setenv_hex("fdtaddr", addr);
+ env_set_hex("fdtaddr", addr);
}
/*
* Get a value from the fdt and format it to be set in the environment
*/
-static int fdt_value_setenv(const void *nodep, int len, const char *var)
+static int fdt_value_env_set(const void *nodep, int len, const char *var)
{
if (is_printable_string(nodep, len))
- setenv(var, (void *)nodep);
+ env_set(var, (void *)nodep);
else if (len == 4) {
char buf[11];
sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
- setenv(var, buf);
+ env_set(var, buf);
} else if (len%4 == 0 && len <= 20) {
/* Needed to print things like sha1 hashes. */
char buf[41];
for (i = 0; i < len; i += sizeof(unsigned int))
sprintf(buf + (i * 2), "%08x",
*(unsigned int *)(nodep + i));
- setenv(var, buf);
+ env_set(var, buf);
} else {
printf("error: unprintable value\n");
return 1;
return 1;
printf("The address of the fdt is %#08lx\n",
control ? (ulong)map_to_sysmem(blob) :
- getenv_hex("fdtaddr", 0));
+ env_get_hex("fdtaddr", 0));
return 0;
}
char *pathp; /* path */
char *prop; /* property */
int nodeoffset; /* node offset from libfdt */
- static char data[SCRATCHPAD]; /* storage for the property */
+ static char data[SCRATCHPAD] __aligned(4);/* property storage */
const void *ptmp;
int len; /* new length of the property */
int ret; /* return value */
len = 0;
} else {
ptmp = fdt_getprop(working_fdt, nodeoffset, prop, &len);
- if (!ptmp) {
- printf("prop (%s) not found!\n", prop);
- return 1;
- }
if (len > SCRATCHPAD) {
printf("prop (%d) doesn't fit in scratchpad!\n",
len);
return 1;
}
- memcpy(data, ptmp, len);
+ if (ptmp != NULL)
+ memcpy(data, ptmp, len);
+
ret = fdt_parse_prop(&argv[4], argc - 4, data, &len);
if (ret != 0)
return ret;
if (curDepth == startDepth + 1)
curIndex++;
if (subcmd[0] == 'n' && curIndex == reqIndex) {
- const char *nodeName = fdt_get_name(
- working_fdt, nextNodeOffset, NULL);
+ const char *node_name;
- setenv(var, (char *)nodeName);
+ node_name = fdt_get_name(working_fdt,
+ nextNodeOffset,
+ NULL);
+ env_set(var, node_name);
return 0;
}
nextNodeOffset = fdt_next_node(
}
if (subcmd[0] == 's') {
/* get the num nodes at this level */
- setenv_ulong(var, curIndex + 1);
+ env_set_ulong(var, curIndex + 1);
} else {
/* node index not found */
printf("libfdt node not found\n");
working_fdt, nodeoffset, prop, &len);
if (len == 0) {
/* no property value */
- setenv(var, "");
+ env_set(var, "");
return 0;
} else if (nodep && len > 0) {
if (subcmd[0] == 'v') {
int ret;
- ret = fdt_value_setenv(nodep, len, var);
+ ret = fdt_value_env_set(nodep, len,
+ var);
if (ret != 0)
return ret;
} else if (subcmd[0] == 'a') {
char buf[11];
sprintf(buf, "0x%p", nodep);
- setenv(var, buf);
+ env_set(var, buf);
} else if (subcmd[0] == 's') {
/* Get size */
char buf[11];
sprintf(buf, "0x%08X", len);
- setenv(var, buf);
+ env_set(var, buf);
} else
return CMD_RET_USAGE;
return 0;
if (!fdt_valid(&blob))
return CMD_RET_FAILURE;
- ret = fdt_overlay_apply(working_fdt, blob);
- if (ret) {
- printf("fdt_overlay_apply(): %s\n", fdt_strerror(ret));
+ /* apply method prints messages on error */
+ ret = fdt_overlay_apply_verbose(working_fdt, blob);
+ if (ret)
return CMD_RET_FAILURE;
- }
}
#endif
/* resize the fdt */