Skip to content

Commit 6f05afc

Browse files
committed
scripts/dtc: Update to upstream version 0931cea3ba20
Sync to upstream dtc commit 0931cea3ba20 ("dtc: fdtdump: check fdt if not in scanning mode"). In particular, this pulls in dtc overlay support. This adds the following commits from upstream: f88865469b65 dtc: Fix memory leak in character literal parsing 00fbb8696b66 Rename boot_info 1ef86ad2c24f dtc: Clean up /dts-v1/ and /plugin/ handling in grammar e3c769aa9c16 dtc: Don't always generate __symbols__ for plugins c96cb3c0169e tests: Don't use -@ on plugin de/recompile tests 66381538ce24 tests: Remove "suppression of fixups" tests ba765b273f0f tests: Clarify dtc overlay tests 6ea8cd944fcd tests: More thorough tests of libfdt overlay application without dtc 7d8ef6e1db97 tests: Correct fdt handling of overlays without fixups and base trees without symbols b4dc0ed8b127 tests: Fix double expansion bugs in test code 3ea879dc0c8f tests: Split overlay tests into those with do/don't exercise dtc plugin generation 47b4d66a2f11 tests: Test auto-alias generation on base tree, not overlay 72e1ad811523 tests: Make overlay/plugin tests unconditional e7b3c3b5951b tests: Add overlay tests 9637e3f772a9 tests: Add check_path test 20f29d8d41f6 dtc: Plugin and fixup support a2c92cac53f8 dtc: Document the dynamic plugin internals 8f70ac39801d checks: Pass boot_info instead of root node ea10f953878f libfdt: add missing errors to fdt_strerror() daa75e8fa594 libfdt: fix fdt_stringlist_search() e28eff5b787a libfdt: fix fdt_stringlist_count() ae97c7722840 tests: overlay: Rename the device tree blobs to be more explicit 96162d2bd9cb tests: overlay: Add test suffix to the compiled blobs 5ce8634733b7 libfdt: Add fdt_overlay_apply to the exported symbols 804a9db90ad2 fdt: strerr: Remove spurious BADOVERLAY e8c3a1a493fa tests: overlay: Move back the bad fixup tests 7a72d89d3f81 libfdt: overlay: Fix symbols and fixups nodes condition cabbaa972cdd libfdt: overlay: Report a bad overlay for mismatching local fixups deb0a5c1aeaa libfdt: Add BADPHANDLE error string 7b7a6be9ba15 libfdt: Don't use 'index' as a local variable name aea8860d831e tests: Add tests cases for the overlay code 0cdd06c5135b libfdt: Add overlay application function 39240cc865cf libfdt: Extend the reach of FDT_ERR_BADPHANDLE 4aa3a6f5e6d9 libfdt: Add new errors for the overlay code 6d1832c9e64b dtc: Remove "home page" link 45fd440a9561 Fix some typing errors in libfdt.h and livetree.c a59be4939c13 Merge tag 'v1.4.2' a34bb721caca dtc: Fix assorted problems in the testcases for the -a option 874f40588d3e Implement the -a option to pad dtb aligned ec02b34c05be dtc: Makefile improvements for release uploading 1ed45d40a137 dtc: Bump version to 1.4.2 36fd7331fb11 libfdt: simplify fdt_del_mem_rsv() d877364e4a0f libfdt: Add fdt_setprop_inplace_namelen_partial 3e9037aaad44 libfdt: Add fdt_getprop_namelen_w 84e0e1346c68 libfdt: Add max phandle retrieval function d29126c90acb libfdt: Add iterator over properties 902d0f0953d0 libfdt: Add a subnodes iterator macro c539075ba8ba fdtput.c: Fix memory leak. f79ddb83e185 fdtget.c: Fix memory leak 1074ee54b63f convert-dtsv0-lexer.l: fix memory leak e24d39a024e6 fdtdump.c: make sure size_t argument to memchr is always unsigned. 44a59713cf05 Remove unused srcpos_dump() function cb9241ae3453 DTC: Fix memory leak on flatname. 1ee0ae24ea09 Simplify check field and macro names 9d97527a8621 Remove property check functions 2e709d158e11 Remove tree check functions c4cb12e193e3 Alter grammar to allow multiple /dts-v1/ tags d71d25d76012 Use xasprintf() in srcpos 9dc404958e9c util: Add xasprintf portable asprintf variant beef80b8b55f Correct a missing space in a fdt_header cast 68d43cec1253 Correct line lengths in libfdt.h b0dbceafd49a Correct space-after-tab in libfdt.h Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 0c744ea commit 6f05afc

24 files changed

Lines changed: 1661 additions & 1019 deletions

‎scripts/dtc/checks.c‎

Lines changed: 181 additions & 168 deletions
Large diffs are not rendered by default.

‎scripts/dtc/dtc-lexer.l‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ static void lexical_error(const char *fmt, ...);
121121
return DT_V1;
122122
}
123123

124+
<*>"/plugin/" {
125+
DPRINT("Keyword: /plugin/\n");
126+
return DT_PLUGIN;
127+
}
128+
124129
<*>"/memreserve/" {
125130
DPRINT("Keyword: /memreserve/\n");
126131
BEGIN_DEFAULT();
@@ -184,16 +189,16 @@ static void lexical_error(const char *fmt, ...);
184189
if (d.len == 1) {
185190
lexical_error("Empty character literal");
186191
yylval.integer = 0;
187-
return DT_CHAR_LITERAL;
188-
}
192+
} else {
193+
yylval.integer = (unsigned char)d.val[0];
189194

190-
yylval.integer = (unsigned char)d.val[0];
191-
192-
if (d.len > 2)
193-
lexical_error("Character literal has %d"
194-
" characters instead of 1",
195-
d.len - 1);
195+
if (d.len > 2)
196+
lexical_error("Character literal has %d"
197+
" characters instead of 1",
198+
d.len - 1);
199+
}
196200

201+
data_free(d);
197202
return DT_CHAR_LITERAL;
198203
}
199204

‎scripts/dtc/dtc-lexer.lex.c_shipped‎

Lines changed: 331 additions & 319 deletions
Large diffs are not rendered by default.

‎scripts/dtc/dtc-parser.tab.c_shipped‎

Lines changed: 392 additions & 360 deletions
Large diffs are not rendered by default.

‎scripts/dtc/dtc-parser.tab.h_shipped‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* A Bison parser, made by GNU Bison 3.0.2. */
1+
/* A Bison parser, made by GNU Bison 3.0.4. */
22

33
/* Bison interface for Yacc-like parsers in C
44

5-
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
5+
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
66

77
This program is free software: you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
@@ -46,35 +46,36 @@ extern int yydebug;
4646
enum yytokentype
4747
{
4848
DT_V1 = 258,
49-
DT_MEMRESERVE = 259,
50-
DT_LSHIFT = 260,
51-
DT_RSHIFT = 261,
52-
DT_LE = 262,
53-
DT_GE = 263,
54-
DT_EQ = 264,
55-
DT_NE = 265,
56-
DT_AND = 266,
57-
DT_OR = 267,
58-
DT_BITS = 268,
59-
DT_DEL_PROP = 269,
60-
DT_DEL_NODE = 270,
61-
DT_PROPNODENAME = 271,
62-
DT_LITERAL = 272,
63-
DT_CHAR_LITERAL = 273,
64-
DT_BYTE = 274,
65-
DT_STRING = 275,
66-
DT_LABEL = 276,
67-
DT_REF = 277,
68-
DT_INCBIN = 278
49+
DT_PLUGIN = 259,
50+
DT_MEMRESERVE = 260,
51+
DT_LSHIFT = 261,
52+
DT_RSHIFT = 262,
53+
DT_LE = 263,
54+
DT_GE = 264,
55+
DT_EQ = 265,
56+
DT_NE = 266,
57+
DT_AND = 267,
58+
DT_OR = 268,
59+
DT_BITS = 269,
60+
DT_DEL_PROP = 270,
61+
DT_DEL_NODE = 271,
62+
DT_PROPNODENAME = 272,
63+
DT_LITERAL = 273,
64+
DT_CHAR_LITERAL = 274,
65+
DT_BYTE = 275,
66+
DT_STRING = 276,
67+
DT_LABEL = 277,
68+
DT_REF = 278,
69+
DT_INCBIN = 279
6970
};
7071
#endif
7172

7273
/* Value type. */
7374
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
74-
typedef union YYSTYPE YYSTYPE;
75+
7576
union YYSTYPE
7677
{
77-
#line 38 "dtc-parser.y" /* yacc.c:1909 */
78+
#line 39 "dtc-parser.y" /* yacc.c:1909 */
7879

7980
char *propnodename;
8081
char *labelref;
@@ -92,9 +93,12 @@ union YYSTYPE
9293
struct node *nodelist;
9394
struct reserve_info *re;
9495
uint64_t integer;
96+
unsigned int flags;
9597

96-
#line 97 "dtc-parser.tab.h" /* yacc.c:1909 */
98+
#line 99 "dtc-parser.tab.h" /* yacc.c:1909 */
9799
};
100+
101+
typedef union YYSTYPE YYSTYPE;
98102
# define YYSTYPE_IS_TRIVIAL 1
99103
# define YYSTYPE_IS_DECLARED 1
100104
#endif

‎scripts/dtc/dtc-parser.y‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
%{
2121
#include <stdio.h>
22+
#include <inttypes.h>
2223

2324
#include "dtc.h"
2425
#include "srcpos.h"
@@ -31,7 +32,7 @@ extern void yyerror(char const *s);
3132
treesource_error = true; \
3233
} while (0)
3334

34-
extern struct boot_info *the_boot_info;
35+
extern struct dt_info *parser_output;
3536
extern bool treesource_error;
3637
%}
3738

@@ -52,9 +53,11 @@ extern bool treesource_error;
5253
struct node *nodelist;
5354
struct reserve_info *re;
5455
uint64_t integer;
56+
unsigned int flags;
5557
}
5658

5759
%token DT_V1
60+
%token DT_PLUGIN
5861
%token DT_MEMRESERVE
5962
%token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
6063
%token DT_BITS
@@ -71,6 +74,8 @@ extern bool treesource_error;
7174

7275
%type <data> propdata
7376
%type <data> propdataprefix
77+
%type <flags> header
78+
%type <flags> headers
7479
%type <re> memreserve
7580
%type <re> memreserves
7681
%type <array> arrayprefix
@@ -101,10 +106,31 @@ extern bool treesource_error;
101106
%%
102107

103108
sourcefile:
104-
DT_V1 ';' memreserves devicetree
109+
headers memreserves devicetree
105110
{
106-
the_boot_info = build_boot_info($3, $4,
107-
guess_boot_cpuid($4));
111+
parser_output = build_dt_info($1, $2, $3,
112+
guess_boot_cpuid($3));
113+
}
114+
;
115+
116+
header:
117+
DT_V1 ';'
118+
{
119+
$$ = DTSF_V1;
120+
}
121+
| DT_V1 ';' DT_PLUGIN ';'
122+
{
123+
$$ = DTSF_V1 | DTSF_PLUGIN;
124+
}
125+
;
126+
127+
headers:
128+
header
129+
| header headers
130+
{
131+
if ($2 != $1)
132+
ERROR(&@2, "Header flags don't match earlier ones");
133+
$$ = $1;
108134
}
109135
;
110136

‎scripts/dtc/dtc.c‎

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ int quiet; /* Level of quietness */
3030
int reservenum; /* Number of memory reservation slots */
3131
int minsize; /* Minimum blob size */
3232
int padsize; /* Additional padding to blob */
33+
int alignsize; /* Additional padding to blob accroding to the alignsize */
3334
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
35+
int generate_symbols; /* enable symbols & fixup support */
36+
int generate_fixups; /* suppress generation of fixups on symbol support */
37+
int auto_label_aliases; /* auto generate labels -> aliases */
38+
39+
static int is_power_of_2(int x)
40+
{
41+
return (x > 0) && ((x & (x - 1)) == 0);
42+
}
3443

3544
static void fill_fullpaths(struct node *tree, const char *prefix)
3645
{
@@ -53,7 +62,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
5362
#define FDT_VERSION(version) _FDT_VERSION(version)
5463
#define _FDT_VERSION(version) #version
5564
static const char usage_synopsis[] = "dtc [options] <input file>";
56-
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
65+
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv";
5766
static struct option const usage_long_opts[] = {
5867
{"quiet", no_argument, NULL, 'q'},
5968
{"in-format", a_argument, NULL, 'I'},
@@ -64,13 +73,16 @@ static struct option const usage_long_opts[] = {
6473
{"reserve", a_argument, NULL, 'R'},
6574
{"space", a_argument, NULL, 'S'},
6675
{"pad", a_argument, NULL, 'p'},
76+
{"align", a_argument, NULL, 'a'},
6777
{"boot-cpu", a_argument, NULL, 'b'},
6878
{"force", no_argument, NULL, 'f'},
6979
{"include", a_argument, NULL, 'i'},
7080
{"sort", no_argument, NULL, 's'},
7181
{"phandle", a_argument, NULL, 'H'},
7282
{"warning", a_argument, NULL, 'W'},
7383
{"error", a_argument, NULL, 'E'},
84+
{"symbols", no_argument, NULL, '@'},
85+
{"auto-alias", no_argument, NULL, 'A'},
7486
{"help", no_argument, NULL, 'h'},
7587
{"version", no_argument, NULL, 'v'},
7688
{NULL, no_argument, NULL, 0x0},
@@ -91,6 +103,7 @@ static const char * const usage_opts_help[] = {
91103
"\n\tMake space for <number> reserve map entries (for dtb and asm output)",
92104
"\n\tMake the blob at least <bytes> long (extra space)",
93105
"\n\tAdd padding to the blob of <bytes> long (extra space)",
106+
"\n\tMake the blob align to the <bytes> (extra space)",
94107
"\n\tSet the physical boot cpu",
95108
"\n\tTry to produce output even if the input tree has errors",
96109
"\n\tAdd a path to search for include files",
@@ -101,6 +114,8 @@ static const char * const usage_opts_help[] = {
101114
"\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
102115
"\n\tEnable/disable warnings (prefix with \"no-\")",
103116
"\n\tEnable/disable errors (prefix with \"no-\")",
117+
"\n\tEnable generation of symbols",
118+
"\n\tEnable auto-alias of labels",
104119
"\n\tPrint this help and exit",
105120
"\n\tPrint version and exit",
106121
NULL,
@@ -153,7 +168,7 @@ static const char *guess_input_format(const char *fname, const char *fallback)
153168

154169
int main(int argc, char *argv[])
155170
{
156-
struct boot_info *bi;
171+
struct dt_info *dti;
157172
const char *inform = NULL;
158173
const char *outform = NULL;
159174
const char *outname = "-";
@@ -169,6 +184,7 @@ int main(int argc, char *argv[])
169184
reservenum = 0;
170185
minsize = 0;
171186
padsize = 0;
187+
alignsize = 0;
172188

173189
while ((opt = util_getopt_long()) != EOF) {
174190
switch (opt) {
@@ -196,6 +212,12 @@ int main(int argc, char *argv[])
196212
case 'p':
197213
padsize = strtol(optarg, NULL, 0);
198214
break;
215+
case 'a':
216+
alignsize = strtol(optarg, NULL, 0);
217+
if (!is_power_of_2(alignsize))
218+
die("Invalid argument \"%d\" to -a option\n",
219+
optarg);
220+
break;
199221
case 'f':
200222
force = true;
201223
break;
@@ -234,6 +256,13 @@ int main(int argc, char *argv[])
234256
parse_checks_option(false, true, optarg);
235257
break;
236258

259+
case '@':
260+
generate_symbols = 1;
261+
break;
262+
case 'A':
263+
auto_label_aliases = 1;
264+
break;
265+
237266
case 'h':
238267
usage(NULL);
239268
default:
@@ -272,11 +301,11 @@ int main(int argc, char *argv[])
272301
}
273302
}
274303
if (streq(inform, "dts"))
275-
bi = dt_from_source(arg);
304+
dti = dt_from_source(arg);
276305
else if (streq(inform, "fs"))
277-
bi = dt_from_fs(arg);
306+
dti = dt_from_fs(arg);
278307
else if(streq(inform, "dtb"))
279-
bi = dt_from_blob(arg);
308+
dti = dt_from_blob(arg);
280309
else
281310
die("Unknown input format \"%s\"\n", inform);
282311

@@ -286,13 +315,29 @@ int main(int argc, char *argv[])
286315
}
287316

288317
if (cmdline_boot_cpuid != -1)
289-
bi->boot_cpuid_phys = cmdline_boot_cpuid;
318+
dti->boot_cpuid_phys = cmdline_boot_cpuid;
319+
320+
fill_fullpaths(dti->dt, "");
321+
process_checks(force, dti);
322+
323+
/* on a plugin, generate by default */
324+
if (dti->dtsflags & DTSF_PLUGIN) {
325+
generate_fixups = 1;
326+
}
290327

291-
fill_fullpaths(bi->dt, "");
292-
process_checks(force, bi);
328+
if (auto_label_aliases)
329+
generate_label_tree(dti, "aliases", false);
330+
331+
if (generate_symbols)
332+
generate_label_tree(dti, "__symbols__", true);
333+
334+
if (generate_fixups) {
335+
generate_fixups_tree(dti, "__fixups__");
336+
generate_local_fixups_tree(dti, "__local_fixups__");
337+
}
293338

294339
if (sort)
295-
sort_tree(bi);
340+
sort_tree(dti);
296341

297342
if (streq(outname, "-")) {
298343
outf = stdout;
@@ -304,11 +349,11 @@ int main(int argc, char *argv[])
304349
}
305350

306351
if (streq(outform, "dts")) {
307-
dt_to_source(outf, bi);
352+
dt_to_source(outf, dti);
308353
} else if (streq(outform, "dtb")) {
309-
dt_to_blob(outf, bi, outversion);
354+
dt_to_blob(outf, dti, outversion);
310355
} else if (streq(outform, "asm")) {
311-
dt_to_asm(outf, bi, outversion);
356+
dt_to_asm(outf, dti, outversion);
312357
} else if (streq(outform, "null")) {
313358
/* do nothing */
314359
} else {

0 commit comments

Comments
 (0)