From 8e15f87cd3420316fe9eae22d288ed221f77d082 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 29 Nov 2019 06:10:17 +0100 Subject: [PATCH] Moved index.html from SPIFFS to program memory. Removed dependencies to SPIFFS. Also, we can use a different partition scheme with much more program space instead of reserving some of it for SPIFFS. --- data/_version.txt | 1 - deploy.sh | 7 +------ include/main.h | 3 ++- include/updater.h | 2 +- partitions.csv | 6 ++++++ platformio.ini | 4 ++++ src/controller.cpp | 1 - src/http_server.cpp | 4 ++-- {data => src}/index.html | 0 src/main.cpp | 24 ------------------------ src/updater.cpp | 32 +++++++------------------------- 11 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 data/_version.txt create mode 100644 partitions.csv rename {data => src}/index.html (100%) diff --git a/data/_version.txt b/data/_version.txt deleted file mode 100644 index d00491f..0000000 --- a/data/_version.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/deploy.sh b/deploy.sh index 3ec8bca..ff1290a 100755 --- a/deploy.sh +++ b/deploy.sh @@ -20,22 +20,17 @@ read -p "Version to generate: " VERSION OTA_VERSION=`grep "VERSION=" bin/update.manifest | cut -d"=" -f2` OTA_VERSION=$(( "$OTA_VERSION" + 1 )) -echo "$OTA_VERSION" > data/_version.txt sed -i.bak "s/#define OTA_VERSION .*/#define OTA_VERSION $OTA_VERSION/" include/config.h include/config.sample.h rm include/config.h.bak include/config.sample.h.bak PLATFORMIO_BUILD_FLAGS='-DVERSION=\"$VERSION\"' pio run -e deploy -t buildprog || exit 1 -pio run -e deploy -t buildfs || exit 1 cp .pio/build/deploy/firmware.bin bin/firmware.bin || exit 1 -cp .pio/build/deploy/spiffs.bin bin/spiffs.bin || exit 1 sed -i.bak "s/VERSION=.*/VERSION=$OTA_VERSION/" bin/update.manifest MD5=`md5sum --binary bin/firmware.bin | cut -d" " -f1` sed -i.bak "s/IMAGE_MD5=.*/IMAGE_MD5=$MD5/" bin/update.manifest -MD5=`md5sum --binary bin/spiffs.bin | cut -d" " -f1` -sed -i.bak "s/SPIFFS_MD5=.*/SPIFFS_MD5=$MD5/" bin/update.manifest rm bin/update.manifest.bak echo; echo; echo; echo; echo @@ -44,7 +39,7 @@ git diff read -p "Press ENTER to continue, Ctrl-C to abort. " foo -git add bin/firmware.bin bin/spiffs.bin bin/update.manifest +git add bin/firmware.bin bin/update.manifest git commit -m "Deploying version $VERSION." git tag -a -m "Deploying version $VERSION" $VERSION git push --follow-tags diff --git a/include/main.h b/include/main.h index b1c6ac1..0117185 100644 --- a/include/main.h +++ b/include/main.h @@ -1,4 +1,5 @@ #pragma once -extern uint16_t spiffs_version; void wifi_connect(); + +extern const uint8_t file_index_html_start[] asm("_binary_src_index_html_start"); diff --git a/include/updater.h b/include/updater.h index 3aa76b7..9d5a3a8 100644 --- a/include/updater.h +++ b/include/updater.h @@ -4,7 +4,7 @@ class Updater { public: - static void run(uint16_t spiffs_version = 0); + static void run(); static bool do_update(int cmd, String url, String expected_md5); static bool read_line(String* dst, HTTPClientWrapper* http, String expected_key); }; diff --git a/partitions.csv b/partitions.csv new file mode 100644 index 0000000..5ed782b --- /dev/null +++ b/partitions.csv @@ -0,0 +1,6 @@ +# Custom partition table without SPIFFS. +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x220000, +app1, app, ota_1, 0x230000,0x220000, diff --git a/platformio.ini b/platformio.ini index f9800a5..8e880cc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -27,6 +27,8 @@ build_flags=!./build_version.sh lib_deps = ${extra.lib_deps} upload_port = /dev/cu.SLAB_USBtoUART monitor_speed = 74480 +board_build.embed_txtfiles = src/index.html +board_build.partitions = partitions.csv ;monitor_port = /dev/cu.wchusbserial1420 [env:deploy] @@ -34,3 +36,5 @@ platform = espressif32 board = esp-wrover-kit framework = arduino lib_deps = ${extra.lib_deps} +board_build.embed_txtfiles = src/index.html +board_build.partitions = partitions.csv diff --git a/src/controller.cpp b/src/controller.cpp index 6189e53..8a30ba4 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -378,7 +378,6 @@ String Controller::json() { json["uptime"] = millis() / 1000; json["free_heap"] = ESP.getFreeHeap(); JsonObject versions = json.createNestedObject("versions"); - versions["spiffs"] = spiffs_version; versions["ota"] = OTA_VERSION; #ifdef VERSION versions["release"] = VERSION; diff --git a/src/http_server.cpp b/src/http_server.cpp index 2687913..087d9f7 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -1,7 +1,7 @@ #include "http_server.h" +#include "main.h" #include "spi_master.h" #include -#include HTTPServer::HTTPServer(Player* p, Controller* c) { _player = p; @@ -12,7 +12,7 @@ HTTPServer::HTTPServer(Player* p, Controller* c) { ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){this->_onEvent(server, client, type, arg, data, len);}); _server->on("/", HTTP_GET, [&](AsyncWebServerRequest* req) { - req->send(SPIFFS, "/index.html", "text/html"); + req->send(200, "text/html", (const char*)file_index_html_start); }); _server->on("/upload", HTTP_POST, [](AsyncWebServerRequest* req) { req->send(200); diff --git a/data/index.html b/src/index.html similarity index 100% rename from data/index.html rename to src/index.html diff --git a/src/main.cpp b/src/main.cpp index 6a50dfd..157e557 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "main.h" #include "config.h" #include "controller.h" @@ -20,8 +19,6 @@ HTTPServer* http_server; uint8_t SPIMaster::state = 0; -uint16_t spiffs_version = 0; - bool connect_to_wifi(String ssid, String pass) { TRACE("Connecting to wifi \"%s\"...\n", ssid.c_str()); WiFi.mode(WIFI_AP_STA); @@ -101,17 +98,6 @@ void setup() { } spi->select_sd(false); - DEBUG("Starting SPIFFS...\n"); - SPIFFS.begin(true); - if (SPIFFS.exists("/_version.txt")) { - File f = SPIFFS.open("/_version.txt", "r"); - spiffs_version = f.readString().toInt(); - f.close(); - DEBUG("SPIFFS filesystem version is %d.\n", spiffs_version); - } else { - DEBUG("No SPIFFS filesystem version found - setting spiffs_version to 0.\n"); - } - DEBUG("Initializing PlaylistManager...\n"); pm = new PlaylistManager(); @@ -122,10 +108,6 @@ void setup() { wifi_connect(); - - - - MDNS.begin("esmp3"); DEBUG("Setting up HTTP server...\n"); @@ -144,12 +126,6 @@ void setup() { INFO("Could not fetch current time via NTP.\n"); } - #ifdef OTA_UPDATE_URL - if (spiffs_version < OTA_VERSION) { - Updater::run(spiffs_version); - } - #endif - INFO("Initialization completed.\n"); } diff --git a/src/updater.cpp b/src/updater.cpp index e0a9351..491e373 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -4,8 +4,7 @@ #include "updater.h" #include "http_client_wrapper.h" -void Updater::run(uint16_t spiffs_version) { - bool update_image = true; +void Updater::run() { DEBUG("Updater is running...\n"); HTTPClientWrapper* http = new HTTPClientWrapper(); DEBUG("Requesting update info...\n"); @@ -26,12 +25,7 @@ void Updater::run(uint16_t spiffs_version) { } DEBUG("Found version %d. My version is %d.\n", version, OTA_VERSION); if (version <= OTA_VERSION) { - if (spiffs_version>0 && spiffs_version < version) { - update_image = false; - DEBUG("SPIFFS needs an update. Continuing.\n"); - } else { - return; - } + return; } String image_path = ""; @@ -44,27 +38,15 @@ void Updater::run(uint16_t spiffs_version) { return; } - String spiffs_path = ""; - if (!read_line(&spiffs_path, http, "SPIFFS_PATH")) { - return; - } - - String spiffs_md5 = ""; - if (!read_line(&spiffs_md5, http, "SPIFFS_MD5")) { - return; - } - http->close(); delete http; - result = true; - if (update_image) { - result = do_update(U_FLASH, image_path, image_md5); + if(do_update(U_FLASH, image_path, image_md5)) { + DEBUG("Update done. Rebooting...\n"); + } else { + DEBUG("Update failed. Rebooting...\n"); } - if (result) { - do_update(U_SPIFFS, spiffs_path, spiffs_md5); - } - DEBUG("Done. Rebooting...\n"); + delay(1000); ESP.restart(); }