On Tue, Apr 29, 2025 at 11:15:58PM +0800, Aristo Chen wrote:
> Tom Rini <tr...@konsulko.com> 於 2025年4月29日 週二 下午10:15寫道:
> >
> > On Tue, Apr 29, 2025 at 06:08:50PM +0800, 陳偉銘 wrote:
> > > Tom Rini <tr...@konsulko.com> 於 2025年4月29日 週二 上午1:24寫道:
> > > >
> > > > On Mon, Apr 28, 2025 at 02:07:57PM +0800, Aristo Chen wrote:
> > > >
> > > > > Currently, when decompressing a gzip-compressed image during bootm, a
> > > > > generic error such as "inflate() returned -5" is shown when the 
> > > > > buffer is
> > > > > too small. However, it is not immediately clear that this is caused by
> > > > > CONFIG_SYS_BOOTM_LEN being too small.
> > > > >
> > > > > This patch improves error handling by:
> > > > > - Detecting Z_BUF_ERROR (-5) returned from the inflate() call
> > > > > - Suggesting the user to increase CONFIG_SYS_BOOTM_LEN when applicable
> > > > > - Preserving the original return code from zunzip() instead of 
> > > > > overwriting
> > > > >   it with -1
> > > > >
> > > > > By providing clearer hints when decompression fails due to 
> > > > > insufficient
> > > > > buffer size, this change helps users diagnose and fix boot failures 
> > > > > more
> > > > > easily.
> > > > >
> > > > > Signed-off-by: Aristo Chen <aristo.c...@canonical.com>
> > > >
> > > > I like the concept but:
> > > >
> > > > > @@ -573,12 +574,26 @@ static int handle_decomp_error(int comp_type, 
> > > > > size_t uncomp_size,
> > > > >                              size_t buf_size, int ret)
> > > > >  {
> > > > >       const char *name = genimg_get_comp_name(comp_type);
> > > > > +     bool likely_buf_too_small = false;
> > > > >
> > > > >       /* ENOSYS means unimplemented compression type, don't reset. */
> > > > >       if (ret == -ENOSYS)
> > > > >               return BOOTM_ERR_UNIMPLEMENTED;
> > > > >
> > > > > +     switch (comp_type) {
> > > > > +     case IH_COMP_GZIP:
> > > > > +             if (ret == Z_BUF_ERROR) /* -5 */
> > > > > +                     likely_buf_too_small = true;
> > > > > +             break;
> > > > > +     // Add more if necessary
> > > > > +     default:
> > > > > +             break;
> > > > > +     }
> > > > > +
> > > > >       if (uncomp_size >= buf_size)
> > > > > +             likely_buf_too_small = true;
> > > > > +
> > > > > +     if (likely_buf_too_small)
> > > > >               printf("Image too large: increase 
> > > > > CONFIG_SYS_BOOTM_LEN\n");
> > > > >       else
> > > > >               printf("%s: uncompress error %d\n", name, ret);
> > > >
> > > > This is a lot of code, why not just:
> > > > if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
> > > >   printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> > > >
> > > Thanks for your suggestion! I am not sure if I get it correctly, do
> > > you mean that we should remove the original if condition( if
> > > (uncomp_size >= buf_size) ) that prints the error message?
> >
> > Ah sorry for being unclear. I just meant we can handle the new print
> > more directly.
> No worries, and thanks for your patience.
> 
> Just to double confirm, would the following meet your expectation?
> 
> if (comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR)
>     printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> else if (uncomp_size >= buf_size)
>     printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> else
>     printf("%s: uncompress error %d\n", name, ret);
> 
> Or would you prefer combining the first two conditions into one?
> 
> if ((comp_type == IH_COMP_GZIP && ret == Z_BUF_ERROR) ||
>     uncomp_size >= buf_size)
>     printf("Image too large: increase CONFIG_SYS_BOOTM_LEN\n");
> else
>     printf("%s: uncompress error %d\n", name, ret);

The second option yes, and then someone in the future can add
(comp_type == IH_COMP_LZO && ret == LZO_EQUIVALENT_ERROR) ||
and so forth.

-- 
Tom

Attachment: signature.asc
Description: PGP signature

Reply via email to