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