Skip to content

Commit 50aafd6

Browse files
committed
scripts/dtc: Update to upstream version v1.4.6-21-g84e414b0b5bc
This adds the following commits from upstream: 84e414b0b5bc tests: Add a test case for the omit-if-no-ref keyword 4038fd90056e dtc: add ability to make nodes conditional on them being referenced e1f139ea4900 checks: drop warning for missing PCI bridge bus-range f4eba68d89ee checks: Print duplicate node name instead of parent name 46df1fb1b211 .travis.yml: Run valgrind checks via Travis 14a3002a1aee tests: Update valgrind suppressions for sw_tree1 02c5fe9debc0 tests: Remove valgrind error from tests/get_path df536831d02c checks: add graph binding checks 2347c96edcbe checks: add a check for duplicate unit-addresses of child nodes 8f1b35f88395 Correct overlay syntactic sugar for generating target-path fragments afbddcd418fb Suppress warnings on overlay fragments 119e27300359 Improve tests for dtc overlay generation Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 9601000 commit 50aafd6

6 files changed

Lines changed: 261 additions & 16 deletions

File tree

‎scripts/dtc/checks.c‎

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
255255
child2;
256256
child2 = child2->next_sibling)
257257
if (streq(child->name, child2->name))
258-
FAIL(c, dti, node, "Duplicate node name");
258+
FAIL(c, dti, child2, "Duplicate node name");
259259
}
260260
ERROR(duplicate_node_names, check_duplicate_node_names, NULL);
261261

@@ -317,6 +317,11 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
317317
const char *unitname = get_unitname(node);
318318
struct property *prop = get_property(node, "reg");
319319

320+
if (get_subnode(node, "__overlay__")) {
321+
/* HACK: Overlay fragments are a special case */
322+
return;
323+
}
324+
320325
if (!prop) {
321326
prop = get_property(node, "ranges");
322327
if (prop && !prop->val.len)
@@ -579,6 +584,8 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
579584

580585
phandle = get_node_phandle(dt, refnode);
581586
*((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
587+
588+
reference_node(refnode);
582589
}
583590
}
584591
}
@@ -609,11 +616,21 @@ static void fixup_path_references(struct check *c, struct dt_info *dti,
609616
path = refnode->fullpath;
610617
prop->val = data_insert_at_marker(prop->val, m, path,
611618
strlen(path) + 1);
619+
620+
reference_node(refnode);
612621
}
613622
}
614623
}
615624
ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
616625

626+
static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti,
627+
struct node *node)
628+
{
629+
if (node->omit_if_unused && !node->is_referenced)
630+
delete_node(node);
631+
}
632+
ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &path_references);
633+
617634
/*
618635
* Semantic checks
619636
*/
@@ -1017,6 +1034,36 @@ static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *d
10171034
}
10181035
WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
10191036

1037+
static void check_unique_unit_address(struct check *c, struct dt_info *dti,
1038+
struct node *node)
1039+
{
1040+
struct node *childa;
1041+
1042+
if (node->addr_cells < 0 || node->size_cells < 0)
1043+
return;
1044+
1045+
if (!node->children)
1046+
return;
1047+
1048+
for_each_child(node, childa) {
1049+
struct node *childb;
1050+
const char *addr_a = get_unitname(childa);
1051+
1052+
if (!strlen(addr_a))
1053+
continue;
1054+
1055+
for_each_child(node, childb) {
1056+
const char *addr_b = get_unitname(childb);
1057+
if (childa == childb)
1058+
break;
1059+
1060+
if (streq(addr_a, addr_b))
1061+
FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath);
1062+
}
1063+
}
1064+
}
1065+
WARNING(unique_unit_address, check_unique_unit_address, NULL, &avoid_default_addr_size);
1066+
10201067
static void check_obsolete_chosen_interrupt_controller(struct check *c,
10211068
struct dt_info *dti,
10221069
struct node *node)
@@ -1357,6 +1404,152 @@ static void check_interrupts_property(struct check *c,
13571404
}
13581405
WARNING(interrupts_property, check_interrupts_property, &phandle_references);
13591406

1407+
static const struct bus_type graph_port_bus = {
1408+
.name = "graph-port",
1409+
};
1410+
1411+
static const struct bus_type graph_ports_bus = {
1412+
.name = "graph-ports",
1413+
};
1414+
1415+
static void check_graph_nodes(struct check *c, struct dt_info *dti,
1416+
struct node *node)
1417+
{
1418+
struct node *child;
1419+
1420+
for_each_child(node, child) {
1421+
if (!(strprefixeq(child->name, child->basenamelen, "endpoint") ||
1422+
get_property(child, "remote-endpoint")))
1423+
continue;
1424+
1425+
node->bus = &graph_port_bus;
1426+
1427+
/* The parent of 'port' nodes can be either 'ports' or a device */
1428+
if (!node->parent->bus &&
1429+
(streq(node->parent->name, "ports") || get_property(node, "reg")))
1430+
node->parent->bus = &graph_ports_bus;
1431+
1432+
break;
1433+
}
1434+
1435+
}
1436+
WARNING(graph_nodes, check_graph_nodes, NULL);
1437+
1438+
static void check_graph_child_address(struct check *c, struct dt_info *dti,
1439+
struct node *node)
1440+
{
1441+
int cnt = 0;
1442+
struct node *child;
1443+
1444+
if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus)
1445+
return;
1446+
1447+
for_each_child(node, child) {
1448+
struct property *prop = get_property(child, "reg");
1449+
1450+
/* No error if we have any non-zero unit address */
1451+
if (prop && propval_cell(prop) != 0)
1452+
return;
1453+
1454+
cnt++;
1455+
}
1456+
1457+
if (cnt == 1 && node->addr_cells != -1)
1458+
FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
1459+
node->children->name);
1460+
}
1461+
WARNING(graph_child_address, check_graph_child_address, NULL, &graph_nodes);
1462+
1463+
static void check_graph_reg(struct check *c, struct dt_info *dti,
1464+
struct node *node)
1465+
{
1466+
char unit_addr[9];
1467+
const char *unitname = get_unitname(node);
1468+
struct property *prop;
1469+
1470+
prop = get_property(node, "reg");
1471+
if (!prop || !unitname)
1472+
return;
1473+
1474+
if (!(prop->val.val && prop->val.len == sizeof(cell_t))) {
1475+
FAIL(c, dti, node, "graph node malformed 'reg' property");
1476+
return;
1477+
}
1478+
1479+
snprintf(unit_addr, sizeof(unit_addr), "%x", propval_cell(prop));
1480+
if (!streq(unitname, unit_addr))
1481+
FAIL(c, dti, node, "graph node unit address error, expected \"%s\"",
1482+
unit_addr);
1483+
1484+
if (node->parent->addr_cells != 1)
1485+
FAIL_PROP(c, dti, node, get_property(node, "#address-cells"),
1486+
"graph node '#address-cells' is %d, must be 1",
1487+
node->parent->addr_cells);
1488+
if (node->parent->size_cells != 0)
1489+
FAIL_PROP(c, dti, node, get_property(node, "#size-cells"),
1490+
"graph node '#size-cells' is %d, must be 0",
1491+
node->parent->size_cells);
1492+
}
1493+
1494+
static void check_graph_port(struct check *c, struct dt_info *dti,
1495+
struct node *node)
1496+
{
1497+
if (node->bus != &graph_port_bus)
1498+
return;
1499+
1500+
if (!strprefixeq(node->name, node->basenamelen, "port"))
1501+
FAIL(c, dti, node, "graph port node name should be 'port'");
1502+
1503+
check_graph_reg(c, dti, node);
1504+
}
1505+
WARNING(graph_port, check_graph_port, NULL, &graph_nodes);
1506+
1507+
static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
1508+
struct node *endpoint)
1509+
{
1510+
int phandle;
1511+
struct node *node;
1512+
struct property *prop;
1513+
1514+
prop = get_property(endpoint, "remote-endpoint");
1515+
if (!prop)
1516+
return NULL;
1517+
1518+
phandle = propval_cell(prop);
1519+
/* Give up if this is an overlay with external references */
1520+
if (phandle == 0 || phandle == -1)
1521+
return NULL;
1522+
1523+
node = get_node_by_phandle(dti->dt, phandle);
1524+
if (!node)
1525+
FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
1526+
1527+
return node;
1528+
}
1529+
1530+
static void check_graph_endpoint(struct check *c, struct dt_info *dti,
1531+
struct node *node)
1532+
{
1533+
struct node *remote_node;
1534+
1535+
if (!node->parent || node->parent->bus != &graph_port_bus)
1536+
return;
1537+
1538+
if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
1539+
FAIL(c, dti, node, "graph endpont node name should be 'endpoint'");
1540+
1541+
check_graph_reg(c, dti, node);
1542+
1543+
remote_node = get_remote_endpoint(c, dti, node);
1544+
if (!remote_node)
1545+
return;
1546+
1547+
if (get_remote_endpoint(c, dti, remote_node) != node)
1548+
FAIL(c, dti, node, "graph connection to node '%s' is not bidirectional",
1549+
remote_node->fullpath);
1550+
}
1551+
WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
1552+
13601553
static struct check *check_table[] = {
13611554
&duplicate_node_names, &duplicate_property_names,
13621555
&node_name_chars, &node_name_format, &property_name_chars,
@@ -1366,6 +1559,7 @@ static struct check *check_table[] = {
13661559

13671560
&explicit_phandles,
13681561
&phandle_references, &path_references,
1562+
&omit_unused_nodes,
13691563

13701564
&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
13711565
&device_type_is_string, &model_is_string, &status_is_string,
@@ -1390,6 +1584,7 @@ static struct check *check_table[] = {
13901584

13911585
&avoid_default_addr_size,
13921586
&avoid_unnecessary_addr_size,
1587+
&unique_unit_address,
13931588
&obsolete_chosen_interrupt_controller,
13941589
&chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
13951590

@@ -1416,6 +1611,8 @@ static struct check *check_table[] = {
14161611

14171612
&alias_paths,
14181613

1614+
&graph_nodes, &graph_child_address, &graph_port, &graph_endpoint,
1615+
14191616
&always_fail,
14201617
};
14211618

‎scripts/dtc/dtc-lexer.l‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
153153
return DT_DEL_NODE;
154154
}
155155

156+
<*>"/omit-if-no-ref/" {
157+
DPRINT("Keyword: /omit-if-no-ref/\n");
158+
DPRINT("<PROPNODENAME>\n");
159+
BEGIN(PROPNODENAME);
160+
return DT_OMIT_NO_REF;
161+
}
162+
156163
<*>{LABEL}: {
157164
DPRINT("Label: %s\n", yytext);
158165
yylval.labelref = xstrdup(yytext);

‎scripts/dtc/dtc-parser.y‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern bool treesource_error;
6363
%token DT_BITS
6464
%token DT_DEL_PROP
6565
%token DT_DEL_NODE
66+
%token DT_OMIT_NO_REF
6667
%token <propnodename> DT_PROPNODENAME
6768
%token <integer> DT_LITERAL
6869
%token <integer> DT_CHAR_LITERAL
@@ -190,18 +191,18 @@ devicetree:
190191
}
191192
| devicetree DT_REF nodedef
192193
{
193-
struct node *target = get_node_by_ref($1, $2);
194-
195-
if (target) {
196-
merge_nodes(target, $3);
194+
/*
195+
* We rely on the rule being always:
196+
* versioninfo plugindecl memreserves devicetree
197+
* so $-1 is what we want (plugindecl)
198+
*/
199+
if ($<flags>-1 & DTSF_PLUGIN) {
200+
add_orphan_node($1, $3, $2);
197201
} else {
198-
/*
199-
* We rely on the rule being always:
200-
* versioninfo plugindecl memreserves devicetree
201-
* so $-1 is what we want (plugindecl)
202-
*/
203-
if ($<flags>-1 & DTSF_PLUGIN)
204-
add_orphan_node($1, $3, $2);
202+
struct node *target = get_node_by_ref($1, $2);
203+
204+
if (target)
205+
merge_nodes(target, $3);
205206
else
206207
ERROR(&@2, "Label or path %s not found", $2);
207208
}
@@ -217,6 +218,18 @@ devicetree:
217218
ERROR(&@3, "Label or path %s not found", $3);
218219

219220

221+
$$ = $1;
222+
}
223+
| devicetree DT_OMIT_NO_REF DT_REF ';'
224+
{
225+
struct node *target = get_node_by_ref($1, $3);
226+
227+
if (target)
228+
omit_node_if_unused(target);
229+
else
230+
ERROR(&@3, "Label or path %s not found", $3);
231+
232+
220233
$$ = $1;
221234
}
222235
;
@@ -523,6 +536,10 @@ subnode:
523536
{
524537
$$ = name_node(build_node_delete(), $2);
525538
}
539+
| DT_OMIT_NO_REF subnode
540+
{
541+
$$ = omit_node_if_unused($2);
542+
}
526543
| DT_LABEL subnode
527544
{
528545
add_label(&$2->labels, $1);

‎scripts/dtc/dtc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ struct node {
168168

169169
struct label *labels;
170170
const struct bus_type *bus;
171+
172+
bool omit_if_unused, is_referenced;
171173
};
172174

173175
#define for_each_label_withdel(l0, l) \
@@ -202,6 +204,8 @@ struct property *reverse_properties(struct property *first);
202204
struct node *build_node(struct property *proplist, struct node *children);
203205
struct node *build_node_delete(void);
204206
struct node *name_node(struct node *node, char *name);
207+
struct node *omit_node_if_unused(struct node *node);
208+
struct node *reference_node(struct node *node);
205209
struct node *chain_node(struct node *first, struct node *list);
206210
struct node *merge_nodes(struct node *old_node, struct node *new_node);
207211
struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref);

0 commit comments

Comments
 (0)