From: Robert Marko <robert.marko@sartura.hr>
To: u-boot@lists.denx.de
Subject: [PATCH] image: Add support for ZSTD decompression
Date: Sat, 25 Apr 2020 19:37:21 +0200 [thread overview]
Message-ID: <20200425173721.2759955-1-robert.marko@sartura.hr> (raw)
This patch adds support for ZSTD decompression of FIT images.
Signed-off-by: Robert Marko <robert.marko@sartura.hr>
Cc: Luka Perkov <luka.perkov@sartura.hr>
---
common/image.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
include/image.h | 1 +
2 files changed, 53 insertions(+)
diff --git a/common/image.c b/common/image.c
index 94873cb6ed..70ba0f4328 100644
--- a/common/image.c
+++ b/common/image.c
@@ -42,6 +42,7 @@
#include <lzma/LzmaTypes.h>
#include <lzma/LzmaDec.h>
#include <lzma/LzmaTools.h>
+#include <linux/zstd.h>
#ifdef CONFIG_CMD_BDI
extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
@@ -193,6 +194,7 @@ static const table_entry_t uimage_comp[] = {
{ IH_COMP_LZMA, "lzma", "lzma compressed", },
{ IH_COMP_LZO, "lzo", "lzo compressed", },
{ IH_COMP_LZ4, "lz4", "lz4 compressed", },
+ { IH_COMP_ZSTD, "zstd", "zstd compressed", },
{ -1, "", "", },
};
@@ -480,6 +482,56 @@ int image_decomp(int comp, ulong load, ulong image_start, int type,
break;
}
#endif /* CONFIG_LZ4 */
+#ifdef CONFIG_ZSTD
+ case IH_COMP_ZSTD: {
+ size_t size = unc_len;
+ ZSTD_DStream *dstream;
+ ZSTD_inBuffer in_buf;
+ ZSTD_outBuffer out_buf;
+ void *workspace;
+ size_t wsize;
+
+ wsize = ZSTD_DStreamWorkspaceBound(image_len);
+ workspace = malloc(wsize);
+ if (!workspace) {
+ debug("%s: cannot allocate workspace of size %zu\n", __func__,
+ wsize);
+ return -1;
+ }
+
+ dstream = ZSTD_initDStream(image_len, workspace, wsize);
+ if (!dstream) {
+ printf("%s: ZSTD_initDStream failed\n", __func__);
+ return ZSTD_getErrorCode(ret);
+ }
+
+ in_buf.src = image_buf;
+ in_buf.pos = 0;
+ in_buf.size = image_len;
+
+ out_buf.dst = load_buf;
+ out_buf.pos = 0;
+ out_buf.size = size;
+
+ while (1) {
+ size_t ret;
+
+ ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf);
+ if (ZSTD_isError(ret)) {
+ printf("%s: ZSTD_decompressStream error %d\n", __func__,
+ ZSTD_getErrorCode(ret));
+ return ZSTD_getErrorCode(ret);
+ }
+
+ if (in_buf.pos >= image_len || !ret)
+ break;
+ }
+
+ image_len = out_buf.pos;
+
+ break;
+ }
+#endif /* CONFIG_ZSTD */
default:
printf("Unimplemented compression type %d\n", comp);
return -ENOSYS;
diff --git a/include/image.h b/include/image.h
index 3ffc0fdd68..8c79f6df9e 100644
--- a/include/image.h
+++ b/include/image.h
@@ -308,6 +308,7 @@ enum {
IH_COMP_LZMA, /* lzma Compression Used */
IH_COMP_LZO, /* lzo Compression Used */
IH_COMP_LZ4, /* lz4 Compression Used */
+ IH_COMP_ZSTD, /* zstd Compression Used */
IH_COMP_COUNT,
};
--
2.26.2
next reply other threads:[~2020-04-25 17:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-25 17:37 Robert Marko [this message]
2020-05-01 14:56 ` [PATCH] image: Add support for ZSTD decompression Tom Rini
2020-05-01 15:15 ` Robert Marko
2020-05-01 16:42 ` Tom Rini
2020-05-03 10:24 ` Robert Marko
2020-05-04 13:03 ` Tom Rini
2020-05-05 21:19 ` Robert Marko
2020-05-20 11:38 ` Robert Marko
2020-05-20 12:35 ` Tom Rini
2020-06-08 19:01 ` Robert Marko
2020-06-10 9:13 ` Rasmus Villemoes
2020-06-11 20:10 ` Tom Rini
2020-07-08 3:02 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200425173721.2759955-1-robert.marko@sartura.hr \
--to=robert.marko@sartura.hr \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.