Skip to contentSkip to conversation

dtc: Implement path references

PATCH Applied David Gibson 2 participants 2 messages Dec 4, 2007 – Dec 5, 2007

lore
Share & tools
lore
#0 lore raw

This patch extends dtc syntax to allow references (&label, or &{/full/path}) directly within property definitions, rather than inside a cell list. Such references are expanded to the full path of the referenced node, as a string, instead of to a phandle as references within cell lists are evaluated.

A testcase is also included.

tests/run_tests.sh +3 -0
Index: dtc/tests/run_tests.sh
===================================================================
@@ -148,6 +148,9 @@
     run_test dtc.sh -I dts -O dtb -o dtc_references_dts0.test.dtb references_dts0.dts
     run_test references dtc_references_dts0.test.dtb
 
+    run_test dtc.sh -I dts -O dtb -o dtc_path-references.test.dtb path-references.dts
+    run_test path-references dtc_path-references.test.dtb
+
     # Check -Odts mode preserve all dtb information
     for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb ; do
 	run_test dtc.sh -I dtb -O dts -o odts_$tree.test.dts $tree
dtc-parser.y +4 -0
Index: dtc/dtc-parser.y
===================================================================
@@ -192,6 +192,10 @@
 		{
 			$$ = data_merge($1, $3);
 		}
+	| propdataprefix DT_REF
+	  	{
+			$$ = data_add_marker($1, REF_PATH, $2);
+		}
 	| propdata DT_LABEL
 		{
 			$$ = data_add_marker($1, LABEL, $2);
dtc.h +3 -0
Index: dtc/dtc.h
===================================================================
@@ -104,6 +104,7 @@
 /* Data blobs */
 enum markertype {
 	REF_PHANDLE,
+	REF_PATH,
 	LABEL,
 };
 
@@ -139,6 +140,8 @@
 struct data data_copy_file(FILE *f, size_t len);
 
 struct data data_append_data(struct data d, const void *p, int len);
+struct data data_insert_at_marker(struct data d, struct marker *m,
+				  const void *p, int len);
 struct data data_merge(struct data d1, struct data d2);
 struct data data_append_cell(struct data d, cell_t word);
 struct data data_append_re(struct data d, const struct fdt_reserve_entry *re);
tests/Makefile.tests +1 -1
Index: dtc/tests/Makefile.tests
===================================================================
@@ -9,7 +9,7 @@
 	sw_tree1 \
 	move_and_save mangle-layout \
 	open_pack rw_tree1 setprop del_property del_node \
-	string_escapes references \
+	string_escapes references path-references \
 	dtbs_equal_ordered
 LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
 
tests/path-references.c new file +83 -0

83 lines not on this page · raw message

tests/path-references.dts new file +14 -0
Index: dtc/tests/path-references.dts
===================================================================
@@ -0,0 +1,14 @@
+/dts-v1/;
+
+/ {
+	/* Check multiple references case */
+	multiref = &n1 , &n2;
+	n1: node1 {
+		ref = &{/node2}; /* reference precedes target */
+		lref = &n2;
+	};
+	n2: node2 {
+		ref = &{/node1}; /* reference after target */
+		lref = &n1;
+	};
+};
data.c +15 -0
Index: dtc/data.c
===================================================================
@@ -202,6 +202,21 @@
 	return d;
 }
 
+struct data data_insert_at_marker(struct data d, struct marker *m,
+				  const void *p, int len)
+{
+	d = data_grow_for(d, len);
+	memmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset);
+	memcpy(d.val + m->offset, p, len);
+	d.len += len;
+
+	/* Adjust all markers after the one we're inserting at */
+	m = m->next;
+	for_each_marker(m)
+		m->offset += len;
+	return d;
+}
+
 struct data data_append_markers(struct data d, struct marker *m)
 {
 	struct marker **mp = &d.markers;
checks.c +26 -1
Index: dtc/checks.c
===================================================================
@@ -302,11 +302,36 @@
 CHECK(phandle_references, NULL, NULL, fixup_phandle_references, NULL, ERROR,
       &duplicate_node_names, &explicit_phandles);
 
+static void fixup_path_references(struct check *c, struct node *dt,
+				  struct node *node, struct property *prop)
+{
+	struct marker *m = prop->val.markers;
+	struct node *refnode;
+	char *path;
+
+	for_each_marker_of_type(m, REF_PATH) {
+		assert(m->offset <= prop->val.len);
+
+		refnode = get_node_by_ref(dt, m->ref);
+		if (!refnode) {
+			FAIL(c, "Reference to non-existent node or label \"%s\"\n",
+			     m->ref);
+			continue;
+		}
+
+		path = refnode->fullpath;
+		prop->val = data_insert_at_marker(prop->val, m, path,
+						  strlen(path) + 1);
+	}
+}
+CHECK(path_references, NULL, NULL, fixup_path_references, NULL, ERROR,
+      &duplicate_node_names);
+
 static struct check *check_table[] = {
 	&duplicate_node_names, &duplicate_property_names,
 	&name_is_string, &name_properties,
 	&explicit_phandles,
-	&phandle_references,
+	&phandle_references, &path_references,
 };
 
 int check_semantics(struct node *dt, int outversion, int boot_cpuid_phys);
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
Applied
#1 lore raw

So, like, the other day David Gibson mumbled:

Quoted 9 lines

This patch extends dtc syntax to allow references (&label, or &{/full/path}) directly within property definitions, rather than inside a cell list. Such references are expanded to the full path of the referenced node, as a string, instead of to a phandle as references within cell lists are evaluated.

A testcase is also included.

Excellent. Very timely! :-)

Applied.

jdl