pull/112/merge
twischer 9 years ago
commit 754f184cd8
  1. 88
      Makefile
  2. 0
      esp-link/cgiadv/cgioptiboot.c
  3. 0
      esp-link/cgiadv/cgioptiboot.h
  4. 0
      esp-link/cgiadv/cgipins.c
  5. 0
      esp-link/cgiadv/cgipins.h
  6. 23
      esp-link/cgiadv/cgiservices.c
  7. 3
      esp-link/cgiadv/cgiservices.h
  8. 0
      esp-link/cgiadv/cgitcp.c
  9. 0
      esp-link/cgiadv/cgitcp.h
  10. 0
      esp-link/cgiadv/stk500.h
  11. 42
      esp-link/cgiflash.c
  12. 2
      esp-link/cgiflash.h
  13. 8
      esp-link/cgimqtt.c
  14. 7
      esp-link/cgiwifi.c
  15. 0
      esp-link/log/log.c
  16. 0
      esp-link/log/log.h
  17. 64
      esp-link/main.c
  18. 8
      esp-link/stringdefs.c
  19. 2
      esp-link/stringdefs.h
  20. 15
      espfs/espfs.c
  21. 5
      espfs/espfs.h
  22. 9
      include/user_config.h
  23. 8
      serial/console/console.c
  24. 0
      serial/console/console.h
  25. 7
      serial/serbridge/serbridge.c
  26. 0
      serial/serbridge/serbridge.h
  27. 0
      serial/serbridge/slip.c
  28. 0
      serial/serbridge/slip.h
  29. 73
      wiflash

@ -56,7 +56,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute # Base directory of the ESP8266 SDK package, absolute
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5 # Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.1) SDK_BASE ?= $(abspath ../esp-open-sdk/sdk)
# Esptool.py path and port, only used for 1-time serial flashing # Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool # Typically you'll use https://github.com/themadinventor/esptool
@ -68,7 +68,7 @@ ESPBAUD ?= 460800
# --------------- chipset configuration --------------- # --------------- chipset configuration ---------------
# Pick your flash size: "512KB", "1MB", or "4MB" # Pick your flash size: "512KB", "1MB", or "4MB"
FLASH_SIZE ?= 4MB FLASH_SIZE ?= 512KB
# The pin assignments below are used when the settings in flash are invalid, they # The pin assignments below are used when the settings in flash are invalid, they
# can be changed via the web interface # can be changed via the web interface
@ -84,7 +84,7 @@ LED_SERIAL_PIN ?= 14
# --------------- esp-link modules config options --------------- # --------------- esp-link modules config options ---------------
# Optional Modules mqtt # Optional Modules mqtt
MODULES ?= mqtt rest syslog #MODULES ?= mqtt rest syslog cmd esp-link/cgiadv esp-link/log serial/console serial/serbridge
# --------------- esphttpd config options --------------- # --------------- esphttpd config options ---------------
@ -113,20 +113,27 @@ COMPRESS_W_HTMLCOMPRESSOR ?= yes
HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar
YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar
# use this option to place the ESP FS image in the other partition of the flash
# which is currently not booted.
USE_OTHER_PARTITION_FOR_ESPFS ?= yes
# -------------- End of config options ------------- # -------------- End of config options -------------
HTML_PATH = $(abspath ./html)/ HTML_PATH = $(abspath ./html)/
WIFI_PATH = $(HTML_PATH)wifi/ WIFI_PATH = $(HTML_PATH)wifi/
ESP_FLASH_MAX ?= 503808 # max bin file ET_PART1 ?= 0x01000
ifeq ("$(FLASH_SIZE)","512KB") ifeq ("$(FLASH_SIZE)","512KB")
# Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11 # Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11
ESP_SPI_SIZE ?= 0 # 0->512KB (256KB+256KB) ESP_SPI_SIZE ?= 0 # 0->512KB (256KB+256KB)
ESP_FLASH_MODE ?= 0 # 0->QIO ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
ESP_FLASH_MAX ?= 241664 # max bin file for 512KB flash: 236KB
ET_FS ?= 4m # 4Mbit flash size in esptool flash command ET_FS ?= 4m # 4Mbit flash size in esptool flash command
ET_FF ?= 40m # 40Mhz flash speed in esptool flash command ET_FF ?= 40m # 40Mhz flash speed in esptool flash command
ET_PART2 ?= 0x41000
ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings
else ifeq ("$(FLASH_SIZE)","1MB") else ifeq ("$(FLASH_SIZE)","1MB")
@ -134,8 +141,10 @@ else ifeq ("$(FLASH_SIZE)","1MB")
ESP_SPI_SIZE ?= 2 # 2->1MB (512KB+512KB) ESP_SPI_SIZE ?= 2 # 2->1MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO ESP_FLASH_MODE ?= 0 # 0->QIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80MHz ESP_FLASH_FREQ_DIV ?= 15 # 15->80MHz
ESP_FLASH_MAX ?= 503808 # max bin file for 1MB flash: 492KB
ET_FS ?= 8m # 8Mbit flash size in esptool flash command ET_FS ?= 8m # 8Mbit flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_PART2 ?= 0x81000
ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings
else ifeq ("$(FLASH_SIZE)","2MB") else ifeq ("$(FLASH_SIZE)","2MB")
@ -146,8 +155,10 @@ else ifeq ("$(FLASH_SIZE)","2MB")
ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
ESP_FLASH_MAX ?= 503808 # max bin file for 1MB flash: 492KB
ET_FS ?= 16m # 16Mbit flash size in esptool flash command ET_FS ?= 16m # 16Mbit flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_PART2 ?= 0x101000
ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings
else else
@ -158,6 +169,7 @@ else
ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB)
ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
ESP_FLASH_MAX ?= 503808 # max bin file for 1MB flash: 492KB
ET_FS ?= 32m # 32Mbit flash size in esptool flash command ET_FS ?= 32m # 32Mbit flash size in esptool flash command
ET_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings
@ -203,9 +215,29 @@ ifneq (,$(findstring syslog,$(MODULES)))
CFLAGS += -DSYSLOG CFLAGS += -DSYSLOG
endif endif
ifneq (,$(findstring cmd,$(MODULES)))
CFLAGS += -DCMD
endif
ifneq (,$(findstring esp-link/cgiadv,$(MODULES)))
CFLAGS += -DCGI_ADVANCED
endif
ifneq (,$(findstring esp-link/log,$(MODULES)))
CFLAGS += -DLOG
endif
ifneq (,$(findstring serial/console,$(MODULES)))
CFLAGS += -DCONSOLE
endif
ifneq (,$(findstring serial/serbridge,$(MODULES)))
CFLAGS += -DSERIAL_BRIDGE
endif
# which modules (subdirectories) of the project to include in compiling # which modules (subdirectories) of the project to include in compiling
LIBRARIES_DIR = libraries LIBRARIES_DIR = libraries
MODULES += espfs httpd user serial cmd esp-link MODULES += espfs httpd user serial esp-link
MODULES += $(foreach sdir,$(LIBRARIES_DIR),$(wildcard $(sdir)/*)) MODULES += $(foreach sdir,$(LIBRARIES_DIR),$(wildcard $(sdir)/*))
EXTRA_INCDIR = include . EXTRA_INCDIR = include .
@ -253,7 +285,11 @@ SDK_TOOLS := $(addprefix $(SDK_BASE)/,$(SDK_TOOLSDIR))
APPGEN_TOOL := $(addprefix $(SDK_TOOLS)/,$(APPGEN_TOOL)) APPGEN_TOOL := $(addprefix $(SDK_TOOLS)/,$(APPGEN_TOOL))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) $(BUILD_BASE)/espfs_img.o OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
ifneq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes")
OBJ += $(BUILD_BASE)/espfs_img.o
endif
LIBS := $(addprefix -l,$(LIBS)) LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
USER1_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).user1.out) USER1_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).user1.out)
@ -312,6 +348,10 @@ ifeq ("$(CHANGE_TO_STA)","yes")
CFLAGS += -DCHANGE_TO_STA CFLAGS += -DCHANGE_TO_STA
endif endif
ifeq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes")
CFLAGS += -DUSE_OTHER_PARTITION_FOR_ESPFS
endif
vpath %.c $(SRC_DIR) vpath %.c $(SRC_DIR)
define compile-objects define compile-objects
@ -322,7 +362,7 @@ endef
.PHONY: all checkdirs clean webpages.espfs wiflash .PHONY: all checkdirs clean webpages.espfs wiflash
all: echo_version checkdirs $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin all: echo_version checkdirs $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(BUILD_BASE)/espfs_img.o
echo_version: echo_version:
@echo VERSION: $(VERSION) @echo VERSION: $(VERSION)
@ -374,16 +414,33 @@ checkdirs: $(BUILD_DIR)
$(BUILD_DIR): $(BUILD_DIR):
$(Q) mkdir -p $@ $(Q) mkdir -p $@
ifeq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes")
wiflash: all
./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin build/espfs.img
else
wiflash: all wiflash: all
./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin ./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
endif
baseflash: all baseflash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x01000 $(FW_BASE)/user1.bin $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(ET_PART1) $(FW_BASE)/user1.bin
ifeq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes")
flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" \
$(ET_PART1) $(FW_BASE)/user1.bin \
$(ET_PART2) build/espfs.img \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin
else
flash: all flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \ $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x01000 $(FW_BASE)/user1.bin \ 0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" \
$(ET_PART1) $(FW_BASE)/user1.bin \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin $(ET_BLANK) $(SDK_BASE)/bin/blank.bin
endif
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
tools/$(HTML_COMPRESSOR): tools/$(HTML_COMPRESSOR):
@ -447,6 +504,18 @@ endif
# edit the loader script to add the espfs section to the end of irom with a 4 byte alignment. # edit the loader script to add the espfs section to the end of irom with a 4 byte alignment.
# we also adjust the sizes of the segments 'cause we need more irom0 # we also adjust the sizes of the segments 'cause we need more irom0
# in the end the only thing that matters wrt size is that the whole shebang fits into the
# 236KB available (in a 512KB flash)
ifeq ("$(FLASH_SIZE)","512KB")
build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.512.app1.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/2B000/38000/' \
$(SDK_LDDIR)/eagle.app.v6.new.512.app1.ld >$@
build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/2B000/38000/' \
$(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld >$@
else
build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app1.ld build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app1.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \ $(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/6B000/7C000/' \ -e '/^ irom0_0_seg/ s/6B000/7C000/' \
@ -455,6 +524,7 @@ build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \ $(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/6B000/7C000/' \ -e '/^ irom0_0_seg/ s/6B000/7C000/' \
$(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld >$@ $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld >$@
endif
espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
$(Q) $(MAKE) -C espfs/mkespfsimage GZIP_COMPRESSION="$(GZIP_COMPRESSION)" $(Q) $(MAKE) -C espfs/mkespfsimage GZIP_COMPRESSION="$(GZIP_COMPRESSION)"

@ -2,9 +2,13 @@
#include "cgiwifi.h" #include "cgiwifi.h"
#include "cgi.h" #include "cgi.h"
#include "config.h" #include "config.h"
#include "syslog.h"
#include "sntp.h" #include "sntp.h"
#include "cgimqtt.h" #include "cgimqtt.h"
#include "stringdefs.h"
#ifdef SYSLOG
#include "syslog.h"
#endif
#ifdef CGISERVICES_DBG #ifdef CGISERVICES_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -12,15 +16,6 @@
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
char* rst_codes[7] = {
"normal", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", "external",
};
char* flash_maps[7] = {
"512KB:256/256", "256KB", "1MB:512/512", "2MB:512/512", "4MB:512/512",
"2MB:1024/1024", "4MB:1024/1024"
};
static ETSTimer reassTimer; static ETSTimer reassTimer;
// Cgi to update system info (name/description) // Cgi to update system info (name/description)
@ -138,6 +133,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
#ifdef SYSLOG
int8_t syslog = 0; int8_t syslog = 0;
syslog |= getStringArg(connData, "syslog_host", flashConfig.syslog_host, sizeof(flashConfig.syslog_host)); syslog |= getStringArg(connData, "syslog_host", flashConfig.syslog_host, sizeof(flashConfig.syslog_host));
@ -146,14 +142,15 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
if (syslog < 0) return HTTPD_CGI_DONE; if (syslog < 0) return HTTPD_CGI_DONE;
syslog |= getUInt8Arg(connData, "syslog_filter", &flashConfig.syslog_filter); syslog |= getUInt8Arg(connData, "syslog_filter", &flashConfig.syslog_filter);
if (syslog < 0) return HTTPD_CGI_DONE; if (syslog < 0) return HTTPD_CGI_DONE;
syslog |= getBoolArg(connData, "syslog_showtick", &flashConfig.syslog_showtick); syslog |= getBoolArg(connData, "syslog_showtick", (bool*)&flashConfig.syslog_showtick);
if (syslog < 0) return HTTPD_CGI_DONE; if (syslog < 0) return HTTPD_CGI_DONE;
syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate); syslog |= getBoolArg(connData, "syslog_showdate", (bool*)&flashConfig.syslog_showdate);
if (syslog < 0) return HTTPD_CGI_DONE; if (syslog < 0) return HTTPD_CGI_DONE;
if (syslog > 0) { if (syslog > 0) {
syslog_init(flashConfig.syslog_host); syslog_init(flashConfig.syslog_host);
} }
#endif
int8_t sntp = 0; int8_t sntp = 0;
sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset); sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset);
@ -166,7 +163,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
} }
int8_t mdns = 0; int8_t mdns = 0;
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); mdns |= getBoolArg(connData, "mdns_enable", (bool*)&flashConfig.mdns_enable);
if (mdns < 0) return HTTPD_CGI_DONE; if (mdns < 0) return HTTPD_CGI_DONE;
if (mdns > 0) { if (mdns > 0) {

@ -10,7 +10,4 @@ void cgiServicesSNTPInit();
int cgiServicesInfo(HttpdConnData *connData); int cgiServicesInfo(HttpdConnData *connData);
int cgiServicesSet(HttpdConnData *connData); int cgiServicesSet(HttpdConnData *connData);
extern char* rst_codes[7];
extern char* flash_maps[7];
#endif // CGISERVICES_H #endif // CGISERVICES_H

@ -18,6 +18,9 @@ Some flash handling cgi routines. Used for reading the existing flash and updati
#include <osapi.h> #include <osapi.h>
#include "cgi.h" #include "cgi.h"
#include "cgiflash.h" #include "cgiflash.h"
#include "espfs.h"
#define SPI_FLASH_MEM_EMU_START_ADDR 0x40200000
#ifdef CGIFLASH_DBG #ifdef CGIFLASH_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -42,11 +45,28 @@ static char* ICACHE_FLASH_ATTR check_header(void *buf) {
// check whether the flash map/size we have allows for OTA upgrade // check whether the flash map/size we have allows for OTA upgrade
static bool canOTA(void) { static bool canOTA(void) {
enum flash_size_map map = system_get_flash_size_map(); enum flash_size_map map = system_get_flash_size_map();
return map >= FLASH_SIZE_8M_MAP_512_512; return map >= FLASH_SIZE_4M_MAP_256_256;
} }
static char *flash_too_small = "Flash too small for OTA update"; static char *flash_too_small = "Flash too small for OTA update";
static int ICACHE_FLASH_ATTR getNextSPIFlashAddr(void) {
const uint8 id = system_upgrade_userbin_check();
const int address = id == 1 ? 4*1024 // either start after 4KB boot partition
: 4*1024 + FIRMWARE_SIZE + 16*1024 + 4*1024; // 4KB boot, fw1, 16KB user param, 4KB reserved
return address;
}
uint32* const ICACHE_FLASH_ATTR getNextFlashAddr(void) {
const uint32 addr = SPI_FLASH_MEM_EMU_START_ADDR + getNextSPIFlashAddr();
/* cast as a pointer, because it is the real address in this system,
* for accessing the SPI flash position through the mem emu
*/
return (uint32*)addr;
}
//===== Cgi to query which firmware needs to be uploaded next //===== Cgi to query which firmware needs to be uploaded next
int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
@ -95,7 +115,14 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) {
connData->post->len < 1024) err = "Invalid request"; connData->post->len < 1024) err = "Invalid request";
// check that data starts with an appropriate header // check that data starts with an appropriate header
if (err == NULL && offset == 0) err = check_header(connData->post->buff); if (err == NULL && offset == 0) {
err = check_header(connData->post->buff);
/* update anyway, if it is an ESP FS image */
if (err != NULL && espFsIsImage(connData->post->buff)) {
err = NULL;
}
}
// make sure we're buffering in 1024 byte chunks // make sure we're buffering in 1024 byte chunks
if (err == NULL && offset % 1024 != 0) { if (err == NULL && offset % 1024 != 0) {
@ -117,13 +144,12 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) {
} }
// let's see which partition we need to flash and what flash address that puts us at // let's see which partition we need to flash and what flash address that puts us at
uint8 id = system_upgrade_userbin_check(); int address = getNextSPIFlashAddr();
int address = id == 1 ? 4*1024 // either start after 4KB boot partition
: 4*1024 + FIRMWARE_SIZE + 16*1024 + 4*1024; // 4KB boot, fw1, 16KB user param, 4KB reserved
address += offset; address += offset;
// erase next flash block if necessary // erase next flash block if necessary
if (address % SPI_FLASH_SEC_SIZE == 0){ if (address % SPI_FLASH_SEC_SIZE == 0){
const uint8 id = system_upgrade_userbin_check();
DBG("Flashing 0x%05x (id=%d)\n", address, 2 - id); DBG("Flashing 0x%05x (id=%d)\n", address, 2 - id);
spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE); spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE);
} }
@ -155,9 +181,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) {
// sanity-check that the 'next' partition actually contains something that looks like // sanity-check that the 'next' partition actually contains something that looks like
// valid firmware // valid firmware
uint8 id = system_upgrade_userbin_check(); const int address = getNextSPIFlashAddr();
int address = id == 1 ? 4*1024 // either start after 4KB boot partition
: 4*1024 + FIRMWARE_SIZE + 16*1024 + 4*1024; // 4KB boot, fw1, 16KB user param, 4KB reserved
uint32 buf[8]; uint32 buf[8];
DBG("Checking %p\n", (void *)address); DBG("Checking %p\n", (void *)address);
spi_flash_read(address, buf, sizeof(buf)); spi_flash_read(address, buf, sizeof(buf));
@ -197,4 +221,4 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) {
os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL);
os_timer_arm(&flash_reboot_timer, 2000, 1); os_timer_arm(&flash_reboot_timer, 2000, 1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }

@ -3,6 +3,8 @@
#include "httpd.h" #include "httpd.h"
uint32* const getNextFlashAddr(void);
int cgiReadFlash(HttpdConnData *connData); int cgiReadFlash(HttpdConnData *connData);
int cgiGetFirmwareNext(HttpdConnData *connData); int cgiGetFirmwareNext(HttpdConnData *connData);
int cgiUploadFirmware(HttpdConnData *connData); int cgiUploadFirmware(HttpdConnData *connData);

@ -95,11 +95,11 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
if (mqtt_server < 0) return HTTPD_CGI_DONE; if (mqtt_server < 0) return HTTPD_CGI_DONE;
mqtt_server |= getBoolArg(connData, "mqtt-clean-session", mqtt_server |= getBoolArg(connData, "mqtt-clean-session",
&flashConfig.mqtt_clean_session); (bool*)&flashConfig.mqtt_clean_session);
if (mqtt_server < 0) return HTTPD_CGI_DONE; if (mqtt_server < 0) return HTTPD_CGI_DONE;
int8_t mqtt_en_chg = getBoolArg(connData, "mqtt-enable", int8_t mqtt_en_chg = getBoolArg(connData, "mqtt-enable",
&flashConfig.mqtt_enable); (bool*)&flashConfig.mqtt_enable);
char buff[16]; char buff[16];
@ -145,14 +145,14 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
// no action required if mqtt status settings change, they just get picked up at the // no action required if mqtt status settings change, they just get picked up at the
// next status tick // next status tick
if (getBoolArg(connData, "mqtt-status-enable", &flashConfig.mqtt_status_enable) < 0) if (getBoolArg(connData, "mqtt-status-enable", (bool*)&flashConfig.mqtt_status_enable) < 0)
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
if (getStringArg(connData, "mqtt-status-topic", if (getStringArg(connData, "mqtt-status-topic",
flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0) flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0)
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
// if SLIP-enable is toggled it gets picked-up immediately by the parser // if SLIP-enable is toggled it gets picked-up immediately by the parser
int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable); int slip_update = getBoolArg(connData, "slip-enable", (bool*)&flashConfig.slip_enable);
if (slip_update < 0) return HTTPD_CGI_DONE; if (slip_update < 0) return HTTPD_CGI_DONE;
if (slip_update > 0) if (slip_update > 0)
DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable); DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable);

@ -18,7 +18,10 @@ Cgi/template routines for the /wifi url.
#include "cgi.h" #include "cgi.h"
#include "status.h" #include "status.h"
#include "config.h" #include "config.h"
#ifdef LOG
#include "log.h" #include "log.h"
#endif
#ifdef CGIWIFI_DBG #ifdef CGIWIFI_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -317,7 +320,9 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif #endif
} }
#ifdef LOG
log_uart(false); log_uart(false);
#endif
// no more resetTimer at this point, gotta use physical reset to recover if in trouble // no more resetTimer at this point, gotta use physical reset to recover if in trouble
} else { } else {
// we don't have an IP address // we don't have an IP address
@ -326,7 +331,9 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
wifi_set_opmode(3); wifi_set_opmode(3);
wifi_softap_set_config(&apconf); wifi_softap_set_config(&apconf);
} }
#ifdef LOG
log_uart(true); log_uart(true);
#endif
DBG("Enabling/continuing uart log\n"); DBG("Enabling/continuing uart log\n");
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
} }

@ -14,23 +14,39 @@
#include "httpdespfs.h" #include "httpdespfs.h"
#include "cgi.h" #include "cgi.h"
#include "cgiwifi.h" #include "cgiwifi.h"
#include "cgipins.h"
#include "cgitcp.h"
#include "cgimqtt.h" #include "cgimqtt.h"
#include "cgiflash.h" #include "cgiflash.h"
#include "cgioptiboot.h"
#include "auth.h" #include "auth.h"
#include "espfs.h" #include "espfs.h"
#include "uart.h" #include "uart.h"
#include "serbridge.h"
#include "status.h" #include "status.h"
#include "serled.h" #include "serled.h"
#include "console.h"
#include "config.h" #include "config.h"
#include "log.h"
#include "gpio.h" #include "gpio.h"
#include "stringdefs.h"
#ifdef LOG
#include "log.h"
#endif
#ifdef SYSLOG
#include "syslog.h" #include "syslog.h"
#endif
#ifdef CONSOLE
#include "console.h"
#endif
#ifdef SERIAL_BRIDGE
#include "serbridge.h"
#endif
#ifdef CGI_ADVANCED
#include "cgiservices.h" #include "cgiservices.h"
#include "cgipins.h"
#include "cgitcp.h"
#include "cgioptiboot.h"
#endif
#define NOTICE(format, ...) do { \ #define NOTICE(format, ...) do { \
LOG_NOTICE(format, ## __VA_ARGS__ ); \ LOG_NOTICE(format, ## __VA_ARGS__ ); \
@ -53,15 +69,26 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/flash/next", cgiGetFirmwareNext, NULL }, { "/flash/next", cgiGetFirmwareNext, NULL },
{ "/flash/upload", cgiUploadFirmware, NULL }, { "/flash/upload", cgiUploadFirmware, NULL },
{ "/flash/reboot", cgiRebootFirmware, NULL }, { "/flash/reboot", cgiRebootFirmware, NULL },
{ "/log/reset", cgiReset, NULL },
#ifdef CGI_ADVANCED
{ "/pgm/sync", cgiOptibootSync, NULL }, { "/pgm/sync", cgiOptibootSync, NULL },
{ "/pgm/upload", cgiOptibootData, NULL }, { "/pgm/upload", cgiOptibootData, NULL },
{ "/pins", cgiPins, NULL },
{ "/system/info", cgiSystemInfo, NULL },
{ "/system/update", cgiSystemSet, NULL },
{ "/services/info", cgiServicesInfo, NULL },
{ "/services/update", cgiServicesSet, NULL },
#endif
#ifdef LOG
{ "/log/text", ajaxLog, NULL }, { "/log/text", ajaxLog, NULL },
{ "/log/dbg", ajaxLogDbg, NULL }, { "/log/dbg", ajaxLogDbg, NULL },
{ "/log/reset", cgiReset, NULL }, #endif
#ifdef CONSOLE
{ "/console/reset", ajaxConsoleReset, NULL }, { "/console/reset", ajaxConsoleReset, NULL },
{ "/console/baud", ajaxConsoleBaud, NULL }, { "/console/baud", ajaxConsoleBaud, NULL },
{ "/console/text", ajaxConsole, NULL }, { "/console/text", ajaxConsole, NULL },
{ "/console/send", ajaxConsoleSend, NULL }, { "/console/send", ajaxConsoleSend, NULL },
#endif
//Enable the line below to protect the WiFi configuration with an username/password combo. //Enable the line below to protect the WiFi configuration with an username/password combo.
// {"/wifi/*", authBasic, myPassFn}, // {"/wifi/*", authBasic, myPassFn},
{ "/wifi", cgiRedirect, "/wifi/wifi.html" }, { "/wifi", cgiRedirect, "/wifi/wifi.html" },
@ -74,11 +101,6 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/wifi/special", cgiWiFiSpecial, NULL }, { "/wifi/special", cgiWiFiSpecial, NULL },
{ "/wifi/apinfo", cgiApSettingsInfo, NULL }, { "/wifi/apinfo", cgiApSettingsInfo, NULL },
{ "/wifi/apchange", cgiApSettingsChange, NULL }, { "/wifi/apchange", cgiApSettingsChange, NULL },
{ "/system/info", cgiSystemInfo, NULL },
{ "/system/update", cgiSystemSet, NULL },
{ "/services/info", cgiServicesInfo, NULL },
{ "/services/update", cgiServicesSet, NULL },
{ "/pins", cgiPins, NULL },
#ifdef MQTT #ifdef MQTT
{ "/mqtt", cgiMqtt, NULL }, { "/mqtt", cgiMqtt, NULL },
#endif #endif
@ -118,7 +140,9 @@ void user_init(void) {
gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
// init UART // init UART
uart_init(flashConfig.baud_rate, 115200); uart_init(flashConfig.baud_rate, 115200);
#ifdef LOG
logInit(); // must come after init of uart logInit(); // must come after init of uart
#endif
// Say hello (leave some time to cause break in TX after boot loader's msg // Say hello (leave some time to cause break in TX after boot loader's msg
os_delay_us(10000L); os_delay_us(10000L);
os_printf("\n\n** %s\n", esp_link_version); os_printf("\n\n** %s\n", esp_link_version);
@ -128,15 +152,23 @@ void user_init(void) {
serledInit(); serledInit();
// Wifi // Wifi
wifiInit(); wifiInit();
// init the flash filesystem with the html stuff // init the flash filesystem with the html stuff
espFsInit(&_binary_espfs_img_start); #ifdef USE_OTHER_PARTITION_FOR_ESPFS
//EspFsInitResult res = espFsInit(&_binary_espfs_img_start); uint32* addr = getNextFlashAddr();
//os_printf("espFsInit %s\n", res?"ERR":"ok"); const EspFsInitResult res = espFsInit(addr);
#else
const EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
#endif
os_printf("espFsInit %s (%u)\n", res?"ERR":"ok", res);
// mount the http handlers // mount the http handlers
httpdInit(builtInUrls, 80); httpdInit(builtInUrls, 80);
#ifdef SERIAL_BRIDGE
// init the wifi-serial transparent bridge (port 23) // init the wifi-serial transparent bridge (port 23)
serbridgeInit(23, 2323); serbridgeInit(23, 2323);
uart_add_recv_cb(&serbridgeUartCb); uart_add_recv_cb(&serbridgeUartCb);
#endif
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer); os_timer_disarm(&prHeapTimer);
os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
@ -153,8 +185,10 @@ void user_init(void) {
fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
NOTICE("** esp-link ready"); NOTICE("** esp-link ready");
#ifdef CGI_ADVANCED
// Init SNTP service // Init SNTP service
cgiServicesSNTPInit(); cgiServicesSNTPInit();
#endif
#ifdef MQTT #ifdef MQTT
NOTICE("initializing MQTT"); NOTICE("initializing MQTT");
mqtt_client_init(); mqtt_client_init();

@ -0,0 +1,8 @@
const char* const rst_codes[7] = {
"normal", "wdt reset", "exception", "soft wdt", "restart", "deep sleep", "external",
};
const char* const flash_maps[7] = {
"512KB:256/256", "256KB", "1MB:512/512", "2MB:512/512", "4MB:512/512",
"2MB:1024/1024", "4MB:1024/1024"
};

@ -0,0 +1,2 @@
extern const char* const rst_codes[7];
extern const char* const flash_maps[7];

@ -67,6 +67,17 @@ Accessing the flash through the mem emulation at 0x40200000 is a bit hairy: All
a memory exception, crashing the program. a memory exception, crashing the program.
*/ */
bool ICACHE_FLASH_ATTR espFsIsImage(const void* const flashAddress) {
// check if there is valid header at address
EspFsHeader testHeader;
os_memcpy(&testHeader, flashAddress, sizeof(EspFsHeader));
#ifdef ESPFS_DBG
os_printf("ESP FS magic is 0x%08x, should 0x%08x, at %p\n", (uint32)testHeader.magic, ESPFS_MAGIC, flashAddress);
#endif
return (testHeader.magic == ESPFS_MAGIC);
}
EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) {
// base address must be aligned to 4 bytes // base address must be aligned to 4 bytes
if (((int)flashAddress & 3) != 0) { if (((int)flashAddress & 3) != 0) {
@ -74,9 +85,7 @@ EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) {
} }
// check if there is valid header at address // check if there is valid header at address
EspFsHeader testHeader; if ( !espFsIsImage(flashAddress) ) {
os_memcpy(&testHeader, flashAddress, sizeof(EspFsHeader));
if (testHeader.magic != ESPFS_MAGIC) {
return ESPFS_INIT_RESULT_NO_IMAGE; return ESPFS_INIT_RESULT_NO_IMAGE;
} }

@ -1,6 +1,8 @@
#ifndef ESPFS_H #ifndef ESPFS_H
#define ESPFS_H #define ESPFS_H
#include <stdbool.h>
typedef enum { typedef enum {
ESPFS_INIT_RESULT_OK, ESPFS_INIT_RESULT_OK,
ESPFS_INIT_RESULT_NO_IMAGE, ESPFS_INIT_RESULT_NO_IMAGE,
@ -9,6 +11,7 @@ typedef enum {
typedef struct EspFsFile EspFsFile; typedef struct EspFsFile EspFsFile;
bool espFsIsImage(const void* const flashAddress);
EspFsInitResult espFsInit(void *flashAddress); EspFsInitResult espFsInit(void *flashAddress);
EspFsFile *espFsOpen(char *fileName); EspFsFile *espFsOpen(char *fileName);
int espFsFlags(EspFsFile *fh); int espFsFlags(EspFsFile *fh);
@ -16,4 +19,4 @@ int espFsRead(EspFsFile *fh, char *buff, int len);
void espFsClose(EspFsFile *fh); void espFsClose(EspFsFile *fh);
#endif #endif

@ -37,6 +37,15 @@
// If defined, the default hostname for DHCP will include the chip ID to make it unique // If defined, the default hostname for DHCP will include the chip ID to make it unique
#undef CHIP_IN_HOSTNAME #undef CHIP_IN_HOSTNAME
#ifndef SYSLOG
#define LOG_DEBUG(format, ...) do { } while(0)
#define LOG_NOTICE(format, ...) do { } while(0)
#define LOG_WARN(format, ...) do { } while(0)
#define LOG_INFO(format, ...) do { } while(0)
#define LOG_ERR(format, ...) do { } while(0)
#endif
extern char* esp_link_version; extern char* esp_link_version;
extern uint8_t UTILS_StrToIP(const char* str, void *ip); extern uint8_t UTILS_StrToIP(const char* str, void *ip);

@ -4,10 +4,14 @@
#include "uart.h" #include "uart.h"
#include "cgi.h" #include "cgi.h"
#include "uart.h" #include "uart.h"
#include "serbridge.h"
#include "config.h" #include "config.h"
#include "console.h" #include "console.h"
#ifdef SERIAL_BRIDGE
#include "serbridge.h"
#endif
// Microcontroller console capturing the last 1024 characters received on the uart so // Microcontroller console capturing the last 1024 characters received on the uart so
// they can be shown on a web page // they can be shown on a web page
@ -54,7 +58,9 @@ ajaxConsoleReset(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
jsonHeader(connData, 200); jsonHeader(connData, 200);
console_rd = console_wr = console_pos = 0; console_rd = console_wr = console_pos = 0;
#ifdef SERIAL_BRIDGE
serbridgeReset(); serbridgeReset();
#endif
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }

@ -10,7 +10,10 @@
#include "console.h" #include "console.h"
#include "slip.h" #include "slip.h"
#include "cmd.h" #include "cmd.h"
#ifdef SYSLOG
#include "syslog.h" #include "syslog.h"
#endif
#define SKIP_AT_RESET #define SKIP_AT_RESET
@ -405,12 +408,16 @@ serbridgeConnectCb(void *arg)
#ifdef SERBR_DBG #ifdef SERBR_DBG
os_printf("Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i); os_printf("Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i);
#endif #endif
#ifdef SYSLOG
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "esp-link", "Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i); syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "esp-link", "Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i);
#endif
if (i==MAX_CONN) { if (i==MAX_CONN) {
#ifdef SERBR_DBG #ifdef SERBR_DBG
os_printf("Aiee, conn pool overflow!\n"); os_printf("Aiee, conn pool overflow!\n");
#endif #endif
#ifdef SYSLOG
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_WARNING, "esp-link", "Aiee, conn pool overflow!\n"); syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_WARNING, "esp-link", "Aiee, conn pool overflow!\n");
#endif
espconn_disconnect(conn); espconn_disconnect(conn);
return; return;
} }

@ -13,7 +13,7 @@
show_help() { show_help() {
cat <<EOT cat <<EOT
Usage: ${0##*/} [-options...] hostname user1.bin user2.bin Usage: ${0##*/} [-options...] hostname user1.bin user2.bin [espfs.img]
Flash the esp8266 running esphttpd at <hostname> with either <user1.bin> or <user2.bin> Flash the esp8266 running esphttpd at <hostname> with either <user1.bin> or <user2.bin>
depending on its current state. Reboot the esp8266 after flashing and wait for it to come depending on its current state. Reboot the esp8266 after flashing and wait for it to come
up again. up again.
@ -25,6 +25,30 @@ Example: ${0##*/} -v esp8266 firmware/user1.bin firmware/user2.bin
EOT EOT
} }
check_response() {
sleep 2
echo "Waiting for ESP8266 to come back"
while true; do
[[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2
next2=`curl -m 10 $v -s "http://$hostname/flash/next"`
[[ -n "$verbose" ]] && echo "got: $next2"
re='user[12]\.bin'
if [[ "$next2" =~ $re ]]; then
if [[ "$next2" != "$next" ]]; then
sec=$(( `date +%s` - $start ))
echo "Success, took $sec seconds" >&2
break
else
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2
exit 1
fi
fi
sleep 1
done
}
if ! which curl >/dev/null; then if ! which curl >/dev/null; then
echo "ERROR: Cannot find curl: it is required for this script." >&2 echo "ERROR: Cannot find curl: it is required for this script." >&2
exit 1 exit 1
@ -49,13 +73,15 @@ done
shift "$((OPTIND-1))" shift "$((OPTIND-1))"
# Get the fixed arguments # Get the fixed arguments
if [[ $# != 3 ]]; then # only 3 or 4 are accepted
if [[ $# < 3 || $# > 4 ]]; then
show_help >&2 show_help >&2
exit 1 exit 1
fi fi
hostname=$1 hostname=$1
user1=$2 user1=$2
user2=$3 user2=$3
espfs=$4
re='[-A-Za-z0-9.]+' re='[-A-Za-z0-9.]+'
if [[ ! "$hostname" =~ $re ]]; then if [[ ! "$hostname" =~ $re ]]; then
@ -112,22 +138,29 @@ sleep 2
echo "Rebooting into new firmware" >&2 echo "Rebooting into new firmware" >&2
curl -m 10 -s "http://$hostname/flash/reboot" curl -m 10 -s "http://$hostname/flash/reboot"
check_response
# everything is done, if no ESP FS image file was spezified
if [ ! "$espfs" ]; then
exit 0
fi
if [[ ! -r "$espfs" ]]; then
echo "ERROR: cannot read ESP FS image file ($espfs)" >&2
exit 1
fi
echo "Uploading ESP FS image" >&2
res=`curl $silent -XPOST --data-binary "@$espfs" "http://$hostname/flash/upload"`
if [[ $? != 0 ]]; then
echo "Error uploading $espfs" >&2
exit 1
fi
sleep 2 sleep 2
echo "Waiting for ESP8266 to come back" echo "Reseting to load new ESP FS image" >&2
while true; do curl -m 10 -s "http://$hostname/log/reset"
[[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2
next2=`curl -m 10 $v -s "http://$hostname/flash/next"` check_response
[[ -n "$verbose" ]] && echo "got: $next2"
re='user[12]\.bin'
if [[ "$next2" =~ $re ]]; then
if [[ "$next2" != "$next" ]]; then
sec=$(( `date +%s` - $start ))
echo "Success, took $sec seconds" >&2
exit 0
else
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2
exit 1
fi
fi
sleep 1
done

Loading…
Cancel
Save