Simon Glass | 1a974af | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __GZIP_H |
| 8 | #define __GZIP_H |
| 9 | |
| 10 | /** |
| 11 | * gzip_parse_header() - Parse a header from a gzip file |
| 12 | * |
| 13 | * This returns the length of the header. |
| 14 | * |
| 15 | * @src: Pointer to gzip file |
| 16 | * @len: Length of data |
| 17 | * @return length of header in bytes, or -1 if not enough data |
| 18 | */ |
| 19 | int gzip_parse_header(const unsigned char *src, unsigned long len); |
| 20 | |
| 21 | /** |
| 22 | * gunzip() - Decompress gzipped data |
| 23 | * |
| 24 | * @dst: Destination for uncompressed data |
| 25 | * @dstlen: Size of destination buffer |
| 26 | * @src: Source data to decompress |
| 27 | * @lenp: Returns length of uncompressed data |
| 28 | * @return 0 if OK, -1 on error |
| 29 | */ |
| 30 | int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp); |
| 31 | |
| 32 | /** |
| 33 | * zunzip() - Uncompress blocks compressed with zlib without headers |
| 34 | * |
| 35 | * @dst: Destination for uncompressed data |
| 36 | * @dstlen: Size of destination buffer |
| 37 | * @src: Source data to decompress |
| 38 | * @lenp: On entry, length data at @src. On exit, number of bytes used from @src |
| 39 | * @stoponerr: 0 to continue when a decode error is found, 1 to stop |
| 40 | * @offset: start offset within the src buffer |
| 41 | * @return 0 if OK, -1 on error |
| 42 | */ |
| 43 | int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, |
| 44 | int stoponerr, int offset); |
| 45 | |
| 46 | /** |
| 47 | * gzwrite progress indicators: defined weak to allow board-specific |
| 48 | * overrides: |
| 49 | * |
| 50 | * gzwrite_progress_init called on startup |
| 51 | * gzwrite_progress called during decompress/write loop |
| 52 | * gzwrite_progress_finish called at end of loop to |
| 53 | * indicate success (retcode=0) or failure |
| 54 | */ |
| 55 | void gzwrite_progress_init(u64 expected_size); |
| 56 | |
| 57 | void gzwrite_progress(int iteration, u64 bytes_written, u64 total_bytes); |
| 58 | |
| 59 | void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize, |
| 60 | u32 expected_crc, u32 calculated_crc); |
| 61 | |
| 62 | /** |
| 63 | * gzwrite() - decompress and write gzipped image from memory to block device |
| 64 | * |
| 65 | * @src: compressed image address |
| 66 | * @len: compressed image length in bytes |
| 67 | * @dev: block device descriptor |
| 68 | * @szwritebuf: bytes per write (pad to erase size) |
| 69 | * @startoffs: offset in bytes of first write |
| 70 | * @szexpected: expected uncompressed length, may be zero to use gzip trailer |
| 71 | * for files under 4GiB |
| 72 | * @return 0 if OK, -1 on error |
| 73 | */ |
| 74 | int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong szwritebuf, |
| 75 | u64 startoffs, u64 szexpected); |
| 76 | |
| 77 | /** |
| 78 | * gzip()- Compress data into a buffer using the gzip algorithm |
| 79 | * |
| 80 | * @dst: Destination buffer for compressed data |
| 81 | * @lenp: On entry, space available in destination buffer (in bytes). On exit, |
| 82 | * number of bytes used in the buffer |
| 83 | * @src: Source data to compress |
| 84 | * @srclen: Size of source data |
| 85 | * @return 0 if OK, -1 on error |
| 86 | */ |
| 87 | int gzip(void *dst, unsigned long *lenp, unsigned char *src, ulong srclen); |
| 88 | |
| 89 | /** |
| 90 | * zzip() - Compress blocks with zlib |
| 91 | * |
| 92 | * @dst: Destination for compressed data |
| 93 | * @lenp: On entry, length data at @dst. On exit, number of bytes written to |
| 94 | * @dst |
| 95 | * @src: Source data to compress |
| 96 | * @srclen: Size of source data |
| 97 | * @stoponerr: 0 to continue when a decode error is found, 1 to stop |
| 98 | * @func: Some sort of function that is called to do something. !ADD DOCS HERE! |
| 99 | */ |
| 100 | int zzip(void *dst, ulong *lenp, unsigned char *src, ulong srclen, |
| 101 | int stoponerr, int (*func)(ulong, ulong)); |
| 102 | |
| 103 | #endif |