Re: [U-Boot] Subject: [PATCH] libfdt: Add fdt functionality for more intuitive fdt handling
On Mon, May 07, 2012 at 02:56:54PM +0200, Peter Feuerer wrote: > libfdt: Add fdt functionality for more intuitive fdt handling Hrm, "more intuitive fdt handling" is a bit of a stretch. It makes certain common operations simpler. > New functions: > fdt_read - retrieve the value of a property by full path > fdt_write - create or change a property with full path and create subnodes if > needed I don't love these names (too vague). fdt_{get,set}prop_global() perhaps. > fdt_create_path - create subnode path with parents > > Signed-off-by: Peter Feuerer > CC: David Gibson > CC: Gerald Van Baren > > --- > include/libfdt.h | 93 > lib/libfdt/fdt_ro.c | 30 + > lib/libfdt/fdt_rw.c | 97 > ++ > lib/libfdt/libfdt_internal.h |4 ++ > 4 files changed, 224 insertions(+), 0 deletions(-) You're patching the core libfdt code, so you should make a patch against upstream libfdt, rather than just the u-boot embedded copy. > diff --git a/include/libfdt.h b/include/libfdt.h > index de82ed5..822ab18 100644 > --- a/include/libfdt.h > +++ b/include/libfdt.h > @@ -548,6 +548,37 @@ static inline void *fdt_getprop_w(void *fdt, int > nodeoffset, > } > > /** > + * fdt_read - retrieve the value of a property by full path > + * @fdt: pointer to the device tree blob > + * @path: string containing the absolute path of the property > + * @name: name of the property > + * @lenp: pointer to an integer variable (will be overwritten) or NULL > + * > + * fdt_getprop() retrieves a pointer to the value of the property This doesn't appear to have been updated for the new function. > + * named 'name' of the node at offset nodeoffset (this will be a > + * pointer to within the device blob itself, not a copy of the value). > + * If lenp is non-NULL, the length of the property value is also > + * returned, in the integer pointed to by lenp. > + * > + * returns: > + * pointer to the property's value > + * if lenp is non-NULL, *lenp contains the length of the property > + * value (>=0) > + * NULL, on error > + * if lenp is non-NULL, *lenp contains an error code (<0): > + * -FDT_ERR_NOTFOUND, node does not have named property > + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE > tag > + * -FDT_ERR_BADPATH, > + * -FDT_ERR_BADMAGIC, > + * -FDT_ERR_BADVERSION, > + * -FDT_ERR_BADSTATE, > + * -FDT_ERR_BADSTRUCTURE, > + * -FDT_ERR_TRUNCATED, standard meanings > + */ > +const void *fdt_read(const void *fdt, const char *path, > + const char *name, int *lenp); > + > +/** > * fdt_get_phandle - retrieve the phandle of a given node > * @fdt: pointer to the device tree blob > * @nodeoffset: structure block offset of the node > @@ -1066,6 +1097,38 @@ int fdt_set_name(void *fdt, int nodeoffset, const char > *name); > */ > int fdt_setprop(void *fdt, int nodeoffset, const char *name, > const void *val, int len); > +/** > + * fdt_write - create or change a property with full path and create > + * all subnodes to the property if needed > + * @fdt: pointer to the device tree blob > + * @path: string containing the absolute path of the property > + * @name: name of the property to change > + * @val: pointer to data to set the property value to > + * @len: length of the property value > + * > + * fdt_write() 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. Additionally it creates all parent nodes if > + * not yet existing. > + * > + * 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_write(void *fdt, const char *path, const char *name, > + const void *val, int len); > > /** > * fdt_setprop_cell - set a property to a single cell value > @@ -1204,6 +1267,36 @@ int fdt_add_subnode_namelen(void *fdt, int > parentoffset, > int fdt_add_subnode(void *fdt, int parentoffset, const char *name); > > /** > + * fdt_create_path - create subnode path with parents > + * @fdt: pointer to the device tree blob > + * @path: absolute path of subnodes to create > + * > + * fdt_create_path() creates absolute subnode path with all needed > + * parents, if they don't exist. > + * > + * This function will ins
[U-Boot] Subject: [PATCH] libfdt: Add fdt functionality for more intuitive fdt handling
libfdt: Add fdt functionality for more intuitive fdt handling New functions: fdt_read - retrieve the value of a property by full path fdt_write - create or change a property with full path and create subnodes if needed fdt_create_path - create subnode path with parents Signed-off-by: Peter Feuerer CC: David Gibson CC: Gerald Van Baren --- include/libfdt.h | 93 lib/libfdt/fdt_ro.c | 30 + lib/libfdt/fdt_rw.c | 97 ++ lib/libfdt/libfdt_internal.h |4 ++ 4 files changed, 224 insertions(+), 0 deletions(-) diff --git a/include/libfdt.h b/include/libfdt.h index de82ed5..822ab18 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -548,6 +548,37 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset, } /** + * fdt_read - retrieve the value of a property by full path + * @fdt: pointer to the device tree blob + * @path: string containing the absolute path of the property + * @name: name of the property + * @lenp: pointer to an integer variable (will be overwritten) or NULL + * + * fdt_getprop() retrieves a pointer to the value of the property + * named 'name' of the node at offset nodeoffset (this will be a + * pointer to within the device blob itself, not a copy of the value). + * If lenp is non-NULL, the length of the property value is also + * returned, in the integer pointed to by lenp. + * + * returns: + * pointer to the property's value + * if lenp is non-NULL, *lenp contains the length of the property + * value (>=0) + * NULL, on error + * if lenp is non-NULL, *lenp contains an error code (<0): + * -FDT_ERR_NOTFOUND, node does not have named property + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag + * -FDT_ERR_BADPATH, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_TRUNCATED, standard meanings + */ +const void *fdt_read(const void *fdt, const char *path, + const char *name, int *lenp); + +/** * fdt_get_phandle - retrieve the phandle of a given node * @fdt: pointer to the device tree blob * @nodeoffset: structure block offset of the node @@ -1066,6 +1097,38 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name); */ int fdt_setprop(void *fdt, int nodeoffset, const char *name, const void *val, int len); +/** + * fdt_write - create or change a property with full path and create + * all subnodes to the property if needed + * @fdt: pointer to the device tree blob + * @path: string containing the absolute path of the property + * @name: name of the property to change + * @val: pointer to data to set the property value to + * @len: length of the property value + * + * fdt_write() 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. Additionally it creates all parent nodes if + * not yet existing. + * + * 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_write(void *fdt, const char *path, const char *name, + const void *val, int len); /** * fdt_setprop_cell - set a property to a single cell value @@ -1204,6 +1267,36 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset, int fdt_add_subnode(void *fdt, int parentoffset, const char *name); /** + * fdt_create_path - create subnode path with parents + * @fdt: pointer to the device tree blob + * @path: absolute path of subnodes to create + * + * fdt_create_path() creates absolute subnode path with all needed + * parents, if they don't exist. + * + * This function will insert data into the blob, and will therefore + * change the offsets of some existing nodes. + * + * returns: + * structure block offset of the created nodeequested subnode (>=0), on success + * -FDT_ERR_NOTFOUND, if the requested subnode does not exist + * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag + * -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of + * the given name + * -FDT_ERR_NOSPACE, if there is insufficient free space in the + * blob to contain the new node + * -FDT_ERR_NOSPACE, + * -FDT_ERR_BADPATH, +