mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
allow paths in fdt_path_offset to begin with a &label reference
When using the CLI tools fdtget and fdtput, or other tools built on top of libfdt (such as perhaps scripts written in Python), it can be convenient to refer to a node by a label rather than having to know the full path from the root. Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
This commit is contained in:
parent
617f3d9b60
commit
2675c5896a
2 changed files with 16 additions and 6 deletions
|
@ -258,14 +258,18 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
|
||||||
if (!can_assume(VALID_INPUT) && namelen <= 0)
|
if (!can_assume(VALID_INPUT) && namelen <= 0)
|
||||||
return -FDT_ERR_BADPATH;
|
return -FDT_ERR_BADPATH;
|
||||||
|
|
||||||
/* see if we have an alias */
|
/* see if we have an alias or symbol */
|
||||||
if (*path != '/') {
|
if (*path != '/') {
|
||||||
const char *q = memchr(path, '/', end - p);
|
const char *q = memchr(path, '/', end - p);
|
||||||
|
|
||||||
if (!q)
|
if (!q)
|
||||||
q = end;
|
q = end;
|
||||||
|
|
||||||
p = fdt_get_alias_namelen(fdt, p, q - p);
|
if (*p == '&')
|
||||||
|
p = fdt_get_symbol_namelen(fdt, p + 1, q - p - 1);
|
||||||
|
else
|
||||||
|
p = fdt_get_alias_namelen(fdt, p, q - p);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
return -FDT_ERR_BADPATH;
|
return -FDT_ERR_BADPATH;
|
||||||
offset = fdt_path_offset(fdt, p);
|
offset = fdt_path_offset(fdt, p);
|
||||||
|
|
|
@ -570,9 +570,10 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
||||||
* address).
|
* address).
|
||||||
*
|
*
|
||||||
* If the path is not absolute (i.e. does not begin with '/'), the
|
* If the path is not absolute (i.e. does not begin with '/'), the
|
||||||
* first component is treated as an alias. That is, the property by
|
* first component is treated as an alias (or, if it begins with '&',
|
||||||
* that name is looked up in the /aliases node, and the value of that
|
* the rest is treated as a symbol). That is, the property by that
|
||||||
* property used in place of that first component.
|
* name is looked up in the /aliases (or /__symbols__) node, and the
|
||||||
|
* value of that property used in place of that first component.
|
||||||
*
|
*
|
||||||
* For example, for this small fragment
|
* For example, for this small fragment
|
||||||
*
|
*
|
||||||
|
@ -592,12 +593,17 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);
|
||||||
*
|
*
|
||||||
* /soc@0/i2c@30a40000/eeprom@52
|
* /soc@0/i2c@30a40000/eeprom@52
|
||||||
* i2c2/eeprom@52
|
* i2c2/eeprom@52
|
||||||
|
* &foo/eeprom@52
|
||||||
|
* &bar
|
||||||
|
*
|
||||||
|
* The latter two only work if the device tree blob has been compiled
|
||||||
|
* with the -@ dtc option.
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* structure block offset of the node with the requested path (>=0), on
|
* structure block offset of the node with the requested path (>=0), on
|
||||||
* success
|
* success
|
||||||
* -FDT_ERR_BADPATH, given path does not begin with '/' and the first
|
* -FDT_ERR_BADPATH, given path does not begin with '/' and the first
|
||||||
* component is not a valid alias
|
* component is not a valid alias or symbol
|
||||||
* -FDT_ERR_NOTFOUND, if the requested node does not exist
|
* -FDT_ERR_NOTFOUND, if the requested node does not exist
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
* -FDT_ERR_BADVERSION,
|
* -FDT_ERR_BADVERSION,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue