diff mbox series

[v4,5/8] spl: fit: Only look up FIT configuration node once

Message ID 20210120164656.1396639-6-mr.nuke.me@gmail.com
State Accepted
Commit 9e9aa0b473a3217796e7d76a51004af2f42161fd
Delegated to: Tom Rini
Headers show
Series spl: fit: Play nicely with OP-TEE and Linux | expand

Commit Message

Alex G. Jan. 20, 2021, 4:46 p.m. UTC
The configuration node a sub node under "/configurations", which
describes the components to load from "/images". We only need to
locate this node once.

However, for each component, spl_fit_get_image_name() would parse the
FIT image, looking for the correct node. Such work duplication is not
necessary. Instead, once the node is found, cache it, and re-use it.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 common/spl/spl_fit.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Tom Rini Feb. 19, 2021, 4:55 p.m. UTC | #1
On Wed, Jan 20, 2021 at 10:46:53AM -0600, Alexandru Gagniuc wrote:

> The configuration node a sub node under "/configurations", which
> describes the components to load from "/images". We only need to
> locate this node once.
> 
> However, for each component, spl_fit_get_image_name() would parse the
> FIT image, looking for the correct node. Such work duplication is not
> necessary. Instead, once the node is found, cache it, and re-use it.
> 
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index a0bb3f7ad6..a8c54e21d0 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -30,6 +30,7 @@  struct spl_fit_info {
 	const void *fit;	/* Pointer to a valid FIT blob */
 	size_t ext_data_offset;	/* Offset to FIT external data (end of FIT) */
 	int images_node;	/* FDT offset to "/images" node */
+	int conf_node;		/* FDT offset to selected configuration node */
 };
 
 __weak void board_spl_fit_post_load(const void *fit)
@@ -83,15 +84,10 @@  static int spl_fit_get_image_name(const struct spl_fit_info *ctx,
 	struct udevice *sysinfo;
 	const char *name, *str;
 	__maybe_unused int node;
-	int conf_node;
 	int len, i;
 	bool found = true;
 
-	conf_node = fit_find_config_node(ctx->fit);
-	if (conf_node < 0)
-		return conf_node;
-
-	name = fdt_getprop(ctx->fit, conf_node, type, &len);
+	name = fdt_getprop(ctx->fit, ctx->conf_node, type, &len);
 	if (!name) {
 		debug("cannot find property '%s': %d\n", type, len);
 		return -EINVAL;
@@ -550,12 +546,15 @@  static int spl_simple_fit_read(struct spl_fit_info *ctx,
 
 static int spl_simple_fit_parse(struct spl_fit_info *ctx)
 {
-	if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) {
-		int conf_offset = fit_find_config_node(ctx->fit);
+	/* Find the correct subnode under "/configurations" */
+	ctx->conf_node = fit_find_config_node(ctx->fit);
+	if (ctx->conf_node < 0)
+		return -EINVAL;
 
+	if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) {
 		printf("## Checking hash(es) for config %s ... ",
-		       fit_get_name(ctx->fit, conf_offset, NULL));
-		if (fit_config_verify(ctx->fit, conf_offset))
+		       fit_get_name(ctx->fit, ctx->conf_node, NULL));
+		if (fit_config_verify(ctx->fit, ctx->conf_node))
 			return -EPERM;
 		puts("OK\n");
 	}