xref: /OK3568_Linux_fs/u-boot/include/u-boot/lz4.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2019 Google LLC
4  */
5 
6 #ifndef __LZ4_H
7 #define __LZ4_H
8 
9 #define LZ4F_MAGIC 0x184D2204
10 
11 struct lz4_frame_header {
12 	u32 magic;
13 	union {
14 		u8 flags;
15 		struct {
16 			u8 reserved0:2;
17 			u8 has_content_checksum:1;
18 			u8 has_content_size:1;
19 			u8 has_block_checksum:1;
20 			u8 independent_blocks:1;
21 			u8 version:2;
22 		};
23 	};
24 	union {
25 		u8 block_descriptor;
26 		struct {
27 			u8 reserved1:4;
28 			u8 max_block_size:3;
29 			u8 reserved2:1;
30 		};
31 	};
32 	/* + u64 content_size iff has_content_size is set */
33 	/* + u8 header_checksum */
34 } __packed;
35 
36 struct lz4_block_header {
37 	union {
38 		u32 raw;
39 		struct {
40 			u32 size:31;
41 			u32 not_compressed:1;
42 		};
43 	};
44 	/* + size bytes of data */
45 	/* + u32 block_checksum iff has_block_checksum is set */
46 } __packed;
47 
48 bool lz4_is_valid_header(const unsigned char *h);
49 
50 /**
51  * ulz4fn() - Decompress LZ4 data
52  *
53  * @src: Source data to decompress
54  * @srcn: Length of source data
55  * @dst: Destination for uncompressed data
56  * @dstn: Returns length of uncompressed data
57  * @return 0 if OK, -EPROTONOSUPPORT if the magic number or version number are
58  *	not recognised or independent blocks are used, -EINVAL if the reserved
59  *	fields are non-zero, or input is overrun, -EENOBUFS if the destination
60  *	buffer is overrun, -EEPROTO if the compressed data causes an error in
61  *	the decompression algorithm
62  */
63 int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
64 
65 #endif
66