aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-09-30 15:52:10 -0400
committerTom Rini <trini@konsulko.com>2022-09-30 15:52:10 -0400
commit6ee6e15975cad3c99fad3a66223f3fd9287a369b (patch)
tree2a1798758c85d3010640cf6bacb1ad7caaa29133 /include
parent01c88e3dcd667281cf3aa6f6b47f90900177aff9 (diff)
parentdb1ef1e12b993275e09f116ebc3d23d675c7e28c (diff)
downloadu-boot-6ee6e15975cad3c99fad3a66223f3fd9287a369b.tar.gz
Merge branch '2022-09-29-dm-core-support-multiple-device-trees-in-ofnode' into next
To quote the author: At present the ofnode interface is somewhat limited, in that it cannot access the device tree provided by the OS, only the one used by U-Boot itself (assuming these are separate). This prevents using ofnode functions to handle device tree fixups, i.e. ft_board_setup() and the like. The ofnode interface was introduced to allow a consistent API to access the device tree, whether a flat tree or a live tree (OF_LIVE) is in use. With the flat tree, adding nodes and properties at the start of the tree (as often happens when writing to the /chosen node) requires copying a lot of data for each operation. With live tree, such operations are quite a bit faster, since there is no memory copying required. This has to be weighed against the required memory allocation with OF_LIVE, as well as the cost of unflattening and flattening the device tree which U-Boot is running. This series enables support for access to multiple device trees with the ofnode interface. This is already available to some extent with OF_LIVE, but some of the ofnode functions need changes to allow the tree to be specified. The mechanism works by using the top 1-4 bits of the device tree offset. The sign bit is not affected, since negative values must be supported. With this implemented, it becomes possible to use the ofnode interface to do device tree fixups. The only current user is the EVT_FT_FIXUP event. This has two main benefits: - ofnode can now be used everywhere, in preference to the libfdt calls - live tree can eventually be used everywhere, with potential speed improvements when larger number of fixups are used This series is only a step along the way. Firstly, while it is possible to access the 'fix-up' tree using OF_LIVE, most of the fixup functions use flat tree directly, rather than the ofnode interface. These need to be updated. Also the tree must be flattened again before it is passed to the OS. This is not currently implemented. With OFNODE_MULTI_TREE disabled this has almost no effect on code size: around 4 bytes if EVENT is enabled, 0 if not. With the feature enabled, the increase is around 700 bytes, e.g. on venice2: $ buildman -b ofn2a venice2 -sS --step 0 Summary of 2 commits for 1 boards (1 thread, 64 jobs per thread) 01: image: Drop some other #ifdefs in image-board.c arm: w+ venice2 48: wip arm: (for 1/1 boards) all +668.0 text +668.0 This size increase is not too bad, considering the extra functionality, but is too large to enable everywhere. So for now this features needs to be opt-in only, based on EVENT.
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/global_data.h4
-rw-r--r--include/bootm.h6
-rw-r--r--include/configs/uniphier.h2
-rw-r--r--include/dm/device.h6
-rw-r--r--include/dm/of.h15
-rw-r--r--include/dm/of_access.h29
-rw-r--r--include/dm/ofnode.h345
-rw-r--r--include/dm/ofnode_decl.h37
-rw-r--r--include/dm/read.h8
-rw-r--r--include/event.h6
-rw-r--r--include/image.h118
-rw-r--r--include/log.h5
-rw-r--r--include/malloc.h12
-rw-r--r--include/spl.h8
-rw-r--r--include/tee/optee.h4
-rw-r--r--include/test/test.h30
-rw-r--r--include/test/ut.h5
17 files changed, 484 insertions, 156 deletions
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 4aeb61f08c4..2d55fe2ac0f 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -646,6 +646,10 @@ enum gd_flags {
* @GD_FLG_SMP_READY: SMP initialization is complete
*/
GD_FLG_SMP_READY = 0x80000,
+ /**
+ * @GD_FLG_FDT_CHANGED: Device tree change has been detected by tests
+ */
+ GD_FLG_FDT_CHANGED = 0x100000,
};
#endif /* __ASSEMBLY__ */
diff --git a/include/bootm.h b/include/bootm.h
index 7ed5650fcaa..044a4797ed3 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -33,7 +33,7 @@ struct cmd_tbl;
* not return.
*/
typedef int boot_os_fn(int flag, int argc, char *const argv[],
- bootm_headers_t *images);
+ struct bootm_headers *images);
extern boot_os_fn do_bootm_linux;
extern boot_os_fn do_bootm_vxworks;
@@ -47,7 +47,7 @@ int bootm_host_load_images(const void *fit, int cfg_noffset);
#endif
int boot_selected_os(int argc, char *const argv[], int state,
- bootm_headers_t *images, boot_os_fn *boot_fn);
+ struct bootm_headers *images, boot_os_fn *boot_fn);
ulong bootm_disable_interrupts(void);
@@ -56,7 +56,7 @@ int bootm_find_images(int flag, int argc, char *const argv[], ulong start,
ulong size);
int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[], int states, bootm_headers_t *images,
+ char *const argv[], int states, struct bootm_headers *images,
int boot_progress);
void arch_preboot_os(void);
diff --git a/include/configs/uniphier.h b/include/configs/uniphier.h
index 15ae0844c1a..d9e95abcc12 100644
--- a/include/configs/uniphier.h
+++ b/include/configs/uniphier.h
@@ -169,7 +169,7 @@
/* only for SPL */
-/* subtract sizeof(struct image_header) */
+/* subtract sizeof(struct legacy_img_hdr) */
#define CONFIG_SYS_UBOOT_BASE (0x130000 - 0x40)
#endif /* __CONFIG_UNIPHIER_H__ */
diff --git a/include/dm/device.h b/include/dm/device.h
index 12c6ba37ff3..f3f953c9afc 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -253,7 +253,7 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic)
* @dev: device to check
* Return: reference of the device's DT node
*/
-static inline ofnode dev_ofnode(const struct udevice *dev)
+static inline __attribute_const__ ofnode dev_ofnode(const struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_REAL)
return dev->node_;
@@ -273,7 +273,7 @@ static inline ofnode dev_ofnode(const struct udevice *dev)
#define dev_get_dma_offset(_dev) 0
#endif
-static inline int dev_of_offset(const struct udevice *dev)
+static inline __attribute_const__ int dev_of_offset(const struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_REAL)
return ofnode_to_offset(dev_ofnode(dev));
@@ -282,7 +282,7 @@ static inline int dev_of_offset(const struct udevice *dev)
#endif
}
-static inline bool dev_has_ofnode(const struct udevice *dev)
+static inline __attribute_const__ bool dev_has_ofnode(const struct udevice *dev)
{
#if CONFIG_IS_ENABLED(OF_REAL)
return ofnode_valid(dev_ofnode(dev));
diff --git a/include/dm/of.h b/include/dm/of.h
index 9c9065b7932..fce7cef0ff6 100644
--- a/include/dm/of.h
+++ b/include/dm/of.h
@@ -31,10 +31,21 @@ struct property {
/**
* struct device_node: Device tree node
*
- * @name: Node name
+ * The top of this tree is typically gd->of_root which points to the root node.
+ *
+ * The head of the list of children for the root node (and any other node) is
+ * in @child, with @sibling providing a link to the next child.
+ *
+ * Each child has a pointer to its parent in @parent.
+ *
+ * A node may have properties in which case the head of the list of properties
+ * @properties pointers to the first one, with struct property->@next pointing
+ * to the next one.
+ *
+ * @name: Node name, "" for the root node
* @type: Node type (value of device_type property) or "<NULL>" if none
* @phandle: Phandle value of this none, or 0 if none
- * @full_name: Full path to node, e.g. "/bus@1/spi@1100"
+ * @full_name: Full path to node, e.g. "/bus@1/spi@1100" ("/" for the root node)
* @properties: Pointer to head of list of properties, or NULL if none
* @parent: Pointer to parent node, or NULL if this is the root node
* @child: Pointer to head of child node list, or NULL if no children
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index 83f34f0d2ad..c556a18f7d9 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -258,11 +258,13 @@ struct device_node *of_find_node_by_prop_value(struct device_node *from,
/**
* of_find_node_by_phandle() - Find a node given a phandle
*
+ * @root: root node to start from (NULL for default device tree)
* @handle: phandle of the node to find
*
* Return: node pointer, or NULL if not found
*/
-struct device_node *of_find_node_by_phandle(phandle handle);
+struct device_node *of_find_node_by_phandle(struct device_node *root,
+ phandle handle);
/**
* of_read_u8() - Find and read a 8-bit integer from a property
@@ -325,8 +327,7 @@ int of_read_u32(const struct device_node *np, const char *propname, u32 *outp);
* @outp: pointer to return value, modified only if return value is 0.
*
* Return:
- * 0 on success, -EINVAL if the property does not exist,
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the
* property data isn't large enough.
*/
int of_read_u32_index(const struct device_node *np, const char *propname,
@@ -343,8 +344,7 @@ int of_read_u32_index(const struct device_node *np, const char *propname,
* @outp: pointer to return value, modified only if return value is 0.
*
* Return:
- * 0 on success, -EINVAL if the property does not exist,
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the
* property data isn't large enough.
*/
int of_read_u64(const struct device_node *np, const char *propname, u64 *outp);
@@ -360,8 +360,8 @@ int of_read_u64(const struct device_node *np, const char *propname, u64 *outp);
* @out_values: pointer to return value, modified only if return value is 0.
* @sz: number of array elements to read
* Return:
- * 0 on success, -EINVAL if the property does not exist, -ENODATA
- * if property does not have a value, and -EOVERFLOW is longer than sz.
+ * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if
+ * longer than sz.
*/
int of_read_u32_array(const struct device_node *np, const char *propname,
u32 *out_values, size_t sz);
@@ -563,4 +563,19 @@ struct device_node *of_get_stdout(void);
int of_write_prop(struct device_node *np, const char *propname, int len,
const void *value);
+/**
+ * of_add_subnode() - add a new subnode to a node
+ *
+ * @node: parent node to add to
+ * @name: name of subnode
+ * @len: length of name (so the caller does not need to nul-terminate a
+ * partial string), or -1 for strlen(@name)
+ * @subnodep: returns pointer to new subnode (valid if the function returns 0
+ * or -EEXIST)
+ * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other
+ * -ve on other error
+ */
+int of_add_subnode(struct device_node *node, const char *name, int len,
+ struct device_node **subnodep);
+
#endif
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index f6085231bbd..7aae2c29ef1 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -27,70 +27,147 @@ struct ofnode_phandle_args {
uint32_t args[OF_MAX_PHANDLE_ARGS];
};
+#if CONFIG_IS_ENABLED(OFNODE_MULTI_TREE)
/**
- * ofnode_to_np() - convert an ofnode to a live DT node pointer
+ * oftree_reset() - reset the state of the oftree list
*
- * This cannot be called if the reference contains an offset.
+ * Reset the oftree list so it can be started again. This should be called
+ * once the control FDT is in place, but before the ofnode interface is used.
+ */
+void oftree_reset(void);
+
+/**
+ * ofnode_to_fdt() - convert an ofnode to a flat DT pointer
*
- * @node: Reference containing struct device_node * (possibly invalid)
- * Return: pointer to device node (can be NULL)
+ * This cannot be called if the reference contains a node pointer.
+ *
+ * @node: Reference containing offset (possibly invalid)
+ * Return: DT offset (can be NULL)
+ */
+__attribute_const__ void *ofnode_to_fdt(ofnode node);
+
+/**
+ * ofnode_to_offset() - convert an ofnode to a flat DT offset
+ *
+ * This cannot be called if the reference contains a node pointer.
+ *
+ * @node: Reference containing offset (possibly invalid)
+ * Return: DT offset (can be -1)
+ */
+__attribute_const__ int ofnode_to_offset(ofnode node);
+
+/**
+ * oftree_from_fdt() - Returns an oftree from a flat device tree pointer
+ *
+ * @fdt: Device tree to use
+ *
+ * Returns: reference to the given node
*/
-static inline const struct device_node *ofnode_to_np(ofnode node)
+oftree oftree_from_fdt(void *fdt);
+
+/**
+ * noffset_to_ofnode() - convert a DT offset to an ofnode
+ *
+ * @other_node: Node in the same tree to use as a reference
+ * @of_offset: DT offset (either valid, or -1)
+ * Return: reference to the associated DT offset
+ */
+ofnode noffset_to_ofnode(ofnode other_node, int of_offset);
+
+#else /* !OFNODE_MULTI_TREE */
+static inline void oftree_reset(void) {}
+
+static inline void *ofnode_to_fdt(ofnode node)
{
#ifdef OF_CHECKS
- if (!of_live_active())
+ if (of_live_active())
return NULL;
#endif
- return node.np;
+ /* Use the control FDT by default */
+ return (void *)gd->fdt_blob;
}
+static inline __attribute_const__ int ofnode_to_offset(ofnode node)
+{
+#ifdef OF_CHECKS
+ if (of_live_active())
+ return -1;
+#endif
+ return node.of_offset;
+}
+
+static inline oftree oftree_from_fdt(void *fdt)
+{
+ oftree tree;
+
+ /* we cannot access other trees without OFNODE_MULTI_TREE */
+ if (fdt == gd->fdt_blob)
+ tree.fdt = fdt;
+ else
+ tree.fdt = NULL;
+
+ return tree;
+}
+
+static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset)
+{
+ ofnode node;
+
+ if (of_live_active())
+ node.np = NULL;
+ else
+ node.of_offset = of_offset;
+
+ return node;
+}
+
+#endif /* OFNODE_MULTI_TREE */
+
/**
- * ofnode_to_npw() - convert an ofnode to a writeable live DT node pointer
+ * ofnode_to_np() - convert an ofnode to a live DT node pointer
*
* This cannot be called if the reference contains an offset.
*
* @node: Reference containing struct device_node * (possibly invalid)
* Return: pointer to device node (can be NULL)
*/
-static inline struct device_node *ofnode_to_npw(ofnode node)
+static inline struct device_node *ofnode_to_np(ofnode node)
{
#ifdef OF_CHECKS
if (!of_live_active())
return NULL;
#endif
- /* Drop constant */
- return (struct device_node *)node.np;
+ return node.np;
}
/**
- * ofnode_to_offset() - convert an ofnode to a flat DT offset
- *
- * This cannot be called if the reference contains a node pointer.
+ * ofnode_valid() - check if an ofnode is valid
*
* @node: Reference containing offset (possibly invalid)
- * Return: DT offset (can be -1)
+ * Return: true if the reference contains a valid ofnode, false if not
*/
-static inline int ofnode_to_offset(ofnode node)
+static inline bool ofnode_valid(ofnode node)
{
-#ifdef OF_CHECKS
if (of_live_active())
- return -1;
-#endif
- return node.of_offset;
+ return node.np != NULL;
+ else
+ return node.of_offset >= 0;
}
/**
- * ofnode_valid() - check if an ofnode is valid
+ * oftree_lookup_fdt() - obtain the FDT pointer from an oftree
*
- * @node: Reference containing offset (possibly invalid)
- * Return: true if the reference contains a valid ofnode, false if it is NULL
+ * This can only be called when flat tree is enabled
+ *
+ * @tree: Tree to look at
+ * @return FDT pointer from the tree
*/
-static inline bool ofnode_valid(ofnode node)
+static inline void *oftree_lookup_fdt(oftree tree)
{
if (of_live_active())
- return node.np != NULL;
+ return NULL;
else
- return node.of_offset >= 0;
+ return tree.fdt;
}
/**
@@ -117,7 +194,7 @@ static inline ofnode offset_to_ofnode(int of_offset)
* @np: Live node pointer (can be NULL)
* Return: reference to the associated node pointer
*/
-static inline ofnode np_to_ofnode(const struct device_node *np)
+static inline ofnode np_to_ofnode(struct device_node *np)
{
ofnode node;
@@ -165,6 +242,38 @@ static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
}
/**
+ * oftree_valid() - check if an oftree is valid
+ *
+ * @tree: Reference containing oftree
+ * Return: true if the reference contains a valid oftree, false if node
+ */
+static inline bool oftree_valid(oftree tree)
+{
+ if (of_live_active())
+ return tree.np;
+ else
+ return tree.fdt;
+}
+
+/**
+ * oftree_null() - Obtain a null oftree
+ *
+ * This returns an oftree which points to no tree. It works both with the flat
+ * tree and livetree.
+ */
+static inline oftree oftree_null(void)
+{
+ oftree tree;
+
+ if (of_live_active())
+ tree.np = NULL;
+ else
+ tree.fdt = NULL;
+
+ return tree;
+}
+
+/**
* ofnode_null() - Obtain a null ofnode
*
* This returns an ofnode which points to no node. It works both with the flat
@@ -195,6 +304,20 @@ static inline ofnode ofnode_root(void)
}
/**
+ * ofprop_valid() - check if an ofprop is valid
+ *
+ * @prop: Pointer to ofprop to check
+ * Return: true if the reference contains a valid ofprop, false if not
+ */
+static inline bool ofprop_valid(struct ofprop *prop)
+{
+ if (of_live_active())
+ return prop->prop;
+ else
+ return prop->offset >= 0;
+}
+
+/**
* oftree_default() - Returns the default device tree (U-Boot's control FDT)
*
* Returns: reference to the control FDT
@@ -212,6 +335,21 @@ static inline oftree oftree_default(void)
}
/**
+ * oftree_from_np() - Returns an oftree from a node pointer
+ *
+ * @root: Root node of the tree
+ * Returns: reference to the given node
+ */
+static inline oftree oftree_from_np(struct device_node *root)
+{
+ oftree tree;
+
+ tree.np = root;
+
+ return tree;
+}
+
+/**
* ofnode_name_eq() - Check if the node name is equivalent to a given name
* ignoring the unit address
*
@@ -377,12 +515,12 @@ const char *ofnode_read_string(ofnode node, const char *propname);
* @propname: name of the property to read
* @out_values: pointer to return value, modified only if return value is 0
* @sz: number of array elements to read
- * Return: 0 if OK, -ve on error
+ * Return: 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough
*
* Search for a property in a device node and read 32-bit value(s) from
- * it. Returns 0 on success, -EINVAL if the property does not exist,
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
- * property data isn't large enough.
+ * it.
*
* The out_values is modified only if a valid u32 value can be decoded.
*/
@@ -484,7 +622,7 @@ ofnode ofnode_get_parent(ofnode node);
* ofnode_get_name() - get the name of a node
*
* @node: valid node to look up
- * Return: name of node
+ * Return: name of node (for the root node this is "")
*/
const char *ofnode_get_name(ofnode node);
@@ -501,12 +639,23 @@ int ofnode_get_path(ofnode node, char *buf, int buflen);
/**
* ofnode_get_by_phandle() - get ofnode from phandle
*
+ * This uses the default (control) device tree
+ *
* @phandle: phandle to look up
* Return: ofnode reference to the phandle
*/
ofnode ofnode_get_by_phandle(uint phandle);
/**
+ * oftree_get_by_phandle() - get ofnode from phandle
+ *
+ * @tree: tree to use
+ * @phandle: phandle to look up
+ * Return: ofnode reference to the phandle
+ */
+ofnode oftree_get_by_phandle(oftree tree, uint phandle);
+
+/**
* ofnode_read_size() - read the size of a property
*
* @node: node to check
@@ -723,18 +872,28 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
ofnode ofnode_path(const char *path);
/**
- * ofnode_path_root() - find a node by full path from a root node
+ * oftree_path() - find a node by full path from a root node
*
* @tree: Device tree to use
* @path: Full path to node, e.g. "/bus/spi@1"
* Return: reference to the node found. Use ofnode_valid() to check if it exists
*/
-ofnode ofnode_path_root(oftree tree, const char *path);
+ofnode oftree_path(oftree tree, const char *path);
+
+/**
+ * oftree_root() - get the root node of a tree
+ *
+ * @tree: Device tree to use
+ * Return: reference to the root node
+ */
+ofnode oftree_root(oftree tree);
/**
* ofnode_read_chosen_prop() - get the value of a chosen property
*
- * This looks for a property within the /chosen node and returns its value
+ * This looks for a property within the /chosen node and returns its value.
+ *
+ * This only works with the control FDT.
*
* @propname: Property name to look for
* @sizep: Returns size of property, or `FDT_ERR_...` error code if function
@@ -749,6 +908,8 @@ const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
* This looks for a property within the /chosen node and returns its value,
* checking that it is a valid nul-terminated string
*
+ * This only works with the control FDT.
+ *
* @propname: Property name to look for
* Return: string value if found, else NULL
*/
@@ -760,6 +921,8 @@ const char *ofnode_read_chosen_string(const char *propname);
* This looks up a named property in the chosen node and uses that as a path to
* look up a code.
*
+ * This only works with the control FDT.
+ *
* @propname: Property name to look for
* Return: the referenced node if present, else ofnode_null()
*/
@@ -770,6 +933,8 @@ ofnode ofnode_get_chosen_node(const char *propname);
*
* This looks for a property within the /aliases node and returns its value
*
+ * This only works with the control FDT.
+ *
* @propname: Property name to look for
* @sizep: Returns size of property, or `FDT_ERR_...` error code if function
* returns NULL
@@ -783,6 +948,8 @@ const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
* This looks up a named property in the aliases node and uses that as a path to
* look up a code.
*
+ * This only works with the control FDT.
+ *
* @propname: Property name to look for
* Return: the referenced node if present, else ofnode_null()
*/
@@ -815,48 +982,64 @@ int ofnode_decode_display_timing(ofnode node, int index,
const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
/**
- * ofnode_get_first_property()- get the reference of the first property
+ * ofnode_first_property()- get the reference of the first property
*
* Get reference to the first property of the node, it is used to iterate
- * and read all the property with ofnode_get_property_by_prop().
+ * and read all the property with ofprop_get_property().
*
* @node: node to read
* @prop: place to put argument reference
* Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
*/
-int ofnode_get_first_property(ofnode node, struct ofprop *prop);
+int ofnode_first_property(ofnode node, struct ofprop *prop);
/**
- * ofnode_get_next_property() - get the reference of the next property
+ * ofnode_next_property() - get the reference of the next property
*
* Get reference to the next property of the node, it is used to iterate
- * and read all the property with ofnode_get_property_by_prop().
+ * and read all the property with ofprop_get_property().
*
* @prop: reference of current argument and place to put reference of next one
* Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
*/
-int ofnode_get_next_property(struct ofprop *prop);
+int ofnode_next_property(struct ofprop *prop);
/**
- * ofnode_get_property_by_prop() - get a pointer to the value of a property
+ * ofnode_for_each_prop() - iterate over all properties of a node
*
- * Get value for the property identified by the provided reference.
+ * @prop: struct ofprop
+ * @node: node (lvalue, ofnode)
*
- * @prop: reference on property
- * @propname: If non-NULL, place to property name on success,
- * @lenp: If non-NULL, place to put length on success
- * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
+ * This is a wrapper around a for loop and is used like this::
+ *
+ * ofnode node;
+ * struct ofprop prop;
+ *
+ * ofnode_for_each_prop(prop, node) {
+ * ...use prop...
+ * }
+ *
+ * Note that this is implemented as a macro and @prop is used as
+ * iterator in the loop. The parent variable can be a constant or even a
+ * literal.
*/
-const void *ofnode_get_property_by_prop(const struct ofprop *prop,
- const char **propname, int *lenp);
+#define ofnode_for_each_prop(prop, node) \
+ for (ofnode_first_property(node, &prop); \
+ ofprop_valid(&prop); \
+ ofnode_next_property(&prop))
/**
- * ofnode_is_available() - check if a node is marked available
+ * ofprop_get_property() - get a pointer to the value of a property
*
- * @node: node to check
- * Return: true if node's 'status' property is "okay" (or is missing)
+ * Get value for the property identified by the provided reference.
+ *
+ * @prop: reference on property
+ * @propname: If non-NULL, place to property name on success,
+ * @lenp: If non-NULL, place to put length on success, or error code on failure
+ * Return: pointer to property, or NULL if not found
*/
-bool ofnode_is_available(ofnode node);
+const void *ofprop_get_property(const struct ofprop *prop,
+ const char **propname, int *lenp);
/**
* ofnode_get_addr_size() - get address and size from a property
@@ -1046,8 +1229,9 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat);
* Find the next node after @from that has a @propname with a value
* @propval and a length @proplen.
*
- * @from: ofnode to start from (use ofnode_null() to start at the
- * beginning)
+ * @from: ofnode to start from. Use ofnode_null() to start at the
+ * beginning, or the return value from oftree_root() to start at the first
+ * child of the root
* @propname: property name to check
* @propval: property value to search for
* @proplen: length of the value in propval
@@ -1166,19 +1350,23 @@ int ofnode_device_is_compatible(ofnode node, const char *compat);
/**
* ofnode_write_prop() - Set a property of a ofnode
*
- * Note that the value passed to the function is *not* allocated by the
- * function itself, but must be allocated by the caller if necessary. However
- * it does allocate memory for the property struct and name.
+ * Note that if @copy is false, the value passed to the function is *not*
+ * allocated by the function itself, but must be allocated by the caller if
+ * necessary. However it does allocate memory for the property struct and name.
*
* @node: The node for whose property should be set
* @propname: The name of the property to set
* @value: The new value of the property (must be valid prior to calling
* the function)
* @len: The length of the new value of the property
+ * @copy: true to allocate memory for the value. This only has any effect with
+ * live tree, since flat tree handles this automatically. It allows a
+ * node's value to be written to the tree, without requiring that the
+ * caller allocate it
* Return: 0 if successful, -ve on error
*/
int ofnode_write_prop(ofnode node, const char *propname, const void *value,
- int len);
+ int len, bool copy);
/**
* ofnode_write_string() - Set a string property of a ofnode
@@ -1251,7 +1439,9 @@ phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
*
* This reads a property from the /config node of the devicetree.
*
- * See doc/config.txt for bindings
+ * This only works with the control FDT.
+ *
+ * See doc/device-tree-bindings/config.txt for bindings
*
* @prop_name: property name to look up
* Return: true, if it exists, false if not
@@ -1263,7 +1453,7 @@ bool ofnode_conf_read_bool(const char *prop_name);
*
* This reads a property from the /config node of the devicetree.
*
- * See doc/config.txt for bindings
+ * See doc/device-tree-bindings/config.txt for bindings
*
* @prop_name: property name to look up
* @default_val: default value to return if the property is not found
@@ -1276,7 +1466,9 @@ int ofnode_conf_read_int(const char *prop_name, int default_val);
*
* This reads a property from the /config node of the devicetree.
*
- * See doc/config.txt for bindings
+ * This only works with the control FDT.
+ *
+ * See doc/device-tree-bindings/config.txt for bindings
*
* @prop_name: property name to look up
* Return: string value, if found, or NULL if not
@@ -1298,6 +1490,35 @@ static inline const char *ofnode_conf_read_str(const char *prop_name)
{
return NULL;
}
+
#endif /* CONFIG_DM */
+/**
+ * of_add_subnode() - add a new subnode to a node
+ *
+ * @parent: parent node to add to
+ * @name: name of subnode
+ * @nodep: returns pointer to new subnode (valid if the function returns 0
+ * or -EEXIST)
+ * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other
+ * -ve on other error
+ */
+int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep);
+
+/**
+ * ofnode_copy_props() - copy all properties from one node to another
+ *
+ * Makes a copy of all properties from the source note in the destination node.
+ * Existing properties in the destination node remain unchanged, except that
+ * any with the same name are overwritten, including changing the size of the
+ * property.
+ *
+ * For livetree, properties are copied / allocated, so the source tree does not
+ * need to be present afterwards.
+ *
+ * @src: Source node to read properties from
+ * @dst: Destination node to write properties too
+ */
+int ofnode_copy_props(ofnode src, ofnode dst);
+
#endif
diff --git a/include/dm/ofnode_decl.h b/include/dm/ofnode_decl.h
index 266253d5e33..5c2115aab0b 100644
--- a/include/dm/ofnode_decl.h
+++ b/include/dm/ofnode_decl.h
@@ -31,18 +31,47 @@
* this increases code size slightly due to the subtraction. Since it offers no
* real benefit, the approach described here seems best.
*
- * For now these points use constant types, since we don't allow writing
- * the DT.
+ * Where multiple trees are in use, this works without any trouble with live
+ * tree, except for aliases, such as ofnode_path("mmc0"), which only work on the
+ * control FDT. When the flat tree is in use, the trees are registered and a
+ * 'tree ID' is encoded into the top bits of @of_offset - see immediately below
+ * for the associated macro definitions. Note that 64-bit machines use the same
+ * encoding, even though there is more space available. This is partly because
+ * the FDT format contains 32-bit values for things like the string-table
+ * offset, therefore 64-bit offsets cannot be supported anyway.
+ *
+ * For the multiple-tree case, an invalid offset (i.e. with of_offset < 0) is
+ * still invalid. It does not contain a tree ID. So there is no way of knowing
+ * which tree produced the invalid offset.
*
* @np: Pointer to device node, used for live tree
* @of_offset: Pointer into flat device tree, used for flat tree. Note that this
* is not a really a pointer to a node: it is an offset value. See above.
*/
typedef union ofnode_union {
- const struct device_node *np;
+ struct device_node *np;
long of_offset;
} ofnode;
+/* shift for the tree ID within of_offset */
+#define OF_TREE_SHIFT 28
+
+/* mask to obtain the device tree offset from of_offset */
+#define OF_TREE_MASK ((1 << OF_TREE_SHIFT) - 1)
+
+/* encode a tree ID and node offset into an of_offset value */
+#define OFTREE_NODE(tree_id, offs) ((tree_id) << OF_TREE_SHIFT | (offs))
+
+/* decode the node offset from an of_offset value */
+#define OFTREE_OFFSET(of_offs) ((of_offs) & OF_TREE_MASK)
+
+/* decode the tree ID from an of_offset value */
+#define OFTREE_TREE_ID(of_offs) ((of_offs) >> OF_TREE_SHIFT)
+
+/* encode a node offset in the tree given by another node's of_offset value */
+#define OFTREE_MAKE_NODE(other_of_offset, offs) \
+ (((offs) & OF_TREE_MASK) | ((other_of_offset) & ~OF_TREE_MASK))
+
/**
* struct ofprop - reference to a property of a device tree node
*
@@ -57,7 +86,7 @@ typedef union ofnode_union {
*
* @node: Pointer to device node
* @offset: Pointer into flat device tree, used for flat tree.
- * @prop: Pointer to property, used for live treee.
+ * @prop: Pointer to property, used for live tree.
*/
struct ofprop {
diff --git a/include/dm/read.h b/include/dm/read.h
index 122b9cd15b8..cc4f16196fd 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -569,7 +569,7 @@ const void *dev_read_prop(const struct udevice *dev, const char *propname,
int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
/**
- * ofnode_get_next_property() - get the reference of the next property
+ * ofnode_next_property() - get the reference of the next property
*
* Get reference to the next property of the node, it is used to iterate
* and read all the property with dev_read_prop_by_prop().
@@ -1079,19 +1079,19 @@ static inline const void *dev_read_prop(const struct udevice *dev,
static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
{
- return ofnode_get_first_property(dev_ofnode(dev), prop);
+ return ofnode_first_property(dev_ofnode(dev), prop);
}
static inline int dev_read_next_prop(struct ofprop *prop)
{
- return ofnode_get_next_property(prop);
+ return ofnode_next_property(prop);
}
static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
const char **propname,
int *lenp)
{
- return ofnode_get_property_by_prop(prop, propname, lenp);
+ return ofprop_get_property(prop, propname, lenp);
}
static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
diff --git a/include/event.h b/include/event.h
index e8f2f55c63d..3e6dcbc3dd6 100644
--- a/include/event.h
+++ b/include/event.h
@@ -60,9 +60,11 @@ union event_data {
* struct event_ft_fixup - FDT fixup before booting
*
* @tree: tree to update
+ * @images: images which are being booted
*/
struct event_ft_fixup {
oftree tree;
+ struct bootm_headers *images;
} ft_fixup;
};
@@ -143,8 +145,8 @@ static inline const char *event_spy_id(struct evspy_info *spy)
* vbe_simple.c - so for now, make it global.
*/
#define EVENT_SPY(_type, _func) \
- __used ll_entry_declare(struct evspy_info, _type, evspy_info) = \
- _ESPY_REC(_type, _func)
+ __used ll_entry_declare(struct evspy_info, _type ## _3_ ## _func, \
+ evspy_info) = _ESPY_REC(_type, _func)
/**
* event_register - register a new spy
diff --git a/include/image.h b/include/image.h
index 03424f05219..eb2513c5b74 100644
--- a/include/image.h
+++ b/include/image.h
@@ -263,7 +263,7 @@ enum {
* Legacy format image header,
* all data in network byte order (aka natural aka bigendian).
*/
-typedef struct image_header {
+struct legacy_img_hdr {
uint32_t ih_magic; /* Image Header Magic Number */
uint32_t ih_hcrc; /* Image Header CRC Checksum */
uint32_t ih_time; /* Image Creation Timestamp */
@@ -276,28 +276,28 @@ typedef struct image_header {
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN]; /* Image Name */
-} image_header_t;
+};
-typedef struct image_info {
+struct image_info {
ulong start, end; /* start/end of blob */
ulong image_start, image_len; /* start of image within blob, len of image */
ulong load; /* load addr for the image */
uint8_t comp, type, os; /* compression, type of image, os type */
uint8_t arch; /* CPU architecture */
-} image_info_t;
+};
/*
* Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
* routines.
*/
-typedef struct bootm_headers {
+struct bootm_headers {
/*
* Legacy os image header, if it is a multi component image
* then boot_get_ramdisk() and get_fdt() will attempt to get
* data from second and third component accordingly.
*/
- image_header_t *legacy_hdr_os; /* image header pointer */
- image_header_t legacy_hdr_os_copy; /* header copy */
+ struct legacy_img_hdr *legacy_hdr_os; /* image header pointer */
+ struct legacy_img_hdr legacy_hdr_os_copy; /* header copy */
ulong legacy_hdr_valid;
/*
@@ -324,7 +324,7 @@ typedef struct bootm_headers {
int fit_noffset_setup;/* x86 setup subimage node offset */
#ifndef USE_HOSTCC
- image_info_t os; /* os image info */
+ struct image_info os; /* os image info */
ulong ep; /* entry point of OS */
ulong rd_start, rd_end;/* ramdisk start/end */
@@ -341,24 +341,24 @@ typedef struct bootm_headers {
int verify; /* env_get("verify")[0] != 'n' */
-#define BOOTM_STATE_START (0x00000001)
-#define BOOTM_STATE_FINDOS (0x00000002)
-#define BOOTM_STATE_FINDOTHER (0x00000004)
-#define BOOTM_STATE_LOADOS (0x00000008)
-#define BOOTM_STATE_RAMDISK (0x00000010)
-#define BOOTM_STATE_FDT (0x00000020)
-#define BOOTM_STATE_OS_CMDLINE (0x00000040)
-#define BOOTM_STATE_OS_BD_T (0x00000080)
-#define BOOTM_STATE_OS_PREP (0x00000100)
-#define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
-#define BOOTM_STATE_OS_GO (0x00000400)
-#define BOOTM_STATE_PRE_LOAD 0x00000800
+#define BOOTM_STATE_START 0x00000001
+#define BOOTM_STATE_FINDOS 0x00000002
+#define BOOTM_STATE_FINDOTHER 0x00000004
+#define BOOTM_STATE_LOADOS 0x00000008
+#define BOOTM_STATE_RAMDISK 0x00000010
+#define BOOTM_STATE_FDT 0x00000020
+#define BOOTM_STATE_OS_CMDLINE 0x00000040
+#define BOOTM_STATE_OS_BD_T 0x00000080
+#define BOOTM_STATE_OS_PREP 0x00000100
+#define BOOTM_STATE_OS_FAKE_GO 0x00000200 /* 'Almost' run the OS */
+#define BOOTM_STATE_OS_GO 0x00000400
+#define BOOTM_STATE_PRE_LOAD 0x00000800
int state;
#if defined(CONFIG_LMB) && !defined(USE_HOSTCC)
struct lmb lmb; /* for memory mgmt */
#endif
-} bootm_headers_t;
+};
#ifdef CONFIG_LMB
#define images_lmb(_images) (&(_images)->lmb)
@@ -366,7 +366,7 @@ typedef struct bootm_headers {
#define images_lmb(_images) NULL
#endif
-extern bootm_headers_t images;
+extern struct bootm_headers images;
/*
* Some systems (for example LWMON) have very short watchdog periods;
@@ -530,7 +530,7 @@ enum fit_load_op {
FIT_LOAD_REQUIRED, /* Must be provided */
};
-int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
+int boot_get_setup(struct bootm_headers *images, uint8_t arch, ulong *setup_start,
ulong *setup_len);
/* Image format types, returned by _get_format() routine */
@@ -544,11 +544,11 @@ ulong genimg_get_kernel_addr_fit(char * const img_addr,
const char **fit_uname_kernel);
ulong genimg_get_kernel_addr(char * const img_addr);
int genimg_get_format(const void *img_addr);
-int genimg_has_config(bootm_headers_t *images);
+int genimg_has_config(struct bootm_headers *images);
-int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
+int boot_get_fpga(int argc, char *const argv[], struct bootm_headers *images,
uint8_t arch, const ulong *ld_start, ulong * const ld_len);
-int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
+int boot_get_ramdisk(int argc, char *const argv[], struct bootm_headers *images,
uint8_t arch, ulong *rd_start, ulong *rd_end);
/**
@@ -572,10 +572,10 @@ int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
* 0, if only valid images or no images are found
* error code, if an error occurs during fit_image_load
*/
-int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
+int boot_get_loadable(int argc, char *const argv[], struct bootm_headers *images,
uint8_t arch, const ulong *ld_start, ulong *const ld_len);
-int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
+int boot_get_setup_fit(struct bootm_headers *images, uint8_t arch,
ulong *setup_start, ulong *setup_len);
/**
@@ -599,9 +599,9 @@ int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
*
* Return: node offset of base image, or -ve error code on error
*/
-int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
- const char **fit_unamep, const char **fit_uname_configp,
- int arch, ulong *datap, ulong *lenp);
+int boot_get_fdt_fit(struct bootm_headers *images, ulong addr,
+ const char **fit_unamep, const char **fit_uname_configp,
+ int arch, ulong *datap, ulong *lenp);
/**
* fit_image_load() - load an image from a FIT
@@ -633,7 +633,7 @@ int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
* @param lenp Returns length of loaded image
* Return: node offset of image, or -ve error code on error
*/
-int fit_image_load(bootm_headers_t *images, ulong addr,
+int fit_image_load(struct bootm_headers *images, ulong addr,
const char **fit_unamep, const char **fit_uname_configp,
int arch, int image_type, int bootstage_id,
enum fit_load_op load_op, ulong *datap, ulong *lenp);
@@ -677,11 +677,11 @@ int image_source_script(ulong addr, const char *fit_uname);
* @param prop_name Property name to look up (FIT_..._PROP)
* @param addr Address of FIT in memory
*/
-int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
- ulong addr);
+int fit_get_node_from_config(struct bootm_headers *images,
+ const char *prop_name, ulong addr);
int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
- bootm_headers_t *images,
+ struct bootm_headers *images,
char **of_flat_tree, ulong *of_size);
void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
@@ -696,11 +696,11 @@ int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd);
/*******************************************************************/
static inline uint32_t image_get_header_size(void)
{
- return (sizeof(image_header_t));
+ return sizeof(struct legacy_img_hdr);
}
#define image_get_hdr_l(f) \
- static inline uint32_t image_get_##f(const image_header_t *hdr) \
+ static inline uint32_t image_get_##f(const struct legacy_img_hdr *hdr) \
{ \
return uimage_to_cpu(hdr->ih_##f); \
}
@@ -713,7 +713,7 @@ image_get_hdr_l(ep) /* image_get_ep */
image_get_hdr_l(dcrc) /* image_get_dcrc */
#define image_get_hdr_b(f) \
- static inline uint8_t image_get_##f(const image_header_t *hdr) \
+ static inline uint8_t image_get_##f(const struct legacy_img_hdr *hdr) \
{ \
return hdr->ih_##f; \
}
@@ -722,12 +722,12 @@ image_get_hdr_b(arch) /* image_get_arch */
image_get_hdr_b(type) /* image_get_type */
image_get_hdr_b(comp) /* image_get_comp */
-static inline char *image_get_name(const image_header_t *hdr)
+static inline char *image_get_name(const struct legacy_img_hdr *hdr)
{
return (char *)hdr->ih_name;
}
-static inline uint32_t image_get_data_size(const image_header_t *hdr)
+static inline uint32_t image_get_data_size(const struct legacy_img_hdr *hdr)
{
return image_get_size(hdr);
}
@@ -743,22 +743,23 @@ static inline uint32_t image_get_data_size(const image_header_t *hdr)
* returns:
* image payload data start address
*/
-static inline ulong image_get_data(const image_header_t *hdr)
+static inline ulong image_get_data(const struct legacy_img_hdr *hdr)
{
return ((ulong)hdr + image_get_header_size());
}
-static inline uint32_t image_get_image_size(const image_header_t *hdr)
+static inline uint32_t image_get_image_size(const struct legacy_img_hdr *hdr)
{
return (image_get_size(hdr) + image_get_header_size());
}
-static inline ulong image_get_image_end(const image_header_t *hdr)
+
+static inline ulong image_get_image_end(const struct legacy_img_hdr *hdr)
{
return ((ulong)hdr + image_get_image_size(hdr));
}
#define image_set_hdr_l(f) \
- static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
+ static inline void image_set_##f(struct legacy_img_hdr *hdr, uint32_t val) \
{ \
hdr->ih_##f = cpu_to_uimage(val); \
}
@@ -771,7 +772,7 @@ image_set_hdr_l(ep) /* image_set_ep */
image_set_hdr_l(dcrc) /* image_set_dcrc */
#define image_set_hdr_b(f) \
- static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
+ static inline void image_set_##f(struct legacy_img_hdr *hdr, uint8_t val) \
{ \
hdr->ih_##f = val; \
}
@@ -780,13 +781,13 @@ image_set_hdr_b(arch) /* image_set_arch */
image_set_hdr_b(type) /* image_set_type */
image_set_hdr_b(comp) /* image_set_comp */
-static inline void image_set_name(image_header_t *hdr, const char *name)
+static inline void image_set_name(struct legacy_img_hdr *hdr, const char *name)
{
strncpy(image_get_name(hdr), name, IH_NMLEN);
}
-int image_check_hcrc(const image_header_t *hdr);
-int image_check_dcrc(const image_header_t *hdr);
+int image_check_hcrc(const struct legacy_img_hdr *hdr);
+int image_check_dcrc(const struct legacy_img_hdr *hdr);
#ifndef USE_HOSTCC
ulong env_get_bootm_low(void);
phys_size_t env_get_bootm_size(void);
@@ -794,15 +795,17 @@ phys_size_t env_get_bootm_mapsize(void);
#endif
void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
-static inline int image_check_magic(const image_header_t *hdr)
+static inline int image_check_magic(const struct legacy_img_hdr *hdr)
{
return (image_get_magic(hdr) == IH_MAGIC);
}
-static inline int image_check_type(const image_header_t *hdr, uint8_t type)
+
+static inline int image_check_type(const struct legacy_img_hdr *hdr, uint8_t type)
{
return (image_get_type(hdr) == type);
}
-static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
+
+static inline int image_check_arch(const struct legacy_img_hdr *hdr, uint8_t arch)
{
/* Let's assume that sandbox can load any architecture */
if (!tools_build() && IS_ENABLED(CONFIG_SANDBOX))
@@ -810,19 +813,20 @@ static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
return (image_get_arch(hdr) == arch) ||
(image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
}
-static inline int image_check_os(const image_header_t *hdr, uint8_t os)
+
+static inline int image_check_os(const struct legacy_img_hdr *hdr, uint8_t os)
{
return (image_get_os(hdr) == os);
}
-ulong image_multi_count(const image_header_t *hdr);
-void image_multi_getimg(const image_header_t *hdr, ulong idx,
+ulong image_multi_count(const struct legacy_img_hdr *hdr);
+void image_multi_getimg(const struct legacy_img_hdr *hdr, ulong idx,
ulong *data, ulong *len);
void image_print_contents(const void *hdr);
#ifndef USE_HOSTCC
-static inline int image_check_target_arch(const image_header_t *hdr)
+static inline int image_check_target_arch(const struct legacy_img_hdr *hdr)
{
#ifndef IH_ARCH_DEFAULT
# error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
@@ -871,7 +875,7 @@ int image_decomp(int comp, ulong load, ulong image_start, int type,
* @lmb: Points to logical memory block structure
* Return: 0 if ok, <0 on failure
*/
-int image_setup_libfdt(bootm_headers_t *images, void *blob,
+int image_setup_libfdt(struct bootm_headers *images, void *blob,
int of_size, struct lmb *lmb);
/**
@@ -883,7 +887,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
* @param images Images information
* Return: 0 if ok, <0 on failure
*/
-int image_setup_linux(bootm_headers_t *images);
+int image_setup_linux(struct bootm_headers *images);
/**
* bootz_setup() - Extract stat and size of a Linux xImage
diff --git a/include/log.h b/include/log.h
index df497bad181..8a7b961bbfb 100644
--- a/include/log.h
+++ b/include/log.h
@@ -322,7 +322,10 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
*
* or:
*
- * return log_msg_ret("fred failed", fred_call());
+ * return log_msg_ret("get", fred_call());
+ *
+ * It is recommended to use <= 3 characters for the name since this will only
+ * use 4 bytes in rodata
*/
#define log_ret(_ret) ({ \
int __ret = (_ret); \
diff --git a/include/malloc.h b/include/malloc.h
index e8c8b254c0d..161ccbd1298 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -883,6 +883,18 @@ extern Void_t* sbrk();
void malloc_simple_info(void);
+/**
+ * malloc_enable_testing() - Put malloc() into test mode
+ *
+ * This only works if UNIT_TESTING is enabled
+ *
+ * @max_allocs: return -ENOMEM after max_allocs calls to malloc()
+ */
+void malloc_enable_testing(int max_allocs);
+
+/** malloc_disable_testing() - Put malloc() into normal mode */
+void malloc_disable_testing(void);
+
#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
#define malloc malloc_simple
#define realloc realloc_simple
diff --git a/include/spl.h b/include/spl.h
index aac6648f946..0fc3686bbca 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -17,7 +17,7 @@
#include <mmc.h>
struct blk_desc;
-struct image_header;
+struct legacy_img_hdr;
/* Value in r0 indicates we booted from U-Boot */
#define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
@@ -29,7 +29,7 @@ struct image_header;
#define MMCSD_MODE_EMMCBOOT 3
struct blk_desc;
-struct image_header;
+struct legacy_img_hdr;
struct spl_boot_device;
/*
@@ -476,7 +476,7 @@ void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
*/
int spl_parse_image_header(struct spl_image_info *spl_image,
const struct spl_boot_device *bootdev,
- const struct image_header *header);
+ const struct legacy_img_hdr *header);
void spl_board_prepare_for_linux(void);
@@ -865,7 +865,7 @@ void spl_perform_fixups(struct spl_image_info *spl_image);
* Returns memory area which can be populated by partial image data,
* ie. uImage or fitImage header.
*/
-struct image_header *spl_get_load_buffer(ssize_t offset, size_t size);
+struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
void spl_save_restore_data(void);
#endif
diff --git a/include/tee/optee.h b/include/tee/optee.h
index 5412bc7386e..77729450bb6 100644
--- a/include/tee/optee.h
+++ b/include/tee/optee.h
@@ -30,7 +30,7 @@ struct optee_header {
};
static inline uint32_t
-optee_image_get_entry_point(const struct image_header *hdr)
+optee_image_get_entry_point(const struct legacy_img_hdr *hdr)
{
struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1);
@@ -38,7 +38,7 @@ optee_image_get_entry_point(const struct image_header *hdr)
}
static inline uint32_t
-optee_image_get_load_addr(const struct image_header *hdr)
+optee_image_get_load_addr(const struct legacy_img_hdr *hdr)
{
return optee_image_get_entry_point(hdr) - sizeof(struct optee_header);
}
diff --git a/include/test/test.h b/include/test/test.h
index 2b68331b546..3bbd77c38b5 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -20,6 +20,12 @@
* @testdev: Test device
* @force_fail_alloc: Force all memory allocs to fail
* @skip_post_probe: Skip uclass post-probe processing
+ * @fdt_chksum: crc8 of the device tree contents
+ * @fdt_copy: Copy of the device tree
+ * @fdt_size: Size of the device-tree copy
+ * @other_fdt: Buffer for the other FDT (UT_TESTF_OTHER_FDT)
+ * @other_fdt_size: Size of the other FDT (UT_TESTF_OTHER_FDT)
+ * @of_other: Live tree for the other FDT
* @runs_per_test: Number of times to run each test (typically 1)
* @expect_str: Temporary string used to hold expected string value
* @actual_str: Temporary string used to hold actual string value
@@ -33,6 +39,12 @@ struct unit_test_state {
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
+ uint fdt_chksum;
+ void *fdt_copy;
+ uint fdt_size;
+ void *other_fdt;
+ int other_fdt_size;
+ struct device_node *of_other;
int runs_per_test;
char expect_str[512];
char actual_str[512];
@@ -48,8 +60,7 @@ enum {
UT_TESTF_CONSOLE_REC = BIT(5), /* needs console recording */
/* do extra driver model init and uninit */
UT_TESTF_DM = BIT(6),
- /* live or flat device tree, but not both in the same executable */
- UT_TESTF_LIVE_OR_FLAT = BIT(4),
+ UT_TESTF_OTHER_FDT = BIT(7), /* read in other device tree */
};
/**
@@ -128,13 +139,24 @@ enum {
*/
struct udevice *testbus_get_clear_removed(void);
-static inline void arch_reset_for_test(void)
-{
#ifdef CONFIG_SANDBOX
#include <asm/state.h>
+#include <asm/test.h>
+#endif
+static inline void arch_reset_for_test(void)
+{
+#ifdef CONFIG_SANDBOX
state_reset_for_test(state_get_current());
#endif
}
+static inline int test_load_other_fdt(struct unit_test_state *uts)
+{
+ int ret = 0;
+#ifdef CONFIG_SANDBOX
+ ret = sandbox_load_other_fdt(&uts->other_fdt, &uts->other_fdt_size);
+#endif
+ return ret;
+}
#endif /* __TEST_TEST_H */
diff --git a/include/test/ut.h b/include/test/ut.h
index f7d1d18f7c1..f7217aa8ac5 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -119,6 +119,11 @@ int ut_check_console_end(struct unit_test_state *uts);
*/
int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
+/* Report a failure, with printf() string */
+#define ut_reportf(fmt, args...) \
+ ut_failf(uts, __FILE__, __LINE__, __func__, "report", \
+ fmt, ##args)
+
/* Assert that a condition is non-zero */
#define ut_assert(cond) \
if (!(cond)) { \