|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // base\omap_hrp\h4_bootloader\inflate2.h |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 |
|
21 #ifndef __INFLATE2_H__ |
|
22 #define __INFLATE2_H__ |
|
23 |
|
24 #define __CONFIGURABLE_F32_LOADER_INFLATE_WINDOW_SIZE__ 0x8000 |
|
25 |
|
26 // inflate |
|
27 const TInt KInflateWindowSize=__CONFIGURABLE_F32_LOADER_INFLATE_WINDOW_SIZE__ ; |
|
28 |
|
29 |
|
30 typedef struct |
|
31 { |
|
32 TUint iPhysicalSector; |
|
33 TUint iSemiPhysicalSector; |
|
34 } TNandReadInfo; |
|
35 |
|
36 //for asm mem copy |
|
37 //#define __JUMP(cc,r) asm("mov"#cc " pc, "#r ) |
|
38 //#define __POPRET(rlist) asm("ldmfd sp!, {"##rlist##"pc} ") |
|
39 |
|
40 void memcpy1(TAny*, const TAny*, TUint); |
|
41 void memset1(void *, int, unsigned); |
|
42 TInt memcmp1(const TUint8* aTrg, const TUint8* aSrc, TInt aLength); |
|
43 |
|
44 void leds(TUint32); |
|
45 extern "C" void memdump(TUint32* aAddr, TUint32* aEnd); |
|
46 |
|
47 #ifdef __cplusplus |
|
48 extern "C" { |
|
49 #endif |
|
50 extern void countout(void); |
|
51 extern void charout(TUint8 aChar); |
|
52 |
|
53 extern void WriteW(TUint32); |
|
54 extern void WriteB(TUint8); |
|
55 extern void mmuoff(void); |
|
56 #ifdef __cplusplus |
|
57 } |
|
58 #endif |
|
59 |
|
60 |
|
61 |
|
62 /** Bit input stream. Good for reading bit streams for packed, compressed or huffman |
|
63 data algorithms. |
|
64 */ |
|
65 class TBitInput |
|
66 { |
|
67 public: |
|
68 TBitInput(); |
|
69 TBitInput(const TUint8* aPtr, TInt aLength, TInt aOffset=0); |
|
70 void Set(const TUint8* aPtr, TInt aLength, TInt aOffset=0); |
|
71 // |
|
72 TUint ReadL(); |
|
73 TUint ReadL(TInt aSize); |
|
74 TUint HuffmanL(const TUint32* aTree); |
|
75 private: |
|
76 virtual void UnderflowL(); |
|
77 private: |
|
78 TInt iCount; |
|
79 TUint iBits; |
|
80 TInt iRemain; |
|
81 const TUint32* volatile iPtr; |
|
82 }; |
|
83 |
|
84 const TInt KHuffTerminate=0x0001; |
|
85 const TUint32 KBranch1=sizeof(TUint32)<<16; |
|
86 |
|
87 |
|
88 /** Huffman code toolkit. |
|
89 |
|
90 This class builds a huffman encoding from a frequency table and builds |
|
91 a decoding tree from a code-lengths table |
|
92 |
|
93 The encoding generated is based on the rule that given two symbols s1 and s2, with |
|
94 code length l1 and l2, and huffman codes h1 and h2: |
|
95 |
|
96 if l1<l2 then h1<h2 when compared lexicographically |
|
97 if l1==l2 and s1<s2 then h1<h2 ditto |
|
98 |
|
99 This allows the encoding to be stored compactly as a table of code lengths |
|
100 */ |
|
101 class Huffman |
|
102 { |
|
103 public: |
|
104 enum {KMaxCodeLength=27}; |
|
105 enum {KMetaCodes=KMaxCodeLength+1}; |
|
106 enum {KMaxCodes=0x8000}; |
|
107 public: |
|
108 static void Decoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aDecodeTree[],TInt aSymbolBase=0); |
|
109 static TBool IsValid(const TUint32 aHuffman[],TInt aNumCodes); |
|
110 // |
|
111 static void InternalizeL(TBitInput& aInput,TUint32 aHuffman[],TInt aNumCodes); |
|
112 }; |
|
113 |
|
114 |
|
115 // deflation constants |
|
116 const TInt KDeflateLengthMag=8; |
|
117 const TInt KDeflateDistanceMag=12; |
|
118 |
|
119 const TInt KDeflateMinLength=3; |
|
120 const TInt KDeflateMaxLength=KDeflateMinLength-1 + (1<<KDeflateLengthMag); |
|
121 const TInt KDeflateMaxDistance=(1<<KDeflateDistanceMag); |
|
122 const TInt KDeflateDistCodeBase=0x200; |
|
123 |
|
124 |
|
125 class TEncoding |
|
126 { |
|
127 public: |
|
128 enum {ELiterals=256,ELengths=(KDeflateLengthMag-1)*4,ESpecials=1,EDistances=(KDeflateDistanceMag-1)*4}; |
|
129 enum {ELitLens=ELiterals+ELengths+ESpecials}; |
|
130 enum {EEos=ELiterals+ELengths}; |
|
131 public: |
|
132 TUint32 iLitLen[ELitLens]; |
|
133 TUint32 iDistance[EDistances]; |
|
134 }; |
|
135 |
|
136 const TInt KDeflationCodes=TEncoding::ELitLens+TEncoding::EDistances; |
|
137 |
|
138 class Inflater |
|
139 { |
|
140 public: |
|
141 static TInt Inflate(TBitInput& aBits, TUint8* aBuffer, TInt aSize); |
|
142 private: |
|
143 static TInt Init(TBitInput& aBits, TEncoding& aEncoding); |
|
144 static TInt DoInflate(TBitInput& aBits, TEncoding& aEncoding, TUint8* aBuffer, TInt aSize); |
|
145 }; |
|
146 |
|
147 |
|
148 class TFileInput : public TBitInput |
|
149 { |
|
150 enum {KBufSize=KInflateWindowSize}; |
|
151 |
|
152 public: |
|
153 TFileInput(TInt aBlockLen, TInt aFileSize); |
|
154 void Init(void); |
|
155 |
|
156 private: |
|
157 void UnderflowL(); |
|
158 |
|
159 private: |
|
160 TUint8* iReadBuf; |
|
161 TPtr8 iPtr; |
|
162 TUint8 iBuf1[KBufSize]; |
|
163 TInt iState; |
|
164 TInt iBlockLen; |
|
165 TInt iFileSize; |
|
166 TInt iImageReadProgress; |
|
167 }; |
|
168 |
|
169 |
|
170 |
|
171 #endif |