Commit 72c55878ecb1f0fdc8bc13516e5cb18fbae505e7
Exists in
master
and in
54 other branches
Merge branch 'master' of git://git.denx.de/u-boot-fdt
Showing 4 changed files Side-by-side Diff
include/libfdt.h
... | ... | @@ -122,7 +122,7 @@ |
122 | 122 | /* Low-level functions (you probably don't need these) */ |
123 | 123 | /**********************************************************************/ |
124 | 124 | |
125 | -const void *fdt_offset_ptr(const void *fdt, int offset, int checklen); | |
125 | +const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); | |
126 | 126 | static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) |
127 | 127 | { |
128 | 128 | return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen); |
... | ... | @@ -457,6 +457,32 @@ |
457 | 457 | * 0, if the node has no phandle, or another error occurs |
458 | 458 | */ |
459 | 459 | uint32_t fdt_get_phandle(const void *fdt, int nodeoffset); |
460 | + | |
461 | +/** | |
462 | + * fdt_get_alias_namelen - get alias based on substring | |
463 | + * @fdt: pointer to the device tree blob | |
464 | + * @name: name of the alias th look up | |
465 | + * @namelen: number of characters of name to consider | |
466 | + * | |
467 | + * Identical to fdt_get_alias(), but only examine the first namelen | |
468 | + * characters of name for matching the alias name. | |
469 | + */ | |
470 | +const char *fdt_get_alias_namelen(const void *fdt, | |
471 | + const char *name, int namelen); | |
472 | + | |
473 | +/** | |
474 | + * fdt_get_alias - retreive the path referenced by a given alias | |
475 | + * @fdt: pointer to the device tree blob | |
476 | + * @name: name of the alias th look up | |
477 | + * | |
478 | + * fdt_get_alias() retrieves the value of a given alias. That is, the | |
479 | + * value of the property named 'name' in the node /aliases. | |
480 | + * | |
481 | + * returns: | |
482 | + * a pointer to the expansion of the alias named 'name', of it exists | |
483 | + * NULL, if the given alias or the /aliases node does not exist | |
484 | + */ | |
485 | +const char *fdt_get_alias(const void *fdt, const char *name); | |
460 | 486 | |
461 | 487 | /** |
462 | 488 | * fdt_get_path - determine the full path of a node |
lib_ppc/bootm.c
... | ... | @@ -145,7 +145,7 @@ |
145 | 145 | * if the user wants it (the logic is in the subroutines). |
146 | 146 | */ |
147 | 147 | if (of_size) { |
148 | - if (fdt_chosen(of_flat_tree, 0) < 0) { | |
148 | + if (fdt_chosen(of_flat_tree, 1) < 0) { | |
149 | 149 | puts ("ERROR: "); |
150 | 150 | puts ("/chosen node create failed"); |
151 | 151 | puts (" - must RESET the board to recover.\n"); |
libfdt/fdt.c
libfdt/fdt_ro.c
... | ... | @@ -145,17 +145,12 @@ |
145 | 145 | |
146 | 146 | /* see if we have an alias */ |
147 | 147 | if (*path != '/') { |
148 | - const char *q; | |
149 | - int aliasoffset = fdt_path_offset(fdt, "/aliases"); | |
148 | + const char *q = strchr(path, '/'); | |
150 | 149 | |
151 | - if (aliasoffset < 0) | |
152 | - return -FDT_ERR_BADPATH; | |
153 | - | |
154 | - q = strchr(path, '/'); | |
155 | 150 | if (!q) |
156 | 151 | q = end; |
157 | 152 | |
158 | - p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL); | |
153 | + p = fdt_get_alias_namelen(fdt, p, q - p); | |
159 | 154 | if (!p) |
160 | 155 | return -FDT_ERR_BADPATH; |
161 | 156 | offset = fdt_path_offset(fdt, p); |
... | ... | @@ -306,6 +301,23 @@ |
306 | 301 | return fdt32_to_cpu(*php); |
307 | 302 | } |
308 | 303 | |
304 | +const char *fdt_get_alias_namelen(const void *fdt, | |
305 | + const char *name, int namelen) | |
306 | +{ | |
307 | + int aliasoffset; | |
308 | + | |
309 | + aliasoffset = fdt_path_offset(fdt, "/aliases"); | |
310 | + if (aliasoffset < 0) | |
311 | + return NULL; | |
312 | + | |
313 | + return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL); | |
314 | +} | |
315 | + | |
316 | +const char *fdt_get_alias(const void *fdt, const char *name) | |
317 | +{ | |
318 | + return fdt_get_alias_namelen(fdt, name, strlen(name)); | |
319 | +} | |
320 | + | |
309 | 321 | int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) |
310 | 322 | { |
311 | 323 | int pdepth = 0, p = 0; |
... | ... | @@ -320,9 +332,6 @@ |
320 | 332 | for (offset = 0, depth = 0; |
321 | 333 | (offset >= 0) && (offset <= nodeoffset); |
322 | 334 | offset = fdt_next_node(fdt, offset, &depth)) { |
323 | - if (pdepth < depth) | |
324 | - continue; /* overflowed buffer */ | |
325 | - | |
326 | 335 | while (pdepth > depth) { |
327 | 336 | do { |
328 | 337 | p--; |
... | ... | @@ -330,14 +339,16 @@ |
330 | 339 | pdepth--; |
331 | 340 | } |
332 | 341 | |
333 | - name = fdt_get_name(fdt, offset, &namelen); | |
334 | - if (!name) | |
335 | - return namelen; | |
336 | - if ((p + namelen + 1) <= buflen) { | |
337 | - memcpy(buf + p, name, namelen); | |
338 | - p += namelen; | |
339 | - buf[p++] = '/'; | |
340 | - pdepth++; | |
342 | + if (pdepth >= depth) { | |
343 | + name = fdt_get_name(fdt, offset, &namelen); | |
344 | + if (!name) | |
345 | + return namelen; | |
346 | + if ((p + namelen + 1) <= buflen) { | |
347 | + memcpy(buf + p, name, namelen); | |
348 | + p += namelen; | |
349 | + buf[p++] = '/'; | |
350 | + pdepth++; | |
351 | + } | |
341 | 352 | } |
342 | 353 | |
343 | 354 | if (offset == nodeoffset) { |
... | ... | @@ -347,7 +358,7 @@ |
347 | 358 | if (p > 1) /* special case so that root path is "/", not "" */ |
348 | 359 | p--; |
349 | 360 | buf[p] = '\0'; |
350 | - return p; | |
361 | + return 0; | |
351 | 362 | } |
352 | 363 | } |
353 | 364 |