From: Ayush Singh <ayush@beagleboard.org>
To: d-gole@ti.com, lorforlinux@beagleboard.org,
jkridner@beagleboard.org, robertcnelson@beagleboard.org,
nenad.marinkovic@mikroe.com, Andrew Davis <afd@ti.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Robert Nelson <robertcnelson@gmail.com>
Cc: devicetree-compiler@vger.kernel.org,
Ayush Singh <ayush@beagleboard.org>,
Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 1/2] dtc: Add /append-property/
Date: Fri, 30 Aug 2024 01:33:39 +0530 [thread overview]
Message-ID: <20240830-append-v2-1-ec1e03f110ad@beagleboard.org> (raw)
In-Reply-To: <20240830-append-v2-0-ec1e03f110ad@beagleboard.org>
Allow appending values to a property instead of overriding the previous
values of property.
Currently, we have /delete-node/ and /delete-property/, but lack
/append-property/. Hence we end up having to repeat all existing values
when appending to a property (e.g. see [1] appending to clocks from
[2]).
This functionality is also important for creating a device tree based
implementation to support different types of addon-boards such as
mikroBUS, Grove [3], etc.
[3] https://lore.kernel.org/linux-arm-kernel/20240702164403.29067-1-afd@ti.com/
[2] https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/renesas/r8a77951-salvator-xs.dts#L39
[1] https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/renesas/r8a77951.dtsi#L3334
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
dtc-lexer.l | 7 +++++++
dtc-parser.y | 6 ++++++
dtc.h | 5 +++++
livetree.c | 29 ++++++++++++++++++++++++-----
4 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/dtc-lexer.l b/dtc-lexer.l
index de60a70..5da4ca5 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -137,6 +137,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
return DT_DEL_NODE;
}
+<*>"/append-property/" {
+ DPRINT("Keyword: /append-property/\n");
+ DPRINT("<PROPNODENAME>\n");
+ BEGIN(PROPNODENAME);
+ return DT_APP_PROP;
+ }
+
<*>"/omit-if-no-ref/" {
DPRINT("Keyword: /omit-if-no-ref/\n");
DPRINT("<PROPNODENAME>\n");
diff --git a/dtc-parser.y b/dtc-parser.y
index 4d5eece..94ce405 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -58,6 +58,7 @@ static bool is_ref_relative(const char *ref)
%token DT_BITS
%token DT_DEL_PROP
%token DT_DEL_NODE
+%token DT_APP_PROP
%token DT_OMIT_NO_REF
%token <propnodename> DT_PROPNODENAME
%token <integer> DT_LITERAL
@@ -296,6 +297,11 @@ propdef:
$$ = build_property_delete($2);
free($2);
}
+ | DT_APP_PROP DT_PROPNODENAME '=' propdata ';'
+ {
+ $$ = build_property_append($2, $4, &@$);
+ free($2);
+ }
| DT_LABEL propdef
{
add_label(&$2->labels, $1);
diff --git a/dtc.h b/dtc.h
index 4c4aaca..3c9ba5a 100644
--- a/dtc.h
+++ b/dtc.h
@@ -205,6 +205,9 @@ struct bus_type {
struct property {
bool deleted;
+ /* Flag to indicate if the property value should be appended instead
+ * of being overwritten */
+ bool append;
char *name;
struct data val;
@@ -263,6 +266,8 @@ void delete_labels(struct label **labels);
struct property *build_property(const char *name, struct data val,
struct srcpos *srcpos);
struct property *build_property_delete(const char *name);
+struct property *build_property_append(const char *name, struct data val,
+ struct srcpos *srcpos);
struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);
diff --git a/livetree.c b/livetree.c
index 49f7230..d9b4dc9 100644
--- a/livetree.c
+++ b/livetree.c
@@ -62,6 +62,20 @@ struct property *build_property_delete(const char *name)
return new;
}
+struct property *build_property_append(const char *name, struct data val,
+ struct srcpos *srcpos)
+{
+ struct property *new = xmalloc(sizeof(*new));
+
+ memset(new, 0, sizeof(*new));
+ new->name = xstrdup(name);
+ new->append = true;
+ new->val = val;
+ new->srcpos = srcpos_copy(srcpos);
+
+ return new;
+}
+
struct property *chain_property(struct property *first, struct property *list)
{
assert(first->next == NULL);
@@ -151,8 +165,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
for_each_label_withdel(new_node->labels, l)
add_label(&old_node->labels, l->label);
- /* Move properties from the new node to the old node. If there
- * is a collision, replace the old value with the new */
+ /* Move properties from the new node to the old node. If there
+ * is a collision, replace/append the old value with the new */
while (new_node->proplist) {
/* Pop the property off the list */
new_prop = new_node->proplist;
@@ -165,15 +179,20 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
continue;
}
- /* Look for a collision, set new value if there is */
+ /* Look for a collision, set new value/append if there is */
for_each_property_withdel(old_node, old_prop) {
if (streq(old_prop->name, new_prop->name)) {
/* Add new labels to old property */
for_each_label_withdel(new_prop->labels, l)
add_label(&old_prop->labels, l->label);
- old_prop->val = new_prop->val;
- old_prop->deleted = 0;
+ if (new_prop->append)
+ old_prop->val = data_merge(old_prop->val, new_prop->val);
+ else
+ old_prop->val = new_prop->val;
+
+ old_prop->deleted = false;
+ old_prop->append = false;
free(old_prop->srcpos);
old_prop->srcpos = new_prop->srcpos;
free(new_prop);
--
2.46.0
next prev parent reply other threads:[~2024-08-29 20:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 20:03 [PATCH v2 0/2] Add capability to append to property Ayush Singh
2024-08-29 20:03 ` Ayush Singh [this message]
2024-08-29 20:03 ` [PATCH v2 2/2] tests: Add test for append-property Ayush Singh
2024-08-30 1:06 ` Simon Glass
2024-08-30 3:28 ` CVS
2024-08-30 8:07 ` Ayush Singh
2024-08-30 8:01 ` Ayush Singh
2024-09-12 11:06 ` CVS
2024-09-17 17:23 ` Ayush Singh
2024-08-30 8:09 ` [PATCH v2 0/2] Add capability to append to property Geert Uytterhoeven
2024-08-30 15:43 ` Andrew Davis
2024-09-12 3:59 ` David Gibson
2024-10-10 6:31 ` Ayush Singh
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=20240830-append-v2-1-ec1e03f110ad@beagleboard.org \
--to=ayush@beagleboard.org \
--cc=afd@ti.com \
--cc=d-gole@ti.com \
--cc=devicetree-compiler@vger.kernel.org \
--cc=geert@linux-m68k.org \
--cc=jkridner@beagleboard.org \
--cc=lorforlinux@beagleboard.org \
--cc=nenad.marinkovic@mikroe.com \
--cc=robertcnelson@beagleboard.org \
--cc=robertcnelson@gmail.com \
--cc=sjg@chromium.org \
/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).