Skip to contentSkip to conversation

tools: image-host: clean function fit_config_get_hash_list

PATCH New Philippe Reynes 3 participants 6 messages Nov 24, 2020 – Jan 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tools: image-host: clean function fit_config_get_hash_list

This commit creates a function fit_config_add_hash that will be used in the next commit to support several 'sub-images'.

---
 tools/image-host.c | 132 ++++++++++++++++++++++++++-------------------
 1 file changed, 76 insertions(+), 56 deletions(-)
tools/image-host.c +76 -56
index e32cc64257..ce829a8ec9 100644
@@ -700,13 +700,84 @@ static const char *fit_config_get_image_list(void *fit, int noffset,
 	return default_list;
 }
 
+static int fit_config_add_hash(void *fit, const char *conf_name, const char *sig_name,
+			       struct strlist *node_inc, const char *iname, int image_noffset)
+{
+	char name[200], 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;
+
+	snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
+		 conf_name);
+
+	/* Add all this image's hashes */
+	hash_count = 0;
+	for (noffset = fdt_first_subnode(fit, image_noffset);
+	     noffset >= 0;
+	     noffset = fdt_next_subnode(fit, noffset)) {
+		const char *name = fit_get_name(fit, noffset, NULL);
+
+		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;
+		hash_count++;
+	}
+
+	if (!hash_count) {
+		printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
+		       conf_name, sig_name, iname);
+		return -ENOMSG;
+	}
+
+	/* Add this image's cipher node if present */
+	noffset = fdt_subnode_offset(fit, image_noffset,
+				     FIT_CIPHER_NODENAME);
+	if (noffset != -FDT_ERR_NOTFOUND) {
+		if (noffset < 0) {
+			printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n",
+			       conf_name, sig_name, iname,
+			       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;
+	}
+
+	return 0;
+
+err_mem:
+	printf("Out of memory processing configuration '%s/%s'\n", conf_name,
+	       sig_name);
+	return -ENOMEM;
+
+err_path:
+	printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
+	       iname, conf_name, sig_name, fdt_strerror(ret));
+	return -ENOENT;
+}
+
 static int fit_config_get_hash_list(void *fit, int conf_noffset,
 				    int sig_offset, struct strlist *node_inc)
 {
 	int allow_missing;
 	const char *prop, *iname, *end;
 	const char *conf_name, *sig_name;
-	char name[200], path[200];
+	char name[200];
 	int image_count;
 	int ret, len;
 
@@ -733,9 +804,7 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset,
 	end = prop + len;
 	image_count = 0;
 	for (iname = prop; iname < end; iname += strlen(iname) + 1) {
-		int noffset;
 		int image_noffset;
-		int hash_count;
 
 		image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
 						       iname);
@@ -748,55 +817,11 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset,
 			return -ENOENT;
 		}
 
-		ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
+		ret = fit_config_add_hash(fit, conf_name,
+					  sig_name, node_inc,
+					  iname, image_noffset);
 		if (ret < 0)
-			goto err_path;
-		if (strlist_add(node_inc, path))
-			goto err_mem;
-
-		snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
-			 conf_name);
-
-		/* Add all this image's hashes */
-		hash_count = 0;
-		for (noffset = fdt_first_subnode(fit, image_noffset);
-		     noffset >= 0;
-		     noffset = fdt_next_subnode(fit, noffset)) {
-			const char *name = fit_get_name(fit, noffset, NULL);
-
-			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;
-			hash_count++;
-		}
-
-		if (!hash_count) {
-			printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
-			       conf_name, sig_name, iname);
-			return -ENOMSG;
-		}
-
-		/* Add this image's cipher node if present */
-		noffset = fdt_subnode_offset(fit, image_noffset,
-					     FIT_CIPHER_NODENAME);
-		if (noffset != -FDT_ERR_NOTFOUND) {
-			if (noffset < 0) {
-				printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n",
-				       conf_name, sig_name, iname,
-				       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;
-		}
+			return ret;
 
 		image_count++;
 	}
@@ -813,11 +838,6 @@ err_mem:
 	printf("Out of memory processing configuration '%s/%s'\n", conf_name,
 	       sig_name);
 	return -ENOMEM;
-
-err_path:
-	printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
-	       iname, conf_name, sig_name, fdt_strerror(ret));
-	return -ENOENT;
 }
 
 static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 tools: image-host: add support for several sub-images

The propoerty sign-images points to images in the configuration node. But thoses images may references severals "sub-images" (for example for images loadable). This commit adds the support of severals sub-images.

---
 tools/image-host.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
tools/image-host.c +21 -15
index ce829a8ec9..33a224129a 100644
@@ -805,25 +805,31 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset,
 	image_count = 0;
 	for (iname = prop; iname < end; iname += strlen(iname) + 1) {
 		int image_noffset;
+		int index, max_index;
 
-		image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
-						       iname);
-		if (image_noffset < 0) {
-			printf("Failed to find image '%s' in  configuration '%s/%s'\n",
-			       iname, conf_name, sig_name);
-			if (allow_missing)
-				continue;
+		max_index = fdt_stringlist_count(fit, conf_noffset, iname);
 
-			return -ENOENT;
-		}
+		for (index = 0; index < max_index; index++) {
+			image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset,
+								     iname, index);
 
-		ret = fit_config_add_hash(fit, conf_name,
-					  sig_name, node_inc,
-					  iname, image_noffset);
-		if (ret < 0)
-			return ret;
+			if (image_noffset < 0) {
+				printf("Failed to find image '%s' in  configuration '%s/%s'\n",
+				       iname, conf_name, sig_name);
+				if (allow_missing)
+					continue;
 
-		image_count++;
+				return -ENOENT;
+			}
+
+			ret = fit_config_add_hash(fit, conf_name,
+						  sig_name, node_inc,
+						  iname, image_noffset);
+			if (ret < 0)
+				return ret;
+
+			image_count++;
+		}
 	}
 
 	if (!image_count) {
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 tools: image-host: add support for several sub-images

Hi Philippe,

Quoted 2 lines · Philippe Reynes

The propoerty sign-images points to images in the configuration

spelling

Quoted 1 line

node. But thoses images may references severals "sub-images" (for

reference several

Quoted 2 lines

example for images loadable). This commit adds the support of severals sub-images.

several

Quoted 5 lines
---
 tools/image-host.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

The code looks OK but is missing docs.

Quoted 53 lines
tools/image-host.c +21 -16
index ce829a8ec9..33a224129a 100644
@@ -805,25 +805,31 @@ static int fit_config_get_hash_list(void *fit, int conf_noffset,
        image_count = 0;
        for (iname = prop; iname < end; iname += strlen(iname) + 1) {
                int image_noffset;
+               int index, max_index;
 
-               image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
-                                                      iname);
-               if (image_noffset < 0) {
-                       printf("Failed to find image '%s' in  configuration '%s/%s'\n",
-                              iname, conf_name, sig_name);
-                       if (allow_missing)
-                               continue;
+               max_index = fdt_stringlist_count(fit, conf_noffset, iname);
 
-                       return -ENOENT;
-               }
+               for (index = 0; index < max_index; index++) {
+                       image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset,
+                                                                    iname, index);
 
-               ret = fit_config_add_hash(fit, conf_name,
-                                         sig_name, node_inc,
-                                         iname, image_noffset);
-               if (ret < 0)
-                       return ret;
+                       if (image_noffset < 0) {
+                               printf("Failed to find image '%s' in  configuration '%s/%s'\n",
+                                      iname, conf_name, sig_name);
+                               if (allow_missing)
+                                       continue;
 
-               image_count++;
+                               return -ENOENT;
+                       }
+
+                       ret = fit_config_add_hash(fit, conf_name,
+                                                 sig_name, node_inc,
+                                                 iname, image_noffset);
+                       if (ret < 0)
+                               return ret;
+
+                       image_count++;
+               }
        }
 
        if (!image_count) {
--
Quoted 2 lines

2.17.1

Regards,
Simon

#3 lore raw

PATCH 2/2 tools: image-host: add support for several sub-images

In reply to Philippe Reynes
Quoted 6 lines · Philippe Reynes

The propoerty sign-images points to images in the configuration node. But thoses images may references severals "sub-images" (for example for images loadable). This commit adds the support of severals sub-images.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210123/bdc28b35/attachment.sig>
#4 lore raw

PATCH 1/2 tools: image-host: clean function fit_config_get_hash_list

In reply to Philippe Reynes

Hi Philippe,

Quoted 9 lines · Philippe Reynes

This commit creates a function fit_config_add_hash that will be used in the next commit to support several 'sub-images'.

---
 tools/image-host.c | 132 ++++++++++++++++++++++++++-------------------
 1 file changed, 76 insertions(+), 56 deletions(-)

I'm not quite clear what you are doing in this series or why. Can you add some documentation updates please?

#5 lore raw

PATCH 1/2 tools: image-host: clean function fit_config_get_hash_list

In reply to Philippe Reynes
Quoted 5 lines · Philippe Reynes

This commit creates a function fit_config_add_hash that will be used in the next commit to support several 'sub-images'.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210123/d0983825/attachment.sig>