checks.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*
  2. * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
  3. *
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  18. * USA
  19. */
  20. #include "dtc.h"
  21. #ifdef TRACE_CHECKS
  22. #define TRACE(c, ...) \
  23. do { \
  24. fprintf(stderr, "=== %s: ", (c)->name); \
  25. fprintf(stderr, __VA_ARGS__); \
  26. fprintf(stderr, "\n"); \
  27. } while (0)
  28. #else
  29. #define TRACE(c, fmt, ...) do { } while (0)
  30. #endif
  31. enum checkstatus {
  32. UNCHECKED = 0,
  33. PREREQ,
  34. PASSED,
  35. FAILED,
  36. };
  37. struct check;
  38. typedef void (*tree_check_fn)(struct check *c, struct node *dt);
  39. typedef void (*node_check_fn)(struct check *c, struct node *dt, struct node *node);
  40. typedef void (*prop_check_fn)(struct check *c, struct node *dt,
  41. struct node *node, struct property *prop);
  42. struct check {
  43. const char *name;
  44. tree_check_fn tree_fn;
  45. node_check_fn node_fn;
  46. prop_check_fn prop_fn;
  47. void *data;
  48. bool warn, error;
  49. enum checkstatus status;
  50. int inprogress;
  51. int num_prereqs;
  52. struct check **prereq;
  53. };
  54. #define CHECK_ENTRY(nm, tfn, nfn, pfn, d, w, e, ...) \
  55. static struct check *nm##_prereqs[] = { __VA_ARGS__ }; \
  56. static struct check nm = { \
  57. .name = #nm, \
  58. .tree_fn = (tfn), \
  59. .node_fn = (nfn), \
  60. .prop_fn = (pfn), \
  61. .data = (d), \
  62. .warn = (w), \
  63. .error = (e), \
  64. .status = UNCHECKED, \
  65. .num_prereqs = ARRAY_SIZE(nm##_prereqs), \
  66. .prereq = nm##_prereqs, \
  67. };
  68. #define WARNING(nm, tfn, nfn, pfn, d, ...) \
  69. CHECK_ENTRY(nm, tfn, nfn, pfn, d, true, false, __VA_ARGS__)
  70. #define ERROR(nm, tfn, nfn, pfn, d, ...) \
  71. CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, true, __VA_ARGS__)
  72. #define CHECK(nm, tfn, nfn, pfn, d, ...) \
  73. CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, false, __VA_ARGS__)
  74. #define TREE_WARNING(nm, d, ...) \
  75. WARNING(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
  76. #define TREE_ERROR(nm, d, ...) \
  77. ERROR(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
  78. #define TREE_CHECK(nm, d, ...) \
  79. CHECK(nm, check_##nm, NULL, NULL, d, __VA_ARGS__)
  80. #define NODE_WARNING(nm, d, ...) \
  81. WARNING(nm, NULL, check_##nm, NULL, d, __VA_ARGS__)
  82. #define NODE_ERROR(nm, d, ...) \
  83. ERROR(nm, NULL, check_##nm, NULL, d, __VA_ARGS__)
  84. #define NODE_CHECK(nm, d, ...) \
  85. CHECK(nm, NULL, check_##nm, NULL, d, __VA_ARGS__)
  86. #define PROP_WARNING(nm, d, ...) \
  87. WARNING(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
  88. #define PROP_ERROR(nm, d, ...) \
  89. ERROR(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
  90. #define PROP_CHECK(nm, d, ...) \
  91. CHECK(nm, NULL, NULL, check_##nm, d, __VA_ARGS__)
  92. #ifdef __GNUC__
  93. static inline void check_msg(struct check *c, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
  94. #endif
  95. static inline void check_msg(struct check *c, const char *fmt, ...)
  96. {
  97. va_list ap;
  98. va_start(ap, fmt);
  99. if ((c->warn && (quiet < 1))
  100. || (c->error && (quiet < 2))) {
  101. fprintf(stderr, "%s (%s): ",
  102. (c->error) ? "ERROR" : "Warning", c->name);
  103. vfprintf(stderr, fmt, ap);
  104. fprintf(stderr, "\n");
  105. }
  106. }
  107. #define FAIL(c, ...) \
  108. do { \
  109. TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
  110. (c)->status = FAILED; \
  111. check_msg((c), __VA_ARGS__); \
  112. } while (0)
  113. static void check_nodes_props(struct check *c, struct node *dt, struct node *node)
  114. {
  115. struct node *child;
  116. struct property *prop;
  117. TRACE(c, "%s", node->fullpath);
  118. if (c->node_fn)
  119. c->node_fn(c, dt, node);
  120. if (c->prop_fn)
  121. for_each_property(node, prop) {
  122. TRACE(c, "%s\t'%s'", node->fullpath, prop->name);
  123. c->prop_fn(c, dt, node, prop);
  124. }
  125. for_each_child(node, child)
  126. check_nodes_props(c, dt, child);
  127. }
  128. static int run_check(struct check *c, struct node *dt)
  129. {
  130. int error = 0;
  131. int i;
  132. assert(!c->inprogress);
  133. if (c->status != UNCHECKED)
  134. goto out;
  135. c->inprogress = 1;
  136. for (i = 0; i < c->num_prereqs; i++) {
  137. struct check *prq = c->prereq[i];
  138. error |= run_check(prq, dt);
  139. if (prq->status != PASSED) {
  140. c->status = PREREQ;
  141. check_msg(c, "Failed prerequisite '%s'",
  142. c->prereq[i]->name);
  143. }
  144. }
  145. if (c->status != UNCHECKED)
  146. goto out;
  147. if (c->node_fn || c->prop_fn)
  148. check_nodes_props(c, dt, dt);
  149. if (c->tree_fn)
  150. c->tree_fn(c, dt);
  151. if (c->status == UNCHECKED)
  152. c->status = PASSED;
  153. TRACE(c, "\tCompleted, status %d", c->status);
  154. out:
  155. c->inprogress = 0;
  156. if ((c->status != PASSED) && (c->error))
  157. error = 1;
  158. return error;
  159. }
  160. /*
  161. * Utility check functions
  162. */
  163. /* A check which always fails, for testing purposes only */
  164. static inline void check_always_fail(struct check *c, struct node *dt)
  165. {
  166. FAIL(c, "always_fail check");
  167. }
  168. TREE_CHECK(always_fail, NULL);
  169. static void check_is_string(struct check *c, struct node *root,
  170. struct node *node)
  171. {
  172. struct property *prop;
  173. char *propname = c->data;
  174. prop = get_property(node, propname);
  175. if (!prop)
  176. return; /* Not present, assumed ok */
  177. if (!data_is_one_string(prop->val))
  178. FAIL(c, "\"%s\" property in %s is not a string",
  179. propname, node->fullpath);
  180. }
  181. #define WARNING_IF_NOT_STRING(nm, propname) \
  182. WARNING(nm, NULL, check_is_string, NULL, (propname))
  183. #define ERROR_IF_NOT_STRING(nm, propname) \
  184. ERROR(nm, NULL, check_is_string, NULL, (propname))
  185. static void check_is_cell(struct check *c, struct node *root,
  186. struct node *node)
  187. {
  188. struct property *prop;
  189. char *propname = c->data;
  190. prop = get_property(node, propname);
  191. if (!prop)
  192. return; /* Not present, assumed ok */
  193. if (prop->val.len != sizeof(cell_t))
  194. FAIL(c, "\"%s\" property in %s is not a single cell",
  195. propname, node->fullpath);
  196. }
  197. #define WARNING_IF_NOT_CELL(nm, propname) \
  198. WARNING(nm, NULL, check_is_cell, NULL, (propname))
  199. #define ERROR_IF_NOT_CELL(nm, propname) \
  200. ERROR(nm, NULL, check_is_cell, NULL, (propname))
  201. /*
  202. * Structural check functions
  203. */
  204. static void check_duplicate_node_names(struct check *c, struct node *dt,
  205. struct node *node)
  206. {
  207. struct node *child, *child2;
  208. for_each_child(node, child)
  209. for (child2 = child->next_sibling;
  210. child2;
  211. child2 = child2->next_sibling)
  212. if (streq(child->name, child2->name))
  213. FAIL(c, "Duplicate node name %s",
  214. child->fullpath);
  215. }
  216. NODE_ERROR(duplicate_node_names, NULL);
  217. static void check_duplicate_property_names(struct check *c, struct node *dt,
  218. struct node *node)
  219. {
  220. struct property *prop, *prop2;
  221. for_each_property(node, prop) {
  222. for (prop2 = prop->next; prop2; prop2 = prop2->next) {
  223. if (prop2->deleted)
  224. continue;
  225. if (streq(prop->name, prop2->name))
  226. FAIL(c, "Duplicate property name %s in %s",
  227. prop->name, node->fullpath);
  228. }
  229. }
  230. }
  231. NODE_ERROR(duplicate_property_names, NULL);
  232. #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
  233. #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  234. #define DIGITS "0123456789"
  235. #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
  236. static void check_node_name_chars(struct check *c, struct node *dt,
  237. struct node *node)
  238. {
  239. int n = strspn(node->name, c->data);
  240. if (n < strlen(node->name))
  241. FAIL(c, "Bad character '%c' in node %s",
  242. node->name[n], node->fullpath);
  243. }
  244. NODE_ERROR(node_name_chars, PROPNODECHARS "@");
  245. static void check_node_name_format(struct check *c, struct node *dt,
  246. struct node *node)
  247. {
  248. if (strchr(get_unitname(node), '@'))
  249. FAIL(c, "Node %s has multiple '@' characters in name",
  250. node->fullpath);
  251. }
  252. NODE_ERROR(node_name_format, NULL, &node_name_chars);
  253. static void check_property_name_chars(struct check *c, struct node *dt,
  254. struct node *node, struct property *prop)
  255. {
  256. int n = strspn(prop->name, c->data);
  257. if (n < strlen(prop->name))
  258. FAIL(c, "Bad character '%c' in property name \"%s\", node %s",
  259. prop->name[n], prop->name, node->fullpath);
  260. }
  261. PROP_ERROR(property_name_chars, PROPNODECHARS);
  262. #define DESCLABEL_FMT "%s%s%s%s%s"
  263. #define DESCLABEL_ARGS(node,prop,mark) \
  264. ((mark) ? "value of " : ""), \
  265. ((prop) ? "'" : ""), \
  266. ((prop) ? (prop)->name : ""), \
  267. ((prop) ? "' in " : ""), (node)->fullpath
  268. static void check_duplicate_label(struct check *c, struct node *dt,
  269. const char *label, struct node *node,
  270. struct property *prop, struct marker *mark)
  271. {
  272. struct node *othernode = NULL;
  273. struct property *otherprop = NULL;
  274. struct marker *othermark = NULL;
  275. othernode = get_node_by_label(dt, label);
  276. if (!othernode)
  277. otherprop = get_property_by_label(dt, label, &othernode);
  278. if (!othernode)
  279. othermark = get_marker_label(dt, label, &othernode,
  280. &otherprop);
  281. if (!othernode)
  282. return;
  283. if ((othernode != node) || (otherprop != prop) || (othermark != mark))
  284. FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT
  285. " and " DESCLABEL_FMT,
  286. label, DESCLABEL_ARGS(node, prop, mark),
  287. DESCLABEL_ARGS(othernode, otherprop, othermark));
  288. }
  289. static void check_duplicate_label_node(struct check *c, struct node *dt,
  290. struct node *node)
  291. {
  292. struct label *l;
  293. for_each_label(node->labels, l)
  294. check_duplicate_label(c, dt, l->label, node, NULL, NULL);
  295. }
  296. static void check_duplicate_label_prop(struct check *c, struct node *dt,
  297. struct node *node, struct property *prop)
  298. {
  299. struct marker *m = prop->val.markers;
  300. struct label *l;
  301. for_each_label(prop->labels, l)
  302. check_duplicate_label(c, dt, l->label, node, prop, NULL);
  303. for_each_marker_of_type(m, LABEL)
  304. check_duplicate_label(c, dt, m->ref, node, prop, m);
  305. }
  306. ERROR(duplicate_label, NULL, check_duplicate_label_node,
  307. check_duplicate_label_prop, NULL);
  308. static void check_explicit_phandles(struct check *c, struct node *root,
  309. struct node *node, struct property *prop)
  310. {
  311. struct marker *m;
  312. struct node *other;
  313. cell_t phandle;
  314. if (!streq(prop->name, "phandle")
  315. && !streq(prop->name, "linux,phandle"))
  316. return;
  317. if (prop->val.len != sizeof(cell_t)) {
  318. FAIL(c, "%s has bad length (%d) %s property",
  319. node->fullpath, prop->val.len, prop->name);
  320. return;
  321. }
  322. m = prop->val.markers;
  323. for_each_marker_of_type(m, REF_PHANDLE) {
  324. assert(m->offset == 0);
  325. if (node != get_node_by_ref(root, m->ref))
  326. /* "Set this node's phandle equal to some
  327. * other node's phandle". That's nonsensical
  328. * by construction. */ {
  329. FAIL(c, "%s in %s is a reference to another node",
  330. prop->name, node->fullpath);
  331. return;
  332. }
  333. /* But setting this node's phandle equal to its own
  334. * phandle is allowed - that means allocate a unique
  335. * phandle for this node, even if it's not otherwise
  336. * referenced. The value will be filled in later, so
  337. * no further checking for now. */
  338. return;
  339. }
  340. phandle = propval_cell(prop);
  341. if ((phandle == 0) || (phandle == -1)) {
  342. FAIL(c, "%s has bad value (0x%x) in %s property",
  343. node->fullpath, phandle, prop->name);
  344. return;
  345. }
  346. if (node->phandle && (node->phandle != phandle))
  347. FAIL(c, "%s has %s property which replaces existing phandle information",
  348. node->fullpath, prop->name);
  349. other = get_node_by_phandle(root, phandle);
  350. if (other && (other != node)) {
  351. FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)",
  352. node->fullpath, phandle, other->fullpath);
  353. return;
  354. }
  355. node->phandle = phandle;
  356. }
  357. PROP_ERROR(explicit_phandles, NULL);
  358. static void check_name_properties(struct check *c, struct node *root,
  359. struct node *node)
  360. {
  361. struct property **pp, *prop = NULL;
  362. for (pp = &node->proplist; *pp; pp = &((*pp)->next))
  363. if (streq((*pp)->name, "name")) {
  364. prop = *pp;
  365. break;
  366. }
  367. if (!prop)
  368. return; /* No name property, that's fine */
  369. if ((prop->val.len != node->basenamelen+1)
  370. || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
  371. FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead"
  372. " of base node name)", node->fullpath, prop->val.val);
  373. } else {
  374. /* The name property is correct, and therefore redundant.
  375. * Delete it */
  376. *pp = prop->next;
  377. free(prop->name);
  378. data_free(prop->val);
  379. free(prop);
  380. }
  381. }
  382. ERROR_IF_NOT_STRING(name_is_string, "name");
  383. NODE_ERROR(name_properties, NULL, &name_is_string);
  384. /*
  385. * Reference fixup functions
  386. */
  387. static void fixup_phandle_references(struct check *c, struct node *dt,
  388. struct node *node, struct property *prop)
  389. {
  390. struct marker *m = prop->val.markers;
  391. struct node *refnode;
  392. cell_t phandle;
  393. for_each_marker_of_type(m, REF_PHANDLE) {
  394. assert(m->offset + sizeof(cell_t) <= prop->val.len);
  395. refnode = get_node_by_ref(dt, m->ref);
  396. if (! refnode) {
  397. FAIL(c, "Reference to non-existent node or label \"%s\"\n",
  398. m->ref);
  399. continue;
  400. }
  401. phandle = get_node_phandle(dt, refnode);
  402. *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
  403. }
  404. }
  405. ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
  406. &duplicate_node_names, &explicit_phandles);
  407. static void fixup_path_references(struct check *c, struct node *dt,
  408. struct node *node, struct property *prop)
  409. {
  410. struct marker *m = prop->val.markers;
  411. struct node *refnode;
  412. char *path;
  413. for_each_marker_of_type(m, REF_PATH) {
  414. assert(m->offset <= prop->val.len);
  415. refnode = get_node_by_ref(dt, m->ref);
  416. if (!refnode) {
  417. FAIL(c, "Reference to non-existent node or label \"%s\"\n",
  418. m->ref);
  419. continue;
  420. }
  421. path = refnode->fullpath;
  422. prop->val = data_insert_at_marker(prop->val, m, path,
  423. strlen(path) + 1);
  424. }
  425. }
  426. ERROR(path_references, NULL, NULL, fixup_path_references, NULL,
  427. &duplicate_node_names);
  428. /*
  429. * Semantic checks
  430. */
  431. WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
  432. WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
  433. WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
  434. WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
  435. WARNING_IF_NOT_STRING(model_is_string, "model");
  436. WARNING_IF_NOT_STRING(status_is_string, "status");
  437. static void fixup_addr_size_cells(struct check *c, struct node *dt,
  438. struct node *node)
  439. {
  440. struct property *prop;
  441. node->addr_cells = -1;
  442. node->size_cells = -1;
  443. prop = get_property(node, "#address-cells");
  444. if (prop)
  445. node->addr_cells = propval_cell(prop);
  446. prop = get_property(node, "#size-cells");
  447. if (prop)
  448. node->size_cells = propval_cell(prop);
  449. }
  450. WARNING(addr_size_cells, NULL, fixup_addr_size_cells, NULL, NULL,
  451. &address_cells_is_cell, &size_cells_is_cell);
  452. #define node_addr_cells(n) \
  453. (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
  454. #define node_size_cells(n) \
  455. (((n)->size_cells == -1) ? 1 : (n)->size_cells)
  456. static void check_reg_format(struct check *c, struct node *dt,
  457. struct node *node)
  458. {
  459. struct property *prop;
  460. int addr_cells, size_cells, entrylen;
  461. prop = get_property(node, "reg");
  462. if (!prop)
  463. return; /* No "reg", that's fine */
  464. if (!node->parent) {
  465. FAIL(c, "Root node has a \"reg\" property");
  466. return;
  467. }
  468. if (prop->val.len == 0)
  469. FAIL(c, "\"reg\" property in %s is empty", node->fullpath);
  470. addr_cells = node_addr_cells(node->parent);
  471. size_cells = node_size_cells(node->parent);
  472. entrylen = (addr_cells + size_cells) * sizeof(cell_t);
  473. if ((prop->val.len % entrylen) != 0)
  474. FAIL(c, "\"reg\" property in %s has invalid length (%d bytes) "
  475. "(#address-cells == %d, #size-cells == %d)",
  476. node->fullpath, prop->val.len, addr_cells, size_cells);
  477. }
  478. NODE_WARNING(reg_format, NULL, &addr_size_cells);
  479. static void check_ranges_format(struct check *c, struct node *dt,
  480. struct node *node)
  481. {
  482. struct property *prop;
  483. int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
  484. prop = get_property(node, "ranges");
  485. if (!prop)
  486. return;
  487. if (!node->parent) {
  488. FAIL(c, "Root node has a \"ranges\" property");
  489. return;
  490. }
  491. p_addr_cells = node_addr_cells(node->parent);
  492. p_size_cells = node_size_cells(node->parent);
  493. c_addr_cells = node_addr_cells(node);
  494. c_size_cells = node_size_cells(node);
  495. entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
  496. if (prop->val.len == 0) {
  497. if (p_addr_cells != c_addr_cells)
  498. FAIL(c, "%s has empty \"ranges\" property but its "
  499. "#address-cells (%d) differs from %s (%d)",
  500. node->fullpath, c_addr_cells, node->parent->fullpath,
  501. p_addr_cells);
  502. if (p_size_cells != c_size_cells)
  503. FAIL(c, "%s has empty \"ranges\" property but its "
  504. "#size-cells (%d) differs from %s (%d)",
  505. node->fullpath, c_size_cells, node->parent->fullpath,
  506. p_size_cells);
  507. } else if ((prop->val.len % entrylen) != 0) {
  508. FAIL(c, "\"ranges\" property in %s has invalid length (%d bytes) "
  509. "(parent #address-cells == %d, child #address-cells == %d, "
  510. "#size-cells == %d)", node->fullpath, prop->val.len,
  511. p_addr_cells, c_addr_cells, c_size_cells);
  512. }
  513. }
  514. NODE_WARNING(ranges_format, NULL, &addr_size_cells);
  515. /*
  516. * Style checks
  517. */
  518. static void check_avoid_default_addr_size(struct check *c, struct node *dt,
  519. struct node *node)
  520. {
  521. struct property *reg, *ranges;
  522. if (!node->parent)
  523. return; /* Ignore root node */
  524. reg = get_property(node, "reg");
  525. ranges = get_property(node, "ranges");
  526. if (!reg && !ranges)
  527. return;
  528. if ((node->parent->addr_cells == -1))
  529. FAIL(c, "Relying on default #address-cells value for %s",
  530. node->fullpath);
  531. if ((node->parent->size_cells == -1))
  532. FAIL(c, "Relying on default #size-cells value for %s",
  533. node->fullpath);
  534. }
  535. NODE_WARNING(avoid_default_addr_size, NULL, &addr_size_cells);
  536. static void check_obsolete_chosen_interrupt_controller(struct check *c,
  537. struct node *dt)
  538. {
  539. struct node *chosen;
  540. struct property *prop;
  541. chosen = get_node_by_path(dt, "/chosen");
  542. if (!chosen)
  543. return;
  544. prop = get_property(chosen, "interrupt-controller");
  545. if (prop)
  546. FAIL(c, "/chosen has obsolete \"interrupt-controller\" "
  547. "property");
  548. }
  549. TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
  550. static struct check *check_table[] = {
  551. &duplicate_node_names, &duplicate_property_names,
  552. &node_name_chars, &node_name_format, &property_name_chars,
  553. &name_is_string, &name_properties,
  554. &duplicate_label,
  555. &explicit_phandles,
  556. &phandle_references, &path_references,
  557. &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
  558. &device_type_is_string, &model_is_string, &status_is_string,
  559. &addr_size_cells, &reg_format, &ranges_format,
  560. &avoid_default_addr_size,
  561. &obsolete_chosen_interrupt_controller,
  562. &always_fail,
  563. };
  564. static void enable_warning_error(struct check *c, bool warn, bool error)
  565. {
  566. int i;
  567. /* Raising level, also raise it for prereqs */
  568. if ((warn && !c->warn) || (error && !c->error))
  569. for (i = 0; i < c->num_prereqs; i++)
  570. enable_warning_error(c->prereq[i], warn, error);
  571. c->warn = c->warn || warn;
  572. c->error = c->error || error;
  573. }
  574. static void disable_warning_error(struct check *c, bool warn, bool error)
  575. {
  576. int i;
  577. /* Lowering level, also lower it for things this is the prereq
  578. * for */
  579. if ((warn && c->warn) || (error && c->error)) {
  580. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  581. struct check *cc = check_table[i];
  582. int j;
  583. for (j = 0; j < cc->num_prereqs; j++)
  584. if (cc->prereq[j] == c)
  585. disable_warning_error(cc, warn, error);
  586. }
  587. }
  588. c->warn = c->warn && !warn;
  589. c->error = c->error && !error;
  590. }
  591. void parse_checks_option(bool warn, bool error, const char *optarg)
  592. {
  593. int i;
  594. const char *name = optarg;
  595. bool enable = true;
  596. if ((strncmp(optarg, "no-", 3) == 0)
  597. || (strncmp(optarg, "no_", 3) == 0)) {
  598. name = optarg + 3;
  599. enable = false;
  600. }
  601. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  602. struct check *c = check_table[i];
  603. if (streq(c->name, name)) {
  604. if (enable)
  605. enable_warning_error(c, warn, error);
  606. else
  607. disable_warning_error(c, warn, error);
  608. return;
  609. }
  610. }
  611. die("Unrecognized check name \"%s\"\n", name);
  612. }
  613. void process_checks(int force, struct boot_info *bi)
  614. {
  615. struct node *dt = bi->dt;
  616. int i;
  617. int error = 0;
  618. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  619. struct check *c = check_table[i];
  620. if (c->warn || c->error)
  621. error = error || run_check(c, dt);
  622. }
  623. if (error) {
  624. if (!force) {
  625. fprintf(stderr, "ERROR: Input tree has errors, aborting "
  626. "(use -f to force output)\n");
  627. exit(2);
  628. } else if (quiet < 3) {
  629. fprintf(stderr, "Warning: Input tree has errors, "
  630. "output forced\n");
  631. }
  632. }
  633. }