From: Benoit Cousson <bcousson@baylibre.com>
To: olof@lixom.net, devicetree@vger.kernel.org,
tomasz.figa@gmail.com, swarren@wwwdotorg.org,
grant.likely@secretlab.ca, rob.herring@calxeda.com
Cc: khilman@linaro.org, linux-omap@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, fparent@baylibre.com,
Benoit Cousson <bcousson@baylibre.com>
Subject: [RFC 07/15] scripts/dtc: can inherit properties
Date: Tue, 24 Sep 2013 18:52:13 +0200 [thread overview]
Message-ID: <1380041541-17529-8-git-send-email-bcousson@baylibre.com> (raw)
In-Reply-To: <1380041541-17529-1-git-send-email-bcousson@baylibre.com>
From: Fabien Parent <fparent@baylibre.com>
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 <fparent@baylibre.com>
Signed-off-by: Benoit Cousson <bcousson@baylibre.com>
---
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
next prev parent reply other threads:[~2013-09-24 16:52 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-24 16:52 [RFC 00/15] Device Tree schemas and validation Benoit Cousson
2013-09-24 16:52 ` [RFC 01/15] scripts/dtc: fix most memory leaks in dtc Benoit Cousson
[not found] ` <1380041541-17529-2-git-send-email-bcousson-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2013-10-02 12:59 ` David Gibson
[not found] ` <CAOwMV_zAZG3vvWS6pkyK-FbOEg_32KRO-k1SmFSh-pc9+0JiPA@mail.gmail.com>
2013-10-03 14:26 ` Fabien Parent
2013-09-24 16:52 ` [RFC 04/15] scripts/dtc: add procedure to handle dts errors Benoit Cousson
2013-09-24 16:52 ` [RFC 05/15] scripts/dtc: check type on properties Benoit Cousson
2013-09-24 16:52 ` Benoit Cousson [this message]
[not found] ` <1380041541-17529-1-git-send-email-bcousson-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2013-09-24 16:52 ` [RFC 02/15] scripts/dtc: build schema index for dts validation Benoit Cousson
2013-09-24 16:52 ` [RFC 03/15] scripts/dtc: validate each nodes and properties Benoit Cousson
2013-09-24 16:52 ` [RFC 06/15] scripts/dtc: check for required properties Benoit Cousson
2013-09-24 16:52 ` [RFC 08/15] scripts/dtc: check array size Benoit Cousson
2013-09-24 16:52 ` [RFC 09/15] scripts/dtc: check value of properties Benoit Cousson
2013-09-24 16:52 ` [RFC 10/15] scripts/dtc: add count limit on nodes Benoit Cousson
2013-10-01 22:22 ` [RFC 00/15] Device Tree schemas and validation Stephen Warren
[not found] ` <524B4B20.4020002-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-10-02 14:29 ` David Gibson
[not found] ` <20131002142914.GI6506-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2013-10-03 13:53 ` Benoit Cousson
2013-10-06 3:02 ` Chaiken, Alison
2013-10-03 13:17 ` Benoit Cousson
2013-09-24 16:52 ` [RFC 11/15] scripts/dtc: check for children nodes Benoit Cousson
2013-09-24 16:52 ` [RFC 12/15] scripts/dtc: check constraints on parents Benoit Cousson
2013-09-24 16:52 ` [RFC 13/15] bindings: OMAP: add new schema files Benoit Cousson
2013-09-24 16:52 ` [RFC 14/15] scripts/dtc: validate dts against schema bindings Benoit Cousson
2013-09-24 16:52 ` [RFC 15/15] scripts/dtc: add verbose options Benoit Cousson
2013-10-01 8:06 ` [RFC 00/15] Device Tree schemas and validation Benoit Cousson
[not found] ` <524A8289.3050107-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2013-10-01 13:17 ` Rob Herring
[not found] ` <524ACB76.1010001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-10-01 15:06 ` Benoit Cousson
2013-10-01 15:17 ` Jon Loeliger
2013-10-02 8:24 ` David Gibson
2013-10-02 9:25 ` Benoit Cousson
[not found] ` <524BE66D.7060308-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2013-10-02 13:22 ` Jon Loeliger
[not found] ` <524AE4FB.4080906-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2013-10-01 20:54 ` Rob Herring
[not found] ` <CAL_JsqJ31TGFJCSeSOqgee=OLVfSUTAYdF4nSn7X2DiCequVAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-02 13:54 ` David Gibson
2013-10-02 18:08 ` Mark Brown
2013-10-02 23:38 ` David Gibson
2013-10-03 6:52 ` Benoit Cousson
2013-10-02 13:52 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380041541-17529-8-git-send-email-bcousson@baylibre.com \
--to=bcousson@baylibre.com \
--cc=devicetree@vger.kernel.org \
--cc=fparent@baylibre.com \
--cc=grant.likely@secretlab.ca \
--cc=khilman@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=olof@lixom.net \
--cc=rob.herring@calxeda.com \
--cc=swarren@wwwdotorg.org \
--cc=tomasz.figa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).