From: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: David Gibson
<david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>,
Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org>,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [RFC PATCH 1/3] dtc: dts source location annotation
Date: Tue, 15 Sep 2015 21:22:18 -0700 [thread overview]
Message-ID: <55F8EE7A.7080301@gmail.com> (raw)
In-Reply-To: <55F8EB35.5010601-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: Frank Rowand <frank.rowand-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
Proof of concept patch.
Annotates input source file and line number of nodes and properties
as comments in output .dts file when --annotate flag is supplied.
Not-signed-off-by: Frank Rowand <frank.rowand-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
---
dtc-lexer.l | 2 +
dtc.c | 9 ++++++++
dtc.h | 14 +++++++++++++
livetree.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
srcpos.h | 6 +++++
treesource.c | 27 ++++++++++++++++++++-----
6 files changed, 115 insertions(+), 5 deletions(-)
Index: b/dtc.h
===================================================================
--- a/dtc.h
+++ b/dtc.h
@@ -54,6 +54,7 @@ extern int reservenum; /* Number of mem
extern int minsize; /* Minimum blob size */
extern int padsize; /* Additional padding to blob */
extern int phandle_format; /* Use linux,phandle or phandle properties */
+extern bool annotate; /* annotate .dts with input source location */
#define PHANDLE_LEGACY 0x1
#define PHANDLE_EPAPR 0x2
@@ -126,6 +127,16 @@ bool data_is_one_string(struct data d);
#define MAX_NODENAME_LEN 31
/* Live trees */
+struct src {
+ char *name;
+ int lineno;
+};
+
+struct prop_src {
+ struct prop_src *prev;
+ struct src src;
+};
+
struct label {
bool deleted;
char *label;
@@ -140,6 +151,7 @@ struct property {
struct property *next;
struct label *labels;
+ struct src src;
};
struct node {
@@ -158,6 +170,8 @@ struct node {
int addr_cells, size_cells;
struct label *labels;
+ struct src begin_src;
+ struct src end_src;
};
#define for_each_label_withdel(l0, l) \
Index: b/livetree.c
===================================================================
--- a/livetree.c
+++ b/livetree.c
@@ -19,6 +19,9 @@
*/
#include "dtc.h"
+#include "srcpos.h"
+
+struct prop_src *prev_prop_src = NULL;
/*
* Tree building functions
@@ -58,6 +61,13 @@ struct property *build_property(char *na
new->name = name;
new->val = val;
+ if (current_srcfile) {
+ new->src.name = current_srcfile->name;
+ new->src.lineno = current_srcfile->lineno;
+ } else {
+ new->src.name = "__builtin__";
+ new->src.lineno = 0;
+ }
return new;
}
@@ -97,10 +107,40 @@ struct property *reverse_properties(stru
return head;
}
+void push_prop_src(void)
+{
+ struct prop_src *new = xmalloc(sizeof(*new));
+
+ memset(new, 0, sizeof(*new));
+
+ if (current_srcfile) {
+ new->src.name = current_srcfile->name;
+ new->src.lineno = current_srcfile->lineno;
+ } else {
+ new->src.name = "__builtin__";
+ new->src.lineno = 0;
+ }
+
+ new->prev = prev_prop_src;
+ prev_prop_src = new;
+}
+
+void pop_prop_src(void)
+{
+ struct prop_src *prev;
+
+ if (prev_prop_src) {
+ prev = prev_prop_src->prev;
+ free(prev_prop_src);
+ prev_prop_src = prev;
+ }
+}
+
struct node *build_node(struct property *proplist, struct node *children)
{
struct node *new = xmalloc(sizeof(*new));
struct node *child;
+ struct prop_src *prev;
memset(new, 0, sizeof(*new));
@@ -111,6 +151,24 @@ struct node *build_node(struct property
child->parent = new;
}
+ prev = prev_prop_src;
+ if (prev) {
+ new->begin_src.name = prev->src.name;
+ new->begin_src.lineno = prev->src.lineno;
+ pop_prop_src();
+ } else {
+ new->begin_src.name = "__builtin__";
+ new->begin_src.lineno = 0;
+ }
+
+ if (current_srcfile) {
+ new->end_src.name = current_srcfile->name;
+ new->end_src.lineno = current_srcfile->lineno;
+ } else {
+ new->end_src.name = "__builtin__";
+ new->end_src.lineno = 0;
+ }
+
return new;
}
@@ -169,6 +227,7 @@ struct node *merge_nodes(struct node *ol
old_prop->val = new_prop->val;
old_prop->deleted = 0;
+ old_prop->src = new_prop->src;
free(new_prop);
new_prop = NULL;
break;
@@ -209,6 +268,9 @@ struct node *merge_nodes(struct node *ol
add_child(old_node, new_child);
}
+ old_node->begin_src = new_node->begin_src;
+ old_node->end_src = new_node->end_src;
+
/* The new node contents are now merged into the old node. Free
* the new node. */
free(new_node);
Index: b/treesource.c
===================================================================
--- a/treesource.c
+++ b/treesource.c
@@ -202,7 +202,11 @@ static void write_propval(FILE *f, struc
int i;
if (len == 0) {
- fprintf(f, ";\n");
+ if (annotate)
+ fprintf(f, "; /* %s:%d */\n",
+ prop->src.name, prop->src.lineno);
+ else
+ fprintf(f, ";\n");
return;
}
@@ -230,7 +234,10 @@ static void write_propval(FILE *f, struc
write_propval_bytes(f, prop->val);
}
- fprintf(f, ";\n");
+ if (annotate)
+ fprintf(f, "; /* %s:%d */\n", prop->src.name, prop->src.lineno);
+ else
+ fprintf(f, ";\n");
}
static void write_tree_source_node(FILE *f, struct node *tree, int level)
@@ -242,10 +249,16 @@ static void write_tree_source_node(FILE
write_prefix(f, level);
for_each_label(tree->labels, l)
fprintf(f, "%s: ", l->label);
+
if (tree->name && (*tree->name))
- fprintf(f, "%s {\n", tree->name);
+ fprintf(f, "%s {", tree->name);
else
- fprintf(f, "/ {\n");
+ fprintf(f, "/ {");
+ if (annotate) {
+ fprintf(f, " /* %s:%d */\n",
+ tree->begin_src.name, tree->begin_src.lineno);
+ } else
+ fprintf(f, "\n");
for_each_property(tree, prop) {
write_prefix(f, level+1);
@@ -259,7 +272,11 @@ static void write_tree_source_node(FILE
write_tree_source_node(f, child, level+1);
}
write_prefix(f, level);
- fprintf(f, "};\n");
+ if (annotate)
+ fprintf(f, "}; /* %s:%d */\n",
+ tree->end_src.name, tree->end_src.lineno);
+ else
+ fprintf(f, "};\n");
}
Index: b/dtc.c
===================================================================
--- a/dtc.c
+++ b/dtc.c
@@ -29,6 +29,7 @@ int reservenum; /* Number of memory res
int minsize; /* Minimum blob size */
int padsize; /* Additional padding to blob */
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
+bool annotate = false; /* annotate .dts with input source location */
static void fill_fullpaths(struct node *tree, const char *prefix)
{
@@ -71,6 +72,7 @@ static struct option const usage_long_op
{"error", a_argument, NULL, 'E'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
+ {"annotate", no_argument, NULL, 'a'},
{NULL, no_argument, NULL, 0x0},
};
static const char * const usage_opts_help[] = {
@@ -101,6 +103,7 @@ static const char * const usage_opts_hel
"\n\tEnable/disable errors (prefix with \"no-\")",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
+ "\n\tAnnotate output .dts with input source file and line",
NULL,
};
@@ -125,6 +128,9 @@ int main(int argc, char *argv[])
while ((opt = util_getopt_long()) != EOF) {
switch (opt) {
+ case 'a':
+ annotate = true;
+ break;
case 'I':
inform = optarg;
break;
@@ -213,6 +219,9 @@ int main(int argc, char *argv[])
fprintf(depfile, "%s:", outname);
}
+ if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
+ die("--annotate requires -I dts -O dts\n");
+
if (streq(inform, "dts"))
bi = dt_from_source(arg);
else if (streq(inform, "fs"))
Index: b/dtc-lexer.l
===================================================================
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -249,6 +249,8 @@ static void lexical_error(const char *fm
DPRINT("<PROPNODENAME>\n");
BEGIN(PROPNODENAME);
}
+ if (yytext[0] == '{')
+ push_prop_src();
return yytext[0];
}
Index: b/srcpos.h
===================================================================
--- a/srcpos.h
+++ b/srcpos.h
@@ -34,6 +34,8 @@ struct srcfile_state {
extern FILE *depfile; /* = NULL */
extern struct srcfile_state *current_srcfile; /* = NULL */
+extern struct prop_src *prev_prop_src; /* = NULL */
+
/**
* Open a source file.
*
@@ -58,6 +60,10 @@ FILE *srcfile_relative_open(const char *
void srcfile_push(const char *fname);
bool srcfile_pop(void);
+void push_prop_src(void);
+void pop_prop_src(void);
+
+
/**
* Add a new directory to the search path for input files
*
next prev parent reply other threads:[~2015-09-16 4:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 4:08 [RFC PATCH 0/3] dtc: dts source location annotation Frank Rowand
[not found] ` <55F8EB35.5010601-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-16 4:19 ` Frank Rowand
2015-09-16 4:22 ` Frank Rowand [this message]
[not found] ` <55F8EE7A.7080301-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-21 6:31 ` [RFC PATCH 1/3] " David Gibson
[not found] ` <20150921063119.GL20331-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2015-09-21 17:55 ` Frank Rowand
2015-09-16 4:24 ` [RFC PATCH 2/3] dtc: make check test for dtc --annotate Frank Rowand
[not found] ` <55F8EF1B.1040003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-21 6:33 ` David Gibson
[not found] ` <20150921063336.GM20331-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2015-09-21 17:55 ` Frank Rowand
2015-09-16 4:29 ` [RFC PATCH 3/3] dtc: linux kernel build process to create annotated .dts Frank Rowand
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=55F8EE7A.7080301@gmail.com \
--to=frowand.list-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=jdl-CYoMK+44s/E@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.