aboutsummaryrefslogtreecommitdiff
path: root/libfdt
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2016-07-29 11:55:48 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2016-08-01 13:34:39 +1000
commitd877364e4a0f405ef24df7f4d50065c586207f5b (patch)
treec5658803023668d2169180003d6d734aec128135 /libfdt
parent3e9037aaad44de3008ad77e4549962473ed71c6d (diff)
downloaddtc-d877364e4a0f405ef24df7f4d50065c586207f5b.zip
dtc-d877364e4a0f405ef24df7f4d50065c586207f5b.tar.gz
dtc-d877364e4a0f405ef24df7f4d50065c586207f5b.tar.bz2
libfdt: Add fdt_setprop_inplace_namelen_partial
Add a function to modify inplace only a portion of a property.. This is especially useful when the property is an array of values, and you want to update one of them without changing the DT size. Acked-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> [dwg: Remove unnecessary unsigned qualifier, correct a comment] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt')
-rw-r--r--libfdt/fdt_wip.c29
-rw-r--r--libfdt/libfdt.h21
2 files changed, 46 insertions, 4 deletions
diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c
index c5bbb68..6aaab39 100644
--- a/libfdt/fdt_wip.c
+++ b/libfdt/fdt_wip.c
@@ -55,21 +55,42 @@
#include "libfdt_internal.h"
+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;
+
+ if (proplen < (len + idx))
+ return -FDT_ERR_NOSPACE;
+
+ memcpy((char *)propval + idx, val, len);
+ return 0;
+}
+
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
const void *val, int len)
{
- void *propval;
+ const void *propval;
int proplen;
- propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen);
+ propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
if (! propval)
return proplen;
if (proplen != len)
return -FDT_ERR_NOSPACE;
- memcpy(propval, val, len);
- return 0;
+ return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
+ strlen(name), 0,
+ val, len);
}
static void _fdt_nop_region(void *start, int len)
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 0189350..376e628 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -1080,6 +1080,27 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
/**********************************************************************/
/**
+ * fdt_setprop_inplace_namelen_partial - change a property's value,
+ * but not its size
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to change
+ * @name: name of the property to change
+ * @namelen: number of characters of name to consider
+ * @idx: index of the property to change in the array
+ * @val: pointer to data to replace the property value with
+ * @len: length of the property value
+ *
+ * Identical to fdt_setprop_inplace(), but modifies the given property
+ * starting from the given index, and using only the first characters
+ * of the name. It is useful when you want to manipulate only one value of
+ * an array and you have a string that doesn't end with \0.
+ */
+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
+ const char *name, int namelen,
+ uint32_t idx, const void *val,
+ int len);
+
+/**
* fdt_setprop_inplace - change a property's value, but not its size
* @fdt: pointer to the device tree blob
* @nodeoffset: offset of the node whose property to change