Skip to content

Commit 658f29a

Browse files
John Bonesioglikely
authored andcommitted
of/flattree: Update dtc to current mainline.
Pull in recent changes from the main dtc repository. These changes primarily allow multiple device trees to be declared which are merged by dtc. This feature allows us to include a basic dts file and then provide more information for the specific system through the merging functionality. Changes pulled from git://git.jdl.com/software/dtc.git commit id: 37c0b6a0, "dtc: Add code to make diffing trees easier" Signed-off-by: John Bonesio <bones@secretlab.ca> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent cd1e650 commit 658f29a

18 files changed

Lines changed: 1721 additions & 1452 deletions

‎scripts/dtc/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ hostprogs-y := dtc
44
always := $(hostprogs-y)
55

66
dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
7-
srcpos.o checks.o
7+
srcpos.o checks.o util.o
88
dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
99

1010
# Source files need to get at the userspace version of libfdt_env.h to compile
@@ -19,6 +19,7 @@ HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC)
1919
HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC)
2020
HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
2121
HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
22+
HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)
2223

2324
HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
2425
HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)

‎scripts/dtc/checks.c‎

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,40 +278,120 @@ static void check_property_name_chars(struct check *c, struct node *dt,
278278
}
279279
PROP_CHECK(property_name_chars, PROPNODECHARS, ERROR);
280280

281+
#define DESCLABEL_FMT "%s%s%s%s%s"
282+
#define DESCLABEL_ARGS(node,prop,mark) \
283+
((mark) ? "value of " : ""), \
284+
((prop) ? "'" : ""), \
285+
((prop) ? (prop)->name : ""), \
286+
((prop) ? "' in " : ""), (node)->fullpath
287+
288+
static void check_duplicate_label(struct check *c, struct node *dt,
289+
const char *label, struct node *node,
290+
struct property *prop, struct marker *mark)
291+
{
292+
struct node *othernode = NULL;
293+
struct property *otherprop = NULL;
294+
struct marker *othermark = NULL;
295+
296+
othernode = get_node_by_label(dt, label);
297+
298+
if (!othernode)
299+
otherprop = get_property_by_label(dt, label, &othernode);
300+
if (!othernode)
301+
othermark = get_marker_label(dt, label, &othernode,
302+
&otherprop);
303+
304+
if (!othernode)
305+
return;
306+
307+
if ((othernode != node) || (otherprop != prop) || (othermark != mark))
308+
FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
309+
" and " DESCLABEL_FMT,
310+
label, DESCLABEL_ARGS(node, prop, mark),
311+
DESCLABEL_ARGS(othernode, otherprop, othermark));
312+
}
313+
314+
static void check_duplicate_label_node(struct check *c, struct node *dt,
315+
struct node *node)
316+
{
317+
struct label *l;
318+
319+
for_each_label(node->labels, l)
320+
check_duplicate_label(c, dt, l->label, node, NULL, NULL);
321+
}
322+
static void check_duplicate_label_prop(struct check *c, struct node *dt,
323+
struct node *node, struct property *prop)
324+
{
325+
struct marker *m = prop->val.markers;
326+
struct label *l;
327+
328+
for_each_label(prop->labels, l)
329+
check_duplicate_label(c, dt, l->label, node, prop, NULL);
330+
331+
for_each_marker_of_type(m, LABEL)
332+
check_duplicate_label(c, dt, m->ref, node, prop, m);
333+
}
334+
CHECK(duplicate_label, NULL, check_duplicate_label_node,
335+
check_duplicate_label_prop, NULL, ERROR);
336+
281337
static void check_explicit_phandles(struct check *c, struct node *root,
282-
struct node *node)
338+
struct node *node, struct property *prop)
283339
{
284-
struct property *prop;
340+
struct marker *m;
285341
struct node *other;
286342
cell_t phandle;
287343

288-
prop = get_property(node, "linux,phandle");
289-
if (! prop)
290-
return; /* No phandle, that's fine */
344+
if (!streq(prop->name, "phandle")
345+
&& !streq(prop->name, "linux,phandle"))
346+
return;
291347

292348
if (prop->val.len != sizeof(cell_t)) {
293-
FAIL(c, "%s has bad length (%d) linux,phandle property",
294-
node->fullpath, prop->val.len);
349+
FAIL(c, "%s has bad length (%d) %s property",
350+
node->fullpath, prop->val.len, prop->name);
351+
return;
352+
}
353+
354+
m = prop->val.markers;
355+
for_each_marker_of_type(m, REF_PHANDLE) {
356+
assert(m->offset == 0);
357+
if (node != get_node_by_ref(root, m->ref))
358+
/* "Set this node's phandle equal to some
359+
* other node's phandle". That's nonsensical
360+
* by construction. */ {
361+
FAIL(c, "%s in %s is a reference to another node",
362+
prop->name, node->fullpath);
363+
return;
364+
}
365+
/* But setting this node's phandle equal to its own
366+
* phandle is allowed - that means allocate a unique
367+
* phandle for this node, even if it's not otherwise
368+
* referenced. The value will be filled in later, so
369+
* no further checking for now. */
295370
return;
296371
}
297372

298373
phandle = propval_cell(prop);
374+
299375
if ((phandle == 0) || (phandle == -1)) {
300-
FAIL(c, "%s has invalid linux,phandle value 0x%x",
301-
node->fullpath, phandle);
376+
FAIL(c, "%s has bad value (0x%x) in %s property",
377+
node->fullpath, phandle, prop->name);
302378
return;
303379
}
304380

381+
if (node->phandle && (node->phandle != phandle))
382+
FAIL(c, "%s has %s property which replaces existing phandle information",
383+
node->fullpath, prop->name);
384+
305385
other = get_node_by_phandle(root, phandle);
306-
if (other) {
386+
if (other && (other != node)) {
307387
FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)",
308388
node->fullpath, phandle, other->fullpath);
309389
return;
310390
}
311391

312392
node->phandle = phandle;
313393
}
314-
NODE_CHECK(explicit_phandles, NULL, ERROR);
394+
PROP_CHECK(explicit_phandles, NULL, ERROR);
315395

316396
static void check_name_properties(struct check *c, struct node *root,
317397
struct node *node)
@@ -549,6 +629,9 @@ static struct check *check_table[] = {
549629
&duplicate_node_names, &duplicate_property_names,
550630
&node_name_chars, &node_name_format, &property_name_chars,
551631
&name_is_string, &name_properties,
632+
633+
&duplicate_label,
634+
552635
&explicit_phandles,
553636
&phandle_references, &path_references,
554637

0 commit comments

Comments
 (0)