From 0c670fc1481d2296f1f5837ea5c15cfbdaed710c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Aug 2019 09:46:36 -0600 Subject: [PATCH] common: Move gzip functions into a new gzip header As part of the effort to remove things from common.h, create a new header for the gzip functions. Move the function declarations to it and add missing documentation. Signed-off-by: Simon Glass Reviewed-by: Simon Goldschmidt --- board/menlo/m53menlo/m53menlo.c | 1 + cmd/bmp.c | 8 +-- cmd/config.c | 1 + cmd/fpga.c | 1 + cmd/license.c | 1 + cmd/unzip.c | 1 + cmd/ximg.c | 1 + common/image.c | 1 + common/spl/spl_fit.c | 1 + common/spl/spl_ymodem.c | 1 + drivers/video/cfb_console.c | 1 + fs/ubifs/ubifs.c | 1 + include/common.h | 52 ---------------- include/gzip.h | 103 ++++++++++++++++++++++++++++++++ lib/fdtdec.c | 1 + lib/gunzip.c | 5 +- lib/gzip.c | 1 + test/compression.c | 1 + 18 files changed, 124 insertions(+), 58 deletions(-) create mode 100644 include/gzip.h diff --git a/board/menlo/m53menlo/m53menlo.c b/board/menlo/m53menlo/m53menlo.c index f2227f6992..a63af5fae0 100644 --- a/board/menlo/m53menlo/m53menlo.c +++ b/board/menlo/m53menlo/m53menlo.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/cmd/bmp.c b/cmd/bmp.c index 00f0256a30..d2a39f677f 100644 --- a/cmd/bmp.c +++ b/cmd/bmp.c @@ -9,16 +9,16 @@ */ #include -#include -#include -#include #include #include -#include +#include +#include +#include #include #include #include #include +#include static int bmp_info (ulong addr); diff --git a/cmd/config.c b/cmd/config.c index fcc9116a49..d2810d573b 100644 --- a/cmd/config.c +++ b/cmd/config.c @@ -5,6 +5,7 @@ #include #include +#include #include #include "config_data_gz.h" diff --git a/cmd/fpga.c b/cmd/fpga.c index eba989a730..9fc2df699d 100644 --- a/cmd/fpga.c +++ b/cmd/fpga.c @@ -11,6 +11,7 @@ #include #include #include +#include #include static long do_fpga_get_device(char *arg) diff --git a/cmd/license.c b/cmd/license.c index 1c0794f095..c5b04c331b 100644 --- a/cmd/license.c +++ b/cmd/license.c @@ -6,6 +6,7 @@ #include #include +#include #include #include "license_data_gz.h" diff --git a/cmd/unzip.c b/cmd/unzip.c index 6c0f97cb4b..8474d9becf 100644 --- a/cmd/unzip.c +++ b/cmd/unzip.c @@ -6,6 +6,7 @@ #include #include +#include static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/cmd/ximg.c b/cmd/ximg.c index 9e53cc4557..920a80edc8 100644 --- a/cmd/ximg.c +++ b/cmd/ximg.c @@ -13,6 +13,7 @@ */ #include #include +#include #include #include #include diff --git a/common/image.c b/common/image.c index 495883185d..719229cc43 100644 --- a/common/image.c +++ b/common/image.c @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 969f7775c1..2e2e09eafb 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index fa539ecd7a..20f4260062 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -9,6 +9,7 @@ * Matt Porter */ #include +#include #include #include #include diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c index 636c3e8c18..ac02921d46 100644 --- a/drivers/video/cfb_console.c +++ b/drivers/video/cfb_console.c @@ -66,6 +66,7 @@ #include #include +#include #include #include #include diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index d5101d3c45..72e8a24d3b 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -12,6 +12,7 @@ */ #include +#include #include #include "ubifs.h" #include diff --git a/include/common.h b/include/common.h index 2c21dee850..d337f68bc4 100644 --- a/include/common.h +++ b/include/common.h @@ -428,51 +428,6 @@ void wait_ticks (unsigned long); ulong usec2ticks (unsigned long usec); ulong ticks2usec (unsigned long ticks); -/* lib/gunzip.c */ -int gzip_parse_header(const unsigned char *src, unsigned long len); -int gunzip(void *, int, unsigned char *, unsigned long *); -int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, - int stoponerr, int offset); - -/** - * gzwrite progress indicators: defined weak to allow board-specific - * overrides: - * - * gzwrite_progress_init called on startup - * gzwrite_progress called during decompress/write loop - * gzwrite_progress_finish called at end of loop to - * indicate success (retcode=0) or failure - */ -void gzwrite_progress_init(u64 expected_size); - -void gzwrite_progress(int iteration, - u64 bytes_written, - u64 total_bytes); - -void gzwrite_progress_finish(int retcode, - u64 totalwritten, - u64 totalsize, - u32 expected_crc, - u32 calculated_crc); - -/** - * decompress and write gzipped image from memory to block device - * - * @param src compressed image address - * @param len compressed image length in bytes - * @param dev block device descriptor - * @param szwritebuf bytes per write (pad to erase size) - * @param startoffs offset in bytes of first write - * @param szexpected expected uncompressed length - * may be zero to use gzip trailer - * for files under 4GiB - */ -int gzwrite(unsigned char *src, int len, - struct blk_desc *dev, - unsigned long szwritebuf, - u64 startoffs, - u64 szexpected); - /* lib/lz4_wrapper.c */ int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn); @@ -506,13 +461,6 @@ unsigned int rand_r(unsigned int *seedp); int serial_printf (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); -/* lib/gzip.c */ -int gzip(void *dst, unsigned long *lenp, - unsigned char *src, unsigned long srclen); -int zzip(void *dst, unsigned long *lenp, unsigned char *src, - unsigned long srclen, int stoponerr, - int (*func)(unsigned long, unsigned long)); - /* lib/net_utils.c */ #include static inline struct in_addr env_get_ip(char *var) diff --git a/include/gzip.h b/include/gzip.h new file mode 100644 index 0000000000..2e340673c3 --- /dev/null +++ b/include/gzip.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __GZIP_H +#define __GZIP_H + +/** + * gzip_parse_header() - Parse a header from a gzip file + * + * This returns the length of the header. + * + * @src: Pointer to gzip file + * @len: Length of data + * @return length of header in bytes, or -1 if not enough data + */ +int gzip_parse_header(const unsigned char *src, unsigned long len); + +/** + * gunzip() - Decompress gzipped data + * + * @dst: Destination for uncompressed data + * @dstlen: Size of destination buffer + * @src: Source data to decompress + * @lenp: Returns length of uncompressed data + * @return 0 if OK, -1 on error + */ +int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp); + +/** + * zunzip() - Uncompress blocks compressed with zlib without headers + * + * @dst: Destination for uncompressed data + * @dstlen: Size of destination buffer + * @src: Source data to decompress + * @lenp: On entry, length data at @src. On exit, number of bytes used from @src + * @stoponerr: 0 to continue when a decode error is found, 1 to stop + * @offset: start offset within the src buffer + * @return 0 if OK, -1 on error + */ +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset); + +/** + * gzwrite progress indicators: defined weak to allow board-specific + * overrides: + * + * gzwrite_progress_init called on startup + * gzwrite_progress called during decompress/write loop + * gzwrite_progress_finish called at end of loop to + * indicate success (retcode=0) or failure + */ +void gzwrite_progress_init(u64 expected_size); + +void gzwrite_progress(int iteration, u64 bytes_written, u64 total_bytes); + +void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize, + u32 expected_crc, u32 calculated_crc); + +/** + * gzwrite() - decompress and write gzipped image from memory to block device + * + * @src: compressed image address + * @len: compressed image length in bytes + * @dev: block device descriptor + * @szwritebuf: bytes per write (pad to erase size) + * @startoffs: offset in bytes of first write + * @szexpected: expected uncompressed length, may be zero to use gzip trailer + * for files under 4GiB + * @return 0 if OK, -1 on error + */ +int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong szwritebuf, + u64 startoffs, u64 szexpected); + +/** + * gzip()- Compress data into a buffer using the gzip algorithm + * + * @dst: Destination buffer for compressed data + * @lenp: On entry, space available in destination buffer (in bytes). On exit, + * number of bytes used in the buffer + * @src: Source data to compress + * @srclen: Size of source data + * @return 0 if OK, -1 on error + */ +int gzip(void *dst, unsigned long *lenp, unsigned char *src, ulong srclen); + +/** + * zzip() - Compress blocks with zlib + * + * @dst: Destination for compressed data + * @lenp: On entry, length data at @dst. On exit, number of bytes written to + * @dst + * @src: Source data to compress + * @srclen: Size of source data + * @stoponerr: 0 to continue when a decode error is found, 1 to stop + * @func: Some sort of function that is called to do something. !ADD DOCS HERE! + */ +int zzip(void *dst, ulong *lenp, unsigned char *src, ulong srclen, + int stoponerr, int (*func)(ulong, ulong)); + +#endif diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 3ee786b579..464de5b3b5 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/gunzip.c b/lib/gunzip.c index 15c7b2c932..1d65616c13 100644 --- a/lib/gunzip.c +++ b/lib/gunzip.c @@ -5,14 +5,15 @@ */ #include -#include #include #include +#include +#include #include #include #include +#include #include -#include #define HEADER0 '\x1f' #define HEADER1 '\x8b' diff --git a/lib/gzip.c b/lib/gzip.c index 674d732fe6..c6c0ec880c 100644 --- a/lib/gzip.c +++ b/lib/gzip.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/test/compression.c b/test/compression.c index dc5e94684f..08fef59d0a 100644 --- a/test/compression.c +++ b/test/compression.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include -- 2.25.1