From f400fc2bb3d2c84ad52f986c2d906c2099551190 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Mon, 13 Oct 2014 11:47:44 +0200 Subject: [PATCH] Fixed various mkespfs bugs --- mkespfsimage/espfsformat.h | 2 +- mkespfsimage/main.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mkespfsimage/espfsformat.h b/mkespfsimage/espfsformat.h index 964d71c..d937f99 100644 --- a/mkespfsimage/espfsformat.h +++ b/mkespfsimage/espfsformat.h @@ -26,6 +26,6 @@ typedef struct { int16_t nameLen; int32_t fileLenComp; int32_t fileLenDecomp; -} EspFsHeader; +} __attribute__((packed)) EspFsHeader; #endif \ No newline at end of file diff --git a/mkespfsimage/main.c b/mkespfsimage/main.c index 63be2b2..b636ef4 100644 --- a/mkespfsimage/main.c +++ b/mkespfsimage/main.c @@ -37,11 +37,11 @@ size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int leve char *inp=in; char *outp=out; int len; - int ws[]={13, 11, 8, 6, 5}; - int ls[]={4, 4, 4, 3, 3}; + int ws[]={5, 6, 8, 11, 13}; + int ls[]={3, 3, 4, 4, 4}; HSE_poll_res pres; HSE_sink_res sres; - size_t r=0; + size_t r; if (level==-1) level=8; level=(level-1)/2; //level is now 0, 1, 2, 3, 4 heatshrink_encoder *enc=heatshrink_encoder_alloc(ws[level], ls[level]); @@ -49,6 +49,11 @@ size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int leve perror("allocating mem for heatshrink"); exit(1); } + //Save encoder parms as first byte + *outp=(ws[level]<<4)|ls[level]; + outp++; outsize--; + + r=1; do { if (insize>0) { sres=heatshrink_encoder_sink(enc, inp, insize, &len); @@ -98,6 +103,7 @@ int handleFile(int f, char *name, int compression, int level) { if (csize>size) { //Compressing enbiggened this file. Revert to uncompressed store. + compression=COMPRESS_NONE; csize=size; cdat=fdat; } @@ -116,9 +122,9 @@ int handleFile(int f, char *name, int compression, int level) { write(1, name, nameLen); //ToDo: this can eat up a few bytes after the buffer. write(1, cdat, csize); //Pad out to 32bit boundary - while (size&3) { + while (csize&3) { write(1, "\000", 1); - size++; + csize++; } munmap(fdat, size); return (csize*100)/size;