From: Fabien Parent <[email protected]>
Sometimes one may want a property to be required but the property could be
defined in a particular node or it could be defined in any of its parents node.
The concept of property inheritence has been added to fill this need. One can
specify that a property must be present in a node or in any of its parents by
using the constraint 'can-be-inherited' in addition to 'is-required'.
Add as well two test files for this feature.
twl {
interrupt-controller;
rtc {
compatible = "ti,twl4030-rtc";
interrupts = <0xc>;
};
}
In the case of the rtc above the interrupt-controller is not present,
but it is present in its parent. If inheriting the property from the parent
makes senses like here one can specify in the schema that interrupt-controller
is required in the rtc node and that the property can be inherited
from a parent.
/dts-v1/;
/ {
compatible = "ti,twl[0-9]+-rtc";
interrupt-controller {
is-required;
can-be-inherited;
};
};
Signed-off-by: Fabien Parent <[email protected]>
Signed-off-by: Benoit Cousson <[email protected]>
---
scripts/dtc/schema-test.c | 6 ++++++
scripts/dtc/schema.c | 15 +++++++++++++--
scripts/dtc/tests/schemas/inheritence-1.schema | 7 +++++++
scripts/dtc/tests/schemas/inheritence-2.schema | 8 ++++++++
scripts/dtc/tests/test1.dts | 4 ++++
5 files changed, 38 insertions(+), 2 deletions(-)
create mode 100644 scripts/dtc/tests/schemas/inheritence-1.schema
create mode 100644 scripts/dtc/tests/schemas/inheritence-2.schema
diff --git a/scripts/dtc/schema-test.c b/scripts/dtc/schema-test.c
index 8ac4f58..99a4142 100644
--- a/scripts/dtc/schema-test.c
+++ b/scripts/dtc/schema-test.c
@@ -24,6 +24,12 @@ static struct schema_test tests[] = {
{"Required Property #2", "tests/test1.dts",
"tests/schemas/required-property-2.schema", 1},
+ /* Inheritence */
+ {"Required Property Inheritence #1", "tests/test1.dts",
+ "tests/schemas/inheritence-1.schema", 0},
+ {"Required Property Inheritence #2", "tests/test1.dts",
+ "tests/schemas/inheritence-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 97ea5b0..95fc44b 100644
--- a/scripts/dtc/schema.c
+++ b/scripts/dtc/schema.c
@@ -35,6 +35,7 @@ struct prop_constraints {
const char *name;
char *type;
int is_required;
+ int can_be_inherited;
};
struct node_constraints {
@@ -201,6 +202,7 @@ load_property_constraints(struct node *schema)
memset(pc, 0, sizeof(*pc));
pc->is_required = get_property(schema, "is-required") != NULL;
+ pc->can_be_inherited = get_property(schema, "can-be-inherited") != NULL;
p = get_property(schema, "name");
if (p)
@@ -258,8 +260,17 @@ 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 (pc->is_required && !p) {
+ if (pc->can_be_inherited && path->next) {
+ assert(path->next->n);
+ ret &= validate_properties(path->next->n,
+ schema,
+ path->next);
+ } else {
+ DT_ERROR(path, NULL, "Missing property '%s'\n",
+ schema->name);
+ }
+ }
if (!p)
goto end;
diff --git a/scripts/dtc/tests/schemas/inheritence-1.schema
b/scripts/dtc/tests/schemas/inheritence-1.schema
new file mode 100644
index 0000000..2a64ea7
--- /dev/null
+++ b/scripts/dtc/tests/schemas/inheritence-1.schema
@@ -0,0 +1,7 @@
+/dts-v1/;
+/ {
+ compatible = "compat2";
+ mypropstr {
+ is-required;
+ };
+};
diff --git a/scripts/dtc/tests/schemas/inheritence-2.schema
b/scripts/dtc/tests/schemas/inheritence-2.schema
new file mode 100644
index 0000000..3da0f64
--- /dev/null
+++ b/scripts/dtc/tests/schemas/inheritence-2.schema
@@ -0,0 +1,8 @@
+/dts-v1/;
+/ {
+ compatible = "compat2";
+ mypropstr {
+ is-required;
+ can-be-inherited;
+ };
+};
diff --git a/scripts/dtc/tests/test1.dts b/scripts/dtc/tests/test1.dts
index 9a950da..a296591 100644
--- a/scripts/dtc/tests/test1.dts
+++ b/scripts/dtc/tests/test1.dts
@@ -6,5 +6,9 @@
compatible = "compat1";
mypropint = <0 2 4 6>;
mypropstr = "value0", "value1", "value2";
+
+ subnode1 {
+ compatible = "compat2";
+ };
};
};
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html