mirror of
https://github.com/linux-sunxi/u-boot-sunxi.git
synced 2024-02-12 11:16:03 +08:00
lib_generic: gunzip: New function zunzip
Separate gunzip in gunzip: Find the end of the header and call zunzip. zunzip: Inflate gunzip block without header. UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of the zlib blocks. UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header. This patch adds a new function zunzip that uncompress a zlib block with no header. Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@uam.es>
This commit is contained in:

committed by
Wolfgang Denk

parent
ccb71dfac9
commit
35f6a943f7
@ -39,6 +39,8 @@
|
|||||||
int gunzip(void *, int, unsigned char *, unsigned long *);
|
int gunzip(void *, int, unsigned char *, unsigned long *);
|
||||||
void *zalloc(void *, unsigned, unsigned);
|
void *zalloc(void *, unsigned, unsigned);
|
||||||
void zfree(void *, void *, unsigned);
|
void zfree(void *, void *, unsigned);
|
||||||
|
int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
|
||||||
|
int stoponerr, int offset);
|
||||||
|
|
||||||
void *zalloc(void *x, unsigned items, unsigned size)
|
void *zalloc(void *x, unsigned items, unsigned size)
|
||||||
{
|
{
|
||||||
@ -59,8 +61,7 @@ void zfree(void *x, void *addr, unsigned nb)
|
|||||||
|
|
||||||
int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
||||||
{
|
{
|
||||||
z_stream s;
|
int i, flags;
|
||||||
int r, i, flags;
|
|
||||||
|
|
||||||
/* skip header */
|
/* skip header */
|
||||||
i = 10;
|
i = 10;
|
||||||
@ -84,6 +85,18 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return zunzip(dst, dstlen, src, lenp, 1, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Uncompress blocks compressed with zlib without headers
|
||||||
|
*/
|
||||||
|
int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
|
||||||
|
int stoponerr, int offset)
|
||||||
|
{
|
||||||
|
z_stream s;
|
||||||
|
int r;
|
||||||
|
|
||||||
s.zalloc = zalloc;
|
s.zalloc = zalloc;
|
||||||
s.zfree = zfree;
|
s.zfree = zfree;
|
||||||
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
||||||
@ -95,14 +108,14 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
|||||||
r = inflateInit2(&s, -MAX_WBITS);
|
r = inflateInit2(&s, -MAX_WBITS);
|
||||||
if (r != Z_OK) {
|
if (r != Z_OK) {
|
||||||
printf ("Error: inflateInit2() returned %d\n", r);
|
printf ("Error: inflateInit2() returned %d\n", r);
|
||||||
return (-1);
|
return -1;
|
||||||
}
|
}
|
||||||
s.next_in = src + i;
|
s.next_in = src + offset;
|
||||||
s.avail_in = *lenp - i;
|
s.avail_in = *lenp - offset;
|
||||||
s.next_out = dst;
|
s.next_out = dst;
|
||||||
s.avail_out = dstlen;
|
s.avail_out = dstlen;
|
||||||
r = inflate(&s, Z_FINISH);
|
r = inflate(&s, Z_FINISH);
|
||||||
if (r != Z_STREAM_END) {
|
if ((r != Z_STREAM_END) && (stoponerr==1)) {
|
||||||
printf ("Error: inflate() returned %d\n", r);
|
printf ("Error: inflate() returned %d\n", r);
|
||||||
inflateEnd(&s);
|
inflateEnd(&s);
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -110,5 +123,5 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
|
|||||||
*lenp = s.next_out - (unsigned char *) dst;
|
*lenp = s.next_out - (unsigned char *) dst;
|
||||||
inflateEnd(&s);
|
inflateEnd(&s);
|
||||||
|
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user