Skip to content

Commit c2e7075

Browse files
committed
scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d145
This adds the following commits from upstream: f267e674d145 checks: Fix crash with multiple source annotations 3616b9a811b6 checks: Use source position information for check failures 2bdbd07a1223 checks: Make each message output atomic a1eff70c02cf util: Add xa{v}sprintf_append functions 82a52ce4573b libfdt: Add a test for fdt_getprop_by_offset() 607b8586b383 PEP8 / Flake8 cleanups for setup.py f9c0a425b648 Remove broken objdir / srcdir support 5182b5e6f28c pylibfdt: Use common PREFIX variable d45bf1f5f2a6 Refine make tests_clean target 99284c4db9cb Refine pylibfdt_clean target a4629cfaedfb Refine libfdt_clean target 08380fc43aa2 tests: Use modern octal literals for Python 8113c00b99d3 pylibfdt: Allow switch to Python 3 via environment variable PYTHON 11738cf01f15 libfdt: Don't use memcpy to handle unaligned reads on ARM 86a288a73670 checks: Restructure check_msg to decrease indentation 5667e7ef9a9a annotations: add the annotation functionality 8e20ccf52f90 annotations: add positions ca930e20bb54 tests: Don't lose errors from make checkm 43366bb4eeee tests: Property count valgrind errors in wrapped tests 5062516fb8cb srcpos: Remove srcpos_empty a3143fafbf83 Revert "annotations: add positions" 403cc79f06a1 checks: Update SPI bus check for 'spi-slave' baa1d2cf7894 annotations: add positions ff2ad38f6a5a Merge remote-tracking branch 'origin/pr/18' aa7254d9cb17 libfdt: return correct value if #size-cells property is not present 49903aed7783 use ptrdiff_t modifier for printing pointer differences da2b691ccf68 treesource: Fix dts output for phandles in middle of a sequence of ints 8f8b77a0d62d tests: Wrap check_align() calls with base_run_test() 522d81d572f2 Fix dts output with a REF_PATH marker e45198c98359 Added test cases for target references 0fcffda15e9f Merge nodes with local target label references 1e4a0928f3b3 pylibfdt: Don't have setup.py depend on where it's invoked from ca399b14956f pylibfdt: Eliminate run_setup make function 98972f1b3e33 pylibfdt: Improved version extraction 7ba2be6cda5f pylibfdt: Don't silence setup.py when V=1 7691f9d39301 pylibfdt: Make SETUP make variable 855b9963def9 pylibfdt: Simpler CFLAGS handling 47cafbeeb977 pylibfdt: Link extension module with libfdt rather than rebuilding dd695d6afb19 pylibfdt: Correctly set build output directory 59327523d0d8 pylibfdt: We don't need include files from the base directory e84742aa7b93 checks: fix simple-bus compatible matching 8c59a97ce096 Fix missing labels when emitting dts format d448f9a5fd94 Revert dts output formatting changes of spaces around brackets Signed-off-by: Rob Herring <robh@kernel.org>
1 parent e8b1dee commit c2e7075

17 files changed

Lines changed: 436 additions & 147 deletions

‎scripts/dtc/checks.c‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include "dtc.h"
22+
#include "srcpos.h"
2223

2324
#ifdef TRACE_CHECKS
2425
#define TRACE(c, ...) \
@@ -78,23 +79,56 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
7879
const char *fmt, ...)
7980
{
8081
va_list ap;
81-
va_start(ap, fmt);
82+
char *str = NULL;
83+
struct srcpos *pos = NULL;
84+
char *file_str;
85+
86+
if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2)))
87+
return;
88+
89+
if (prop && prop->srcpos)
90+
pos = prop->srcpos;
91+
else if (node && node->srcpos)
92+
pos = node->srcpos;
93+
94+
if (pos) {
95+
file_str = srcpos_string(pos);
96+
xasprintf(&str, "%s", file_str);
97+
free(file_str);
98+
} else if (streq(dti->outname, "-")) {
99+
xasprintf(&str, "<stdout>");
100+
} else {
101+
xasprintf(&str, "%s", dti->outname);
102+
}
82103

83-
if ((c->warn && (quiet < 1))
84-
|| (c->error && (quiet < 2))) {
85-
fprintf(stderr, "%s: %s (%s): ",
86-
strcmp(dti->outname, "-") ? dti->outname : "<stdout>",
104+
xasprintf_append(&str, ": %s (%s): ",
87105
(c->error) ? "ERROR" : "Warning", c->name);
88-
if (node) {
89-
fprintf(stderr, "%s", node->fullpath);
90-
if (prop)
91-
fprintf(stderr, ":%s", prop->name);
92-
fputs(": ", stderr);
93-
}
94-
vfprintf(stderr, fmt, ap);
95-
fprintf(stderr, "\n");
106+
107+
if (node) {
108+
if (prop)
109+
xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
110+
else
111+
xasprintf_append(&str, "%s: ", node->fullpath);
96112
}
113+
114+
va_start(ap, fmt);
115+
xavsprintf_append(&str, fmt, ap);
97116
va_end(ap);
117+
118+
xasprintf_append(&str, "\n");
119+
120+
if (!prop && pos) {
121+
pos = node->srcpos;
122+
while (pos->next) {
123+
pos = pos->next;
124+
125+
file_str = srcpos_string(pos);
126+
xasprintf_append(&str, " also defined at %s\n", file_str);
127+
free(file_str);
128+
}
129+
}
130+
131+
fputs(str, stderr);
98132
}
99133

100134
#define FAIL(c, dti, node, ...) \
@@ -910,7 +944,7 @@ static bool node_is_compatible(struct node *node, const char *compat)
910944

911945
for (str = prop->val.val, end = str + prop->val.len; str < end;
912946
str += strnlen(str, end - str) + 1) {
913-
if (strprefixeq(str, end - str, compat))
947+
if (streq(str, compat))
914948
return true;
915949
}
916950
return false;
@@ -921,7 +955,8 @@ static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct
921955
if (node_is_compatible(node, "simple-bus"))
922956
node->bus = &simple_bus;
923957
}
924-
WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL, &addr_size_cells);
958+
WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL,
959+
&addr_size_cells, &compatible_is_string_list);
925960

926961
static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
927962
{
@@ -1035,6 +1070,7 @@ static const struct bus_type spi_bus = {
10351070

10361071
static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
10371072
{
1073+
int spi_addr_cells = 1;
10381074

10391075
if (strprefixeq(node->name, node->basenamelen, "spi")) {
10401076
node->bus = &spi_bus;
@@ -1063,7 +1099,9 @@ static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct no
10631099
if (node->bus != &spi_bus || !node->children)
10641100
return;
10651101

1066-
if (node_addr_cells(node) != 1)
1102+
if (get_property(node, "spi-slave"))
1103+
spi_addr_cells = 0;
1104+
if (node_addr_cells(node) != spi_addr_cells)
10671105
FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
10681106
if (node_size_cells(node) != 0)
10691107
FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
@@ -1082,6 +1120,9 @@ static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node
10821120
if (!node->parent || (node->parent->bus != &spi_bus))
10831121
return;
10841122

1123+
if (get_property(node->parent, "spi-slave"))
1124+
return;
1125+
10851126
prop = get_property(node, "reg");
10861127
if (prop)
10871128
cells = (cell_t *)prop->val.val;

‎scripts/dtc/dtc-lexer.l‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
213213
<*>\&{LABEL} { /* label reference */
214214
DPRINT("Ref: %s\n", yytext+1);
215215
yylval.labelref = xstrdup(yytext+1);
216-
return DT_REF;
216+
return DT_LABEL_REF;
217217
}
218218

219219
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
220220
yytext[yyleng-1] = '\0';
221221
DPRINT("Ref: %s\n", yytext+2);
222222
yylval.labelref = xstrdup(yytext+2);
223-
return DT_REF;
223+
return DT_PATH_REF;
224224
}
225225

226226
<BYTESTRING>[0-9a-fA-F]{2} {

‎scripts/dtc/dtc-parser.y‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ extern bool treesource_error;
7070
%token <byte> DT_BYTE
7171
%token <data> DT_STRING
7272
%token <labelref> DT_LABEL
73-
%token <labelref> DT_REF
73+
%token <labelref> DT_LABEL_REF
74+
%token <labelref> DT_PATH_REF
7475
%token DT_INCBIN
7576

7677
%type <data> propdata
@@ -83,6 +84,7 @@ extern bool treesource_error;
8384
%type <data> bytestring
8485
%type <prop> propdef
8586
%type <proplist> proplist
87+
%type <labelref> dt_ref
8688

8789
%type <node> devicetree
8890
%type <node> nodedef
@@ -158,6 +160,8 @@ memreserve:
158160
}
159161
;
160162

163+
dt_ref: DT_LABEL_REF | DT_PATH_REF;
164+
161165
devicetree:
162166
'/' nodedef
163167
{
@@ -167,7 +171,7 @@ devicetree:
167171
{
168172
$$ = merge_nodes($1, $3);
169173
}
170-
| DT_REF nodedef
174+
| dt_ref nodedef
171175
{
172176
/*
173177
* We rely on the rule being always:
@@ -176,9 +180,12 @@ devicetree:
176180
*/
177181
if (!($<flags>-1 & DTSF_PLUGIN))
178182
ERROR(&@2, "Label or path %s not found", $1);
179-
$$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1);
183+
$$ = add_orphan_node(
184+
name_node(build_node(NULL, NULL, NULL),
185+
""),
186+
$2, $1);
180187
}
181-
| devicetree DT_LABEL DT_REF nodedef
188+
| devicetree DT_LABEL dt_ref nodedef
182189
{
183190
struct node *target = get_node_by_ref($1, $3);
184191

@@ -189,7 +196,7 @@ devicetree:
189196
ERROR(&@3, "Label or path %s not found", $3);
190197
$$ = $1;
191198
}
192-
| devicetree DT_REF nodedef
199+
| devicetree DT_PATH_REF nodedef
193200
{
194201
/*
195202
* We rely on the rule being always:
@@ -208,7 +215,26 @@ devicetree:
208215
}
209216
$$ = $1;
210217
}
211-
| devicetree DT_DEL_NODE DT_REF ';'
218+
| devicetree DT_LABEL_REF nodedef
219+
{
220+
struct node *target = get_node_by_ref($1, $2);
221+
222+
if (target) {
223+
merge_nodes(target, $3);
224+
} else {
225+
/*
226+
* We rely on the rule being always:
227+
* versioninfo plugindecl memreserves devicetree
228+
* so $-1 is what we want (plugindecl)
229+
*/
230+
if ($<flags>-1 & DTSF_PLUGIN)
231+
add_orphan_node($1, $3, $2);
232+
else
233+
ERROR(&@2, "Label or path %s not found", $2);
234+
}
235+
$$ = $1;
236+
}
237+
| devicetree DT_DEL_NODE dt_ref ';'
212238
{
213239
struct node *target = get_node_by_ref($1, $3);
214240

@@ -220,7 +246,7 @@ devicetree:
220246

221247
$$ = $1;
222248
}
223-
| devicetree DT_OMIT_NO_REF DT_REF ';'
249+
| devicetree DT_OMIT_NO_REF dt_ref ';'
224250
{
225251
struct node *target = get_node_by_ref($1, $3);
226252

@@ -237,7 +263,7 @@ devicetree:
237263
nodedef:
238264
'{' proplist subnodes '}' ';'
239265
{
240-
$$ = build_node($2, $3);
266+
$$ = build_node($2, $3, &@$);
241267
}
242268
;
243269

@@ -255,11 +281,11 @@ proplist:
255281
propdef:
256282
DT_PROPNODENAME '=' propdata ';'
257283
{
258-
$$ = build_property($1, $3);
284+
$$ = build_property($1, $3, &@$);
259285
}
260286
| DT_PROPNODENAME ';'
261287
{
262-
$$ = build_property($1, empty_data);
288+
$$ = build_property($1, empty_data, &@$);
263289
}
264290
| DT_DEL_PROP DT_PROPNODENAME ';'
265291
{
@@ -285,7 +311,7 @@ propdata:
285311
{
286312
$$ = data_merge($1, $3);
287313
}
288-
| propdataprefix DT_REF
314+
| propdataprefix dt_ref
289315
{
290316
$1 = data_add_marker($1, TYPE_STRING, $2);
291317
$$ = data_add_marker($1, REF_PATH, $2);
@@ -383,7 +409,7 @@ arrayprefix:
383409

384410
$$.data = data_append_integer($1.data, $2, $1.bits);
385411
}
386-
| arrayprefix DT_REF
412+
| arrayprefix dt_ref
387413
{
388414
uint64_t val = ~0ULL >> (64 - $1.bits);
389415

@@ -540,7 +566,7 @@ subnode:
540566
}
541567
| DT_DEL_NODE DT_PROPNODENAME ';'
542568
{
543-
$$ = name_node(build_node_delete(), $2);
569+
$$ = name_node(build_node_delete(&@$), $2);
544570
}
545571
| DT_OMIT_NO_REF subnode
546572
{

‎scripts/dtc/dtc.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties *
3535
int generate_symbols; /* enable symbols & fixup support */
3636
int generate_fixups; /* suppress generation of fixups on symbol support */
3737
int auto_label_aliases; /* auto generate labels -> aliases */
38+
int annotate; /* Level of annotation: 1 for input source location
39+
>1 for full input source location. */
3840

3941
static int is_power_of_2(int x)
4042
{
@@ -60,7 +62,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
6062

6163
/* Usage related data. */
6264
static const char usage_synopsis[] = "dtc [options] <input file>";
63-
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv";
65+
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv";
6466
static struct option const usage_long_opts[] = {
6567
{"quiet", no_argument, NULL, 'q'},
6668
{"in-format", a_argument, NULL, 'I'},
@@ -81,6 +83,7 @@ static struct option const usage_long_opts[] = {
8183
{"error", a_argument, NULL, 'E'},
8284
{"symbols", no_argument, NULL, '@'},
8385
{"auto-alias", no_argument, NULL, 'A'},
86+
{"annotate", no_argument, NULL, 'T'},
8487
{"help", no_argument, NULL, 'h'},
8588
{"version", no_argument, NULL, 'v'},
8689
{NULL, no_argument, NULL, 0x0},
@@ -117,6 +120,7 @@ static const char * const usage_opts_help[] = {
117120
"\n\tEnable/disable errors (prefix with \"no-\")",
118121
"\n\tEnable generation of symbols",
119122
"\n\tEnable auto-alias of labels",
123+
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
120124
"\n\tPrint this help and exit",
121125
"\n\tPrint version and exit",
122126
NULL,
@@ -264,6 +268,9 @@ int main(int argc, char *argv[])
264268
case 'A':
265269
auto_label_aliases = 1;
266270
break;
271+
case 'T':
272+
annotate++;
273+
break;
267274

268275
case 'h':
269276
usage(NULL);
@@ -302,6 +309,8 @@ int main(int argc, char *argv[])
302309
outform = "dts";
303310
}
304311
}
312+
if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
313+
die("--annotate requires -I dts -O dts\n");
305314
if (streq(inform, "dts"))
306315
dti = dt_from_source(arg);
307316
else if (streq(inform, "fs"))

‎scripts/dtc/dtc.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern int phandle_format; /* Use linux,phandle or phandle properties */
5858
extern int generate_symbols; /* generate symbols for nodes with labels */
5959
extern int generate_fixups; /* generate fixups */
6060
extern int auto_label_aliases; /* auto generate labels -> aliases */
61+
extern int annotate; /* annotate .dts with input source location */
6162

6263
#define PHANDLE_LEGACY 0x1
6364
#define PHANDLE_EPAPR 0x2
@@ -158,6 +159,7 @@ struct property {
158159
struct property *next;
159160

160161
struct label *labels;
162+
struct srcpos *srcpos;
161163
};
162164

163165
struct node {
@@ -177,6 +179,7 @@ struct node {
177179

178180
struct label *labels;
179181
const struct bus_type *bus;
182+
struct srcpos *srcpos;
180183

181184
bool omit_if_unused, is_referenced;
182185
};
@@ -205,13 +208,15 @@ struct node {
205208
void add_label(struct label **labels, char *label);
206209
void delete_labels(struct label **labels);
207210

208-
struct property *build_property(char *name, struct data val);
211+
struct property *build_property(char *name, struct data val,
212+
struct srcpos *srcpos);
209213
struct property *build_property_delete(char *name);
210214
struct property *chain_property(struct property *first, struct property *list);
211215
struct property *reverse_properties(struct property *first);
212216

213-
struct node *build_node(struct property *proplist, struct node *children);
214-
struct node *build_node_delete(void);
217+
struct node *build_node(struct property *proplist, struct node *children,
218+
struct srcpos *srcpos);
219+
struct node *build_node_delete(struct srcpos *srcpos);
215220
struct node *name_node(struct node *node, char *name);
216221
struct node *omit_node_if_unused(struct node *node);
217222
struct node *reference_node(struct node *node);

0 commit comments

Comments
 (0)