@ -8,12 +8,15 @@
# include <sys/mman.h>
# include <sys/mman.h>
# include <arpa/inet.h>
# include <arpa/inet.h>
# include <string.h>
# include <string.h>
# include "espfs.h"
# include "espfsformat.h"
# include "espfsformat.h"
//Heatshrink
//Heatshrink
# ifdef ESPFS_HEATSHRINK
# include "heatshrink_common.h"
# include "heatshrink_common.h"
# include "heatshrink_config.h"
# include "heatshrink_config.h"
# include "heatshrink_encoder.h"
# include "heatshrink_encoder.h"
# endif
//Routines to convert host format to the endianness used in the xtensa
//Routines to convert host format to the endianness used in the xtensa
@ -33,6 +36,7 @@ int htoxl(int in) {
return * ( ( int * ) r ) ;
return * ( ( int * ) r ) ;
}
}
# ifdef ESPFS_HEATSHRINK
size_t compressHeatshrink ( char * in , int insize , char * out , int outsize , int level ) {
size_t compressHeatshrink ( char * in , int insize , char * out , int outsize , int level ) {
char * inp = in ;
char * inp = in ;
char * outp = out ;
char * outp = out ;
@ -77,6 +81,7 @@ size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int leve
heatshrink_encoder_free ( enc ) ;
heatshrink_encoder_free ( enc ) ;
return r ;
return r ;
}
}
# endif
int handleFile ( int f , char * name , int compression , int level ) {
int handleFile ( int f , char * name , int compression , int level ) {
char * fdat , * cdat ;
char * fdat , * cdat ;
@ -93,9 +98,11 @@ int handleFile(int f, char *name, int compression, int level) {
if ( compression = = COMPRESS_NONE ) {
if ( compression = = COMPRESS_NONE ) {
csize = size ;
csize = size ;
cdat = fdat ;
cdat = fdat ;
# ifdef ESPFS_HEATSHRINK
} else if ( compression = = COMPRESS_HEATSHRINK ) {
} else if ( compression = = COMPRESS_HEATSHRINK ) {
cdat = malloc ( size * 2 ) ;
cdat = malloc ( size * 2 ) ;
csize = compressHeatshrink ( fdat , size , cdat , size * 2 , level ) ;
csize = compressHeatshrink ( fdat , size , cdat , size * 2 , level ) ;
# endif
} else {
} else {
fprintf ( stderr , " Unknown compression - %d \n " , compression ) ;
fprintf ( stderr , " Unknown compression - %d \n " , compression ) ;
exit ( 1 ) ;
exit ( 1 ) ;
@ -151,15 +158,21 @@ int main(int argc, char **argv) {
int serr ;
int serr ;
int rate ;
int rate ;
int err = 0 ;
int err = 0 ;
int compType = 1 ; //default compression type - heatshrink
int compType ; //default compression type - heatshrink
int compLvl = - 1 ;
int compLvl = - 1 ;
# ifdef ESPFS_HEATSHRINK
compType = COMPRESS_HEATSHRINK ;
# else
compType = COMPRESS_NONE ;
# endif
for ( x = 1 ; x < argc ; x + + ) {
for ( x = 1 ; x < argc ; x + + ) {
if ( strcmp ( argv [ x ] , " -c " ) = = 0 & & argc > = x - 2 ) {
if ( strcmp ( argv [ x ] , " -c " ) = = 0 & & argc > = x - 2 ) {
compType = atoi ( argv [ x = 1 ] ) ;
compType = atoi ( argv [ x + 1 ] ) ;
x + + ;
x + + ;
} else if ( strcmp ( argv [ x ] , " -l " ) = = 0 & & argc > = x - 2 ) {
} else if ( strcmp ( argv [ x ] , " -l " ) = = 0 & & argc > = x - 2 ) {
compLvl = atoi ( argv [ x = 1 ] ) ;
compLvl = atoi ( argv [ x + 1 ] ) ;
if ( compLvl < 1 | | compLvl > 9 ) err = 1 ;
if ( compLvl < 1 | | compLvl > 9 ) err = 1 ;
x + + ;
x + + ;
} else {
} else {
@ -170,8 +183,13 @@ int main(int argc, char **argv) {
if ( err ) {
if ( err ) {
fprintf ( stderr , " %s - Program to create espfs images \n " , argv [ 0 ] ) ;
fprintf ( stderr , " %s - Program to create espfs images \n " , argv [ 0 ] ) ;
fprintf ( stderr , " Usage: \n find | %s [-c compressor] [-l compression_level] > out.espfs \n " , argv [ 0 ] ) ;
fprintf ( stderr , " Usage: \n find | %s [-c compressor] [-l compression_level] > out.espfs \n " , argv [ 0 ] ) ;
fprintf ( stderr , " Compressors: \n 0 - None \n 1 - Heatshrink(defautl \n " ) ;
fprintf ( stderr , " Compressors: \n " ) ;
fprintf ( stderr , " Compression level: 1 is worst but low RAM usage, higher is better compression \n but uses more ram on decompression. -1 = compressors default. \n " ) ;
# ifdef ESPFS_HEATSHRINK
fprintf ( stderr , " 0 - None \n 1 - Heatshrink(default) \n " ) ;
# else
fprintf ( stderr , " 0 - None(default) \n " ) ;
# endif
fprintf ( stderr , " \n Compression level: 1 is worst but low RAM usage, higher is better compression \n but uses more ram on decompression. -1 = compressors default. \n " ) ;
exit ( 0 ) ;
exit ( 0 ) ;
}
}