diff options
author | Thierry Reding <treding@nvidia.com> | 2014-08-26 17:33:52 +0200 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2014-10-11 01:06:35 +0200 |
commit | b276b9c1353a6681d85f31885b6ae8c1fe61522f (patch) | |
tree | 7402c776a937e62ce1fc230f5337482a9274fef7 /lib | |
parent | 5b1515b61e35c3ba75be86fe531ab3c3a06145bd (diff) |
fdt: Add functions to retrieve strings
Given a device tree node, a property name and an index, the new function
fdt_get_string_index() will return in an output argument a pointer to
the index'th string in the property's value.
The fdt_get_string() is a shortcut for the above with the index being 0.
Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfdt/fdt_ro.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index fec4a0a141f..03733e574f7 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -537,6 +537,36 @@ int fdt_find_string(const void *fdt, int node, const char *property, return -FDT_ERR_NOTFOUND; } +int fdt_get_string_index(const void *fdt, int node, const char *property, + int index, const char **output) +{ + const char *list; + int length, i; + + list = fdt_getprop(fdt, node, property, &length); + + for (i = 0; i < length; i++) { + int len = strlen(list); + + if (index == 0) { + *output = list; + return 0; + } + + list += len + 1; + i += len; + index--; + } + + return FDT_ERR_NOTFOUND; +} + +int fdt_get_string(const void *fdt, int node, const char *property, + const char **output) +{ + return fdt_get_string_index(fdt, node, property, 0, output); +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) { |