mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
libfdt: Add fdt_setprop_namelen()
Allow specifying name length in setprop similar to `fdt_get_property_namelen` functions. Signed-off-by: Ayush Singh <ayush@beagleboard.org> Message-ID: <20241205-setprop-namelen-v2-3-0d85a3d2e7b1@beagleboard.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
0f69cedc08
commit
bdca861200
3 changed files with 103 additions and 21 deletions
|
@ -124,31 +124,33 @@ static int fdt_splice_string_(void *fdt, int newlen)
|
||||||
* allocated. Ignored if can_assume(NO_ROLLBACK)
|
* allocated. Ignored if can_assume(NO_ROLLBACK)
|
||||||
* @return offset of string in the string table (whether found or added)
|
* @return offset of string in the string table (whether found or added)
|
||||||
*/
|
*/
|
||||||
static int fdt_find_add_string_(void *fdt, const char *s, int *allocated)
|
static int fdt_find_add_string_(void *fdt, const char *s, int slen,
|
||||||
|
int *allocated)
|
||||||
{
|
{
|
||||||
char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
|
char *strtab = (char *)fdt + fdt_off_dt_strings(fdt);
|
||||||
const char *p;
|
const char *p;
|
||||||
char *new;
|
char *new;
|
||||||
int len = strlen(s) + 1;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!can_assume(NO_ROLLBACK))
|
if (!can_assume(NO_ROLLBACK))
|
||||||
*allocated = 0;
|
*allocated = 0;
|
||||||
|
|
||||||
p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s);
|
p = fdt_find_string_len_(strtab, fdt_size_dt_strings(fdt), s, slen);
|
||||||
if (p)
|
if (p)
|
||||||
/* found it */
|
/* found it */
|
||||||
return (p - strtab);
|
return (p - strtab);
|
||||||
|
|
||||||
new = strtab + fdt_size_dt_strings(fdt);
|
new = strtab + fdt_size_dt_strings(fdt);
|
||||||
err = fdt_splice_string_(fdt, len);
|
err = fdt_splice_string_(fdt, slen + 1);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (!can_assume(NO_ROLLBACK))
|
if (!can_assume(NO_ROLLBACK))
|
||||||
*allocated = 1;
|
*allocated = 1;
|
||||||
|
|
||||||
memcpy(new, s, len);
|
memcpy(new, s, slen);
|
||||||
|
new[slen] = '\0';
|
||||||
|
|
||||||
return (new - strtab);
|
return (new - strtab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,13 +183,15 @@ int fdt_del_mem_rsv(void *fdt, int n)
|
||||||
return fdt_splice_mem_rsv_(fdt, re, 1, 0);
|
return fdt_splice_mem_rsv_(fdt, re, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name,
|
static int fdt_resize_property_(void *fdt, int nodeoffset,
|
||||||
|
const char *name, int namelen,
|
||||||
int len, struct fdt_property **prop)
|
int len, struct fdt_property **prop)
|
||||||
{
|
{
|
||||||
int oldlen;
|
int oldlen;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
*prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
|
*prop = fdt_get_property_namelen_w(fdt, nodeoffset, name, namelen,
|
||||||
|
&oldlen);
|
||||||
if (!*prop)
|
if (!*prop)
|
||||||
return oldlen;
|
return oldlen;
|
||||||
|
|
||||||
|
@ -200,7 +204,7 @@ static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
|
static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
|
||||||
int len, struct fdt_property **prop)
|
int namelen, int len, struct fdt_property **prop)
|
||||||
{
|
{
|
||||||
int proplen;
|
int proplen;
|
||||||
int nextoffset;
|
int nextoffset;
|
||||||
|
@ -211,7 +215,7 @@ static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,
|
||||||
if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
|
if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0)
|
||||||
return nextoffset;
|
return nextoffset;
|
||||||
|
|
||||||
namestroff = fdt_find_add_string_(fdt, name, &allocated);
|
namestroff = fdt_find_add_string_(fdt, name, namelen, &allocated);
|
||||||
if (namestroff < 0)
|
if (namestroff < 0)
|
||||||
return namestroff;
|
return namestroff;
|
||||||
|
|
||||||
|
@ -255,17 +259,18 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
|
||||||
int len, void **prop_data)
|
int namelen, int len, void **prop_data)
|
||||||
{
|
{
|
||||||
struct fdt_property *prop;
|
struct fdt_property *prop;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
FDT_RW_PROBE(fdt);
|
FDT_RW_PROBE(fdt);
|
||||||
|
|
||||||
err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop);
|
err = fdt_resize_property_(fdt, nodeoffset, name, namelen, len, &prop);
|
||||||
if (err == -FDT_ERR_NOTFOUND)
|
if (err == -FDT_ERR_NOTFOUND)
|
||||||
err = fdt_add_property_(fdt, nodeoffset, name, len, &prop);
|
err = fdt_add_property_(fdt, nodeoffset, name, namelen, len,
|
||||||
|
&prop);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -273,13 +278,14 @@ int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
|
||||||
const void *val, int len)
|
int namelen, const void *val, int len)
|
||||||
{
|
{
|
||||||
void *prop_data;
|
void *prop_data;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data);
|
err = fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, namelen,
|
||||||
|
len, &prop_data);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -307,7 +313,8 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
|
||||||
prop->len = cpu_to_fdt32(newlen);
|
prop->len = cpu_to_fdt32(newlen);
|
||||||
memcpy(prop->data + oldlen, val, len);
|
memcpy(prop->data + oldlen, val, len);
|
||||||
} else {
|
} else {
|
||||||
err = fdt_add_property_(fdt, nodeoffset, name, len, &prop);
|
err = fdt_add_property_(fdt, nodeoffset, name, strlen(name),
|
||||||
|
len, &prop);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
memcpy(prop->data, val, len);
|
memcpy(prop->data, val, len);
|
||||||
|
|
|
@ -1666,6 +1666,38 @@ int fdt_del_mem_rsv(void *fdt, int n);
|
||||||
*/
|
*/
|
||||||
int fdt_set_name(void *fdt, int nodeoffset, const char *name);
|
int fdt_set_name(void *fdt, int nodeoffset, const char *name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fdt_setprop_namelen - create or change a property
|
||||||
|
* @fdt: pointer to the device tree blob
|
||||||
|
* @nodeoffset: offset of the node whose property to change
|
||||||
|
* @name: name of the property to change
|
||||||
|
* @namelen: length of the name
|
||||||
|
* @val: pointer to data to set the property value to
|
||||||
|
* @len: length of the property value
|
||||||
|
*
|
||||||
|
* fdt_setprop_namelen() sets the value of the named property in the given
|
||||||
|
* node to the given value and length, creating the property if it
|
||||||
|
* does not already exist.
|
||||||
|
*
|
||||||
|
* This function may insert or delete data from the blob, and will
|
||||||
|
* therefore change the offsets of some existing nodes.
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* 0, on success
|
||||||
|
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||||
|
* contain the new property value
|
||||||
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_BADMAGIC,
|
||||||
|
* -FDT_ERR_BADVERSION,
|
||||||
|
* -FDT_ERR_BADSTATE,
|
||||||
|
* -FDT_ERR_BADSTRUCTURE,
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_TRUNCATED, standard meanings
|
||||||
|
*/
|
||||||
|
int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name,
|
||||||
|
int namelen, const void *val, int len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_setprop - create or change a property
|
* fdt_setprop - create or change a property
|
||||||
* @fdt: pointer to the device tree blob
|
* @fdt: pointer to the device tree blob
|
||||||
|
@ -1694,8 +1726,44 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name);
|
||||||
* -FDT_ERR_BADLAYOUT,
|
* -FDT_ERR_BADLAYOUT,
|
||||||
* -FDT_ERR_TRUNCATED, standard meanings
|
* -FDT_ERR_TRUNCATED, standard meanings
|
||||||
*/
|
*/
|
||||||
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
static inline int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||||
const void *val, int len);
|
const void *val, int len)
|
||||||
|
{
|
||||||
|
return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val,
|
||||||
|
len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fdt_setprop_placeholder_namelen - allocate space for a property
|
||||||
|
* @fdt: pointer to the device tree blob
|
||||||
|
* @nodeoffset: offset of the node whose property to change
|
||||||
|
* @name: name of the property to change
|
||||||
|
* @namelen: length of the name
|
||||||
|
* @len: length of the property value
|
||||||
|
* @prop_data: return pointer to property data
|
||||||
|
*
|
||||||
|
* fdt_setprop_placeholder_namelen() allocates the named property in the given node.
|
||||||
|
* If the property exists it is resized. In either case a pointer to the
|
||||||
|
* property data is returned.
|
||||||
|
*
|
||||||
|
* This function may insert or delete data from the blob, and will
|
||||||
|
* therefore change the offsets of some existing nodes.
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* 0, on success
|
||||||
|
* -FDT_ERR_NOSPACE, there is insufficient free space in the blob to
|
||||||
|
* contain the new property value
|
||||||
|
* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_BADMAGIC,
|
||||||
|
* -FDT_ERR_BADVERSION,
|
||||||
|
* -FDT_ERR_BADSTATE,
|
||||||
|
* -FDT_ERR_BADSTRUCTURE,
|
||||||
|
* -FDT_ERR_BADLAYOUT,
|
||||||
|
* -FDT_ERR_TRUNCATED, standard meanings
|
||||||
|
*/
|
||||||
|
int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name,
|
||||||
|
int namelen, int len, void **prop_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_setprop_placeholder - allocate space for a property
|
* fdt_setprop_placeholder - allocate space for a property
|
||||||
|
@ -1725,8 +1793,13 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,
|
||||||
* -FDT_ERR_BADLAYOUT,
|
* -FDT_ERR_BADLAYOUT,
|
||||||
* -FDT_ERR_TRUNCATED, standard meanings
|
* -FDT_ERR_TRUNCATED, standard meanings
|
||||||
*/
|
*/
|
||||||
int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
|
static inline int fdt_setprop_placeholder(void *fdt, int nodeoffset,
|
||||||
int len, void **prop_data);
|
const char *name, int len,
|
||||||
|
void **prop_data)
|
||||||
|
{
|
||||||
|
return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name,
|
||||||
|
strlen(name), len, prop_data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_setprop_u32 - set a property to a 32-bit integer
|
* fdt_setprop_u32 - set a property to a 32-bit integer
|
||||||
|
|
|
@ -43,6 +43,7 @@ LIBFDT_1.2 {
|
||||||
fdt_add_mem_rsv;
|
fdt_add_mem_rsv;
|
||||||
fdt_del_mem_rsv;
|
fdt_del_mem_rsv;
|
||||||
fdt_set_name;
|
fdt_set_name;
|
||||||
|
fdt_setprop_namelen;
|
||||||
fdt_setprop;
|
fdt_setprop;
|
||||||
fdt_delprop;
|
fdt_delprop;
|
||||||
fdt_add_subnode_namelen;
|
fdt_add_subnode_namelen;
|
||||||
|
@ -71,6 +72,7 @@ LIBFDT_1.2 {
|
||||||
fdt_find_max_phandle;
|
fdt_find_max_phandle;
|
||||||
fdt_generate_phandle;
|
fdt_generate_phandle;
|
||||||
fdt_check_full;
|
fdt_check_full;
|
||||||
|
fdt_setprop_placeholder_namelen;
|
||||||
fdt_setprop_placeholder;
|
fdt_setprop_placeholder;
|
||||||
fdt_property_placeholder;
|
fdt_property_placeholder;
|
||||||
fdt_header_size_;
|
fdt_header_size_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue