Skip to contentSkip to conversation

imxtract: add support for zstd-compressed images

PATCH In review Dmitry Gerasimov 2 participants 2 messages Jun 2, 2024 – Jun 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 imxtract: add support for zstd-compressed images

Allow extraction of zstd-compressed images from FIT using imxtract command. This is especially useful when one has to load an image via some interface (e.g. SPI) rather that just to the memory.

---

 cmd/ximg.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
cmd/ximg.c +23 -0
index 0e7eead8d1..25a15fa184 100644
@@ -16,6 +16,9 @@
 #include <cpu_func.h>
 #include <env.h>
 #include <gzip.h>
+#if IS_ENABLED(CONFIG_ZSTD)
+#include <linux/zstd.h>
+#endif
 #include <image.h>
 #include <malloc.h>
 #include <mapmem.h>
@@ -238,6 +241,26 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			}
 			break;
 #endif /* CONFIG_BZIP2 */
+#if IS_ENABLED(CONFIG_ZSTD)
+		case IH_COMP_ZSTD:
+			{
+				int ret;
+				struct abuf in, out;
+
+				printf("   Uncompressing part %d ... ", part);
+
+				abuf_init_set(&in, (void *)data, len);
+				abuf_init_set(&out, (void *)dest, unc_len);
+				ret = zstd_decompress(&in, &out);
+				if (ret < 0) {
+					printf("ZSTD ERROR %d - "
+					       "image not loaded\n", ret);
+					return 1;
+				}
+				len = ret;
+			}
+			break;
+#endif
 		default:
 			printf("Unimplemented compression type %d\n", comp);
 			return 1;
Signature · 1 line
2.45.1
#1 lore raw
Quoted 5 lines · Dmitry Gerasimov

Allow extraction of zstd-compressed images from FIT using imxtract command. This is especially useful when one has to load an image via some interface (e.g. SPI) rather that just to the memory.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom