[U-Boot] [PATCH v3 02/17] fdt_ro.c: add new function: fdt_node_check_prop_compatible()

Przemyslaw Marczak
2015-03-24T20:30:36Z

This commit:
- moves fdt_node_check_compatible() code to fdt_node_check_prop_compatible()
- adds call to fdt_node_check_prop_compatible() in fdt_node_check_compatible()
with 'compatible' as the name of compatible property.

The function: fdt_node_check_compatible() - works the same as previous.
The function fdt_node_check_prop_compatible() - allows for checking compatible
string in given property name.

If some fdt node uses different name for compatible property, than 'compatible',
then the function fdt_node_check_prop_compatible() can be used with the custom
compatible property name as an argument.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
---
include/libfdt.h | 27 +++++++++++++++++++++++++++
lib/libfdt/fdt_ro.c | 14 +++++++++++---
2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index f3cbb63..0ff91b6 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -807,6 +807,33 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);

/**
+ * fdt_node_check_prop_compatible: check a node's 'property_name' for compatible
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of a tree node
+ * @property_name: name of property within looking for the 'compatible' string
+ * @compatible: string to match against
+ *
+ *
+ * fdt_node_check_prop_compatible() returns 0 if the given node contains a
+ * 'compatible' property with the given string as one of its elements,
+ * it returns non-zero otherwise, or on error.
+ *
+ * returns:
+ * 0, if the node has a 'compatible' property listing the given string
+ * 1, if the node has a 'compatible' property, but it does not list
+ * the given string
+ * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
+ * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
+ * -FDT_ERR_BADMAGIC,
+ * -FDT_ERR_BADVERSION,
+ * -FDT_ERR_BADSTATE,
+ * -FDT_ERR_BADSTRUCTURE, standard meanings
+ */
+int fdt_node_check_prop_compatible(const void *fdt, int nodeoffset,
+ const char *property_name,
+ const char *compatible);
+
+/**
* fdt_node_check_compatible: check a node's compatible property
* @fdt: pointer to the device tree blob
* @nodeoffset: offset of a tree node
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
index 03733e5..a3f4f8a 100644
--- a/lib/libfdt/fdt_ro.c
+++ b/lib/libfdt/fdt_ro.c
@@ -567,13 +567,14 @@ int fdt_get_string(const void *fdt, int node, const char *property,
return fdt_get_string_index(fdt, node, property, 0, output);
}

-int fdt_node_check_compatible(const void *fdt, int nodeoffset,
- const char *compatible)
+int fdt_node_check_prop_compatible(const void *fdt, int nodeoffset,
+ const char *prop_name,
+ const char *compatible)
{
const void *prop;
int len;

- prop = fdt_getprop(fdt, nodeoffset, "compatible", &len);
+ prop = fdt_getprop(fdt, nodeoffset, prop_name, &len);
if (!prop)
return len;
if (fdt_stringlist_contains(prop, len, compatible))
@@ -582,6 +583,13 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
return 1;
}

+int fdt_node_check_compatible(const void *fdt, int nodeoffset,
+ const char *compatible)
+{
+ return fdt_node_check_prop_compatible(fdt, nodeoffset, "compatible",
+ compatible);
+}
+
int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
const char *compatible)
{
--
1.9.1