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