Skip to contentSkip to conversation

tools: imagetool: Fix error message when verify_header is undefined

PATCH In review Pali Rohár 3 participants 11 messages Jan 29, 2023 – Feb 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 tools: imagetool: Fix error message when verify_header is undefined

---
 tools/imagetool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/imagetool.c +1 -1
index f14ca2fb979f..688169b3a813 100644
@@ -105,7 +105,7 @@ static int imagetool_verify_print_header_by_type(
 		}
 
 	} else {
-		fprintf(stderr, "%s: print_header undefined for %s\n",
+		fprintf(stderr, "%s: verify_header undefined for %s\n",
 			params->cmdname, tparams->name);
 	}
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/3 tools: imagetool: Show error message when detecting image type failed

---
 tools/imagetool.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/imagetool.c +5 -0
index 688169b3a813..e1021f44f5ad 100644
@@ -71,6 +71,11 @@ int imagetool_verify_print_header(
 		}
 	}
 
+	if (retval != 0) {
+		fprintf(stderr, "%s: cannot detect image type\n",
+			params->cmdname);
+	}
+
 	return retval;
 }
 
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH u-boot 2/3] tools: imagetool: Show error message when detecting image type failed

Quoted 1 line · Pali Rohár

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH 3/3 tools: imagetool: Skip autodetection of gpimage type

In reply to Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

---
 tools/imagetool.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/imagetool.c +6 -0
index e1021f44f5ad..87eee4ad04ed 100644
@@ -49,6 +49,12 @@ int imagetool_verify_print_header(
 		return imagetool_verify_print_header_by_type(ptr, sbuf, tparams, params);
 
 	for (curr = start; curr != end; curr++) {
+		/*
+		 * Basically every data file can be guessed / verified as gpimage,
+		 * so skip autodetection of data file as gpimage as it does not work.
+		 */
+		if ((*curr)->check_image_type && (*curr)->check_image_type(IH_TYPE_GPIMAGE) == 0)
+			continue;
 		if ((*curr)->verify_header) {
 			retval = (*curr)->verify_header((unsigned char *)ptr,
 						     sbuf->st_size, params);
Signature · 1 line
2.20.1
Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH u-boot 3/3] tools: imagetool: Skip autodetection of gpimage type

Quoted 7 lines · Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

Quoted 5 lines
---
 tools/imagetool.c | 6 ++++++
 1 file changed, 6 insertions(+)
#5 lore raw

Re: [PATCH u-boot 3/3] tools: imagetool: Skip autodetection of gpimage type

Quoted 8 lines · Simon Glass
Quoted 7 lines · Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

Quoted 7 lines
Quoted 5 lines
---
 tools/imagetool.c | 6 ++++++
 1 file changed, 6 insertions(+)

I see we've had problems with gpimage before too. This seems reasonable but I'm adding Nishanth here too, as the current interested person in keystone2 platforms, to see if there's any other / better ways to address this problem.

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH u-boot 3/3] tools: imagetool: Skip autodetection of gpimage type

Quoted 15 lines · On Monday 30 January 2023 13:02:42 Tom Rini wrote:
Quoted 14 lines · Simon Glass
Quoted 12 lines · Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

---
 tools/imagetool.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 9 lines
Quoted 1 line

I see we've had problems with gpimage before too. This seems reasonable but I'm adding Nishanth here too, as the current interested person in keystone2 platforms, to see if there's any other / better ways to address this problem.

Signature · 1 line
Tom

I do not think that there is a better solution for gpimage. Basically it is not possible to write autodetection code for gpimage due to its generic nature. So the best what we can do is to disable gpimage in autodetection code.

I would suggest to apply this patch, so people can test their build setups sooner than later.

#7 lore raw

Re: [PATCH u-boot 3/3] tools: imagetool: Skip autodetection of gpimage type

Quoted 23 lines · Pali Rohár
Quoted 15 lines · On Monday 30 January 2023 13:02:42 Tom Rini wrote:
Quoted 14 lines · Simon Glass
Quoted 12 lines · Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

---
 tools/imagetool.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 6 lines
Quoted 1 line

I see we've had problems with gpimage before too. This seems reasonable but I'm adding Nishanth here too, as the current interested person in keystone2 platforms, to see if there's any other / better ways to address this problem.

Quoted 7 lines

I do not think that there is a better solution for gpimage. Basically it is not possible to write autodetection code for gpimage due to its generic nature. So the best what we can do is to disable gpimage in autodetection code.

I would suggest to apply this patch, so people can test their build setups sooner than later.

Yes, I will pick this up before -rc2. I was wondering / hoping Nishanth might have access to further internal information that might be helpful here.

Signature · 1 line
Tom
#8 lore raw

Re: [PATCH u-boot 3/3] tools: imagetool: Skip autodetection of gpimage type

In reply to Pali Rohár
Quoted 8 lines · Pali Rohár

gpimage type requires only that two first 32-bit words of data file are non-zero. So basically every random data file can be guessed and verified as gpimage. So completely skip gpimage type from image autodetection code to prevent lot of false positive results. Data file with gpimage type can be still verified and parsed by explicitly specifying -T gpimage.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#9 lore raw
In reply to Pali Rohár

On Sun, 29 Jan 2023 at 09:46, Pali Rohár <[email protected]> wrote:

commit message? Also it is good to keep subjects to under 60 chars

Quoted 22 lines
---
 tools/imagetool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/imagetool.c +1 -2
index f14ca2fb979f..688169b3a813 100644
@@ -105,7 +105,7 @@ static int imagetool_verify_print_header_by_type(
                }
 
        } else {
-               fprintf(stderr, "%s: print_header undefined for %s\n",
+               fprintf(stderr, "%s: verify_header undefined for %s\n",
                        params->cmdname, tparams->name);
        }
 
--

2.20.1