201-v5.16-scripts-dtc-Update-to-upstream-version-v1.6.1-19-g0a.patch 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. From a77725a9a3c5924e2fd4cd5b3557dd92a8e46f87 Mon Sep 17 00:00:00 2001
  2. From: Rob Herring <[email protected]>
  3. Date: Mon, 25 Oct 2021 11:05:45 -0500
  4. Subject: [PATCH 1/1] scripts/dtc: Update to upstream version
  5. v1.6.1-19-g0a3a9d3449c8
  6. This adds the following commits from upstream:
  7. 0a3a9d3449c8 checks: Add an interrupt-map check
  8. 8fd24744e361 checks: Ensure '#interrupt-cells' only exists in interrupt providers
  9. d8d1a9a77863 checks: Drop interrupt provider '#address-cells' check
  10. 52a16fd72824 checks: Make interrupt_provider check dependent on interrupts_extended_is_cell
  11. 37fd700685da treesource: Maintain phandle label/path on output
  12. e33ce1d6a8c7 flattree: Use '\n', not ';' to separate asm pseudo-ops
  13. d24cc189dca6 asm: Use assembler macros instead of cpp macros
  14. ff3a30c115ad asm: Use .asciz and .ascii instead of .string
  15. 5eb5927d81ee fdtdump: fix -Werror=int-to-pointer-cast
  16. 0869f8269161 libfdt: Add ALIGNMENT error string
  17. 69595a167f06 checks: Fix bus-range check
  18. 72d09e2682a4 Makefile: add -Wsign-compare to warning options
  19. b587787ef388 checks: Fix signedness comparisons warnings
  20. 69bed6c2418f dtc: Wrap phandle validity check
  21. 910221185560 fdtget: Fix signedness comparisons warnings
  22. d966f08fcd21 tests: Fix signedness comparisons warnings
  23. ecfb438c07fa dtc: Fix signedness comparisons warnings: pointer diff
  24. 5bec74a6d135 dtc: Fix signedness comparisons warnings: reservednum
  25. 24e7f511fd4a fdtdump: Fix signedness comparisons warnings
  26. b6910bec1161 Bump version to v1.6.1
  27. 21d61d18f968 Fix CID 1461557
  28. 4c2ef8f4d14c checks: Introduce is_multiple_of()
  29. e59ca36fb70e Make handling of cpp line information more tolerant
  30. 0c3fd9b6aceb checks: Drop interrupt_cells_is_cell check
  31. 6b3081abc4ac checks: Add check_is_cell() for all phandle+arg properties
  32. 2dffc192a77f yamltree: Remove marker ordering dependency
  33. 61e513439e40 pylibfdt: Rework "avoid unused variable warning" lines
  34. c8bddd106095 tests: add a positive gpio test case
  35. ad4abfadb687 checks: replace strstr and strrchr with strends
  36. 09c6a6e88718 dtc.h: add strends for suffix matching
  37. 9bb9b8d0b4a0 checks: tigthen up nr-gpios prop exception
  38. b07b62ee3342 libfdt: Add FDT alignment check to fdt_check_header()
  39. a2def5479950 libfdt: Check that the root-node name is empty
  40. 4ca61f84dc21 libfdt: Check that there is only one root node
  41. 34d708249a91 dtc: Remove -O dtbo support
  42. 8e7ff260f755 libfdt: Fix a possible "unchecked return value" warning
  43. 88875268c05c checks: Warn on node-name and property name being the same
  44. 9d2279e7e6ee checks: Change node-name check to match devicetree spec
  45. f527c867a8c6 util: limit gnu_printf format attribute to gcc >= 4.4.0
  46. Reviewed-by: Frank Rowand <[email protected]>
  47. Tested-by: Frank Rowand <[email protected]>
  48. Signed-off-by: Rob Herring <[email protected]>
  49. ---
  50. scripts/dtc/checks.c | 222 ++++++++++++++++++++++--------
  51. scripts/dtc/dtc-lexer.l | 2 +-
  52. scripts/dtc/dtc.c | 6 +-
  53. scripts/dtc/dtc.h | 40 +++++-
  54. scripts/dtc/flattree.c | 11 +-
  55. scripts/dtc/libfdt/fdt.c | 4 +
  56. scripts/dtc/libfdt/fdt_rw.c | 18 ++-
  57. scripts/dtc/libfdt/fdt_strerror.c | 1 +
  58. scripts/dtc/libfdt/libfdt.h | 7 +
  59. scripts/dtc/livetree.c | 6 +-
  60. scripts/dtc/treesource.c | 48 +++----
  61. scripts/dtc/util.h | 6 +-
  62. scripts/dtc/version_gen.h | 2 +-
  63. scripts/dtc/yamltree.c | 16 ++-
  64. 14 files changed, 275 insertions(+), 114 deletions(-)
  65. --- a/scripts/dtc/checks.c
  66. +++ b/scripts/dtc/checks.c
  67. @@ -143,6 +143,14 @@ static void check_nodes_props(struct che
  68. check_nodes_props(c, dti, child);
  69. }
  70. +static bool is_multiple_of(int multiple, int divisor)
  71. +{
  72. + if (divisor == 0)
  73. + return multiple == 0;
  74. + else
  75. + return (multiple % divisor) == 0;
  76. +}
  77. +
  78. static bool run_check(struct check *c, struct dt_info *dti)
  79. {
  80. struct node *dt = dti->dt;
  81. @@ -297,19 +305,20 @@ ERROR(duplicate_property_names, check_du
  82. #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
  83. #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  84. #define DIGITS "0123456789"
  85. -#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
  86. +#define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@"
  87. +#define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
  88. #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
  89. static void check_node_name_chars(struct check *c, struct dt_info *dti,
  90. struct node *node)
  91. {
  92. - int n = strspn(node->name, c->data);
  93. + size_t n = strspn(node->name, c->data);
  94. if (n < strlen(node->name))
  95. FAIL(c, dti, node, "Bad character '%c' in node name",
  96. node->name[n]);
  97. }
  98. -ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");
  99. +ERROR(node_name_chars, check_node_name_chars, NODECHARS);
  100. static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
  101. struct node *node)
  102. @@ -330,6 +339,20 @@ static void check_node_name_format(struc
  103. }
  104. ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
  105. +static void check_node_name_vs_property_name(struct check *c,
  106. + struct dt_info *dti,
  107. + struct node *node)
  108. +{
  109. + if (!node->parent)
  110. + return;
  111. +
  112. + if (get_property(node->parent, node->name)) {
  113. + FAIL(c, dti, node, "node name and property name conflict");
  114. + }
  115. +}
  116. +WARNING(node_name_vs_property_name, check_node_name_vs_property_name,
  117. + NULL, &node_name_chars);
  118. +
  119. static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
  120. struct node *node)
  121. {
  122. @@ -363,14 +386,14 @@ static void check_property_name_chars(st
  123. struct property *prop;
  124. for_each_property(node, prop) {
  125. - int n = strspn(prop->name, c->data);
  126. + size_t n = strspn(prop->name, c->data);
  127. if (n < strlen(prop->name))
  128. FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name",
  129. prop->name[n]);
  130. }
  131. }
  132. -ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);
  133. +ERROR(property_name_chars, check_property_name_chars, PROPCHARS);
  134. static void check_property_name_chars_strict(struct check *c,
  135. struct dt_info *dti,
  136. @@ -380,7 +403,7 @@ static void check_property_name_chars_st
  137. for_each_property(node, prop) {
  138. const char *name = prop->name;
  139. - int n = strspn(name, c->data);
  140. + size_t n = strspn(name, c->data);
  141. if (n == strlen(prop->name))
  142. continue;
  143. @@ -497,7 +520,7 @@ static cell_t check_phandle_prop(struct
  144. phandle = propval_cell(prop);
  145. - if ((phandle == 0) || (phandle == -1)) {
  146. + if (!phandle_is_valid(phandle)) {
  147. FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
  148. phandle, prop->name);
  149. return 0;
  150. @@ -556,7 +579,7 @@ static void check_name_properties(struct
  151. if (!prop)
  152. return; /* No name property, that's fine */
  153. - if ((prop->val.len != node->basenamelen+1)
  154. + if ((prop->val.len != node->basenamelen + 1U)
  155. || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
  156. FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead"
  157. " of base node name)", prop->val.val);
  158. @@ -657,7 +680,6 @@ ERROR(omit_unused_nodes, fixup_omit_unus
  159. */
  160. WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
  161. WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
  162. -WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
  163. WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
  164. WARNING_IF_NOT_STRING(model_is_string, "model");
  165. @@ -672,8 +694,7 @@ static void check_names_is_string_list(s
  166. struct property *prop;
  167. for_each_property(node, prop) {
  168. - const char *s = strrchr(prop->name, '-');
  169. - if (!s || !streq(s, "-names"))
  170. + if (!strends(prop->name, "-names"))
  171. continue;
  172. c->data = prop->name;
  173. @@ -753,7 +774,7 @@ static void check_reg_format(struct chec
  174. size_cells = node_size_cells(node->parent);
  175. entrylen = (addr_cells + size_cells) * sizeof(cell_t);
  176. - if (!entrylen || (prop->val.len % entrylen) != 0)
  177. + if (!is_multiple_of(prop->val.len, entrylen))
  178. FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
  179. "(#address-cells == %d, #size-cells == %d)",
  180. prop->val.len, addr_cells, size_cells);
  181. @@ -794,7 +815,7 @@ static void check_ranges_format(struct c
  182. "#size-cells (%d) differs from %s (%d)",
  183. ranges, c_size_cells, node->parent->fullpath,
  184. p_size_cells);
  185. - } else if ((prop->val.len % entrylen) != 0) {
  186. + } else if (!is_multiple_of(prop->val.len, entrylen)) {
  187. FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
  188. "(parent #address-cells == %d, child #address-cells == %d, "
  189. "#size-cells == %d)", ranges, prop->val.len,
  190. @@ -871,7 +892,7 @@ static void check_pci_device_bus_num(str
  191. } else {
  192. cells = (cell_t *)prop->val.val;
  193. min_bus = fdt32_to_cpu(cells[0]);
  194. - max_bus = fdt32_to_cpu(cells[0]);
  195. + max_bus = fdt32_to_cpu(cells[1]);
  196. }
  197. if ((bus_num < min_bus) || (bus_num > max_bus))
  198. FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
  199. @@ -1367,9 +1388,9 @@ static void check_property_phandle_args(
  200. const struct provider *provider)
  201. {
  202. struct node *root = dti->dt;
  203. - int cell, cellsize = 0;
  204. + unsigned int cell, cellsize = 0;
  205. - if (prop->val.len % sizeof(cell_t)) {
  206. + if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
  207. FAIL_PROP(c, dti, node, prop,
  208. "property size (%d) is invalid, expected multiple of %zu",
  209. prop->val.len, sizeof(cell_t));
  210. @@ -1379,14 +1400,14 @@ static void check_property_phandle_args(
  211. for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
  212. struct node *provider_node;
  213. struct property *cellprop;
  214. - int phandle;
  215. + cell_t phandle;
  216. phandle = propval_cell_n(prop, cell);
  217. /*
  218. * Some bindings use a cell value 0 or -1 to skip over optional
  219. * entries when each index position has a specific definition.
  220. */
  221. - if (phandle == 0 || phandle == -1) {
  222. + if (!phandle_is_valid(phandle)) {
  223. /* Give up if this is an overlay with external references */
  224. if (dti->dtsflags & DTSF_PLUGIN)
  225. break;
  226. @@ -1452,7 +1473,8 @@ static void check_provider_cells_propert
  227. }
  228. #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
  229. static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
  230. - WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);
  231. + WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \
  232. + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);
  233. WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
  234. WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
  235. @@ -1473,24 +1495,17 @@ WARNING_PROPERTY_PHANDLE_CELLS(thermal_s
  236. static bool prop_is_gpio(struct property *prop)
  237. {
  238. - char *str;
  239. -
  240. /*
  241. * *-gpios and *-gpio can appear in property names,
  242. * so skip over any false matches (only one known ATM)
  243. */
  244. - if (strstr(prop->name, "nr-gpio"))
  245. + if (strends(prop->name, ",nr-gpios"))
  246. return false;
  247. - str = strrchr(prop->name, '-');
  248. - if (str)
  249. - str++;
  250. - else
  251. - str = prop->name;
  252. - if (!(streq(str, "gpios") || streq(str, "gpio")))
  253. - return false;
  254. -
  255. - return true;
  256. + return strends(prop->name, "-gpios") ||
  257. + streq(prop->name, "gpios") ||
  258. + strends(prop->name, "-gpio") ||
  259. + streq(prop->name, "gpio");
  260. }
  261. static void check_gpios_property(struct check *c,
  262. @@ -1525,13 +1540,10 @@ static void check_deprecated_gpio_proper
  263. struct property *prop;
  264. for_each_property(node, prop) {
  265. - char *str;
  266. -
  267. if (!prop_is_gpio(prop))
  268. continue;
  269. - str = strstr(prop->name, "gpio");
  270. - if (!streq(str, "gpio"))
  271. + if (!strends(prop->name, "gpio"))
  272. continue;
  273. FAIL_PROP(c, dti, node, prop,
  274. @@ -1561,21 +1573,106 @@ static void check_interrupt_provider(str
  275. struct node *node)
  276. {
  277. struct property *prop;
  278. + bool irq_provider = node_is_interrupt_provider(node);
  279. - if (!node_is_interrupt_provider(node))
  280. + prop = get_property(node, "#interrupt-cells");
  281. + if (irq_provider && !prop) {
  282. + FAIL(c, dti, node,
  283. + "Missing '#interrupt-cells' in interrupt provider");
  284. return;
  285. + }
  286. - prop = get_property(node, "#interrupt-cells");
  287. - if (!prop)
  288. + if (!irq_provider && prop) {
  289. FAIL(c, dti, node,
  290. - "Missing #interrupt-cells in interrupt provider");
  291. + "'#interrupt-cells' found, but node is not an interrupt provider");
  292. + return;
  293. + }
  294. +}
  295. +WARNING(interrupt_provider, check_interrupt_provider, NULL, &interrupts_extended_is_cell);
  296. - prop = get_property(node, "#address-cells");
  297. - if (!prop)
  298. +static void check_interrupt_map(struct check *c,
  299. + struct dt_info *dti,
  300. + struct node *node)
  301. +{
  302. + struct node *root = dti->dt;
  303. + struct property *prop, *irq_map_prop;
  304. + size_t cellsize, cell, map_cells;
  305. +
  306. + irq_map_prop = get_property(node, "interrupt-map");
  307. + if (!irq_map_prop)
  308. + return;
  309. +
  310. + if (node->addr_cells < 0) {
  311. FAIL(c, dti, node,
  312. - "Missing #address-cells in interrupt provider");
  313. + "Missing '#address-cells' in interrupt-map provider");
  314. + return;
  315. + }
  316. + cellsize = node_addr_cells(node);
  317. + cellsize += propval_cell(get_property(node, "#interrupt-cells"));
  318. +
  319. + prop = get_property(node, "interrupt-map-mask");
  320. + if (prop && (prop->val.len != (cellsize * sizeof(cell_t))))
  321. + FAIL_PROP(c, dti, node, prop,
  322. + "property size (%d) is invalid, expected %zu",
  323. + prop->val.len, cellsize * sizeof(cell_t));
  324. +
  325. + if (!is_multiple_of(irq_map_prop->val.len, sizeof(cell_t))) {
  326. + FAIL_PROP(c, dti, node, irq_map_prop,
  327. + "property size (%d) is invalid, expected multiple of %zu",
  328. + irq_map_prop->val.len, sizeof(cell_t));
  329. + return;
  330. + }
  331. +
  332. + map_cells = irq_map_prop->val.len / sizeof(cell_t);
  333. + for (cell = 0; cell < map_cells; ) {
  334. + struct node *provider_node;
  335. + struct property *cellprop;
  336. + int phandle;
  337. + size_t parent_cellsize;
  338. +
  339. + if ((cell + cellsize) >= map_cells) {
  340. + FAIL_PROP(c, dti, node, irq_map_prop,
  341. + "property size (%d) too small, expected > %zu",
  342. + irq_map_prop->val.len, (cell + cellsize) * sizeof(cell_t));
  343. + break;
  344. + }
  345. + cell += cellsize;
  346. +
  347. + phandle = propval_cell_n(irq_map_prop, cell);
  348. + if (!phandle_is_valid(phandle)) {
  349. + /* Give up if this is an overlay with external references */
  350. + if (!(dti->dtsflags & DTSF_PLUGIN))
  351. + FAIL_PROP(c, dti, node, irq_map_prop,
  352. + "Cell %zu is not a phandle(%d)",
  353. + cell, phandle);
  354. + break;
  355. + }
  356. +
  357. + provider_node = get_node_by_phandle(root, phandle);
  358. + if (!provider_node) {
  359. + FAIL_PROP(c, dti, node, irq_map_prop,
  360. + "Could not get phandle(%d) node for (cell %zu)",
  361. + phandle, cell);
  362. + break;
  363. + }
  364. +
  365. + cellprop = get_property(provider_node, "#interrupt-cells");
  366. + if (cellprop) {
  367. + parent_cellsize = propval_cell(cellprop);
  368. + } else {
  369. + FAIL(c, dti, node, "Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])",
  370. + provider_node->fullpath, cell);
  371. + break;
  372. + }
  373. +
  374. + cellprop = get_property(provider_node, "#address-cells");
  375. + if (cellprop)
  376. + parent_cellsize += propval_cell(cellprop);
  377. +
  378. + cell += 1 + parent_cellsize;
  379. + }
  380. }
  381. -WARNING(interrupt_provider, check_interrupt_provider, NULL);
  382. +WARNING(interrupt_map, check_interrupt_map, NULL, &phandle_references, &addr_size_cells, &interrupt_provider);
  383. static void check_interrupts_property(struct check *c,
  384. struct dt_info *dti,
  385. @@ -1584,13 +1681,13 @@ static void check_interrupts_property(st
  386. struct node *root = dti->dt;
  387. struct node *irq_node = NULL, *parent = node;
  388. struct property *irq_prop, *prop = NULL;
  389. - int irq_cells, phandle;
  390. + cell_t irq_cells, phandle;
  391. irq_prop = get_property(node, "interrupts");
  392. if (!irq_prop)
  393. return;
  394. - if (irq_prop->val.len % sizeof(cell_t))
  395. + if (!is_multiple_of(irq_prop->val.len, sizeof(cell_t)))
  396. FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu",
  397. irq_prop->val.len, sizeof(cell_t));
  398. @@ -1603,7 +1700,7 @@ static void check_interrupts_property(st
  399. prop = get_property(parent, "interrupt-parent");
  400. if (prop) {
  401. phandle = propval_cell(prop);
  402. - if ((phandle == 0) || (phandle == -1)) {
  403. + if (!phandle_is_valid(phandle)) {
  404. /* Give up if this is an overlay with
  405. * external references */
  406. if (dti->dtsflags & DTSF_PLUGIN)
  407. @@ -1639,7 +1736,7 @@ static void check_interrupts_property(st
  408. }
  409. irq_cells = propval_cell(prop);
  410. - if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) {
  411. + if (!is_multiple_of(irq_prop->val.len, irq_cells * sizeof(cell_t))) {
  412. FAIL_PROP(c, dti, node, prop,
  413. "size is (%d), expected multiple of %d",
  414. irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
  415. @@ -1750,7 +1847,7 @@ WARNING(graph_port, check_graph_port, NU
  416. static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
  417. struct node *endpoint)
  418. {
  419. - int phandle;
  420. + cell_t phandle;
  421. struct node *node;
  422. struct property *prop;
  423. @@ -1760,7 +1857,7 @@ static struct node *get_remote_endpoint(
  424. phandle = propval_cell(prop);
  425. /* Give up if this is an overlay with external references */
  426. - if (phandle == 0 || phandle == -1)
  427. + if (!phandle_is_valid(phandle))
  428. return NULL;
  429. node = get_node_by_phandle(dti->dt, phandle);
  430. @@ -1796,7 +1893,7 @@ WARNING(graph_endpoint, check_graph_endp
  431. static struct check *check_table[] = {
  432. &duplicate_node_names, &duplicate_property_names,
  433. &node_name_chars, &node_name_format, &property_name_chars,
  434. - &name_is_string, &name_properties,
  435. + &name_is_string, &name_properties, &node_name_vs_property_name,
  436. &duplicate_label,
  437. @@ -1804,7 +1901,7 @@ static struct check *check_table[] = {
  438. &phandle_references, &path_references,
  439. &omit_unused_nodes,
  440. - &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
  441. + &address_cells_is_cell, &size_cells_is_cell,
  442. &device_type_is_string, &model_is_string, &status_is_string,
  443. &label_is_string,
  444. @@ -1839,26 +1936,43 @@ static struct check *check_table[] = {
  445. &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
  446. &clocks_property,
  447. + &clocks_is_cell,
  448. &cooling_device_property,
  449. + &cooling_device_is_cell,
  450. &dmas_property,
  451. + &dmas_is_cell,
  452. &hwlocks_property,
  453. + &hwlocks_is_cell,
  454. &interrupts_extended_property,
  455. + &interrupts_extended_is_cell,
  456. &io_channels_property,
  457. + &io_channels_is_cell,
  458. &iommus_property,
  459. + &iommus_is_cell,
  460. &mboxes_property,
  461. + &mboxes_is_cell,
  462. &msi_parent_property,
  463. + &msi_parent_is_cell,
  464. &mux_controls_property,
  465. + &mux_controls_is_cell,
  466. &phys_property,
  467. + &phys_is_cell,
  468. &power_domains_property,
  469. + &power_domains_is_cell,
  470. &pwms_property,
  471. + &pwms_is_cell,
  472. &resets_property,
  473. + &resets_is_cell,
  474. &sound_dai_property,
  475. + &sound_dai_is_cell,
  476. &thermal_sensors_property,
  477. + &thermal_sensors_is_cell,
  478. &deprecated_gpio_property,
  479. &gpios_property,
  480. &interrupts_property,
  481. &interrupt_provider,
  482. + &interrupt_map,
  483. &alias_paths,
  484. @@ -1882,7 +1996,7 @@ static void enable_warning_error(struct
  485. static void disable_warning_error(struct check *c, bool warn, bool error)
  486. {
  487. - int i;
  488. + unsigned int i;
  489. /* Lowering level, also lower it for things this is the prereq
  490. * for */
  491. @@ -1903,7 +2017,7 @@ static void disable_warning_error(struct
  492. void parse_checks_option(bool warn, bool error, const char *arg)
  493. {
  494. - int i;
  495. + unsigned int i;
  496. const char *name = arg;
  497. bool enable = true;
  498. @@ -1930,7 +2044,7 @@ void parse_checks_option(bool warn, bool
  499. void process_checks(bool force, struct dt_info *dti)
  500. {
  501. - int i;
  502. + unsigned int i;
  503. int error = 0;
  504. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  505. --- a/scripts/dtc/dtc-lexer.l
  506. +++ b/scripts/dtc/dtc-lexer.l
  507. @@ -57,7 +57,7 @@ static void PRINTF(1, 2) lexical_error(c
  508. push_input_file(name);
  509. }
  510. -<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
  511. +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* {
  512. char *line, *fnstart, *fnend;
  513. struct data fn;
  514. /* skip text before line # */
  515. --- a/scripts/dtc/dtc.c
  516. +++ b/scripts/dtc/dtc.c
  517. @@ -12,7 +12,7 @@
  518. * Command line options
  519. */
  520. int quiet; /* Level of quietness */
  521. -int reservenum; /* Number of memory reservation slots */
  522. +unsigned int reservenum;/* Number of memory reservation slots */
  523. int minsize; /* Minimum blob size */
  524. int padsize; /* Additional padding to blob */
  525. int alignsize; /* Additional padding to blob accroding to the alignsize */
  526. @@ -197,7 +197,7 @@ int main(int argc, char *argv[])
  527. depname = optarg;
  528. break;
  529. case 'R':
  530. - reservenum = strtol(optarg, NULL, 0);
  531. + reservenum = strtoul(optarg, NULL, 0);
  532. break;
  533. case 'S':
  534. minsize = strtol(optarg, NULL, 0);
  535. @@ -359,8 +359,6 @@ int main(int argc, char *argv[])
  536. #endif
  537. } else if (streq(outform, "dtb")) {
  538. dt_to_blob(outf, dti, outversion);
  539. - } else if (streq(outform, "dtbo")) {
  540. - dt_to_blob(outf, dti, outversion);
  541. } else if (streq(outform, "asm")) {
  542. dt_to_asm(outf, dti, outversion);
  543. } else if (streq(outform, "null")) {
  544. --- a/scripts/dtc/dtc.h
  545. +++ b/scripts/dtc/dtc.h
  546. @@ -35,7 +35,7 @@
  547. * Command line options
  548. */
  549. extern int quiet; /* Level of quietness */
  550. -extern int reservenum; /* Number of memory reservation slots */
  551. +extern unsigned int reservenum; /* Number of memory reservation slots */
  552. extern int minsize; /* Minimum blob size */
  553. extern int padsize; /* Additional padding to blob */
  554. extern int alignsize; /* Additional padding to blob accroding to the alignsize */
  555. @@ -51,6 +51,11 @@ extern int annotate; /* annotate .dts w
  556. typedef uint32_t cell_t;
  557. +static inline bool phandle_is_valid(cell_t phandle)
  558. +{
  559. + return phandle != 0 && phandle != ~0U;
  560. +}
  561. +
  562. static inline uint16_t dtb_ld16(const void *p)
  563. {
  564. const uint8_t *bp = (const uint8_t *)p;
  565. @@ -86,6 +91,16 @@ static inline uint64_t dtb_ld64(const vo
  566. #define streq(a, b) (strcmp((a), (b)) == 0)
  567. #define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
  568. #define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
  569. +static inline bool strends(const char *str, const char *suffix)
  570. +{
  571. + unsigned int len, suffix_len;
  572. +
  573. + len = strlen(str);
  574. + suffix_len = strlen(suffix);
  575. + if (len < suffix_len)
  576. + return false;
  577. + return streq(str + len - suffix_len, suffix);
  578. +}
  579. #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
  580. @@ -101,6 +116,12 @@ enum markertype {
  581. TYPE_UINT64,
  582. TYPE_STRING,
  583. };
  584. +
  585. +static inline bool is_type_marker(enum markertype type)
  586. +{
  587. + return type >= TYPE_UINT8;
  588. +}
  589. +
  590. extern const char *markername(enum markertype markertype);
  591. struct marker {
  592. @@ -125,7 +146,22 @@ struct data {
  593. for_each_marker(m) \
  594. if ((m)->type == (t))
  595. -size_t type_marker_length(struct marker *m);
  596. +static inline struct marker *next_type_marker(struct marker *m)
  597. +{
  598. + for_each_marker(m)
  599. + if (is_type_marker(m->type))
  600. + break;
  601. + return m;
  602. +}
  603. +
  604. +static inline size_t type_marker_length(struct marker *m)
  605. +{
  606. + struct marker *next = next_type_marker(m->next);
  607. +
  608. + if (next)
  609. + return next->offset - m->offset;
  610. + return 0;
  611. +}
  612. void data_free(struct data d);
  613. --- a/scripts/dtc/flattree.c
  614. +++ b/scripts/dtc/flattree.c
  615. @@ -124,7 +124,8 @@ static void asm_emit_cell(void *e, cell_
  616. {
  617. FILE *f = e;
  618. - fprintf(f, "\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n",
  619. + fprintf(f, "\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n"
  620. + "\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n",
  621. (val >> 24) & 0xff, (val >> 16) & 0xff,
  622. (val >> 8) & 0xff, val & 0xff);
  623. }
  624. @@ -134,9 +135,9 @@ static void asm_emit_string(void *e, con
  625. FILE *f = e;
  626. if (len != 0)
  627. - fprintf(f, "\t.string\t\"%.*s\"\n", len, str);
  628. + fprintf(f, "\t.asciz\t\"%.*s\"\n", len, str);
  629. else
  630. - fprintf(f, "\t.string\t\"%s\"\n", str);
  631. + fprintf(f, "\t.asciz\t\"%s\"\n", str);
  632. }
  633. static void asm_emit_align(void *e, int a)
  634. @@ -295,7 +296,7 @@ static struct data flatten_reserve_list(
  635. {
  636. struct reserve_info *re;
  637. struct data d = empty_data;
  638. - int j;
  639. + unsigned int j;
  640. for (re = reservelist; re; re = re->next) {
  641. d = data_append_re(d, re->address, re->size);
  642. @@ -438,7 +439,7 @@ static void dump_stringtable_asm(FILE *f
  643. while (p < (strbuf.val + strbuf.len)) {
  644. len = strlen(p);
  645. - fprintf(f, "\t.string \"%s\"\n", p);
  646. + fprintf(f, "\t.asciz \"%s\"\n", p);
  647. p += len+1;
  648. }
  649. }
  650. --- a/scripts/dtc/libfdt/fdt.c
  651. +++ b/scripts/dtc/libfdt/fdt.c
  652. @@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
  653. {
  654. size_t hdrsize;
  655. + /* The device tree must be at an 8-byte aligned address */
  656. + if ((uintptr_t)fdt & 7)
  657. + return -FDT_ERR_ALIGNMENT;
  658. +
  659. if (fdt_magic(fdt) != FDT_MAGIC)
  660. return -FDT_ERR_BADMAGIC;
  661. if (!can_assume(LATEST)) {
  662. --- a/scripts/dtc/libfdt/fdt_rw.c
  663. +++ b/scripts/dtc/libfdt/fdt_rw.c
  664. @@ -349,7 +349,10 @@ int fdt_add_subnode_namelen(void *fdt, i
  665. return offset;
  666. /* Try to place the new node after the parent's properties */
  667. - fdt_next_tag(fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
  668. + tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
  669. + /* the fdt_subnode_offset_namelen() should ensure this never hits */
  670. + if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE))
  671. + return -FDT_ERR_INTERNAL;
  672. do {
  673. offset = nextoffset;
  674. tag = fdt_next_tag(fdt, offset, &nextoffset);
  675. @@ -391,7 +394,9 @@ int fdt_del_node(void *fdt, int nodeoffs
  676. }
  677. static void fdt_packblocks_(const char *old, char *new,
  678. - int mem_rsv_size, int struct_size)
  679. + int mem_rsv_size,
  680. + int struct_size,
  681. + int strings_size)
  682. {
  683. int mem_rsv_off, struct_off, strings_off;
  684. @@ -406,8 +411,7 @@ static void fdt_packblocks_(const char *
  685. fdt_set_off_dt_struct(new, struct_off);
  686. fdt_set_size_dt_struct(new, struct_size);
  687. - memmove(new + strings_off, old + fdt_off_dt_strings(old),
  688. - fdt_size_dt_strings(old));
  689. + memmove(new + strings_off, old + fdt_off_dt_strings(old), strings_size);
  690. fdt_set_off_dt_strings(new, strings_off);
  691. fdt_set_size_dt_strings(new, fdt_size_dt_strings(old));
  692. }
  693. @@ -467,7 +471,8 @@ int fdt_open_into(const void *fdt, void
  694. return -FDT_ERR_NOSPACE;
  695. }
  696. - fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size);
  697. + fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size,
  698. + fdt_size_dt_strings(fdt));
  699. memmove(buf, tmp, newsize);
  700. fdt_set_magic(buf, FDT_MAGIC);
  701. @@ -487,7 +492,8 @@ int fdt_pack(void *fdt)
  702. mem_rsv_size = (fdt_num_mem_rsv(fdt)+1)
  703. * sizeof(struct fdt_reserve_entry);
  704. - fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt));
  705. + fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt),
  706. + fdt_size_dt_strings(fdt));
  707. fdt_set_totalsize(fdt, fdt_data_size_(fdt));
  708. return 0;
  709. --- a/scripts/dtc/libfdt/fdt_strerror.c
  710. +++ b/scripts/dtc/libfdt/fdt_strerror.c
  711. @@ -39,6 +39,7 @@ static struct fdt_errtabent fdt_errtable
  712. FDT_ERRTABENT(FDT_ERR_BADOVERLAY),
  713. FDT_ERRTABENT(FDT_ERR_NOPHANDLES),
  714. FDT_ERRTABENT(FDT_ERR_BADFLAGS),
  715. + FDT_ERRTABENT(FDT_ERR_ALIGNMENT),
  716. };
  717. #define FDT_ERRTABSIZE ((int)(sizeof(fdt_errtable) / sizeof(fdt_errtable[0])))
  718. --- a/scripts/dtc/libfdt/libfdt.h
  719. +++ b/scripts/dtc/libfdt/libfdt.h
  720. @@ -131,6 +131,13 @@ uint32_t fdt_next_tag(const void *fdt, i
  721. * to work even with unaligned pointers on platforms (such as ARMv5) that don't
  722. * like unaligned loads and stores.
  723. */
  724. +static inline uint16_t fdt16_ld(const fdt16_t *p)
  725. +{
  726. + const uint8_t *bp = (const uint8_t *)p;
  727. +
  728. + return ((uint16_t)bp[0] << 8) | bp[1];
  729. +}
  730. +
  731. static inline uint32_t fdt32_ld(const fdt32_t *p)
  732. {
  733. const uint8_t *bp = (const uint8_t *)p;
  734. --- a/scripts/dtc/livetree.c
  735. +++ b/scripts/dtc/livetree.c
  736. @@ -526,7 +526,7 @@ struct node *get_node_by_path(struct nod
  737. p = strchr(path, '/');
  738. for_each_child(tree, child) {
  739. - if (p && strprefixeq(path, p - path, child->name))
  740. + if (p && strprefixeq(path, (size_t)(p - path), child->name))
  741. return get_node_by_path(child, p+1);
  742. else if (!p && streq(path, child->name))
  743. return child;
  744. @@ -559,7 +559,7 @@ struct node *get_node_by_phandle(struct
  745. {
  746. struct node *child, *node;
  747. - if ((phandle == 0) || (phandle == -1)) {
  748. + if (!phandle_is_valid(phandle)) {
  749. assert(generate_fixups);
  750. return NULL;
  751. }
  752. @@ -594,7 +594,7 @@ cell_t get_node_phandle(struct node *roo
  753. static cell_t phandle = 1; /* FIXME: ick, static local */
  754. struct data d = empty_data;
  755. - if ((node->phandle != 0) && (node->phandle != -1))
  756. + if (phandle_is_valid(node->phandle))
  757. return node->phandle;
  758. while (get_node_by_phandle(root, phandle))
  759. --- a/scripts/dtc/treesource.c
  760. +++ b/scripts/dtc/treesource.c
  761. @@ -124,27 +124,6 @@ static void write_propval_int(FILE *f, c
  762. }
  763. }
  764. -static bool has_data_type_information(struct marker *m)
  765. -{
  766. - return m->type >= TYPE_UINT8;
  767. -}
  768. -
  769. -static struct marker *next_type_marker(struct marker *m)
  770. -{
  771. - while (m && !has_data_type_information(m))
  772. - m = m->next;
  773. - return m;
  774. -}
  775. -
  776. -size_t type_marker_length(struct marker *m)
  777. -{
  778. - struct marker *next = next_type_marker(m->next);
  779. -
  780. - if (next)
  781. - return next->offset - m->offset;
  782. - return 0;
  783. -}
  784. -
  785. static const char *delim_start[] = {
  786. [TYPE_UINT8] = "[",
  787. [TYPE_UINT16] = "/bits/ 16 <",
  788. @@ -229,26 +208,39 @@ static void write_propval(FILE *f, struc
  789. size_t chunk_len = (m->next ? m->next->offset : len) - m->offset;
  790. size_t data_len = type_marker_length(m) ? : len - m->offset;
  791. const char *p = &prop->val.val[m->offset];
  792. + struct marker *m_phandle;
  793. - if (has_data_type_information(m)) {
  794. + if (is_type_marker(m->type)) {
  795. emit_type = m->type;
  796. fprintf(f, " %s", delim_start[emit_type]);
  797. } else if (m->type == LABEL)
  798. fprintf(f, " %s:", m->ref);
  799. - else if (m->offset)
  800. - fputc(' ', f);
  801. - if (emit_type == TYPE_NONE) {
  802. - assert(chunk_len == 0);
  803. + if (emit_type == TYPE_NONE || chunk_len == 0)
  804. continue;
  805. - }
  806. switch(emit_type) {
  807. case TYPE_UINT16:
  808. write_propval_int(f, p, chunk_len, 2);
  809. break;
  810. case TYPE_UINT32:
  811. - write_propval_int(f, p, chunk_len, 4);
  812. + m_phandle = prop->val.markers;
  813. + for_each_marker_of_type(m_phandle, REF_PHANDLE)
  814. + if (m->offset == m_phandle->offset)
  815. + break;
  816. +
  817. + if (m_phandle) {
  818. + if (m_phandle->ref[0] == '/')
  819. + fprintf(f, "&{%s}", m_phandle->ref);
  820. + else
  821. + fprintf(f, "&%s", m_phandle->ref);
  822. + if (chunk_len > 4) {
  823. + fputc(' ', f);
  824. + write_propval_int(f, p + 4, chunk_len - 4, 4);
  825. + }
  826. + } else {
  827. + write_propval_int(f, p, chunk_len, 4);
  828. + }
  829. break;
  830. case TYPE_UINT64:
  831. write_propval_int(f, p, chunk_len, 8);
  832. --- a/scripts/dtc/util.h
  833. +++ b/scripts/dtc/util.h
  834. @@ -13,10 +13,10 @@
  835. */
  836. #ifdef __GNUC__
  837. -#ifdef __clang__
  838. -#define PRINTF(i, j) __attribute__((format (printf, i, j)))
  839. -#else
  840. +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
  841. #define PRINTF(i, j) __attribute__((format (gnu_printf, i, j)))
  842. +#else
  843. +#define PRINTF(i, j) __attribute__((format (printf, i, j)))
  844. #endif
  845. #define NORETURN __attribute__((noreturn))
  846. #else
  847. --- a/scripts/dtc/version_gen.h
  848. +++ b/scripts/dtc/version_gen.h
  849. @@ -1 +1 @@
  850. -#define DTC_VERSION "DTC 1.6.0-g183df9e9"
  851. +#define DTC_VERSION "DTC 1.6.1-g0a3a9d34"
  852. --- a/scripts/dtc/yamltree.c
  853. +++ b/scripts/dtc/yamltree.c
  854. @@ -29,11 +29,12 @@ char *yaml_error_name[] = {
  855. (emitter)->problem, __func__, __LINE__); \
  856. })
  857. -static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, char *data, unsigned int len, int width)
  858. +static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers,
  859. + char *data, unsigned int seq_offset, unsigned int len, int width)
  860. {
  861. yaml_event_t event;
  862. void *tag;
  863. - unsigned int off, start_offset = markers->offset;
  864. + unsigned int off;
  865. switch(width) {
  866. case 1: tag = "!u8"; break;
  867. @@ -66,7 +67,7 @@ static void yaml_propval_int(yaml_emitte
  868. m = markers;
  869. is_phandle = false;
  870. for_each_marker_of_type(m, REF_PHANDLE) {
  871. - if (m->offset == (start_offset + off)) {
  872. + if (m->offset == (seq_offset + off)) {
  873. is_phandle = true;
  874. break;
  875. }
  876. @@ -114,6 +115,7 @@ static void yaml_propval(yaml_emitter_t
  877. yaml_event_t event;
  878. unsigned int len = prop->val.len;
  879. struct marker *m = prop->val.markers;
  880. + struct marker *markers = prop->val.markers;
  881. /* Emit the property name */
  882. yaml_scalar_event_initialize(&event, NULL,
  883. @@ -151,19 +153,19 @@ static void yaml_propval(yaml_emitter_t
  884. switch(m->type) {
  885. case TYPE_UINT16:
  886. - yaml_propval_int(emitter, m, data, chunk_len, 2);
  887. + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 2);
  888. break;
  889. case TYPE_UINT32:
  890. - yaml_propval_int(emitter, m, data, chunk_len, 4);
  891. + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 4);
  892. break;
  893. case TYPE_UINT64:
  894. - yaml_propval_int(emitter, m, data, chunk_len, 8);
  895. + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 8);
  896. break;
  897. case TYPE_STRING:
  898. yaml_propval_string(emitter, data, chunk_len);
  899. break;
  900. default:
  901. - yaml_propval_int(emitter, m, data, chunk_len, 1);
  902. + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 1);
  903. break;
  904. }
  905. }