2019-06-20 23:19:39 +02:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
|
2006-11-27 06:21:28 +01:00
|
|
|
/*
|
|
|
|
* libfdt - Flat Device Tree manipulation
|
|
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
|
|
*/
|
|
|
|
#include "libfdt_env.h"
|
|
|
|
|
|
|
|
#include <fdt.h>
|
|
|
|
#include <libfdt.h>
|
|
|
|
|
|
|
|
#include "libfdt_internal.h"
|
|
|
|
|
2016-07-29 11:55:48 +02:00
|
|
|
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
|
|
|
|
const char *name, int namelen,
|
|
|
|
uint32_t idx, const void *val,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
void *propval;
|
|
|
|
int proplen;
|
|
|
|
|
|
|
|
propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
|
|
|
|
&proplen);
|
|
|
|
if (!propval)
|
|
|
|
return proplen;
|
|
|
|
|
2020-10-01 18:46:28 +02:00
|
|
|
if ((unsigned)proplen < (len + idx))
|
2016-07-29 11:55:48 +02:00
|
|
|
return -FDT_ERR_NOSPACE;
|
|
|
|
|
|
|
|
memcpy((char *)propval + idx, val, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
|
2006-11-27 06:21:28 +01:00
|
|
|
const void *val, int len)
|
|
|
|
{
|
2016-07-29 11:55:48 +02:00
|
|
|
const void *propval;
|
2006-11-27 06:21:28 +01:00
|
|
|
int proplen;
|
|
|
|
|
2016-07-29 11:55:48 +02:00
|
|
|
propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
|
2017-04-08 18:14:42 +02:00
|
|
|
if (!propval)
|
2006-12-15 05:12:51 +01:00
|
|
|
return proplen;
|
2006-11-27 06:21:28 +01:00
|
|
|
|
|
|
|
if (proplen != len)
|
2006-12-15 05:12:52 +01:00
|
|
|
return -FDT_ERR_NOSPACE;
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2016-07-29 11:55:48 +02:00
|
|
|
return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
|
|
|
|
strlen(name), 0,
|
|
|
|
val, len);
|
2006-11-27 06:21:28 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
static void fdt_nop_region_(void *start, int len)
|
2006-11-27 06:21:28 +01:00
|
|
|
{
|
2012-11-14 01:34:30 +01:00
|
|
|
fdt32_t *p;
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2008-07-07 02:10:48 +02:00
|
|
|
for (p = start; (char *)p < ((char *)start + len); p++)
|
2006-12-04 02:52:45 +01:00
|
|
|
*p = cpu_to_fdt32(FDT_NOP);
|
2006-11-27 06:21:28 +01:00
|
|
|
}
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
|
2006-11-27 06:21:28 +01:00
|
|
|
{
|
|
|
|
struct fdt_property *prop;
|
|
|
|
int len;
|
|
|
|
|
2007-06-13 06:18:10 +02:00
|
|
|
prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
|
2017-04-08 18:14:42 +02:00
|
|
|
if (!prop)
|
2006-12-15 05:12:51 +01:00
|
|
|
return len;
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
fdt_nop_region_(prop, len + sizeof(*prop));
|
2006-11-27 06:21:28 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
int fdt_node_end_offset_(void *fdt, int offset)
|
2006-11-27 06:21:28 +01:00
|
|
|
{
|
2009-02-06 04:01:56 +01:00
|
|
|
int depth = 0;
|
|
|
|
|
|
|
|
while ((offset >= 0) && (depth >= 0))
|
|
|
|
offset = fdt_next_node(fdt, offset, &depth);
|
|
|
|
|
|
|
|
return offset;
|
2006-12-01 06:59:43 +01:00
|
|
|
}
|
2006-11-27 06:21:28 +01:00
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
int fdt_nop_node(void *fdt, int nodeoffset)
|
2006-12-01 06:59:43 +01:00
|
|
|
{
|
|
|
|
int endoffset;
|
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
endoffset = fdt_node_end_offset_(fdt, nodeoffset);
|
2006-12-15 05:12:51 +01:00
|
|
|
if (endoffset < 0)
|
|
|
|
return endoffset;
|
2006-12-01 06:59:43 +01:00
|
|
|
|
2017-10-18 08:22:40 +02:00
|
|
|
fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
|
2008-07-09 06:10:24 +02:00
|
|
|
endoffset - nodeoffset);
|
2006-12-01 06:59:43 +01:00
|
|
|
return 0;
|
2006-11-27 06:21:28 +01:00
|
|
|
}
|