]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - fs/jffs2/compr_rubin.c
Initial revision
[karo-tx-uboot.git] / fs / jffs2 / compr_rubin.c
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright (C) 2001 Red Hat, Inc.
5  *
6  * Created by Arjan van de Ven <arjanv@redhat.com>
7  *
8  * Heavily modified by Russ Dill <Russ.Dill@asu.edu> in an attempt at
9  * a little more speed.
10  *
11  * The original JFFS, from which the design for JFFS2 was derived,
12  * was designed and implemented by Axis Communications AB.
13  *
14  * The contents of this file are subject to the Red Hat eCos Public
15  * License Version 1.1 (the "Licence"); you may not use this file
16  * except in compliance with the Licence.  You may obtain a copy of
17  * the Licence at http://www.redhat.com/
18  *
19  * Software distributed under the Licence is distributed on an "AS IS"
20  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
21  * See the Licence for the specific language governing rights and
22  * limitations under the Licence.
23  *
24  * The Original Code is JFFS2 - Journalling Flash File System, version 2
25  *
26  * Alternatively, the contents of this file may be used under the
27  * terms of the GNU General Public License version 2 (the "GPL"), in
28  * which case the provisions of the GPL are applicable instead of the
29  * above.  If you wish to allow the use of your version of this file
30  * only under the terms of the GPL and not to allow others to use your
31  * version of this file under the RHEPL, indicate your decision by
32  * deleting the provisions above and replace them with the notice and
33  * other provisions required by the GPL.  If you do not delete the
34  * provisions above, a recipient may use your version of this file
35  * under either the RHEPL or the GPL.
36  *
37  * $Id: compr_rubin.c,v 1.2 2002/01/24 22:58:42 rfeany Exp $
38  *
39  */
40
41 #include <config.h>
42 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
43
44 #include <jffs2/jffs2.h>
45 #include <jffs2/compr_rubin.h>
46
47
48 void rubin_do_decompress(unsigned char *bits, unsigned char *in,
49                          unsigned char *page_out, __u32 destlen)
50 {
51         register char *curr = page_out;
52         char *end = page_out + destlen;
53         register unsigned long temp;
54         register unsigned long result;
55         register unsigned long p;
56         register unsigned long q;
57         register unsigned long rec_q;
58         register unsigned long bit;
59         register long i0;
60         unsigned long i;
61
62         /* init_pushpull */
63         temp = *(u32 *) in;
64         bit = 16;
65
66         /* init_rubin */
67         q = 0;
68         p = (long) (2 * UPPER_BIT_RUBIN);
69
70         /* init_decode */
71         rec_q = (in[0] << 8) | in[1];
72
73         while (curr < end) {
74                 /* in byte */
75
76                 result = 0;
77                 for (i = 0; i < 8; i++) {
78                         /* decode */
79
80                         while ((q & UPPER_BIT_RUBIN) || ((p + q) <= UPPER_BIT_RUBIN)) {
81                                 q &= ~UPPER_BIT_RUBIN;
82                                 q <<= 1;
83                                 p <<= 1;
84                                 rec_q &= ~UPPER_BIT_RUBIN;
85                                 rec_q <<= 1;
86                                 rec_q |= (temp >> (bit++ ^ 7)) & 1;
87                                 if (bit > 31) {
88                                         bit = 0;
89                                         temp = *(++((u32 *) in));
90                                 }
91                         }
92                         i0 =  (bits[i] * p) >> 8;
93
94                         if (i0 <= 0) i0 = 1;
95                         /* if it fails, it fails, we have our crc
96                         if (i0 >= p) i0 = p - 1; */
97
98                         result >>= 1;
99                         if (rec_q < q + i0) {
100                                 /* result |= 0x00; */
101                                 p = i0;
102                         } else {
103                                 result |= 0x80;
104                                 p -= i0;
105                                 q += i0;
106                         }
107                 }
108                 *(curr++) = result;
109         }
110 }
111
112 void dynrubin_decompress(unsigned char *data_in, unsigned char *cpage_out,
113                    unsigned long sourcelen, unsigned long dstlen)
114 {
115         unsigned char bits[8];
116         int c;
117
118         for (c=0; c<8; c++)
119                 bits[c] = (256 - data_in[c]);
120
121         rubin_do_decompress(bits, data_in+8, cpage_out, dstlen);
122 }
123
124 #endif /* CFG_CMD_JFFS2 */