Skip to content

Move Updater from core to libraries. #6393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;

#include "HardwareSerial.h"
#include "Esp.h"
#include "Updater.h"
#include "debug.h"

using std::min;
Expand Down
35 changes: 0 additions & 35 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,41 +534,6 @@ uint32_t EspClass::getFreeSketchSpace() {
return freeSpaceEnd - freeSpaceStart;
}

bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool restartOnSuccess) {
if(!Update.begin(size)){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
Update.printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

if(Update.writeStream(in) != size){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
Update.printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

if(!Update.end()){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
Update.printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("Update SUCCESS");
#endif
if(restartOnSuccess) ESP.restart();
return true;
}

static const int FLASH_INT_MASK = ((B10 << 8) | B00111010);

bool EspClass::flashEraseSector(uint32_t sector) {
Expand Down
1 change: 0 additions & 1 deletion cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class EspClass {
uint32_t getSketchSize();
String getSketchMD5();
uint32_t getFreeSketchSpace();
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);

String getResetReason();
String getResetInfo();
Expand Down
10 changes: 10 additions & 0 deletions libraries/Updater/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=Updater
version=1.0
author=me-no-dev <[email protected]>
maintainer=me-no-dev <[email protected]>
sentence=Flash Updater Back-end
paragraph=Manages the updating of firmware on the ESP8266. It is mainly used by ArduinoOTA and other similar online flash updating libraries
category=Other
url=
architectures=esp8266
dot_a_linkage=true
46 changes: 40 additions & 6 deletions cores/esp8266/Updater.cpp → libraries/Updater/src/Updater.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Updater.h"
#include "Arduino.h"
#include "eboot_command.h"
#include <eboot_command.h>
#include <esp8266_peri.h>

//#define DEBUG_UPDATER Serial
Expand All @@ -11,16 +10,16 @@
#endif

#if ARDUINO_SIGNING
#include "../../libraries/ESP8266WiFi/src/BearSSLHelpers.h"
#include "../../../libraries/ESP8266WiFi/src/BearSSLHelpers.h"
static BearSSL::PublicKey signPubKey(signing_pubkey);
static BearSSL::HashSHA256 hash;
static BearSSL::SigningVerifier sign(&signPubKey);
#endif

extern "C" {
#include "c_types.h"
#include "spi_flash.h"
#include "user_interface.h"
#include <c_types.h>
#include <spi_flash.h>
#include <user_interface.h>
}

extern "C" uint32_t _FS_start;
Expand Down Expand Up @@ -525,4 +524,39 @@ void UpdaterClass::printError(Print &out){
}
}

bool UpdaterClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool restartOnSuccess) {
if(!begin(size)){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

if(writeStream(in) != size){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

if(!end()){
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print("Update ");
printError(DEBUG_SERIAL);
#endif
if(restartOnFail) ESP.restart();
return false;
}

#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("Update SUCCESS");
#endif
if(restartOnSuccess) ESP.restart();
return true;
}

UpdaterClass Update;
2 changes: 2 additions & 0 deletions cores/esp8266/Updater.h → libraries/Updater/src/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class UpdaterClass {
return written;
}

bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);

private:
void _reset();
bool _writeBuffer();
Expand Down
4 changes: 3 additions & 1 deletion tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ $(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a
ARDUINO_LIBS := \
$(addprefix $(CORE_PATH)/,\
IPAddress.cpp \
Updater.cpp \
base64.cpp \
) \
$(addprefix ../../libraries/Updater/src/,\
Updater.cpp \
) \
$(addprefix ../../libraries/ESP8266WiFi/src/,\
ESP8266WiFi.cpp \
ESP8266WiFiAP.cpp \
Expand Down