Skip to content
Snippets Groups Projects
libfdt.h 53.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	val = cpu_to_fdt64(val);
    	return fdt_property(fdt, name, &val, sizeof(val));
    }
    static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
    {
    	return fdt_property_u32(fdt, name, val);
    }
    
    #define fdt_property_string(fdt, name, str) \
    	fdt_property(fdt, name, str, strlen(str)+1)
    int fdt_end_node(void *fdt);
    int fdt_finish(void *fdt);
    
    
    /**********************************************************************/
    /* Read-write functions                                               */
    /**********************************************************************/
    
    
    int fdt_create_empty_tree(void *buf, int bufsize);
    
    int fdt_open_into(const void *fdt, void *buf, int bufsize);
    
    int fdt_pack(void *fdt);
    
    
    /**
     * fdt_add_mem_rsv - add one memory reserve map entry
     * @fdt: pointer to the device tree blob
    
     * @address, @size: 64-bit values (native endian)
    
     *
     * Adds a reserve map entry to the given blob reserving a region at
     * address address of length size.
     *
     * This function will insert data into the reserve map and will
    
     * therefore change the indexes of some entries in the table.
    
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new reservation entry
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size);
    
    
    /**
     * fdt_del_mem_rsv - remove a memory reserve map entry
     * @fdt: pointer to the device tree blob
     * @n: entry to remove
     *
     * fdt_del_mem_rsv() removes the n-th memory reserve map entry from
     * the blob.
     *
     * This function will delete data from the reservation table and will
    
     * therefore change the indexes of some entries in the table.
    
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOTFOUND, there is no entry of the given index (i.e. there
     *		are less than n+1 reserve map entries)
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    int fdt_del_mem_rsv(void *fdt, int n);
    
    
    /**
     * fdt_set_name - change the name of a given node
     * @fdt: pointer to the device tree blob
     * @nodeoffset: structure block offset of a node
     * @name: name to give the node
     *
     * fdt_set_name() replaces the name (including unit address, if any)
     * of the given node with the given string.  NOTE: this function can't
     * efficiently check if the new name is unique amongst the given
     * node's siblings; results are undefined if this function is invoked
     * with a name equal to one of the given node's siblings.
     *
     * This function may insert or delete data from the blob, and will
     * therefore change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob
     *		to contain the new name
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE, standard meanings
     */
    int fdt_set_name(void *fdt, int nodeoffset, const char *name);
    
    
    /**
     * fdt_setprop - create or change a property
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @val: pointer to data to set the property value to
     * @len: length of the property value
     *
     * fdt_setprop() sets the value of the named property in the given
    
     * node to the given value and length, creating the property if it
    
     * does not already exist.
     *
     * This function may insert or delete data from the blob, and will
     * therefore change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    int fdt_setprop(void *fdt, int nodeoffset, const char *name,
    		const void *val, int len);
    
     * fdt_setprop_u32 - set a property to a 32-bit integer
    
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @val: 32-bit integer value for the property (native endian)
     *
    
     * fdt_setprop_u32() sets the value of the named property in the given
     * node to the given 32-bit integer value (converting to big-endian if
    
     * necessary), or creates a new property with that value if it does
     * not already exist.
     *
     * This function may insert or delete data from the blob, and will
     * therefore change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    static inline int fdt_setprop_u32(void *fdt, int nodeoffset, const char *name,
    				  uint32_t val)
    
    {
    	val = cpu_to_fdt32(val);
    	return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
    }
    
    /**
     * fdt_setprop_u64 - set a property to a 64-bit integer
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @val: 64-bit integer value for the property (native endian)
     *
     * fdt_setprop_u64() sets the value of the named property in the given
     * node to the given 64-bit integer value (converting to big-endian if
     * necessary), or creates a new property with that value if it does
     * not already exist.
     *
     * This function may insert or delete data from the blob, and will
     * therefore change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    static inline int fdt_setprop_u64(void *fdt, int nodeoffset, const char *name,
    				  uint64_t val)
    {
    	val = cpu_to_fdt64(val);
    	return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
    }
    
    /**
     * fdt_setprop_cell - set a property to a single cell value
     *
     * This is an alternative name for fdt_setprop_u32()
     */
    static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
    				   uint32_t val)
    {
    	return fdt_setprop_u32(fdt, nodeoffset, name, val);
    }
    
    
    /**
     * fdt_setprop_string - set a property to a string value
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @str: string value for the property
     *
     * fdt_setprop_string() sets the value of the named property in the
     * given node to the given string value (using the length of the
     * string to determine the new length of the property), or creates a
     * new property with that value if it does not already exist.
     *
     * This function may insert or delete data from the blob, and will
     * therefore change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    #define fdt_setprop_string(fdt, nodeoffset, name, str) \
    	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
    
    /**
     * fdt_appendprop - append to or create a property
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to append to
     * @val: pointer to data to append to the property value
     * @len: length of the data to append to the property value
     *
     * fdt_appendprop() appends the value to the named property in the
     * given node, creating the property if it does not already exist.
     *
     * This function may insert data into the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
    		   const void *val, int len);
    
    /**
    
     * fdt_appendprop_u32 - append a 32-bit integer value to a property
    
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @val: 32-bit integer value to append to the property (native endian)
     *
    
     * fdt_appendprop_u32() appends the given 32-bit integer value
     * (converting to big-endian if necessary) to the value of the named
     * property in the given node, or creates a new property with that
     * value if it does not already exist.
    
     *
     * This function may insert data into the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    static inline int fdt_appendprop_u32(void *fdt, int nodeoffset,
    				     const char *name, uint32_t val)
    
    {
    	val = cpu_to_fdt32(val);
    	return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
    }
    
    
    /**
     * fdt_appendprop_u64 - append a 64-bit integer value to a property
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @val: 64-bit integer value to append to the property (native endian)
     *
     * fdt_appendprop_u64() appends the given 64-bit integer value
     * (converting to big-endian if necessary) to the value of the named
     * property in the given node, or creates a new property with that
     * value if it does not already exist.
     *
     * This function may insert data into the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    static inline int fdt_appendprop_u64(void *fdt, int nodeoffset,
    				     const char *name, uint64_t val)
    {
    	val = cpu_to_fdt64(val);
    	return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
    }
    
    /**
     * fdt_appendprop_cell - append a single cell value to a property
     *
     * This is an alternative name for fdt_appendprop_u32()
     */
    static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
    				      const char *name, uint32_t val)
    {
    	return fdt_appendprop_u32(fdt, nodeoffset, name, val);
    }
    
    
    /**
     * fdt_appendprop_string - append a string to a property
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to change
     * @name: name of the property to change
     * @str: string value to append to the property
     *
     * fdt_appendprop_string() appends the given string to the value of
     * the named property in the given node, or creates a new property
     * with that value if it does not already exist.
     *
     * This function may insert data into the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
     *		contain the new property value
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    #define fdt_appendprop_string(fdt, nodeoffset, name, str) \
    	fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
    
    
    /**
     * fdt_delprop - delete a property
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node whose property to nop
     * @name: name of the property to nop
     *
     * fdt_del_property() will delete the given property.
     *
     * This function will delete data from the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_NOTFOUND, node does not have the named property
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    int fdt_delprop(void *fdt, int nodeoffset, const char *name);
    
    
    /**
     * fdt_add_subnode_namelen - creates a new node based on substring
     * @fdt: pointer to the device tree blob
     * @parentoffset: structure block offset of a node
     * @name: name of the subnode to locate
     * @namelen: number of characters of name to consider
     *
     * Identical to fdt_add_subnode(), but use only the first namelen
     * characters of name as the name of the new node.  This is useful for
     * creating subnodes based on a portion of a larger string, such as a
     * full path.
     */
    
    int fdt_add_subnode_namelen(void *fdt, int parentoffset,
    			    const char *name, int namelen);
    
    
    /**
     * fdt_add_subnode - creates a new node
     * @fdt: pointer to the device tree blob
     * @parentoffset: structure block offset of a node
     * @name: name of the subnode to locate
     *
     * fdt_add_subnode() creates a new node as a subnode of the node at
     * structure block offset parentoffset, with the given name (which
     * should include the unit address, if any).
     *
     * This function will insert data into the blob, and will therefore
     * change the offsets of some existing nodes.
    
     * returns:
     *	structure block offset of the created nodeequested subnode (>=0), on success
     *	-FDT_ERR_NOTFOUND, if the requested subnode does not exist
     *	-FDT_ERR_BADOFFSET, if parentoffset did not point to an FDT_BEGIN_NODE tag
     *	-FDT_ERR_EXISTS, if the node at parentoffset already has a subnode of
     *		the given name
     *	-FDT_ERR_NOSPACE, if there is insufficient free space in the
     *		blob to contain the new node
     *	-FDT_ERR_NOSPACE
     *	-FDT_ERR_BADLAYOUT
     *      -FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_TRUNCATED, standard meanings.
     */
    
    int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
    
    
    /**
     * fdt_del_node - delete a node (subtree)
     * @fdt: pointer to the device tree blob
     * @nodeoffset: offset of the node to nop
     *
     * fdt_del_node() will remove the given node, including all its
     * subnodes if any, from the blob.
     *
     * This function will delete data from the blob, and will therefore
     * change the offsets of some existing nodes.
     *
     * returns:
     *	0, on success
     *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
     *	-FDT_ERR_BADLAYOUT,
     *	-FDT_ERR_BADMAGIC,
     *	-FDT_ERR_BADVERSION,
     *	-FDT_ERR_BADSTATE,
     *	-FDT_ERR_BADSTRUCTURE,
     *	-FDT_ERR_TRUNCATED, standard meanings
     */
    
    int fdt_del_node(void *fdt, int nodeoffset);
    
    
    /**********************************************************************/
    /* Debugging / informational functions                                */
    /**********************************************************************/
    
    
    const char *fdt_strerror(int errval);
    
    #endif /* _LIBFDT_H */