devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v2 3/3] treesource: Maintain phandle label/path on output
Date: Tue,  8 Jun 2021 15:46:26 -0500	[thread overview]
Message-ID: <20210608204626.1545418-4-robh@kernel.org> (raw)
In-Reply-To: <20210608204626.1545418-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

The dts output will just output phandle integer values, but often the
necessary markers are present with path or label references. Improve the
output and maintain phandle label or path references when present in dts
output.

Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
v2:
 - New patch
---
 treesource.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/treesource.c b/treesource.c
index 061ba8c9c5e8..36c5c1ec683e 100644
--- a/treesource.c
+++ b/treesource.c
@@ -229,6 +229,7 @@ static void write_propval(FILE *f, struct property *prop)
 		size_t chunk_len = (m->next ? m->next->offset : len) - m->offset;
 		size_t data_len = type_marker_length(m) ? : len - m->offset;
 		const char *p = &prop->val.val[m->offset];
+		struct marker *m_phandle;
 
 		if (has_data_type_information(m)) {
 			emit_type = m->type;
@@ -238,17 +239,31 @@ static void write_propval(FILE *f, struct property *prop)
 		else if (m->offset)
 			fputc(' ', f);
 
-		if (emit_type == TYPE_NONE) {
-			assert(chunk_len == 0);
+		if (emit_type == TYPE_NONE || chunk_len == 0)
 			continue;
-		}
 
 		switch(emit_type) {
 		case TYPE_UINT16:
 			write_propval_int(f, p, chunk_len, 2);
 			break;
 		case TYPE_UINT32:
-			write_propval_int(f, p, chunk_len, 4);
+			m_phandle = prop->val.markers;
+			for_each_marker_of_type(m_phandle, REF_PHANDLE)
+				if (m->offset == m_phandle->offset)
+					break;
+
+			if (m_phandle) {
+				if (m_phandle->ref[0] == '/')
+					fprintf(f, "&{%s}", m_phandle->ref);
+				else
+					fprintf(f, "&%s", m_phandle->ref);
+				if (chunk_len > 4) {
+					fputc(' ', f);
+					write_propval_int(f, p + 4, chunk_len - 4, 4);
+				}
+			} else {
+				write_propval_int(f, p, chunk_len, 4);
+			}
 			break;
 		case TYPE_UINT64:
 			write_propval_int(f, p, chunk_len, 8);
-- 
2.27.0


      parent reply	other threads:[~2021-06-08 20:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 20:46 [PATCH v2 0/3] Improve output type formatting Rob Herring
     [not found] ` <20210608204626.1545418-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-08 20:46   ` [PATCH v2 1/3] checks: Add markers on known properties Rob Herring
     [not found]     ` <20210608204626.1545418-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-19  9:22       ` David Gibson
2021-06-21 18:22         ` Rob Herring
     [not found]           ` <CAL_JsqLnbiz-TzH0C0vw57B-1J=N6jBSHeiyv5yKA+Z3+0fWPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-07-12  2:37             ` David Gibson
2021-07-12 22:15               ` Rob Herring
     [not found]                 ` <CAL_JsqLYx7Zgd2v_CvTiF0yynB2HX=U+ROV-tkT7qqwxFPnjAQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-07-26  4:44                   ` David Gibson
2021-07-26 18:32                     ` Rob Herring
2021-06-08 20:46   ` [PATCH v2 2/3] dtc: Drop dts source restriction for yaml output Rob Herring
2021-06-08 20:46   ` Rob Herring [this message]

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=20210608204626.1545418-4-robh@kernel.org \
    --to=robh-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 read-only IMAP folder(s) and NNTP newsgroup(s).