Skip to content
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

Draft
wants to merge 64 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6fde10f
Proof of concept for post OTA 1st boot erase config.
mhightower83 Dec 28, 2019
93fb3d3
Added a 2nd method
mhightower83 Dec 30, 2019
c66ae2e
Merge branch 'master' into pr-erase-config
mhightower83 Dec 30, 2019
6d882e4
Added two_shots init to noextra4k
mhightower83 Dec 30, 2019
500b7cc
Removed cleaned up debug crud and added test example.
mhightower83 Dec 31, 2019
afd603b
Merge branch 'master' into pr-erase-config
mhightower83 Dec 31, 2019
bfb21b1
A proof of concept for handling Erase WiFi Setting after OTA
mhightower83 Dec 31, 2019
e51ab08
Addressed Tavis CI style issues.
mhightower83 Dec 31, 2019
a284b0a
Take two
mhightower83 Dec 31, 2019
3258d63
Merge branch 'master' into pr-erase-config
mhightower83 Jan 6, 2020
9d6e059
Merge branch 'master' into pr-erase-config
mhightower83 Jan 8, 2020
95eefed
Update example. Removed some debug crud. Added a Flash Info hotkey op…
mhightower83 Jan 8, 2020
815f1dc
Merge branch 'master' into pr-erase-config
mhightower83 Jan 9, 2020
660d19c
Merge branch 'master' into pr-erase-config
mhightower83 Jan 9, 2020
4554a7c
style fix
mhightower83 Jan 9, 2020
1ce4c60
Merge branch 'master' into pr-erase-config
mhightower83 Jan 16, 2020
7130877
Merge branch 'master' into pr-erase-config
mhightower83 Jan 23, 2020
73f16dc
Merge branch 'master' into pr-erase-config
mhightower83 Jan 28, 2020
9c4e44b
Added print messages to show progress.
mhightower83 Feb 6, 2020
546f0cb
Merge branch 'master' into pr-erase-config
mhightower83 Feb 6, 2020
560ddc5
Set default Method to 2, to side step travis issue of using preinit().
mhightower83 Feb 7, 2020
049d91b
Added a Third method.
mhightower83 Feb 18, 2020
4e2493a
Resolve merge conflict.
mhightower83 Feb 19, 2020
39160c8
one more :(
mhightower83 Feb 19, 2020
c0394fb
Merge branch 'master' into pr-erase-config
mhightower83 Feb 19, 2020
f1acb40
Access bin image header through ICACHE reduces IRAM usage by 16.
mhightower83 Feb 19, 2020
604b40a
Merge branch 'master' into pr-erase-config
mhightower83 Feb 21, 2020
4553009
Made function name longer to avoid possible name conflicts in the fut…
mhightower83 Feb 22, 2020
372998c
Merge branch 'master' into pr-erase-config
mhightower83 Mar 11, 2020
39b9508
CI issues
mhightower83 Mar 11, 2020
4954dcd
Merge branch 'master' into pr-erase-config
mhightower83 Mar 17, 2020
828a47d
Merge branch 'master' into pr-erase-config
mhightower83 Mar 27, 2020
b2d35ea
Merge branch 'master' into pr-erase-config
mhightower83 Apr 9, 2020
74129c5
Merge branch 'master' into pr-erase-config
mhightower83 Apr 16, 2020
14fede0
Merge branch 'master' into pr-erase-config
mhightower83 Apr 28, 2020
be5fe6d
Merge branch 'master' into pr-erase-config
mhightower83 May 5, 2020
cfd54df
Merge branch 'master' into pr-erase-config
mhightower83 May 16, 2020
6f91be0
Merge branch 'master' into pr-erase-config
mhightower83 May 31, 2020
6b1cdb8
Merge branch 'master' into pr-erase-config
mhightower83 Jun 4, 2020
fcb8b21
Merge branch 'master' into pr-erase-config
mhightower83 Jun 19, 2020
c40a873
Merge branch 'master' into pr-erase-config
mhightower83 Jul 7, 2020
2b2def2
Corrected new errors after upgrade to GCC 10.1 toolchain.
mhightower83 Jul 10, 2020
48ed5e9
Merge branch 'master' into pr-erase-config
devyte Jul 22, 2020
b211727
Merge branch 'master' into pr-erase-config
mhightower83 Sep 2, 2020
ab9b6b2
Corrected manual merge error, with init order of class.
mhightower83 Sep 2, 2020
e5539fe
Merge branch 'master' into pr-erase-config
mhightower83 Sep 17, 2020
502d8bc
Merge branch 'master' into pr-erase-config
mhightower83 Oct 2, 2020
f50b3a6
Merge branch 'master' into pr-erase-config
mhightower83 Nov 11, 2020
94365e1
Fixed merge errors and code rot.
mhightower83 Nov 11, 2020
5234f3f
Updated wifi_health_t and WiFiDisconnectLog_t to take
mhightower83 Nov 11, 2020
025bb2f
Merge branch 'master' into pr-erase-config
mhightower83 Dec 8, 2020
edade1c
Merge branch 'master' into pr-erase-config
mhightower83 Dec 29, 2020
24a117c
Merge branch 'master' into pr-erase-config
d-a-v Feb 19, 2021
4e31c91
Merge branch 'master' into pr-erase-config
mhightower83 Mar 14, 2021
0b01518
Replaced ROM_uart_div_modify and associated logic, with the current
mhightower83 Mar 14, 2021
f9a3f95
Merge branch 'master' into pr-erase-config
devyte Apr 3, 2021
217b2d2
Cleanup merge conflict. Now use IRAM_ATTR and _NOINLINE_STATIC w/o ch…
mhightower83 Apr 3, 2021
0b7fced
Merge branch 'master' into pr-erase-config
mhightower83 Jul 28, 2021
9f0e220
Merge branch 'master' into pr-erase-config
mhightower83 Aug 8, 2021
e44e752
Merge branch 'master' into pr-erase-config
mhightower83 Aug 21, 2021
c44a3f9
Changed to comply with strict-aliasing rules. Changes based on discus…
mhightower83 Aug 22, 2021
63a2048
Merge branch 'pr-erase-config' of github.com:mhightower83/Arduino int…
mhightower83 Aug 22, 2021
21b0154
Merge branch 'master' into pr-erase-config
mhightower83 Dec 21, 2021
fb05f15
Merge branch 'master' into pr-erase-config
mhightower83 May 2, 2022
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: 1 addition & 0 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C" {

#include "core_esp8266_features.h"
#include "core_esp8266_version.h"
#include "erase_config.h"

#define HIGH 0x1
#define LOW 0x0
Expand Down
31 changes: 31 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,36 @@ FlashMode_t EspClass::getFlashChipMode(void)
return mode;
}

#ifdef ERASE_CONFIG_H
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

// This change is only needed for method 3
extern "C" uint32_t esp_c_magic_flash_chip_size(uint8_t byte)
{
switch(byte & 0x0F) {
case 0x0: // 4 Mbit (512KB)
return (512_kB);
case 0x1: // 2 MBit (256KB)
return (256_kB);
case 0x2: // 8 MBit (1MB)
return (1_MB);
case 0x3: // 16 MBit (2MB)
return (2_MB);
case 0x4: // 32 MBit (4MB)
return (4_MB);
case 0x8: // 64 MBit (8MB)
return (8_MB);
case 0x9: // 128 MBit (16MB)
return (16_MB);
default: // fail?
return 0;
}
}

uint32_t EspClass::magicFlashChipSize(uint8_t byte)
{
return esp_c_magic_flash_chip_size(byte);
}

#else
uint32_t EspClass::magicFlashChipSize(uint8_t byte) {
switch(byte & 0x0F) {
case 0x0: // 4 Mbit (512KB)
Expand All @@ -345,6 +375,7 @@ uint32_t EspClass::magicFlashChipSize(uint8_t byte) {
return 0;
}
}
#endif

uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
switch(byte & 0x0F) {
Expand Down
25 changes: 19 additions & 6 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERASE_CONFIG_H always defined, drop the condition (leaving host_mock)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"));
Expand All @@ -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."));
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -298,10 +303,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
Expand All @@ -311,6 +323,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] = (uintptr_t)&_FS_start - 0x40200000;
Expand Down Expand Up @@ -359,7 +372,7 @@ bool UpdaterClass::_writeBuffer(){
modifyFlashMode = true;
}
}

if (eraseResult) {
if(!_async) yield();
writeResult = ESP.flashWrite(_currentAddress, _buffer, _bufferLen);
Expand Down Expand Up @@ -443,7 +456,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;
}

Expand All @@ -455,7 +468,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;
}

Expand All @@ -464,7 +477,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;
}

Expand Down
15 changes: 13 additions & 2 deletions cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <flash_utils.h>
#include <MD5Builder.h>
#include <functional>
#include <erase_config.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arduino.h already includes this file always, now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay


#define UPDATE_ERROR_OK (0)
#define UPDATE_ERROR_WRITE (1)
Expand Down Expand Up @@ -52,7 +53,7 @@ class UpdaterVerifyClass {
class UpdaterClass {
public:
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;

UpdaterClass();
~UpdaterClass();

Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same #if comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
*/
Expand Down Expand Up @@ -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;
Expand All @@ -199,6 +207,9 @@ class UpdaterClass {
int _ledPin = -1;
uint8_t _ledOn;

#ifdef ERASE_CONFIG_H
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ibid

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Expand Down
20 changes: 20 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ void init_done() {
https:/esp8266/Arduino/pull/4889

*/
#if defined(DEBUG_ERASE_CONFIG)
extern "C" void erase_config__fix_divider(void);
#define ERASE_CFG__FIX_DIVIDER erase_config__fix_divider
#define ERASE_CFG__ETS_PRINTF(...) ets_uart_printf(__VA_ARGS__)
#define ERASE_CFG__ETS_DELAY_US(a) ets_delay_us(a)
#else
#define ERASE_CFG__FIX_DIVIDER() do {} while(0)
#define ERASE_CFG__ETS_PRINTF(...) do {} while(0)
#define ERASE_CFG__ETS_DELAY_US(a) do {} while(0)
#endif


extern "C" void app_entry_redefinable(void) __attribute__((weak));
extern "C" void app_entry_redefinable(void)
Expand All @@ -318,6 +329,9 @@ extern "C" void app_entry_redefinable(void)
cont_t s_cont __attribute__((aligned(16)));
g_pcont = &s_cont;

ERASE_CFG__FIX_DIVIDER();
ERASE_CFG__ETS_PRINTF("\n\ncall_user_start()\n");

/* Call the entry point of the SDK code. */
call_user_start();
}
Expand All @@ -339,7 +353,13 @@ extern "C" void user_init(void) {
struct rst_info *rtc_info_ptr = system_get_rst_info();
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));

#if defined(DEBUG_ERASE_CONFIG)
uart_div_modify(0, UART_CLK_FREQ / (74880));
ERASE_CFG__ETS_DELAY_US(150);
ERASE_CFG__ETS_PRINTF("\nuser_init()\n");
#else
uart_div_modify(0, UART_CLK_FREQ / (115200));
#endif

init(); // in core_esp8266_wiring.c, inits hw regs and sdk timer

Expand Down
Loading