Skip to contentSkip to conversation

libfdt: Add support for appending the values to a existing property

PATCH Applied David Gibson 2 participants 3 messages Dec 5, 2011 – Dec 6, 2011 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

From: Minghuan Lian <[email protected]>

Some properties may contain multiple values, these values may need to be added to the property respectively. this patch provides this functionality. The main purpose of fdt_append_prop() is to append the values to a existing property, or create a new property if it dose not exist.

---

Jon,

Minghuan Lian sent this to the list ages ago, but it got stuck for months in a mailing list mishap. It more recently resurfaced, I made some small cleanups and added testcases. Please apply.

libfdt/fdt_rw.c +27 -0
Index: dtc/libfdt/fdt_rw.c
===================================================================
@@ -289,6 +289,33 @@ int fdt_setprop(void *fdt, int nodeoffse
 	return 0;
 }
 
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
+		   const void *val, int len)
+{
+	struct fdt_property *prop;
+	int err, oldlen, newlen;
+
+	FDT_RW_CHECK_HEADER(fdt);
+
+	prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
+	if (prop) {
+		newlen = len + oldlen;
+		err = _fdt_splice_struct(fdt, prop->data,
+					 FDT_TAGALIGN(oldlen),
+					 FDT_TAGALIGN(newlen));
+		if (err)
+			return err;
+		prop->len = cpu_to_fdt32(newlen);
+		memcpy(prop->data + oldlen, val, len);
+	} else {
+		err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
+		if (err)
+			return err;
+		memcpy(prop->data, val, len);
+	}
+	return 0;
+}
+
 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
 {
 	struct fdt_property *prop;
libfdt/libfdt.h +95 -0

101 lines not on this page · raw message

tests/appendprop1.c new file +70 -0

70 lines not on this page · raw message

tests/appendprop.dts new file +7 -0
Index: dtc/tests/appendprop.dts
===================================================================
@@ -0,0 +1,7 @@
+/dts-v1/;
+
+/ {
+	prop-str = "hello world", "nastystring: \a\b\t\n\v\f\r\\\"";
+	prop-int = <0xdeadbeef 123456789>;
+	prop-bytes = [00010203040001020304];
+};
tests/appendprop2.c new file +64 -0

64 lines not on this page · raw message

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

A message that is not in the archive (sent off-list or not yet received): 20111205012207.GA3734-MK4v0fQdeXQXU02nzanrWNbf9cGiqdzd@public.gmane.org

Applied
#2 lore raw
Quoted 10 lines

From: Minghuan Lian <[email protected]>

Some properties may contain multiple values, these values may need to be added to the property respectively. this patch provides this functionality. The main purpose of fdt_append_prop() is to append the values to a existing property, or create a new property if it dose not exist.

Quoted 7 lines

---

Jon,

Minghuan Lian sent this to the list ages ago, but it got stuck for months in a mailing list mishap. It more recently resurfaced, I made some small cleanups and added testcases. Please apply.

Ooo, sorry. So, yeah...

Applied.

Thanks,
jdl

A message that is not in the archive (sent off-list or not yet received): E1RXbId-0003zK-SS-CYoMK+44s/[email protected]

#4 lore raw
Quoted 14 lines · Jon Loeliger
Quoted 14 lines

From: Minghuan Lian <[email protected]>

Some properties may contain multiple values, these values may need to be added to the property respectively. this patch provides this functionality. The main purpose of fdt_append_prop() is to append the values to a existing property, or create a new property if it dose not exist.

---

Jon,

Quoted 7 lines
Quoted 3 lines

Minghuan Lian sent this to the list ages ago, but it got stuck for months in a mailing list mishap. It more recently resurfaced, I made some small cleanups and added testcases. Please apply.

Ooo, sorry. So, yeah...

Applied.

Thanks.

But, apparently I've been using git so much lately, I've forgotten how to use quilt :(. Seems I left out the updates to the tests makefile and script:

tests/Makefile.tests +1 -0
index 215a8c5..3f92074 100644
@@ -12,6 +12,7 @@ LIB_TESTS_L = get_mem_rsv \
 	sw_tree1 \
 	move_and_save mangle-layout nopulate \
 	open_pack rw_tree1 set_name setprop del_property del_node \
+	appendprop1 appendprop2 \
 	string_escapes references path-references phandle_format \
 	boot-cpuid incbin \
 	extra-terminating-null \
tests/run_tests.sh +4 -0
index da6f970..c72b9d2 100755
@@ -178,6 +178,10 @@ libfdt_tests () {
     run_test rw_tree1
     tree1_tests rw_tree1.test.dtb
     tree1_tests_rw rw_tree1.test.dtb
+    run_test appendprop1
+    run_test appendprop2 appendprop1.test.dtb
+    run_dtc_test -I dts -O dtb -o appendprop.test.dtb appendprop.dts
+    run_test dtbs_equal_ordered appendprop2.test.dtb appendprop.test.dtb
 
     for basetree in test_tree1.dtb sw_tree1.test.dtb rw_tree1.test.dtb; do
 	run_test nopulate $basetree
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