summaryrefslogtreecommitdiffstats
path: root/tools/mtd-utils/patches/101-ubifs-optional_lzo.patch
blob: d49c94bb2887a7938706e928ba69e2666d23b2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
diff --git a/mkfs.ubifs/Makefile b/mkfs.ubifs/Makefile
index a678b0a..919ce89 100644
--- a/mkfs.ubifs/Makefile
+++ b/mkfs.ubifs/Makefile
@@ -5,7 +5,7 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
 
 TARGETS = mkfs.ubifs
 
-LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L../ubi-utils/ -lubi
+LDLIBS_mkfs.ubifs = -lz $(if,$(NO_LZO),,-llzo2) -lm -luuid -L../ubi-utils/ -lubi
 
 include ../common.mk
 
diff --git a/mkfs.ubifs/compr.c b/mkfs.ubifs/compr.c
index e378c5d..0208f80 100644
--- a/mkfs.ubifs/compr.c
+++ b/mkfs.ubifs/compr.c
@@ -25,7 +25,9 @@
 #include <stdint.h>
 #include <string.h>
 #include <zlib.h>
+#if CONFIG_UBIFS_LZO
 #include <lzo/lzo1x.h>
+#endif
 #include <linux/types.h>
 
 #include "compr.h"
@@ -83,6 +85,17 @@ static int zlib_deflate(void *in_buf, size_t in_len, void *out_buf,
 	return 0;
 }
 
+static int no_compress(void *in_buf, size_t in_len, void *out_buf,
+		       size_t *out_len)
+{
+	memcpy(out_buf, in_buf, in_len);
+	*out_len = in_len;
+	return 0;
+}
+
+
+#if CONFIG_UBIFS_LZO
+
 static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
 			size_t *out_len)
 {
@@ -101,14 +114,16 @@ static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
 	return 0;
 }
 
-static int no_compress(void *in_buf, size_t in_len, void *out_buf,
-		       size_t *out_len)
+#else
+
+static int lzo_compress(void *in_buf, size_t in_len, void *out_buf,
+			size_t *out_len)
 {
-	memcpy(out_buf, in_buf, in_len);
-	*out_len = in_len;
-	return 0;
+	return -1;
 }
 
+#endif
+
 static char *zlib_buf;
 
 static int favor_lzo_compress(void *in_buf, size_t in_len, void *out_buf,
@@ -195,9 +210,11 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
 
 int init_compression(void)
 {
+#ifdef CONFIG_UBIFS_LZO
 	lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
 	if (!lzo_mem)
 		return -1;
+#endif
 
 	zlib_buf = malloc(UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR);
 	if (!zlib_buf) {
@@ -211,7 +228,9 @@ int init_compression(void)
 void destroy_compression(void)
 {
 	free(zlib_buf);
+#ifdef CONFIG_UBIFS_LZO
 	free(lzo_mem);
+#endif
 	if (errcnt)
 		fprintf(stderr, "%llu compression errors occurred\n", errcnt);
 }