From 0fb366c9a7adf86597804f401822c644f2196980 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Sun, 28 Feb 2016 16:26:58 +0100 Subject: [PATCH 01/10] Unifiy SDK paths --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4e5fa72..e80e253 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/ # Base directory of the ESP8266 SDK package, absolute # 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 # Typically you'll use https://github.com/themadinventor/esptool From 3b60f88a6ef086bb25ba1c649bb767800ab15e3b Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Sun, 28 Feb 2016 16:29:47 +0100 Subject: [PATCH 02/10] Use type bool cast to mind errors --- esp-link/cgimqtt.c | 8 ++++---- esp-link/cgiservices.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/esp-link/cgimqtt.c b/esp-link/cgimqtt.c index 88aa6ed..444294b 100644 --- a/esp-link/cgimqtt.c +++ b/esp-link/cgimqtt.c @@ -95,11 +95,11 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) { if (mqtt_server < 0) return HTTPD_CGI_DONE; mqtt_server |= getBoolArg(connData, "mqtt-clean-session", - &flashConfig.mqtt_clean_session); + (bool*)&flashConfig.mqtt_clean_session); if (mqtt_server < 0) return HTTPD_CGI_DONE; int8_t mqtt_en_chg = getBoolArg(connData, "mqtt-enable", - &flashConfig.mqtt_enable); + (bool*)&flashConfig.mqtt_enable); 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 // 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; if (getStringArg(connData, "mqtt-status-topic", flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0) return HTTPD_CGI_DONE; // 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) DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable); diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 81f7200..6d3704c 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -146,9 +146,9 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { if (syslog < 0) return HTTPD_CGI_DONE; syslog |= getUInt8Arg(connData, "syslog_filter", &flashConfig.syslog_filter); 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; - 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) { @@ -166,7 +166,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { } 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) { From a3fd9bfd5135e93073e9c5b90587dba00b4f177b Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Mon, 29 Feb 2016 12:04:39 +0100 Subject: [PATCH 03/10] flash ESP FS to the other (currently not used) partition of the --- Makefile | 27 ++++++++++++++++++++++----- esp-link/cgiflash.c | 38 ++++++++++++++++++++++++++++++-------- esp-link/cgiflash.h | 2 ++ esp-link/main.c | 5 +++++ espfs/espfs.c | 11 ++++++++--- espfs/espfs.h | 5 ++++- 6 files changed, 71 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index e80e253..c8f9db5 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ ESPBAUD ?= 460800 # --------------- chipset configuration --------------- # 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 # can be changed via the web interface @@ -84,7 +84,7 @@ LED_SERIAL_PIN ?= 14 # --------------- esp-link modules config options --------------- # Optional Modules mqtt -MODULES ?= mqtt rest syslog +#MODULES ?= mqtt rest syslog # --------------- esphttpd config options --------------- @@ -113,18 +113,24 @@ COMPRESS_W_HTMLCOMPRESSOR ?= yes HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar + +# use this option to place the ESP FS in the other partition of the flash +# which is currently not booted. +# ONLY works with wifi update. +USE_OTHER_PARTITION_FOR_ESPFS ?= yes + # -------------- End of config options ------------- HTML_PATH = $(abspath ./html)/ WIFI_PATH = $(HTML_PATH)wifi/ -ESP_FLASH_MAX ?= 503808 # max bin file ifeq ("$(FLASH_SIZE)","512KB") # Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11 ESP_SPI_SIZE ?= 0 # 0->512KB (256KB+256KB) ESP_FLASH_MODE ?= 0 # 0->QIO 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_FF ?= 40m # 40Mhz flash speed in esptool flash command ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings @@ -134,6 +140,7 @@ else ifeq ("$(FLASH_SIZE)","1MB") ESP_SPI_SIZE ?= 2 # 2->1MB (512KB+512KB) ESP_FLASH_MODE ?= 0 # 0->QIO 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_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings @@ -146,6 +153,7 @@ else ifeq ("$(FLASH_SIZE)","2MB") ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO 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_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings @@ -158,6 +166,7 @@ else ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB) ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO 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_FF ?= 80m # 80Mhz flash speed in esptool flash command ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings @@ -253,7 +262,11 @@ SDK_TOOLS := $(addprefix $(SDK_BASE)/,$(SDK_TOOLSDIR)) APPGEN_TOOL := $(addprefix $(SDK_TOOLS)/,$(APPGEN_TOOL)) 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)) APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) USER1_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).user1.out) @@ -312,6 +325,10 @@ ifeq ("$(CHANGE_TO_STA)","yes") CFLAGS += -DCHANGE_TO_STA endif +ifeq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes") +CFLAGS += -DUSE_OTHER_PARTITION_FOR_ESPFS +endif + vpath %.c $(SRC_DIR) define compile-objects @@ -322,7 +339,7 @@ endef .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: $(VERSION) diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 8c39e36..c6f3ff2 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -18,6 +18,7 @@ Some flash handling cgi routines. Used for reading the existing flash and updati #include #include "cgi.h" #include "cgiflash.h" +#include "espfs.h" #ifdef CGIFLASH_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -47,6 +48,23 @@ static bool canOTA(void) { 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 = 0x4200000 + 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 int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. @@ -95,7 +113,14 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { connData->post->len < 1024) err = "Invalid request"; // 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 if (err == NULL && offset % 1024 != 0) { @@ -117,13 +142,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 - uint8 id = system_upgrade_userbin_check(); - 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 + int address = getNextSPIFlashAddr(); address += offset; // erase next flash block if necessary if (address % SPI_FLASH_SEC_SIZE == 0){ + const uint8 id = system_upgrade_userbin_check(); DBG("Flashing 0x%05x (id=%d)\n", address, 2 - id); spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE); } @@ -155,9 +179,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { // sanity-check that the 'next' partition actually contains something that looks like // valid firmware - uint8 id = system_upgrade_userbin_check(); - 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 + const int address = getNextSPIFlashAddr(); uint32 buf[8]; DBG("Checking %p\n", (void *)address); spi_flash_read(address, buf, sizeof(buf)); @@ -197,4 +219,4 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) { os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); os_timer_arm(&flash_reboot_timer, 2000, 1); return HTTPD_CGI_DONE; -} \ No newline at end of file +} diff --git a/esp-link/cgiflash.h b/esp-link/cgiflash.h index f03b8e0..6674125 100644 --- a/esp-link/cgiflash.h +++ b/esp-link/cgiflash.h @@ -3,6 +3,8 @@ #include "httpd.h" +uint32* const getNextFlashAddr(void); + int cgiReadFlash(HttpdConnData *connData); int cgiGetFirmwareNext(HttpdConnData *connData); int cgiUploadFirmware(HttpdConnData *connData); diff --git a/esp-link/main.c b/esp-link/main.c index 4f7de35..bfc0745 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -129,9 +129,14 @@ void user_init(void) { // Wifi wifiInit(); // init the flash filesystem with the html stuff +#ifdef USE_OTHER_PARTITION_FOR_ESPFS + uint32* addr = getNextFlashAddr(); + espFsInit(addr); +#else espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //os_printf("espFsInit %s\n", res?"ERR":"ok"); +#endif // mount the http handlers httpdInit(builtInUrls, 80); // init the wifi-serial transparent bridge (port 23) diff --git a/espfs/espfs.c b/espfs/espfs.c index f9942f3..963075e 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -67,6 +67,13 @@ Accessing the flash through the mem emulation at 0x40200000 is a bit hairy: All a memory exception, crashing the program. */ +bool ICACHE_FLASH_ATTR espFsIsImage(const void* const flashAddress) { + // check if there is valid header at address + const EspFsHeader* const testHeader = (EspFsHeader*)flashAddress; + return (testHeader->magic == ESPFS_MAGIC); +} + + EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { // base address must be aligned to 4 bytes if (((int)flashAddress & 3) != 0) { @@ -74,9 +81,7 @@ EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { } // check if there is valid header at address - EspFsHeader testHeader; - os_memcpy(&testHeader, flashAddress, sizeof(EspFsHeader)); - if (testHeader.magic != ESPFS_MAGIC) { + if (espFsIsImage(flashAddress)) { return ESPFS_INIT_RESULT_NO_IMAGE; } diff --git a/espfs/espfs.h b/espfs/espfs.h index c8e13e7..b57a7d6 100644 --- a/espfs/espfs.h +++ b/espfs/espfs.h @@ -1,6 +1,8 @@ #ifndef ESPFS_H #define ESPFS_H +#include + typedef enum { ESPFS_INIT_RESULT_OK, ESPFS_INIT_RESULT_NO_IMAGE, @@ -9,6 +11,7 @@ typedef enum { typedef struct EspFsFile EspFsFile; +bool espFsIsImage(const void* const flashAddress); EspFsInitResult espFsInit(void *flashAddress); EspFsFile *espFsOpen(char *fileName); int espFsFlags(EspFsFile *fh); @@ -16,4 +19,4 @@ int espFsRead(EspFsFile *fh, char *buff, int len); void espFsClose(EspFsFile *fh); -#endif \ No newline at end of file +#endif From a9831d9cc6f4131c77fdb4814b77840015838e4f Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Mon, 29 Feb 2016 12:13:03 +0100 Subject: [PATCH 04/10] Make it possible to disable syslog --- esp-link/cgiservices.c | 7 ++++++- esp-link/main.c | 5 ++++- include/user_config.h | 9 +++++++++ serial/serbridge.c | 7 +++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/esp-link/cgiservices.c b/esp-link/cgiservices.c index 6d3704c..c42fd96 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiservices.c @@ -2,10 +2,13 @@ #include "cgiwifi.h" #include "cgi.h" #include "config.h" -#include "syslog.h" #include "sntp.h" #include "cgimqtt.h" +#ifdef SYSLOG +#include "syslog.h" +#endif + #ifdef CGISERVICES_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #else @@ -138,6 +141,7 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. +#ifdef SYSLOG int8_t syslog = 0; syslog |= getStringArg(connData, "syslog_host", flashConfig.syslog_host, sizeof(flashConfig.syslog_host)); @@ -154,6 +158,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) { if (syslog > 0) { syslog_init(flashConfig.syslog_host); } +#endif int8_t sntp = 0; sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset); diff --git a/esp-link/main.c b/esp-link/main.c index bfc0745..e7a65f1 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -29,9 +29,12 @@ #include "config.h" #include "log.h" #include "gpio.h" -#include "syslog.h" #include "cgiservices.h" +#ifdef SYSLOG +#include "syslog.h" +#endif + #define NOTICE(format, ...) do { \ LOG_NOTICE(format, ## __VA_ARGS__ ); \ os_printf(format "\n", ## __VA_ARGS__); \ diff --git a/include/user_config.h b/include/user_config.h index a939533..f0b6d3e 100644 --- a/include/user_config.h +++ b/include/user_config.h @@ -37,6 +37,15 @@ // If defined, the default hostname for DHCP will include the chip ID to make it unique #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 uint8_t UTILS_StrToIP(const char* str, void *ip); diff --git a/serial/serbridge.c b/serial/serbridge.c index 1e82e3d..2ba1834 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -10,7 +10,10 @@ #include "console.h" #include "slip.h" #include "cmd.h" + +#ifdef SYSLOG #include "syslog.h" +#endif #define SKIP_AT_RESET @@ -405,12 +408,16 @@ serbridgeConnectCb(void *arg) #ifdef SERBR_DBG os_printf("Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i); #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); +#endif if (i==MAX_CONN) { #ifdef SERBR_DBG os_printf("Aiee, conn pool overflow!\n"); #endif +#ifdef SYSLOG syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_WARNING, "esp-link", "Aiee, conn pool overflow!\n"); +#endif espconn_disconnect(conn); return; } From 54c1268fe510493535b2ce559ccaf7bda87ec3c2 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Mon, 29 Feb 2016 14:37:53 +0100 Subject: [PATCH 05/10] Exclude some modules --- esp-link/{ => cgiadv}/cgioptiboot.c | 0 esp-link/{ => cgiadv}/cgioptiboot.h | 0 esp-link/{ => cgiadv}/cgipins.c | 0 esp-link/{ => cgiadv}/cgipins.h | 0 esp-link/{ => cgiadv}/cgitcp.c | 0 esp-link/{ => cgiadv}/cgitcp.h | 0 esp-link/{ => cgiadv}/stk500.h | 0 esp-link/{ => log}/log.c | 0 esp-link/{ => log}/log.h | 0 serial/{ => console}/console.c | 0 serial/{ => console}/console.h | 0 serial/{ => serbridge}/serbridge.c | 0 serial/{ => serbridge}/serbridge.h | 0 serial/{ => serbridge}/slip.c | 0 serial/{ => serbridge}/slip.h | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename esp-link/{ => cgiadv}/cgioptiboot.c (100%) rename esp-link/{ => cgiadv}/cgioptiboot.h (100%) rename esp-link/{ => cgiadv}/cgipins.c (100%) rename esp-link/{ => cgiadv}/cgipins.h (100%) rename esp-link/{ => cgiadv}/cgitcp.c (100%) rename esp-link/{ => cgiadv}/cgitcp.h (100%) rename esp-link/{ => cgiadv}/stk500.h (100%) rename esp-link/{ => log}/log.c (100%) rename esp-link/{ => log}/log.h (100%) rename serial/{ => console}/console.c (100%) rename serial/{ => console}/console.h (100%) rename serial/{ => serbridge}/serbridge.c (100%) rename serial/{ => serbridge}/serbridge.h (100%) rename serial/{ => serbridge}/slip.c (100%) rename serial/{ => serbridge}/slip.h (100%) diff --git a/esp-link/cgioptiboot.c b/esp-link/cgiadv/cgioptiboot.c similarity index 100% rename from esp-link/cgioptiboot.c rename to esp-link/cgiadv/cgioptiboot.c diff --git a/esp-link/cgioptiboot.h b/esp-link/cgiadv/cgioptiboot.h similarity index 100% rename from esp-link/cgioptiboot.h rename to esp-link/cgiadv/cgioptiboot.h diff --git a/esp-link/cgipins.c b/esp-link/cgiadv/cgipins.c similarity index 100% rename from esp-link/cgipins.c rename to esp-link/cgiadv/cgipins.c diff --git a/esp-link/cgipins.h b/esp-link/cgiadv/cgipins.h similarity index 100% rename from esp-link/cgipins.h rename to esp-link/cgiadv/cgipins.h diff --git a/esp-link/cgitcp.c b/esp-link/cgiadv/cgitcp.c similarity index 100% rename from esp-link/cgitcp.c rename to esp-link/cgiadv/cgitcp.c diff --git a/esp-link/cgitcp.h b/esp-link/cgiadv/cgitcp.h similarity index 100% rename from esp-link/cgitcp.h rename to esp-link/cgiadv/cgitcp.h diff --git a/esp-link/stk500.h b/esp-link/cgiadv/stk500.h similarity index 100% rename from esp-link/stk500.h rename to esp-link/cgiadv/stk500.h diff --git a/esp-link/log.c b/esp-link/log/log.c similarity index 100% rename from esp-link/log.c rename to esp-link/log/log.c diff --git a/esp-link/log.h b/esp-link/log/log.h similarity index 100% rename from esp-link/log.h rename to esp-link/log/log.h diff --git a/serial/console.c b/serial/console/console.c similarity index 100% rename from serial/console.c rename to serial/console/console.c diff --git a/serial/console.h b/serial/console/console.h similarity index 100% rename from serial/console.h rename to serial/console/console.h diff --git a/serial/serbridge.c b/serial/serbridge/serbridge.c similarity index 100% rename from serial/serbridge.c rename to serial/serbridge/serbridge.c diff --git a/serial/serbridge.h b/serial/serbridge/serbridge.h similarity index 100% rename from serial/serbridge.h rename to serial/serbridge/serbridge.h diff --git a/serial/slip.c b/serial/serbridge/slip.c similarity index 100% rename from serial/slip.c rename to serial/serbridge/slip.c diff --git a/serial/slip.h b/serial/serbridge/slip.h similarity index 100% rename from serial/slip.h rename to serial/serbridge/slip.h From 21bdae68c531d835a41d2aa6f641669638150b71 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Mon, 29 Feb 2016 15:05:45 +0100 Subject: [PATCH 06/10] Make CGI services as own module --- esp-link/{ => cgiadv}/cgiservices.c | 10 +----- esp-link/{ => cgiadv}/cgiservices.h | 3 -- esp-link/cgiwifi.c | 7 +++++ esp-link/main.c | 49 ++++++++++++++++++++++------- esp-link/stringdefs.c | 8 +++++ esp-link/stringdefs.h | 2 ++ serial/console/console.c | 8 ++++- 7 files changed, 62 insertions(+), 25 deletions(-) rename esp-link/{ => cgiadv}/cgiservices.c (96%) rename esp-link/{ => cgiadv}/cgiservices.h (84%) create mode 100644 esp-link/stringdefs.c create mode 100644 esp-link/stringdefs.h diff --git a/esp-link/cgiservices.c b/esp-link/cgiadv/cgiservices.c similarity index 96% rename from esp-link/cgiservices.c rename to esp-link/cgiadv/cgiservices.c index c42fd96..d13ad12 100644 --- a/esp-link/cgiservices.c +++ b/esp-link/cgiadv/cgiservices.c @@ -4,6 +4,7 @@ #include "config.h" #include "sntp.h" #include "cgimqtt.h" +#include "stringdefs.h" #ifdef SYSLOG #include "syslog.h" @@ -15,15 +16,6 @@ #define DBG(format, ...) do { } while(0) #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; // Cgi to update system info (name/description) diff --git a/esp-link/cgiservices.h b/esp-link/cgiadv/cgiservices.h similarity index 84% rename from esp-link/cgiservices.h rename to esp-link/cgiadv/cgiservices.h index 9c44242..d27fc6d 100644 --- a/esp-link/cgiservices.h +++ b/esp-link/cgiadv/cgiservices.h @@ -10,7 +10,4 @@ void cgiServicesSNTPInit(); int cgiServicesInfo(HttpdConnData *connData); int cgiServicesSet(HttpdConnData *connData); -extern char* rst_codes[7]; -extern char* flash_maps[7]; - #endif // CGISERVICES_H diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 50ea536..239fd46 100755 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -18,7 +18,10 @@ Cgi/template routines for the /wifi url. #include "cgi.h" #include "status.h" #include "config.h" + +#ifdef LOG #include "log.h" +#endif #ifdef CGIWIFI_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -315,7 +318,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 #endif } +#ifdef LOG log_uart(false); +#endif // no more resetTimer at this point, gotta use physical reset to recover if in trouble } else { if (m != 3) { @@ -323,7 +328,9 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { wifi_set_opmode(3); wifi_softap_set_config(&apconf); } +#ifdef LOG log_uart(true); +#endif DBG("Enabling/continuing uart log\n"); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); } diff --git a/esp-link/main.c b/esp-link/main.c index e7a65f1..ee4d163 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -14,27 +14,40 @@ #include "httpdespfs.h" #include "cgi.h" #include "cgiwifi.h" -#include "cgipins.h" -#include "cgitcp.h" #include "cgimqtt.h" #include "cgiflash.h" -#include "cgioptiboot.h" #include "auth.h" #include "espfs.h" #include "uart.h" -#include "serbridge.h" #include "status.h" #include "serled.h" -#include "console.h" #include "config.h" -#include "log.h" #include "gpio.h" -#include "cgiservices.h" +#include "stringdefs.h" + +#ifdef LOG +#include "log.h" +#endif #ifdef SYSLOG #include "syslog.h" #endif +#ifdef CONSOLE +#include "console.h" +#endif + +#ifdef SERIAL_BRIDGE +#include "serbridge.h" +#endif + +#ifdef CGI_ADVANCED +#include "cgiservices.h" +#include "cgipins.h" +#include "cgitcp.h" +#include "cgioptiboot.h" +#endif + #define NOTICE(format, ...) do { \ LOG_NOTICE(format, ## __VA_ARGS__ ); \ os_printf(format "\n", ## __VA_ARGS__); \ @@ -56,15 +69,26 @@ HttpdBuiltInUrl builtInUrls[] = { { "/flash/next", cgiGetFirmwareNext, NULL }, { "/flash/upload", cgiUploadFirmware, NULL }, { "/flash/reboot", cgiRebootFirmware, NULL }, +#ifdef CGI_ADVANCED { "/pgm/sync", cgiOptibootSync, 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/dbg", ajaxLogDbg, NULL }, { "/log/reset", cgiReset, NULL }, +#endif +#ifdef CONSOLE { "/console/reset", ajaxConsoleReset, NULL }, { "/console/baud", ajaxConsoleBaud, NULL }, { "/console/text", ajaxConsole, NULL }, { "/console/send", ajaxConsoleSend, NULL }, +#endif //Enable the line below to protect the WiFi configuration with an username/password combo. // {"/wifi/*", authBasic, myPassFn}, { "/wifi", cgiRedirect, "/wifi/wifi.html" }, @@ -77,11 +101,6 @@ HttpdBuiltInUrl builtInUrls[] = { { "/wifi/special", cgiWiFiSpecial, NULL }, { "/wifi/apinfo", cgiApSettingsInfo, 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 { "/mqtt", cgiMqtt, NULL }, #endif @@ -121,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 // init UART uart_init(flashConfig.baud_rate, 115200); +#ifdef LOG logInit(); // must come after init of uart +#endif // Say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); @@ -142,9 +163,11 @@ void user_init(void) { #endif // mount the http handlers httpdInit(builtInUrls, 80); +#ifdef SERIAL_BRIDGE // init the wifi-serial transparent bridge (port 23) serbridgeInit(23, 2323); uart_add_recv_cb(&serbridgeUartCb); +#endif #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); @@ -161,8 +184,10 @@ void user_init(void) { fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); NOTICE("** esp-link ready"); +#ifdef CGI_ADVANCED // Init SNTP service cgiServicesSNTPInit(); +#endif #ifdef MQTT NOTICE("initializing MQTT"); mqtt_client_init(); diff --git a/esp-link/stringdefs.c b/esp-link/stringdefs.c new file mode 100644 index 0000000..131b65a --- /dev/null +++ b/esp-link/stringdefs.c @@ -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" +}; \ No newline at end of file diff --git a/esp-link/stringdefs.h b/esp-link/stringdefs.h new file mode 100644 index 0000000..40733a7 --- /dev/null +++ b/esp-link/stringdefs.h @@ -0,0 +1,2 @@ +extern const char* const rst_codes[7]; +extern const char* const flash_maps[7]; \ No newline at end of file diff --git a/serial/console/console.c b/serial/console/console.c index 68b5b55..1f68dbd 100644 --- a/serial/console/console.c +++ b/serial/console/console.c @@ -4,10 +4,14 @@ #include "uart.h" #include "cgi.h" #include "uart.h" -#include "serbridge.h" #include "config.h" #include "console.h" +#ifdef SERIAL_BRIDGE +#include "serbridge.h" +#endif + + // Microcontroller console capturing the last 1024 characters received on the uart so // 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. jsonHeader(connData, 200); console_rd = console_wr = console_pos = 0; +#ifdef SERIAL_BRIDGE serbridgeReset(); +#endif return HTTPD_CGI_DONE; } From e7678550df1644deb574dad87b07801a004cf6d4 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Mon, 29 Feb 2016 16:07:08 +0100 Subject: [PATCH 07/10] Upload ESP FS to other not used partition --- Makefile | 24 ++++++++++++++++++++---- esp-link/cgiflash.c | 4 +++- esp-link/main.c | 9 +++++---- espfs/espfs.c | 10 +++++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index c8f9db5..d0aff0c 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ LED_SERIAL_PIN ?= 14 # --------------- esp-link modules config options --------------- # Optional Modules mqtt -#MODULES ?= mqtt rest syslog +#MODULES ?= mqtt rest syslog cmd # --------------- esphttpd config options --------------- @@ -124,6 +124,7 @@ USE_OTHER_PARTITION_FOR_ESPFS ?= yes HTML_PATH = $(abspath ./html)/ WIFI_PATH = $(HTML_PATH)wifi/ +ET_PART1 ?= 0x01000 ifeq ("$(FLASH_SIZE)","512KB") # Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11 @@ -133,6 +134,7 @@ 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_FF ?= 40m # 40Mhz flash speed in esptool flash command +ET_PART2 ?= 0x41000 ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings else ifeq ("$(FLASH_SIZE)","1MB") @@ -143,6 +145,7 @@ 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_FF ?= 80m # 80Mhz flash speed in esptool flash command +ET_PART2 ?= 0x81000 ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings else ifeq ("$(FLASH_SIZE)","2MB") @@ -156,6 +159,7 @@ 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_FF ?= 80m # 80Mhz flash speed in esptool flash command +ET_PART2 ?= 0x101000 ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings else @@ -214,7 +218,7 @@ endif # which modules (subdirectories) of the project to include in compiling 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)/*)) EXTRA_INCDIR = include . @@ -395,12 +399,24 @@ wiflash: all ./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin 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 $(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 +endif + ifeq ($(OS),Windows_NT) tools/$(HTML_COMPRESSOR): diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index c6f3ff2..50c797d 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -20,6 +20,8 @@ Some flash handling cgi routines. Used for reading the existing flash and updati #include "cgiflash.h" #include "espfs.h" +#define SPI_FLASH_MEM_EMU_START_ADDR 0x40200000 + #ifdef CGIFLASH_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #else @@ -57,7 +59,7 @@ static int ICACHE_FLASH_ATTR getNextSPIFlashAddr(void) { } uint32* const ICACHE_FLASH_ATTR getNextFlashAddr(void) { - const uint32 addr = 0x4200000 + getNextSPIFlashAddr(); + 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 diff --git a/esp-link/main.c b/esp-link/main.c index ee4d163..371e264 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -152,15 +152,16 @@ void user_init(void) { serledInit(); // Wifi wifiInit(); + // init the flash filesystem with the html stuff #ifdef USE_OTHER_PARTITION_FOR_ESPFS uint32* addr = getNextFlashAddr(); - espFsInit(addr); + const EspFsInitResult res = espFsInit(addr); #else - espFsInit(&_binary_espfs_img_start); - //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); - //os_printf("espFsInit %s\n", res?"ERR":"ok"); + const EspFsInitResult res = espFsInit(&_binary_espfs_img_start); #endif + os_printf("espFsInit %s (%u)\n", res?"ERR":"ok", res); + // mount the http handlers httpdInit(builtInUrls, 80); #ifdef SERIAL_BRIDGE diff --git a/espfs/espfs.c b/espfs/espfs.c index 963075e..51f4088 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -69,8 +69,12 @@ a memory exception, crashing the program. bool ICACHE_FLASH_ATTR espFsIsImage(const void* const flashAddress) { // check if there is valid header at address - const EspFsHeader* const testHeader = (EspFsHeader*)flashAddress; - return (testHeader->magic == ESPFS_MAGIC); + 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); } @@ -81,7 +85,7 @@ EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { } // check if there is valid header at address - if (espFsIsImage(flashAddress)) { + if ( !espFsIsImage(flashAddress) ) { return ESPFS_INIT_RESULT_NO_IMAGE; } From 9ecfb2a0a5d6456ac23a2b0cf2cfbcfd734e20e8 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Tue, 1 Mar 2016 13:09:36 +0100 Subject: [PATCH 08/10] Upload ESP FS image after flashing and reboot --- Makefile | 20 ++++++++++++- esp-link/cgiflash.c | 2 +- esp-link/main.c | 2 +- wiflash | 73 ++++++++++++++++++++++++++++++++------------- 4 files changed, 74 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index d0aff0c..aa14ba4 100644 --- a/Makefile +++ b/Makefile @@ -395,9 +395,14 @@ checkdirs: $(BUILD_DIR) $(BUILD_DIR): $(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 $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin - +endif + baseflash: all $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(ET_PART1) $(FW_BASE)/user1.bin @@ -480,6 +485,18 @@ endif # 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 +# 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 $(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \ -e '/^ irom0_0_seg/ s/6B000/7C000/' \ @@ -488,6 +505,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 '}' \ -e '/^ irom0_0_seg/ s/6B000/7C000/' \ $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld >$@ +endif espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ $(Q) $(MAKE) -C espfs/mkespfsimage GZIP_COMPRESSION="$(GZIP_COMPRESSION)" diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 50c797d..3c76211 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -45,7 +45,7 @@ static char* ICACHE_FLASH_ATTR check_header(void *buf) { // check whether the flash map/size we have allows for OTA upgrade static bool canOTA(void) { 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"; diff --git a/esp-link/main.c b/esp-link/main.c index 371e264..9487bd1 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -69,6 +69,7 @@ HttpdBuiltInUrl builtInUrls[] = { { "/flash/next", cgiGetFirmwareNext, NULL }, { "/flash/upload", cgiUploadFirmware, NULL }, { "/flash/reboot", cgiRebootFirmware, NULL }, + { "/log/reset", cgiReset, NULL }, #ifdef CGI_ADVANCED { "/pgm/sync", cgiOptibootSync, NULL }, { "/pgm/upload", cgiOptibootData, NULL }, @@ -81,7 +82,6 @@ HttpdBuiltInUrl builtInUrls[] = { #ifdef LOG { "/log/text", ajaxLog, NULL }, { "/log/dbg", ajaxLogDbg, NULL }, - { "/log/reset", cgiReset, NULL }, #endif #ifdef CONSOLE { "/console/reset", ajaxConsoleReset, NULL }, diff --git a/wiflash b/wiflash index d8c12ea..e26346e 100755 --- a/wiflash +++ b/wiflash @@ -13,7 +13,7 @@ show_help() { cat < with either or depending on its current state. Reboot the esp8266 after flashing and wait for it to come up again. @@ -25,6 +25,30 @@ Example: ${0##*/} -v esp8266 firmware/user1.bin firmware/user2.bin 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 echo "ERROR: Cannot find curl: it is required for this script." >&2 exit 1 @@ -49,13 +73,15 @@ done shift "$((OPTIND-1))" # Get the fixed arguments -if [[ $# != 3 ]]; then +# only 3 or 4 are accepted +if [[ $# < 3 || $# > 4 ]]; then show_help >&2 exit 1 fi hostname=$1 user1=$2 user2=$3 +espfs=$4 re='[-A-Za-z0-9.]+' if [[ ! "$hostname" =~ $re ]]; then @@ -112,22 +138,29 @@ sleep 2 echo "Rebooting into new firmware" >&2 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 -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 - exit 0 - else - echo "Flashing seems to have failed and it reverted to the old firmware?" >&2 - exit 1 - fi - fi - sleep 1 -done +echo "Reseting to load new ESP FS image" >&2 +curl -m 10 -s "http://$hostname/log/reset" + +check_response From 1a3167bf3cbaa8099cbee42a57310ed6386e2e33 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Tue, 1 Mar 2016 13:21:26 +0100 Subject: [PATCH 09/10] Make all modules configurable --- Makefile | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aa14ba4..27d89ce 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ LED_SERIAL_PIN ?= 14 # --------------- esp-link modules config options --------------- # Optional Modules mqtt -#MODULES ?= mqtt rest syslog cmd +#MODULES ?= mqtt rest syslog cmd esp-link/cgiadv esp-link/log serial/console serial/serbridge # --------------- esphttpd config options --------------- @@ -216,6 +216,26 @@ ifneq (,$(findstring syslog,$(MODULES))) CFLAGS += -DSYSLOG 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 LIBRARIES_DIR = libraries MODULES += espfs httpd user serial esp-link From 5466336d8d6296430a709ba609bc50807223a851 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Tue, 1 Mar 2016 13:34:41 +0100 Subject: [PATCH 10/10] Process some comments --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 27d89ce..bb290df 100644 --- a/Makefile +++ b/Makefile @@ -114,9 +114,8 @@ HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar -# use this option to place the ESP FS in the other partition of the flash +# use this option to place the ESP FS image in the other partition of the flash # which is currently not booted. -# ONLY works with wifi update. USE_OTHER_PARTITION_FOR_ESPFS ?= yes # -------------- End of config options ------------- @@ -422,7 +421,7 @@ else wiflash: all ./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin endif - + baseflash: all $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(ET_PART1) $(FW_BASE)/user1.bin