blob: 304002ffc42b6ae48d31b4d046045429c6bc2bc8 [file] [log] [blame]
Simon Glass1a974af2019-08-01 09:46:36 -06001/* 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 Rinidec7ea02024-05-20 13:35:03 -060010#include <linux/types.h>
11
Simon Glass655306c2020-05-10 11:39:58 -060012struct blk_desc;
13
Simon Glass1a974af2019-08-01 09:46:36 -060014/**
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 Schuchardt47b4c022022-01-19 18:05:50 +010021 * Return: length of header in bytes, or -1 if not enough data
Simon Glass1a974af2019-08-01 09:46:36 -060022 */
23int 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
Simon Glass3edebe42024-09-20 09:24:27 +020031 * @lenp: On entry, length of data at @src. On exit, number of bytes used from
32 * @src
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010033 * Return: 0 if OK, -1 on error
Simon Glass1a974af2019-08-01 09:46:36 -060034 */
35int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
36
37/**
38 * zunzip() - Uncompress blocks compressed with zlib without headers
39 *
40 * @dst: Destination for uncompressed data
41 * @dstlen: Size of destination buffer
42 * @src: Source data to decompress
Simon Glass3edebe42024-09-20 09:24:27 +020043 * @lenp: On entry, length of data at @src. On exit, number of bytes used from
44 * @src
Simon Glass1a974af2019-08-01 09:46:36 -060045 * @stoponerr: 0 to continue when a decode error is found, 1 to stop
46 * @offset: start offset within the src buffer
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010047 * Return: 0 if OK, -1 on error
Simon Glass1a974af2019-08-01 09:46:36 -060048 */
49int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
50 int stoponerr, int offset);
51
52/**
53 * gzwrite progress indicators: defined weak to allow board-specific
54 * overrides:
55 *
56 * gzwrite_progress_init called on startup
57 * gzwrite_progress called during decompress/write loop
58 * gzwrite_progress_finish called at end of loop to
59 * indicate success (retcode=0) or failure
60 */
Simon Glasse8c011d2021-09-25 07:03:13 -060061void gzwrite_progress_init(ulong expected_size);
Simon Glass1a974af2019-08-01 09:46:36 -060062
Simon Glasse8c011d2021-09-25 07:03:13 -060063void gzwrite_progress(int iteration, ulong bytes_written, ulong total_bytes);
Simon Glass1a974af2019-08-01 09:46:36 -060064
Simon Glasse8c011d2021-09-25 07:03:13 -060065void gzwrite_progress_finish(int retcode, ulong totalwritten, ulong totalsize,
Simon Glass1a974af2019-08-01 09:46:36 -060066 u32 expected_crc, u32 calculated_crc);
67
68/**
69 * gzwrite() - decompress and write gzipped image from memory to block device
70 *
71 * @src: compressed image address
72 * @len: compressed image length in bytes
73 * @dev: block device descriptor
74 * @szwritebuf: bytes per write (pad to erase size)
75 * @startoffs: offset in bytes of first write
76 * @szexpected: expected uncompressed length, may be zero to use gzip trailer
77 * for files under 4GiB
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010078 * Return: 0 if OK, -1 on error
Simon Glass1a974af2019-08-01 09:46:36 -060079 */
80int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong szwritebuf,
Simon Glasse8c011d2021-09-25 07:03:13 -060081 ulong startoffs, ulong szexpected);
Simon Glass1a974af2019-08-01 09:46:36 -060082
83/**
84 * gzip()- Compress data into a buffer using the gzip algorithm
85 *
86 * @dst: Destination buffer for compressed data
87 * @lenp: On entry, space available in destination buffer (in bytes). On exit,
88 * number of bytes used in the buffer
89 * @src: Source data to compress
90 * @srclen: Size of source data
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010091 * Return: 0 if OK, -1 on error
Simon Glass1a974af2019-08-01 09:46:36 -060092 */
93int gzip(void *dst, unsigned long *lenp, unsigned char *src, ulong srclen);
94
95/**
96 * zzip() - Compress blocks with zlib
97 *
98 * @dst: Destination for compressed data
99 * @lenp: On entry, length data at @dst. On exit, number of bytes written to
100 * @dst
101 * @src: Source data to compress
102 * @srclen: Size of source data
103 * @stoponerr: 0 to continue when a decode error is found, 1 to stop
104 * @func: Some sort of function that is called to do something. !ADD DOCS HERE!
105 */
106int zzip(void *dst, ulong *lenp, unsigned char *src, ulong srclen,
107 int stoponerr, int (*func)(ulong, ulong));
108
109#endif