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

scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c

This adds the following commits from upstream:

52f07dcca47c dtc: Add informative error for stray identifier
9cabae6b0351 checks: Fix detection of 'i2c-bus' node
605dc044c3fe New helper to add markers
7da5d106c740 fdtput: Fix documentation about existing nodes
53c63dd421d7 dtdiff: Use input format dtb for dtbo files
84d9dd2fcbc8 dtc: Add data_insert_data function
97011d1f4e98 meson: use override_find_program/override_dependency
b841391bbd08 srcpos: Define srcpos_free
e0b7749c26a9 Add alloc_marker
ecb21febfdd3 meson: port python bindings to build natively via meson and meson-python
7ebfcac8520e Makefile: deprecate in favor of Meson
f4c53f4ebf78 Use __ASSEMBLER__ instead of __ASSEMBLY__
205fbef17b7b Fix some typos
da85f91931e5 Remove duplicated words in documentation and comments
dd1b3e532d22 meson: support building libfdt without static library
1ccd232709d4 meson: don't build test programs by default
ce1d8588880a tests: When building .so from -O asm output mark as non-executable stack
915daadbb62d Start with empty __local_fixups__ and __fixups__ nodes
4ea851f5a44d Let get_subnode() not return deleted nodes
175d2a564c47 Use build_root_node() instead of open-coding it
18f4f305fdd7 build: fix -Dtools=false build
267efc7d4694 checks: Warn about missing #address-cells for interrupt parents
755db115355b libfdt: Add fdt_setprop_namelen_string()
bdca8612009e libfdt: Add fdt_setprop_namelen()
0f69cedc08fc libfdt_internal: fdt_find_string_len_()
56b2b30c5bd0 libfdt: add fdt_get_property_namelen_w()
1e8c5f60e127 Add clang-format config
6f183c7d9246 checks: Relax avoid_unnecessary_addr_size check to allow child ranges properties
66c7d0e6f4f3 tests/sw_tree1.c: fix unitialized saveptr
9a969f3b70b0 pylibfdt/libfdt.i: fix backwards compatibility of return values
4292b072a23a .github/workflows: update ubuntu runner to supported version
1c745a9bd169 libfdt: Remove fdt parameter from overlay_fixup_one_phandle
b3bbee6b1242 libfdt: Move the SBOM authors section
d1656730abfb Add a SBOM file in CycloneDX format
b75515af4576 libfdt: Remove extra semi-colons outside functions
2d10aa2afe35 Bump version to v1.7.2
48795c82bdb6 pylibfdt: Don't emit warnings from swig generate C code
838f11e830e3 fdtoverlay: provide better error message for missing `/__symbols__`
d1e2384185c5 pylibfdt/libfdt.i: Use SWIG_AppendOutput
18aa49a9f68d Escape spaces in depfile with backslashes.
f9968fa06921 libfdt.h: whitespace consistency fixups
9b5f65fb3d8d libfdt.h: typo and consistency fixes
99031e3a4a6e Bump version to v1.7.1
3d5e376925fd setup: Move setting of srcdir down to the bottom
e277553b9880 setup: Collect top-level code together
7e5a88984081 setup: Move version and full_description into a function
78b6a85c113b Tidy up some pylint warnings
3501d373f0a2 Require Python 3

The added include of string.h in libfdt_internal.h breaks the kernel
overriding libfdt_env.h with its own string functions, so it is dropped.
An upstream fix is pending.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

+373 -108
+1
scripts/Makefile.dtbs
··· 97 97 -Wno-avoid_unnecessary_addr_size \ 98 98 -Wno-alias_paths \ 99 99 -Wno-graph_child_address \ 100 + -Wno-interrupt_map \ 100 101 -Wno-simple_bus_reg 101 102 else 102 103 DTC_FLAGS += -Wunique_unit_address_if_enabled
+15 -8
scripts/dtc/checks.c
··· 1024 1024 } else if (strprefixeq(node->name, node->basenamelen, "i2c")) { 1025 1025 struct node *child; 1026 1026 for_each_child(node, child) { 1027 - if (strprefixeq(child->name, node->basenamelen, "i2c-bus")) 1027 + if (strprefixeq(child->name, child->basenamelen, "i2c-bus")) 1028 1028 return; 1029 1029 } 1030 1030 node->bus = &i2c_bus; ··· 1217 1217 static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti, 1218 1218 struct node *node) 1219 1219 { 1220 - struct property *prop; 1221 1220 struct node *child; 1222 - bool has_reg = false; 1223 1221 1224 1222 if (!node->parent || node->addr_cells < 0 || node->size_cells < 0) 1225 1223 return; ··· 1226 1228 return; 1227 1229 1228 1230 for_each_child(node, child) { 1229 - prop = get_property(child, "reg"); 1230 - if (prop) 1231 - has_reg = true; 1231 + /* 1232 + * Even if the child devices' address space is not mapped into 1233 + * the parent bus (no 'ranges' property on node), children can 1234 + * still have registers on a local bus, or map local addresses 1235 + * to another subordinate address space. The properties on the 1236 + * child nodes then make #address-cells/#size-cells necessary: 1237 + */ 1238 + if (get_property(child, "reg") || get_property(child, "ranges")) 1239 + return; 1232 1240 } 1233 1241 1234 - if (!has_reg) 1235 - FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" property"); 1242 + FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property"); 1236 1243 } 1237 1244 WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size); 1238 1245 ··· 1676 1673 cellprop = get_property(provider_node, "#address-cells"); 1677 1674 if (cellprop) 1678 1675 parent_cellsize += propval_cell(cellprop); 1676 + else 1677 + FAIL_PROP(c, dti, node, irq_map_prop, 1678 + "Missing property '#address-cells' in node %s, using 0 as fallback", 1679 + provider_node->fullpath); 1679 1680 1680 1681 cell += 1 + parent_cellsize; 1681 1682 if (cell > map_cells)
+42 -5
scripts/dtc/data.c
··· 228 228 { 229 229 struct marker *m; 230 230 231 - m = xmalloc(sizeof(*m)); 232 - m->offset = d.len; 233 - m->type = type; 234 - m->ref = ref; 235 - m->next = NULL; 231 + m = alloc_marker(d.len, type, ref); 236 232 237 233 return data_append_markers(d, m); 238 234 } ··· 249 253 return false; 250 254 251 255 return true; 256 + } 257 + 258 + struct data data_insert_data(struct data d, struct marker *m, struct data old) 259 + { 260 + unsigned int offset = m->offset; 261 + struct marker *next = m->next; 262 + struct marker *marker; 263 + struct data new_data; 264 + char *ref; 265 + 266 + new_data = data_insert_at_marker(d, m, old.val, old.len); 267 + 268 + /* Copy all markers from old value */ 269 + marker = old.markers; 270 + for_each_marker(marker) { 271 + ref = NULL; 272 + 273 + if (marker->ref) 274 + ref = xstrdup(marker->ref); 275 + 276 + m->next = alloc_marker(marker->offset + offset, marker->type, 277 + ref); 278 + m = m->next; 279 + } 280 + m->next = next; 281 + 282 + return new_data; 283 + } 284 + 285 + struct marker *alloc_marker(unsigned int offset, enum markertype type, 286 + char *ref) 287 + { 288 + struct marker *m; 289 + 290 + m = xmalloc(sizeof(*m)); 291 + m->offset = offset; 292 + m->type = type; 293 + m->ref = ref; 294 + m->next = NULL; 295 + 296 + return m; 252 297 }
+15
scripts/dtc/dtc-lexer.l
··· 151 151 return DT_LABEL; 152 152 } 153 153 154 + <V1>{LABEL} { 155 + /* Missed includes or macro definitions while 156 + * preprocessing can lead to unexpected identifiers in 157 + * the input. Report a slightly more informative error 158 + * in this case */ 159 + 160 + lexical_error("Unexpected '%s'", yytext); 161 + 162 + /* Treat it as a literal which often generates further 163 + * useful error messages */ 164 + 165 + yylval.integer = 0; 166 + return DT_LITERAL; 167 + } 168 + 154 169 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { 155 170 char *e; 156 171 DPRINT("Integer Literal: '%s'\n", yytext);
+4 -2
scripts/dtc/dtc.c
··· 15 15 unsigned int reservenum;/* Number of memory reservation slots */ 16 16 int minsize; /* Minimum blob size */ 17 17 int padsize; /* Additional padding to blob */ 18 - int alignsize; /* Additional padding to blob accroding to the alignsize */ 18 + int alignsize; /* Additional padding to blob according to the alignsize */ 19 19 int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties */ 20 20 int generate_symbols; /* enable symbols & fixup support */ 21 21 int generate_fixups; /* suppress generation of fixups on symbol support */ ··· 289 289 if (!depfile) 290 290 die("Couldn't open dependency file %s: %s\n", depname, 291 291 strerror(errno)); 292 - fprintf(depfile, "%s:", outname); 292 + 293 + fprint_path_escaped(depfile, outname); 294 + fputc(':', depfile); 293 295 } 294 296 295 297 if (inform == NULL)
+4 -1
scripts/dtc/dtc.h
··· 38 38 extern unsigned int reservenum; /* Number of memory reservation slots */ 39 39 extern int minsize; /* Minimum blob size */ 40 40 extern int padsize; /* Additional padding to blob */ 41 - extern int alignsize; /* Additional padding to blob accroding to the alignsize */ 41 + extern int alignsize; /* Additional padding to blob according to the alignsize */ 42 42 extern int phandle_format; /* Use linux,phandle or phandle properties */ 43 43 extern int generate_symbols; /* generate symbols for nodes with labels */ 44 44 extern int generate_fixups; /* generate fixups */ ··· 182 182 struct data data_append_byte(struct data d, uint8_t byte); 183 183 struct data data_append_zeroes(struct data d, int len); 184 184 struct data data_append_align(struct data d, int align); 185 + struct data data_insert_data(struct data d, struct marker *m, struct data old); 185 186 187 + struct marker *alloc_marker(unsigned int offset, enum markertype type, 188 + char *ref); 186 189 struct data data_add_marker(struct data d, enum markertype type, char *ref); 187 190 188 191 bool data_is_one_string(struct data d);
+8
scripts/dtc/fdtoverlay.c
··· 46 46 char *tmp = NULL; 47 47 char *tmpo; 48 48 int ret; 49 + bool has_symbols; 49 50 50 51 /* 51 52 * We take copies first, because a failed apply can trash ··· 63 62 fdt_strerror(ret)); 64 63 goto fail; 65 64 } 65 + ret = fdt_path_offset(tmp, "/__symbols__"); 66 + has_symbols = ret >= 0; 66 67 67 68 memcpy(tmpo, overlay, fdt_totalsize(overlay)); 68 69 ··· 77 74 if (ret) { 78 75 fprintf(stderr, "\nFailed to apply '%s': %s\n", 79 76 name, fdt_strerror(ret)); 77 + if (!has_symbols) { 78 + fprintf(stderr, 79 + "base blob does not have a '/__symbols__' node, " 80 + "make sure you have compiled the base blob with '-@' option\n"); 81 + } 80 82 goto fail; 81 83 } 82 84
+1 -1
scripts/dtc/flattree.c
··· 503 503 * Reserve map entries. 504 504 * Align the reserve map to a doubleword boundary. 505 505 * Each entry is an (address, size) pair of u64 values. 506 - * Always supply a zero-sized temination entry. 506 + * Always supply a zero-sized termination entry. 507 507 */ 508 508 asm_emit_align(f, 8); 509 509 emit_label(f, symprefix, "reserve_map");
+4 -4
scripts/dtc/libfdt/fdt.c
··· 312 312 return offset; 313 313 } 314 314 315 - const char *fdt_find_string_(const char *strtab, int tabsize, const char *s) 315 + const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s, 316 + int slen) 316 317 { 317 - int len = strlen(s) + 1; 318 - const char *last = strtab + tabsize - len; 318 + const char *last = strtab + tabsize - (slen + 1); 319 319 const char *p; 320 320 321 321 for (p = strtab; p <= last; p++) 322 - if (memcmp(p, s, len) == 0) 322 + if (memcmp(p, s, slen) == 0 && p[slen] == '\0') 323 323 return p; 324 324 return NULL; 325 325 }
+2 -2
scripts/dtc/libfdt/fdt.h
··· 7 7 * Copyright 2012 Kim Phillips, Freescale Semiconductor. 8 8 */ 9 9 10 - #ifndef __ASSEMBLY__ 10 + #ifndef __ASSEMBLER__ 11 11 12 12 struct fdt_header { 13 13 fdt32_t magic; /* magic word FDT_MAGIC */ ··· 45 45 char data[]; 46 46 }; 47 47 48 - #endif /* !__ASSEMBLY */ 48 + #endif /* !__ASSEMBLER__ */ 49 49 50 50 #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ 51 51 #define FDT_TAGSIZE sizeof(fdt32_t)
+3 -5
scripts/dtc/libfdt/fdt_overlay.c
··· 307 307 308 308 /** 309 309 * overlay_fixup_one_phandle - Set an overlay phandle to the base one 310 - * @fdt: Base Device Tree blob 311 310 * @fdto: Device tree overlay blob 312 311 * @symbols_off: Node offset of the symbols node in the base device tree 313 312 * @path: Path to a node holding a phandle in the overlay ··· 327 328 * 0 on success 328 329 * Negative error code on failure 329 330 */ 330 - static int overlay_fixup_one_phandle(void *fdt, void *fdto, 331 - int symbols_off, 331 + static int overlay_fixup_one_phandle(void *fdto, int symbols_off, 332 332 const char *path, uint32_t path_len, 333 333 const char *name, uint32_t name_len, 334 334 int poffset, uint32_t phandle) ··· 349 351 name, name_len, poffset, 350 352 &phandle_prop, 351 353 sizeof(phandle_prop)); 352 - }; 354 + } 353 355 354 356 /** 355 357 * overlay_fixup_phandle - Set an overlay phandle to the base one ··· 441 443 if ((*endptr != '\0') || (endptr <= (sep + 1))) 442 444 return -FDT_ERR_BADOVERLAY; 443 445 444 - ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off, 446 + ret = overlay_fixup_one_phandle(fdto, symbols_off, 445 447 path, path_len, name, name_len, 446 448 poffset, phandle); 447 449 if (ret)
+24 -17
scripts/dtc/libfdt/fdt_rw.c
··· 124 124 * allocated. Ignored if can_assume(NO_ROLLBACK) 125 125 * @return offset of string in the string table (whether found or added) 126 126 */ 127 - static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) 127 + static int fdt_find_add_string_(void *fdt, const char *s, int slen, 128 + int *allocated) 128 129 { 129 130 char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); 130 131 const char *p; 131 132 char *new; 132 - int len = strlen(s) + 1; 133 133 int err; 134 134 135 135 if (!can_assume(NO_ROLLBACK)) 136 136 *allocated = 0; 137 137 138 - p = fdt_find_string_(strtab, fdt_size_dt_strings(fdt), s); 138 + p = fdt_find_string_len_(strtab, fdt_size_dt_strings(fdt), s, slen); 139 139 if (p) 140 140 /* found it */ 141 141 return (p - strtab); 142 142 143 143 new = strtab + fdt_size_dt_strings(fdt); 144 - err = fdt_splice_string_(fdt, len); 144 + err = fdt_splice_string_(fdt, slen + 1); 145 145 if (err) 146 146 return err; 147 147 148 148 if (!can_assume(NO_ROLLBACK)) 149 149 *allocated = 1; 150 150 151 - memcpy(new, s, len); 151 + memcpy(new, s, slen); 152 + new[slen] = '\0'; 153 + 152 154 return (new - strtab); 153 155 } 154 156 ··· 183 181 return fdt_splice_mem_rsv_(fdt, re, 1, 0); 184 182 } 185 183 186 - static int fdt_resize_property_(void *fdt, int nodeoffset, const char *name, 184 + static int fdt_resize_property_(void *fdt, int nodeoffset, 185 + const char *name, int namelen, 187 186 int len, struct fdt_property **prop) 188 187 { 189 188 int oldlen; 190 189 int err; 191 190 192 - *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); 191 + *prop = fdt_get_property_namelen_w(fdt, nodeoffset, name, namelen, 192 + &oldlen); 193 193 if (!*prop) 194 194 return oldlen; 195 195 ··· 204 200 } 205 201 206 202 static int fdt_add_property_(void *fdt, int nodeoffset, const char *name, 207 - int len, struct fdt_property **prop) 203 + int namelen, int len, struct fdt_property **prop) 208 204 { 209 205 int proplen; 210 206 int nextoffset; ··· 215 211 if ((nextoffset = fdt_check_node_offset_(fdt, nodeoffset)) < 0) 216 212 return nextoffset; 217 213 218 - namestroff = fdt_find_add_string_(fdt, name, &allocated); 214 + namestroff = fdt_find_add_string_(fdt, name, namelen, &allocated); 219 215 if (namestroff < 0) 220 216 return namestroff; 221 217 ··· 259 255 return 0; 260 256 } 261 257 262 - int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, 263 - int len, void **prop_data) 258 + int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name, 259 + int namelen, int len, void **prop_data) 264 260 { 265 261 struct fdt_property *prop; 266 262 int err; 267 263 268 264 FDT_RW_PROBE(fdt); 269 265 270 - err = fdt_resize_property_(fdt, nodeoffset, name, len, &prop); 266 + err = fdt_resize_property_(fdt, nodeoffset, name, namelen, len, &prop); 271 267 if (err == -FDT_ERR_NOTFOUND) 272 - err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); 268 + err = fdt_add_property_(fdt, nodeoffset, name, namelen, len, 269 + &prop); 273 270 if (err) 274 271 return err; 275 272 ··· 278 273 return 0; 279 274 } 280 275 281 - int fdt_setprop(void *fdt, int nodeoffset, const char *name, 282 - const void *val, int len) 276 + int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name, 277 + int namelen, const void *val, int len) 283 278 { 284 279 void *prop_data; 285 280 int err; 286 281 287 - err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); 282 + err = fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, namelen, 283 + len, &prop_data); 288 284 if (err) 289 285 return err; 290 286 ··· 313 307 prop->len = cpu_to_fdt32(newlen); 314 308 memcpy(prop->data + oldlen, val, len); 315 309 } else { 316 - err = fdt_add_property_(fdt, nodeoffset, name, len, &prop); 310 + err = fdt_add_property_(fdt, nodeoffset, name, strlen(name), 311 + len, &prop); 317 312 if (err) 318 313 return err; 319 314 memcpy(prop->data, val, len);
+146 -35
scripts/dtc/libfdt/libfdt.h
··· 14 14 #endif 15 15 16 16 #define FDT_FIRST_SUPPORTED_VERSION 0x02 17 - #define FDT_LAST_COMPATIBLE_VERSION 0x10 17 + #define FDT_LAST_COMPATIBLE_VERSION 0x10 18 18 #define FDT_LAST_SUPPORTED_VERSION 0x11 19 19 20 20 /* Error codes: informative error codes */ ··· 263 263 struct fdt_header *fdth = (struct fdt_header *)fdt; \ 264 264 fdth->name = cpu_to_fdt32(val); \ 265 265 } 266 - fdt_set_hdr_(magic); 267 - fdt_set_hdr_(totalsize); 268 - fdt_set_hdr_(off_dt_struct); 269 - fdt_set_hdr_(off_dt_strings); 270 - fdt_set_hdr_(off_mem_rsvmap); 271 - fdt_set_hdr_(version); 272 - fdt_set_hdr_(last_comp_version); 273 - fdt_set_hdr_(boot_cpuid_phys); 274 - fdt_set_hdr_(size_dt_strings); 275 - fdt_set_hdr_(size_dt_struct); 266 + fdt_set_hdr_(magic) 267 + fdt_set_hdr_(totalsize) 268 + fdt_set_hdr_(off_dt_struct) 269 + fdt_set_hdr_(off_dt_strings) 270 + fdt_set_hdr_(off_mem_rsvmap) 271 + fdt_set_hdr_(version) 272 + fdt_set_hdr_(last_comp_version) 273 + fdt_set_hdr_(boot_cpuid_phys) 274 + fdt_set_hdr_(size_dt_strings) 275 + fdt_set_hdr_(size_dt_struct) 276 276 #undef fdt_set_hdr_ 277 277 278 278 /** ··· 285 285 286 286 /** 287 287 * fdt_header_size_ - internal function to get header size from a version number 288 - * @version: devicetree version number 288 + * @version: device tree version number 289 289 * 290 290 * Return: size of DTB header in bytes 291 291 */ ··· 554 554 * -FDT_ERR_BADPATH, given path does not begin with '/' and the first 555 555 * component is not a valid alias 556 556 * -FDT_ERR_NOTFOUND, if the requested node does not exist 557 - * -FDT_ERR_BADMAGIC, 557 + * -FDT_ERR_BADMAGIC, 558 558 * -FDT_ERR_BADVERSION, 559 559 * -FDT_ERR_BADSTATE, 560 560 * -FDT_ERR_BADSTRUCTURE, ··· 599 599 * structure block offset of the property (>=0), on success 600 600 * -FDT_ERR_NOTFOUND, if the requested node has no properties 601 601 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_BEGIN_NODE tag 602 - * -FDT_ERR_BADMAGIC, 602 + * -FDT_ERR_BADMAGIC, 603 603 * -FDT_ERR_BADVERSION, 604 604 * -FDT_ERR_BADSTATE, 605 605 * -FDT_ERR_BADSTRUCTURE, ··· 620 620 * structure block offset of the next property (>=0), on success 621 621 * -FDT_ERR_NOTFOUND, if the given property is the last in its node 622 622 * -FDT_ERR_BADOFFSET, if nodeoffset did not point to an FDT_PROP tag 623 - * -FDT_ERR_BADMAGIC, 623 + * -FDT_ERR_BADMAGIC, 624 624 * -FDT_ERR_BADVERSION, 625 625 * -FDT_ERR_BADSTATE, 626 626 * -FDT_ERR_BADSTRUCTURE, ··· 712 712 int nodeoffset, 713 713 const char *name, 714 714 int namelen, int *lenp); 715 + static inline struct fdt_property * 716 + fdt_get_property_namelen_w(void *fdt, int nodeoffset, const char *name, 717 + int namelen, int *lenp) 718 + { 719 + return (struct fdt_property *)(uintptr_t)fdt_get_property_namelen( 720 + fdt, nodeoffset, name, namelen, lenp); 721 + } 715 722 #endif 716 723 717 724 /** ··· 771 764 * to within the device blob itself, not a copy of the value). If 772 765 * lenp is non-NULL, the length of the property value is also 773 766 * returned, in the integer pointed to by lenp. If namep is non-NULL, 774 - * the property's namne will also be returned in the char * pointed to 767 + * the property's name will also be returned in the char * pointed to 775 768 * by namep (this will be a pointer to within the device tree's string 776 769 * block, not a new copy of the name). 777 770 * ··· 779 772 * pointer to the property's value 780 773 * if lenp is non-NULL, *lenp contains the length of the property 781 774 * value (>=0) 782 - * if namep is non-NULL *namep contiains a pointer to the property 775 + * if namep is non-NULL *namep contains a pointer to the property 783 776 * name. 784 777 * NULL, on error 785 778 * if lenp is non-NULL, *lenp contains an error code (<0): ··· 873 866 /** 874 867 * fdt_get_alias_namelen - get alias based on substring 875 868 * @fdt: pointer to the device tree blob 876 - * @name: name of the alias th look up 869 + * @name: name of the alias to look up 877 870 * @namelen: number of characters of name to consider 878 871 * 879 872 * Identical to fdt_get_alias(), but only examine the first @namelen ··· 890 883 /** 891 884 * fdt_get_alias - retrieve the path referenced by a given alias 892 885 * @fdt: pointer to the device tree blob 893 - * @name: name of the alias th look up 886 + * @name: name of the alias to look up 894 887 * 895 888 * fdt_get_alias() retrieves the value of a given alias. That is, the 896 889 * value of the property named @name in the node /aliases. ··· 1266 1259 * 1267 1260 * returns: 1268 1261 * 0 <= n < FDT_MAX_NCELLS, on success 1269 - * 2, if the node has no #address-cells property 1270 - * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1262 + * 2, if the node has no #address-cells property 1263 + * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1271 1264 * #address-cells property 1272 1265 * -FDT_ERR_BADMAGIC, 1273 1266 * -FDT_ERR_BADVERSION, ··· 1287 1280 * 1288 1281 * returns: 1289 1282 * 0 <= n < FDT_MAX_NCELLS, on success 1290 - * 1, if the node has no #size-cells property 1291 - * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1283 + * 1, if the node has no #size-cells property 1284 + * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1292 1285 * #size-cells property 1293 1286 * -FDT_ERR_BADMAGIC, 1294 1287 * -FDT_ERR_BADVERSION, ··· 1569 1562 * @fdt: pointer to the device tree blob 1570 1563 * @name: name of property to add 1571 1564 * @len: length of property value in bytes 1572 - * @valp: returns a pointer to where where the value should be placed 1565 + * @valp: returns a pointer to where the value should be placed 1573 1566 * 1574 1567 * returns: 1575 1568 * 0, on success ··· 1667 1660 int fdt_set_name(void *fdt, int nodeoffset, const char *name); 1668 1661 1669 1662 /** 1663 + * fdt_setprop_namelen - create or change a property 1664 + * @fdt: pointer to the device tree blob 1665 + * @nodeoffset: offset of the node whose property to change 1666 + * @name: name of the property to change 1667 + * @namelen: length of the name 1668 + * @val: pointer to data to set the property value to 1669 + * @len: length of the property value 1670 + * 1671 + * fdt_setprop_namelen() sets the value of the named property in the given 1672 + * node to the given value and length, creating the property if it 1673 + * does not already exist. 1674 + * 1675 + * This function may insert or delete data from the blob, and will 1676 + * therefore change the offsets of some existing nodes. 1677 + * 1678 + * returns: 1679 + * 0, on success 1680 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 1681 + * contain the new property value 1682 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1683 + * -FDT_ERR_BADLAYOUT, 1684 + * -FDT_ERR_BADMAGIC, 1685 + * -FDT_ERR_BADVERSION, 1686 + * -FDT_ERR_BADSTATE, 1687 + * -FDT_ERR_BADSTRUCTURE, 1688 + * -FDT_ERR_BADLAYOUT, 1689 + * -FDT_ERR_TRUNCATED, standard meanings 1690 + */ 1691 + int fdt_setprop_namelen(void *fdt, int nodeoffset, const char *name, 1692 + int namelen, const void *val, int len); 1693 + 1694 + /** 1670 1695 * fdt_setprop - create or change a property 1671 1696 * @fdt: pointer to the device tree blob 1672 1697 * @nodeoffset: offset of the node whose property to change ··· 1726 1687 * -FDT_ERR_BADLAYOUT, 1727 1688 * -FDT_ERR_TRUNCATED, standard meanings 1728 1689 */ 1729 - int fdt_setprop(void *fdt, int nodeoffset, const char *name, 1730 - const void *val, int len); 1690 + static inline int fdt_setprop(void *fdt, int nodeoffset, const char *name, 1691 + const void *val, int len) 1692 + { 1693 + return fdt_setprop_namelen(fdt, nodeoffset, name, strlen(name), val, 1694 + len); 1695 + } 1731 1696 1732 1697 /** 1733 - * fdt_setprop_placeholder - allocate space for a property 1698 + * fdt_setprop_placeholder_namelen - allocate space for a property 1734 1699 * @fdt: pointer to the device tree blob 1735 1700 * @nodeoffset: offset of the node whose property to change 1736 1701 * @name: name of the property to change 1702 + * @namelen: length of the name 1737 1703 * @len: length of the property value 1738 1704 * @prop_data: return pointer to property data 1739 1705 * 1740 - * fdt_setprop_placeholer() allocates the named property in the given node. 1706 + * fdt_setprop_placeholder_namelen() allocates the named property in the given node. 1741 1707 * If the property exists it is resized. In either case a pointer to the 1742 1708 * property data is returned. 1743 1709 * ··· 1762 1718 * -FDT_ERR_BADLAYOUT, 1763 1719 * -FDT_ERR_TRUNCATED, standard meanings 1764 1720 */ 1765 - int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, 1766 - int len, void **prop_data); 1721 + int fdt_setprop_placeholder_namelen(void *fdt, int nodeoffset, const char *name, 1722 + int namelen, int len, void **prop_data); 1723 + 1724 + /** 1725 + * fdt_setprop_placeholder - allocate space for a property 1726 + * @fdt: pointer to the device tree blob 1727 + * @nodeoffset: offset of the node whose property to change 1728 + * @name: name of the property to change 1729 + * @len: length of the property value 1730 + * @prop_data: return pointer to property data 1731 + * 1732 + * fdt_setprop_placeholder() allocates the named property in the given node. 1733 + * If the property exists it is resized. In either case a pointer to the 1734 + * property data is returned. 1735 + * 1736 + * This function may insert or delete data from the blob, and will 1737 + * therefore change the offsets of some existing nodes. 1738 + * 1739 + * returns: 1740 + * 0, on success 1741 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 1742 + * contain the new property value 1743 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1744 + * -FDT_ERR_BADLAYOUT, 1745 + * -FDT_ERR_BADMAGIC, 1746 + * -FDT_ERR_BADVERSION, 1747 + * -FDT_ERR_BADSTATE, 1748 + * -FDT_ERR_BADSTRUCTURE, 1749 + * -FDT_ERR_BADLAYOUT, 1750 + * -FDT_ERR_TRUNCATED, standard meanings 1751 + */ 1752 + static inline int fdt_setprop_placeholder(void *fdt, int nodeoffset, 1753 + const char *name, int len, 1754 + void **prop_data) 1755 + { 1756 + return fdt_setprop_placeholder_namelen(fdt, nodeoffset, name, 1757 + strlen(name), len, prop_data); 1758 + } 1767 1759 1768 1760 /** 1769 1761 * fdt_setprop_u32 - set a property to a 32-bit integer ··· 1919 1839 #define fdt_setprop_string(fdt, nodeoffset, name, str) \ 1920 1840 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1) 1921 1841 1842 + /** 1843 + * fdt_setprop_namelen_string - set a property to a string value 1844 + * @fdt: pointer to the device tree blob 1845 + * @nodeoffset: offset of the node whose property to change 1846 + * @name: name of the property to change 1847 + * @namelen: number of characters of name to consider 1848 + * @str: string value for the property 1849 + * 1850 + * fdt_setprop_namelen_string() sets the value of the named property in the 1851 + * given node to the given string value (using the length of the 1852 + * string to determine the new length of the property), or creates a 1853 + * new property with that value if it does not already exist. 1854 + * 1855 + * This function may insert or delete data from the blob, and will 1856 + * therefore change the offsets of some existing nodes. 1857 + * 1858 + * returns: 1859 + * 0, on success 1860 + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to 1861 + * contain the new property value 1862 + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag 1863 + * -FDT_ERR_BADLAYOUT, 1864 + * -FDT_ERR_BADMAGIC, 1865 + * -FDT_ERR_BADVERSION, 1866 + * -FDT_ERR_BADSTATE, 1867 + * -FDT_ERR_BADSTRUCTURE, 1868 + * -FDT_ERR_BADLAYOUT, 1869 + * -FDT_ERR_TRUNCATED, standard meanings 1870 + */ 1871 + #define fdt_setprop_namelen_string(fdt, nodeoffset, name, namelen, str) \ 1872 + fdt_setprop_namelen((fdt), (nodeoffset), (name), (namelen), (str), \ 1873 + strlen(str) + 1) 1922 1874 1923 1875 /** 1924 1876 * fdt_setprop_empty - set a property to an empty value ··· 2171 2059 * @nodeoffset: offset of the node whose property to nop 2172 2060 * @name: name of the property to nop 2173 2061 * 2174 - * fdt_del_property() will delete the given property. 2062 + * fdt_delprop() will delete the given property. 2175 2063 * 2176 2064 * This function will delete data from the blob, and will therefore 2177 2065 * change the offsets of some existing nodes. ··· 2223 2111 * change the offsets of some existing nodes. 2224 2112 * 2225 2113 * returns: 2226 - * structure block offset of the created nodeequested subnode (>=0), on 2227 - * success 2114 + * structure block offset of the created subnode (>=0), on success 2228 2115 * -FDT_ERR_NOTFOUND, if the requested subnode does not exist 2229 2116 * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE 2230 2117 * tag ··· 2233 2122 * blob to contain the new node 2234 2123 * -FDT_ERR_NOSPACE 2235 2124 * -FDT_ERR_BADLAYOUT 2236 - * -FDT_ERR_BADMAGIC, 2125 + * -FDT_ERR_BADMAGIC, 2237 2126 * -FDT_ERR_BADVERSION, 2238 2127 * -FDT_ERR_BADSTATE, 2239 2128 * -FDT_ERR_BADSTRUCTURE, ··· 2278 2167 * returns: 2279 2168 * 0, on success 2280 2169 * -FDT_ERR_NOSPACE, there's not enough space in the base device tree 2281 - * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or 2170 + * -FDT_ERR_NOTFOUND, the overlay points to some nonexistent nodes or 2282 2171 * properties in the base DT 2283 2172 * -FDT_ERR_BADPHANDLE, 2284 2173 * -FDT_ERR_BADOVERLAY,
+11 -3
scripts/dtc/libfdt/libfdt_internal.h
··· 20 20 21 21 int fdt_check_node_offset_(const void *fdt, int offset); 22 22 int fdt_check_prop_offset_(const void *fdt, int offset); 23 - const char *fdt_find_string_(const char *strtab, int tabsize, const char *s); 23 + 24 + const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s, 25 + int s_len); 26 + static inline const char *fdt_find_string_(const char *strtab, int tabsize, 27 + const char *s) 28 + { 29 + return fdt_find_string_len_(strtab, tabsize, s, strlen(s)); 30 + } 31 + 24 32 int fdt_node_end_offset_(void *fdt, int nodeoffset); 25 33 26 34 static inline const void *fdt_offset_ptr_(const void *fdt, int offset) ··· 55 47 } 56 48 57 49 /* 58 - * Internal helpers to access tructural elements of the device tree 59 - * blob (rather than for exaple reading integers from within property 50 + * Internal helpers to access structural elements of the device tree 51 + * blob (rather than for example reading integers from within property 60 52 * values). We assume that we are either given a naturally aligned 61 53 * address for the platform or if we are not, we are on a platform 62 54 * where unaligned memory reads will be handled in a graceful manner.
+18 -7
scripts/dtc/livetree.c
··· 174 174 175 175 old_prop->val = new_prop->val; 176 176 old_prop->deleted = 0; 177 - free(old_prop->srcpos); 177 + srcpos_free(old_prop->srcpos); 178 178 old_prop->srcpos = new_prop->srcpos; 179 179 free(new_prop); 180 180 new_prop = NULL; ··· 504 504 struct node *child; 505 505 506 506 for_each_child(node, child) 507 - if (streq(child->name, nodename)) 507 + if (streq(child->name, nodename) && !child->deleted) 508 508 return child; 509 509 510 510 return NULL; ··· 1014 1014 /* walk the path components creating nodes if they don't exist */ 1015 1015 for (wn = lfn, i = 1; i < depth; i++, wn = nwn) { 1016 1016 /* if no node exists, create it */ 1017 - nwn = get_subnode(wn, compp[i]); 1018 - if (!nwn) 1019 - nwn = build_and_name_child_node(wn, compp[i]); 1017 + nwn = build_root_node(wn, compp[i]); 1020 1018 } 1021 1019 1022 1020 free(compp); ··· 1056 1058 1057 1059 void generate_fixups_tree(struct dt_info *dti, const char *name) 1058 1060 { 1061 + struct node *n = get_subnode(dti->dt, name); 1062 + 1063 + /* Start with an empty __fixups__ node to not get duplicates */ 1064 + if (n) 1065 + n->deleted = true; 1066 + 1059 1067 if (!any_fixup_tree(dti, dti->dt)) 1060 1068 return; 1061 - generate_fixups_tree_internal(dti, build_root_node(dti->dt, name), 1069 + generate_fixups_tree_internal(dti, 1070 + build_and_name_child_node(dti->dt, name), 1062 1071 dti->dt); 1063 1072 } 1064 1073 1065 1074 void generate_local_fixups_tree(struct dt_info *dti, const char *name) 1066 1075 { 1076 + struct node *n = get_subnode(dti->dt, name); 1077 + 1078 + /* Start with an empty __local_fixups__ node to not get duplicates */ 1079 + if (n) 1080 + n->deleted = true; 1067 1081 if (!any_local_fixup_tree(dti, dti->dt)) 1068 1082 return; 1069 - generate_local_fixups_tree_internal(dti, build_root_node(dti->dt, name), 1083 + generate_local_fixups_tree_internal(dti, 1084 + build_and_name_child_node(dti->dt, name), 1070 1085 dti->dt); 1071 1086 }
+15 -2
scripts/dtc/srcpos.c
··· 160 160 strerror(errno)); 161 161 } 162 162 163 - if (depfile) 164 - fprintf(depfile, " %s", fullname); 163 + if (depfile) { 164 + fputc(' ', depfile); 165 + fprint_path_escaped(depfile, fullname); 166 + } 165 167 166 168 if (fullnamep) 167 169 *fullnamep = fullname; ··· 285 283 for (p = pos; p->next != NULL; p = p->next); 286 284 p->next = newtail; 287 285 return pos; 286 + } 287 + 288 + void srcpos_free(struct srcpos *pos) 289 + { 290 + struct srcpos *p_next; 291 + 292 + while (pos) { 293 + p_next = pos->next; 294 + free(pos); 295 + pos = p_next; 296 + } 288 297 } 289 298 290 299 char *
+1
scripts/dtc/srcpos.h
··· 88 88 extern struct srcpos *srcpos_copy(struct srcpos *pos); 89 89 extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos, 90 90 struct srcpos *old_srcpos); 91 + extern void srcpos_free(struct srcpos *pos); 91 92 extern char *srcpos_string(struct srcpos *pos); 92 93 extern char *srcpos_string_first(struct srcpos *pos, int level); 93 94 extern char *srcpos_string_last(struct srcpos *pos, int level);
+37 -15
scripts/dtc/treesource.c
··· 139 139 [TYPE_STRING] = "", 140 140 }; 141 141 142 + /* 143 + * The invariants in the marker list are: 144 + * - offsets are non-strictly monotonically increasing 145 + * - for a single offset there is at most one type marker 146 + * - for a single offset that has both a type marker and non-type markers, the 147 + * type marker appears before the others. 148 + */ 149 + static struct marker **add_marker(struct marker **mi, 150 + enum markertype type, unsigned int offset, char *ref) 151 + { 152 + struct marker *nm; 153 + 154 + while (*mi && (*mi)->offset < offset) 155 + mi = &(*mi)->next; 156 + 157 + if (*mi && (*mi)->offset == offset && is_type_marker((*mi)->type)) { 158 + if (is_type_marker(type)) 159 + return mi; 160 + mi = &(*mi)->next; 161 + } 162 + 163 + if (*mi && (*mi)->offset == offset && type == (*mi)->type) 164 + return mi; 165 + 166 + nm = xmalloc(sizeof(*nm)); 167 + nm->type = type; 168 + nm->offset = offset; 169 + nm->ref = ref; 170 + nm->next = *mi; 171 + *mi = nm; 172 + 173 + return &nm->next; 174 + } 175 + 142 176 static void add_string_markers(struct property *prop) 143 177 { 144 178 int l, len = prop->val.len; 145 179 const char *p = prop->val.val; 180 + struct marker **mi = &prop->val.markers; 146 181 147 - for (l = strlen(p) + 1; l < len; l += strlen(p + l) + 1) { 148 - struct marker *m, **nextp; 149 - 150 - m = xmalloc(sizeof(*m)); 151 - m->offset = l; 152 - m->type = TYPE_STRING; 153 - m->ref = NULL; 154 - m->next = NULL; 155 - 156 - /* Find the end of the markerlist */ 157 - nextp = &prop->val.markers; 158 - while (*nextp) 159 - nextp = &((*nextp)->next); 160 - *nextp = m; 161 - } 182 + for (l = strlen(p) + 1; l < len; l += strlen(p + l) + 1) 183 + mi = add_marker(mi, TYPE_STRING, l, NULL); 162 184 } 163 185 164 186 static enum markertype guess_value_type(struct property *prop)
+16
scripts/dtc/util.c
··· 23 23 #include "util.h" 24 24 #include "version_gen.h" 25 25 26 + void fprint_path_escaped(FILE *fp, const char *path) 27 + { 28 + const char *p = path; 29 + 30 + while (*p) { 31 + if (*p == ' ') { 32 + fputc('\\', fp); 33 + fputc(' ', fp); 34 + } else { 35 + fputc(*p, fp); 36 + } 37 + 38 + p++; 39 + } 40 + } 41 + 26 42 char *xstrdup(const char *s) 27 43 { 28 44 int len = strlen(s) + 1;
+5
scripts/dtc/util.h
··· 42 42 exit(1); 43 43 } 44 44 45 + /** 46 + * Writes path to fp, escaping spaces with a backslash. 47 + */ 48 + void fprint_path_escaped(FILE *fp, const char *path); 49 + 45 50 static inline void *xmalloc(size_t len) 46 51 { 47 52 void *new = malloc(len);
+1 -1
scripts/dtc/version_gen.h
··· 1 - #define DTC_VERSION "DTC 1.7.0-gbcd02b52" 1 + #define DTC_VERSION "DTC 1.7.2-g52f07dcc"