-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
PoC for handling Erase WiFi Setting after OTA #6965
base: master
Are you sure you want to change the base?
Changes from all commits
6fde10f
93fb3d3
c66ae2e
6d882e4
500b7cc
afd603b
bfb21b1
e51ab08
a284b0a
3258d63
9d6e059
95eefed
815f1dc
660d19c
4554a7c
1ce4c60
7130877
73f16dc
9c4e44b
546f0cb
560ddc5
049d91b
4e2493a
39160c8
c0394fb
f1acb40
604b40a
4553009
372998c
39b9508
4954dcd
828a47d
b2d35ea
74129c5
14fede0
be5fe6d
cfd54df
6f91be0
6b1cdb8
fcb8b21
c40a873
2b2def2
48ed5e9
b211727
ab9b6b2
e5539fe
502d8bc
f50b3a6
94365e1
5234f3f
025bb2f
edade1c
24a117c
4e31c91
0b01518
f9a3f95
217b2d2
0b7fced
9f0e220
e44e752
c44a3f9
63a2048
21b0154
fb05f15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,11 @@ void UpdaterClass::_reset() { | |
} | ||
|
||
bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) { | ||
#if defined(ERASE_CONFIG_H) && !defined(HOST_MOCK) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ERASE_CONFIG_H always defined, drop the condition (leaving host_mock) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
// Empty call so erase_config.cpp module to ensure it is built and linked in. | ||
enable_erase_config_at_link_time(); | ||
#endif | ||
|
||
if(_size > 0){ | ||
#ifdef DEBUG_UPDATER | ||
DEBUG_UPDATER.println(F("[begin] already running")); | ||
|
@@ -82,7 +87,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) { | |
_setError(UPDATE_ERROR_BOOTSTRAP); | ||
return false; | ||
} | ||
|
||
#ifdef DEBUG_UPDATER | ||
if (command == U_FS) { | ||
DEBUG_UPDATER.println(F("[begin] Update Filesystem.")); | ||
|
@@ -129,7 +134,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) { | |
|
||
//make sure that the size of both sketches is less than the total space (updateEndAddress) | ||
if(updateStartAddress < currentSketchSize) { | ||
_setError(UPDATE_ERROR_SPACE); | ||
_setError(UPDATE_ERROR_SPACE); | ||
return false; | ||
} | ||
} | ||
|
@@ -312,10 +317,17 @@ bool UpdaterClass::end(bool evenIfRemaining){ | |
|
||
if (_command == U_FLASH) { | ||
eboot_command ebcmd; | ||
memset(&ebcmd, 0, sizeof(ebcmd)); | ||
ebcmd.action = ACTION_COPY_RAW; | ||
ebcmd.args[0] = _startAddress; | ||
ebcmd.args[1] = 0x00000; | ||
ebcmd.args[2] = _size; | ||
#ifdef ERASE_CONFIG_H | ||
ebcmd.args[4] = _eraseConfigOption; | ||
ebcmd.args[5] = ~_eraseConfigOption; | ||
ebcmd.args[6] = _eraseConfigOption; | ||
ebcmd.args[7] = ~_eraseConfigOption; | ||
#endif | ||
eboot_command_write(&ebcmd); | ||
|
||
#ifdef DEBUG_UPDATER | ||
|
@@ -325,6 +337,7 @@ bool UpdaterClass::end(bool evenIfRemaining){ | |
else if (_command == U_FS) { | ||
#ifdef ATOMIC_FS_UPDATE | ||
eboot_command ebcmd; | ||
memset(&ebcmd, 0, sizeof(ebcmd)); | ||
ebcmd.action = ACTION_COPY_RAW; | ||
ebcmd.args[0] = _startAddress; | ||
ebcmd.args[1] = FS_start - 0x40200000; | ||
|
@@ -373,7 +386,7 @@ bool UpdaterClass::_writeBuffer(){ | |
modifyFlashMode = true; | ||
} | ||
} | ||
|
||
if (eraseResult) { | ||
if(!_async) yield(); | ||
writeResult = ESP.flashWrite(_currentAddress, _buffer, _bufferLen); | ||
|
@@ -457,7 +470,7 @@ bool UpdaterClass::_verifyEnd() { | |
uint8_t buf[4] __attribute__((aligned(4))); | ||
if(!ESP.flashRead(_startAddress, (uint32_t *) &buf[0], 4)) { | ||
_currentAddress = (_startAddress); | ||
_setError(UPDATE_ERROR_READ); | ||
_setError(UPDATE_ERROR_READ); | ||
return false; | ||
} | ||
|
||
|
@@ -469,7 +482,7 @@ bool UpdaterClass::_verifyEnd() { | |
return true; | ||
} else if (buf[0] != 0xE9) { | ||
_currentAddress = (_startAddress); | ||
_setError(UPDATE_ERROR_MAGIC_BYTE); | ||
_setError(UPDATE_ERROR_MAGIC_BYTE); | ||
return false; | ||
} | ||
|
||
|
@@ -481,7 +494,7 @@ bool UpdaterClass::_verifyEnd() { | |
// check if new bin fits to SPI flash | ||
if(bin_flash_size > ESP.getFlashChipRealSize()) { | ||
_currentAddress = (_startAddress); | ||
_setError(UPDATE_ERROR_NEW_FLASH_CONFIG); | ||
_setError(UPDATE_ERROR_NEW_FLASH_CONFIG); | ||
return false; | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include <flash_utils.h> | ||
#include <MD5Builder.h> | ||
#include <functional> | ||
#include <erase_config.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arduino.h already includes this file always, now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
|
||
#define UPDATE_ERROR_OK (0) | ||
#define UPDATE_ERROR_WRITE (1) | ||
|
@@ -52,7 +53,7 @@ class UpdaterVerifyClass { | |
class UpdaterClass { | ||
public: | ||
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress; | ||
|
||
UpdaterClass(); | ||
~UpdaterClass(); | ||
|
||
|
@@ -65,6 +66,13 @@ class UpdaterClass { | |
*/ | ||
bool begin(size_t size, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW); | ||
|
||
#ifdef ERASE_CONFIG_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same #if comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
/* | ||
*/ | ||
inline void setEraseConfigOption(ERASE_CONFIG_MASK_t eraseOption) { | ||
_eraseConfigOption = eraseOption; | ||
} | ||
#endif | ||
/* | ||
Run Updater from asynchronous callbacs | ||
*/ | ||
|
@@ -181,7 +189,7 @@ class UpdaterClass { | |
bool _verifyHeader(uint8_t data); | ||
bool _verifyEnd(); | ||
|
||
void _setError(int error); | ||
void _setError(int error); | ||
|
||
bool _async = false; | ||
uint8_t _error = 0; | ||
|
@@ -199,6 +207,9 @@ class UpdaterClass { | |
int _ledPin = -1; | ||
uint8_t _ledOn; | ||
|
||
#ifdef ERASE_CONFIG_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ibid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
uint32_t _eraseConfigOption = ERASE_CONFIG_BLANK_BIN; | ||
#endif | ||
// Optional signed binary verification | ||
UpdaterHashClass *_hash = nullptr; | ||
UpdaterVerifyClass *_verify = nullptr; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the
Arduino.h
change,ERASE_CONFIG_H
seems like it is always defined. Therefore, can we remove the #if/#else/#endif blocking?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Back when I did this, I was asked to not add it to eboot because there was very little space left and other activities that needed the space. So, I tried to get the task done before the SDK started. There are three methods because I don't like any of them. Since it is a PoC I kept all the 3 ideas as methods to pick from. I was hoping for some indication of which one might be better.
RE: ERASE_CONFIG_H is more for development. I left it in since this is a PoC and it makes it clear where code is changing. Since the Arduino IDE does not have a flexible way of setting a global, it also makes it easy to remove the feature by editing Arduino.h.