imx8m: config: convert to bootm_size
[platform/kernel/u-boot.git] / fs / squashfs / sqfs_decompressor.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020 Bootlin
4  *
5  * Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
6  */
7
8 #include <errno.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #if IS_ENABLED(CONFIG_ZLIB)
13 #include <u-boot/zlib.h>
14 #endif
15
16 #include "sqfs_decompressor.h"
17 #include "sqfs_filesystem.h"
18 #include "sqfs_utils.h"
19
20 #if IS_ENABLED(CONFIG_ZLIB)
21 static void zlib_decompression_status(int ret)
22 {
23         switch (ret) {
24         case Z_BUF_ERROR:
25                 printf("Error: 'dest' buffer is not large enough.\n");
26                 break;
27         case Z_DATA_ERROR:
28                 printf("Error: corrupted compressed data.\n");
29                 break;
30         case Z_MEM_ERROR:
31                 printf("Error: insufficient memory.\n");
32                 break;
33         }
34 }
35 #endif
36
37 int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
38                     void *source, u32 lenp)
39 {
40         int ret = 0;
41
42         switch (comp_type) {
43 #if IS_ENABLED(CONFIG_ZLIB)
44         case SQFS_COMP_ZLIB:
45                 ret = uncompress(dest, dest_len, source, lenp);
46                 if (ret) {
47                         zlib_decompression_status(ret);
48                         return -EINVAL;
49                 }
50
51                 break;
52 #endif
53         default:
54                 printf("Error: unknown compression type.\n");
55                 return -EINVAL;
56         }
57
58         return ret;
59 }