Index: /ar5315_microredboot/microredboot/CHANGELOG =================================================================== --- /ar5315_microredboot/microredboot/CHANGELOG (revision 12324) +++ /ar5315_microredboot/microredboot/CHANGELOG (revision 12325) @@ -1,4 +1,5 @@ 20.6.09 * AR5312/AR2313: fix nvram erase for nor flash devices (tested) + * make LzmaDecoder 2-3 times faster. this increases size, but we are still in 64 kb limit note: - finally the bootloader works now for ap51,ap65 and ap48 with all current planned features Index: /ar5315_microredboot/microredboot/boot/src/misc_lzma.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/misc_lzma.c (revision 12323) +++ /ar5315_microredboot/microredboot/boot/src/misc_lzma.c (revision 12325) @@ -43,7 +43,19 @@ static unsigned outcnt; /* bytes in output buffer */ -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) - -static int fill_inbuf(void); +static void fill_inbuf(void); + +static inline unsigned char get_byte(void) +{ + static unsigned int vall; + + if (((unsigned int)inptr % 4) == 0) { + vall = *(unsigned int *)inbuf; + inbuf += 4; + } + return *(((unsigned char *)&vall) + (inptr++ & 3)); +} + +//#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) + static void flush_window(void); static void error(char *m); @@ -63,5 +75,16 @@ #include "lib/LzmaDecode.h" -static int read_byte(unsigned char **buffer, UInt32 * bufferSize); +static unsigned int icnt = 0; +static inline int read_byte(unsigned char **buffer, UInt32 * bufferSize) +{ + static unsigned char val; + *bufferSize = 1; + val = get_byte(); + *buffer = &val; + if (icnt++ % (1024 * 10) == 0) + putc('.'); + return LZMA_RESULT_OK; +} + #include "lib/LzmaDecode.c" @@ -80,4 +103,6 @@ unsigned char *workspace; unsigned int lc, lp, pb; + if (inptr >= insize) + fill_inbuf(); // lzma args @@ -153,16 +178,4 @@ */ -static unsigned int icnt = 0; -static int read_byte(unsigned char **buffer, UInt32 * bufferSize) -{ - static unsigned char val; - *bufferSize = 1; - val = get_byte(); - *buffer = &val; - if (icnt++ % (1024 * 10) == 0) - putc('.'); - return LZMA_RESULT_OK; -} - struct fis_image_desc { unsigned char name[16]; // Null terminated name @@ -206,12 +219,12 @@ bootoffset = fis->entry_point; output_data = (uch *) fis->mem_base; -#ifdef AR5312 +//#ifdef AR5312 return fis->flash_base; -#else - memcpy((unsigned char *)ZCACHEADDR, - (unsigned char *)fis->flash_base, - 1 * 1024 * 1024); - return ZCACHEADDR; -#endif +//#else +// memcpy((unsigned char *)ZCACHEADDR, +// (unsigned char *)fis->flash_base, +// 1 * 1024 * 1024); +// return ZCACHEADDR; +//#endif } p += 256; @@ -231,5 +244,5 @@ static int resettrigger = 0; -static int fill_inbuf(void) +static void fill_inbuf(void) { if (insize != 0) @@ -238,11 +251,11 @@ inbuf = (uch *) linuxaddr; insize = 0x400000; - inptr = 1; + inptr = 0; } else { inbuf = input_data; insize = &input_data_end[0] - &input_data[0]; - inptr = 1; - } - return inbuf[0]; + inptr = 0; + } + return; } @@ -943,5 +956,8 @@ header->len, header); nvramdetect = (unsigned int)header; - memcpy(nvram_buf, header, NVRAM_SPACE); + unsigned int *src = header; + unsigned int *dst = nvram_buf; + for (i = 0; i < NVRAM_SPACE / 4; i++) + dst[i] = src[i]; return; } Index: /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c (revision 12320) +++ /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c (revision 12325) @@ -41,8 +41,7 @@ int Result; #endif - int ExtraBytes; } CRangeDecoder; -static Byte RangeDecoderReadByte(CRangeDecoder * rd) +static inline Byte RangeDecoderReadByte(CRangeDecoder * rd) { if (rd->Buffer == rd->BufferLim) { @@ -51,10 +50,5 @@ rd->Result = read_byte(&rd->Buffer, &size); rd->BufferLim = rd->Buffer + size; - if (size == 0) -#endif - { - rd->ExtraBytes = 1; - return 0xFF; - } +#endif } return (*rd->Buffer++); @@ -73,5 +67,4 @@ rd->BufferLim = stream + bufferSize; #endif - rd->ExtraBytes = 0; rd->Code = 0; rd->Range = (0xFFFFFFFF); @@ -84,5 +77,6 @@ #define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; } -static UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder * rd, int numTotalBits) +static inline UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder * rd, + int numTotalBits) { RC_INIT_VAR UInt32 result = 0; @@ -107,5 +101,5 @@ } -static int RangeDecoderBitDecode(CProb * prob, CRangeDecoder * rd) +static inline int RangeDecoderBitDecode(CProb * prob, CRangeDecoder * rd) { UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob; @@ -140,6 +134,6 @@ #define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;) -static int RangeDecoderBitTreeDecode(CProb * probs, int numLevels, - CRangeDecoder * rd) +static int inline RangeDecoderBitTreeDecode(CProb * probs, int numLevels, + CRangeDecoder * rd) { int mi = 1; @@ -162,6 +156,6 @@ } -static int RangeDecoderReverseBitTreeDecode(CProb * probs, int numLevels, - CRangeDecoder * rd) +static int inline RangeDecoderReverseBitTreeDecode(CProb * probs, int numLevels, + CRangeDecoder * rd) { int mi = 1; @@ -187,5 +181,5 @@ } -static Byte LzmaLiteralDecode(CProb * probs, CRangeDecoder * rd) +static Byte inline LzmaLiteralDecode(CProb * probs, CRangeDecoder * rd) { int symbol = 1; @@ -210,6 +204,6 @@ } -static Byte LzmaLiteralDecodeMatch(CProb * probs, CRangeDecoder * rd, - Byte matchByte) +static inline Byte LzmaLiteralDecodeMatch(CProb * probs, CRangeDecoder * rd, + Byte matchByte) { int symbol = 1; @@ -272,5 +266,5 @@ #define kNumLenProbs (LenHigh + kLenNumHighSymbols) -static int LzmaLenDecode(CProb * p, CRangeDecoder * rd, int posState) +static inline int LzmaLenDecode(CProb * p, CRangeDecoder * rd, int posState) { if (RangeDecoderBitDecode(p + LenChoice, rd) == 0) @@ -364,7 +358,7 @@ } -static int LzmaDecode(unsigned char *buffer, - unsigned char *outStream, UInt32 outSize, - UInt32 * outSizeProcessed) +int LzmaDecode(unsigned char *buffer, + unsigned char *outStream, UInt32 outSize, + UInt32 * outSizeProcessed) { LzmaVarState *vs = (LzmaVarState *) buffer; @@ -443,6 +437,4 @@ return rd.Result; #endif - if (rd.ExtraBytes != 0) - return LZMA_RESULT_DATA_ERROR; if (RangeDecoderBitDecode (p + IsMatch + (state << kNumPosBitsMax) + posState, Index: /ar5315_microredboot/microredboot/boot/src/Makefile =================================================================== --- /ar5315_microredboot/microredboot/boot/src/Makefile (revision 12321) +++ /ar5315_microredboot/microredboot/boot/src/Makefile (revision 12325) @@ -49,5 +49,5 @@ HEAD = head.o OBJS = misc_lzma.o lib/lib.o lib/print.o lib/printf.o -MEMCPY = memcpy.o memset.o +MEMCPY = memset.o # CFLAGS = $(CPPFLAGS) -O2 -DSTDC_HEADERS $(CFLAGS_BOOT) ZLDFLAGS = -G 0 -static -X -T ld.script