diff mbox series

image: Add support for ZSTD decompression

Message ID 20200425173721.2759955-1-robert.marko@sartura.hr
State Accepted
Commit 26073f9ed3ab0aaf3c2a2b433fecb30a95a067d6
Headers show
Series image: Add support for ZSTD decompression | expand

Commit Message

Robert Marko April 25, 2020, 5:37 p.m. UTC
This patch adds support for ZSTD decompression of FIT images.

Signed-off-by: Robert Marko <robert.marko at sartura.hr>
Cc: Luka Perkov <luka.perkov at sartura.hr>
---
 common/image.c  | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/image.h |  1 +
 2 files changed, 53 insertions(+)

Comments

Tom Rini May 1, 2020, 2:56 p.m. UTC | #1
On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:

> This patch adds support for ZSTD decompression of FIT images.
> 
> Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> Cc: Luka Perkov <luka.perkov at 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

We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
Robert Marko May 1, 2020, 3:15 p.m. UTC | #2
On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
>
> On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
>
> > This patch adds support for ZSTD decompression of FIT images.
> >
> > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> > Cc: Luka Perkov <luka.perkov at 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
>
> We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
> CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
Hi,
is that something that I need to do or?

Thanks
>
> --
> Tom
Tom Rini May 1, 2020, 4:42 p.m. UTC | #3
On Fri, May 01, 2020 at 05:15:41PM +0200, Robert Marko wrote:
> On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
> >
> > On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
> >
> > > This patch adds support for ZSTD decompression of FIT images.
> > >
> > > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> > > Cc: Luka Perkov <luka.perkov at 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
> >
> > We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
> > CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
> Hi,
> is that something that I need to do or?

Yes.  You need to add the symbol, and then the code you're adding needs
to make use of '#if CONFIG_IS_ENABLED(ZSTD)' rather than '#ifdef
CONFIG_ZSTD'.  Sorry for not being clear enough.
Robert Marko May 3, 2020, 10:24 a.m. UTC | #4
Hi,

I checked and SPL_ZSTD symbol already exists.
But trying to use #if CONFIG_IS_ENABLED(ZSTD) inside
of the switch case will fail with the preprocessor error:
In file included from tools/common/image.c:1:

> ./tools/../common/image.c: In function ?image_decomp?:
> ./tools/../common/image.c:510:22: error: missing binary operator before
> token "("
>   510 | #if CONFIG_IS_ENABLED(ZSTD)


Outside of the switch_case it works fine


On Fri, May 1, 2020 at 6:42 PM Tom Rini <trini at konsulko.com> wrote:

> On Fri, May 01, 2020 at 05:15:41PM +0200, Robert Marko wrote:
> > On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
> > >
> > > On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
> > >
> > > > This patch adds support for ZSTD decompression of FIT images.
> > > >
> > > > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> > > > Cc: Luka Perkov <luka.perkov at 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
> > >
> > > We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
> > > CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
> > Hi,
> > is that something that I need to do or?
>
> Yes.  You need to add the symbol, and then the code you're adding needs
> to make use of '#if CONFIG_IS_ENABLED(ZSTD)' rather than '#ifdef
> CONFIG_ZSTD'.  Sorry for not being clear enough.
>
> --
> Tom
>
Tom Rini May 4, 2020, 1:03 p.m. UTC | #5
On Sun, May 03, 2020 at 12:24:14PM +0200, Robert Marko wrote:
> Hi,
> 
> I checked and SPL_ZSTD symbol already exists.
> But trying to use #if CONFIG_IS_ENABLED(ZSTD) inside
> of the switch case will fail with the preprocessor error:
> In file included from tools/common/image.c:1:

Ah right, oops.

> > ./tools/../common/image.c: In function ?image_decomp?:
> > ./tools/../common/image.c:510:22: error: missing binary operator before
> > token "("
> >   510 | #if CONFIG_IS_ENABLED(ZSTD)
> 
> 
> Outside of the switch_case it works fine

Sounds like <linux/kconfig.h> needs an explicit #include then.

> 
> 
> On Fri, May 1, 2020 at 6:42 PM Tom Rini <trini at konsulko.com> wrote:
> 
> > On Fri, May 01, 2020 at 05:15:41PM +0200, Robert Marko wrote:
> > > On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
> > > >
> > > > On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
> > > >
> > > > > This patch adds support for ZSTD decompression of FIT images.
> > > > >
> > > > > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> > > > > Cc: Luka Perkov <luka.perkov at 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
> > > >
> > > > We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
> > > > CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
> > > Hi,
> > > is that something that I need to do or?
> >
> > Yes.  You need to add the symbol, and then the code you're adding needs
> > to make use of '#if CONFIG_IS_ENABLED(ZSTD)' rather than '#ifdef
> > CONFIG_ZSTD'.  Sorry for not being clear enough.
> >
> > --
> > Tom
> >
Robert Marko May 5, 2020, 9:19 p.m. UTC | #6
On Mon, May 4, 2020 at 3:04 PM Tom Rini <trini at konsulko.com> wrote:

> On Sun, May 03, 2020 at 12:24:14PM +0200, Robert Marko wrote:
> > Hi,
> >
> > I checked and SPL_ZSTD symbol already exists.
> > But trying to use #if CONFIG_IS_ENABLED(ZSTD) inside
> > of the switch case will fail with the preprocessor error:
> > In file included from tools/common/image.c:1:
>
> Ah right, oops.
>
> > > ./tools/../common/image.c: In function ?image_decomp?:
> > > ./tools/../common/image.c:510:22: error: missing binary operator before
> > > token "("
> > >   510 | #if CONFIG_IS_ENABLED(ZSTD)
> >
> >
> > Outside of the switch_case it works fine
>
> Sounds like <linux/kconfig.h> needs an explicit #include then.
>
Unfortunately, it does not help.
Preprocessor throws the same error

>
> >
> >
> > On Fri, May 1, 2020 at 6:42 PM Tom Rini <trini at konsulko.com> wrote:
> >
> > > On Fri, May 01, 2020 at 05:15:41PM +0200, Robert Marko wrote:
> > > > On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
> > > > >
> > > > > On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
> > > > >
> > > > > > This patch adds support for ZSTD decompression of FIT images.
> > > > > >
> > > > > > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> > > > > > Cc: Luka Perkov <luka.perkov at 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
> > > > >
> > > > > We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
> > > > > CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
> > > > Hi,
> > > > is that something that I need to do or?
> > >
> > > Yes.  You need to add the symbol, and then the code you're adding needs
> > > to make use of '#if CONFIG_IS_ENABLED(ZSTD)' rather than '#ifdef
> > > CONFIG_ZSTD'.  Sorry for not being clear enough.
> > >
> > > --
> > > Tom
> > >
>
> --
> Tom
>
Robert Marko May 20, 2020, 11:38 a.m. UTC | #7
Tom,
I have tried various things but CONFIG_IS_ENABLED won't work inside of
switch case.
It works fine outside of if though.


On Tue, May 5, 2020 at 11:19 PM Robert Marko <robert.marko at sartura.hr> wrote:
>
>
>
> On Mon, May 4, 2020 at 3:04 PM Tom Rini <trini at konsulko.com> wrote:
>>
>> On Sun, May 03, 2020 at 12:24:14PM +0200, Robert Marko wrote:
>> > Hi,
>> >
>> > I checked and SPL_ZSTD symbol already exists.
>> > But trying to use #if CONFIG_IS_ENABLED(ZSTD) inside
>> > of the switch case will fail with the preprocessor error:
>> > In file included from tools/common/image.c:1:
>>
>> Ah right, oops.
>>
>> > > ./tools/../common/image.c: In function ?image_decomp?:
>> > > ./tools/../common/image.c:510:22: error: missing binary operator before
>> > > token "("
>> > >   510 | #if CONFIG_IS_ENABLED(ZSTD)
>> >
>> >
>> > Outside of the switch_case it works fine
>>
>> Sounds like <linux/kconfig.h> needs an explicit #include then.
>
> Unfortunately, it does not help.
> Preprocessor throws the same error
>>
>>
>> >
>> >
>> > On Fri, May 1, 2020 at 6:42 PM Tom Rini <trini at konsulko.com> wrote:
>> >
>> > > On Fri, May 01, 2020 at 05:15:41PM +0200, Robert Marko wrote:
>> > > > On Fri, May 1, 2020 at 4:56 PM Tom Rini <trini at konsulko.com> wrote:
>> > > > >
>> > > > > On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:
>> > > > >
>> > > > > > This patch adds support for ZSTD decompression of FIT images.
>> > > > > >
>> > > > > > Signed-off-by: Robert Marko <robert.marko at sartura.hr>
>> > > > > > Cc: Luka Perkov <luka.perkov at 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
>> > > > >
>> > > > > We need to add SPL_ZSTD as a symbol to lib/Kconfig and then use
>> > > > > CONFIG_IS_ENABLED() tests here to avoid growth in SPL.  Thanks!
>> > > > Hi,
>> > > > is that something that I need to do or?
>> > >
>> > > Yes.  You need to add the symbol, and then the code you're adding needs
>> > > to make use of '#if CONFIG_IS_ENABLED(ZSTD)' rather than '#ifdef
>> > > CONFIG_ZSTD'.  Sorry for not being clear enough.
>> > >
>> > > --
>> > > Tom
>> > >
>>
>> --
>> Tom
Tom Rini May 20, 2020, 12:35 p.m. UTC | #8
On Wed, May 20, 2020 at 01:38:01PM +0200, Robert Marko wrote:

> Tom,
> I have tried various things but CONFIG_IS_ENABLED won't work inside of
> switch case.
> It works fine outside of if though.

OK, thanks, I'll poke things more to make sure what I'm worried about
doesn't happen.
Robert Marko June 8, 2020, 7:01 p.m. UTC | #9
On Wed, May 20, 2020 at 2:35 PM Tom Rini <trini at konsulko.com> wrote:
>
> On Wed, May 20, 2020 at 01:38:01PM +0200, Robert Marko wrote:
>
> > Tom,
> > I have tried various things but CONFIG_IS_ENABLED won't work inside of
> > switch case.
> > It works fine outside of if though.
>
> OK, thanks, I'll poke things more to make sure what I'm worried about
> doesn't happen.

Hi,
were you able to test the commit?

Regards,
Robert
>
> --
> Tom
Tom Rini July 8, 2020, 3:02 a.m. UTC | #10
On Sat, Apr 25, 2020 at 07:37:21PM +0200, Robert Marko wrote:

> This patch adds support for ZSTD decompression of FIT images.
> 
> Signed-off-by: Robert Marko <robert.marko at sartura.hr>
> Cc: Luka Perkov <luka.perkov at sartura.hr>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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,
 };