diff --git a/.gitignore b/.gitignore index eca98a6..3f5e38b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ build/ firmware/ -mkespfsimage/*.o -mkespfsimage/mkespfsimage +espfs/mkespfsimage/*.o +espfs/mkespfsimage/mkespfsimage webpages.espfs -espfstest/*.o -espfstest/espfstest +espfs/espfstest/*.o +espfs/espfstest/espfstest *.DS_Store diff --git a/Makefile b/Makefile index ce2196b..e8e68d2 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ TARGET = httpd # which modules (subdirectories) of the project to include in compiling #MODULES = driver user lwip/api lwip/app lwip/core lwip/core/ipv4 lwip/netif -MODULES = driver user +MODULES = espfs user EXTRA_INCDIR = include \ . \ lib/heatshrink/ @@ -147,7 +147,7 @@ $(BUILD_DIR): flash: $(TARGET_OUT) $(FW_BASE) $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin -webpages.espfs: html/ html/wifi/ mkespfsimage/mkespfsimage +webpages.espfs: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage ifeq ($(GZIP_COMPRESSION),"yes") $(Q) rm -rf html_compressed; $(Q) cp -r html html_compressed; @@ -158,13 +158,13 @@ ifeq ($(COMPRESS_W_YUI),"yes") $(Q) awk "BEGIN {printf \"YUI compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" endif $(Q) cd html_compressed; find . -type f -regex ".*/.*\.\(html\|css\|js\)" -exec sh -c "gzip -n {}; mv {}.gz {}" \;; cd ..; - $(Q) cd html_compressed; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..; + $(Q) cd html_compressed; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..; $(Q) awk "BEGIN {printf \"GZIP compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" else - $(Q) cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. + $(Q) cd html; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. endif -mkespfsimage/mkespfsimage: mkespfsimage/ - make -C mkespfsimage +espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ + make -C espfs/mkespfsimage htmlflash: webpages.espfs $(Q) if [ $$(stat -c '%s' webpages.espfs) -gt $$(( 0x2E000 )) ]; then echo "webpages.espfs too big!"; false; fi diff --git a/user/espfs.c b/espfs/espfs.c similarity index 96% rename from user/espfs.c rename to espfs/espfs.c index 0789f35..0e5ef53 100644 --- a/user/espfs.c +++ b/espfs/espfs.c @@ -43,10 +43,11 @@ It's written for use with httpd, but doesn't need to be used as such. extern char* espFsData; #endif -#include "../mkespfsimage/espfsformat.h" +#include "espfsformat.h" #include "espfs.h" -#include "httpdconfig.h" -#ifdef EFS_HEATSHRINK + +#ifdef ESPFS_HEATSHRINK +#include "heatshrink_config_custom.h" #include "heatshrink_decoder.h" #endif @@ -83,6 +84,7 @@ a memory exception, crashing the program. //aligned 32-bit reads. Yes, it's no too optimized but it's short and sweet and it works. //ToDo: perhaps os_memcpy also does unaligned accesses? +#ifdef __ets__ void ICACHE_FLASH_ATTR memcpyAligned(char *dst, char *src, int len) { int x; int w, b; @@ -96,6 +98,9 @@ void ICACHE_FLASH_ATTR memcpyAligned(char *dst, char *src, int len) { dst++; src++; } } +#else +#define memcpyAligned memcpy +#endif //Open a file and return a pointer to the file desc struct. @@ -142,7 +147,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { r->posDecomp=0; if (h.compression==COMPRESS_NONE) { r->decompData=NULL; -#ifdef EFS_HEATSHRINK +#ifdef ESPFS_HEATSHRINK } else if (h.compression==COMPRESS_HEATSHRINK) { //File is compressed with Heatshrink. char parm; @@ -183,10 +188,10 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { fh->posComp+=len; // os_printf("Done reading %d bytes, pos=%x\n", len, fh->posComp); return len; -#ifdef EFS_HEATSHRINK +#ifdef ESPFS_HEATSHRINK } else if (fh->decompressor==COMPRESS_HEATSHRINK) { int decoded=0; - unsigned int elen, rlen; + size_t elen, rlen; char ebuff[16]; heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; // os_printf("Alloc %p\n", dec); @@ -218,7 +223,7 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { //Close the file. void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) { if (fh==NULL) return; -#ifdef EFS_HEATSHRINK +#ifdef ESPFS_HEATSHRINK if (fh->decompressor==COMPRESS_HEATSHRINK) { heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; heatshrink_decoder_free(dec); diff --git a/user/espfs.h b/espfs/espfs.h similarity index 50% rename from user/espfs.h rename to espfs/espfs.h index a6545e9..98e8aaa 100644 --- a/user/espfs.h +++ b/espfs/espfs.h @@ -1,6 +1,12 @@ #ifndef ESPFS_H #define ESPFS_H +//Define this if you want to be able to use Heatshrink-compressed espfs images. +#define ESPFS_HEATSHRINK + +//Pos of esp fs in flash +#define ESPFS_POS 0x12000 +#define ESPFS_SIZE 0x2E000 typedef struct EspFsFile EspFsFile; diff --git a/mkespfsimage/espfsformat.h b/espfs/espfsformat.h similarity index 100% rename from mkespfsimage/espfsformat.h rename to espfs/espfsformat.h diff --git a/espfs/espfstest/Makefile b/espfs/espfstest/Makefile new file mode 100644 index 0000000..5cf091e --- /dev/null +++ b/espfs/espfstest/Makefile @@ -0,0 +1,13 @@ +CFLAGS=-I../../lib/heatshrink -I.. -std=gnu99 + +espfstest: main.o espfs.o heatshrink_decoder.o + $(CC) -o $@ $^ + +espfs.o: ../espfs.c + $(CC) $(CFLAGS) -c $^ -o $@ + +heatshrink_decoder.o: ../heatshrink_decoder.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -f *.o espfstest diff --git a/espfstest/main.c b/espfs/espfstest/main.c similarity index 100% rename from espfstest/main.c rename to espfs/espfstest/main.c diff --git a/user/heatshrink_config_httpd.h b/espfs/heatshrink_config_custom.h similarity index 85% rename from user/heatshrink_config_httpd.h rename to espfs/heatshrink_config_custom.h index b487bdb..f885f87 100644 --- a/user/heatshrink_config_httpd.h +++ b/espfs/heatshrink_config_custom.h @@ -7,8 +7,13 @@ #if HEATSHRINK_DYNAMIC_ALLOC /* Optional replacement of malloc/free */ + #ifdef __ets__ #define HEATSHRINK_MALLOC(SZ) os_malloc(SZ) #define HEATSHRINK_FREE(P, SZ) os_free(P) + #else + #define HEATSHRINK_MALLOC(SZ) malloc(SZ) + #define HEATSHRINK_FREE(P, SZ) free(P) + #endif #else /* Required parameters for static configuration */ #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 @@ -23,4 +28,3 @@ #define HEATSHRINK_USE_INDEX 1 #endif - diff --git a/user/heatshrink_decoder.c b/espfs/heatshrink_decoder.c similarity index 76% rename from user/heatshrink_decoder.c rename to espfs/heatshrink_decoder.c index 6685652..87f042c 100644 --- a/user/heatshrink_decoder.c +++ b/espfs/heatshrink_decoder.c @@ -1,8 +1,10 @@ -#include "httpdconfig.h" -#ifdef EFS_HEATSHRINK +#include "espfs.h" +#ifdef ESPFS_HEATSHRINK //Stupid wrapper so we don't have to move c-files around //Also loads httpd-specific config. +#ifdef __ets__ +//esp build #define _STDLIB_H_ #define _STRING_H_ #define _STDDEF_H @@ -11,9 +13,13 @@ #include "c_types.h" #include "mem.h" #include "osapi.h" -#include "heatshrink_config_httpd.h" + #define memset(x,y,z) os_memset(x,y,z) #define memcpy(x,y,z) os_memcpy(x,y,z) +#endif + +#include "heatshrink_config_custom.h" #include "../lib/heatshrink/heatshrink_decoder.c" + #endif diff --git a/mkespfsimage/Makefile b/espfs/mkespfsimage/Makefile similarity index 58% rename from mkespfsimage/Makefile rename to espfs/mkespfsimage/Makefile index c1f71eb..542f5a6 100644 --- a/mkespfsimage/Makefile +++ b/espfs/mkespfsimage/Makefile @@ -1,5 +1,5 @@ -CFLAGS=-I../lib/heatshrink -std=gnu99 +CFLAGS=-I../../lib/heatshrink -I.. -std=gnu99 OBJS=main.o heatshrink_encoder.o TARGET=mkespfsimage diff --git a/mkespfsimage/heatshrink_encoder.c b/espfs/mkespfsimage/heatshrink_encoder.c similarity index 100% rename from mkespfsimage/heatshrink_encoder.c rename to espfs/mkespfsimage/heatshrink_encoder.c diff --git a/mkespfsimage/main.c b/espfs/mkespfsimage/main.c similarity index 100% rename from mkespfsimage/main.c rename to espfs/mkespfsimage/main.c diff --git a/espfstest/Makefile b/espfstest/Makefile deleted file mode 100644 index b5c8d32..0000000 --- a/espfstest/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CFLAGS=-I../lib/heatshrink -I../user -I../include -std=gnu99 - -espfstest: main.o espfs.o heatshrink_decoder.o - $(CC) -o $@ $^ - -espfs.o: espfs.c ../user/espfs.c - - -clean: - rm -f *.o espfstest diff --git a/espfstest/espfs.c b/espfstest/espfs.c deleted file mode 100644 index 2a10112..0000000 --- a/espfstest/espfs.c +++ /dev/null @@ -1,3 +0,0 @@ - -#include -#include "../user/espfs.c" diff --git a/espfstest/heatshrink_decoder.c b/espfstest/heatshrink_decoder.c deleted file mode 100644 index e1c6dbb..0000000 --- a/espfstest/heatshrink_decoder.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "httpdconfig.h" -#ifdef EFS_HEATSHRINK -//Stupid wrapper so we don't have to move c-files around -//Also loads httpd-specific config. - -#include "../lib/heatshrink/heatshrink_decoder.c" - -#endif diff --git a/include/httpdconfig.h b/include/httpdconfig.h deleted file mode 100644 index 193b12f..0000000 --- a/include/httpdconfig.h +++ /dev/null @@ -1,10 +0,0 @@ - -//Define this if you want to be able to use Heatshrink-compressed espfs images. -#define EFS_HEATSHRINK - -//Pos of esp fs in flash -#define ESPFS_POS 0x12000 -#define ESPFS_SIZE 0x2E000 - -//If you want, you can define a realm for the authentication system. -//#define HTTP_AUTH_REALM "MyRealm" \ No newline at end of file diff --git a/user/auth.h b/user/auth.h index 98809b8..3bf9e36 100644 --- a/user/auth.h +++ b/user/auth.h @@ -1,8 +1,6 @@ #ifndef AUTH_H #define AUTH_H -#include "httpdconfig.h" - #ifndef HTTP_AUTH_REALM #define HTTP_AUTH_REALM "Protected" #endif diff --git a/user/cgi.c b/user/cgi.c index d16a37e..1381105 100644 --- a/user/cgi.c +++ b/user/cgi.c @@ -22,7 +22,6 @@ flash as a binary. Also handles the hit counter on the main page. #include "io.h" #include #include "espmissingincludes.h" -#include "../include/httpdconfig.h" //cause I can't be bothered to write an ioGetLed() diff --git a/user/cgiflash.c b/user/cgiflash.c index 68fa141..63c21ce 100644 --- a/user/cgiflash.c +++ b/user/cgiflash.c @@ -21,7 +21,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati #include "io.h" #include #include "espmissingincludes.h" -#include "../include/httpdconfig.h" +#include "espfs.h" //Cgi that reads the SPI flash. Assumes 512KByte flash. diff --git a/user/httpd.c b/user/httpd.c index 46ccce5..3fe7df1 100644 --- a/user/httpd.c +++ b/user/httpd.c @@ -19,10 +19,7 @@ Esp8266 http server - core routines #include "mem.h" #include "osapi.h" -#include "espconn.h" #include "httpd.h" -#include "io.h" -#include "espfs.h" //Max length of request head diff --git a/user/httpdespfs.c b/user/httpdespfs.c index 3b6f002..e2328a7 100644 --- a/user/httpdespfs.c +++ b/user/httpdespfs.c @@ -19,8 +19,6 @@ Connector to let httpd use the espfs filesystem to serve the files in it. #include "espconn.h" #include "mem.h" -#include "httpd.h" -#include "espfs.h" #include "httpdespfs.h"