Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8

This adds the following commits from upstream:

0a3a9d3449c8 checks: Add an interrupt-map check
8fd24744e361 checks: Ensure '#interrupt-cells' only exists in interrupt providers
d8d1a9a77863 checks: Drop interrupt provider '#address-cells' check
52a16fd72824 checks: Make interrupt_provider check dependent on interrupts_extended_is_cell
37fd700685da treesource: Maintain phandle label/path on output
e33ce1d6a8c7 flattree: Use '\n', not ';' to separate asm pseudo-ops
d24cc189dca6 asm: Use assembler macros instead of cpp macros
ff3a30c115ad asm: Use .asciz and .ascii instead of .string
5eb5927d81ee fdtdump: fix -Werror=int-to-pointer-cast
0869f8269161 libfdt: Add ALIGNMENT error string
69595a167f06 checks: Fix bus-range check
72d09e2682a4 Makefile: add -Wsign-compare to warning options
b587787ef388 checks: Fix signedness comparisons warnings
69bed6c2418f dtc: Wrap phandle validity check
910221185560 fdtget: Fix signedness comparisons warnings
d966f08fcd21 tests: Fix signedness comparisons warnings
ecfb438c07fa dtc: Fix signedness comparisons warnings: pointer diff
5bec74a6d135 dtc: Fix signedness comparisons warnings: reservednum
24e7f511fd4a fdtdump: Fix signedness comparisons warnings
b6910bec1161 Bump version to v1.6.1
21d61d18f968 Fix CID 1461557
4c2ef8f4d14c checks: Introduce is_multiple_of()
e59ca36fb70e Make handling of cpp line information more tolerant
0c3fd9b6aceb checks: Drop interrupt_cells_is_cell check
6b3081abc4ac checks: Add check_is_cell() for all phandle+arg properties
2dffc192a77f yamltree: Remove marker ordering dependency
61e513439e40 pylibfdt: Rework "avoid unused variable warning" lines
c8bddd106095 tests: add a positive gpio test case
ad4abfadb687 checks: replace strstr and strrchr with strends
09c6a6e88718 dtc.h: add strends for suffix matching
9bb9b8d0b4a0 checks: tigthen up nr-gpios prop exception
b07b62ee3342 libfdt: Add FDT alignment check to fdt_check_header()
a2def5479950 libfdt: Check that the root-node name is empty
4ca61f84dc21 libfdt: Check that there is only one root node
34d708249a91 dtc: Remove -O dtbo support
8e7ff260f755 libfdt: Fix a possible "unchecked return value" warning
88875268c05c checks: Warn on node-name and property name being the same
9d2279e7e6ee checks: Change node-name check to match devicetree spec
f527c867a8c6 util: limit gnu_printf format attribute to gcc >= 4.4.0

Reviewed-by: Frank Rowand <frank.rowand@sony.com>
Tested-by: Frank Rowand <frank.rowand@sony.com>
Signed-off-by: Rob Herring <robh@kernel.org>

+276 -115
+169 -55
scripts/dtc/checks.c
··· 143 143 check_nodes_props(c, dti, child); 144 144 } 145 145 146 + static bool is_multiple_of(int multiple, int divisor) 147 + { 148 + if (divisor == 0) 149 + return multiple == 0; 150 + else 151 + return (multiple % divisor) == 0; 152 + } 153 + 146 154 static bool run_check(struct check *c, struct dt_info *dti) 147 155 { 148 156 struct node *dt = dti->dt; ··· 305 297 #define LOWERCASE "abcdefghijklmnopqrstuvwxyz" 306 298 #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 307 299 #define DIGITS "0123456789" 308 - #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" 300 + #define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@" 301 + #define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" 309 302 #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-" 310 303 311 304 static void check_node_name_chars(struct check *c, struct dt_info *dti, 312 305 struct node *node) 313 306 { 314 - int n = strspn(node->name, c->data); 307 + size_t n = strspn(node->name, c->data); 315 308 316 309 if (n < strlen(node->name)) 317 310 FAIL(c, dti, node, "Bad character '%c' in node name", 318 311 node->name[n]); 319 312 } 320 - ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@"); 313 + ERROR(node_name_chars, check_node_name_chars, NODECHARS); 321 314 322 315 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti, 323 316 struct node *node) ··· 338 329 FAIL(c, dti, node, "multiple '@' characters in node name"); 339 330 } 340 331 ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars); 332 + 333 + static void check_node_name_vs_property_name(struct check *c, 334 + struct dt_info *dti, 335 + struct node *node) 336 + { 337 + if (!node->parent) 338 + return; 339 + 340 + if (get_property(node->parent, node->name)) { 341 + FAIL(c, dti, node, "node name and property name conflict"); 342 + } 343 + } 344 + WARNING(node_name_vs_property_name, check_node_name_vs_property_name, 345 + NULL, &node_name_chars); 341 346 342 347 static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti, 343 348 struct node *node) ··· 386 363 struct property *prop; 387 364 388 365 for_each_property(node, prop) { 389 - int n = strspn(prop->name, c->data); 366 + size_t n = strspn(prop->name, c->data); 390 367 391 368 if (n < strlen(prop->name)) 392 369 FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name", 393 370 prop->name[n]); 394 371 } 395 372 } 396 - ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS); 373 + ERROR(property_name_chars, check_property_name_chars, PROPCHARS); 397 374 398 375 static void check_property_name_chars_strict(struct check *c, 399 376 struct dt_info *dti, ··· 403 380 404 381 for_each_property(node, prop) { 405 382 const char *name = prop->name; 406 - int n = strspn(name, c->data); 383 + size_t n = strspn(name, c->data); 407 384 408 385 if (n == strlen(prop->name)) 409 386 continue; ··· 520 497 521 498 phandle = propval_cell(prop); 522 499 523 - if ((phandle == 0) || (phandle == -1)) { 500 + if (!phandle_is_valid(phandle)) { 524 501 FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property", 525 502 phandle, prop->name); 526 503 return 0; ··· 579 556 if (!prop) 580 557 return; /* No name property, that's fine */ 581 558 582 - if ((prop->val.len != node->basenamelen+1) 559 + if ((prop->val.len != node->basenamelen + 1U) 583 560 || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) { 584 561 FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead" 585 562 " of base node name)", prop->val.val); ··· 680 657 */ 681 658 WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells"); 682 659 WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells"); 683 - WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells"); 684 660 685 661 WARNING_IF_NOT_STRING(device_type_is_string, "device_type"); 686 662 WARNING_IF_NOT_STRING(model_is_string, "model"); ··· 694 672 struct property *prop; 695 673 696 674 for_each_property(node, prop) { 697 - const char *s = strrchr(prop->name, '-'); 698 - if (!s || !streq(s, "-names")) 675 + if (!strends(prop->name, "-names")) 699 676 continue; 700 677 701 678 c->data = prop->name; ··· 774 753 size_cells = node_size_cells(node->parent); 775 754 entrylen = (addr_cells + size_cells) * sizeof(cell_t); 776 755 777 - if (!entrylen || (prop->val.len % entrylen) != 0) 756 + if (!is_multiple_of(prop->val.len, entrylen)) 778 757 FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) " 779 758 "(#address-cells == %d, #size-cells == %d)", 780 759 prop->val.len, addr_cells, size_cells); ··· 815 794 "#size-cells (%d) differs from %s (%d)", 816 795 ranges, c_size_cells, node->parent->fullpath, 817 796 p_size_cells); 818 - } else if ((prop->val.len % entrylen) != 0) { 797 + } else if (!is_multiple_of(prop->val.len, entrylen)) { 819 798 FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) " 820 799 "(parent #address-cells == %d, child #address-cells == %d, " 821 800 "#size-cells == %d)", ranges, prop->val.len, ··· 892 871 } else { 893 872 cells = (cell_t *)prop->val.val; 894 873 min_bus = fdt32_to_cpu(cells[0]); 895 - max_bus = fdt32_to_cpu(cells[0]); 874 + max_bus = fdt32_to_cpu(cells[1]); 896 875 } 897 876 if ((bus_num < min_bus) || (bus_num > max_bus)) 898 877 FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)", ··· 1388 1367 const struct provider *provider) 1389 1368 { 1390 1369 struct node *root = dti->dt; 1391 - int cell, cellsize = 0; 1370 + unsigned int cell, cellsize = 0; 1392 1371 1393 - if (prop->val.len % sizeof(cell_t)) { 1372 + if (!is_multiple_of(prop->val.len, sizeof(cell_t))) { 1394 1373 FAIL_PROP(c, dti, node, prop, 1395 1374 "property size (%d) is invalid, expected multiple of %zu", 1396 1375 prop->val.len, sizeof(cell_t)); ··· 1400 1379 for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) { 1401 1380 struct node *provider_node; 1402 1381 struct property *cellprop; 1403 - int phandle; 1382 + cell_t phandle; 1404 1383 1405 1384 phandle = propval_cell_n(prop, cell); 1406 1385 /* 1407 1386 * Some bindings use a cell value 0 or -1 to skip over optional 1408 1387 * entries when each index position has a specific definition. 1409 1388 */ 1410 - if (phandle == 0 || phandle == -1) { 1389 + if (!phandle_is_valid(phandle)) { 1411 1390 /* Give up if this is an overlay with external references */ 1412 1391 if (dti->dtsflags & DTSF_PLUGIN) 1413 1392 break; ··· 1473 1452 } 1474 1453 #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \ 1475 1454 static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \ 1476 - WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references); 1455 + WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \ 1456 + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references); 1477 1457 1478 1458 WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells"); 1479 1459 WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells"); ··· 1495 1473 1496 1474 static bool prop_is_gpio(struct property *prop) 1497 1475 { 1498 - char *str; 1499 - 1500 1476 /* 1501 1477 * *-gpios and *-gpio can appear in property names, 1502 1478 * so skip over any false matches (only one known ATM) 1503 1479 */ 1504 - if (strstr(prop->name, "nr-gpio")) 1480 + if (strends(prop->name, ",nr-gpios")) 1505 1481 return false; 1506 1482 1507 - str = strrchr(prop->name, '-'); 1508 - if (str) 1509 - str++; 1510 - else 1511 - str = prop->name; 1512 - if (!(streq(str, "gpios") || streq(str, "gpio"))) 1513 - return false; 1514 - 1515 - return true; 1483 + return strends(prop->name, "-gpios") || 1484 + streq(prop->name, "gpios") || 1485 + strends(prop->name, "-gpio") || 1486 + streq(prop->name, "gpio"); 1516 1487 } 1517 1488 1518 1489 static void check_gpios_property(struct check *c, ··· 1540 1525 struct property *prop; 1541 1526 1542 1527 for_each_property(node, prop) { 1543 - char *str; 1544 - 1545 1528 if (!prop_is_gpio(prop)) 1546 1529 continue; 1547 1530 1548 - str = strstr(prop->name, "gpio"); 1549 - if (!streq(str, "gpio")) 1531 + if (!strends(prop->name, "gpio")) 1550 1532 continue; 1551 1533 1552 1534 FAIL_PROP(c, dti, node, prop, ··· 1573 1561 struct node *node) 1574 1562 { 1575 1563 struct property *prop; 1576 - 1577 - if (!node_is_interrupt_provider(node)) 1578 - return; 1564 + bool irq_provider = node_is_interrupt_provider(node); 1579 1565 1580 1566 prop = get_property(node, "#interrupt-cells"); 1581 - if (!prop) 1567 + if (irq_provider && !prop) { 1582 1568 FAIL(c, dti, node, 1583 - "Missing #interrupt-cells in interrupt provider"); 1569 + "Missing '#interrupt-cells' in interrupt provider"); 1570 + return; 1571 + } 1584 1572 1585 - prop = get_property(node, "#address-cells"); 1586 - if (!prop) 1573 + if (!irq_provider && prop) { 1587 1574 FAIL(c, dti, node, 1588 - "Missing #address-cells in interrupt provider"); 1575 + "'#interrupt-cells' found, but node is not an interrupt provider"); 1576 + return; 1577 + } 1589 1578 } 1590 - WARNING(interrupt_provider, check_interrupt_provider, NULL); 1579 + WARNING(interrupt_provider, check_interrupt_provider, NULL, &interrupts_extended_is_cell); 1580 + 1581 + static void check_interrupt_map(struct check *c, 1582 + struct dt_info *dti, 1583 + struct node *node) 1584 + { 1585 + struct node *root = dti->dt; 1586 + struct property *prop, *irq_map_prop; 1587 + size_t cellsize, cell, map_cells; 1588 + 1589 + irq_map_prop = get_property(node, "interrupt-map"); 1590 + if (!irq_map_prop) 1591 + return; 1592 + 1593 + if (node->addr_cells < 0) { 1594 + FAIL(c, dti, node, 1595 + "Missing '#address-cells' in interrupt-map provider"); 1596 + return; 1597 + } 1598 + cellsize = node_addr_cells(node); 1599 + cellsize += propval_cell(get_property(node, "#interrupt-cells")); 1600 + 1601 + prop = get_property(node, "interrupt-map-mask"); 1602 + if (prop && (prop->val.len != (cellsize * sizeof(cell_t)))) 1603 + FAIL_PROP(c, dti, node, prop, 1604 + "property size (%d) is invalid, expected %zu", 1605 + prop->val.len, cellsize * sizeof(cell_t)); 1606 + 1607 + if (!is_multiple_of(irq_map_prop->val.len, sizeof(cell_t))) { 1608 + FAIL_PROP(c, dti, node, irq_map_prop, 1609 + "property size (%d) is invalid, expected multiple of %zu", 1610 + irq_map_prop->val.len, sizeof(cell_t)); 1611 + return; 1612 + } 1613 + 1614 + map_cells = irq_map_prop->val.len / sizeof(cell_t); 1615 + for (cell = 0; cell < map_cells; ) { 1616 + struct node *provider_node; 1617 + struct property *cellprop; 1618 + int phandle; 1619 + size_t parent_cellsize; 1620 + 1621 + if ((cell + cellsize) >= map_cells) { 1622 + FAIL_PROP(c, dti, node, irq_map_prop, 1623 + "property size (%d) too small, expected > %zu", 1624 + irq_map_prop->val.len, (cell + cellsize) * sizeof(cell_t)); 1625 + break; 1626 + } 1627 + cell += cellsize; 1628 + 1629 + phandle = propval_cell_n(irq_map_prop, cell); 1630 + if (!phandle_is_valid(phandle)) { 1631 + /* Give up if this is an overlay with external references */ 1632 + if (!(dti->dtsflags & DTSF_PLUGIN)) 1633 + FAIL_PROP(c, dti, node, irq_map_prop, 1634 + "Cell %zu is not a phandle(%d)", 1635 + cell, phandle); 1636 + break; 1637 + } 1638 + 1639 + provider_node = get_node_by_phandle(root, phandle); 1640 + if (!provider_node) { 1641 + FAIL_PROP(c, dti, node, irq_map_prop, 1642 + "Could not get phandle(%d) node for (cell %zu)", 1643 + phandle, cell); 1644 + break; 1645 + } 1646 + 1647 + cellprop = get_property(provider_node, "#interrupt-cells"); 1648 + if (cellprop) { 1649 + parent_cellsize = propval_cell(cellprop); 1650 + } else { 1651 + FAIL(c, dti, node, "Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])", 1652 + provider_node->fullpath, cell); 1653 + break; 1654 + } 1655 + 1656 + cellprop = get_property(provider_node, "#address-cells"); 1657 + if (cellprop) 1658 + parent_cellsize += propval_cell(cellprop); 1659 + 1660 + cell += 1 + parent_cellsize; 1661 + } 1662 + } 1663 + WARNING(interrupt_map, check_interrupt_map, NULL, &phandle_references, &addr_size_cells, &interrupt_provider); 1591 1664 1592 1665 static void check_interrupts_property(struct check *c, 1593 1666 struct dt_info *dti, ··· 1681 1584 struct node *root = dti->dt; 1682 1585 struct node *irq_node = NULL, *parent = node; 1683 1586 struct property *irq_prop, *prop = NULL; 1684 - int irq_cells, phandle; 1587 + cell_t irq_cells, phandle; 1685 1588 1686 1589 irq_prop = get_property(node, "interrupts"); 1687 1590 if (!irq_prop) 1688 1591 return; 1689 1592 1690 - if (irq_prop->val.len % sizeof(cell_t)) 1593 + if (!is_multiple_of(irq_prop->val.len, sizeof(cell_t))) 1691 1594 FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu", 1692 1595 irq_prop->val.len, sizeof(cell_t)); 1693 1596 ··· 1700 1603 prop = get_property(parent, "interrupt-parent"); 1701 1604 if (prop) { 1702 1605 phandle = propval_cell(prop); 1703 - if ((phandle == 0) || (phandle == -1)) { 1606 + if (!phandle_is_valid(phandle)) { 1704 1607 /* Give up if this is an overlay with 1705 1608 * external references */ 1706 1609 if (dti->dtsflags & DTSF_PLUGIN) ··· 1736 1639 } 1737 1640 1738 1641 irq_cells = propval_cell(prop); 1739 - if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) { 1642 + if (!is_multiple_of(irq_prop->val.len, irq_cells * sizeof(cell_t))) { 1740 1643 FAIL_PROP(c, dti, node, prop, 1741 1644 "size is (%d), expected multiple of %d", 1742 1645 irq_prop->val.len, (int)(irq_cells * sizeof(cell_t))); ··· 1847 1750 static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti, 1848 1751 struct node *endpoint) 1849 1752 { 1850 - int phandle; 1753 + cell_t phandle; 1851 1754 struct node *node; 1852 1755 struct property *prop; 1853 1756 ··· 1857 1760 1858 1761 phandle = propval_cell(prop); 1859 1762 /* Give up if this is an overlay with external references */ 1860 - if (phandle == 0 || phandle == -1) 1763 + if (!phandle_is_valid(phandle)) 1861 1764 return NULL; 1862 1765 1863 1766 node = get_node_by_phandle(dti->dt, phandle); ··· 1893 1796 static struct check *check_table[] = { 1894 1797 &duplicate_node_names, &duplicate_property_names, 1895 1798 &node_name_chars, &node_name_format, &property_name_chars, 1896 - &name_is_string, &name_properties, 1799 + &name_is_string, &name_properties, &node_name_vs_property_name, 1897 1800 1898 1801 &duplicate_label, 1899 1802 ··· 1901 1804 &phandle_references, &path_references, 1902 1805 &omit_unused_nodes, 1903 1806 1904 - &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, 1807 + &address_cells_is_cell, &size_cells_is_cell, 1905 1808 &device_type_is_string, &model_is_string, &status_is_string, 1906 1809 &label_is_string, 1907 1810 ··· 1936 1839 &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path, 1937 1840 1938 1841 &clocks_property, 1842 + &clocks_is_cell, 1939 1843 &cooling_device_property, 1844 + &cooling_device_is_cell, 1940 1845 &dmas_property, 1846 + &dmas_is_cell, 1941 1847 &hwlocks_property, 1848 + &hwlocks_is_cell, 1942 1849 &interrupts_extended_property, 1850 + &interrupts_extended_is_cell, 1943 1851 &io_channels_property, 1852 + &io_channels_is_cell, 1944 1853 &iommus_property, 1854 + &iommus_is_cell, 1945 1855 &mboxes_property, 1856 + &mboxes_is_cell, 1946 1857 &msi_parent_property, 1858 + &msi_parent_is_cell, 1947 1859 &mux_controls_property, 1860 + &mux_controls_is_cell, 1948 1861 &phys_property, 1862 + &phys_is_cell, 1949 1863 &power_domains_property, 1864 + &power_domains_is_cell, 1950 1865 &pwms_property, 1866 + &pwms_is_cell, 1951 1867 &resets_property, 1868 + &resets_is_cell, 1952 1869 &sound_dai_property, 1870 + &sound_dai_is_cell, 1953 1871 &thermal_sensors_property, 1872 + &thermal_sensors_is_cell, 1954 1873 1955 1874 &deprecated_gpio_property, 1956 1875 &gpios_property, 1957 1876 &interrupts_property, 1958 1877 &interrupt_provider, 1878 + &interrupt_map, 1959 1879 1960 1880 &alias_paths, 1961 1881 ··· 1996 1882 1997 1883 static void disable_warning_error(struct check *c, bool warn, bool error) 1998 1884 { 1999 - int i; 1885 + unsigned int i; 2000 1886 2001 1887 /* Lowering level, also lower it for things this is the prereq 2002 1888 * for */ ··· 2017 1903 2018 1904 void parse_checks_option(bool warn, bool error, const char *arg) 2019 1905 { 2020 - int i; 1906 + unsigned int i; 2021 1907 const char *name = arg; 2022 1908 bool enable = true; 2023 1909 ··· 2044 1930 2045 1931 void process_checks(bool force, struct dt_info *dti) 2046 1932 { 2047 - int i; 1933 + unsigned int i; 2048 1934 int error = 0; 2049 1935 2050 1936 for (i = 0; i < ARRAY_SIZE(check_table); i++) {
+1 -1
scripts/dtc/dtc-lexer.l
··· 57 57 push_input_file(name); 58 58 } 59 59 60 - <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { 60 + <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* { 61 61 char *line, *fnstart, *fnend; 62 62 struct data fn; 63 63 /* skip text before line # */
+2 -4
scripts/dtc/dtc.c
··· 12 12 * Command line options 13 13 */ 14 14 int quiet; /* Level of quietness */ 15 - int reservenum; /* Number of memory reservation slots */ 15 + unsigned int reservenum;/* Number of memory reservation slots */ 16 16 int minsize; /* Minimum blob size */ 17 17 int padsize; /* Additional padding to blob */ 18 18 int alignsize; /* Additional padding to blob accroding to the alignsize */ ··· 197 197 depname = optarg; 198 198 break; 199 199 case 'R': 200 - reservenum = strtol(optarg, NULL, 0); 200 + reservenum = strtoul(optarg, NULL, 0); 201 201 break; 202 202 case 'S': 203 203 minsize = strtol(optarg, NULL, 0); ··· 358 358 dt_to_yaml(outf, dti); 359 359 #endif 360 360 } else if (streq(outform, "dtb")) { 361 - dt_to_blob(outf, dti, outversion); 362 - } else if (streq(outform, "dtbo")) { 363 361 dt_to_blob(outf, dti, outversion); 364 362 } else if (streq(outform, "asm")) { 365 363 dt_to_asm(outf, dti, outversion);
+38 -2
scripts/dtc/dtc.h
··· 35 35 * Command line options 36 36 */ 37 37 extern int quiet; /* Level of quietness */ 38 - extern int reservenum; /* Number of memory reservation slots */ 38 + extern unsigned int reservenum; /* Number of memory reservation slots */ 39 39 extern int minsize; /* Minimum blob size */ 40 40 extern int padsize; /* Additional padding to blob */ 41 41 extern int alignsize; /* Additional padding to blob accroding to the alignsize */ ··· 50 50 #define PHANDLE_BOTH 0x3 51 51 52 52 typedef uint32_t cell_t; 53 + 54 + static inline bool phandle_is_valid(cell_t phandle) 55 + { 56 + return phandle != 0 && phandle != ~0U; 57 + } 53 58 54 59 static inline uint16_t dtb_ld16(const void *p) 55 60 { ··· 91 86 #define streq(a, b) (strcmp((a), (b)) == 0) 92 87 #define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0) 93 88 #define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0)) 89 + static inline bool strends(const char *str, const char *suffix) 90 + { 91 + unsigned int len, suffix_len; 92 + 93 + len = strlen(str); 94 + suffix_len = strlen(suffix); 95 + if (len < suffix_len) 96 + return false; 97 + return streq(str + len - suffix_len, suffix); 98 + } 94 99 95 100 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 96 101 ··· 116 101 TYPE_UINT64, 117 102 TYPE_STRING, 118 103 }; 104 + 105 + static inline bool is_type_marker(enum markertype type) 106 + { 107 + return type >= TYPE_UINT8; 108 + } 109 + 119 110 extern const char *markername(enum markertype markertype); 120 111 121 112 struct marker { ··· 146 125 for_each_marker(m) \ 147 126 if ((m)->type == (t)) 148 127 149 - size_t type_marker_length(struct marker *m); 128 + static inline struct marker *next_type_marker(struct marker *m) 129 + { 130 + for_each_marker(m) 131 + if (is_type_marker(m->type)) 132 + break; 133 + return m; 134 + } 135 + 136 + static inline size_t type_marker_length(struct marker *m) 137 + { 138 + struct marker *next = next_type_marker(m->next); 139 + 140 + if (next) 141 + return next->offset - m->offset; 142 + return 0; 143 + } 150 144 151 145 void data_free(struct data d); 152 146
+6 -5
scripts/dtc/flattree.c
··· 124 124 { 125 125 FILE *f = e; 126 126 127 - fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n", 127 + fprintf(f, "\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n" 128 + "\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n", 128 129 (val >> 24) & 0xff, (val >> 16) & 0xff, 129 130 (val >> 8) & 0xff, val & 0xff); 130 131 } ··· 135 134 FILE *f = e; 136 135 137 136 if (len != 0) 138 - fprintf(f, "\t.string\t\"%.*s\"\n", len, str); 137 + fprintf(f, "\t.asciz\t\"%.*s\"\n", len, str); 139 138 else 140 - fprintf(f, "\t.string\t\"%s\"\n", str); 139 + fprintf(f, "\t.asciz\t\"%s\"\n", str); 141 140 } 142 141 143 142 static void asm_emit_align(void *e, int a) ··· 296 295 { 297 296 struct reserve_info *re; 298 297 struct data d = empty_data; 299 - int j; 298 + unsigned int j; 300 299 301 300 for (re = reservelist; re; re = re->next) { 302 301 d = data_append_re(d, re->address, re->size); ··· 439 438 440 439 while (p < (strbuf.val + strbuf.len)) { 441 440 len = strlen(p); 442 - fprintf(f, "\t.string \"%s\"\n", p); 441 + fprintf(f, "\t.asciz \"%s\"\n", p); 443 442 p += len+1; 444 443 } 445 444 }
+4
scripts/dtc/libfdt/fdt.c
··· 90 90 { 91 91 size_t hdrsize; 92 92 93 + /* The device tree must be at an 8-byte aligned address */ 94 + if ((uintptr_t)fdt & 7) 95 + return -FDT_ERR_ALIGNMENT; 96 + 93 97 if (fdt_magic(fdt) != FDT_MAGIC) 94 98 return -FDT_ERR_BADMAGIC; 95 99 if (!can_assume(LATEST)) {
+12 -6
scripts/dtc/libfdt/fdt_rw.c
··· 349 349 return offset; 350 350 351 351 /* Try to place the new node after the parent's properties */ 352 - fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */ 352 + tag = fdt_next_tag(fdt, parentoffset, &nextoffset); 353 + /* the fdt_subnode_offset_namelen() should ensure this never hits */ 354 + if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE)) 355 + return -FDT_ERR_INTERNAL; 353 356 do { 354 357 offset = nextoffset; 355 358 tag = fdt_next_tag(fdt, offset, &nextoffset); ··· 394 391 } 395 392 396 393 static void fdt_packblocks_(const char *old, char *new, 397 - int mem_rsv_size, int struct_size) 394 + int mem_rsv_size, 395 + int struct_size, 396 + int strings_size) 398 397 { 399 398 int mem_rsv_off, struct_off, strings_off; 400 399 ··· 411 406 fdt_set_off_dt_struct(new, struct_off); 412 407 fdt_set_size_dt_struct(new, struct_size); 413 408 414 - memmove(new + strings_off, old + fdt_off_dt_strings(old), 415 - fdt_size_dt_strings(old)); 409 + memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size); 416 410 fdt_set_off_dt_strings(new, strings_off); 417 411 fdt_set_size_dt_strings(new, fdt_size_dt_strings(old)); 418 412 } ··· 471 467 return -FDT_ERR_NOSPACE; 472 468 } 473 469 474 - fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size); 470 + fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size, 471 + fdt_size_dt_strings(fdt)); 475 472 memmove(buf, tmp, newsize); 476 473 477 474 fdt_set_magic(buf, FDT_MAGIC); ··· 492 487 493 488 mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) 494 489 * sizeof(struct fdt_reserve_entry); 495 - fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); 490 + fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt), 491 + fdt_size_dt_strings(fdt)); 496 492 fdt_set_totalsize(fdt, fdt_data_size_(fdt)); 497 493 498 494 return 0;
+1
scripts/dtc/libfdt/fdt_strerror.c
··· 39 39 FDT_ERRTABENT(FDT_ERR_BADOVERLAY), 40 40 FDT_ERRTABENT(FDT_ERR_NOPHANDLES), 41 41 FDT_ERRTABENT(FDT_ERR_BADFLAGS), 42 + FDT_ERRTABENT(FDT_ERR_ALIGNMENT), 42 43 }; 43 44 #define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))) 44 45
+7
scripts/dtc/libfdt/libfdt.h
··· 131 131 * to work even with unaligned pointers on platforms (such as ARMv5) that don't 132 132 * like unaligned loads and stores. 133 133 */ 134 + static inline uint16_t fdt16_ld(const fdt16_t *p) 135 + { 136 + const uint8_t *bp = (const uint8_t *)p; 137 + 138 + return ((uint16_t)bp[0] << 8) | bp[1]; 139 + } 140 + 134 141 static inline uint32_t fdt32_ld(const fdt32_t *p) 135 142 { 136 143 const uint8_t *bp = (const uint8_t *)p;
+3 -3
scripts/dtc/livetree.c
··· 526 526 p = strchr(path, '/'); 527 527 528 528 for_each_child(tree, child) { 529 - if (p && strprefixeq(path, p - path, child->name)) 529 + if (p && strprefixeq(path, (size_t)(p - path), child->name)) 530 530 return get_node_by_path(child, p+1); 531 531 else if (!p && streq(path, child->name)) 532 532 return child; ··· 559 559 { 560 560 struct node *child, *node; 561 561 562 - if ((phandle == 0) || (phandle == -1)) { 562 + if (!phandle_is_valid(phandle)) { 563 563 assert(generate_fixups); 564 564 return NULL; 565 565 } ··· 594 594 static cell_t phandle = 1; /* FIXME: ick, static local */ 595 595 struct data d = empty_data; 596 596 597 - if ((node->phandle != 0) && (node->phandle != -1)) 597 + if (phandle_is_valid(node->phandle)) 598 598 return node->phandle; 599 599 600 600 while (get_node_by_phandle(root, phandle))
+20 -28
scripts/dtc/treesource.c
··· 124 124 } 125 125 } 126 126 127 - static bool has_data_type_information(struct marker *m) 128 - { 129 - return m->type >= TYPE_UINT8; 130 - } 131 - 132 - static struct marker *next_type_marker(struct marker *m) 133 - { 134 - while (m && !has_data_type_information(m)) 135 - m = m->next; 136 - return m; 137 - } 138 - 139 - size_t type_marker_length(struct marker *m) 140 - { 141 - struct marker *next = next_type_marker(m->next); 142 - 143 - if (next) 144 - return next->offset - m->offset; 145 - return 0; 146 - } 147 - 148 127 static const char *delim_start[] = { 149 128 [TYPE_UINT8] = "[", 150 129 [TYPE_UINT16] = "/bits/ 16 <", ··· 208 229 size_t chunk_len = (m->next ? m->next->offset : len) - m->offset; 209 230 size_t data_len = type_marker_length(m) ? : len - m->offset; 210 231 const char *p = &prop->val.val[m->offset]; 232 + struct marker *m_phandle; 211 233 212 - if (has_data_type_information(m)) { 234 + if (is_type_marker(m->type)) { 213 235 emit_type = m->type; 214 236 fprintf(f, " %s", delim_start[emit_type]); 215 237 } else if (m->type == LABEL) 216 238 fprintf(f, " %s:", m->ref); 217 - else if (m->offset) 218 - fputc(' ', f); 219 239 220 - if (emit_type == TYPE_NONE) { 221 - assert(chunk_len == 0); 240 + if (emit_type == TYPE_NONE || chunk_len == 0) 222 241 continue; 223 - } 224 242 225 243 switch(emit_type) { 226 244 case TYPE_UINT16: 227 245 write_propval_int(f, p, chunk_len, 2); 228 246 break; 229 247 case TYPE_UINT32: 230 - write_propval_int(f, p, chunk_len, 4); 248 + m_phandle = prop->val.markers; 249 + for_each_marker_of_type(m_phandle, REF_PHANDLE) 250 + if (m->offset == m_phandle->offset) 251 + break; 252 + 253 + if (m_phandle) { 254 + if (m_phandle->ref[0] == '/') 255 + fprintf(f, "&{%s}", m_phandle->ref); 256 + else 257 + fprintf(f, "&%s", m_phandle->ref); 258 + if (chunk_len > 4) { 259 + fputc(' ', f); 260 + write_propval_int(f, p + 4, chunk_len - 4, 4); 261 + } 262 + } else { 263 + write_propval_int(f, p, chunk_len, 4); 264 + } 231 265 break; 232 266 case TYPE_UINT64: 233 267 write_propval_int(f, p, chunk_len, 8);
+3 -3
scripts/dtc/util.h
··· 13 13 */ 14 14 15 15 #ifdef __GNUC__ 16 - #ifdef __clang__ 17 - #define PRINTF(i, j) __attribute__((format (printf, i, j))) 18 - #else 16 + #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) 19 17 #define PRINTF(i, j) __attribute__((format (gnu_printf, i, j))) 18 + #else 19 + #define PRINTF(i, j) __attribute__((format (printf, i, j))) 20 20 #endif 21 21 #define NORETURN __attribute__((noreturn)) 22 22 #else
+1 -1
scripts/dtc/version_gen.h
··· 1 - #define DTC_VERSION "DTC 1.6.0-g183df9e9" 1 + #define DTC_VERSION "DTC 1.6.1-g0a3a9d34"
+9 -7
scripts/dtc/yamltree.c
··· 29 29 (emitter)->problem, __func__, __LINE__); \ 30 30 }) 31 31 32 - static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, char *data, unsigned int len, int width) 32 + static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, 33 + char *data, unsigned int seq_offset, unsigned int len, int width) 33 34 { 34 35 yaml_event_t event; 35 36 void *tag; 36 - unsigned int off, start_offset = markers->offset; 37 + unsigned int off; 37 38 38 39 switch(width) { 39 40 case 1: tag = "!u8"; break; ··· 67 66 m = markers; 68 67 is_phandle = false; 69 68 for_each_marker_of_type(m, REF_PHANDLE) { 70 - if (m->offset == (start_offset + off)) { 69 + if (m->offset == (seq_offset + off)) { 71 70 is_phandle = true; 72 71 break; 73 72 } ··· 115 114 yaml_event_t event; 116 115 unsigned int len = prop->val.len; 117 116 struct marker *m = prop->val.markers; 117 + struct marker *markers = prop->val.markers; 118 118 119 119 /* Emit the property name */ 120 120 yaml_scalar_event_initialize(&event, NULL, ··· 153 151 154 152 switch(m->type) { 155 153 case TYPE_UINT16: 156 - yaml_propval_int(emitter, m, data, chunk_len, 2); 154 + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 2); 157 155 break; 158 156 case TYPE_UINT32: 159 - yaml_propval_int(emitter, m, data, chunk_len, 4); 157 + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 4); 160 158 break; 161 159 case TYPE_UINT64: 162 - yaml_propval_int(emitter, m, data, chunk_len, 8); 160 + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 8); 163 161 break; 164 162 case TYPE_STRING: 165 163 yaml_propval_string(emitter, data, chunk_len); 166 164 break; 167 165 default: 168 - yaml_propval_int(emitter, m, data, chunk_len, 1); 166 + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 1); 169 167 break; 170 168 } 171 169 }