summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Golle <[email protected]>2026-07-28 23:09:38 +0100
committerTom Rini <[email protected]>2026-08-10 12:32:41 -0600
commitba9ce23d21e3536b7de5e5722f20b8d6be695d3c (patch)
tree276a50a45043ec6caadfc73b33ea4e2d82b1c330
parentb635d43bca429500cb8ef20aa151cb5773b9a8a5 (diff)
boot: fit: factor out node-path collection in fit_config_add_hash()
Both the boot-side and host-side fit_config_add_hash() repeat the same sequence to append a node's path to the hashed-node list three times: for the image node, for each hash subnode and for the cipher subnode. Extract it into a helper, fit_config_add_node(), in each file, with no functional change. Signed-off-by: Daniel Golle <[email protected]> Reviewed-by: Tom Rini <[email protected]> Reviewed-by: Simon Glass <[email protected]>
-rw-r--r--boot/image-fit-sig.c73
-rw-r--r--tools/image-host.c73
2 files changed, 91 insertions, 55 deletions
diff --git a/boot/image-fit-sig.c b/boot/image-fit-sig.c
index fe7ca6e4ab5..3357ec92116 100644
--- a/boot/image-fit-sig.c
+++ b/boot/image-fit-sig.c
@@ -231,6 +231,37 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
}
/**
+ * fit_config_add_node() - Append one node's path to the hashed-node list
+ *
+ * @fit: FIT blob
+ * @noffset: Offset of the node whose path should be added
+ * @node_inc: Array of path pointers to fill
+ * @count: Pointer to current count (updated on return)
+ * @max_nodes: Maximum entries in @node_inc
+ * @buf: Buffer for packed path strings
+ * @buf_used: Pointer to bytes used in @buf (updated on return)
+ * @buf_len: Total size of @buf
+ * Return: 0 on success, -ve on error
+ */
+static int fit_config_add_node(const void *fit, int noffset, char **node_inc,
+ int *count, int max_nodes, char *buf,
+ int *buf_used, int buf_len)
+{
+ int ret, len;
+
+ if (*count >= max_nodes)
+ return -ENOSPC;
+ ret = fdt_get_path(fit, noffset, buf + *buf_used, buf_len - *buf_used);
+ if (ret < 0)
+ return -ENOENT;
+ len = strlen(buf + *buf_used) + 1;
+ node_inc[(*count)++] = buf + *buf_used;
+ *buf_used += len;
+
+ return 0;
+}
+
+/**
* fit_config_add_hash() - Add hash nodes for one image to the node list
*
* Adds the image path, all its hash-* subnode paths, and its cipher
@@ -250,18 +281,12 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
char **node_inc, int *count, int max_nodes,
char *buf, int *buf_used, int buf_len)
{
- int noffset, hash_count, ret, len;
+ int noffset, hash_count, ret;
- if (*count >= max_nodes)
- return -ENOSPC;
-
- ret = fdt_get_path(fit, image_noffset, buf + *buf_used,
- buf_len - *buf_used);
- if (ret < 0)
- return -ENOENT;
- len = strlen(buf + *buf_used) + 1;
- node_inc[(*count)++] = buf + *buf_used;
- *buf_used += len;
+ ret = fit_config_add_node(fit, image_noffset, node_inc, count,
+ max_nodes, buf, buf_used, buf_len);
+ if (ret)
+ return ret;
/* Add all this image's hash subnodes */
hash_count = 0;
@@ -273,15 +298,10 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
if (strncmp(name, FIT_HASH_NODENAME,
strlen(FIT_HASH_NODENAME)))
continue;
- if (*count >= max_nodes)
- return -ENOSPC;
- ret = fdt_get_path(fit, noffset, buf + *buf_used,
- buf_len - *buf_used);
- if (ret < 0)
- return -ENOENT;
- len = strlen(buf + *buf_used) + 1;
- node_inc[(*count)++] = buf + *buf_used;
- *buf_used += len;
+ ret = fit_config_add_node(fit, noffset, node_inc, count,
+ max_nodes, buf, buf_used, buf_len);
+ if (ret)
+ return ret;
hash_count++;
}
@@ -296,15 +316,10 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
if (noffset != -FDT_ERR_NOTFOUND) {
if (noffset < 0)
return -EIO;
- if (*count >= max_nodes)
- return -ENOSPC;
- ret = fdt_get_path(fit, noffset, buf + *buf_used,
- buf_len - *buf_used);
- if (ret < 0)
- return -ENOENT;
- len = strlen(buf + *buf_used) + 1;
- node_inc[(*count)++] = buf + *buf_used;
- *buf_used += len;
+ ret = fit_config_add_node(fit, noffset, node_inc, count,
+ max_nodes, buf, buf_used, buf_len);
+ if (ret)
+ return ret;
}
return 0;
diff --git a/tools/image-host.c b/tools/image-host.c
index 8f1e7be4066..fd2ef99d399 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -1184,6 +1184,41 @@ static const char *fit_config_get_image_list(const void *fit, int noffset,
}
/**
+ * fit_config_add_node() - Add a node's path to a list of nodes to hash
+ *
+ * @fit: Pointer to the FIT format image header
+ * @noffset: Offset of the node whose path should be added
+ * @node_inc: List of nodes to add to
+ * @conf_name Configuration-node name, child of /configurations node (only
+ * used for error messages)
+ * @sig_name Signature-node name (only used for error messages)
+ * @iname: Name of image being processed (e.g. "kernel-1" (only used
+ * for error messages)
+ */
+static int fit_config_add_node(const void *fit, int noffset,
+ struct strlist *node_inc, const char *conf_name,
+ const char *sig_name, const char *iname)
+{
+ char path[200];
+ int ret;
+
+ ret = fdt_get_path(fit, noffset, path, sizeof(path));
+ if (ret < 0) {
+ fprintf(stderr,
+ "Failed to get path for image '%s' in configuration '%s/%s': %s\n",
+ iname, conf_name, sig_name, fdt_strerror(ret));
+ return -ENOENT;
+ }
+ if (strlist_add(node_inc, path)) {
+ fprintf(stderr, "Out of memory processing configuration '%s/%s'\n",
+ conf_name, sig_name);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+/**
* fit_config_add_hash() - Add a list of nodes to hash for an image
*
* This adds a list of paths to image nodes (as referred to by a particular
@@ -1202,16 +1237,14 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
struct strlist *node_inc, const char *conf_name,
const char *sig_name, const char *iname)
{
- char path[200];
int noffset;
int hash_count;
int ret;
- ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
- if (ret < 0)
- goto err_path;
- if (strlist_add(node_inc, path))
- goto err_mem;
+ ret = fit_config_add_node(fit, image_noffset, node_inc, conf_name,
+ sig_name, iname);
+ if (ret)
+ return ret;
/* Add all this image's hashes */
hash_count = 0;
@@ -1223,11 +1256,10 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
if (strncmp(name, FIT_HASH_NODENAME,
strlen(FIT_HASH_NODENAME)))
continue;
- ret = fdt_get_path(fit, noffset, path, sizeof(path));
- if (ret < 0)
- goto err_path;
- if (strlist_add(node_inc, path))
- goto err_mem;
+ ret = fit_config_add_node(fit, noffset, node_inc, conf_name,
+ sig_name, iname);
+ if (ret)
+ return ret;
hash_count++;
}
@@ -1249,24 +1281,13 @@ static int fit_config_add_hash(const void *fit, int image_noffset,
fdt_strerror(noffset));
return -EIO;
}
- ret = fdt_get_path(fit, noffset, path, sizeof(path));
- if (ret < 0)
- goto err_path;
- if (strlist_add(node_inc, path))
- goto err_mem;
+ ret = fit_config_add_node(fit, noffset, node_inc, conf_name,
+ sig_name, iname);
+ if (ret)
+ return ret;
}
return 0;
-
-err_mem:
- fprintf(stderr, "Out of memory processing configuration '%s/%s'\n", conf_name,
- sig_name);
- return -ENOMEM;
-
-err_path:
- fprintf(stderr, "Failed to get path for image '%s' in configuration '%s/%s': %s\n",
- iname, conf_name, sig_name, fdt_strerror(ret));
- return -ENOENT;
}
/**