Skip to contentSkip to conversation

image-fit: don't set compression if it can't be read

PATCH Superseded Daniel Golle 3 participants 16 messages Aug 15, 2022 – Aug 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 image-fit: don't set compression if it can't be read

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
 boot/bootm.c     | 6 ++----
 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
boot/bootm.c +2 -4
index 86dbfbcfed..b659825305 100644
@@ -1024,10 +1024,8 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 		return -EINVAL;
 	}
 
-	if (fit_image_get_comp(fit, noffset, &imape_comp)) {
-		puts("Can't get image compression!\n");
-		return -EINVAL;
-	}
+	if (fit_image_get_comp(fit, noffset, &imape_comp))
+		image_comp = IH_COMP_NONE;
 
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
boot/image-fit.c +1 -2
index df3e5df883..21dbd05118 100644
@@ -477,7 +477,7 @@ void fit_print_contents(const void *fit)
 void fit_image_print(const void *fit, int image_noffset, const char *p)
 {
 	char *desc;
-	uint8_t type, arch, os, comp;
+	uint8_t type, arch, os, comp = IH_COMP_NONE;
 	size_t size;
 	ulong load, entry;
 	const void *data;
@@ -794,7 +794,6 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
 	data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
 	if (data == NULL) {
 		fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
-		*comp = -1;
 		return -1;
 	}
 
cmd/ximg.c +2 -5
index 65ba41320a..f84141ff45 100644
@@ -171,11 +171,8 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			return 1;
 		}
 
-		if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-			puts("Could not find script subimage "
-				"compression type\n");
-			return 1;
-		}
+		if (fit_image_get_comp(fit_hdr, noffset, &comp))
+			comp = IH_COMP_NONE;
 
 		data = (ulong)fit_data;
 		len = (ulong)fit_len;
Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Daniel Golle

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

Quoted 6 lines
---
 boot/bootm.c     | 6 ++----
 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
#2 lore raw
In reply to Daniel Golle
Quoted 11 lines · Daniel Golle

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

This causes most platforms to fail to build with an error such as:
https://source.denx.de/u-boot/u-boot/-/jobs/486959#L140

Signature · 1 line
Tom
#3 lore raw

PATCH v2 1/1 image-fit: don't set compression if it can't be read

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
v2: fix typo 'imape_comp' vs. 'image_comp'

 boot/bootm.c     | 6 ++----
 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
boot/bootm.c +2 -4
index 86dbfbcfed..fcdf23f19c 100644
@@ -1024,10 +1024,8 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 		return -EINVAL;
 	}
 
-	if (fit_image_get_comp(fit, noffset, &imape_comp)) {
-		puts("Can't get image compression!\n");
-		return -EINVAL;
-	}
+	if (fit_image_get_comp(fit, noffset, &imape_comp))
+		imape_comp = IH_COMP_NONE;
 
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
boot/image-fit.c +1 -2
index df3e5df883..21dbd05118 100644
@@ -477,7 +477,7 @@ void fit_print_contents(const void *fit)
 void fit_image_print(const void *fit, int image_noffset, const char *p)
 {
 	char *desc;
-	uint8_t type, arch, os, comp;
+	uint8_t type, arch, os, comp = IH_COMP_NONE;
 	size_t size;
 	ulong load, entry;
 	const void *data;
@@ -794,7 +794,6 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
 	data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
 	if (data == NULL) {
 		fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
-		*comp = -1;
 		return -1;
 	}
 
cmd/ximg.c +2 -5
index 65ba41320a..f84141ff45 100644
@@ -171,11 +171,8 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			return 1;
 		}
 
-		if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-			puts("Could not find script subimage "
-				"compression type\n");
-			return 1;
-		}
+		if (fit_image_get_comp(fit_hdr, noffset, &comp))
+			comp = IH_COMP_NONE;
 
 		data = (ulong)fit_data;
 		len = (ulong)fit_len;
Signature · 1 line
2.37.2
#4 lore raw

Hi Daniel,

Quoted 75 lines · Daniel Golle

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
v2: fix typo 'imape_comp' vs. 'image_comp'

 boot/bootm.c     | 6 ++----
 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
boot/bootm.c +2 -4
index 86dbfbcfed..fcdf23f19c 100644
@@ -1024,10 +1024,8 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
                return -EINVAL;
        }
 
-       if (fit_image_get_comp(fit, noffset, &imape_comp)) {
-               puts("Can't get image compression!\n");
-               return -EINVAL;
-       }
+       if (fit_image_get_comp(fit, noffset, &imape_comp))
+               imape_comp = IH_COMP_NONE;
 
        /* Allow the image to expand by a factor of 4, should be safe */
        buf_size = (1 << 20) + len * 4;
boot/image-fit.c +1 -2
index df3e5df883..21dbd05118 100644
@@ -477,7 +477,7 @@ void fit_print_contents(const void *fit)
 void fit_image_print(const void *fit, int image_noffset, const char *p)
 {
        char *desc;
-       uint8_t type, arch, os, comp;
+       uint8_t type, arch, os, comp = IH_COMP_NONE;
        size_t size;
        ulong load, entry;
        const void *data;
@@ -794,7 +794,6 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
        data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
        if (data == NULL) {
                fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
-               *comp = -1;
                return -1;
        }
 
cmd/ximg.c +2 -6
index 65ba41320a..f84141ff45 100644
@@ -171,11 +171,8 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
                        return 1;
                }
 
-               if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-                       puts("Could not find script subimage "
-                               "compression type\n");
-                       return 1;
-               }
+               if (fit_image_get_comp(fit_hdr, noffset, &comp))
+                       comp = IH_COMP_NONE;
 
                data = (ulong)fit_data;
                len = (ulong)fit_len;
--
Quoted 2 lines

2.37.2

Well it should be imape_comp, so could you fix that error first (in a patch before this one)?

Regards,
SImon

#5 lore raw

PATCH v3 1/2 bootm: fix typo imape_comp -> image_comp

Chage variable name 'imape_comp' to the supposedly intended name 'image_comp'.

---
 boot/bootm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
boot/bootm.c +3 -3
index 86dbfbcfed..4de573e24e 100644
@@ -1006,7 +1006,7 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 	int noffset;
 	ulong load_end, buf_size;
 	uint8_t image_type;
-	uint8_t imape_comp;
+	uint8_t image_comp;
 	void *load_buf;
 	int ret;
 
@@ -1032,12 +1032,12 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
 	load_buf = malloc(buf_size);
-	ret = image_decomp(imape_comp, 0, data, image_type, load_buf,
+	ret = image_decomp(image_comp, 0, data, image_type, load_buf,
 			   (void *)data, len, buf_size, &load_end);
 	free(load_buf);
 
 	if (ret) {
-		ret = handle_decomp_error(imape_comp, load_end - 0, buf_size, ret);
+		ret = handle_decomp_error(image_comp, load_end - 0, buf_size, ret);
 		if (ret != BOOTM_ERR_UNIMPLEMENTED)
 			return ret;
 	}
Signature · 1 line
2.37.2
#6 lore raw

PATCH v3 2/2 image-fit: don't set compression if it can't be read

In reply to Simon Glass

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
 boot/bootm.c     | 6 ++----
 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
boot/bootm.c +2 -4
index 4de573e24e..29c067fae7 100644
@@ -1024,10 +1024,8 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 		return -EINVAL;
 	}
 
-	if (fit_image_get_comp(fit, noffset, &imape_comp)) {
-		puts("Can't get image compression!\n");
-		return -EINVAL;
-	}
+	if (fit_image_get_comp(fit, noffset, &image_comp))
+		image_comp = IH_COMP_NONE;
 
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
boot/image-fit.c +1 -2
index df3e5df883..21dbd05118 100644
@@ -477,7 +477,7 @@ void fit_print_contents(const void *fit)
 void fit_image_print(const void *fit, int image_noffset, const char *p)
 {
 	char *desc;
-	uint8_t type, arch, os, comp;
+	uint8_t type, arch, os, comp = IH_COMP_NONE;
 	size_t size;
 	ulong load, entry;
 	const void *data;
@@ -794,7 +794,6 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
 	data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
 	if (data == NULL) {
 		fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
-		*comp = -1;
 		return -1;
 	}
 
cmd/ximg.c +2 -5
index 65ba41320a..f84141ff45 100644
@@ -171,11 +171,8 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			return 1;
 		}
 
-		if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-			puts("Could not find script subimage "
-				"compression type\n");
-			return 1;
-		}
+		if (fit_image_get_comp(fit_hdr, noffset, &comp))
+			comp = IH_COMP_NONE;
 
 		data = (ulong)fit_data;
 		len = (ulong)fit_len;
Signature · 1 line
2.37.2
#7 lore raw

PATCH v4 1/2 bootm: fix typo imape_comp -> image_comp

In reply to Simon Glass

Chage variable name 'imape_comp' to the supposedly intended name 'image_comp'.

---
v4: add missing name replacement

boot/bootm.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
boot/bootm.c +4 -4
index 86dbfbcfed..63c79a9cfc 100644
@@ -1006,7 +1006,7 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 	int noffset;
 	ulong load_end, buf_size;
 	uint8_t image_type;
-	uint8_t imape_comp;
+	uint8_t image_comp;
 	void *load_buf;
 	int ret;
 
@@ -1024,7 +1024,7 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 		return -EINVAL;
 	}
 
-	if (fit_image_get_comp(fit, noffset, &imape_comp)) {
+	if (fit_image_get_comp(fit, noffset, &image_comp)) {
 		puts("Can't get image compression!\n");
 		return -EINVAL;
 	}
@@ -1032,12 +1032,12 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
 	load_buf = malloc(buf_size);
-	ret = image_decomp(imape_comp, 0, data, image_type, load_buf,
+	ret = image_decomp(image_comp, 0, data, image_type, load_buf,
 			   (void *)data, len, buf_size, &load_end);
 	free(load_buf);
 
 	if (ret) {
-		ret = handle_decomp_error(imape_comp, load_end - 0, buf_size, ret);
+		ret = handle_decomp_error(image_comp, load_end - 0, buf_size, ret);
 		if (ret != BOOTM_ERR_UNIMPLEMENTED)
 			return ret;
 	}
Signature · 1 line
2.37.2
Reviewed-by on v4 1/2
#8 lore raw

Re: [PATCH v4 1/2] bootm: fix typo imape_comp -> image_comp

Quoted 2 lines · Daniel Golle

Chage variable name 'imape_comp' to the supposedly intended name

Change

Quoted 9 lines

'image_comp'.

---
v4: add missing name replacement

boot/bootm.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
#9 lore raw

Re: [PATCH v4 1/2] bootm: fix typo imape_comp -> image_comp

Quoted 5 lines · Simon Glass
Quoted 2 lines · Daniel Golle

Chage variable name 'imape_comp' to the supposedly intended name

Change

Can you fix that on-the-fly while comitting or should I repost with that typo in the patch description fixed?

Quoted 12 lines
Quoted 10 lines

'image_comp'.

---
v4: add missing name replacement

boot/bootm.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
#10 lore raw

Re: [PATCH v4 1/2] bootm: fix typo imape_comp -> image_comp

Hi Daniel,

Quoted 10 lines · Daniel Golle
Quoted 5 lines · Simon Glass
Quoted 2 lines · Daniel Golle

Chage variable name 'imape_comp' to the supposedly intended name

Change

Can you fix that on-the-fly while comitting or should I repost with that typo in the patch description fixed?

Yes I suspect Tom can do that.

Regards,
Simon

Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

'image_comp'.

---
v4: add missing name replacement

boot/bootm.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
#11 lore raw

Re: [PATCH v4 1/2] bootm: fix typo imape_comp -> image_comp

Quoted 7 lines · Simon Glass

Hi Daniel,

Quoted 4 lines · Daniel Golle
Quoted 2 lines · Simon Glass
Quoted 1 line · Daniel Golle
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Chage variable name 'imape_comp' to the supposedly intended name

Change

Can you fix that on-the-fly while comitting or should I repost with that typo in the patch description fixed?

Yes I suspect Tom can do that.

Yes, that's fine.

Signature · 1 line
Tom
#13 lore raw

PATCH v4 2/2 image-fit: don't set compression if it can't be read

In reply to Simon Glass

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
v2: fix typo 'imape_comp' vs. 'image_comp'
v3: rather fix the typo everywhere in an additional patch before
v4: rebase on updated patch fixing typo

boot/bootm.c | 6 ++----

 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
boot/bootm.c +2 -4
index 63c79a9cfc..29c067fae7 100644
@@ -1024,10 +1024,8 @@ static int bootm_host_load_image(const void *fit, int req_image_type,
 		return -EINVAL;
 	}
 
-	if (fit_image_get_comp(fit, noffset, &image_comp)) {
-		puts("Can't get image compression!\n");
-		return -EINVAL;
-	}
+	if (fit_image_get_comp(fit, noffset, &image_comp))
+		image_comp = IH_COMP_NONE;
 
 	/* Allow the image to expand by a factor of 4, should be safe */
 	buf_size = (1 << 20) + len * 4;
boot/image-fit.c +1 -2
index df3e5df883..21dbd05118 100644
@@ -477,7 +477,7 @@ void fit_print_contents(const void *fit)
 void fit_image_print(const void *fit, int image_noffset, const char *p)
 {
 	char *desc;
-	uint8_t type, arch, os, comp;
+	uint8_t type, arch, os, comp = IH_COMP_NONE;
 	size_t size;
 	ulong load, entry;
 	const void *data;
@@ -794,7 +794,6 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
 	data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
 	if (data == NULL) {
 		fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
-		*comp = -1;
 		return -1;
 	}
 
cmd/ximg.c +2 -5
index 65ba41320a..f84141ff45 100644
@@ -171,11 +171,8 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			return 1;
 		}
 
-		if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
-			puts("Could not find script subimage "
-				"compression type\n");
-			return 1;
-		}
+		if (fit_image_get_comp(fit_hdr, noffset, &comp))
+			comp = IH_COMP_NONE;
 
 		data = (ulong)fit_data;
 		len = (ulong)fit_len;
Signature · 1 line
2.37.2
Reviewed-by on v4 2/2
#14 lore raw
Quoted 16 lines · Daniel Golle

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

---
v2: fix typo 'imape_comp' vs. 'image_comp'
v3: rather fix the typo everywhere in an additional patch before
v4: rebase on updated patch fixing typo

Quoted 4 lines

boot/bootm.c | 6 ++----

 boot/image-fit.c | 3 +--
 cmd/ximg.c       | 7 ++-----
 3 files changed, 5 insertions(+), 11 deletions(-)
#15 lore raw
In reply to Daniel Golle
Quoted 11 lines · Daniel Golle

fit_image_get_comp() should not set value -1 in case it can't read the compression node. Instead, leave the value untouched in that case as it can be absent and a default value previously defined by the caller of fit_image_get_comp() should be used.

As a result the warning message
WARNING: 'compression' nodes for ramdisks are deprecated, please fix your .its file! no longer shows if the compression node is actually absent.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom