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

2021-01-23 Thread Tom Rini
On Tue, Nov 24, 2020 at 02:39:47PM +0100, Philippe Reynes wrote:

> This commit creates a function fit_config_add_hash that will be
> used in the next commit to support several 'sub-images'.
> 
> Signed-off-by: Philippe Reynes 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


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

2020-11-30 Thread Simon Glass
Hi Philippe,

On Tue, 24 Nov 2020 at 06:40, Philippe Reynes
 wrote:
>
> This commit creates a function fit_config_add_hash that will be
> used in the next commit to support several 'sub-images'.
>
> Signed-off-by: Philippe Reynes 
> ---
>  tools/image-host.c | 132 ++---
>  1 file changed, 76 insertions(+), 56 deletions(-)
>

Reviewed-by: Simon Glass 

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


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

2020-11-24 Thread Philippe Reynes
This commit creates a function fit_config_add_hash that will be
used in the next commit to support several 'sub-images'.

Signed-off-by: Philippe Reynes 
---
 tools/image-host.c | 132 ++---
 1 file changed, 76 insertions(+), 56 deletions(-)

diff --git a/tools/image-host.c b/tools/image-host.c
index e32cc64257..ce829a8ec9 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -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,