1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-10-04 21:11:58 +03:00

[adm5120] update LZMA code

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@9756 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
juhosg 2007-12-14 20:35:22 +00:00
parent 8a1d2d9ac0
commit 6f5d61ecf3
5 changed files with 273 additions and 216 deletions

View File

@ -2,7 +2,7 @@
LzmaDecode.c LzmaDecode.c
LZMA Decoder (optimized for Speed version) LZMA Decoder (optimized for Speed version)
LZMA SDK 4.16 Copyright (c) 1999-2005 Igor Pavlov (2005-03-18) LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
http://www.7-zip.org/ http://www.7-zip.org/
LZMA SDK is licensed under two licenses: LZMA SDK is licensed under two licenses:
@ -21,10 +21,6 @@
#include "LzmaDecode.h" #include "LzmaDecode.h"
#ifndef Byte
#define Byte unsigned char
#endif
#define kNumTopBits 24 #define kNumTopBits 24
#define kTopValue ((UInt32)1 << kNumTopBits) #define kTopValue ((UInt32)1 << kNumTopBits)
@ -40,7 +36,7 @@
#ifdef _LZMA_IN_CB #ifdef _LZMA_IN_CB
#define RC_TEST { if (Buffer == BufferLim) \ #define RC_TEST { if (Buffer == BufferLim) \
{ UInt32 size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \ { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }} BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
#define RC_INIT Buffer = BufferLim = 0; RC_INIT2 #define RC_INIT Buffer = BufferLim = 0; RC_INIT2
@ -121,109 +117,86 @@
StopCompilingDueBUG StopCompilingDueBUG
#endif #endif
#ifdef _LZMA_OUT_READ int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
typedef struct _LzmaVarState
{ {
Byte *Buffer; unsigned char prop0;
Byte *BufferLim; if (size < LZMA_PROPERTIES_SIZE)
UInt32 Range; return LZMA_RESULT_DATA_ERROR;
UInt32 Code; prop0 = propsData[0];
#ifdef _LZMA_IN_CB if (prop0 >= (9 * 5 * 5))
ILzmaInCallback *InCallback; return LZMA_RESULT_DATA_ERROR;
#endif {
Byte *Dictionary; for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
UInt32 DictionarySize; for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
UInt32 DictionaryPos; propsRes->lc = prop0;
UInt32 GlobalPos; /*
UInt32 Reps[4]; unsigned char remainder = (unsigned char)(prop0 / 9);
int lc; propsRes->lc = prop0 % 9;
int lp; propsRes->pb = remainder / 5;
int pb; propsRes->lp = remainder % 5;
int State; */
int RemainLen; }
Byte TempDictionary[4];
} LzmaVarState;
int LzmaDecoderInit( #ifdef _LZMA_OUT_READ
unsigned char *buffer, UInt32 bufferSize, {
int lc, int lp, int pb, int i;
unsigned char *dictionary, UInt32 dictionarySize, propsRes->DictionarySize = 0;
#ifdef _LZMA_IN_CB for (i = 0; i < 4; i++)
ILzmaInCallback *InCallback propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
#else if (propsRes->DictionarySize == 0)
unsigned char *inStream, UInt32 inSize propsRes->DictionarySize = 1;
#endif }
)
{
Byte *Buffer;
Byte *BufferLim;
UInt32 Range;
UInt32 Code;
LzmaVarState *vs = (LzmaVarState *)buffer;
CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
UInt32 i;
if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
return LZMA_RESULT_NOT_ENOUGH_MEM;
vs->Dictionary = dictionary;
vs->DictionarySize = dictionarySize;
vs->DictionaryPos = 0;
vs->GlobalPos = 0;
vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
vs->lc = lc;
vs->lp = lp;
vs->pb = pb;
vs->State = 0;
vs->RemainLen = 0;
dictionary[dictionarySize - 1] = 0;
for (i = 0; i < numProbs; i++)
p[i] = kBitModelTotal >> 1;
#ifdef _LZMA_IN_CB
RC_INIT;
#else
RC_INIT(inStream, inSize);
#endif #endif
vs->Buffer = Buffer;
vs->BufferLim = BufferLim;
vs->Range = Range;
vs->Code = Code;
#ifdef _LZMA_IN_CB
vs->InCallback = InCallback;
#endif
return LZMA_RESULT_OK; return LZMA_RESULT_OK;
} }
int LzmaDecode(unsigned char *buffer, #define kLzmaStreamWasFinishedId (-1)
unsigned char *outStream, UInt32 outSize,
UInt32 *outSizeProcessed) int LzmaDecode(CLzmaDecoderState *vs,
#ifdef _LZMA_IN_CB
ILzmaInCallback *InCallback,
#else
const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
#endif
unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
{ {
LzmaVarState *vs = (LzmaVarState *)buffer; CProb *p = vs->Probs;
Byte *Buffer = vs->Buffer; SizeT nowPos = 0;
Byte *BufferLim = vs->BufferLim; Byte previousByte = 0;
UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
int lc = vs->Properties.lc;
#ifdef _LZMA_OUT_READ
UInt32 Range = vs->Range; UInt32 Range = vs->Range;
UInt32 Code = vs->Code; UInt32 Code = vs->Code;
#ifdef _LZMA_IN_CB #ifdef _LZMA_IN_CB
ILzmaInCallback *InCallback = vs->InCallback; const Byte *Buffer = vs->Buffer;
const Byte *BufferLim = vs->BufferLim;
#else
const Byte *Buffer = inStream;
const Byte *BufferLim = inStream + inSize;
#endif #endif
CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
int state = vs->State; int state = vs->State;
Byte previousByte;
UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
UInt32 nowPos = 0;
UInt32 posStateMask = (1 << (vs->pb)) - 1;
UInt32 literalPosMask = (1 << (vs->lp)) - 1;
int lc = vs->lc;
int len = vs->RemainLen; int len = vs->RemainLen;
UInt32 globalPos = vs->GlobalPos; UInt32 globalPos = vs->GlobalPos;
UInt32 distanceLimit = vs->DistanceLimit;
Byte *dictionary = vs->Dictionary; Byte *dictionary = vs->Dictionary;
UInt32 dictionarySize = vs->DictionarySize; UInt32 dictionarySize = vs->Properties.DictionarySize;
UInt32 dictionaryPos = vs->DictionaryPos; UInt32 dictionaryPos = vs->DictionaryPos;
Byte tempDictionary[4]; Byte tempDictionary[4];
#ifndef _LZMA_IN_CB
*inSizeProcessed = 0;
#endif
*outSizeProcessed = 0;
if (len == kLzmaStreamWasFinishedId)
return LZMA_RESULT_OK;
if (dictionarySize == 0) if (dictionarySize == 0)
{ {
dictionary = tempDictionary; dictionary = tempDictionary;
@ -231,12 +204,27 @@ int LzmaDecode(unsigned char *buffer,
tempDictionary[0] = vs->TempDictionary[0]; tempDictionary[0] = vs->TempDictionary[0];
} }
if (len == -1) if (len == kLzmaNeedInitId)
{ {
*outSizeProcessed = 0; {
return LZMA_RESULT_OK; UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
UInt32 i;
for (i = 0; i < numProbs; i++)
p[i] = kBitModelTotal >> 1;
rep0 = rep1 = rep2 = rep3 = 1;
state = 0;
globalPos = 0;
distanceLimit = 0;
dictionaryPos = 0;
dictionary[dictionarySize - 1] = 0;
#ifdef _LZMA_IN_CB
RC_INIT;
#else
RC_INIT(inStream, inSize);
#endif
}
len = 0;
} }
while(len != 0 && nowPos < outSize) while(len != 0 && nowPos < outSize)
{ {
UInt32 pos = dictionaryPos - rep0; UInt32 pos = dictionaryPos - rep0;
@ -251,50 +239,37 @@ int LzmaDecode(unsigned char *buffer,
previousByte = dictionary[dictionarySize - 1]; previousByte = dictionary[dictionarySize - 1];
else else
previousByte = dictionary[dictionaryPos - 1]; previousByte = dictionary[dictionaryPos - 1];
#else
int LzmaDecode( #else /* if !_LZMA_OUT_READ */
Byte *buffer, UInt32 bufferSize,
int lc, int lp, int pb,
#ifdef _LZMA_IN_CB
ILzmaInCallback *InCallback,
#else
unsigned char *inStream, UInt32 inSize,
#endif
unsigned char *outStream, UInt32 outSize,
UInt32 *outSizeProcessed)
{
UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
CProb *p = (CProb *)buffer;
UInt32 i;
int state = 0; int state = 0;
Byte previousByte = 0;
UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
UInt32 nowPos = 0;
UInt32 posStateMask = (1 << pb) - 1;
UInt32 literalPosMask = (1 << lp) - 1;
int len = 0; int len = 0;
const Byte *Buffer;
Byte *Buffer; const Byte *BufferLim;
Byte *BufferLim;
UInt32 Range; UInt32 Range;
UInt32 Code; UInt32 Code;
if (bufferSize < numProbs * sizeof(CProb))
return LZMA_RESULT_NOT_ENOUGH_MEM;
for (i = 0; i < numProbs; i++)
p[i] = kBitModelTotal >> 1;
#ifndef _LZMA_IN_CB
*inSizeProcessed = 0;
#endif
*outSizeProcessed = 0;
{
UInt32 i;
UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
for (i = 0; i < numProbs; i++)
p[i] = kBitModelTotal >> 1;
}
#ifdef _LZMA_IN_CB #ifdef _LZMA_IN_CB
RC_INIT; RC_INIT;
#else #else
RC_INIT(inStream, inSize); RC_INIT(inStream, inSize);
#endif #endif
#endif
*outSizeProcessed = 0; #endif /* _LZMA_OUT_READ */
while(nowPos < outSize) while(nowPos < outSize)
{ {
CProb *prob; CProb *prob;
@ -332,7 +307,6 @@ int LzmaDecode(
#else #else
matchByte = outStream[nowPos - rep0]; matchByte = outStream[nowPos - rep0];
#endif #endif
// prob += 0x100;
do do
{ {
int bit; int bit;
@ -343,7 +317,6 @@ int LzmaDecode(
RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break) RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
} }
while (symbol < 0x100); while (symbol < 0x100);
// prob -= 0x100;
} }
while (symbol < 0x100) while (symbol < 0x100)
{ {
@ -354,6 +327,9 @@ int LzmaDecode(
outStream[nowPos++] = previousByte; outStream[nowPos++] = previousByte;
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
if (distanceLimit < dictionarySize)
distanceLimit++;
dictionary[dictionaryPos] = previousByte; dictionary[dictionaryPos] = previousByte;
if (++dictionaryPos == dictionarySize) if (++dictionaryPos == dictionarySize)
dictionaryPos = 0; dictionaryPos = 0;
@ -364,7 +340,6 @@ int LzmaDecode(
} }
else else
{ {
// int isItRep;
UpdateBit1(prob); UpdateBit1(prob);
prob = p + IsRep + state; prob = p + IsRep + state;
IfBit0(prob) IfBit0(prob)
@ -390,12 +365,14 @@ int LzmaDecode(
UInt32 pos; UInt32 pos;
#endif #endif
UpdateBit0(prob); UpdateBit0(prob);
if (nowPos
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
+ globalPos if (distanceLimit == 0)
#endif #else
== 0) if (nowPos == 0)
#endif
return LZMA_RESULT_DATA_ERROR; return LZMA_RESULT_DATA_ERROR;
state = state < kNumLitStates ? 9 : 11; state = state < kNumLitStates ? 9 : 11;
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
pos = dictionaryPos - rep0; pos = dictionaryPos - rep0;
@ -409,6 +386,11 @@ int LzmaDecode(
previousByte = outStream[nowPos - rep0]; previousByte = outStream[nowPos - rep0];
#endif #endif
outStream[nowPos++] = previousByte; outStream[nowPos++] = previousByte;
#ifdef _LZMA_OUT_READ
if (distanceLimit < dictionarySize)
distanceLimit++;
#endif
continue; continue;
} }
else else
@ -535,18 +517,26 @@ int LzmaDecode(
if (++rep0 == (UInt32)(0)) if (++rep0 == (UInt32)(0))
{ {
/* it's for stream version */ /* it's for stream version */
len = -1; len = kLzmaStreamWasFinishedId;
break; break;
} }
} }
len += kMatchMinLen; len += kMatchMinLen;
if (rep0 > nowPos #ifdef _LZMA_OUT_READ
#ifdef _LZMA_OUT_READ if (rep0 > distanceLimit)
+ globalPos || rep0 > dictionarySize #else
#endif if (rep0 > nowPos)
) #endif
return LZMA_RESULT_DATA_ERROR; return LZMA_RESULT_DATA_ERROR;
#ifdef _LZMA_OUT_READ
if (dictionarySize - distanceLimit > (UInt32)len)
distanceLimit += len;
else
distanceLimit = dictionarySize;
#endif
do do
{ {
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
@ -569,12 +559,11 @@ int LzmaDecode(
RC_NORMALIZE; RC_NORMALIZE;
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
vs->Buffer = Buffer;
vs->BufferLim = BufferLim;
vs->Range = Range; vs->Range = Range;
vs->Code = Code; vs->Code = Code;
vs->DictionaryPos = dictionaryPos; vs->DictionaryPos = dictionaryPos;
vs->GlobalPos = globalPos + nowPos; vs->GlobalPos = globalPos + (UInt32)nowPos;
vs->DistanceLimit = distanceLimit;
vs->Reps[0] = rep0; vs->Reps[0] = rep0;
vs->Reps[1] = rep1; vs->Reps[1] = rep1;
vs->Reps[2] = rep2; vs->Reps[2] = rep2;
@ -584,6 +573,12 @@ int LzmaDecode(
vs->TempDictionary[0] = tempDictionary[0]; vs->TempDictionary[0] = tempDictionary[0];
#endif #endif
#ifdef _LZMA_IN_CB
vs->Buffer = Buffer;
vs->BufferLim = BufferLim;
#else
*inSizeProcessed = (SizeT)(Buffer - inStream);
#endif
*outSizeProcessed = nowPos; *outSizeProcessed = nowPos;
return LZMA_RESULT_OK; return LZMA_RESULT_OK;
} }

View File

@ -2,7 +2,7 @@
LzmaDecode.h LzmaDecode.h
LZMA Decoder interface LZMA Decoder interface
LZMA SDK 4.16 Copyright (c) 1999-2005 Igor Pavlov (2005-03-18) LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
http://www.7-zip.org/ http://www.7-zip.org/
LZMA SDK is licensed under two licenses: LZMA SDK is licensed under two licenses:
@ -22,6 +22,8 @@
#ifndef __LZMADECODE_H #ifndef __LZMADECODE_H
#define __LZMADECODE_H #define __LZMADECODE_H
#include "LzmaTypes.h"
/* #define _LZMA_IN_CB */ /* #define _LZMA_IN_CB */
/* Use callback for input data */ /* Use callback for input data */
@ -35,66 +37,77 @@
/* #define _LZMA_LOC_OPT */ /* #define _LZMA_LOC_OPT */
/* Enable local speed optimizations inside code */ /* Enable local speed optimizations inside code */
#ifndef UInt32
#ifdef _LZMA_UINT32_IS_ULONG
#define UInt32 unsigned long
#else
#define UInt32 unsigned int
#endif
#endif
#ifdef _LZMA_PROB32 #ifdef _LZMA_PROB32
#define CProb UInt32 #define CProb UInt32
#else #else
#define CProb unsigned short #define CProb UInt16
#endif #endif
#define LZMA_RESULT_OK 0 #define LZMA_RESULT_OK 0
#define LZMA_RESULT_DATA_ERROR 1 #define LZMA_RESULT_DATA_ERROR 1
#define LZMA_RESULT_NOT_ENOUGH_MEM 2
#ifdef _LZMA_IN_CB #ifdef _LZMA_IN_CB
typedef struct _ILzmaInCallback typedef struct _ILzmaInCallback
{ {
int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize); int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
} ILzmaInCallback; } ILzmaInCallback;
#endif #endif
#define LZMA_BASE_SIZE 1846 #define LZMA_BASE_SIZE 1846
#define LZMA_LIT_SIZE 768 #define LZMA_LIT_SIZE 768
/* #define LZMA_PROPERTIES_SIZE 5
bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
bufferSize += 100 in case of _LZMA_OUT_READ typedef struct _CLzmaProperties
by default CProb is unsigned short, {
but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int) int lc;
*/ int lp;
int pb;
#ifdef _LZMA_OUT_READ
UInt32 DictionarySize;
#endif
}CLzmaProperties;
int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
#define kLzmaNeedInitId (-2)
typedef struct _CLzmaDecoderState
{
CLzmaProperties Properties;
CProb *Probs;
#ifdef _LZMA_IN_CB
const unsigned char *Buffer;
const unsigned char *BufferLim;
#endif
#ifdef _LZMA_OUT_READ
unsigned char *Dictionary;
UInt32 Range;
UInt32 Code;
UInt32 DictionaryPos;
UInt32 GlobalPos;
UInt32 DistanceLimit;
UInt32 Reps[4];
int State;
int RemainLen;
unsigned char TempDictionary[4];
#endif
} CLzmaDecoderState;
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
int LzmaDecoderInit( #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
unsigned char *buffer, UInt32 bufferSize,
int lc, int lp, int pb,
unsigned char *dictionary, UInt32 dictionarySize,
#ifdef _LZMA_IN_CB
ILzmaInCallback *inCallback
#else
unsigned char *inStream, UInt32 inSize
#endif
);
#endif #endif
int LzmaDecode( int LzmaDecode(CLzmaDecoderState *vs,
unsigned char *buffer, #ifdef _LZMA_IN_CB
#ifndef _LZMA_OUT_READ
UInt32 bufferSize,
int lc, int lp, int pb,
#ifdef _LZMA_IN_CB
ILzmaInCallback *inCallback, ILzmaInCallback *inCallback,
#else #else
unsigned char *inStream, UInt32 inSize, const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
#endif #endif
#endif unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
unsigned char *outStream, UInt32 outSize,
UInt32 *outSizeProcessed);
#endif #endif

View File

@ -0,0 +1,45 @@
/*
LzmaTypes.h
Types for LZMA Decoder
This file written and distributed to public domain by Igor Pavlov.
This file is part of LZMA SDK 4.40 (2006-05-01)
*/
#ifndef __LZMATYPES_H
#define __LZMATYPES_H
#ifndef _7ZIP_BYTE_DEFINED
#define _7ZIP_BYTE_DEFINED
typedef unsigned char Byte;
#endif
#ifndef _7ZIP_UINT16_DEFINED
#define _7ZIP_UINT16_DEFINED
typedef unsigned short UInt16;
#endif
#ifndef _7ZIP_UINT32_DEFINED
#define _7ZIP_UINT32_DEFINED
#ifdef _LZMA_UINT32_IS_ULONG
typedef unsigned long UInt32;
#else
typedef unsigned int UInt32;
#endif
#endif
/* #define _LZMA_NO_SYSTEM_SIZE_T */
/* You can use it, if you don't want <stddef.h> */
#ifndef _7ZIP_SIZET_DEFINED
#define _7ZIP_SIZET_DEFINED
#ifdef _LZMA_NO_SYSTEM_SIZE_T
typedef UInt32 SizeT;
#else
#include <stddef.h>
typedef size_t SizeT;
#endif
#endif
#endif

View File

@ -40,7 +40,7 @@ CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
-ffunction-sections -pipe -mlong-calls -fno-common \ -ffunction-sections -pipe -mlong-calls -fno-common \
-ffreestanding \ -ffreestanding \
-mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap
CFLAGS += -DLOADADDR=$(LOADADDR) CFLAGS += -DLOADADDR=$(LOADADDR) -D_LZMA_PROB32
ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DLZMA_STARTUP_ORG=$(LZMA_STARTUP_ORG) ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DLZMA_STARTUP_ORG=$(LZMA_STARTUP_ORG)

View File

@ -118,12 +118,13 @@ struct env_var {
extern unsigned char workspace[]; extern unsigned char workspace[];
extern void board_init(void); extern void board_init(void);
static CLzmaDecoderState lzma_state;
typedef void (*kernel_entry)(unsigned long reg_a0, unsigned long reg_a1, typedef void (*kernel_entry)(unsigned long reg_a0, unsigned long reg_a1,
unsigned long reg_a2, unsigned long reg_a3); unsigned long reg_a2, unsigned long reg_a3);
static int decompress_data(unsigned char *buffer, UInt32 bufferSize, static int decompress_data(CLzmaDecoderState *vs, unsigned char *outStream,
int lc, int lp, int pb, unsigned char *outStream, UInt32 outSize, UInt32 outSize);
UInt32 *outSizeProcessed);
#ifdef CONFIG_PASS_KARGS #ifdef CONFIG_PASS_KARGS
#define ENVV(n,v) {.name = (n), .value = (v)} #define ENVV(n,v) {.name = (n), .value = (v)}
@ -139,7 +140,7 @@ static void halt(void)
for(;;); for(;;);
} }
#if LZMA_WRAPPER #if (LZMA_WRAPPER)
extern unsigned char _lzma_data_start[]; extern unsigned char _lzma_data_start[];
extern unsigned char _lzma_data_end[]; extern unsigned char _lzma_data_end[];
@ -158,12 +159,12 @@ static void decompress_init(void)
datalen = _lzma_data_end - _lzma_data_start; datalen = _lzma_data_end - _lzma_data_start;
} }
static int decompress_data(unsigned char *buffer, UInt32 bufferSize, static int decompress_data(CLzmaDecoderState *vs, unsigned char *outStream,
int lc, int lp, int pb, unsigned char *outStream, UInt32 outSize, SizeT outSize)
UInt32 *outSizeProcessed)
{ {
return LzmaDecode(buffer, bufferSize, lc, lp, pb, data, datalen, SizeT ip, op;
outStream, outSize, outSizeProcessed);
return LzmaDecode(vs, data, datalen, &ip, outStream, outSize, &op);
} }
#endif /* LZMA_WRAPPER */ #endif /* LZMA_WRAPPER */
@ -181,7 +182,8 @@ static __inline__ unsigned char get_byte(void)
return *(flash_base+flash_ofs++); return *(flash_base+flash_ofs++);
} }
static int lzma_read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize) static int lzma_read_byte(void *object, const unsigned char **buffer,
SizeT *bufferSize)
{ {
unsigned long len; unsigned long len;
@ -263,12 +265,17 @@ static void decompress_init(void)
flash_max = flash_ofs+klen; flash_max = flash_ofs+klen;
} }
static int decompress_data(unsigned char *buffer, UInt32 bufferSize, static int decompress_data(CLzmaDecoderState *vs, unsigned char *outStream,
int lc, int lp, int pb, unsigned char *outStream, UInt32 outSize, SizeT outSize)
UInt32 *outSizeProcessed)
{ {
return LzmaDecode(buffer, bufferSize, lc, lp, pb, &lzma_callback, SizeT op;
outStream, outSize, outSizeProcessed);
#if 0
vs->Buffer = data;
vs->BufferLim = datalen;
#endif
return LzmaDecode(vs, &lzma_callback, outStream, outSize, &op);
} }
#endif /* !(LZMA_WRAPPER) */ #endif /* !(LZMA_WRAPPER) */
@ -278,11 +285,9 @@ void decompress_entry(unsigned long reg_a0, unsigned long reg_a1,
unsigned long icache_size, unsigned long icache_lsize, unsigned long icache_size, unsigned long icache_lsize,
unsigned long dcache_size, unsigned long dcache_lsize) unsigned long dcache_size, unsigned long dcache_lsize)
{ {
unsigned char props[LZMA_PROPERTIES_SIZE];
unsigned int i; /* temp value */ unsigned int i; /* temp value */
unsigned int lc; /* literal context bits */ SizeT osize; /* uncompressed size */
unsigned int lp; /* literal pos state bits */
unsigned int pb; /* pos state bits */
unsigned int osize; /* uncompressed size */
int res; int res;
board_init(); board_init();
@ -293,29 +298,31 @@ void decompress_entry(unsigned long reg_a0, unsigned long reg_a1,
decompress_init(); decompress_init();
/* lzma args */ /* lzma args */
i = get_byte(); for (i = 0; i < LZMA_PROPERTIES_SIZE; i++)
lc = i % 9, i = i / 9; props[i] = get_byte();
lp = i % 5, pb = i / 5;
/* skip rest of the LZMA coder property */ /* skip rest of the LZMA coder property */
for (i = 0; i < 4; i++)
get_byte();
/* read the lower half of uncompressed size in the header */ /* read the lower half of uncompressed size in the header */
osize = ((unsigned int)get_byte()) + osize = ((SizeT)get_byte()) +
((unsigned int)get_byte() << 8) + ((SizeT)get_byte() << 8) +
((unsigned int)get_byte() << 16) + ((SizeT)get_byte() << 16) +
((unsigned int)get_byte() << 24); ((SizeT)get_byte() << 24);
/* skip rest of the header (upper half of uncompressed size) */ /* skip rest of the header (upper half of uncompressed size) */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
get_byte(); get_byte();
res = LzmaDecodeProperties(&lzma_state.Properties, props,
LZMA_PROPERTIES_SIZE);
if (res != LZMA_RESULT_OK) {
printf("Incorrect LZMA stream properties!\n");
halt();
}
printf("decompressing kernel... "); printf("decompressing kernel... ");
/* decompress kernel */ lzma_state.Probs = (CProb *)workspace;
res = decompress_data(workspace, ~0, lc, lp, pb, res = decompress_data(&lzma_state, (unsigned char *)LOADADDR, osize);
(unsigned char *)LOADADDR, osize, &i);
if (res != LZMA_RESULT_OK) { if (res != LZMA_RESULT_OK) {
printf("failed, "); printf("failed, ");
@ -323,9 +330,6 @@ void decompress_entry(unsigned long reg_a0, unsigned long reg_a1,
case LZMA_RESULT_DATA_ERROR: case LZMA_RESULT_DATA_ERROR:
printf("data error!\n"); printf("data error!\n");
break; break;
case LZMA_RESULT_NOT_ENOUGH_MEM:
printf("not enough memory!\n");
break;
default: default:
printf("unknown error %d!\n", res); printf("unknown error %d!\n", res);
} }