Switched Zlib for Puff to reduce size to prepare for moving from gz to lzma...

Signed-off-by: Swizzy <swizzy@hotmail.co.uk>
This commit is contained in:
Swizzy 2013-08-16 07:37:23 +02:00
parent 1b970d9dcd
commit 48244cc86a
2 changed files with 59 additions and 57 deletions

View File

@ -17,7 +17,7 @@ include $(DEVKITXENON)/rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := stage2 TARGET := stage2
BUILD := build BUILD := build
SOURCES := source/lv2 source/lv2/tftp source/lv2/httpd source/lv2/linux source/lv2/kboot SOURCES := source/lv2 source/lv2/tftp source/lv2/httpd source/lv2/linux source/lv2/kboot source/lv1/puff
DATA := data DATA := data
INCLUDES := source/lv2 INCLUDES := source/lv2
@ -36,7 +36,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,--gc-sections -Wl,-Map,$(notdir $@).map
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project # any extra libraries we wish to link with the project
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -lxenon -lz -lfat -lext2fs -lntfs -lxtaf -lm LIBS := -lxenon -lfat -lext2fs -lntfs -lxtaf -lm
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing

View File

@ -9,7 +9,7 @@ used for zlib support ...
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <zlib.h> //#include <zlib.h>
#include <xetypes.h> #include <xetypes.h>
#include <elf/elf.h> #include <elf/elf.h>
#include <network/network.h> #include <network/network.h>
@ -24,6 +24,7 @@ used for zlib support ...
#include "file.h" #include "file.h"
#include "kboot/kbootconf.h" #include "kboot/kbootconf.h"
#include "tftp/tftp.h" #include "tftp/tftp.h"
#include "../lv1/puff/puff.h"
#define CHUNK 16384 #define CHUNK 16384
@ -47,58 +48,58 @@ struct filenames filelist[] = {
//{NULL, NULL} //Dunno why this is here? :S //{NULL, NULL} //Dunno why this is here? :S
}; };
//Decompress a gzip file ... //Decompress a gzip file ...
int inflate_read(char *source,int len,char **dest,int * destsize, int gzip) { //int inflate_read(char *source,int len,char **dest,int * destsize, int gzip) {
int ret; // int ret;
unsigned have; // unsigned have;
z_stream strm; // z_stream strm;
unsigned char out[CHUNK]; // unsigned char out[CHUNK];
int totalsize = 0; // int totalsize = 0;
//
/* allocate inflate state */ // /* allocate inflate state */
strm.zalloc = Z_NULL; // strm.zalloc = Z_NULL;
strm.zfree = Z_NULL; // strm.zfree = Z_NULL;
strm.opaque = Z_NULL; // strm.opaque = Z_NULL;
strm.avail_in = 0; // strm.avail_in = 0;
strm.next_in = Z_NULL; // strm.next_in = Z_NULL;
//
if(gzip) // if(gzip)
ret = inflateInit2(&strm, 16+MAX_WBITS); // ret = inflateInit2(&strm, 16+MAX_WBITS);
else // else
ret = inflateInit(&strm); // ret = inflateInit(&strm);
//
if (ret != Z_OK) // if (ret != Z_OK)
return ret; // return ret;
//
strm.avail_in = len; // strm.avail_in = len;
strm.next_in = (Bytef*)source; // strm.next_in = (Bytef*)source;
//
/* run inflate() on input until output buffer not full */ // /* run inflate() on input until output buffer not full */
do { // do {
strm.avail_out = CHUNK; // strm.avail_out = CHUNK;
strm.next_out = (Bytef*)out; // strm.next_out = (Bytef*)out;
ret = inflate(&strm, Z_NO_FLUSH); // ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */ // assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) { // switch (ret) {
case Z_NEED_DICT: // case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */ // ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR: // case Z_DATA_ERROR:
case Z_MEM_ERROR: // case Z_MEM_ERROR:
inflateEnd(&strm); // inflateEnd(&strm);
return ret; // return ret;
} // }
have = CHUNK - strm.avail_out; // have = CHUNK - strm.avail_out;
totalsize += have; // totalsize += have;
if (totalsize > ELF_MAXSIZE) // if (totalsize > ELF_MAXSIZE)
return Z_BUF_ERROR; // return Z_BUF_ERROR;
//*dest = (char*)realloc(*dest,totalsize); // //*dest = (char*)realloc(*dest,totalsize);
memcpy(*dest + totalsize - have,out,have); // memcpy(*dest + totalsize - have,out,have);
*destsize = totalsize; // *destsize = totalsize;
} while (strm.avail_out == 0); // } while (strm.avail_out == 0);
//
/* clean up and return */ // /* clean up and return */
(void)inflateEnd(&strm); // (void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; // return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
} //}
void wait_and_cleanup_line() void wait_and_cleanup_line()
{ {
@ -121,8 +122,9 @@ int launch_file(void * addr, unsigned len, int filetype){
//found a gzip file //found a gzip file
printf(" * Found a gzip file...\n"); printf(" * Found a gzip file...\n");
char * dest = malloc(ELF_MAXSIZE); char * dest = malloc(ELF_MAXSIZE);
int destsize = 0; long unsigned int destsize = 0;
if(inflate_read((char*)addr, len, &dest, &destsize, 1) == 0){ //if(inflate_read((char*)addr, len, &dest, &destsize, 1) == 0){
if (puff((unsigned char*)dest, &destsize, addr, (long unsigned int*)&len)==0){
//relocate elf ... //relocate elf ...
memcpy(addr,dest,destsize); memcpy(addr,dest,destsize);
printf(" * Successfully unpacked...\n"); printf(" * Successfully unpacked...\n");