diff options
author | Thierry Reding <treding@nvidia.com> | 2014-08-26 17:33:51 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-10-22 16:56:40 -0600 |
commit | fc503c1791f35294d04495cd8ba3794bb6f15055 (patch) | |
tree | 533bf4e7806abd8a90b41e8ec6a7c7390fe8d47f /lib/libfdt | |
parent | bc4147ab2d698bf7375a10af73ce34d76129edff (diff) | |
download | u-boot-imx-fc503c1791f35294d04495cd8ba3794bb6f15055.zip u-boot-imx-fc503c1791f35294d04495cd8ba3794bb6f15055.tar.gz u-boot-imx-fc503c1791f35294d04495cd8ba3794bb6f15055.tar.bz2 |
fdt: Add a function to get the index of a string
Given a device tree node and a property name, the new fdt_find_string()
function will look up a given string in the string list contained in the
property's value and return its index.
Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/libfdt')
-rw-r--r-- | lib/libfdt/fdt_ro.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index cb06a9b..fec4a0a 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -511,6 +511,32 @@ int fdt_count_strings(const void *fdt, int node, const char *property) return count; } +int fdt_find_string(const void *fdt, int node, const char *property, + const char *string) +{ + const char *list, *end; + int len, index = 0; + + list = fdt_getprop(fdt, node, property, &len); + if (!list) + return len; + + end = list + len; + len = strlen(string); + + while (list < end) { + int l = strlen(list); + + if (l == len && memcmp(list, string, len) == 0) + return index; + + list += l + 1; + index++; + } + + return -FDT_ERR_NOTFOUND; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) { |