This adds the following commits from upstream: aadd0b65c987 checks: centralize printing of property names in failure messages 88960e398907 checks: centralize printing of node path in check_msg f1879e1a50eb Add limited read-only support for older (V2 and V3) device tree to libfdt. 37dea76e9700 srcpos: drop special handling of tab 65893da4aee0 libfdt: overlay: Add missing license 962a45ca034d Avoid installing pylibfdt when dependencies are missing cd6ea1b2bea6 Makefile: Split INSTALL out into INSTALL_{PROGRAM,LIB,DATA,SCRIPT} 51b3a16338df Makefile.tests: Add LIBDL make(1) variable for portability sake 333d533a8f4d Attempt to auto-detect stat(1) being used if not given proper invocation e54388015af1 dtc: Bump version to v1.4.6 a1fe86f380cb fdtoverlay: Switch from using alloca to malloc c8d5472de3ff tests: Improve compatibility with other platforms c81d389a10cc checks: add chosen node checks e671852042a7 checks: add aliases node checks d0c44ebe3f42 checks: check for #{size,address}-cells without child nodes 18a3d84bb802 checks: add string list check for *-names properties 8fe94fd6f19f checks: add string list check 6c5730819604 checks: add a string check for 'label' property a384191eba09 checks: fix sound-dai phandle with arg property check b260c4f610c0 Fix ambiguous grammar for devicetree rule fe667e382bac tests: Add some basic tests for the pci_bridge checks 7975f6422260 Fix widespread incorrect use of strneq(), replace with new strprefixeq() fca296445eab Add strstarts() helper function cc392f089007 tests: Check non-matching cases for fdt_node_check_compatible() bba26a5291c8 livetree: avoid assertion of orphan phandles with overlays c8f8194d76cc implement strnlen for systems that need it c8b38f65fdec libfdt: Remove leading underscores from identifiers 3b62fdaebfe5 Remove leading underscores from identifiers 2d45d1c5c65e Replace FDT_VERSION() with stringify() 2e6fe5a107b5 Fix some errors in comments b0ae9e4b0ceb tests: Correct warning in sw_tree1.c Commit c8b38f65fdec upstream ("libfdt: Remove leading underscores from identifiers") changed the multiple inclusion define protection, so the kernel's libfdt_env.h needs the corresponding update.
Showing the changes to scripts (20 of 21 files). Show all
Unified · Split
| @@ -53,26 +53,28 @@ struct check { · 52 unmodified lines | ||
| 53 | 53 | struct check **prereq; |
| 54 | 54 | }; |
| 55 | 55 | |
| 56 | −#define CHECK_ENTRY(_nm, _fn, _d, _w, _e, ...) \ | |
| 57 | − static struct check *_nm##_prereqs[] = { __VA_ARGS__ }; \ | |
| 58 | − static struct check _nm = { \ | |
| 59 | − .name = #_nm, \ | |
| 60 | − .fn = (_fn), \ | |
| 61 | − .data = (_d), \ | |
| 62 | − .warn = (_w), \ | |
| 63 | − .error = (_e), \ | |
| 56 | +#define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \ | |
| 57 | + static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \ | |
| 58 | + static struct check nm_ = { \ | |
| 59 | + .name = #nm_, \ | |
| 60 | + .fn = (fn_), \ | |
| 61 | + .data = (d_), \ | |
| 62 | + .warn = (w_), \ | |
| 63 | + .error = (e_), \ | |
| 64 | 64 | .status = UNCHECKED, \ |
| 65 | − .num_prereqs = ARRAY_SIZE(_nm##_prereqs), \ | |
| 66 | − .prereq = _nm##_prereqs, \ | |
| 65 | + .num_prereqs = ARRAY_SIZE(nm_##_prereqs), \ | |
| 66 | + .prereq = nm_##_prereqs, \ | |
| 67 | 67 | }; |
| 68 | −#define WARNING(_nm, _fn, _d, ...) \ | |
| 69 | − CHECK_ENTRY(_nm, _fn, _d, true, false, __VA_ARGS__) | |
| 70 | −#define ERROR(_nm, _fn, _d, ...) \ | |
| 71 | − CHECK_ENTRY(_nm, _fn, _d, false, true, __VA_ARGS__) | |
| 72 | −#define CHECK(_nm, _fn, _d, ...) \ | |
| 73 | − CHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__) | |
| 74 | − | |
| 75 | −static inline void PRINTF(3, 4) check_msg(struct check *c, struct dt_info *dti, | |
| 68 | +#define WARNING(nm_, fn_, d_, ...) \ | |
| 69 | + CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__) | |
| 70 | +#define ERROR(nm_, fn_, d_, ...) \ | |
| 71 | + CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__) | |
| 72 | +#define CHECK(nm_, fn_, d_, ...) \ | |
| 73 | + CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__) | |
| 74 | + | |
| 75 | +static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, | |
| 76 | + struct node *node, | |
| 77 | + struct property *prop, | |
| 76 | 78 | const char *fmt, ...) |
| 77 | 79 | { |
| 78 | 80 | va_list ap; |
| @@ -83,19 +85,33 @@ static inline void PRINTF(3, 4) check_msg(struct check *c, struct dt_info *dti, · 4 unmodified lines | ||
| 83 | 85 | fprintf(stderr, "%s: %s (%s): ", |
| 84 | 86 | strcmp(dti->outname, "-") ? dti->outname : "<stdout>", |
| 85 | 87 | (c->error) ? "ERROR" : "Warning", c->name); |
| 88 | + if (node) { | |
| 89 | + fprintf(stderr, "%s", node->fullpath); | |
| 90 | + if (prop) | |
| 91 | + fprintf(stderr, ":%s", prop->name); | |
| 92 | + fputs(": ", stderr); | |
| 93 | + } | |
| 86 | 94 | vfprintf(stderr, fmt, ap); |
| 87 | 95 | fprintf(stderr, "\n"); |
| 88 | 96 | } |
| 89 | 97 | va_end(ap); |
| 90 | 98 | } |
| 91 | 99 | |
| 92 | −#define FAIL(c, dti, ...) \ | |
| 100 | +#define FAIL(c, dti, node, ...) \ | |
| 101 | + do { \ | |
| 102 | + TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \ | |
| 103 | + (c)->status = FAILED; \ | |
| 104 | + check_msg((c), dti, node, NULL, __VA_ARGS__); \ | |
| 105 | + } while (0) | |
| 106 | + | |
| 107 | +#define FAIL_PROP(c, dti, node, prop, ...) \ | |
| 93 | 108 | do { \ |
| 94 | 109 | TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \ |
| 95 | 110 | (c)->status = FAILED; \ |
| 96 | − check_msg((c), dti, __VA_ARGS__); \ | |
| 111 | + check_msg((c), dti, node, prop, __VA_ARGS__); \ | |
| 97 | 112 | } while (0) |
| 98 | 113 | |
| 114 | + | |
| 99 | 115 | static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node) |
| 100 | 116 | { |
| 101 | 117 | struct node *child; |
| @@ -126,7 +142,7 @@ static bool run_check(struct check *c, struct dt_info *dti) · 24 unmodified lines | ||
| 126 | 142 | error = error || run_check(prq, dti); |
| 127 | 143 | if (prq->status != PASSED) { |
| 128 | 144 | c->status = PREREQ; |
| 129 | − check_msg(c, dti, "Failed prerequisite '%s'", | |
| 145 | + check_msg(c, dti, NULL, NULL, "Failed prerequisite '%s'", | |
| 130 | 146 | c->prereq[i]->name); |
| 131 | 147 | } |
| 132 | 148 | } |
| @@ -156,7 +172,7 @@ out: · 23 unmodified lines | ||
| 156 | 172 | static inline void check_always_fail(struct check *c, struct dt_info *dti, |
| 157 | 173 | struct node *node) |
| 158 | 174 | { |
| 159 | − FAIL(c, dti, "always_fail check"); | |
| 175 | + FAIL(c, dti, node, "always_fail check"); | |
| 160 | 176 | } |
| 161 | 177 | CHECK(always_fail, check_always_fail, NULL); |
| 162 | 178 | |
| @@ -171,14 +187,42 @@ static void check_is_string(struct check *c, struct dt_info *dti, · 8 unmodified lines | ||
| 171 | 187 | return; /* Not present, assumed ok */ |
| 172 | 188 | |
| 173 | 189 | if (!data_is_one_string(prop->val)) |
| 174 | − FAIL(c, dti, "\"%s\" property in %s is not a string", | |
| 175 | − propname, node->fullpath); | |
| 190 | + FAIL_PROP(c, dti, node, prop, "property is not a string"); | |
| 176 | 191 | } |
| 177 | 192 | #define WARNING_IF_NOT_STRING(nm, propname) \ |
| 178 | 193 | WARNING(nm, check_is_string, (propname)) |
| 179 | 194 | #define ERROR_IF_NOT_STRING(nm, propname) \ |
| 180 | 195 | ERROR(nm, check_is_string, (propname)) |
| 181 | 196 | |
| 197 | +static void check_is_string_list(struct check *c, struct dt_info *dti, | |
| 198 | + struct node *node) | |
| 199 | +{ | |
| 200 | + int rem, l; | |
| 201 | + struct property *prop; | |
| 202 | + char *propname = c->data; | |
| 203 | + char *str; | |
| 204 | + | |
| 205 | + prop = get_property(node, propname); | |
| 206 | + if (!prop) | |
| 207 | + return; /* Not present, assumed ok */ | |
| 208 | + | |
| 209 | + str = prop->val.val; | |
| 210 | + rem = prop->val.len; | |
| 211 | + while (rem > 0) { | |
| 212 | + l = strnlen(str, rem); | |
| 213 | + if (l == rem) { | |
| 214 | + FAIL_PROP(c, dti, node, prop, "property is not a string list"); | |
| 215 | + break; | |
| 216 | + } | |
| 217 | + rem -= l + 1; | |
| 218 | + str += l + 1; | |
| 219 | + } | |
| 220 | +} | |
| 221 | +#define WARNING_IF_NOT_STRING_LIST(nm, propname) \ | |
| 222 | + WARNING(nm, check_is_string_list, (propname)) | |
| 223 | +#define ERROR_IF_NOT_STRING_LIST(nm, propname) \ | |
| 224 | + ERROR(nm, check_is_string_list, (propname)) | |
| 225 | + | |
| 182 | 226 | static void check_is_cell(struct check *c, struct dt_info *dti, |
| 183 | 227 | struct node *node) |
| 184 | 228 | { |
| @@ -190,8 +234,7 @@ static void check_is_cell(struct check *c, struct dt_info *dti, · 5 unmodified lines | ||
| 190 | 234 | return; /* Not present, assumed ok */ |
| 191 | 235 | |
| 192 | 236 | if (prop->val.len != sizeof(cell_t)) |
| 193 | − FAIL(c, dti, "\"%s\" property in %s is not a single cell", | |
| 194 | − propname, node->fullpath); | |
| 237 | + FAIL_PROP(c, dti, node, prop, "property is not a single cell"); | |
| 195 | 238 | } |
| 196 | 239 | #define WARNING_IF_NOT_CELL(nm, propname) \ |
| 197 | 240 | WARNING(nm, check_is_cell, (propname)) |
| @@ -212,8 +255,7 @@ static void check_duplicate_node_names(struct check *c, struct dt_info *dti, · 14 unmodified lines | ||
| 212 | 255 | child2; |
| 213 | 256 | child2 = child2->next_sibling) |
| 214 | 257 | if (streq(child->name, child2->name)) |
| 215 | − FAIL(c, dti, "Duplicate node name %s", | |
| 216 | − child->fullpath); | |
| 258 | + FAIL(c, dti, node, "Duplicate node name"); | |
| 217 | 259 | } |
| 218 | 260 | ERROR(duplicate_node_names, check_duplicate_node_names, NULL); |
| 219 | 261 | |
| @@ -227,8 +269,7 @@ static void check_duplicate_property_names(struct check *c, struct dt_info *dti, · 7 unmodified lines | ||
| 227 | 269 | if (prop2->deleted) |
| 228 | 270 | continue; |
| 229 | 271 | if (streq(prop->name, prop2->name)) |
| 230 | − FAIL(c, dti, "Duplicate property name %s in %s", | |
| 231 | − prop->name, node->fullpath); | |
| 272 | + FAIL_PROP(c, dti, node, prop, "Duplicate property name"); | |
| 232 | 273 | } |
| 233 | 274 | } |
| 234 | 275 | } |
| @@ -246,8 +287,8 @@ static void check_node_name_chars(struct check *c, struct dt_info *dti, · 11 unmodified lines | ||
| 246 | 287 | int n = strspn(node->name, c->data); |
| 247 | 288 | |
| 248 | 289 | if (n < strlen(node->name)) |
| 249 | − FAIL(c, dti, "Bad character '%c' in node %s", | |
| 250 | − node->name[n], node->fullpath); | |
| 290 | + FAIL(c, dti, node, "Bad character '%c' in node name", | |
| 291 | + node->name[n]); | |
| 251 | 292 | } |
| 252 | 293 | ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@"); |
| 253 | 294 | |
| @@ -257,8 +298,8 @@ static void check_node_name_chars_strict(struct check *c, struct dt_info *dti, · 3 unmodified lines | ||
| 257 | 298 | int n = strspn(node->name, c->data); |
| 258 | 299 | |
| 259 | 300 | if (n < node->basenamelen) |
| 260 | − FAIL(c, dti, "Character '%c' not recommended in node %s", | |
| 261 | − node->name[n], node->fullpath); | |
| 301 | + FAIL(c, dti, node, "Character '%c' not recommended in node name", | |
| 302 | + node->name[n]); | |
| 262 | 303 | } |
| 263 | 304 | CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT); |
| 264 | 305 | |
| @@ -266,8 +307,7 @@ static void check_node_name_format(struct check *c, struct dt_info *dti, · 1 unmodified line | ||
| 266 | 307 | struct node *node) |
| 267 | 308 | { |
| 268 | 309 | if (strchr(get_unitname(node), '@')) |
| 269 | − FAIL(c, dti, "Node %s has multiple '@' characters in name", | |
| 270 | − node->fullpath); | |
| 310 | + FAIL(c, dti, node, "multiple '@' characters in node name"); | |
| 271 | 311 | } |
| 272 | 312 | ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars); |
| 273 | 313 | |
| @@ -285,12 +325,10 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti, · 11 unmodified lines | ||
| 285 | 325 | |
| 286 | 326 | if (prop) { |
| 287 | 327 | if (!unitname[0]) |
| 288 | − FAIL(c, dti, "Node %s has a reg or ranges property, but no unit name", | |
| 289 | − node->fullpath); | |
| 328 | + FAIL(c, dti, node, "node has a reg or ranges property, but no unit name"); | |
| 290 | 329 | } else { |
| 291 | 330 | if (unitname[0]) |
| 292 | − FAIL(c, dti, "Node %s has a unit name, but no reg property", | |
| 293 | − node->fullpath); | |
| 331 | + FAIL(c, dti, node, "node has a unit name, but no reg property"); | |
| 294 | 332 | } |
| 295 | 333 | } |
| 296 | 334 | WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL); |
| @@ -304,8 +342,8 @@ static void check_property_name_chars(struct check *c, struct dt_info *dti, · 7 unmodified lines | ||
| 304 | 342 | int n = strspn(prop->name, c->data); |
| 305 | 343 | |
| 306 | 344 | if (n < strlen(prop->name)) |
| 307 | − FAIL(c, dti, "Bad character '%c' in property name \"%s\", node %s", | |
| 308 | − prop->name[n], prop->name, node->fullpath); | |
| 345 | + FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name", | |
| 346 | + prop->name[n]); | |
| 309 | 347 | } |
| 310 | 348 | } |
| 311 | 349 | ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS); |
| @@ -336,8 +374,8 @@ static void check_property_name_chars_strict(struct check *c, · 24 unmodified lines | ||
| 336 | 374 | n = strspn(name, c->data); |
| 337 | 375 | } |
| 338 | 376 | if (n < strlen(name)) |
| 339 | − FAIL(c, dti, "Character '%c' not recommended in property name \"%s\", node %s", | |
| 340 | − name[n], prop->name, node->fullpath); | |
| 377 | + FAIL_PROP(c, dti, node, prop, "Character '%c' not recommended in property name", | |
| 378 | + name[n]); | |
| 341 | 379 | } |
| 342 | 380 | } |
| 343 | 381 | CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT); |
| @@ -370,7 +408,7 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti, · 26 unmodified lines | ||
| 370 | 408 | return; |
| 371 | 409 | |
| 372 | 410 | if ((othernode != node) || (otherprop != prop) || (othermark != mark)) |
| 373 | − FAIL(c, dti, "Duplicate label '%s' on " DESCLABEL_FMT | |
| 411 | + FAIL(c, dti, node, "Duplicate label '%s' on " DESCLABEL_FMT | |
| 374 | 412 | " and " DESCLABEL_FMT, |
| 375 | 413 | label, DESCLABEL_ARGS(node, prop, mark), |
| 376 | 414 | DESCLABEL_ARGS(othernode, otherprop, othermark)); |
| @@ -410,8 +448,8 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, · 33 unmodified lines | ||
| 410 | 448 | return 0; |
| 411 | 449 | |
| 412 | 450 | if (prop->val.len != sizeof(cell_t)) { |
| 413 | − FAIL(c, dti, "%s has bad length (%d) %s property", | |
| 414 | − node->fullpath, prop->val.len, prop->name); | |
| 451 | + FAIL_PROP(c, dti, node, prop, "bad length (%d) %s property", | |
| 452 | + prop->val.len, prop->name); | |
| 415 | 453 | return 0; |
| 416 | 454 | } |
| 417 | 455 | |
| @@ -422,8 +460,8 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, · 4 unmodified lines | ||
| 422 | 460 | /* "Set this node's phandle equal to some |
| 423 | 461 | * other node's phandle". That's nonsensical |
| 424 | 462 | * by construction. */ { |
| 425 | − FAIL(c, dti, "%s in %s is a reference to another node", | |
| 426 | − prop->name, node->fullpath); | |
| 463 | + FAIL(c, dti, node, "%s is a reference to another node", | |
| 464 | + prop->name); | |
| 427 | 465 | } |
| 428 | 466 | /* But setting this node's phandle equal to its own |
| 429 | 467 | * phandle is allowed - that means allocate a unique |
| @@ -436,8 +474,8 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, · 6 unmodified lines | ||
| 436 | 474 | phandle = propval_cell(prop); |
| 437 | 475 | |
| 438 | 476 | if ((phandle == 0) || (phandle == -1)) { |
| 439 | − FAIL(c, dti, "%s has bad value (0x%x) in %s property", | |
| 440 | − node->fullpath, phandle, prop->name); | |
| 477 | + FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property", | |
| 478 | + phandle, prop->name); | |
| 441 | 479 | return 0; |
| 442 | 480 | } |
| 443 | 481 | |
| @@ -463,16 +501,16 @@ static void check_explicit_phandles(struct check *c, struct dt_info *dti, · 19 unmodified lines | ||
| 463 | 501 | return; |
| 464 | 502 | |
| 465 | 503 | if (linux_phandle && phandle && (phandle != linux_phandle)) |
| 466 | − FAIL(c, dti, "%s has mismatching 'phandle' and 'linux,phandle'" | |
| 467 | − " properties", node->fullpath); | |
| 504 | + FAIL(c, dti, node, "mismatching 'phandle' and 'linux,phandle'" | |
| 505 | + " properties"); | |
| 468 | 506 | |
| 469 | 507 | if (linux_phandle && !phandle) |
| 470 | 508 | phandle = linux_phandle; |
| 471 | 509 | |
| 472 | 510 | other = get_node_by_phandle(root, phandle); |
| 473 | 511 | if (other && (other != node)) { |
| 474 | − FAIL(c, dti, "%s has duplicated phandle 0x%x (seen before at %s)", | |
| 475 | − node->fullpath, phandle, other->fullpath); | |
| 512 | + FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)", | |
| 513 | + phandle, other->fullpath); | |
| 476 | 514 | return; |
| 477 | 515 | } |
| 478 | 516 | |
| @@ -496,8 +534,8 @@ static void check_name_properties(struct check *c, struct dt_info *dti, · 17 unmodified lines | ||
| 496 | 534 | |
| 497 | 535 | if ((prop->val.len != node->basenamelen+1) |
| 498 | 536 | || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) { |
| 499 | − FAIL(c, dti, "\"name\" property in %s is incorrect (\"%s\" instead" | |
| 500 | − " of base node name)", node->fullpath, prop->val.val); | |
| 537 | + FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead" | |
| 538 | + " of base node name)", prop->val.val); | |
| 501 | 539 | } else { |
| 502 | 540 | /* The name property is correct, and therefore redundant. |
| 503 | 541 | * Delete it */ |
| @@ -531,7 +569,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti, · 27 unmodified lines | ||
| 531 | 569 | refnode = get_node_by_ref(dt, m->ref); |
| 532 | 570 | if (! refnode) { |
| 533 | 571 | if (!(dti->dtsflags & DTSF_PLUGIN)) |
| 534 | − FAIL(c, dti, "Reference to non-existent node or " | |
| 572 | + FAIL(c, dti, node, "Reference to non-existent node or " | |
| 535 | 573 | "label \"%s\"\n", m->ref); |
| 536 | 574 | else /* mark the entry as unresolved */ |
| 537 | 575 | *((fdt32_t *)(prop->val.val + m->offset)) = |
| @@ -563,7 +601,7 @@ static void fixup_path_references(struct check *c, struct dt_info *dti, · 25 unmodified lines | ||
| 563 | 601 | |
| 564 | 602 | refnode = get_node_by_ref(dt, m->ref); |
| 565 | 603 | if (!refnode) { |
| 566 | − FAIL(c, dti, "Reference to non-existent node or label \"%s\"\n", | |
| 604 | + FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n", | |
| 567 | 605 | m->ref); |
| 568 | 606 | continue; |
| 569 | 607 | } |
| @@ -586,6 +624,45 @@ WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells"); · 16 unmodified lines | ||
| 586 | 624 | WARNING_IF_NOT_STRING(device_type_is_string, "device_type"); |
| 587 | 625 | WARNING_IF_NOT_STRING(model_is_string, "model"); |
| 588 | 626 | WARNING_IF_NOT_STRING(status_is_string, "status"); |
| 627 | +WARNING_IF_NOT_STRING(label_is_string, "label"); | |
| 628 | + | |
| 629 | +WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible"); | |
| 630 | + | |
| 631 | +static void check_names_is_string_list(struct check *c, struct dt_info *dti, | |
| 632 | + struct node *node) | |
| 633 | +{ | |
| 634 | + struct property *prop; | |
| 635 | + | |
| 636 | + for_each_property(node, prop) { | |
| 637 | + const char *s = strrchr(prop->name, '-'); | |
| 638 | + if (!s || !streq(s, "-names")) | |
| 639 | + continue; | |
| 640 | + | |
| 641 | + c->data = prop->name; | |
| 642 | + check_is_string_list(c, dti, node); | |
| 643 | + } | |
| 644 | +} | |
| 645 | +WARNING(names_is_string_list, check_names_is_string_list, NULL); | |
| 646 | + | |
| 647 | +static void check_alias_paths(struct check *c, struct dt_info *dti, | |
| 648 | + struct node *node) | |
| 649 | +{ | |
| 650 | + struct property *prop; | |
| 651 | + | |
| 652 | + if (!streq(node->name, "aliases")) | |
| 653 | + return; | |
| 654 | + | |
| 655 | + for_each_property(node, prop) { | |
| 656 | + if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val)) { | |
| 657 | + FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)", | |
| 658 | + prop->val.val); | |
| 659 | + continue; | |
| 660 | + } | |
| 661 | + if (strspn(prop->name, LOWERCASE DIGITS "-") != strlen(prop->name)) | |
| 662 | + FAIL(c, dti, node, "aliases property name must include only lowercase and '-'"); | |
| 663 | + } | |
| 664 | +} | |
| 665 | +WARNING(alias_paths, check_alias_paths, NULL); | |
| 589 | 666 | |
| 590 | 667 | static void fixup_addr_size_cells(struct check *c, struct dt_info *dti, |
| 591 | 668 | struct node *node) |
| @@ -622,21 +699,21 @@ static void check_reg_format(struct check *c, struct dt_info *dti, · 30 unmodified lines | ||
| 622 | 699 | return; /* No "reg", that's fine */ |
| 623 | 700 | |
| 624 | 701 | if (!node->parent) { |
| 625 | − FAIL(c, dti, "Root node has a \"reg\" property"); | |
| 702 | + FAIL(c, dti, node, "Root node has a \"reg\" property"); | |
| 626 | 703 | return; |
| 627 | 704 | } |
| 628 | 705 | |
| 629 | 706 | if (prop->val.len == 0) |
| 630 | − FAIL(c, dti, "\"reg\" property in %s is empty", node->fullpath); | |
| 707 | + FAIL_PROP(c, dti, node, prop, "property is empty"); | |
| 631 | 708 | |
| 632 | 709 | addr_cells = node_addr_cells(node->parent); |
| 633 | 710 | size_cells = node_size_cells(node->parent); |
| 634 | 711 | entrylen = (addr_cells + size_cells) * sizeof(cell_t); |
| 635 | 712 | |
| 636 | 713 | if (!entrylen || (prop->val.len % entrylen) != 0) |
| 637 | − FAIL(c, dti, "\"reg\" property in %s has invalid length (%d bytes) " | |
| 638 | − "(#address-cells == %d, #size-cells == %d)", | |
| 639 | − node->fullpath, prop->val.len, addr_cells, size_cells); | |
| 714 | + FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) " | |
| 715 | + "(#address-cells == %d, #size-cells == %d)", | |
| 716 | + prop->val.len, addr_cells, size_cells); | |
| 640 | 717 | } |
| 641 | 718 | WARNING(reg_format, check_reg_format, NULL, &addr_size_cells); |
| 642 | 719 | |
| @@ -651,7 +728,7 @@ static void check_ranges_format(struct check *c, struct dt_info *dti, · 8 unmodified lines | ||
| 651 | 728 | return; |
| 652 | 729 | |
| 653 | 730 | if (!node->parent) { |
| 654 | − FAIL(c, dti, "Root node has a \"ranges\" property"); | |
| 731 | + FAIL_PROP(c, dti, node, prop, "Root node has a \"ranges\" property"); | |
| 655 | 732 | return; |
| 656 | 733 | } |
| 657 | 734 | |
| @@ -663,20 +740,20 @@ static void check_ranges_format(struct check *c, struct dt_info *dti, · 5 unmodified lines | ||
| 663 | 740 | |
| 664 | 741 | if (prop->val.len == 0) { |
| 665 | 742 | if (p_addr_cells != c_addr_cells) |
| 666 | − FAIL(c, dti, "%s has empty \"ranges\" property but its " | |
| 667 | − "#address-cells (%d) differs from %s (%d)", | |
| 668 | − node->fullpath, c_addr_cells, node->parent->fullpath, | |
| 669 | − p_addr_cells); | |
| 743 | + FAIL_PROP(c, dti, node, prop, "empty \"ranges\" property but its " | |
| 744 | + "#address-cells (%d) differs from %s (%d)", | |
| 745 | + c_addr_cells, node->parent->fullpath, | |
| 746 | + p_addr_cells); | |
| 670 | 747 | if (p_size_cells != c_size_cells) |
| 671 | − FAIL(c, dti, "%s has empty \"ranges\" property but its " | |
| 672 | − "#size-cells (%d) differs from %s (%d)", | |
| 673 | − node->fullpath, c_size_cells, node->parent->fullpath, | |
| 674 | − p_size_cells); | |
| 748 | + FAIL_PROP(c, dti, node, prop, "empty \"ranges\" property but its " | |
| 749 | + "#size-cells (%d) differs from %s (%d)", | |
| 750 | + c_size_cells, node->parent->fullpath, | |
| 751 | + p_size_cells); | |
| 675 | 752 | } else if ((prop->val.len % entrylen) != 0) { |
| 676 | − FAIL(c, dti, "\"ranges\" property in %s has invalid length (%d bytes) " | |
| 677 | − "(parent #address-cells == %d, child #address-cells == %d, " | |
| 678 | − "#size-cells == %d)", node->fullpath, prop->val.len, | |
| 679 | − p_addr_cells, c_addr_cells, c_size_cells); | |
| 753 | + FAIL_PROP(c, dti, node, prop, "\"ranges\" property has invalid length (%d bytes) " | |
| 754 | + "(parent #address-cells == %d, child #address-cells == %d, " | |
| 755 | + "#size-cells == %d)", prop->val.len, | |
| 756 | + p_addr_cells, c_addr_cells, c_size_cells); | |
| 680 | 757 | } |
| 681 | 758 | } |
| 682 | 759 | WARNING(ranges_format, check_ranges_format, NULL, &addr_size_cells); |
| @@ -696,41 +773,33 @@ static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node * · 13 unmodified lines | ||
| 696 | 773 | |
| 697 | 774 | node->bus = &pci_bus; |
| 698 | 775 | |
| 699 | − if (!strneq(node->name, "pci", node->basenamelen) && | |
| 700 | − !strneq(node->name, "pcie", node->basenamelen)) | |
| 701 | − FAIL(c, dti, "Node %s node name is not \"pci\" or \"pcie\"", | |
| 702 | − node->fullpath); | |
| 776 | + if (!strprefixeq(node->name, node->basenamelen, "pci") && | |
| 777 | + !strprefixeq(node->name, node->basenamelen, "pcie")) | |
| 778 | + FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\""); | |
| 703 | 779 | |
| 704 | 780 | prop = get_property(node, "ranges"); |
| 705 | 781 | if (!prop) |
| 706 | − FAIL(c, dti, "Node %s missing ranges for PCI bridge (or not a bridge)", | |
| 707 | − node->fullpath); | |
| 782 | + FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)"); | |
| 708 | 783 | |
| 709 | 784 | if (node_addr_cells(node) != 3) |
| 710 | − FAIL(c, dti, "Node %s incorrect #address-cells for PCI bridge", | |
| 711 | − node->fullpath); | |
| 785 | + FAIL(c, dti, node, "incorrect #address-cells for PCI bridge"); | |
| 712 | 786 | if (node_size_cells(node) != 2) |
| 713 | − FAIL(c, dti, "Node %s incorrect #size-cells for PCI bridge", | |
| 714 | − node->fullpath); | |
| 787 | + FAIL(c, dti, node, "incorrect #size-cells for PCI bridge"); | |
| 715 | 788 | |
| 716 | 789 | prop = get_property(node, "bus-range"); |
| 717 | 790 | if (!prop) { |
| 718 | − FAIL(c, dti, "Node %s missing bus-range for PCI bridge", | |
| 719 | − node->fullpath); | |
| 791 | + FAIL(c, dti, node, "missing bus-range for PCI bridge"); | |
| 720 | 792 | return; |
| 721 | 793 | } |
| 722 | 794 | if (prop->val.len != (sizeof(cell_t) * 2)) { |
| 723 | − FAIL(c, dti, "Node %s bus-range must be 2 cells", | |
| 724 | − node->fullpath); | |
| 795 | + FAIL_PROP(c, dti, node, prop, "value must be 2 cells"); | |
| 725 | 796 | return; |
| 726 | 797 | } |
| 727 | 798 | cells = (cell_t *)prop->val.val; |
| 728 | 799 | if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1])) |
| 729 | − FAIL(c, dti, "Node %s bus-range 1st cell must be less than or equal to 2nd cell", | |
| 730 | − node->fullpath); | |
| 800 | + FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell"); | |
| 731 | 801 | if (fdt32_to_cpu(cells[1]) > 0xff) |
| 732 | − FAIL(c, dti, "Node %s bus-range maximum bus number must be less than 256", | |
| 733 | − node->fullpath); | |
| 802 | + FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256"); | |
| 734 | 803 | } |
| 735 | 804 | WARNING(pci_bridge, check_pci_bridge, NULL, |
| 736 | 805 | &device_type_is_string, &addr_size_cells); |
| @@ -760,8 +829,8 @@ static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struc · 23 unmodified lines | ||
| 760 | 829 | max_bus = fdt32_to_cpu(cells[0]); |
| 761 | 830 | } |
| 762 | 831 | if ((bus_num < min_bus) || (bus_num > max_bus)) |
| 763 | − FAIL(c, dti, "Node %s PCI bus number %d out of range, expected (%d - %d)", | |
| 764 | − node->fullpath, bus_num, min_bus, max_bus); | |
| 832 | + FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)", | |
| 833 | + bus_num, min_bus, max_bus); | |
| 765 | 834 | } |
| 766 | 835 | WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, ®_format, &pci_bridge); |
| 767 | 836 | |
| @@ -778,25 +847,22 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct no · 10 unmodified lines | ||
| 778 | 847 | |
| 779 | 848 | prop = get_property(node, "reg"); |
| 780 | 849 | if (!prop) { |
| 781 | − FAIL(c, dti, "Node %s missing PCI reg property", node->fullpath); | |
| 850 | + FAIL(c, dti, node, "missing PCI reg property"); | |
| 782 | 851 | return; |
| 783 | 852 | } |
| 784 | 853 | |
| 785 | 854 | cells = (cell_t *)prop->val.val; |
| 786 | 855 | if (cells[1] || cells[2]) |
| 787 | − FAIL(c, dti, "Node %s PCI reg config space address cells 2 and 3 must be 0", | |
| 788 | − node->fullpath); | |
| 856 | + FAIL_PROP(c, dti, node, prop, "PCI reg config space address cells 2 and 3 must be 0"); | |
| 789 | 857 | |
| 790 | 858 | reg = fdt32_to_cpu(cells[0]); |
| 791 | 859 | dev = (reg & 0xf800) >> 11; |
| 792 | 860 | func = (reg & 0x700) >> 8; |
| 793 | 861 | |
| 794 | 862 | if (reg & 0xff000000) |
| 795 | − FAIL(c, dti, "Node %s PCI reg address is not configuration space", | |
| 796 | − node->fullpath); | |
| 863 | + FAIL_PROP(c, dti, node, prop, "PCI reg address is not configuration space"); | |
| 797 | 864 | if (reg & 0x000000ff) |
| 798 | − FAIL(c, dti, "Node %s PCI reg config space address register number must be 0", | |
| 799 | − node->fullpath); | |
| 865 | + FAIL_PROP(c, dti, node, prop, "PCI reg config space address register number must be 0"); | |
| 800 | 866 | |
| 801 | 867 | if (func == 0) { |
| 802 | 868 | snprintf(unit_addr, sizeof(unit_addr), "%x", dev); |
| @@ -808,8 +874,8 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct no · 5 unmodified lines | ||
| 808 | 874 | if (streq(unitname, unit_addr)) |
| 809 | 875 | return; |
| 810 | 876 | |
| 811 | − FAIL(c, dti, "Node %s PCI unit address format error, expected \"%s\"", | |
| 812 | − node->fullpath, unit_addr); | |
| 877 | + FAIL(c, dti, node, "PCI unit address format error, expected \"%s\"", | |
| 878 | + unit_addr); | |
| 813 | 879 | } |
| 814 | 880 | WARNING(pci_device_reg, check_pci_device_reg, NULL, ®_format, &pci_bridge); |
| 815 | 881 | |
| @@ -828,7 +894,7 @@ static bool node_is_compatible(struct node *node, const char *compat) · 12 unmodified lines | ||
| 828 | 894 | |
| 829 | 895 | for (str = prop->val.val, end = str + prop->val.len; str < end; |
| 830 | 896 | str += strnlen(str, end - str) + 1) { |
| 831 | − if (strneq(str, compat, end - str)) | |
| 897 | + if (strprefixeq(str, end - str, compat)) | |
| 832 | 898 | return true; |
| 833 | 899 | } |
| 834 | 900 | return false; |
| @@ -865,7 +931,7 @@ static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct no · 30 unmodified lines | ||
| 865 | 931 | |
| 866 | 932 | if (!cells) { |
| 867 | 933 | if (node->parent->parent && !(node->bus == &simple_bus)) |
| 868 | − FAIL(c, dti, "Node %s missing or empty reg/ranges property", node->fullpath); | |
| 934 | + FAIL(c, dti, node, "missing or empty reg/ranges property"); | |
| 869 | 935 | return; |
| 870 | 936 | } |
| 871 | 937 | |
| @@ -875,8 +941,8 @@ static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct no · 3 unmodified lines | ||
| 875 | 941 | |
| 876 | 942 | snprintf(unit_addr, sizeof(unit_addr), "%"PRIx64, reg); |
| 877 | 943 | if (!streq(unitname, unit_addr)) |
| 878 | − FAIL(c, dti, "Node %s simple-bus unit address format error, expected \"%s\"", | |
| 879 | − node->fullpath, unit_addr); | |
| 944 | + FAIL(c, dti, node, "simple-bus unit address format error, expected \"%s\"", | |
| 945 | + unit_addr); | |
| 880 | 946 | } |
| 881 | 947 | WARNING(simple_bus_reg, check_simple_bus_reg, NULL, ®_format, &simple_bus_bridge); |
| 882 | 948 | |
| @@ -892,14 +958,12 @@ static void check_unit_address_format(struct check *c, struct dt_info *dti, · 9 unmodified lines | ||
| 892 | 958 | return; |
| 893 | 959 | |
| 894 | 960 | if (!strncmp(unitname, "0x", 2)) { |
| 895 | − FAIL(c, dti, "Node %s unit name should not have leading \"0x\"", | |
| 896 | − node->fullpath); | |
| 961 | + FAIL(c, dti, node, "unit name should not have leading \"0x\""); | |
| 897 | 962 | /* skip over 0x for next test */ |
| 898 | 963 | unitname += 2; |
| 899 | 964 | } |
| 900 | 965 | if (unitname[0] == '0' && isxdigit(unitname[1])) |
| 901 | − FAIL(c, dti, "Node %s unit name should not have leading 0s", | |
| 902 | − node->fullpath); | |
| 966 | + FAIL(c, dti, node, "unit name should not have leading 0s"); | |
| 903 | 967 | } |
| 904 | 968 | WARNING(unit_address_format, check_unit_address_format, NULL, |
| 905 | 969 | &node_name_format, &pci_bridge, &simple_bus_bridge); |
| @@ -922,16 +986,38 @@ static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti, · 16 unmodified lines | ||
| 922 | 986 | return; |
| 923 | 987 | |
| 924 | 988 | if (node->parent->addr_cells == -1) |
| 925 | − FAIL(c, dti, "Relying on default #address-cells value for %s", | |
| 926 | − node->fullpath); | |
| 989 | + FAIL(c, dti, node, "Relying on default #address-cells value"); | |
| 927 | 990 | |
| 928 | 991 | if (node->parent->size_cells == -1) |
| 929 | − FAIL(c, dti, "Relying on default #size-cells value for %s", | |
| 930 | − node->fullpath); | |
| 992 | + FAIL(c, dti, node, "Relying on default #size-cells value"); | |
| 931 | 993 | } |
| 932 | 994 | WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL, |
| 933 | 995 | &addr_size_cells); |
| 934 | 996 | |
| 997 | +static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti, | |
| 998 | + struct node *node) | |
| 999 | +{ | |
| 1000 | + struct property *prop; | |
| 1001 | + struct node *child; | |
| 1002 | + bool has_reg = false; | |
| 1003 | + | |
| 1004 | + if (!node->parent || node->addr_cells < 0 || node->size_cells < 0) | |
| 1005 | + return; | |
| 1006 | + | |
| 1007 | + if (get_property(node, "ranges") || !node->children) | |
| 1008 | + return; | |
| 1009 | + | |
| 1010 | + for_each_child(node, child) { | |
| 1011 | + prop = get_property(child, "reg"); | |
| 1012 | + if (prop) | |
| 1013 | + has_reg = true; | |
| 1014 | + } | |
| 1015 | + | |
| 1016 | + if (!has_reg) | |
| 1017 | + FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property"); | |
| 1018 | +} | |
| 1019 | +WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size); | |
| 1020 | + | |
| 935 | 1021 | static void check_obsolete_chosen_interrupt_controller(struct check *c, |
| 936 | 1022 | struct dt_info *dti, |
| 937 | 1023 | struct node *node) |
| @@ -950,12 +1036,61 @@ static void check_obsolete_chosen_interrupt_controller(struct check *c, · 12 unmodified lines | ||
| 950 | 1036 | |
| 951 | 1037 | prop = get_property(chosen, "interrupt-controller"); |
| 952 | 1038 | if (prop) |
| 953 | − FAIL(c, dti, "/chosen has obsolete \"interrupt-controller\" " | |
| 954 | − "property"); | |
| 1039 | + FAIL_PROP(c, dti, node, prop, | |
| 1040 | + "/chosen has obsolete \"interrupt-controller\" property"); | |
| 955 | 1041 | } |
| 956 | 1042 | WARNING(obsolete_chosen_interrupt_controller, |
| 957 | 1043 | check_obsolete_chosen_interrupt_controller, NULL); |
| 958 | 1044 | |
| 1045 | +static void check_chosen_node_is_root(struct check *c, struct dt_info *dti, | |
| 1046 | + struct node *node) | |
| 1047 | +{ | |
| 1048 | + if (!streq(node->name, "chosen")) | |
| 1049 | + return; | |
| 1050 | + | |
| 1051 | + if (node->parent != dti->dt) | |
| 1052 | + FAIL(c, dti, node, "chosen node must be at root node"); | |
| 1053 | +} | |
| 1054 | +WARNING(chosen_node_is_root, check_chosen_node_is_root, NULL); | |
| 1055 | + | |
| 1056 | +static void check_chosen_node_bootargs(struct check *c, struct dt_info *dti, | |
| 1057 | + struct node *node) | |
| 1058 | +{ | |
| 1059 | + struct property *prop; | |
| 1060 | + | |
| 1061 | + if (!streq(node->name, "chosen")) | |
| 1062 | + return; | |
| 1063 | + | |
| 1064 | + prop = get_property(node, "bootargs"); | |
| 1065 | + if (!prop) | |
| 1066 | + return; | |
| 1067 | + | |
| 1068 | + c->data = prop->name; | |
| 1069 | + check_is_string(c, dti, node); | |
| 1070 | +} | |
| 1071 | +WARNING(chosen_node_bootargs, check_chosen_node_bootargs, NULL); | |
| 1072 | + | |
| 1073 | +static void check_chosen_node_stdout_path(struct check *c, struct dt_info *dti, | |
| 1074 | + struct node *node) | |
| 1075 | +{ | |
| 1076 | + struct property *prop; | |
| 1077 | + | |
| 1078 | + if (!streq(node->name, "chosen")) | |
| 1079 | + return; | |
| 1080 | + | |
| 1081 | + prop = get_property(node, "stdout-path"); | |
| 1082 | + if (!prop) { | |
| 1083 | + prop = get_property(node, "linux,stdout-path"); | |
| 1084 | + if (!prop) | |
| 1085 | + return; | |
| 1086 | + FAIL_PROP(c, dti, node, prop, "Use 'stdout-path' instead"); | |
| 1087 | + } | |
| 1088 | + | |
| 1089 | + c->data = prop->name; | |
| 1090 | + check_is_string(c, dti, node); | |
| 1091 | +} | |
| 1092 | +WARNING(chosen_node_stdout_path, check_chosen_node_stdout_path, NULL); | |
| 1093 | + | |
| 959 | 1094 | struct provider { |
| 960 | 1095 | const char *prop_name; |
| 961 | 1096 | const char *cell_name; |
| @@ -972,8 +1107,9 @@ static void check_property_phandle_args(struct check *c, · 10 unmodified lines | ||
| 972 | 1107 | int cell, cellsize = 0; |
| 973 | 1108 | |
| 974 | 1109 | if (prop->val.len % sizeof(cell_t)) { |
| 975 | − FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s", | |
| 976 | − prop->name, prop->val.len, sizeof(cell_t), node->fullpath); | |
| 1110 | + FAIL_PROP(c, dti, node, prop, | |
| 1111 | + "property size (%d) is invalid, expected multiple of %zu", | |
| 1112 | + prop->val.len, sizeof(cell_t)); | |
| 977 | 1113 | return; |
| 978 | 1114 | } |
| 979 | 1115 | |
| @@ -1004,14 +1140,16 @@ static void check_property_phandle_args(struct check *c, · 24 unmodified lines | ||
| 1004 | 1140 | break; |
| 1005 | 1141 | } |
| 1006 | 1142 | if (!m) |
| 1007 | − FAIL(c, dti, "Property '%s', cell %d is not a phandle reference in %s", | |
| 1008 | − prop->name, cell, node->fullpath); | |
| 1143 | + FAIL_PROP(c, dti, node, prop, | |
| 1144 | + "cell %d is not a phandle reference", | |
| 1145 | + cell); | |
| 1009 | 1146 | } |
| 1010 | 1147 | |
| 1011 | 1148 | provider_node = get_node_by_phandle(root, phandle); |
| 1012 | 1149 | if (!provider_node) { |
| 1013 | − FAIL(c, dti, "Could not get phandle node for %s:%s(cell %d)", | |
| 1014 | − node->fullpath, prop->name, cell); | |
| 1150 | + FAIL_PROP(c, dti, node, prop, | |
| 1151 | + "Could not get phandle node for (cell %d)", | |
| 1152 | + cell); | |
| 1015 | 1153 | break; |
| 1016 | 1154 | } |
| 1017 | 1155 | |
| @@ -1021,16 +1159,17 @@ static void check_property_phandle_args(struct check *c, · 3 unmodified lines | ||
| 1021 | 1159 | } else if (provider->optional) { |
| 1022 | 1160 | cellsize = 0; |
| 1023 | 1161 | } else { |
| 1024 | − FAIL(c, dti, "Missing property '%s' in node %s or bad phandle (referred from %s:%s[%d])", | |
| 1162 | + FAIL(c, dti, node, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])", | |
| 1025 | 1163 | provider->cell_name, |
| 1026 | 1164 | provider_node->fullpath, |
| 1027 | − node->fullpath, prop->name, cell); | |
| 1165 | + prop->name, cell); | |
| 1028 | 1166 | break; |
| 1029 | 1167 | } |
| 1030 | 1168 | |
| 1031 | 1169 | if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) { |
| 1032 | − FAIL(c, dti, "%s property size (%d) too small for cell size %d in %s", | |
| 1033 | − prop->name, prop->val.len, cellsize, node->fullpath); | |
| 1170 | + FAIL_PROP(c, dti, node, prop, | |
| 1171 | + "property size (%d) too small for cell size %d", | |
| 1172 | + prop->val.len, cellsize); | |
| 1034 | 1173 | } |
| 1035 | 1174 | } |
| 1036 | 1175 | } |
| @@ -1066,7 +1205,7 @@ WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells"); · 29 unmodified lines | ||
| 1066 | 1205 | WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells"); |
| 1067 | 1206 | WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells"); |
| 1068 | 1207 | WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells"); |
| 1069 | −WARNING_PROPERTY_PHANDLE_CELLS(sound_dais, "sound-dais", "#sound-dai-cells"); | |
| 1208 | +WARNING_PROPERTY_PHANDLE_CELLS(sound_dai, "sound-dai", "#sound-dai-cells"); | |
| 1070 | 1209 | WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells"); |
| 1071 | 1210 | |
| 1072 | 1211 | static bool prop_is_gpio(struct property *prop) |
| @@ -1132,8 +1271,8 @@ static void check_deprecated_gpio_property(struct check *c, · 59 unmodified lines | ||
| 1132 | 1271 | if (!streq(str, "gpio")) |
| 1133 | 1272 | continue; |
| 1134 | 1273 | |
| 1135 | − FAIL(c, dti, "'[*-]gpio' is deprecated, use '[*-]gpios' instead for %s:%s", | |
| 1136 | − node->fullpath, prop->name); | |
| 1274 | + FAIL_PROP(c, dti, node, prop, | |
| 1275 | + "'[*-]gpio' is deprecated, use '[*-]gpios' instead"); | |
| 1137 | 1276 | } |
| 1138 | 1277 | |
| 1139 | 1278 | } |
| @@ -1167,9 +1306,8 @@ static void check_interrupts_property(struct check *c, · 27 unmodified lines | ||
| 1167 | 1306 | return; |
| 1168 | 1307 | |
| 1169 | 1308 | if (irq_prop->val.len % sizeof(cell_t)) |
| 1170 | − FAIL(c, dti, "property '%s' size (%d) is invalid, expected multiple of %zu in node %s", | |
| 1171 | − irq_prop->name, irq_prop->val.len, sizeof(cell_t), | |
| 1172 | − node->fullpath); | |
| 1309 | + FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu", | |
| 1310 | + irq_prop->val.len, sizeof(cell_t)); | |
| 1173 | 1311 | |
| 1174 | 1312 | while (parent && !prop) { |
| 1175 | 1313 | if (parent != node && node_is_interrupt_provider(parent)) { |
| @@ -1187,14 +1325,12 @@ static void check_interrupts_property(struct check *c, · 11 unmodified lines | ||
| 1187 | 1325 | |
| 1188 | 1326 | irq_node = get_node_by_phandle(root, phandle); |
| 1189 | 1327 | if (!irq_node) { |
| 1190 | − FAIL(c, dti, "Bad interrupt-parent phandle for %s", | |
| 1191 | − node->fullpath); | |
| 1328 | + FAIL_PROP(c, dti, parent, prop, "Bad phandle"); | |
| 1192 | 1329 | return; |
| 1193 | 1330 | } |
| 1194 | 1331 | if (!node_is_interrupt_provider(irq_node)) |
| 1195 | − FAIL(c, dti, | |
| 1196 | − "Missing interrupt-controller or interrupt-map property in %s", | |
| 1197 | − irq_node->fullpath); | |
| 1332 | + FAIL(c, dti, irq_node, | |
| 1333 | + "Missing interrupt-controller or interrupt-map property"); | |
| 1198 | 1334 | |
| 1199 | 1335 | break; |
| 1200 | 1336 | } |
| @@ -1203,23 +1339,21 @@ static void check_interrupts_property(struct check *c, · 2 unmodified lines | ||
| 1203 | 1339 | } |
| 1204 | 1340 | |
| 1205 | 1341 | if (!irq_node) { |
| 1206 | − FAIL(c, dti, "Missing interrupt-parent for %s", node->fullpath); | |
| 1342 | + FAIL(c, dti, node, "Missing interrupt-parent"); | |
| 1207 | 1343 | return; |
| 1208 | 1344 | } |
| 1209 | 1345 | |
| 1210 | 1346 | prop = get_property(irq_node, "#interrupt-cells"); |
| 1211 | 1347 | if (!prop) { |
| 1212 | − FAIL(c, dti, "Missing #interrupt-cells in interrupt-parent %s", | |
| 1213 | − irq_node->fullpath); | |
| 1348 | + FAIL(c, dti, irq_node, "Missing #interrupt-cells in interrupt-parent"); | |
| 1214 | 1349 | return; |
| 1215 | 1350 | } |
| 1216 | 1351 | |
| 1217 | 1352 | irq_cells = propval_cell(prop); |
| 1218 | 1353 | if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) { |
| 1219 | − FAIL(c, dti, | |
| 1220 | − "interrupts size is (%d), expected multiple of %d in %s", | |
| 1221 | − irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)), | |
| 1222 | − node->fullpath); | |
| 1354 | + FAIL_PROP(c, dti, node, prop, | |
| 1355 | + "size is (%d), expected multiple of %d", | |
| 1356 | + irq_prop->val.len, (int)(irq_cells * sizeof(cell_t))); | |
| 1223 | 1357 | } |
| 1224 | 1358 | } |
| 1225 | 1359 | WARNING(interrupts_property, check_interrupts_property, &phandle_references); |
| @@ -1236,6 +1370,9 @@ static struct check *check_table[] = { · 10 unmodified lines | ||
| 1236 | 1370 | |
| 1237 | 1371 | &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, |
| 1238 | 1372 | &device_type_is_string, &model_is_string, &status_is_string, |
| 1373 | + &label_is_string, | |
| 1374 | + | |
| 1375 | + &compatible_is_string_list, &names_is_string_list, | |
| 1239 | 1376 | |
| 1240 | 1377 | &property_name_chars_strict, |
| 1241 | 1378 | &node_name_chars_strict, |
| @@ -1253,7 +1390,9 @@ static struct check *check_table[] = { · 11 unmodified lines | ||
| 1253 | 1390 | &simple_bus_reg, |
| 1254 | 1391 | |
| 1255 | 1392 | &avoid_default_addr_size, |
| 1393 | + &avoid_unnecessary_addr_size, | |
| 1256 | 1394 | &obsolete_chosen_interrupt_controller, |
| 1395 | + &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path, | |
| 1257 | 1396 | |
| 1258 | 1397 | &clocks_property, |
| 1259 | 1398 | &cooling_device_property, |
| @@ -1269,13 +1408,15 @@ static struct check *check_table[] = { · 9 unmodified lines | ||
| 1269 | 1408 | &power_domains_property, |
| 1270 | 1409 | &pwms_property, |
| 1271 | 1410 | &resets_property, |
| 1272 | − &sound_dais_property, | |
| 1411 | + &sound_dai_property, | |
| 1273 | 1412 | &thermal_sensors_property, |
| 1274 | 1413 | |
| 1275 | 1414 | &deprecated_gpio_property, |
| 1276 | 1415 | &gpios_property, |
| 1277 | 1416 | &interrupts_property, |
| 1278 | 1417 | |
| 1418 | + &alias_paths, | |
| 1419 | + | |
| 1279 | 1420 | &always_fail, |
| 1280 | 1421 | }; |
| 1281 | 1422 | |
| @@ -166,7 +166,17 @@ devicetree: · 165 unmodified lines | ||
| 166 | 166 | { |
| 167 | 167 | $$ = merge_nodes($1, $3); |
| 168 | 168 | } |
| 169 | − | |
| 169 | + | DT_REF nodedef | |
| 170 | + { | |
| 171 | + /* | |
| 172 | + * We rely on the rule being always: | |
| 173 | + * versioninfo plugindecl memreserves devicetree | |
| 174 | + * so $-1 is what we want (plugindecl) | |
| 175 | + */ | |
| 176 | + if (!($<flags>-1 & DTSF_PLUGIN)) | |
| 177 | + ERROR(&@2, "Label or path %s not found", $1); | |
| 178 | + $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); | |
| 179 | + } | |
| 170 | 180 | | devicetree DT_LABEL DT_REF nodedef |
| 171 | 181 | { |
| 172 | 182 | struct node *target = get_node_by_ref($1, $3); |
| @@ -209,11 +219,6 @@ devicetree: · 36 unmodified lines | ||
| 209 | 219 | |
| 210 | 220 | $$ = $1; |
| 211 | 221 | } |
| 212 | − | /* empty */ | |
| 213 | − { | |
| 214 | − /* build empty node */ | |
| 215 | − $$ = name_node(build_node(NULL, NULL), ""); | |
| 216 | − } | |
| 217 | 222 | ; |
| 218 | 223 | |
| 219 | 224 | nodedef: |
| @@ -59,8 +59,6 @@ static void fill_fullpaths(struct node *tree, const char *prefix) · 58 unmodified lines | ||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /* Usage related data. */ |
| 62 | −#define FDT_VERSION(version) _FDT_VERSION(version) | |
| 63 | −#define _FDT_VERSION(version) #version | |
| 64 | 62 | static const char usage_synopsis[] = "dtc [options] <input file>"; |
| 65 | 63 | static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv"; |
| 66 | 64 | static struct option const usage_long_opts[] = { |
| @@ -98,7 +96,7 @@ static const char * const usage_opts_help[] = { · 31 unmodified lines | ||
| 98 | 96 | "\t\tdts - device tree source text\n" |
| 99 | 97 | "\t\tdtb - device tree blob\n" |
| 100 | 98 | "\t\tasm - assembler source", |
| 101 | − "\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)", | |
| 99 | + "\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)", | |
| 102 | 100 | "\n\tOutput dependency file", |
| 103 | 101 | "\n\tMake space for <number> reserve map entries (for dtb and asm output)", |
| 104 | 102 | "\n\tMake the blob at least <bytes> long (extra space)", |
| @@ -319,13 +317,14 @@ int main(int argc, char *argv[]) · 214 unmodified lines | ||
| 319 | 317 | dti->boot_cpuid_phys = cmdline_boot_cpuid; |
| 320 | 318 | |
| 321 | 319 | fill_fullpaths(dti->dt, ""); |
| 322 | − process_checks(force, dti); | |
| 323 | 320 | |
| 324 | 321 | /* on a plugin, generate by default */ |
| 325 | 322 | if (dti->dtsflags & DTSF_PLUGIN) { |
| 326 | 323 | generate_fixups = 1; |
| 327 | 324 | } |
| 328 | 325 | |
| 326 | + process_checks(force, dti); | |
| 327 | + | |
| 329 | 328 | if (auto_label_aliases) |
| 330 | 329 | generate_label_tree(dti, "aliases", false); |
| 331 | 330 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _DTC_H | |
| 2 | −#define _DTC_H | |
| 1 | +#ifndef DTC_H | |
| 2 | +#define DTC_H | |
| 3 | 3 | |
| 4 | 4 | /* |
| 5 | 5 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
| @@ -67,7 +67,8 @@ typedef uint32_t cell_t; · 61 unmodified lines | ||
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | #define streq(a, b) (strcmp((a), (b)) == 0) |
| 70 | −#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) | |
| 70 | +#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0) | |
| 71 | +#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0)) | |
| 71 | 72 | |
| 72 | 73 | #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) |
| 73 | 74 | |
| @@ -203,7 +204,7 @@ struct node *build_node_delete(void); · 129 unmodified lines | ||
| 203 | 204 | struct node *name_node(struct node *node, char *name); |
| 204 | 205 | struct node *chain_node(struct node *first, struct node *list); |
| 205 | 206 | struct node *merge_nodes(struct node *old_node, struct node *new_node); |
| 206 | −void add_orphan_node(struct node *old_node, struct node *new_node, char *ref); | |
| 207 | +struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref); | |
| 207 | 208 | |
| 208 | 209 | void add_property(struct node *node, struct property *prop); |
| 209 | 210 | void delete_property_by_name(struct node *node, char *name); |
| @@ -289,4 +290,4 @@ struct dt_info *dt_from_source(const char *f); · 79 unmodified lines | ||
| 289 | 290 | |
| 290 | 291 | struct dt_info *dt_from_fs(const char *dirname); |
| 291 | 292 | |
| 292 | −#endif /* _DTC_H */ | |
| 293 | +#endif /* DTC_H */ | |
| @@ -731,7 +731,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath) · 730 unmodified lines | ||
| 731 | 731 | |
| 732 | 732 | plen = strlen(ppath); |
| 733 | 733 | |
| 734 | − if (!strneq(ppath, cpath, plen)) | |
| 734 | + if (!strstarts(cpath, ppath)) | |
| 735 | 735 | die("Path \"%s\" is not valid as a child of \"%s\"\n", |
| 736 | 736 | cpath, ppath); |
| 737 | 737 | |
| @@ -88,7 +88,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) · 87 unmodified lines | ||
| 88 | 88 | || ((offset + len) > fdt_size_dt_struct(fdt))) |
| 89 | 89 | return NULL; |
| 90 | 90 | |
| 91 | − return _fdt_offset_ptr(fdt, offset); | |
| 91 | + return fdt_offset_ptr_(fdt, offset); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) |
| @@ -123,6 +123,9 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) · 28 unmodified lines | ||
| 123 | 123 | /* skip-name offset, length and value */ |
| 124 | 124 | offset += sizeof(struct fdt_property) - FDT_TAGSIZE |
| 125 | 125 | + fdt32_to_cpu(*lenp); |
| 126 | + if (fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 && | |
| 127 | + ((offset - fdt32_to_cpu(*lenp)) % 8) != 0) | |
| 128 | + offset += 4; | |
| 126 | 129 | break; |
| 127 | 130 | |
| 128 | 131 | case FDT_END: |
| @@ -141,7 +144,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) · 12 unmodified lines | ||
| 141 | 144 | return tag; |
| 142 | 145 | } |
| 143 | 146 | |
| 144 | −int _fdt_check_node_offset(const void *fdt, int offset) | |
| 147 | +int fdt_check_node_offset_(const void *fdt, int offset) | |
| 145 | 148 | { |
| 146 | 149 | if ((offset < 0) || (offset % FDT_TAGSIZE) |
| 147 | 150 | || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)) |
| @@ -150,7 +153,7 @@ int _fdt_check_node_offset(const void *fdt, int offset) · 2 unmodified lines | ||
| 150 | 153 | return offset; |
| 151 | 154 | } |
| 152 | 155 | |
| 153 | −int _fdt_check_prop_offset(const void *fdt, int offset) | |
| 156 | +int fdt_check_prop_offset_(const void *fdt, int offset) | |
| 154 | 157 | { |
| 155 | 158 | if ((offset < 0) || (offset % FDT_TAGSIZE) |
| 156 | 159 | || (fdt_next_tag(fdt, offset, &offset) != FDT_PROP)) |
| @@ -165,7 +168,7 @@ int fdt_next_node(const void *fdt, int offset, int *depth) · 8 unmodified lines | ||
| 165 | 168 | uint32_t tag; |
| 166 | 169 | |
| 167 | 170 | if (offset >= 0) |
| 168 | − if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0) | |
| 171 | + if ((nextoffset = fdt_check_node_offset_(fdt, offset)) < 0) | |
| 169 | 172 | return nextoffset; |
| 170 | 173 | |
| 171 | 174 | do { |
| @@ -227,7 +230,7 @@ int fdt_next_subnode(const void *fdt, int offset) · 55 unmodified lines | ||
| 227 | 230 | return offset; |
| 228 | 231 | } |
| 229 | 232 | |
| 230 | −const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) | |
| 233 | +const char *fdt_find_string_(const char *strtab, int tabsize, const char *s) | |
| 231 | 234 | { |
| 232 | 235 | int len = strlen(s) + 1; |
| 233 | 236 | const char *last = strtab + tabsize - len; |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _FDT_H | |
| 2 | −#define _FDT_H | |
| 1 | +#ifndef FDT_H | |
| 2 | +#define FDT_H | |
| 3 | 3 | /* |
| 4 | 4 | * libfdt - Flat Device Tree manipulation |
| 5 | 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
| @@ -108,4 +108,4 @@ struct fdt_property { · 102 unmodified lines | ||
| 108 | 108 | #define FDT_V16_SIZE FDT_V3_SIZE |
| 109 | 109 | #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) |
| 110 | 110 | |
| 111 | −#endif /* _FDT_H */ | |
| 111 | +#endif /* FDT_H */ | |
| @@ -1,3 +1,54 @@ | ||
| 1 | +/* | |
| 2 | + * libfdt - Flat Device Tree manipulation | |
| 3 | + * Copyright (C) 2016 Free Electrons | |
| 4 | + * Copyright (C) 2016 NextThing Co. | |
| 5 | + * | |
| 6 | + * libfdt is dual licensed: you can use it either under the terms of | |
| 7 | + * the GPL, or the BSD license, at your option. | |
| 8 | + * | |
| 9 | + * a) This library is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU General Public License as | |
| 11 | + * published by the Free Software Foundation; either version 2 of the | |
| 12 | + * License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * This library is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + * GNU General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU General Public | |
| 20 | + * License along with this library; if not, write to the Free | |
| 21 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 22 | + * MA 02110-1301 USA | |
| 23 | + * | |
| 24 | + * Alternatively, | |
| 25 | + * | |
| 26 | + * b) Redistribution and use in source and binary forms, with or | |
| 27 | + * without modification, are permitted provided that the following | |
| 28 | + * conditions are met: | |
| 29 | + * | |
| 30 | + * 1. Redistributions of source code must retain the above | |
| 31 | + * copyright notice, this list of conditions and the following | |
| 32 | + * disclaimer. | |
| 33 | + * 2. Redistributions in binary form must reproduce the above | |
| 34 | + * copyright notice, this list of conditions and the following | |
| 35 | + * disclaimer in the documentation and/or other materials | |
| 36 | + * provided with the distribution. | |
| 37 | + * | |
| 38 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
| 39 | + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
| 40 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 41 | + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 42 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 43 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 44 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
| 45 | + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 46 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 47 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 48 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 49 | + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 50 | + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 51 | + */ | |
| 1 | 52 | #include "libfdt_env.h" |
| 2 | 53 | |
| 3 | 54 | #include <fdt.h> |
| @@ -55,12 +55,13 @@ · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | #include "libfdt_internal.h" |
| 57 | 57 | |
| 58 | −static int _fdt_nodename_eq(const void *fdt, int offset, | |
| 58 | +static int fdt_nodename_eq_(const void *fdt, int offset, | |
| 59 | 59 | const char *s, int len) |
| 60 | 60 | { |
| 61 | − const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1); | |
| 61 | + int olen; | |
| 62 | + const char *p = fdt_get_name(fdt, offset, &olen); | |
| 62 | 63 | |
| 63 | − if (!p) | |
| 64 | + if (!p || olen < len) | |
| 64 | 65 | /* short match */ |
| 65 | 66 | return 0; |
| 66 | 67 | |
| @@ -80,7 +81,7 @@ const char *fdt_string(const void *fdt, int stroffset) · 13 unmodified lines | ||
| 80 | 81 | return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset; |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | −static int _fdt_string_eq(const void *fdt, int stroffset, | |
| 84 | +static int fdt_string_eq_(const void *fdt, int stroffset, | |
| 84 | 85 | const char *s, int len) |
| 85 | 86 | { |
| 86 | 87 | const char *p = fdt_string(fdt, stroffset); |
| @@ -117,8 +118,8 @@ uint32_t fdt_get_max_phandle(const void *fdt) · 30 unmodified lines | ||
| 117 | 118 | int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) |
| 118 | 119 | { |
| 119 | 120 | FDT_CHECK_HEADER(fdt); |
| 120 | − *address = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->address); | |
| 121 | − *size = fdt64_to_cpu(_fdt_mem_rsv(fdt, n)->size); | |
| 121 | + *address = fdt64_to_cpu(fdt_mem_rsv_(fdt, n)->address); | |
| 122 | + *size = fdt64_to_cpu(fdt_mem_rsv_(fdt, n)->size); | |
| 122 | 123 | return 0; |
| 123 | 124 | } |
| 124 | 125 | |
| @@ -126,12 +127,12 @@ int fdt_num_mem_rsv(const void *fdt) · 1 unmodified line | ||
| 126 | 127 | { |
| 127 | 128 | int i = 0; |
| 128 | 129 | |
| 129 | − while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0) | |
| 130 | + while (fdt64_to_cpu(fdt_mem_rsv_(fdt, i)->size) != 0) | |
| 130 | 131 | i++; |
| 131 | 132 | return i; |
| 132 | 133 | } |
| 133 | 134 | |
| 134 | −static int _nextprop(const void *fdt, int offset) | |
| 135 | +static int nextprop_(const void *fdt, int offset) | |
| 135 | 136 | { |
| 136 | 137 | uint32_t tag; |
| 137 | 138 | int nextoffset; |
| @@ -166,7 +167,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int offset, · 28 unmodified lines | ||
| 166 | 167 | (offset >= 0) && (depth >= 0); |
| 167 | 168 | offset = fdt_next_node(fdt, offset, &depth)) |
| 168 | 169 | if ((depth == 1) |
| 169 | − && _fdt_nodename_eq(fdt, offset, name, namelen)) | |
| 170 | + && fdt_nodename_eq_(fdt, offset, name, namelen)) | |
| 170 | 171 | return offset; |
| 171 | 172 | |
| 172 | 173 | if (depth < 0) |
| @@ -232,17 +233,35 @@ int fdt_path_offset(const void *fdt, const char *path) · 59 unmodified lines | ||
| 232 | 233 | |
| 233 | 234 | const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) |
| 234 | 235 | { |
| 235 | − const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); | |
| 236 | + const struct fdt_node_header *nh = fdt_offset_ptr_(fdt, nodeoffset); | |
| 237 | + const char *nameptr; | |
| 236 | 238 | int err; |
| 237 | 239 | |
| 238 | 240 | if (((err = fdt_check_header(fdt)) != 0) |
| 239 | − || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0)) | |
| 241 | + || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)) | |
| 240 | 242 | goto fail; |
| 241 | 243 | |
| 244 | + nameptr = nh->name; | |
| 245 | + | |
| 246 | + if (fdt_version(fdt) < 0x10) { | |
| 247 | + /* | |
| 248 | + * For old FDT versions, match the naming conventions of V16: | |
| 249 | + * give only the leaf name (after all /). The actual tree | |
| 250 | + * contents are loosely checked. | |
| 251 | + */ | |
| 252 | + const char *leaf; | |
| 253 | + leaf = strrchr(nameptr, '/'); | |
| 254 | + if (leaf == NULL) { | |
| 255 | + err = -FDT_ERR_BADSTRUCTURE; | |
| 256 | + goto fail; | |
| 257 | + } | |
| 258 | + nameptr = leaf+1; | |
| 259 | + } | |
| 260 | + | |
| 242 | 261 | if (len) |
| 243 | − *len = strlen(nh->name); | |
| 262 | + *len = strlen(nameptr); | |
| 244 | 263 | |
| 245 | − return nh->name; | |
| 264 | + return nameptr; | |
| 246 | 265 | |
| 247 | 266 | fail: |
| 248 | 267 | if (len) |
| @@ -254,34 +273,34 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset) · 5 unmodified lines | ||
| 254 | 273 | { |
| 255 | 274 | int offset; |
| 256 | 275 | |
| 257 | − if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) | |
| 276 | + if ((offset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) | |
| 258 | 277 | return offset; |
| 259 | 278 | |
| 260 | − return _nextprop(fdt, offset); | |
| 279 | + return nextprop_(fdt, offset); | |
| 261 | 280 | } |
| 262 | 281 | |
| 263 | 282 | int fdt_next_property_offset(const void *fdt, int offset) |
| 264 | 283 | { |
| 265 | − if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0) | |
| 284 | + if ((offset = fdt_check_prop_offset_(fdt, offset)) < 0) | |
| 266 | 285 | return offset; |
| 267 | 286 | |
| 268 | − return _nextprop(fdt, offset); | |
| 287 | + return nextprop_(fdt, offset); | |
| 269 | 288 | } |
| 270 | 289 | |
| 271 | −const struct fdt_property *fdt_get_property_by_offset(const void *fdt, | |
| 272 | − int offset, | |
| 273 | − int *lenp) | |
| 290 | +static const struct fdt_property *fdt_get_property_by_offset_(const void *fdt, | |
| 291 | + int offset, | |
| 292 | + int *lenp) | |
| 274 | 293 | { |
| 275 | 294 | int err; |
| 276 | 295 | const struct fdt_property *prop; |
| 277 | 296 | |
| 278 | − if ((err = _fdt_check_prop_offset(fdt, offset)) < 0) { | |
| 297 | + if ((err = fdt_check_prop_offset_(fdt, offset)) < 0) { | |
| 279 | 298 | if (lenp) |
| 280 | 299 | *lenp = err; |
| 281 | 300 | return NULL; |
| 282 | 301 | } |
| 283 | 302 | |
| 284 | − prop = _fdt_offset_ptr(fdt, offset); | |
| 303 | + prop = fdt_offset_ptr_(fdt, offset); | |
| 285 | 304 | |
| 286 | 305 | if (lenp) |
| 287 | 306 | *lenp = fdt32_to_cpu(prop->len); |
| @@ -289,23 +308,44 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt, · 1 unmodified line | ||
| 289 | 308 | return prop; |
| 290 | 309 | } |
| 291 | 310 | |
| 292 | −const struct fdt_property *fdt_get_property_namelen(const void *fdt, | |
| 293 | − int offset, | |
| 294 | − const char *name, | |
| 295 | − int namelen, int *lenp) | |
| 311 | +const struct fdt_property *fdt_get_property_by_offset(const void *fdt, | |
| 312 | + int offset, | |
| 313 | + int *lenp) | |
| 314 | +{ | |
| 315 | + /* Prior to version 16, properties may need realignment | |
| 316 | + * and this API does not work. fdt_getprop_*() will, however. */ | |
| 317 | + | |
| 318 | + if (fdt_version(fdt) < 0x10) { | |
| 319 | + if (lenp) | |
| 320 | + *lenp = -FDT_ERR_BADVERSION; | |
| 321 | + return NULL; | |
| 322 | + } | |
| 323 | + | |
| 324 | + return fdt_get_property_by_offset_(fdt, offset, lenp); | |
| 325 | +} | |
| 326 | + | |
| 327 | +static const struct fdt_property *fdt_get_property_namelen_(const void *fdt, | |
| 328 | + int offset, | |
| 329 | + const char *name, | |
| 330 | + int namelen, | |
| 331 | + int *lenp, | |
| 332 | + int *poffset) | |
| 296 | 333 | { |
| 297 | 334 | for (offset = fdt_first_property_offset(fdt, offset); |
| 298 | 335 | (offset >= 0); |
| 299 | 336 | (offset = fdt_next_property_offset(fdt, offset))) { |
| 300 | 337 | const struct fdt_property *prop; |
| 301 | 338 | |
| 302 | − if (!(prop = fdt_get_property_by_offset(fdt, offset, lenp))) { | |
| 339 | + if (!(prop = fdt_get_property_by_offset_(fdt, offset, lenp))) { | |
| 303 | 340 | offset = -FDT_ERR_INTERNAL; |
| 304 | 341 | break; |
| 305 | 342 | } |
| 306 | − if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff), | |
| 307 | − name, namelen)) | |
| 343 | + if (fdt_string_eq_(fdt, fdt32_to_cpu(prop->nameoff), | |
| 344 | + name, namelen)) { | |
| 345 | + if (poffset) | |
| 346 | + *poffset = offset; | |
| 308 | 347 | return prop; |
| 348 | + } | |
| 309 | 349 | } |
| 310 | 350 | |
| 311 | 351 | if (lenp) |
| @@ -313,6 +353,25 @@ const struct fdt_property *fdt_get_property_namelen(const void *fdt, · 1 unmodified line | ||
| 313 | 353 | return NULL; |
| 314 | 354 | } |
| 315 | 355 | |
| 356 | + | |
| 357 | +const struct fdt_property *fdt_get_property_namelen(const void *fdt, | |
| 358 | + int offset, | |
| 359 | + const char *name, | |
| 360 | + int namelen, int *lenp) | |
| 361 | +{ | |
| 362 | + /* Prior to version 16, properties may need realignment | |
| 363 | + * and this API does not work. fdt_getprop_*() will, however. */ | |
| 364 | + if (fdt_version(fdt) < 0x10) { | |
| 365 | + if (lenp) | |
| 366 | + *lenp = -FDT_ERR_BADVERSION; | |
| 367 | + return NULL; | |
| 368 | + } | |
| 369 | + | |
| 370 | + return fdt_get_property_namelen_(fdt, offset, name, namelen, lenp, | |
| 371 | + NULL); | |
| 372 | +} | |
| 373 | + | |
| 374 | + | |
| 316 | 375 | const struct fdt_property *fdt_get_property(const void *fdt, |
| 317 | 376 | int nodeoffset, |
| 318 | 377 | const char *name, int *lenp) |
| @@ -324,12 +383,18 @@ const struct fdt_property *fdt_get_property(const void *fdt, · 5 unmodified lines | ||
| 324 | 383 | const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, |
| 325 | 384 | const char *name, int namelen, int *lenp) |
| 326 | 385 | { |
| 386 | + int poffset; | |
| 327 | 387 | const struct fdt_property *prop; |
| 328 | 388 | |
| 329 | − prop = fdt_get_property_namelen(fdt, nodeoffset, name, namelen, lenp); | |
| 389 | + prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen, lenp, | |
| 390 | + &poffset); | |
| 330 | 391 | if (!prop) |
| 331 | 392 | return NULL; |
| 332 | 393 | |
| 394 | + /* Handle realignment */ | |
| 395 | + if (fdt_version(fdt) < 0x10 && (poffset + sizeof(*prop)) % 8 && | |
| 396 | + fdt32_to_cpu(prop->len) >= 8) | |
| 397 | + return prop->data + 4; | |
| 333 | 398 | return prop->data; |
| 334 | 399 | } |
| 335 | 400 | |
| @@ -338,11 +403,16 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset, · 2 unmodified lines | ||
| 338 | 403 | { |
| 339 | 404 | const struct fdt_property *prop; |
| 340 | 405 | |
| 341 | − prop = fdt_get_property_by_offset(fdt, offset, lenp); | |
| 406 | + prop = fdt_get_property_by_offset_(fdt, offset, lenp); | |
| 342 | 407 | if (!prop) |
| 343 | 408 | return NULL; |
| 344 | 409 | if (namep) |
| 345 | 410 | *namep = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); |
| 411 | + | |
| 412 | + /* Handle realignment */ | |
| 413 | + if (fdt_version(fdt) < 0x10 && (offset + sizeof(*prop)) % 8 && | |
| 414 | + fdt32_to_cpu(prop->len) >= 8) | |
| 415 | + return prop->data + 4; | |
| 346 | 416 | return prop->data; |
| 347 | 417 | } |
| 348 | 418 | |
| @@ -55,8 +55,8 @@ · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | #include "libfdt_internal.h" |
| 57 | 57 | |
| 58 | −static int _fdt_blocks_misordered(const void *fdt, | |
| 59 | − int mem_rsv_size, int struct_size) | |
| 58 | +static int fdt_blocks_misordered_(const void *fdt, | |
| 59 | + int mem_rsv_size, int struct_size) | |
| 60 | 60 | { |
| 61 | 61 | return (fdt_off_mem_rsvmap(fdt) < FDT_ALIGN(sizeof(struct fdt_header), 8)) |
| 62 | 62 | || (fdt_off_dt_struct(fdt) < |
| @@ -67,13 +67,13 @@ static int _fdt_blocks_misordered(const void *fdt, · 4 unmodified lines | ||
| 67 | 67 | (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | −static int _fdt_rw_check_header(void *fdt) | |
| 70 | +static int fdt_rw_check_header_(void *fdt) | |
| 71 | 71 | { |
| 72 | 72 | FDT_CHECK_HEADER(fdt); |
| 73 | 73 | |
| 74 | 74 | if (fdt_version(fdt) < 17) |
| 75 | 75 | return -FDT_ERR_BADVERSION; |
| 76 | − if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), | |
| 76 | + if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry), | |
| 77 | 77 | fdt_size_dt_struct(fdt))) |
| 78 | 78 | return -FDT_ERR_BADLAYOUT; |
| 79 | 79 | if (fdt_version(fdt) > 17) |
| @@ -84,20 +84,20 @@ static int _fdt_rw_check_header(void *fdt) · 4 unmodified lines | ||
| 84 | 84 | |
| 85 | 85 | #define FDT_RW_CHECK_HEADER(fdt) \ |
| 86 | 86 | { \ |
| 87 | − int __err; \ | |
| 88 | − if ((__err = _fdt_rw_check_header(fdt)) != 0) \ | |
| 89 | − return __err; \ | |
| 87 | + int err_; \ | |
| 88 | + if ((err_ = fdt_rw_check_header_(fdt)) != 0) \ | |
| 89 | + return err_; \ | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | −static inline int _fdt_data_size(void *fdt) | |
| 92 | +static inline int fdt_data_size_(void *fdt) | |
| 93 | 93 | { |
| 94 | 94 | return fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | −static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) | |
| 97 | +static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen) | |
| 98 | 98 | { |
| 99 | 99 | char *p = splicepoint; |
| 100 | − char *end = (char *)fdt + _fdt_data_size(fdt); | |
| 100 | + char *end = (char *)fdt + fdt_data_size_(fdt); | |
| 101 | 101 | |
| 102 | 102 | if (((p + oldlen) < p) || ((p + oldlen) > end)) |
| 103 | 103 | return -FDT_ERR_BADOFFSET; |
| @@ -109,12 +109,12 @@ static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) · 5 unmodified lines | ||
| 109 | 109 | return 0; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | −static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, | |
| 112 | +static int fdt_splice_mem_rsv_(void *fdt, struct fdt_reserve_entry *p, | |
| 113 | 113 | int oldn, int newn) |
| 114 | 114 | { |
| 115 | 115 | int delta = (newn - oldn) * sizeof(*p); |
| 116 | 116 | int err; |
| 117 | − err = _fdt_splice(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); | |
| 117 | + err = fdt_splice_(fdt, p, oldn * sizeof(*p), newn * sizeof(*p)); | |
| 118 | 118 | if (err) |
| 119 | 119 | return err; |
| 120 | 120 | fdt_set_off_dt_struct(fdt, fdt_off_dt_struct(fdt) + delta); |
| @@ -122,13 +122,13 @@ static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, · 1 unmodified line | ||
| 122 | 122 | return 0; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | −static int _fdt_splice_struct(void *fdt, void *p, | |
| 125 | +static int fdt_splice_struct_(void *fdt, void *p, | |
| 126 | 126 | int oldlen, int newlen) |
| 127 | 127 | { |
| 128 | 128 | int delta = newlen - oldlen; |
| 129 | 129 | int err; |
| 130 | 130 | |
| 131 | − if ((err = _fdt_splice(fdt, p, oldlen, newlen))) | |
| 131 | + if ((err = fdt_splice_(fdt, p, oldlen, newlen))) | |
| 132 | 132 | return err; |
| 133 | 133 | |
| 134 | 134 | fdt_set_size_dt_struct(fdt, fdt_size_dt_struct(fdt) + delta); |
| @@ -136,20 +136,20 @@ static int _fdt_splice_struct(void *fdt, void *p, · 1 unmodified line | ||
| 136 | 136 | return 0; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | −static int _fdt_splice_string(void *fdt, int newlen) | |
| 139 | +static int fdt_splice_string_(void *fdt, int newlen) | |
| 140 | 140 | { |
| 141 | 141 | void *p = (char *)fdt |
| 142 | 142 | + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt); |
| 143 | 143 | int err; |
| 144 | 144 | |
| 145 | − if ((err = _fdt_splice(fdt, p, 0, newlen))) | |
| 145 | + if ((err = fdt_splice_(fdt, p, 0, newlen))) | |
| 146 | 146 | return err; |
| 147 | 147 | |
| 148 | 148 | fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) + newlen); |
| 149 | 149 | return 0; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | −static int _fdt_find_add_string(void *fdt, const char *s) | |
| 152 | +static int fdt_find_add_string_(void *fdt, const char *s) | |
| 153 | 153 | { |
| 154 | 154 | char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); |
| 155 | 155 | const char *p; |
| @@ -157,13 +157,13 @@ static int _fdt_find_add_string(void *fdt, const char *s) · 1 unmodified line | ||
| 157 | 157 | int len = strlen(s) + 1; |
| 158 | 158 | int err; |
| 159 | 159 | |
| 160 | − p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s); | |
| 160 | + p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s); | |
| 161 | 161 | if (p) |
| 162 | 162 | /* found it */ |
| 163 | 163 | return (p - strtab); |
| 164 | 164 | |
| 165 | 165 | new = strtab + fdt_size_dt_strings(fdt); |
| 166 | − err = _fdt_splice_string(fdt, len); | |
| 166 | + err = fdt_splice_string_(fdt, len); | |
| 167 | 167 | if (err) |
| 168 | 168 | return err; |
| 169 | 169 | |
| @@ -178,8 +178,8 @@ int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) · 8 unmodified lines | ||
| 178 | 178 | |
| 179 | 179 | FDT_RW_CHECK_HEADER(fdt); |
| 180 | 180 | |
| 181 | − re = _fdt_mem_rsv_w(fdt, fdt_num_mem_rsv(fdt)); | |
| 182 | − err = _fdt_splice_mem_rsv(fdt, re, 0, 1); | |
| 181 | + re = fdt_mem_rsv_w_(fdt, fdt_num_mem_rsv(fdt)); | |
| 182 | + err = fdt_splice_mem_rsv_(fdt, re, 0, 1); | |
| 183 | 183 | if (err) |
| 184 | 184 | return err; |
| 185 | 185 | |
| @@ -190,17 +190,17 @@ int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) · 4 unmodified lines | ||
| 190 | 190 | |
| 191 | 191 | int fdt_del_mem_rsv(void *fdt, int n) |
| 192 | 192 | { |
| 193 | − struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n); | |
| 193 | + struct fdt_reserve_entry *re = fdt_mem_rsv_w_(fdt, n); | |
| 194 | 194 | |
| 195 | 195 | FDT_RW_CHECK_HEADER(fdt); |
| 196 | 196 | |
| 197 | 197 | if (n >= fdt_num_mem_rsv(fdt)) |
| 198 | 198 | return -FDT_ERR_NOTFOUND; |
| 199 | 199 | |
| 200 | − return _fdt_splice_mem_rsv(fdt, re, 1, 0); | |
| 200 | + return fdt_splice_mem_rsv_(fdt, re, 1, 0); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | −static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, | |
| 203 | +static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name, | |
| 204 | 204 | int len, struct fdt_property **prop) |
| 205 | 205 | { |
| 206 | 206 | int oldlen; |
| @@ -210,7 +210,7 @@ static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, · 3 unmodified lines | ||
| 210 | 210 | if (!*prop) |
| 211 | 211 | return oldlen; |
| 212 | 212 | |
| 213 | − if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), | |
| 213 | + if ((err = fdt_splice_struct_(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), | |
| 214 | 214 | FDT_TAGALIGN(len)))) |
| 215 | 215 | return err; |
| 216 | 216 | |
| @@ -218,7 +218,7 @@ static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, · 1 unmodified line | ||
| 218 | 218 | return 0; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | −static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, | |
| 221 | +static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, | |
| 222 | 222 | int len, struct fdt_property **prop) |
| 223 | 223 | { |
| 224 | 224 | int proplen; |
| @@ -226,17 +226,17 @@ static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, · 1 unmodified line | ||
| 226 | 226 | int namestroff; |
| 227 | 227 | int err; |
| 228 | 228 | |
| 229 | − if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) | |
| 229 | + if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) | |
| 230 | 230 | return nextoffset; |
| 231 | 231 | |
| 232 | − namestroff = _fdt_find_add_string(fdt, name); | |
| 232 | + namestroff = fdt_find_add_string_(fdt, name); | |
| 233 | 233 | if (namestroff < 0) |
| 234 | 234 | return namestroff; |
| 235 | 235 | |
| 236 | − *prop = _fdt_offset_ptr_w(fdt, nextoffset); | |
| 236 | + *prop = fdt_offset_ptr_w_(fdt, nextoffset); | |
| 237 | 237 | proplen = sizeof(**prop) + FDT_TAGALIGN(len); |
| 238 | 238 | |
| 239 | − err = _fdt_splice_struct(fdt, *prop, 0, proplen); | |
| 239 | + err = fdt_splice_struct_(fdt, *prop, 0, proplen); | |
| 240 | 240 | if (err) |
| 241 | 241 | return err; |
| 242 | 242 | |
| @@ -260,7 +260,7 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name) · 17 unmodified lines | ||
| 260 | 260 | |
| 261 | 261 | newlen = strlen(name); |
| 262 | 262 | |
| 263 | − err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1), | |
| 263 | + err = fdt_splice_struct_(fdt, namep, FDT_TAGALIGN(oldlen+1), | |
| 264 | 264 | FDT_TAGALIGN(newlen+1)); |
| 265 | 265 | if (err) |
| 266 | 266 | return err; |
| @@ -277,9 +277,9 @@ int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, · 10 unmodified lines | ||
| 277 | 277 | |
| 278 | 278 | FDT_RW_CHECK_HEADER(fdt); |
| 279 | 279 | |
| 280 | − err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop); | |
| 280 | + err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop); | |
| 281 | 281 | if (err == -FDT_ERR_NOTFOUND) |
| 282 | − err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); | |
| 282 | + err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); | |
| 283 | 283 | if (err) |
| 284 | 284 | return err; |
| 285 | 285 | |
| @@ -313,7 +313,7 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name, · 27 unmodified lines | ||
| 313 | 313 | prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); |
| 314 | 314 | if (prop) { |
| 315 | 315 | newlen = len + oldlen; |
| 316 | − err = _fdt_splice_struct(fdt, prop->data, | |
| 316 | + err = fdt_splice_struct_(fdt, prop->data, | |
| 317 | 317 | FDT_TAGALIGN(oldlen), |
| 318 | 318 | FDT_TAGALIGN(newlen)); |
| 319 | 319 | if (err) |
| @@ -321,7 +321,7 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name, · 1 unmodified line | ||
| 321 | 321 | prop->len = cpu_to_fdt32(newlen); |
| 322 | 322 | memcpy(prop->data + oldlen, val, len); |
| 323 | 323 | } else { |
| 324 | − err = _fdt_add_property(fdt, nodeoffset, name, len, &prop); | |
| 324 | + err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); | |
| 325 | 325 | if (err) |
| 326 | 326 | return err; |
| 327 | 327 | memcpy(prop->data, val, len); |
| @@ -341,7 +341,7 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name) · 13 unmodified lines | ||
| 341 | 341 | return len; |
| 342 | 342 | |
| 343 | 343 | proplen = sizeof(*prop) + FDT_TAGALIGN(len); |
| 344 | − return _fdt_splice_struct(fdt, prop, proplen, 0); | |
| 344 | + return fdt_splice_struct_(fdt, prop, proplen, 0); | |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | int fdt_add_subnode_namelen(void *fdt, int parentoffset, |
| @@ -369,10 +369,10 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset, · 21 unmodified lines | ||
| 369 | 369 | tag = fdt_next_tag(fdt, offset, &nextoffset); |
| 370 | 370 | } while ((tag == FDT_PROP) || (tag == FDT_NOP)); |
| 371 | 371 | |
| 372 | − nh = _fdt_offset_ptr_w(fdt, offset); | |
| 372 | + nh = fdt_offset_ptr_w_(fdt, offset); | |
| 373 | 373 | nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE; |
| 374 | 374 | |
| 375 | − err = _fdt_splice_struct(fdt, nh, 0, nodelen); | |
| 375 | + err = fdt_splice_struct_(fdt, nh, 0, nodelen); | |
| 376 | 376 | if (err) |
| 377 | 377 | return err; |
| 378 | 378 | |
| @@ -396,15 +396,15 @@ int fdt_del_node(void *fdt, int nodeoffset) · 17 unmodified lines | ||
| 396 | 396 | |
| 397 | 397 | FDT_RW_CHECK_HEADER(fdt); |
| 398 | 398 | |
| 399 | − endoffset = _fdt_node_end_offset(fdt, nodeoffset); | |
| 399 | + endoffset = fdt_node_end_offset_(fdt, nodeoffset); | |
| 400 | 400 | if (endoffset < 0) |
| 401 | 401 | return endoffset; |
| 402 | 402 | |
| 403 | − return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset), | |
| 403 | + return fdt_splice_struct_(fdt, fdt_offset_ptr_w_(fdt, nodeoffset), | |
| 404 | 404 | endoffset - nodeoffset, 0); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | −static void _fdt_packblocks(const char *old, char *new, | |
| 407 | +static void fdt_packblocks_(const char *old, char *new, | |
| 408 | 408 | int mem_rsv_size, int struct_size) |
| 409 | 409 | { |
| 410 | 410 | int mem_rsv_off, struct_off, strings_off; |
| @@ -450,7 +450,7 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize) · 39 unmodified lines | ||
| 450 | 450 | return struct_size; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | − if (!_fdt_blocks_misordered(fdt, mem_rsv_size, struct_size)) { | |
| 453 | + if (!fdt_blocks_misordered_(fdt, mem_rsv_size, struct_size)) { | |
| 454 | 454 | /* no further work necessary */ |
| 455 | 455 | err = fdt_move(fdt, buf, bufsize); |
| 456 | 456 | if (err) |
| @@ -478,7 +478,7 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize) · 21 unmodified lines | ||
| 478 | 478 | return -FDT_ERR_NOSPACE; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | − _fdt_packblocks(fdt, tmp, mem_rsv_size, struct_size); | |
| 481 | + fdt_packblocks_(fdt, tmp, mem_rsv_size, struct_size); | |
| 482 | 482 | memmove(buf, tmp, newsize); |
| 483 | 483 | |
| 484 | 484 | fdt_set_magic(buf, FDT_MAGIC); |
| @@ -498,8 +498,8 @@ int fdt_pack(void *fdt) · 13 unmodified lines | ||
| 498 | 498 | |
| 499 | 499 | mem_rsv_size = (fdt_num_mem_rsv(fdt)+1) |
| 500 | 500 | * sizeof(struct fdt_reserve_entry); |
| 501 | − _fdt_packblocks(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); | |
| 502 | − fdt_set_totalsize(fdt, _fdt_data_size(fdt)); | |
| 501 | + fdt_packblocks_(fdt, fdt, mem_rsv_size, fdt_size_dt_struct(fdt)); | |
| 502 | + fdt_set_totalsize(fdt, fdt_data_size_(fdt)); | |
| 503 | 503 | |
| 504 | 504 | return 0; |
| 505 | 505 | } |
| @@ -55,7 +55,7 @@ · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | #include "libfdt_internal.h" |
| 57 | 57 | |
| 58 | −static int _fdt_sw_check_header(void *fdt) | |
| 58 | +static int fdt_sw_check_header_(void *fdt) | |
| 59 | 59 | { |
| 60 | 60 | if (fdt_magic(fdt) != FDT_SW_MAGIC) |
| 61 | 61 | return -FDT_ERR_BADMAGIC; |
| @@ -66,11 +66,11 @@ static int _fdt_sw_check_header(void *fdt) · 4 unmodified lines | ||
| 66 | 66 | #define FDT_SW_CHECK_HEADER(fdt) \ |
| 67 | 67 | { \ |
| 68 | 68 | int err; \ |
| 69 | − if ((err = _fdt_sw_check_header(fdt)) != 0) \ | |
| 69 | + if ((err = fdt_sw_check_header_(fdt)) != 0) \ | |
| 70 | 70 | return err; \ |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | −static void *_fdt_grab_space(void *fdt, size_t len) | |
| 73 | +static void *fdt_grab_space_(void *fdt, size_t len) | |
| 74 | 74 | { |
| 75 | 75 | int offset = fdt_size_dt_struct(fdt); |
| 76 | 76 | int spaceleft; |
| @@ -82,7 +82,7 @@ static void *_fdt_grab_space(void *fdt, size_t len) · 5 unmodified lines | ||
| 82 | 82 | return NULL; |
| 83 | 83 | |
| 84 | 84 | fdt_set_size_dt_struct(fdt, offset + len); |
| 85 | − return _fdt_offset_ptr_w(fdt, offset); | |
| 85 | + return fdt_offset_ptr_w_(fdt, offset); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | int fdt_create(void *buf, int bufsize) |
| @@ -174,7 +174,7 @@ int fdt_begin_node(void *fdt, const char *name) · 85 unmodified lines | ||
| 174 | 174 | |
| 175 | 175 | FDT_SW_CHECK_HEADER(fdt); |
| 176 | 176 | |
| 177 | − nh = _fdt_grab_space(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); | |
| 177 | + nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); | |
| 178 | 178 | if (! nh) |
| 179 | 179 | return -FDT_ERR_NOSPACE; |
| 180 | 180 | |
| @@ -189,7 +189,7 @@ int fdt_end_node(void *fdt) · 8 unmodified lines | ||
| 189 | 189 | |
| 190 | 190 | FDT_SW_CHECK_HEADER(fdt); |
| 191 | 191 | |
| 192 | − en = _fdt_grab_space(fdt, FDT_TAGSIZE); | |
| 192 | + en = fdt_grab_space_(fdt, FDT_TAGSIZE); | |
| 193 | 193 | if (! en) |
| 194 | 194 | return -FDT_ERR_NOSPACE; |
| 195 | 195 | |
| @@ -197,7 +197,7 @@ int fdt_end_node(void *fdt) · 1 unmodified line | ||
| 197 | 197 | return 0; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | −static int _fdt_find_add_string(void *fdt, const char *s) | |
| 200 | +static int fdt_find_add_string_(void *fdt, const char *s) | |
| 201 | 201 | { |
| 202 | 202 | char *strtab = (char *)fdt + fdt_totalsize(fdt); |
| 203 | 203 | const char *p; |
| @@ -205,7 +205,7 @@ static int _fdt_find_add_string(void *fdt, const char *s) · 1 unmodified line | ||
| 205 | 205 | int len = strlen(s) + 1; |
| 206 | 206 | int struct_top, offset; |
| 207 | 207 | |
| 208 | − p = _fdt_find_string(strtab - strtabsize, strtabsize, s); | |
| 208 | + p = fdt_find_string_(strtab - strtabsize, strtabsize, s); | |
| 209 | 209 | if (p) |
| 210 | 210 | return p - strtab; |
| 211 | 211 | |
| @@ -227,11 +227,11 @@ int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp) · 15 unmodified lines | ||
| 227 | 227 | |
| 228 | 228 | FDT_SW_CHECK_HEADER(fdt); |
| 229 | 229 | |
| 230 | − nameoff = _fdt_find_add_string(fdt, name); | |
| 230 | + nameoff = fdt_find_add_string_(fdt, name); | |
| 231 | 231 | if (nameoff == 0) |
| 232 | 232 | return -FDT_ERR_NOSPACE; |
| 233 | 233 | |
| 234 | − prop = _fdt_grab_space(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); | |
| 234 | + prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); | |
| 235 | 235 | if (! prop) |
| 236 | 236 | return -FDT_ERR_NOSPACE; |
| 237 | 237 | |
| @@ -265,7 +265,7 @@ int fdt_finish(void *fdt) · 27 unmodified lines | ||
| 265 | 265 | FDT_SW_CHECK_HEADER(fdt); |
| 266 | 266 | |
| 267 | 267 | /* Add terminator */ |
| 268 | − end = _fdt_grab_space(fdt, sizeof(*end)); | |
| 268 | + end = fdt_grab_space_(fdt, sizeof(*end)); | |
| 269 | 269 | if (! end) |
| 270 | 270 | return -FDT_ERR_NOSPACE; |
| 271 | 271 | *end = cpu_to_fdt32(FDT_END); |
| @@ -281,7 +281,7 @@ int fdt_finish(void *fdt) · 9 unmodified lines | ||
| 281 | 281 | while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) { |
| 282 | 282 | if (tag == FDT_PROP) { |
| 283 | 283 | struct fdt_property *prop = |
| 284 | − _fdt_offset_ptr_w(fdt, offset); | |
| 284 | + fdt_offset_ptr_w_(fdt, offset); | |
| 285 | 285 | int nameoff; |
| 286 | 286 | |
| 287 | 287 | nameoff = fdt32_to_cpu(prop->nameoff); |
| @@ -93,7 +93,7 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, · 92 unmodified lines | ||
| 93 | 93 | val, len); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | −static void _fdt_nop_region(void *start, int len) | |
| 96 | +static void fdt_nop_region_(void *start, int len) | |
| 97 | 97 | { |
| 98 | 98 | fdt32_t *p; |
| 99 | 99 | |
| @@ -110,12 +110,12 @@ int fdt_nop_property(void *fdt, int nodeoffset, const char *name) · 10 unmodified lines | ||
| 110 | 110 | if (!prop) |
| 111 | 111 | return len; |
| 112 | 112 | |
| 113 | − _fdt_nop_region(prop, len + sizeof(*prop)); | |
| 113 | + fdt_nop_region_(prop, len + sizeof(*prop)); | |
| 114 | 114 | |
| 115 | 115 | return 0; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | −int _fdt_node_end_offset(void *fdt, int offset) | |
| 118 | +int fdt_node_end_offset_(void *fdt, int offset) | |
| 119 | 119 | { |
| 120 | 120 | int depth = 0; |
| 121 | 121 | |
| @@ -129,11 +129,11 @@ int fdt_nop_node(void *fdt, int nodeoffset) · 7 unmodified lines | ||
| 129 | 129 | { |
| 130 | 130 | int endoffset; |
| 131 | 131 | |
| 132 | − endoffset = _fdt_node_end_offset(fdt, nodeoffset); | |
| 132 | + endoffset = fdt_node_end_offset_(fdt, nodeoffset); | |
| 133 | 133 | if (endoffset < 0) |
| 134 | 134 | return endoffset; |
| 135 | 135 | |
| 136 | − _fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0), | |
| 136 | + fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0), | |
| 137 | 137 | endoffset - nodeoffset); |
| 138 | 138 | return 0; |
| 139 | 139 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _LIBFDT_H | |
| 2 | −#define _LIBFDT_H | |
| 1 | +#ifndef LIBFDT_H | |
| 2 | +#define LIBFDT_H | |
| 3 | 3 | /* |
| 4 | 4 | * libfdt - Flat Device Tree manipulation |
| 5 | 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
| @@ -54,7 +54,7 @@ · 48 unmodified lines | ||
| 54 | 54 | #include "libfdt_env.h" |
| 55 | 55 | #include "fdt.h" |
| 56 | 56 | |
| 57 | −#define FDT_FIRST_SUPPORTED_VERSION 0x10 | |
| 57 | +#define FDT_FIRST_SUPPORTED_VERSION 0x02 | |
| 58 | 58 | #define FDT_LAST_SUPPORTED_VERSION 0x11 |
| 59 | 59 | |
| 60 | 60 | /* Error codes: informative error codes */ |
| @@ -225,23 +225,23 @@ int fdt_next_subnode(const void *fdt, int offset); · 164 unmodified lines | ||
| 225 | 225 | #define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings)) |
| 226 | 226 | #define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct)) |
| 227 | 227 | |
| 228 | −#define __fdt_set_hdr(name) \ | |
| 228 | +#define fdt_set_hdr_(name) \ | |
| 229 | 229 | static inline void fdt_set_##name(void *fdt, uint32_t val) \ |
| 230 | 230 | { \ |
| 231 | 231 | struct fdt_header *fdth = (struct fdt_header *)fdt; \ |
| 232 | 232 | fdth->name = cpu_to_fdt32(val); \ |
| 233 | 233 | } |
| 234 | −__fdt_set_hdr(magic); | |
| 235 | −__fdt_set_hdr(totalsize); | |
| 236 | −__fdt_set_hdr(off_dt_struct); | |
| 237 | −__fdt_set_hdr(off_dt_strings); | |
| 238 | −__fdt_set_hdr(off_mem_rsvmap); | |
| 239 | −__fdt_set_hdr(version); | |
| 240 | −__fdt_set_hdr(last_comp_version); | |
| 241 | −__fdt_set_hdr(boot_cpuid_phys); | |
| 242 | −__fdt_set_hdr(size_dt_strings); | |
| 243 | −__fdt_set_hdr(size_dt_struct); | |
| 244 | −#undef __fdt_set_hdr | |
| 234 | +fdt_set_hdr_(magic); | |
| 235 | +fdt_set_hdr_(totalsize); | |
| 236 | +fdt_set_hdr_(off_dt_struct); | |
| 237 | +fdt_set_hdr_(off_dt_strings); | |
| 238 | +fdt_set_hdr_(off_mem_rsvmap); | |
| 239 | +fdt_set_hdr_(version); | |
| 240 | +fdt_set_hdr_(last_comp_version); | |
| 241 | +fdt_set_hdr_(boot_cpuid_phys); | |
| 242 | +fdt_set_hdr_(size_dt_strings); | |
| 243 | +fdt_set_hdr_(size_dt_struct); | |
| 244 | +#undef fdt_set_hdr_ | |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * fdt_check_header - sanity check a device tree or possible device tree |
| @@ -527,6 +527,9 @@ int fdt_next_property_offset(const void *fdt, int offset); · 279 unmodified lines | ||
| 527 | 527 | * offset. If lenp is non-NULL, the length of the property value is |
| 528 | 528 | * also returned, in the integer pointed to by lenp. |
| 529 | 529 | * |
| 530 | + * Note that this code only works on device tree versions >= 16. fdt_getprop() | |
| 531 | + * works on all versions. | |
| 532 | + * | |
| 530 | 533 | * returns: |
| 531 | 534 | * pointer to the structure representing the property |
| 532 | 535 | * if lenp is non-NULL, *lenp contains the length of the property |
| @@ -1449,7 +1452,7 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, · 916 unmodified lines | ||
| 1449 | 1452 | const void *val, int len); |
| 1450 | 1453 | |
| 1451 | 1454 | /** |
| 1452 | − * fdt_setprop _placeholder - allocate space for a property | |
| 1455 | + * fdt_setprop_placeholder - allocate space for a property | |
| 1453 | 1456 | * @fdt: pointer to the device tree blob |
| 1454 | 1457 | * @nodeoffset: offset of the node whose property to change |
| 1455 | 1458 | * @name: name of the property to change |
| @@ -1896,4 +1899,4 @@ int fdt_overlay_apply(void *fdt, void *fdto); · 440 unmodified lines | ||
| 1896 | 1899 | |
| 1897 | 1900 | const char *fdt_strerror(int errval); |
| 1898 | 1901 | |
| 1899 | −#endif /* _LIBFDT_H */ | |
| 1902 | +#endif /* LIBFDT_H */ | |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _LIBFDT_ENV_H | |
| 2 | −#define _LIBFDT_ENV_H | |
| 1 | +#ifndef LIBFDT_ENV_H | |
| 2 | +#define LIBFDT_ENV_H | |
| 3 | 3 | /* |
| 4 | 4 | * libfdt - Flat Device Tree manipulation |
| 5 | 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
| @@ -109,4 +109,31 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x) · 103 unmodified lines | ||
| 109 | 109 | #undef CPU_TO_FDT16 |
| 110 | 110 | #undef EXTRACT_BYTE |
| 111 | 111 | |
| 112 | −#endif /* _LIBFDT_ENV_H */ | |
| 112 | +#ifdef __APPLE__ | |
| 113 | +#include <AvailabilityMacros.h> | |
| 114 | + | |
| 115 | +/* strnlen() is not available on Mac OS < 10.7 */ | |
| 116 | +# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \ | |
| 117 | + MAC_OS_X_VERSION_10_7) | |
| 118 | + | |
| 119 | +#define strnlen fdt_strnlen | |
| 120 | + | |
| 121 | +/* | |
| 122 | + * fdt_strnlen: returns the length of a string or max_count - which ever is | |
| 123 | + * smallest. | |
| 124 | + * Input 1 string: the string whose size is to be determined | |
| 125 | + * Input 2 max_count: the maximum value returned by this function | |
| 126 | + * Output: length of the string or max_count (the smallest of the two) | |
| 127 | + */ | |
| 128 | +static inline size_t fdt_strnlen(const char *string, size_t max_count) | |
| 129 | +{ | |
| 130 | + const char *p = memchr(string, 0, max_count); | |
| 131 | + return p ? p - string : max_count; | |
| 132 | +} | |
| 133 | + | |
| 134 | +#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < | |
| 135 | + MAC_OS_X_VERSION_10_7) */ | |
| 136 | + | |
| 137 | +#endif /* __APPLE__ */ | |
| 138 | + | |
| 139 | +#endif /* LIBFDT_ENV_H */ | |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _LIBFDT_INTERNAL_H | |
| 2 | −#define _LIBFDT_INTERNAL_H | |
| 1 | +#ifndef LIBFDT_INTERNAL_H | |
| 2 | +#define LIBFDT_INTERNAL_H | |
| 3 | 3 | /* |
| 4 | 4 | * libfdt - Flat Device Tree manipulation |
| 5 | 5 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
| @@ -57,27 +57,27 @@ · 51 unmodified lines | ||
| 57 | 57 | |
| 58 | 58 | #define FDT_CHECK_HEADER(fdt) \ |
| 59 | 59 | { \ |
| 60 | − int __err; \ | |
| 61 | − if ((__err = fdt_check_header(fdt)) != 0) \ | |
| 62 | − return __err; \ | |
| 60 | + int err_; \ | |
| 61 | + if ((err_ = fdt_check_header(fdt)) != 0) \ | |
| 62 | + return err_; \ | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | −int _fdt_check_node_offset(const void *fdt, int offset); | |
| 66 | −int _fdt_check_prop_offset(const void *fdt, int offset); | |
| 67 | −const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); | |
| 68 | −int _fdt_node_end_offset(void *fdt, int nodeoffset); | |
| 65 | +int fdt_check_node_offset_(const void *fdt, int offset); | |
| 66 | +int fdt_check_prop_offset_(const void *fdt, int offset); | |
| 67 | +const char *fdt_find_string_(const char *strtab, int tabsize, const char *s); | |
| 68 | +int fdt_node_end_offset_(void *fdt, int nodeoffset); | |
| 69 | 69 | |
| 70 | −static inline const void *_fdt_offset_ptr(const void *fdt, int offset) | |
| 70 | +static inline const void *fdt_offset_ptr_(const void *fdt, int offset) | |
| 71 | 71 | { |
| 72 | 72 | return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | −static inline void *_fdt_offset_ptr_w(void *fdt, int offset) | |
| 75 | +static inline void *fdt_offset_ptr_w_(void *fdt, int offset) | |
| 76 | 76 | { |
| 77 | − return (void *)(uintptr_t)_fdt_offset_ptr(fdt, offset); | |
| 77 | + return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | −static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) | |
| 80 | +static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) | |
| 81 | 81 | { |
| 82 | 82 | const struct fdt_reserve_entry *rsv_table = |
| 83 | 83 | (const struct fdt_reserve_entry *) |
| @@ -85,11 +85,11 @@ static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int · 1 unmodified line | ||
| 85 | 85 | |
| 86 | 86 | return rsv_table + n; |
| 87 | 87 | } |
| 88 | −static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) | |
| 88 | +static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) | |
| 89 | 89 | { |
| 90 | − return (void *)(uintptr_t)_fdt_mem_rsv(fdt, n); | |
| 90 | + return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | #define FDT_SW_MAGIC (~FDT_MAGIC) |
| 94 | 94 | |
| 95 | −#endif /* _LIBFDT_INTERNAL_H */ | |
| 95 | +#endif /* LIBFDT_INTERNAL_H */ | |
| @@ -216,7 +216,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node) · 215 unmodified lines | ||
| 216 | 216 | return old_node; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | −void add_orphan_node(struct node *dt, struct node *new_node, char *ref) | |
| 219 | +struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref) | |
| 220 | 220 | { |
| 221 | 221 | static unsigned int next_orphan_fragment = 0; |
| 222 | 222 | struct node *node; |
| @@ -236,6 +236,7 @@ void add_orphan_node(struct node *dt, struct node *new_node, char *ref) · 13 unmodified lines | ||
| 236 | 236 | name_node(node, name); |
| 237 | 237 | |
| 238 | 238 | add_child(dt, node); |
| 239 | + return dt; | |
| 239 | 240 | } |
| 240 | 241 | |
| 241 | 242 | struct node *chain_node(struct node *first, struct node *list) |
| @@ -507,7 +508,7 @@ struct node *get_node_by_path(struct node *tree, const char *path) · 265 unmodified lines | ||
| 507 | 508 | |
| 508 | 509 | for_each_child(tree, child) { |
| 509 | 510 | if (p && (strlen(child->name) == p-path) && |
| 510 | − strneq(path, child->name, p-path)) | |
| 511 | + strprefixeq(path, p - path, child->name)) | |
| 511 | 512 | return get_node_by_path(child, p+1); |
| 512 | 513 | else if (!p && streq(path, child->name)) |
| 513 | 514 | return child; |
| @@ -540,7 +541,10 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle) · 26 unmodified lines | ||
| 540 | 541 | { |
| 541 | 542 | struct node *child, *node; |
| 542 | 543 | |
| 543 | − assert((phandle != 0) && (phandle != -1)); | |
| 544 | + if ((phandle == 0) || (phandle == -1)) { | |
| 545 | + assert(generate_fixups); | |
| 546 | + return NULL; | |
| 547 | + } | |
| 544 | 548 | |
| 545 | 549 | if (tree->phandle == phandle) { |
| 546 | 550 | if (tree->deleted) |
| @@ -209,8 +209,6 @@ struct srcpos srcpos_empty = { · 208 unmodified lines | ||
| 209 | 209 | .file = NULL, |
| 210 | 210 | }; |
| 211 | 211 | |
| 212 | −#define TAB_SIZE 8 | |
| 213 | − | |
| 214 | 212 | void srcpos_update(struct srcpos *pos, const char *text, int len) |
| 215 | 213 | { |
| 216 | 214 | int i; |
| @@ -224,9 +222,6 @@ void srcpos_update(struct srcpos *pos, const char *text, int len) · 7 unmodified lines | ||
| 224 | 222 | if (text[i] == '\n') { |
| 225 | 223 | current_srcfile->lineno++; |
| 226 | 224 | current_srcfile->colno = 1; |
| 227 | − } else if (text[i] == '\t') { | |
| 228 | − current_srcfile->colno = | |
| 229 | − ALIGN(current_srcfile->colno, TAB_SIZE); | |
| 230 | 225 | } else { |
| 231 | 226 | current_srcfile->colno++; |
| 232 | 227 | } |
| @@ -17,8 +17,8 @@ · 16 unmodified lines | ||
| 17 | 17 | * USA |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | −#ifndef _SRCPOS_H_ | |
| 21 | −#define _SRCPOS_H_ | |
| 20 | +#ifndef SRCPOS_H | |
| 21 | +#define SRCPOS_H | |
| 22 | 22 | |
| 23 | 23 | #include <stdio.h> |
| 24 | 24 | #include <stdbool.h> |
| @@ -114,4 +114,4 @@ extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix, · 89 unmodified lines | ||
| 114 | 114 | |
| 115 | 115 | extern void srcpos_set_line(char *f, int l); |
| 116 | 116 | |
| 117 | −#endif /* _SRCPOS_H_ */ | |
| 117 | +#endif /* SRCPOS_H */ | |
| @@ -1,5 +1,5 @@ | ||
| 1 | −#ifndef _UTIL_H | |
| 2 | −#define _UTIL_H | |
| 1 | +#ifndef UTIL_H | |
| 2 | +#define UTIL_H | |
| 3 | 3 | |
| 4 | 4 | #include <stdarg.h> |
| 5 | 5 | #include <stdbool.h> |
| @@ -35,6 +35,9 @@ · 29 unmodified lines | ||
| 35 | 35 | |
| 36 | 36 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 37 | 37 | |
| 38 | +#define stringify(s) stringify_(s) | |
| 39 | +#define stringify_(s) #s | |
| 40 | + | |
| 38 | 41 | static inline void NORETURN PRINTF(1, 2) die(const char *str, ...) |
| 39 | 42 | { |
| 40 | 43 | va_list ap; |
| @@ -260,4 +263,4 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis, · 219 unmodified lines | ||
| 260 | 263 | case 'V': util_version(); \ |
| 261 | 264 | case '?': usage("unknown option"); |
| 262 | 265 | |
| 263 | −#endif /* _UTIL_H */ | |
| 266 | +#endif /* UTIL_H */ | |
| @@ -1 +1 @@ | ||
| 1 | −#define DTC_VERSION "DTC 1.4.5-gc1e55a55" | |
| 1 | +#define DTC_VERSION "DTC 1.4.6-gaadd0b65" | |