diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2008-08-20 16:55:14 +1000 |
---|---|---|
committer | Gerald Van Baren <vanbaren@cideas.com> | 2008-10-02 19:06:09 -0400 |
commit | 9a6cf73a88ddab2e1ac39088f2806177982cc62c (patch) | |
tree | 16af8bb02d53d727c06f64852d71b20786294577 /libfdt | |
parent | 3e38577208e4256956bc33bb8bcd0a6b6fab55c3 (diff) | |
download | u-boot-imx-9a6cf73a88ddab2e1ac39088f2806177982cc62c.zip u-boot-imx-9a6cf73a88ddab2e1ac39088f2806177982cc62c.tar.gz u-boot-imx-9a6cf73a88ddab2e1ac39088f2806177982cc62c.tar.bz2 |
libfdt: Add function to explicitly expand aliases
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias. This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt')
-rw-r--r-- | libfdt/fdt_ro.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index f559eed..b705f91 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -145,17 +145,12 @@ int fdt_path_offset(const void *fdt, const char *path) /* see if we have an alias */ if (*path != '/') { - const char *q; - int aliasoffset = fdt_path_offset(fdt, "/aliases"); - - if (aliasoffset < 0) - return -FDT_ERR_BADPATH; + const char *q = strchr(path, '/'); - q = strchr(path, '/'); if (!q) q = end; - p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL); + p = fdt_get_alias_namelen(fdt, p, q - p); if (!p) return -FDT_ERR_BADPATH; offset = fdt_path_offset(fdt, p); @@ -306,6 +301,23 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) return fdt32_to_cpu(*php); } +const char *fdt_get_alias_namelen(const void *fdt, + const char *name, int namelen) +{ + int aliasoffset; + + aliasoffset = fdt_path_offset(fdt, "/aliases"); + if (aliasoffset < 0) + return NULL; + + return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL); +} + +const char *fdt_get_alias(const void *fdt, const char *name) +{ + return fdt_get_alias_namelen(fdt, name, strlen(name)); +} + int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) { int pdepth = 0, p = 0; |