Thread (1 message) 1 message, 1 author, 2013-09-24

[RFC 06/15] scripts/dtc: check for required properties

From: Benoit Cousson <hidden>
Date: 2013-09-24 16:52:12
Also in: linux-omap
Subsystem: open firmware and flattened device tree, the rest · Maintainers: Rob Herring, Saravana Kannan, Linus Torvalds

From: Fabien Parent <fparent-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>

Add the ability to specify inside a schema that a property is required to be
present in the validated node. By default a property can be missing but one can
require its presence inside a node via the 'is-required' property.

Add as well two test files for this feature.

timer1: timer@4a318000 {
    compatible = "ti,omap3430-timer";
    reg = <0x4a318000 0x80>;
    interrupts = <0x0 0x25 0x4>;
    ti,hwmods = "timer1";
    ti,timer-alwon;
};

To make the ti,hwmods a required property inside an omap timer, one can use the
following schema:
/dts-v1/;
/ {
    compatible = "ti,omap[0-9]+-timer";
    ti,hwmods {
        is-required;
    };
};

Signed-off-by: Fabien Parent <fparent-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
Signed-off-by: Benoit Cousson <bcousson-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
---
 scripts/dtc/schema-test.c                            | 6 ++++++
 scripts/dtc/schema.c                                 | 6 ++++++
 scripts/dtc/tests/schemas/required-property-1.schema | 7 +++++++
 scripts/dtc/tests/schemas/required-property-2.schema | 7 +++++++
 4 files changed, 26 insertions(+)
 create mode 100644 scripts/dtc/tests/schemas/required-property-1.schema
 create mode 100644 scripts/dtc/tests/schemas/required-property-2.schema
diff --git a/scripts/dtc/schema-test.c b/scripts/dtc/schema-test.c
index 57c86d0..8ac4f58 100644
--- a/scripts/dtc/schema-test.c
+++ b/scripts/dtc/schema-test.c
@@ -18,6 +18,12 @@ struct schema_test {
 };
 
 static struct schema_test tests[] = {
+	/* Required Properties */
+	{"Required Property #1", "tests/test1.dts",
+	 "tests/schemas/required-property-1.schema", 0},
+	{"Required Property #2", "tests/test1.dts",
+	 "tests/schemas/required-property-2.schema", 1},
+
 	/* Types */
 	{"Types #1", "tests/test1.dts",
 	 "tests/schemas/types-1.schema", 1},
diff --git a/scripts/dtc/schema.c b/scripts/dtc/schema.c
index c01cdee..97ea5b0 100644
--- a/scripts/dtc/schema.c
+++ b/scripts/dtc/schema.c
@@ -34,6 +34,7 @@ struct node_list {
 struct prop_constraints {
 	const char *name;
 	char *type;
+	int is_required;
 };
 
 struct node_constraints {
@@ -199,6 +200,8 @@ load_property_constraints(struct node *schema)
 	pc = xmalloc(sizeof(*pc));
 	memset(pc, 0, sizeof(*pc));
 
+	pc->is_required = get_property(schema, "is-required") != NULL;
+
 	p = get_property(schema, "name");
 	if (p)
 		pc->name = p->val.val;
@@ -255,6 +258,9 @@ static int validate_property(struct node *n,
 	assert(pc);
 	assert(path);
 
+	if (pc->is_required && !p)
+		DT_ERROR(path, NULL, "Missing property '%s'\n", schema->name);
+
 	if (!p)
 		goto end;
 
diff --git a/scripts/dtc/tests/schemas/required-property-1.schema b/scripts/dtc/tests/schemas/required-property-1.schema
new file mode 100644
index 0000000..469fa5b
--- /dev/null
+++ b/scripts/dtc/tests/schemas/required-property-1.schema
@@ -0,0 +1,7 @@
+/dts-v1/;
+/ {
+	compatible = "compat1";
+	abc {
+		is-required;
+	};
+};
diff --git a/scripts/dtc/tests/schemas/required-property-2.schema b/scripts/dtc/tests/schemas/required-property-2.schema
new file mode 100644
index 0000000..35bdde1
--- /dev/null
+++ b/scripts/dtc/tests/schemas/required-property-2.schema
@@ -0,0 +1,7 @@
+/dts-v1/;
+/ {
+	compatible = "compat1";
+	mypropstr {
+		is-required;
+	};
+};
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help