From b08d896a6c8eb01c8b206df9c490f7f0ca6ce5ac Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Thu, 11 May 2017 16:50:43 -0500 Subject: [PATCH] Allow SPIFFS update via ESP8266HTTPUpdateServer This adds capability to update the SPIFFS image via the same mechansism as firmware in the ESP8266HTTPUpdateServer. It does not provide any dependency or linkage between firmware and spiffs image updating; they are each taken on their own, each followed by a reboot. (I wrote this before seeing the other PR for similar functionality; I like this a bit better, becaue it uses the available SPIFFS size, and does not hide magic numbers (U_SPIFFS) in the html...) (It also cleans up a stray \n from commit ace0622) --- .../src/ESP8266HTTPUpdateServer.cpp | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp index 1223596cf8..7f4b17ffa6 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp @@ -6,13 +6,22 @@ #include "StreamString.h" #include "ESP8266HTTPUpdateServer.h" +extern "C" uint32_t _SPIFFS_start; +extern "C" uint32_t _SPIFFS_end; static const char serverIndex[] PROGMEM = - R"(
- - + R"( + + Firmware:
+ +
- \n)"; +
+ Spiffs:
+ + +
+ )"; static const char successResponse[] PROGMEM = "Update Success! Rebooting...\n"; @@ -71,9 +80,16 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server, const char * path, WiFiUDP::stopAll(); if (_serial_output) Serial.printf("Update: %s\n", upload.filename.c_str()); - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - if(!Update.begin(maxSketchSpace)){//start with max available size - _setUpdaterError(); + if (upload.name == "spiffs") { + size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start); + if (!Update.begin(spiffsSize, U_SPIFFS)){//start with max available size + if (_serial_output) Update.printError(Serial); + } + } else { + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; + if (!Update.begin(maxSketchSpace, U_FLASH)){//start with max available size + _setUpdaterError(); + } } } else if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){ if (_serial_output) Serial.printf(".");