libfdt: Add fdt_set_name() function
This patch adds an fdt_set_name() function to libfdt, mirroring fdt_get_name(). This is a r/w function which alters the name of a given device tree node.
libfdt/libfdt.h +26 -0
@@ -846,6 +846,32 @@ int fdt_add_mem_rsv(void *fdt, uint64_tint fdt_del_mem_rsv (void *fdt,int n);/** +* fdt_set_name - change the name of a given node +* @fdt: pointer to the device tree blob +* @nodeoffset: structure block offset of a node +* @name: name to give the node +* +* fdt_set_name() replaces the name (including unit address, if any) +* of the given node with the given string. NOTE: this function can't +* efficiently check if the new name is unique amongst the given +* node's siblings; results are undefined if this function is invoked +* with a name equal to one of the given node's siblings. +* +* 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 name +* -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag +* -FDT_ERR_BADMAGIC, +* -FDT_ERR_BADVERSION, +* -FDT_ERR_BADSTATE, standard meanings +*/ +int fdt_set_name (void *fdt,int nodeoffset,const char *name); + +/** * fdt_setprop - create or change a property * @fdt: pointer to the device tree blob * @nodeoffset: offset of the node whose property to change
libfdt/fdt_rw.c +24 -0
@@ -252,6 +252,30 @@ static int _add_property(void *fdt, intreturn 0 ; } +int fdt_set_name (void *fdt,int nodeoffset,const char *name) +{ +char *namep; +int oldlen, newlen; +int err; + +if ((err =rw_check_header (fdt))) +return err; + + namep = (char *)fdt_get_name (fdt, nodeoffset, &oldlen); +if (!namep) +return oldlen; + + newlen =strlen (name); + + err =_blob_splice_struct (fdt, namep,ALIGN (oldlen+1 ,FDT_TAGSIZE ), +ALIGN (newlen+1 ,FDT_TAGSIZE )); +if (err) +return err; + +memcpy (namep, name, newlen+1 ); +return 0 ; +} +int fdt_setprop (void *fdt,int nodeoffset,const char *name,const void *val,int len) {
tests/Makefile.tests +1 -1
@@ -8,7 +8,7 @@ LIB_TESTS_L = get_mem_rsv \ setprop_inplace nop_property nop_node \ sw_tree1 \ move_and_save mangle-layout \ - open_pack rw_tree1 setprop del_property del_node \ + open_pack rw_tree1 set_name setprop del_property del_node \ string_escapes references path-references \ dtbs_equal_ordered LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
tests/set_name.c new file +91 -0
91 lines not on this page · raw message
tests/run_tests.sh +1 -0
@@ -69,6 +69,7 @@ tree1_tests_rw () { TREE=$1 # Read-write tests + run_test set_name $TREE run_test setprop $TREE run_test del_property $TREE run_test del_node $TREE
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Jon Loeliger
AppliedSo, like, the other day David Gibson mumbled:
Quoted 5 lines
This patch adds an
fdt_set_name()function to libfdt, mirroringfdt_get_name(). This is a r/w function which alters the name of a given device tree node.Signed-off-by David Gibson <[email protected]>
Applied.
jdl
Quoted 8 lines · On Fri, 11 Jan 2008 07:44:33 -0600 Jon Loeliger <[email protected]> wrote:
So, like, the other day David Gibson mumbled:
Quoted 5 lines
This patch adds an
fdt_set_name()function to libfdt, mirroringfdt_get_name(). This is a r/w function which alters the name of a given device tree node.Signed-off-by David Gibson <[email protected]>Applied.
Awesome. Now if we could just get that into the kernel and usable in the wrappers... :)
josh
So, like, the other day Josh Boyer mumbled:
Quoted 8 lines
Quoted 5 lines · On Fri, 11 Jan 2008 07:44:33 -0600 Jon Loeliger <[email protected]> wrote:
So, like, the other day David Gibson mumbled:
Quoted 4 lines
This patch adds an
fdt_set_name()function to libfdt, mirroringfdt_get_name(). This is a r/w function which alters the name of a given device tree node.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by David Gibson <[email protected]>Applied.
Awesome. Now if we could just get that into the kernel and usable in the wrappers... :)
I've pushed it out now.
I guess we'll try to get the real v1.1.0 into the kernel then? Maybe at 2.6.25?
jdl