Fixing espfs upload capability

upstream
Jeroen Domburg 10 years ago
parent cc90701949
commit 98304bc9e5
  1. 16
      Makefile
  2. 15
      libesphttpd/Makefile
  3. 6
      libesphttpd/include/cgiflash.h
  4. 7
      libesphttpd/util/captdns.c
  5. 10
      libesphttpd/util/cgiflash.c
  6. 22
      user/user_main.c

@ -1,4 +1,8 @@
#Position and maximum length of espfs in flash memory. This can be undefined. In this case
#the webpages will be linked in into the executable file. If this is defined, please do a
#'make htmlflash' to flash the espfs into the ESPs memory.
ESPFS_POS = 0x12000
ESPFS_SIZE = 0x2E000
# Output directors to store intermediate compiled files
# relative to the project directory
@ -19,19 +23,11 @@ ESPPORT ?= /dev/ttyUSB0
ESPDELAY ?= 3
ESPBAUD ?= 460800
#Position and maximum length of espfs in flash memory
#This can be undefined. In this case the webpages will be linked in into the
#file.
#ESPFS_POS = 0x12000
#ESPFS_SIZE = 0x2E000
# name for the target project
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 = user
EXTRA_INCDIR = include libesphttpd/include
@ -104,7 +100,7 @@ ifeq ("$(ESPFS_POS)","")
#No hardcoded espfs position: link it in with the binaries.
LIBS += -lwebpages-espfs
else
#Pass espfs position to rest of code
#Hardcoded espfs location: Pass espfs position to rest of code
CFLAGS += -DESPFS_POS=$(ESPFS_POS) -DESPFS_SIZE=$(ESPFS_SIZE)
endif

@ -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);

@ -1,5 +1,3 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
@ -9,6 +7,11 @@
* ----------------------------------------------------------------------------
*/
/*
This is example code for the esphttpd library. It's a small-ish demo showing off
the server, including WiFi connection management capabilities, some IO and
some pictures of cats.
*/
#include <esp8266.h>
#include "httpd.h"
@ -27,7 +30,7 @@
//#define SHOW_HEAP_USE
//The example can act as a captive portal, that is, if someone connects their phone to the access
//point, it will automatically
//point, it will automatically load up the main page on most phones/tablets.
#define CAPTIVE_PORTAL
//Function that tells the authentication system what users/passwords live on the system.
@ -47,6 +50,12 @@ int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pas
return 0;
}
#ifdef ESPFS_POS
CgiUploadEspfsParams espfsParams={
.espFsPos=ESPFS_POS,
.espFsSize=ESPFS_SIZE
};
#endif
/*
This is the main url->function dispatching data struct.
@ -67,8 +76,9 @@ HttpdBuiltInUrl builtInUrls[]={
{"/led.tpl", cgiEspFsTemplate, tplLed},
{"/index.tpl", cgiEspFsTemplate, tplCounter},
{"/led.cgi", cgiLed, NULL},
{"/updateweb.cgi", cgiUploadEspfs, NULL},
#ifdef ESPFS_POS
{"/updateweb.cgi", cgiUploadEspfs, &espfsParams},
#endif
//Routines to make the /wifi URL and everything beneath it work.
//Enable the line below to protect the WiFi configuration with an username/password combo.
@ -99,11 +109,9 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) {
void user_init(void) {
stdoutInit();
ioInit();
#ifdef CAPTIVE_PORTAL
captdnsInit();
#endif
// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS

Loading…
Cancel
Save