mirror of https://github.com/arendst/Tasmota.git
Refactor GUI fw upgrade
This commit is contained in:
parent
e105d5b4f4
commit
fab5f3ddc3
|
@ -2709,7 +2709,7 @@ void HandleUploadDone(void)
|
|||
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
||||
TasmotaGlobal.restart_flag = 2; // Always restart to re-enable disabled features during update
|
||||
|
||||
#if defined(USE_TASMOTA_CLIENT) || defined(SHELLY_FW_UPGRADE) || defined(USE_RF_FLASH)
|
||||
#ifdef USE_TASMOTA_CLIENT
|
||||
if (BUpload.ready) {
|
||||
WSContentSend_P(PSTR("<br><div style='text-align:center;'><b>" D_TRANSFER_STARTED " ...</b></div>"));
|
||||
TasmotaGlobal.restart_flag = 0; // Hold restart as code still needs to be transferred to STM
|
||||
|
@ -2728,16 +2728,6 @@ void HandleUploadDone(void)
|
|||
|
||||
#ifdef USE_WEB_FW_UPGRADE
|
||||
if (BUpload.ready) {
|
||||
#ifdef USE_RF_FLASH
|
||||
if (UPL_EFM8BB1 == Web.upload_file_type) {
|
||||
SnfBrFlash(BUploadStartSector() * SPI_FLASH_SEC_SIZE, BUpload.spi_hex_size);
|
||||
}
|
||||
#endif // USE_RF_FLASH
|
||||
#ifdef SHELLY_FW_UPGRADE
|
||||
if (UPL_SHD == Web.upload_file_type) {
|
||||
ShdFlash(BUploadStartSector() * SPI_FLASH_SEC_SIZE, BUpload.spi_hex_size);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_TASMOTA_CLIENT
|
||||
if (UPL_TASMOTACLIENT == Web.upload_file_type) {
|
||||
TasmotaClient_Flash(BUploadStartSector() * SPI_FLASH_SEC_SIZE, BUpload.spi_hex_size);
|
||||
|
@ -2925,7 +2915,32 @@ void HandleUploadLoop(void)
|
|||
#ifdef USE_WEB_FW_UPGRADE
|
||||
else if (BUpload.active) {
|
||||
// Done writing the hex to SPI flash
|
||||
BUpload.ready = true; // So we know on upload success page if it needs to flash hex or do a normal restart
|
||||
BUpload.ready = true; // So we know on upload success page if it needs to flash hex or do a normal restart
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD "Transfer %u bytes"), upload.totalSize);
|
||||
|
||||
uint8_t* data = (uint8_t*)(0x40200000 + (BUploadStartSector() * SPI_FLASH_SEC_SIZE));
|
||||
|
||||
// uint32_t* values = (uint32_t*)(data); // Only 4-byte access allowed
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Head 0x%08X"), values[0]);
|
||||
|
||||
uint32_t error = 0;
|
||||
#ifdef USE_RF_FLASH
|
||||
if (UPL_EFM8BB1 == Web.upload_file_type) {
|
||||
error = SnfBrUpdateFirmware(data, BUpload.spi_hex_size);
|
||||
BUploadDone();
|
||||
}
|
||||
#endif // USE_RF_FLASH
|
||||
#ifdef SHELLY_FW_UPGRADE
|
||||
else if (UPL_SHD == Web.upload_file_type) {
|
||||
error = ShdFlash(data, BUpload.spi_hex_size);
|
||||
BUploadDone();
|
||||
}
|
||||
#endif
|
||||
if (error != 0) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Transfer error %d"), error);
|
||||
Web.upload_error = 8; // File invalid
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif // USE_WEB_FW_UPGRADE
|
||||
else if (!Update.end(true)) { // true to set the size to the current progress
|
||||
|
|
|
@ -140,7 +140,7 @@ uint8_t rf_erase_flash(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32_t SnfBrUpdateFirmware(uint8_t* data, unsigned int size) {
|
||||
uint32_t SnfBrUpdateFirmware(uint8_t* data, uint32_t size) {
|
||||
pinMode(PIN_C2CK, OUTPUT);
|
||||
pinMode(PIN_C2D, INPUT);
|
||||
|
||||
|
@ -151,17 +151,6 @@ uint32_t SnfBrUpdateFirmware(uint8_t* data, unsigned int size) {
|
|||
|
||||
return rf_search_and_write(data, size);
|
||||
}
|
||||
|
||||
void SnfBrFlash(uint32_t data, size_t size) {
|
||||
// uint32_t* values = (uint32_t*)(0x40200000 + data);
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("RFB: Flash 0x%08X"), values[0]);
|
||||
|
||||
uint32_t error = SnfBrUpdateFirmware((uint8_t*)(0x40200000 + data), size); // Allow flash access without ESP.flashRead
|
||||
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("RFB: FW flash state %d"), error);
|
||||
|
||||
TasmotaGlobal.restart_flag = 2; // Restart to re-init stopped services
|
||||
}
|
||||
#endif // USE_RF_FLASH
|
||||
|
||||
/********************************************************************************************/
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
|
||||
#define XDRV_31 31
|
||||
|
||||
#ifndef USE_TASMOTA_CLIENT_FLASH_SPEED
|
||||
#define USE_TASMOTA_CLIENT_FLASH_SPEED 57600 // Usually 57600 for 3.3V variants and 115200 for 5V variants
|
||||
#endif
|
||||
#ifndef USE_TASMOTA_CLIENT_SERIAL_SPEED
|
||||
#define USE_TASMOTA_CLIENT_SERIAL_SPEED 57600 // Depends on the sketch that is running on the Uno/Pro Mini
|
||||
#endif
|
||||
|
||||
#define CONST_STK_CRC_EOP 0x20
|
||||
|
||||
#define CMND_STK_GET_SYNC 0x30
|
||||
|
@ -134,7 +141,6 @@ uint8_t SimpleHexParse::getByte(char* hexline, uint8_t idx) {
|
|||
struct TCLIENT {
|
||||
uint8_t inverted = LOW;
|
||||
bool type = false;
|
||||
bool flashing = false;
|
||||
bool SerialEnabled = false;
|
||||
uint8_t waitstate = 0; // We use this so that features detection does not slow down other stuff on startup
|
||||
bool unsupported = false;
|
||||
|
@ -320,25 +326,22 @@ void TasmotaClient_FlashPage(uint8_t addr_h, uint8_t addr_l, uint8_t* data) {
|
|||
TasmotaClient_Serial->read();
|
||||
}
|
||||
|
||||
void TasmotaClient_Flash(uint32_t data, size_t size) {
|
||||
bool reading = true;
|
||||
uint32_t TasmotaClient_Flash(uint32_t data, size_t size) {
|
||||
if (!TasmotaClient_SetupFlash()) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("TCL: Flashing aborted!"));
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t read = 0;
|
||||
uint32_t processed = 0;
|
||||
char thishexline[50];
|
||||
uint8_t position = 0;
|
||||
char* flash_buffer;
|
||||
|
||||
SimpleHexParse hexParse = SimpleHexParse();
|
||||
|
||||
if (!TasmotaClient_SetupFlash()) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("TCL: Flashing aborted!"));
|
||||
TClient.flashing = false;
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
flash_buffer = new char[SPI_FLASH_SEC_SIZE];
|
||||
char* flash_buffer = new char[SPI_FLASH_SEC_SIZE];
|
||||
uint32_t flash_start = data;
|
||||
bool reading = true;
|
||||
while (reading) {
|
||||
ESP.flashRead(flash_start + read, (uint32_t*)flash_buffer, SPI_FLASH_SEC_SIZE);
|
||||
read = read + SPI_FLASH_SEC_SIZE;
|
||||
|
@ -370,16 +373,8 @@ void TasmotaClient_Flash(uint32_t data, size_t size) {
|
|||
}
|
||||
TasmotaClient_exitProgMode();
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("TCL: Flash done!"));
|
||||
TClient.flashing = false;
|
||||
TasmotaGlobal.restart_flag = 2;
|
||||
}
|
||||
|
||||
void TasmotaClient_SetFlagFlashing(bool value) {
|
||||
TClient.flashing = value;
|
||||
}
|
||||
|
||||
bool TasmotaClient_GetFlagFlashing(void) {
|
||||
return TClient.flashing;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TasmotaClient_Init(void) {
|
||||
|
|
|
@ -130,7 +130,7 @@ void ShdResetToDFUMode()
|
|||
delay(50); // wait 50ms fot the co-processor to come online
|
||||
}
|
||||
|
||||
bool ShdUpdateFirmware(const uint8_t data[], unsigned int size)
|
||||
bool ShdUpdateFirmware(uint8_t* data, uint32_t size)
|
||||
{
|
||||
#ifdef SHELLY_DIMMER_DEBUG
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(SHD_LOGNAME "Update firmware"));
|
||||
|
@ -188,7 +188,7 @@ bool ShdPresent(void) {
|
|||
return Shd.present;
|
||||
}
|
||||
|
||||
void ShdFlash(uint32_t data, size_t size) {
|
||||
uint32_t ShdFlash(uint8_t* data, size_t size) {
|
||||
#ifdef SHELLY_DIMMER_DEBUG
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(SHD_LOGNAME "Updating firmware v%u.%u with %u bytes"), Shd.dimmer.version_major, Shd.dimmer.version_minor, size);
|
||||
#endif // SHELLY_DIMMER_DEBUG
|
||||
|
@ -196,17 +196,13 @@ void ShdFlash(uint32_t data, size_t size) {
|
|||
Serial.end();
|
||||
Serial.begin(115200, SERIAL_8E1);
|
||||
ShdResetToDFUMode();
|
||||
// uint32_t* values = (uint32_t*)(0x40200000 + data);
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(SHD_LOGNAME "Flash 0x%08X"), values[0]);
|
||||
ShdUpdateFirmware((uint8_t*)(0x40200000 + data), size); // Allow flash access without ESP.flashRead
|
||||
bool error = !ShdUpdateFirmware(data, size); // Allow flash access without ESP.flashRead
|
||||
Serial.end();
|
||||
|
||||
ShdResetToAppMode();
|
||||
Serial.begin(115200, SERIAL_8N1);
|
||||
|
||||
ShdSendVersion();
|
||||
|
||||
TasmotaGlobal.restart_flag = 2; // Restart to re-init stopped services
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // SHELLY_FW_UPGRADE
|
||||
|
|
Loading…
Reference in New Issue