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.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Maxime Ripard 2016-07-05 10:26:43 +02:00 committed by Alexandre Bard
parent 7436c8dedb
commit b5db892f31
2 changed files with 47 additions and 5 deletions

View File

@ -1039,6 +1039,27 @@ int fdt_size_cells(const void *fdt, int nodeoffset);
/* Write-in-place functions */ /* Write-in-place functions */
/**********************************************************************/ /**********************************************************************/
/**
* 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
* @index: 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 index, const void *val,
int len);
/** /**
* fdt_setprop_inplace - change a property's value, but not its size * fdt_setprop_inplace - change a property's value, but not its size
* @fdt: pointer to the device tree blob * @fdt: pointer to the device tree blob

View File

@ -14,21 +14,42 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
const void *val, int len) const char *name, int namelen,
uint32_t index, const void *val,
int len)
{ {
void *propval; void *propval;
int proplen; int proplen;
propval = fdt_getprop_w(fdt, nodeoffset, name, &proplen); propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
&proplen);
if (!propval)
return proplen;
if (proplen < (len + index))
return -FDT_ERR_NOSPACE;
memcpy(propval + index, val, len);
return 0;
}
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
const void *val, int len)
{
const void *propval;
int proplen;
propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
if (!propval) if (!propval)
return proplen; return proplen;
if (proplen != len) if (proplen != len)
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
memcpy(propval, val, len); return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
return 0; strlen(name), 0,
val, len);
} }
static void _fdt_nop_region(void *start, int len) static void _fdt_nop_region(void *start, int len)