Fixing espfs upload capability
This commit is contained in:
+5
-10
@@ -2,7 +2,7 @@
|
||||
# Directory the Makefile is in. Please don't include other Makefiles before this.
|
||||
THISDIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
|
||||
#Include httpd config from lower level
|
||||
#Include httpd config from lower level, if it exists
|
||||
-include ../esphttpdconfig.mk
|
||||
|
||||
|
||||
@@ -29,11 +29,10 @@ SDK_BASE ?= /opt/Espressif/ESP8266_SDK
|
||||
LIB = libesphttpd.a
|
||||
|
||||
# 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 = espfs core util
|
||||
EXTRA_INCDIR = ./include \
|
||||
. \
|
||||
lib/heatshrink/
|
||||
. \
|
||||
lib/heatshrink/
|
||||
|
||||
|
||||
# compiler flags using during compilation of source files
|
||||
@@ -44,15 +43,13 @@ CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-
|
||||
# various paths from the SDK used in this project
|
||||
SDK_LIBDIR = lib
|
||||
SDK_LDDIR = ld
|
||||
SDK_INCDIR = include include/json
|
||||
SDK_INCDIR = include
|
||||
|
||||
# select which tools to use as compiler, librarian and linker
|
||||
CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
|
||||
AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
|
||||
LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
|
||||
OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
|
||||
|
||||
|
||||
OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
|
||||
|
||||
####
|
||||
#### no user configurable options below here
|
||||
@@ -117,7 +114,6 @@ ifeq ("$(COMPRESS_W_YUI)","yes")
|
||||
$(Q) for file in `find html_compressed -type f -name "*.js"`; do $(YUI-COMPRESSOR) --type js $$file -o $$file; done
|
||||
$(Q) for file in `find html_compressed -type f -name "*.css"`; do $(YUI-COMPRESSOR) --type css $$file -o $$file; done
|
||||
$(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}"
|
||||
|
||||
# mkespfsimage will compress html, css and js files with gzip by default if enabled
|
||||
# override with -g cmdline parameter
|
||||
$(Q) cd html_compressed; find | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd ..;
|
||||
@@ -135,7 +131,6 @@ libwebpages-espfs.a: webpages.espfs
|
||||
|
||||
espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
|
||||
$(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)"
|
||||
$(Q) $(AR) cru $@ $^
|
||||
|
||||
clean:
|
||||
$(Q) rm -f $(LIB)
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
|
||||
#include "httpd.h"
|
||||
|
||||
typedef struct {
|
||||
int espFsPos;
|
||||
int espFsSize;
|
||||
} CgiUploadEspfsParams;
|
||||
|
||||
|
||||
int cgiReadFlash(HttpdConnData *connData);
|
||||
int cgiUploadEspfs(HttpdConnData *connData);
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
|
||||
/*
|
||||
This is a 'captive portal' DNS server: it basically replies with a fixed IP for any and all DNS
|
||||
queries. This can be used to send mobile phones, tablets etc which connect to the ESP in
|
||||
AP mode directly to the internal webserver.
|
||||
This is a 'captive portal' DNS server: it basically replies with a fixed IP (in this case:
|
||||
the one of the SoftAP interface of this ESP module) for any and all DNS queries. This can
|
||||
be used to send mobile phones, tablets etc which connect to the ESP in AP mode directly to
|
||||
the internal webserver.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -42,15 +42,14 @@ int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) {
|
||||
|
||||
//Cgi that allows the ESPFS image to be replaced via http POST
|
||||
int ICACHE_FLASH_ATTR cgiUploadEspfs(HttpdConnData *connData) {
|
||||
//Now esphttpd is a lib and doesn't know ESPFS_POS/ESPFS_SIZE, this does not work anymore. ToDo: Find some way
|
||||
//to reinstate it?
|
||||
#if 0
|
||||
const CgiUploadEspfsParams *up=(CgiUploadEspfsParams*)connData->cgiArg;
|
||||
|
||||
if (connData->conn==NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
if(connData->post->len > ESPFS_SIZE){
|
||||
if(connData->post->len > up->espFsSize){
|
||||
// The uploaded file is too large
|
||||
os_printf("ESPFS file too large\n");
|
||||
httpdSend(connData, "HTTP/1.0 500 Internal Server Error\r\nServer: esp8266-httpd/0.3\r\nConnection: close\r\nContent-Type: text/plain\r\nContent-Length: 24\r\n\r\nESPFS image loo large.\r\n", -1);
|
||||
@@ -58,7 +57,7 @@ int ICACHE_FLASH_ATTR cgiUploadEspfs(HttpdConnData *connData) {
|
||||
}
|
||||
|
||||
// The source should be 4byte aligned, so go ahead and flash whatever we have
|
||||
int address = ESPFS_POS + connData->post->received - connData->post->buffLen;
|
||||
int address = up->espFsPos + connData->post->received - connData->post->buffLen;
|
||||
if(address % SPI_FLASH_SEC_SIZE == 0){
|
||||
// We need to erase this block
|
||||
os_printf("Erasing flash at %d\n", address/SPI_FLASH_SEC_SIZE);
|
||||
@@ -68,7 +67,6 @@ int ICACHE_FLASH_ATTR cgiUploadEspfs(HttpdConnData *connData) {
|
||||
os_printf("Writing at: 0x%x\n", address);
|
||||
spi_flash_write(address, (uint32 *)connData->post->buff, connData->post->buffLen);
|
||||
os_printf("Wrote %d bytes (%dB of %d)\n", connData->post->buffSize, connData->post->received, connData->post->len);//&connData->postBuff));
|
||||
#endif
|
||||
|
||||
if (connData->post->received == connData->post->len){
|
||||
httpdSend(connData, "Finished uploading", -1);
|
||||
|
||||
Reference in New Issue
Block a user