diff --git a/lib/uzlib/adler32.c b/lib/uzlib/adler32.c index 1f1759493b..65fe1181b8 100644 --- a/lib/uzlib/adler32.c +++ b/lib/uzlib/adler32.c @@ -36,7 +36,7 @@ * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler */ -#include "tinf.h" +#include "uzlib.h" #define A32_BASE 65521 #define A32_NMAX 5552 diff --git a/lib/uzlib/crc32.c b/lib/uzlib/crc32.c index e24c643b6a..1e3b1756b3 100644 --- a/lib/uzlib/crc32.c +++ b/lib/uzlib/crc32.c @@ -36,7 +36,7 @@ * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler */ -#include "tinf.h" +#include "uzlib.h" static const unsigned int tinf_crc32tab[16] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, diff --git a/lib/uzlib/tinf.h b/lib/uzlib/tinf.h deleted file mode 100644 index ae6e1c4073..0000000000 --- a/lib/uzlib/tinf.h +++ /dev/null @@ -1,3 +0,0 @@ -/* Compatibility header for the original tinf lib/older versions of uzlib. - Note: may be removed in the future, please migrate to uzlib.h. */ -#include "uzlib.h" diff --git a/lib/uzlib/tinf_compat.h b/lib/uzlib/tinf_compat.h deleted file mode 100644 index f763804bd9..0000000000 --- a/lib/uzlib/tinf_compat.h +++ /dev/null @@ -1,9 +0,0 @@ -/* This header contains compatibility defines for the original tinf API - and uzlib 2.x and below API. These defines are deprecated and going - to be removed in the future, so applications should migrate to new - uzlib API. */ -#define TINF_DATA struct uzlib_uncomp - -#define destSize dest_size -#define destStart dest_start -#define readSource source_read_cb diff --git a/lib/uzlib/tinfgzip.c b/lib/uzlib/tinfgzip.c index 22b000df9a..3b0feb5321 100644 --- a/lib/uzlib/tinfgzip.c +++ b/lib/uzlib/tinfgzip.c @@ -33,7 +33,7 @@ * any source distribution. */ -#include "tinf.h" +#include "uzlib.h" #define FTEXT 1 #define FHCRC 2 @@ -41,38 +41,38 @@ #define FNAME 8 #define FCOMMENT 16 -void tinf_skip_bytes(TINF_DATA *d, int num); -uint16_t tinf_get_uint16(TINF_DATA *d); +void tinf_skip_bytes(uzlib_uncomp_t *d, int num); +uint16_t tinf_get_uint16(uzlib_uncomp_t *d); -void tinf_skip_bytes(TINF_DATA *d, int num) +void tinf_skip_bytes(uzlib_uncomp_t *d, int num) { while (num--) uzlib_get_byte(d); } -uint16_t tinf_get_uint16(TINF_DATA *d) +uint16_t tinf_get_uint16(uzlib_uncomp_t *d) { unsigned int v = uzlib_get_byte(d); v = (uzlib_get_byte(d) << 8) | v; return v; } -int uzlib_gzip_parse_header(TINF_DATA *d) +int uzlib_gzip_parse_header(uzlib_uncomp_t *d) { unsigned char flg; /* -- check format -- */ /* check id bytes */ - if (uzlib_get_byte(d) != 0x1f || uzlib_get_byte(d) != 0x8b) return TINF_DATA_ERROR; + if (uzlib_get_byte(d) != 0x1f || uzlib_get_byte(d) != 0x8b) return UZLIB_DATA_ERROR; /* check method is deflate */ - if (uzlib_get_byte(d) != 8) return TINF_DATA_ERROR; + if (uzlib_get_byte(d) != 8) return UZLIB_DATA_ERROR; /* get flag byte */ flg = uzlib_get_byte(d); /* check that reserved bits are zero */ - if (flg & 0xe0) return TINF_DATA_ERROR; + if (flg & 0xe0) return UZLIB_DATA_ERROR; /* -- find start of compressed data -- */ @@ -99,12 +99,12 @@ int uzlib_gzip_parse_header(TINF_DATA *d) // TODO: Check! // if (hcrc != (tinf_crc32(src, start - src) & 0x0000ffff)) -// return TINF_DATA_ERROR; +// return UZLIB_DATA_ERROR; } /* initialize for crc32 checksum */ - d->checksum_type = TINF_CHKSUM_CRC; + d->checksum_type = UZLIB_CHKSUM_CRC; d->checksum = ~0; - return TINF_OK; + return UZLIB_OK; } diff --git a/lib/uzlib/tinflate.c b/lib/uzlib/tinflate.c index 045952c755..e844d7faa4 100644 --- a/lib/uzlib/tinflate.c +++ b/lib/uzlib/tinflate.c @@ -33,7 +33,7 @@ */ #include -#include "tinf.h" +#include "uzlib.h" #define UZLIB_DUMP_ARRAY(heading, arr, size) \ { \ @@ -44,8 +44,8 @@ printf("\n"); \ } -uint32_t tinf_get_le_uint32(TINF_DATA *d); -uint32_t tinf_get_be_uint32(TINF_DATA *d); +uint32_t tinf_get_le_uint32(uzlib_uncomp_t *d); +uint32_t tinf_get_be_uint32(uzlib_uncomp_t *d); /* --------------------------------------------------- * * -- uninitialized global data (static structures) -- * @@ -189,7 +189,7 @@ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned * -- decode functions -- * * ---------------------- */ -unsigned char uzlib_get_byte(TINF_DATA *d) +unsigned char uzlib_get_byte(uzlib_uncomp_t *d) { /* If end of source buffer is not reached, return next byte from source buffer. */ @@ -200,14 +200,14 @@ unsigned char uzlib_get_byte(TINF_DATA *d) /* Otherwise if there's callback and we haven't seen EOF yet, try to read next byte using it. (Note: the callback can also update ->source and ->source_limit). */ - if (d->readSource && !d->eof) { - int val = d->readSource(d); + if (d->source_read_cb && !d->eof) { + int val = d->source_read_cb(d); if (val >= 0) { return (unsigned char)val; } } - /* Otherwise, we hit EOF (either from ->readSource() or from exhaustion + /* Otherwise, we hit EOF (either from ->source_read_cb() or from exhaustion of the buffer), and it will be "sticky", i.e. further calls to this function will end up here too. */ d->eof = true; @@ -215,7 +215,7 @@ unsigned char uzlib_get_byte(TINF_DATA *d) return 0; } -uint32_t tinf_get_le_uint32(TINF_DATA *d) +uint32_t tinf_get_le_uint32(uzlib_uncomp_t *d) { uint32_t val = 0; int i; @@ -225,7 +225,7 @@ uint32_t tinf_get_le_uint32(TINF_DATA *d) return val; } -uint32_t tinf_get_be_uint32(TINF_DATA *d) +uint32_t tinf_get_be_uint32(uzlib_uncomp_t *d) { uint32_t val = 0; int i; @@ -236,7 +236,7 @@ uint32_t tinf_get_be_uint32(TINF_DATA *d) } /* get one bit from source stream */ -static int tinf_getbit(TINF_DATA *d) +static int tinf_getbit(uzlib_uncomp_t *d) { unsigned int bit; @@ -256,7 +256,7 @@ static int tinf_getbit(TINF_DATA *d) } /* read a num bit value from a stream and add base */ -static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) +static unsigned int tinf_read_bits(uzlib_uncomp_t *d, int num, int base) { unsigned int val = 0; @@ -274,7 +274,7 @@ static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) } /* given a data stream and a tree, decode a symbol */ -static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) +static int tinf_decode_symbol(uzlib_uncomp_t *d, TINF_TREE *t) { int sum = 0, cur = 0, len = 0; @@ -284,7 +284,7 @@ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) cur = 2*cur + tinf_getbit(d); if (++len == TINF_ARRAY_SIZE(t->table)) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } sum += t->table[len]; @@ -295,7 +295,7 @@ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) sum += cur; #if UZLIB_CONF_PARANOID_CHECKS if (sum < 0 || sum >= TINF_ARRAY_SIZE(t->trans)) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } #endif @@ -303,7 +303,7 @@ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) } /* given a data stream, decode dynamic trees from it */ -static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) +static int tinf_decode_trees(uzlib_uncomp_t *d, TINF_TREE *lt, TINF_TREE *dt) { /* code lengths for 288 literal/len symbols and 32 dist symbols */ unsigned char lengths[288+32]; @@ -348,7 +348,7 @@ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) { case 16: /* copy previous code length 3-6 times (read 2 bits) */ - if (num == 0) return TINF_DATA_ERROR; + if (num == 0) return UZLIB_DATA_ERROR; fill_value = lengths[num - 1]; lbits = 2; break; @@ -370,7 +370,7 @@ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) /* special code length 16-18 are handled here */ length = tinf_read_bits(d, lbits, lbase); - if (num + length > hlimit) return TINF_DATA_ERROR; + if (num + length > hlimit) return UZLIB_DATA_ERROR; for (; length; --length) { lengths[num++] = fill_value; @@ -387,7 +387,7 @@ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) #if UZLIB_CONF_PARANOID_CHECKS /* Check that there's "end of block" symbol */ if (lengths[256] == 0) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } #endif @@ -395,7 +395,7 @@ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) tinf_build_tree(lt, lengths, hlit); tinf_build_tree(dt, lengths + hlit, hdist); - return TINF_OK; + return UZLIB_OK; } /* ----------------------------- * @@ -403,7 +403,7 @@ static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) * ----------------------------- */ /* given a stream and two trees, inflate next byte of output */ -static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) +static int tinf_inflate_block_data(uzlib_uncomp_t *d, TINF_TREE *lt, TINF_TREE *dt) { if (d->curlen == 0) { unsigned int offs; @@ -412,24 +412,24 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) //printf("huff sym: %02x\n", sym); if (d->eof) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } /* literal byte */ if (sym < 256) { TINF_PUT(d, sym); - return TINF_OK; + return UZLIB_OK; } /* end of block */ if (sym == 256) { - return TINF_DONE; + return UZLIB_DONE; } /* substring from sliding dictionary */ sym -= 257; if (sym >= 29) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } /* possibly get more bits from length code */ @@ -437,7 +437,7 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) dist = tinf_decode_symbol(d, dt); if (dist >= 30) { - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } /* possibly get more bits from distance code */ @@ -446,7 +446,7 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) /* calculate and validate actual LZ offset to use */ if (d->dict_ring) { if (offs > d->dict_size) { - return TINF_DICT_ERROR; + return UZLIB_DICT_ERROR; } /* Note: unlike full-dest-in-memory case below, we don't try to catch offset which points to not yet filled @@ -464,8 +464,8 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) } } else { /* catch trying to point before the start of dest buffer */ - if (offs > (unsigned int)(d->dest - d->destStart)) { - return TINF_DATA_ERROR; + if (offs > (unsigned int)(d->dest - d->dest_start)) { + return UZLIB_DATA_ERROR; } d->lzOff = -offs; } @@ -482,11 +482,11 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) d->dest++; } d->curlen--; - return TINF_OK; + return UZLIB_OK; } /* inflate next byte from uncompressed block of data */ -static int tinf_inflate_uncompressed_block(TINF_DATA *d) +static int tinf_inflate_uncompressed_block(uzlib_uncomp_t *d) { if (d->curlen == 0) { unsigned int length, invlength; @@ -498,9 +498,9 @@ static int tinf_inflate_uncompressed_block(TINF_DATA *d) invlength = uzlib_get_byte(d); invlength += 256 * uzlib_get_byte(d); /* check length */ - if (length != (~invlength & 0x0000ffff)) return TINF_DATA_ERROR; + if (length != (~invlength & 0x0000ffff)) return UZLIB_DATA_ERROR; - /* increment length to properly return TINF_DONE below, without + /* increment length to properly return UZLIB_DONE below, without producing data at the same time */ d->curlen = length + 1; @@ -509,12 +509,12 @@ static int tinf_inflate_uncompressed_block(TINF_DATA *d) } if (--d->curlen == 0) { - return TINF_DONE; + return UZLIB_DONE; } unsigned char c = uzlib_get_byte(d); TINF_PUT(d, c); - return TINF_OK; + return UZLIB_OK; } /* ---------------------- * @@ -536,7 +536,7 @@ void uzlib_init(void) } /* initialize decompression structure */ -void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen) +void uzlib_uncompress_init(uzlib_uncomp_t *d, void *dict, unsigned int dictLen) { d->eof = 0; d->bitcount = 0; @@ -549,7 +549,7 @@ void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen) } /* inflate next output bytes from compressed stream */ -int uzlib_uncompress(TINF_DATA *d) +int uzlib_uncompress(uzlib_uncomp_t *d) { do { int res; @@ -572,7 +572,7 @@ next_blk: } else if (d->btype == 2) { /* decode trees from stream */ res = tinf_decode_trees(d, &d->ltree, &d->dtree); - if (res != TINF_OK) { + if (res != UZLIB_OK) { return res; } } @@ -592,27 +592,27 @@ next_blk: res = tinf_inflate_block_data(d, &d->ltree, &d->dtree); break; default: - return TINF_DATA_ERROR; + return UZLIB_DATA_ERROR; } - if (res == TINF_DONE && !d->bfinal) { + if (res == UZLIB_DONE && !d->bfinal) { /* the block has ended (without producing more data), but we can't return without data, so start procesing next block */ goto next_blk; } - if (res != TINF_OK) { + if (res != UZLIB_OK) { return res; } } while (d->dest < d->dest_limit); - return TINF_OK; + return UZLIB_OK; } /* inflate next output bytes from compressed stream, updating checksum, and at the end of stream, verify it */ -int uzlib_uncompress_chksum(TINF_DATA *d) +int uzlib_uncompress_chksum(uzlib_uncomp_t *d) { int res; unsigned char *data = d->dest; @@ -623,31 +623,31 @@ int uzlib_uncompress_chksum(TINF_DATA *d) switch (d->checksum_type) { - case TINF_CHKSUM_ADLER: + case UZLIB_CHKSUM_ADLER: d->checksum = uzlib_adler32(data, d->dest - data, d->checksum); break; - case TINF_CHKSUM_CRC: + case UZLIB_CHKSUM_CRC: d->checksum = uzlib_crc32(data, d->dest - data, d->checksum); break; } - if (res == TINF_DONE) { + if (res == UZLIB_DONE) { unsigned int val; switch (d->checksum_type) { - case TINF_CHKSUM_ADLER: + case UZLIB_CHKSUM_ADLER: val = tinf_get_be_uint32(d); if (d->checksum != val) { - return TINF_CHKSUM_ERROR; + return UZLIB_CHKSUM_ERROR; } break; - case TINF_CHKSUM_CRC: + case UZLIB_CHKSUM_CRC: val = tinf_get_le_uint32(d); if (~d->checksum != val) { - return TINF_CHKSUM_ERROR; + return UZLIB_CHKSUM_ERROR; } // Uncompressed size. TODO: Check val = tinf_get_le_uint32(d); diff --git a/lib/uzlib/tinfzlib.c b/lib/uzlib/tinfzlib.c index 5cb8852fcc..03954cefae 100644 --- a/lib/uzlib/tinfzlib.c +++ b/lib/uzlib/tinfzlib.c @@ -33,9 +33,9 @@ * any source distribution. */ -#include "tinf.h" +#include "uzlib.h" -int uzlib_zlib_parse_header(TINF_DATA *d) +int uzlib_zlib_parse_header(uzlib_uncomp_t *d) { unsigned char cmf, flg; @@ -47,19 +47,19 @@ int uzlib_zlib_parse_header(TINF_DATA *d) /* -- check format -- */ /* check checksum */ - if ((256*cmf + flg) % 31) return TINF_DATA_ERROR; + if ((256*cmf + flg) % 31) return UZLIB_DATA_ERROR; /* check method is deflate */ - if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR; + if ((cmf & 0x0f) != 8) return UZLIB_DATA_ERROR; /* check window size is valid */ - if ((cmf >> 4) > 7) return TINF_DATA_ERROR; + if ((cmf >> 4) > 7) return UZLIB_DATA_ERROR; /* check there is no preset dictionary */ - if (flg & 0x20) return TINF_DATA_ERROR; + if (flg & 0x20) return UZLIB_DATA_ERROR; /* initialize for adler32 checksum */ - d->checksum_type = TINF_CHKSUM_ADLER; + d->checksum_type = UZLIB_CHKSUM_ADLER; d->checksum = 1; return cmf >> 4; diff --git a/lib/uzlib/uzlib.h b/lib/uzlib/uzlib.h index 83dddcd477..ca58299fc3 100644 --- a/lib/uzlib/uzlib.h +++ b/lib/uzlib/uzlib.h @@ -7,6 +7,9 @@ * * Copyright (c) 2014-2018 by Paul Sokolovsky * + * Optimised for MicroPython: + * Copyright (c) 2023 by Jim Mussared + * * This software is provided 'as-is', without any express * or implied warranty. In no event will the authors be * held liable for any damages arising from the use of @@ -46,31 +49,22 @@ #include #endif -/* calling convention */ -#ifndef TINFCC - #ifdef __WATCOMC__ - #define TINFCC __cdecl - #else - #define TINFCC - #endif -#endif - #ifdef __cplusplus extern "C" { #endif /* ok status, more data produced */ -#define TINF_OK 0 +#define UZLIB_OK 0 /* end of compressed stream reached */ -#define TINF_DONE 1 -#define TINF_DATA_ERROR (-3) -#define TINF_CHKSUM_ERROR (-4) -#define TINF_DICT_ERROR (-5) +#define UZLIB_DONE 1 +#define UZLIB_DATA_ERROR (-3) +#define UZLIB_CHKSUM_ERROR (-4) +#define UZLIB_DICT_ERROR (-5) /* checksum types */ -#define TINF_CHKSUM_NONE 0 -#define TINF_CHKSUM_ADLER 1 -#define TINF_CHKSUM_CRC 2 +#define UZLIB_CHKSUM_NONE 0 +#define UZLIB_CHKSUM_ADLER 1 +#define UZLIB_CHKSUM_CRC 2 /* helper macros */ #define TINF_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr))) @@ -82,7 +76,7 @@ typedef struct { unsigned short trans[288]; /* code -> symbol translation table */ } TINF_TREE; -struct uzlib_uncomp { +typedef struct _uzlib_uncomp_t { /* Pointer to the next byte in the input buffer */ const unsigned char *source; /* Pointer to the next byte past the input buffer (source_limit = source + len) */ @@ -92,7 +86,7 @@ struct uzlib_uncomp { also return -1 in case of EOF (or irrecoverable error). Note that besides returning the next byte, it may also update source and source_limit fields, thus allowing for buffered operation. */ - int (*source_read_cb)(struct uzlib_uncomp *uncomp); + int (*source_read_cb)(struct _uzlib_uncomp_t *uncomp); unsigned int tag; unsigned int bitcount; @@ -119,9 +113,7 @@ struct uzlib_uncomp { TINF_TREE ltree; /* dynamic length/symbol tree */ TINF_TREE dtree; /* dynamic distance tree */ -}; - -#include "tinf_compat.h" +} uzlib_uncomp_t; #define TINF_PUT(d, c) \ { \ @@ -129,17 +121,17 @@ struct uzlib_uncomp { if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \ } -unsigned char TINFCC uzlib_get_byte(TINF_DATA *d); +unsigned char uzlib_get_byte(uzlib_uncomp_t *d); /* Decompression API */ -void TINFCC uzlib_init(void); -void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen); -int TINFCC uzlib_uncompress(TINF_DATA *d); -int TINFCC uzlib_uncompress_chksum(TINF_DATA *d); +void uzlib_init(void); +void uzlib_uncompress_init(uzlib_uncomp_t *d, void *dict, unsigned int dictLen); +int uzlib_uncompress(uzlib_uncomp_t *d); +int uzlib_uncompress_chksum(uzlib_uncomp_t *d); -int TINFCC uzlib_zlib_parse_header(TINF_DATA *d); -int TINFCC uzlib_gzip_parse_header(TINF_DATA *d); +int uzlib_zlib_parse_header(uzlib_uncomp_t *d); +int uzlib_gzip_parse_header(uzlib_uncomp_t *d); /* Compression API */ @@ -151,15 +143,15 @@ struct uzlib_lz77_state { size_t hist_len; }; -void TINFCC uzlib_lz77_init(struct uzlib_lz77_state *state, uint8_t *hist, size_t hist_max); -void TINFCC uzlib_lz77_compress(struct uzlib_lz77_state *state, const uint8_t *src, unsigned len); +void uzlib_lz77_init(struct uzlib_lz77_state *state, uint8_t *hist, size_t hist_max); +void uzlib_lz77_compress(struct uzlib_lz77_state *state, const uint8_t *src, unsigned len); /* Checksum API */ /* prev_sum is previous value for incremental computation, 1 initially */ -uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum); +uint32_t uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum); /* crc is previous value for incremental computation, 0xffffffff initially */ -uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc); +uint32_t uzlib_crc32(const void *data, unsigned int length, uint32_t crc); #ifdef __cplusplus } /* extern "C" */ diff --git a/ports/stm32/mboot/fsload.c b/ports/stm32/mboot/fsload.c index f3ea57c89f..abc3514ed1 100644 --- a/ports/stm32/mboot/fsload.c +++ b/ports/stm32/mboot/fsload.c @@ -27,7 +27,7 @@ #include #include "py/mphal.h" -#include "lib/uzlib/tinf.h" +#include "lib/uzlib/uzlib.h" #include "mboot.h" #include "pack.h" #include "vfs.h" diff --git a/ports/stm32/mboot/gzstream.c b/ports/stm32/mboot/gzstream.c index 6ed8a21d99..f008eca5cd 100644 --- a/ports/stm32/mboot/gzstream.c +++ b/ports/stm32/mboot/gzstream.c @@ -38,14 +38,14 @@ typedef struct _gz_stream_t { void *stream_data; stream_read_t stream_read; - struct uzlib_uncomp tinf; + uzlib_uncomp_t decomp; uint8_t buf[512]; uint8_t dict[DICT_SIZE]; } gz_stream_t; static gz_stream_t gz_stream SECTION_NOZERO_BSS; -static int gz_stream_read_src(TINF_DATA *tinf) { +static int gz_stream_read_src(uzlib_uncomp_t *decomp) { int n = gz_stream.stream_read(gz_stream.stream_data, gz_stream.buf, sizeof(gz_stream.buf)); if (n < 0) { // Stream error @@ -56,17 +56,17 @@ static int gz_stream_read_src(TINF_DATA *tinf) { return -1; } - tinf->source = gz_stream.buf + 1; - tinf->source_limit = gz_stream.buf + n; + decomp->source = gz_stream.buf + 1; + decomp->source_limit = gz_stream.buf + n; return gz_stream.buf[0]; } int gz_stream_init_from_raw_data(const uint8_t *data, size_t len) { - memset(&gz_stream.tinf, 0, sizeof(gz_stream.tinf)); - gz_stream.tinf.source = data; - gz_stream.tinf.source_limit = data + len; + memset(&gz_stream.decomp, 0, sizeof(gz_stream.decomp)); + gz_stream.decomp.source = data; + gz_stream.decomp.source_limit = data + len; - uzlib_uncompress_init(&gz_stream.tinf, gz_stream.dict, DICT_SIZE); + uzlib_uncompress_init(&gz_stream.decomp, gz_stream.dict, DICT_SIZE); return 0; } @@ -75,36 +75,36 @@ int gz_stream_init_from_stream(void *stream_data, stream_read_t stream_read) { gz_stream.stream_data = stream_data; gz_stream.stream_read = stream_read; - memset(&gz_stream.tinf, 0, sizeof(gz_stream.tinf)); - gz_stream.tinf.source_read_cb = gz_stream_read_src; + memset(&gz_stream.decomp, 0, sizeof(gz_stream.decomp)); + gz_stream.decomp.source_read_cb = gz_stream_read_src; - int st = uzlib_gzip_parse_header(&gz_stream.tinf); - if (st != TINF_OK) { + int st = uzlib_gzip_parse_header(&gz_stream.decomp); + if (st != UZLIB_OK) { return -MBOOT_ERRNO_GUNZIP_FAILED; } - uzlib_uncompress_init(&gz_stream.tinf, gz_stream.dict, DICT_SIZE); + uzlib_uncompress_init(&gz_stream.decomp, gz_stream.dict, DICT_SIZE); return 0; } int gz_stream_read(size_t len, uint8_t *buf) { - if (gz_stream.tinf.source == NULL && gz_stream.tinf.source_read_cb == NULL) { + if (gz_stream.decomp.source == NULL && gz_stream.decomp.source_read_cb == NULL) { // End of stream. return 0; } - gz_stream.tinf.dest = buf; - gz_stream.tinf.dest_limit = buf + len; - int st = uzlib_uncompress_chksum(&gz_stream.tinf); + gz_stream.decomp.dest = buf; + gz_stream.decomp.dest_limit = buf + len; + int st = uzlib_uncompress_chksum(&gz_stream.decomp); if (st < 0) { return st; } - if (st == TINF_DONE) { + if (st == UZLIB_DONE) { // Indicate end-of-stream for subsequent calls. - gz_stream.tinf.source = NULL; - gz_stream.tinf.source_read_cb = NULL; + gz_stream.decomp.source = NULL; + gz_stream.decomp.source_read_cb = NULL; } - return gz_stream.tinf.dest - buf; + return gz_stream.decomp.dest - buf; } #endif // MBOOT_FSLOAD || MBOOT_ENABLE_PACKING