#define FDT_ERR_NOTFOUND 1\r
/* FDT_ERR_NOTFOUND: The requested node or property does not exist */\r
#define FDT_ERR_EXISTS 2\r
- /* FDT_ERR_EXISTS: Attemped to create a node or property which\r
+ /* FDT_ERR_EXISTS: Attempted to create a node or property which\r
* already exists */\r
#define FDT_ERR_NOSPACE 3\r
/* FDT_ERR_NOSPACE: Operation needed to expand the device\r
* (e.g. missing a leading / for a function which requires an\r
* absolute path) */\r
#define FDT_ERR_BADPHANDLE 6\r
- /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle\r
- * value. phandle values of 0 and -1 are not permitted. */\r
+ /* FDT_ERR_BADPHANDLE: Function was passed an invalid phandle.\r
+ * This can be caused either by an invalid phandle property\r
+ * length, or the phandle value was either 0 or -1, which are\r
+ * not permitted. */\r
#define FDT_ERR_BADSTATE 7\r
/* FDT_ERR_BADSTATE: Function was passed an incomplete device\r
* tree created by the sequential-write functions, which is\r
* Should never be returned, if it is, it indicates a bug in\r
* libfdt itself. */\r
\r
-#define FDT_ERR_MAX 13\r
+/* Errors in device tree content */\r
+#define FDT_ERR_BADNCELLS 14\r
+ /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells\r
+ * or similar property with a bad format or value */\r
+\r
+#define FDT_ERR_BADVALUE 15\r
+ /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected\r
+ * value. For example: a property expected to contain a string list\r
+ * is not NUL-terminated within the length of its value. */\r
+\r
+#define FDT_ERR_BADOVERLAY 16\r
+ /* FDT_ERR_BADOVERLAY: The device tree overlay, while\r
+ * correctly structured, cannot be applied due to some\r
+ * unexpected or missing value, property or node. */\r
+\r
+#define FDT_ERR_NOPHANDLES 17\r
+ /* FDT_ERR_NOPHANDLES: The device tree doesn't have any\r
+ * phandle available anymore without causing an overflow */\r
+\r
+#define FDT_ERR_MAX 17\r
\r
/**********************************************************************/\r
/* Low-level functions (you probably don't need these) */\r
/**********************************************************************/\r
\r
+#ifndef SWIG /* This function is not useful in Python */\r
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);\r
+#endif\r
static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)\r
{\r
return (void *)(uintptr_t)fdt_offset_ptr(fdt, offset, checklen);\r
\r
int fdt_next_node(const void *fdt, int offset, int *depth);\r
\r
+/**\r
+ * fdt_first_subnode() - get offset of first direct subnode\r
+ *\r
+ * @fdt: FDT blob\r
+ * @offset: Offset of node to check\r
+ * @return offset of first subnode, or -FDT_ERR_NOTFOUND if there is none\r
+ */\r
+int fdt_first_subnode(const void *fdt, int offset);\r
+\r
+/**\r
+ * fdt_next_subnode() - get offset of next direct subnode\r
+ *\r
+ * After first calling fdt_first_subnode(), call this function repeatedly to\r
+ * get direct subnodes of a parent node.\r
+ *\r
+ * @fdt: FDT blob\r
+ * @offset: Offset of previous subnode\r
+ * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more\r
+ * subnodes\r
+ */\r
+int fdt_next_subnode(const void *fdt, int offset);\r
+\r
+/**\r
+ * fdt_for_each_subnode - iterate over all subnodes of a parent\r
+ *\r
+ * @node: child node (int, lvalue)\r
+ * @fdt: FDT blob (const void *)\r
+ * @parent: parent node (int)\r
+ *\r
+ * This is actually a wrapper around a for loop and would be used like so:\r
+ *\r
+ * fdt_for_each_subnode(node, fdt, parent) {\r
+ * Use node\r
+ * ...\r
+ * }\r
+ *\r
+ * if ((node < 0) && (node != -FDT_ERR_NOT_FOUND)) {\r
+ * Error handling\r
+ * }\r
+ *\r
+ * Note that this is implemented as a macro and @node is used as\r
+ * iterator in the loop. The parent variable be constant or even a\r
+ * literal.\r
+ *\r
+ */\r
+#define fdt_for_each_subnode(node, fdt, parent) \\r
+ for (node = fdt_first_subnode(fdt, parent); \\r
+ node >= 0; \\r
+ node = fdt_next_subnode(fdt, node))\r
+\r
/**********************************************************************/\r
/* General functions */\r
/**********************************************************************/\r
-\r
#define fdt_get_header(fdt, field) \\r
(fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))\r
-#define fdt_magic(fdt) (fdt_get_header(fdt, magic))\r
+#define fdt_magic(fdt) (fdt_get_header(fdt, magic))\r
#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))\r
#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))\r
#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))\r
#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))\r
#define fdt_version(fdt) (fdt_get_header(fdt, version))\r
-#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))\r
-#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))\r
-#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))\r
+#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))\r
+#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))\r
+#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))\r
#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))\r
\r
#define __fdt_set_hdr(name) \\r
static inline void fdt_set_##name(void *fdt, uint32_t val) \\r
{ \\r
- struct fdt_header *fdth = (struct fdt_header*)fdt; \\r
+ struct fdt_header *fdth = (struct fdt_header *)fdt; \\r
fdth->name = cpu_to_fdt32(val); \\r
}\r
__fdt_set_hdr(magic);\r
*/\r
const char *fdt_string(const void *fdt, int stroffset);\r
\r
+/**\r
+ * fdt_get_max_phandle - retrieves the highest phandle in a tree\r
+ * @fdt: pointer to the device tree blob\r
+ *\r
+ * fdt_get_max_phandle retrieves the highest phandle in the given\r
+ * device tree. This will ignore badly formatted phandles, or phandles\r
+ * with a value of 0 or -1.\r
+ *\r
+ * returns:\r
+ * the highest phandle on success\r
+ * 0, if no phandle was found in the device tree\r
+ * -1, if an error occurred\r
+ */\r
+uint32_t fdt_get_max_phandle(const void *fdt);\r
+\r
/**\r
* fdt_num_mem_rsv - retrieve the number of memory reserve map entries\r
* @fdt: pointer to the device tree blob\r
* useful for finding subnodes based on a portion of a larger string,\r
* such as a full path.\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,\r
const char *name, int namelen);\r
+#endif\r
/**\r
* fdt_subnode_offset - find a subnode of a given node\r
* @fdt: pointer to the device tree blob\r
* returns:\r
* structure block offset of the requested subnode (>=0), on success\r
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
- * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
- * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE\r
+ * tag\r
+ * -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* -FDT_ERR_BADSTRUCTURE,\r
*/\r
int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);\r
\r
+/**\r
+ * fdt_path_offset_namelen - find a tree node by its full path\r
+ * @fdt: pointer to the device tree blob\r
+ * @path: full path of the node to locate\r
+ * @namelen: number of characters of path to consider\r
+ *\r
+ * Identical to fdt_path_offset(), but only consider the first namelen\r
+ * characters of path as the path name.\r
+ */\r
+#ifndef SWIG /* Not available in Python */\r
+int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);\r
+#endif\r
+\r
/**\r
* fdt_path_offset - find a tree node by its full path\r
* @fdt: pointer to the device tree blob\r
* address).\r
*\r
* returns:\r
- * structure block offset of the node with the requested path (>=0), on success\r
+ * structure block offset of the node with the requested path (>=0), on\r
+ * success\r
* -FDT_ERR_BADPATH, given path does not begin with '/' or is invalid\r
* -FDT_ERR_NOTFOUND, if the requested node does not exist\r
* -FDT_ERR_BADMAGIC,\r
*\r
* returns:\r
* pointer to the node's name, on success\r
- * If lenp is non-NULL, *lenp contains the length of that name (>=0)\r
+ * If lenp is non-NULL, *lenp contains the length of that name\r
+ * (>=0)\r
* NULL, on error\r
* if lenp is non-NULL *lenp contains an error code (<0):\r
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\r
+ * tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE, standard meanings\r
*/\r
int fdt_next_property_offset(const void *fdt, int offset);\r
\r
+/**\r
+ * fdt_for_each_property_offset - iterate over all properties of a node\r
+ *\r
+ * @property_offset: property offset (int, lvalue)\r
+ * @fdt: FDT blob (const void *)\r
+ * @node: node offset (int)\r
+ *\r
+ * This is actually a wrapper around a for loop and would be used like so:\r
+ *\r
+ * fdt_for_each_property_offset(property, fdt, node) {\r
+ * Use property\r
+ * ...\r
+ * }\r
+ *\r
+ * if ((property < 0) && (property != -FDT_ERR_NOT_FOUND)) {\r
+ * Error handling\r
+ * }\r
+ *\r
+ * Note that this is implemented as a macro and property is used as\r
+ * iterator in the loop. The node variable can be constant or even a\r
+ * literal.\r
+ */\r
+#define fdt_for_each_property_offset(property, fdt, node) \\r
+ for (property = fdt_first_property_offset(fdt, node); \\r
+ property >= 0; \\r
+ property = fdt_next_property_offset(fdt, property))\r
+\r
/**\r
* fdt_get_property_by_offset - retrieve the property at a given offset\r
* @fdt: pointer to the device tree blob\r
* @namelen: number of characters of name to consider\r
* @lenp: pointer to an integer variable (will be overwritten) or NULL\r
*\r
- * Identical to fdt_get_property_namelen(), but only examine the first\r
- * namelen characters of name for matching the property name.\r
+ * Identical to fdt_get_property(), but only examine the first namelen\r
+ * characters of name for matching the property name.\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
const struct fdt_property *fdt_get_property_namelen(const void *fdt,\r
int nodeoffset,\r
const char *name,\r
int namelen, int *lenp);\r
+#endif\r
\r
/**\r
* fdt_get_property - find a given property in a given node\r
* NULL, on error\r
* if lenp is non-NULL, *lenp contains an error code (<0):\r
* -FDT_ERR_NOTFOUND, node does not have named property\r
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\r
+ * tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* -FDT_ERR_BADSTRUCTURE,\r
* -FDT_ERR_TRUNCATED, standard meanings\r
*/\r
+#ifndef SWIG /* This function is not useful in Python */\r
const void *fdt_getprop_by_offset(const void *fdt, int offset,\r
const char **namep, int *lenp);\r
+#endif\r
\r
/**\r
* fdt_getprop_namelen - get property value based on substring\r
* Identical to fdt_getprop(), but only examine the first namelen\r
* characters of name for matching the property name.\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
const void *fdt_getprop_namelen(const void *fdt, int nodeoffset,\r
const char *name, int namelen, int *lenp);\r
+static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset,\r
+ const char *name, int namelen,\r
+ int *lenp)\r
+{\r
+ return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name,\r
+ namelen, lenp);\r
+}\r
+#endif\r
\r
/**\r
* fdt_getprop - retrieve the value of a given property\r
* NULL, on error\r
* if lenp is non-NULL, *lenp contains an error code (<0):\r
* -FDT_ERR_NOTFOUND, node does not have named property\r
- * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE\r
+ * tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* Identical to fdt_get_alias(), but only examine the first namelen\r
* characters of name for matching the alias name.\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
const char *fdt_get_alias_namelen(const void *fdt,\r
const char *name, int namelen);\r
+#endif\r
\r
/**\r
- * fdt_get_alias - retreive the path referenced by a given alias\r
+ * fdt_get_alias - retrieve the path referenced by a given alias\r
* @fdt: pointer to the device tree blob\r
* @name: name of the alias th look up\r
*\r
* value of the property named 'name' in the node /aliases.\r
*\r
* returns:\r
- * a pointer to the expansion of the alias named 'name', of it exists\r
+ * a pointer to the expansion of the alias named 'name', if it exists\r
* NULL, if the given alias or the /aliases node does not exist\r
*/\r
const char *fdt_get_alias(const void *fdt, const char *name);\r
* 0, on success\r
* buf contains the absolute path of the node at\r
* nodeoffset, as a NUL-terminated string.\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_NOSPACE, the path of the given node is longer than (bufsize-1)\r
* characters and will not fit in the given buffer.\r
* -FDT_ERR_BADMAGIC,\r
* structure from the start to nodeoffset.\r
*\r
* returns:\r
-\r
* structure block offset of the node at node offset's ancestor\r
* of depth supernodedepth (>=0), on success\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
-* -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of nodeoffset\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_NOTFOUND, supernodedepth was greater than the depth of\r
+ * nodeoffset\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
*\r
* returns:\r
* depth of the node at nodeoffset (>=0), on success\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* returns:\r
* structure block offset of the parent of the node at nodeoffset\r
* (>=0), on success\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* on success\r
* -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
* tree after startoffset\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* 1, if the node has a 'compatible' property, but it does not list\r
* the given string\r
* -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property\r
- * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
* on success\r
* -FDT_ERR_NOTFOUND, no node matching the criterion exists in the\r
* tree after startoffset\r
- * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, nodeoffset does not refer to a BEGIN_NODE tag\r
* -FDT_ERR_BADMAGIC,\r
* -FDT_ERR_BADVERSION,\r
* -FDT_ERR_BADSTATE,\r
int fdt_node_offset_by_compatible(const void *fdt, int startoffset,\r
const char *compatible);\r
\r
+/**\r
+ * fdt_stringlist_contains - check a string list property for a string\r
+ * @strlist: Property containing a list of strings to check\r
+ * @listlen: Length of property\r
+ * @str: String to search for\r
+ *\r
+ * This is a utility function provided for convenience. The list contains\r
+ * one or more strings, each terminated by \0, as is found in a device tree\r
+ * "compatible" property.\r
+ *\r
+ * @return: 1 if the string is found in the list, 0 not found, or invalid list\r
+ */\r
+int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);\r
+\r
+/**\r
+ * fdt_stringlist_count - count the number of strings in a string list\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of a tree node\r
+ * @property: name of the property containing the string list\r
+ * @return:\r
+ * the number of strings in the given property\r
+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\r
+ * -FDT_ERR_NOTFOUND if the property does not exist\r
+ */\r
+int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);\r
+\r
+/**\r
+ * fdt_stringlist_search - find a string in a string list and return its index\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of a tree node\r
+ * @property: name of the property containing the string list\r
+ * @string: string to look up in the string list\r
+ *\r
+ * Note that it is possible for this function to succeed on property values\r
+ * that are not NUL-terminated. That's because the function will stop after\r
+ * finding the first occurrence of @string. This can for example happen with\r
+ * small-valued cell properties, such as #address-cells, when searching for\r
+ * the empty string.\r
+ *\r
+ * @return:\r
+ * the index of the string in the list of strings\r
+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\r
+ * -FDT_ERR_NOTFOUND if the property does not exist or does not contain\r
+ * the given string\r
+ */\r
+int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,\r
+ const char *string);\r
+\r
+/**\r
+ * fdt_stringlist_get() - obtain the string at a given index in a string list\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of a tree node\r
+ * @property: name of the property containing the string list\r
+ * @index: index of the string to return\r
+ * @lenp: return location for the string length or an error code on failure\r
+ *\r
+ * Note that this will successfully extract strings from properties with\r
+ * non-NUL-terminated values. For example on small-valued cell properties\r
+ * this function will return the empty string.\r
+ *\r
+ * If non-NULL, the length of the string (on success) or a negative error-code\r
+ * (on failure) will be stored in the integer pointer to by lenp.\r
+ *\r
+ * @return:\r
+ * A pointer to the string at the given index in the string list or NULL on\r
+ * failure. On success the length of the string will be stored in the memory\r
+ * location pointed to by the lenp parameter, if non-NULL. On failure one of\r
+ * the following negative error codes will be returned in the lenp parameter\r
+ * (if non-NULL):\r
+ * -FDT_ERR_BADVALUE if the property value is not NUL-terminated\r
+ * -FDT_ERR_NOTFOUND if the property does not exist\r
+ */\r
+const char *fdt_stringlist_get(const void *fdt, int nodeoffset,\r
+ const char *property, int index,\r
+ int *lenp);\r
+\r
+/**********************************************************************/\r
+/* Read-only functions (addressing related) */\r
+/**********************************************************************/\r
+\r
+/**\r
+ * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells\r
+ *\r
+ * This is the maximum value for #address-cells, #size-cells and\r
+ * similar properties that will be processed by libfdt. IEE1275\r
+ * requires that OF implementations handle values up to 4.\r
+ * Implementations may support larger values, but in practice higher\r
+ * values aren't used.\r
+ */\r
+#define FDT_MAX_NCELLS 4\r
+\r
+/**\r
+ * fdt_address_cells - retrieve address size for a bus represented in the tree\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node to find the address size for\r
+ *\r
+ * When the node has a valid #address-cells property, returns its value.\r
+ *\r
+ * returns:\r
+ * 0 <= n < FDT_MAX_NCELLS, on success\r
+ * 2, if the node has no #address-cells property\r
+ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid\r
+ * #address-cells property\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADVERSION,\r
+ * -FDT_ERR_BADSTATE,\r
+ * -FDT_ERR_BADSTRUCTURE,\r
+ * -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_address_cells(const void *fdt, int nodeoffset);\r
+\r
+/**\r
+ * fdt_size_cells - retrieve address range size for a bus represented in the\r
+ * tree\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node to find the address range size for\r
+ *\r
+ * When the node has a valid #size-cells property, returns its value.\r
+ *\r
+ * returns:\r
+ * 0 <= n < FDT_MAX_NCELLS, on success\r
+ * 2, if the node has no #address-cells property\r
+ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid\r
+ * #size-cells property\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADVERSION,\r
+ * -FDT_ERR_BADSTATE,\r
+ * -FDT_ERR_BADSTRUCTURE,\r
+ * -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_size_cells(const void *fdt, int nodeoffset);\r
+\r
+\r
/**********************************************************************/\r
/* Write-in-place functions */\r
/**********************************************************************/\r
\r
+/**\r
+ * fdt_setprop_inplace_namelen_partial - change a property's value,\r
+ * but not its size\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @namelen: number of characters of name to consider\r
+ * @idx: index of the property to change in the array\r
+ * @val: pointer to data to replace the property value with\r
+ * @len: length of the property value\r
+ *\r
+ * Identical to fdt_setprop_inplace(), but modifies the given property\r
+ * starting from the given index, and using only the first characters\r
+ * of the name. It is useful when you want to manipulate only one value of\r
+ * an array and you have a string that doesn't end with \0.\r
+ */\r
+#ifndef SWIG /* Not available in Python */\r
+int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,\r
+ const char *name, int namelen,\r
+ uint32_t idx, const void *val,\r
+ int len);\r
+#endif\r
+\r
/**\r
* fdt_setprop_inplace - change a property's value, but not its size\r
* @fdt: pointer to the device tree blob\r
* -FDT_ERR_BADSTRUCTURE,\r
* -FDT_ERR_TRUNCATED, standard meanings\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,\r
const void *val, int len);\r
+#endif\r
\r
/**\r
* fdt_setprop_inplace_u32 - change the value of a 32-bit integer property\r
static inline int fdt_setprop_inplace_u32(void *fdt, int nodeoffset,\r
const char *name, uint32_t val)\r
{\r
- val = cpu_to_fdt32(val);\r
- return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt32_t tmp = cpu_to_fdt32(val);\r
+ return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
static inline int fdt_setprop_inplace_u64(void *fdt, int nodeoffset,\r
const char *name, uint64_t val)\r
{\r
- val = cpu_to_fdt64(val);\r
- return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt64_t tmp = cpu_to_fdt64(val);\r
+ return fdt_setprop_inplace(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
/**********************************************************************/\r
\r
int fdt_create(void *buf, int bufsize);\r
+int fdt_resize(void *fdt, void *buf, int bufsize);\r
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);\r
int fdt_finish_reservemap(void *fdt);\r
int fdt_begin_node(void *fdt, const char *name);\r
int fdt_property(void *fdt, const char *name, const void *val, int len);\r
static inline int fdt_property_u32(void *fdt, const char *name, uint32_t val)\r
{\r
- val = cpu_to_fdt32(val);\r
- return fdt_property(fdt, name, &val, sizeof(val));\r
+ fdt32_t tmp = cpu_to_fdt32(val);\r
+ return fdt_property(fdt, name, &tmp, sizeof(tmp));\r
}\r
static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val)\r
{\r
- val = cpu_to_fdt64(val);\r
- return fdt_property(fdt, name, &val, sizeof(val));\r
+ fdt64_t tmp = cpu_to_fdt64(val);\r
+ return fdt_property(fdt, name, &tmp, sizeof(tmp));\r
}\r
static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)\r
{\r
return fdt_property_u32(fdt, name, val);\r
}\r
+\r
+/**\r
+ * fdt_property_placeholder - add a new property and return a ptr to its value\r
+ *\r
+ * @fdt: pointer to the device tree blob\r
+ * @name: name of property to add\r
+ * @len: length of property value in bytes\r
+ * @valp: returns a pointer to where where the value should be placed\r
+ *\r
+ * returns:\r
+ * 0, on success\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_NOSPACE, standard meanings\r
+ */\r
+int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp);\r
+\r
#define fdt_property_string(fdt, name, str) \\r
fdt_property(fdt, name, str, strlen(str)+1)\r
int fdt_end_node(void *fdt);\r
int fdt_setprop(void *fdt, int nodeoffset, const char *name,\r
const void *val, int len);\r
\r
+/**\r
+ * fdt_setprop _placeholder - allocate space for a property\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ * @len: length of the property value\r
+ * @prop_data: return pointer to property data\r
+ *\r
+ * fdt_setprop_placeholer() allocates the named property in the given node.\r
+ * If the property exists it is resized. In either case a pointer to the\r
+ * property data is returned.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ * 0, on success\r
+ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ * contain the new property value\r
+ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADLAYOUT,\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADVERSION,\r
+ * -FDT_ERR_BADSTATE,\r
+ * -FDT_ERR_BADSTRUCTURE,\r
+ * -FDT_ERR_BADLAYOUT,\r
+ * -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,\r
+ int len, void **prop_data);\r
+\r
/**\r
* fdt_setprop_u32 - set a property to a 32-bit integer\r
* @fdt: pointer to the device tree blob\r
static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,\r
uint32_t val)\r
{\r
- val = cpu_to_fdt32(val);\r
- return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt32_t tmp = cpu_to_fdt32(val);\r
+ return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,\r
uint64_t val)\r
{\r
- val = cpu_to_fdt64(val);\r
- return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt64_t tmp = cpu_to_fdt64(val);\r
+ return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
#define fdt_setprop_string(fdt, nodeoffset, name, str) \\r
fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)\r
\r
+\r
+/**\r
+ * fdt_setprop_empty - set a property to an empty value\r
+ * @fdt: pointer to the device tree blob\r
+ * @nodeoffset: offset of the node whose property to change\r
+ * @name: name of the property to change\r
+ *\r
+ * fdt_setprop_empty() sets the value of the named property in the\r
+ * given node to an empty (zero length) value, or creates a new empty\r
+ * property if it does not already exist.\r
+ *\r
+ * This function may insert or delete data from the blob, and will\r
+ * therefore change the offsets of some existing nodes.\r
+ *\r
+ * returns:\r
+ * 0, on success\r
+ * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to\r
+ * contain the new property value\r
+ * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADLAYOUT,\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADVERSION,\r
+ * -FDT_ERR_BADSTATE,\r
+ * -FDT_ERR_BADSTRUCTURE,\r
+ * -FDT_ERR_BADLAYOUT,\r
+ * -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+#define fdt_setprop_empty(fdt, nodeoffset, name) \\r
+ fdt_setprop((fdt), (nodeoffset), (name), NULL, 0)\r
+\r
/**\r
* fdt_appendprop - append to or create a property\r
* @fdt: pointer to the device tree blob\r
static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,\r
const char *name, uint32_t val)\r
{\r
- val = cpu_to_fdt32(val);\r
- return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt32_t tmp = cpu_to_fdt32(val);\r
+ return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,\r
const char *name, uint64_t val)\r
{\r
- val = cpu_to_fdt64(val);\r
- return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));\r
+ fdt64_t tmp = cpu_to_fdt64(val);\r
+ return fdt_appendprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));\r
}\r
\r
/**\r
* creating subnodes based on a portion of a larger string, such as a\r
* full path.\r
*/\r
+#ifndef SWIG /* Not available in Python */\r
int fdt_add_subnode_namelen(void *fdt, int parentoffset,\r
const char *name, int namelen);\r
+#endif\r
\r
/**\r
* fdt_add_subnode - creates a new node\r
* change the offsets of some existing nodes.\r
\r
* returns:\r
- * structure block offset of the created nodeequested subnode (>=0), on success\r
+ * structure block offset of the created nodeequested subnode (>=0), on\r
+ * success\r
* -FDT_ERR_NOTFOUND, if the requested subnode does not exist\r
- * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag\r
+ * -FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE\r
+ * tag\r
* -FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of\r
* the given name\r
* -FDT_ERR_NOSPACE, if there is insufficient free space in the\r
*/\r
int fdt_del_node(void *fdt, int nodeoffset);\r
\r
+/**\r
+ * fdt_overlay_apply - Applies a DT overlay on a base DT\r
+ * @fdt: pointer to the base device tree blob\r
+ * @fdto: pointer to the device tree overlay blob\r
+ *\r
+ * fdt_overlay_apply() will apply the given device tree overlay on the\r
+ * given base device tree.\r
+ *\r
+ * Expect the base device tree to be modified, even if the function\r
+ * returns an error.\r
+ *\r
+ * returns:\r
+ * 0, on success\r
+ * -FDT_ERR_NOSPACE, there's not enough space in the base device tree\r
+ * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or\r
+ * properties in the base DT\r
+ * -FDT_ERR_BADPHANDLE,\r
+ * -FDT_ERR_BADOVERLAY,\r
+ * -FDT_ERR_NOPHANDLES,\r
+ * -FDT_ERR_INTERNAL,\r
+ * -FDT_ERR_BADLAYOUT,\r
+ * -FDT_ERR_BADMAGIC,\r
+ * -FDT_ERR_BADOFFSET,\r
+ * -FDT_ERR_BADPATH,\r
+ * -FDT_ERR_BADVERSION,\r
+ * -FDT_ERR_BADSTRUCTURE,\r
+ * -FDT_ERR_BADSTATE,\r
+ * -FDT_ERR_TRUNCATED, standard meanings\r
+ */\r
+int fdt_overlay_apply(void *fdt, void *fdto);\r
+\r
/**********************************************************************/\r
/* Debugging / informational functions */\r
/**********************************************************************/\r