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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
Add LZO support to mtd-utils to generate LZO compressed jffs2 images
Unlike the kernel version, the standard lzo userspace library is used
along with lzo1x_999_compress rather than the lzo1x_1_compress version
since better compression ratios can be obtained (at no significant cost
to decompression time).
Signed-off-by: Richard Purdie <rpurdie@openedhand.com>
---
Makefile | 3 -
compr.c | 6 ++
compr.h | 6 ++
compr_lzo.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/jffs2.h | 1
5 files changed, 135 insertions(+), 1 deletion(-)
Index: git/Makefile
===================================================================
--- git.orig/Makefile 2007-03-01 11:57:58.000000000 +0000
+++ git/Makefile 2007-03-01 11:58:01.000000000 +0000
@@ -58,8 +58,9 @@ $(BUILDDIR)/mkfs.jffs2: $(BUILDDIR)/crc3
$(BUILDDIR)/compr_rtime.o \
$(BUILDDIR)/mkfs.jffs2.o \
$(BUILDDIR)/compr_zlib.o \
+ $(BUILDDIR)/compr_lzo.o \
$(BUILDDIR)/compr.o
- $(CC) $(LDFLAGS) -o $@ $^ -lz
+ $(CC) $(LDFLAGS) -o $@ $^ -lz -llzo
$(BUILDDIR)/flash_eraseall: $(BUILDDIR)/crc32.o $(BUILDDIR)/flash_eraseall.o
$(CC) $(LDFLAGS) -o $@ $^
Index: git/compr.c
===================================================================
--- git.orig/compr.c 2007-03-01 11:57:58.000000000 +0000
+++ git/compr.c 2007-03-01 11:58:01.000000000 +0000
@@ -474,6 +474,9 @@ int jffs2_compressors_init(void)
#ifdef CONFIG_JFFS2_RTIME
jffs2_rtime_init();
#endif
+#ifdef CONFIG_JFFS2_LZO
+ jffs2_lzo_init();
+#endif
return 0;
}
@@ -485,5 +488,8 @@ int jffs2_compressors_exit(void)
#ifdef CONFIG_JFFS2_ZLIB
jffs2_zlib_exit();
#endif
+#ifdef CONFIG_JFFS2_LZO
+ jffs2_lzo_exit();
+#endif
return 0;
}
Index: git/compr.h
===================================================================
--- git.orig/compr.h 2007-03-01 11:57:58.000000000 +0000
+++ git/compr.h 2007-03-01 11:58:01.000000000 +0000
@@ -21,11 +21,13 @@
#define CONFIG_JFFS2_ZLIB
#define CONFIG_JFFS2_RTIME
+#define CONFIG_JFFS2_LZO
#define JFFS2_RUBINMIPS_PRIORITY 10
#define JFFS2_DYNRUBIN_PRIORITY 20
#define JFFS2_RTIME_PRIORITY 50
#define JFFS2_ZLIB_PRIORITY 60
+#define JFFS2_LZO_PRIORITY 80
#define JFFS2_COMPR_MODE_NONE 0
#define JFFS2_COMPR_MODE_PRIORITY 1
@@ -111,5 +113,9 @@ void jffs2_zlib_exit(void);
int jffs2_rtime_init(void);
void jffs2_rtime_exit(void);
#endif
+#ifdef CONFIG_JFFS2_LZO
+int jffs2_lzo_init(void);
+void jffs2_lzo_exit(void);
+#endif
#endif /* __JFFS2_COMPR_H__ */
Index: git/compr_lzo.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ git/compr_lzo.c 2007-03-01 11:58:01.000000000 +0000
@@ -0,0 +1,120 @@
+/*
+ * JFFS2 LZO Compression Interface.
+ *
+ * Copyright (C) 2007 Nokia Corporation. All rights reserved.
+ *
+ * Author: Richard Purdie <rpurdie@openedhand.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <asm/types.h>
+#include <linux/jffs2.h>
+#include <lzo1x.h>
+#include "compr.h"
+
+extern int page_size;
+
+static void *lzo_mem;
+static void *lzo_compress_buf;
+
+/*
+ * Note about LZO compression.
+ *
+ * We want to use the _999_ compression routine which gives better compression
+ * rates at the expense of time. Decompression time is unaffected. We might as
+ * well use the standard lzo library routines for this but they will overflow
+ * the destination buffer since they don't check the destination size.
+ *
+ * We therefore compress to a temporary buffer and copy if it will fit.
+ *
+ */
+static int jffs2_lzo_cmpr(unsigned char *data_in, unsigned char *cpage_out,
+ uint32_t *sourcelen, uint32_t *dstlen, void *model)
+{
+ uint32_t compress_size;
+ int ret;
+
+ ret = lzo1x_999_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem);
+
+ if (ret != LZO_E_OK)
+ return -1;
+
+ if (compress_size > *dstlen)
+ return -1;
+
+ memcpy(cpage_out, lzo_compress_buf, compress_size);
+ *dstlen = compress_size;
+
+ return 0;
+}
+
+static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out,
+ uint32_t srclen, uint32_t destlen, void *model)
+{
+ int ret;
+ uint32_t dl;
+
+ ret = lzo1x_decompress_safe(data_in,srclen,cpage_out,&dl,NULL);
+
+ if (ret != LZO_E_OK || dl != destlen)
+ return -1;
+
+ return 0;
+}
+
+static struct jffs2_compressor jffs2_lzo_comp = {
+ .priority = JFFS2_LZO_PRIORITY,
+ .name = "lzo",
+ .compr = JFFS2_COMPR_LZO,
+ .compress = &jffs2_lzo_cmpr,
+ .decompress = &jffs2_lzo_decompress,
+ .disabled = 0,
+};
+
+int jffs2_lzo_init(void)
+{
+ int ret;
+
+ lzo_mem = malloc(LZO1X_999_MEM_COMPRESS);
+ if (!lzo_mem)
+ return -1;
+
+ /* Worse case LZO compression size from their FAQ */
+ lzo_compress_buf = malloc(page_size + (page_size / 64) + 16 + 3);
+ if (!lzo_compress_buf) {
+ free(lzo_mem);
+ return -1;
+ }
+
+ ret = jffs2_register_compressor(&jffs2_lzo_comp);
+ if (ret < 0) {
+ free(lzo_compress_buf);
+ free(lzo_mem);
+ }
+
+ return ret;
+}
+
+void jffs2_lzo_exit(void)
+{
+ jffs2_unregister_compressor(&jffs2_lzo_comp);
+ free(lzo_compress_buf);
+ free(lzo_mem);
+}
Index: git/include/linux/jffs2.h
===================================================================
--- git.orig/include/linux/jffs2.h 2007-03-01 11:57:58.000000000 +0000
+++ git/include/linux/jffs2.h 2007-03-01 11:58:01.000000000 +0000
@@ -46,6 +46,7 @@
#define JFFS2_COMPR_COPY 0x04
#define JFFS2_COMPR_DYNRUBIN 0x05
#define JFFS2_COMPR_ZLIB 0x06
+#define JFFS2_COMPR_LZO 0x07
/* Compatibility flags. */
#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
#define JFFS2_NODE_ACCURATE 0x2000
|