mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Fix ESP32-C3 safeboot upload
This commit is contained in:
parent
a7439cf853
commit
d6e5c89463
@ -269,6 +269,17 @@ void QPCWrite(const void *pSettings, unsigned nSettingsLen) {
|
|||||||
NvmSave("qpc", "pcreg", pSettings, nSettingsLen);
|
NvmSave("qpc", "pcreg", pSettings, nSettingsLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OtaFactoryRead(void) {
|
||||||
|
uint32_t pOtaLoader;
|
||||||
|
NvmLoad("otal", "otal", &pOtaLoader, sizeof(pOtaLoader));
|
||||||
|
return pOtaLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OtaFactoryWrite(bool value) {
|
||||||
|
uint32_t pOtaLoader = value;
|
||||||
|
NvmSave("otal", "otal", &pOtaLoader, sizeof(pOtaLoader));
|
||||||
|
}
|
||||||
|
|
||||||
void NvsInfo(void) {
|
void NvsInfo(void) {
|
||||||
nvs_stats_t nvs_stats;
|
nvs_stats_t nvs_stats;
|
||||||
nvs_get_stats(NULL, &nvs_stats);
|
nvs_get_stats(NULL, &nvs_stats);
|
||||||
|
@ -1175,6 +1175,9 @@ void Every250mSeconds(void)
|
|||||||
if (TasmotaGlobal.ota_state_flag && CommandsReady()) {
|
if (TasmotaGlobal.ota_state_flag && CommandsReady()) {
|
||||||
TasmotaGlobal.ota_state_flag--;
|
TasmotaGlobal.ota_state_flag--;
|
||||||
if (2 == TasmotaGlobal.ota_state_flag) {
|
if (2 == TasmotaGlobal.ota_state_flag) {
|
||||||
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
OtaFactoryWrite(false);
|
||||||
|
#endif
|
||||||
RtcSettings.ota_loader = 0; // Try requested image first
|
RtcSettings.ota_loader = 0; // Try requested image first
|
||||||
ota_retry_counter = OTA_ATTEMPTS;
|
ota_retry_counter = OTA_ATTEMPTS;
|
||||||
SettingsSave(1); // Free flash for OTA update
|
SettingsSave(1); // Free flash for OTA update
|
||||||
@ -1246,6 +1249,9 @@ void Every250mSeconds(void)
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#ifndef FIRMWARE_MINIMAL
|
#ifndef FIRMWARE_MINIMAL
|
||||||
if (EspSingleOtaPartition()) {
|
if (EspSingleOtaPartition()) {
|
||||||
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
OtaFactoryWrite(true);
|
||||||
|
#endif
|
||||||
RtcSettings.ota_loader = 1; // Try safeboot image next
|
RtcSettings.ota_loader = 1; // Try safeboot image next
|
||||||
SettingsSaveAll();
|
SettingsSaveAll();
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING));
|
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING));
|
||||||
@ -1413,10 +1419,19 @@ void Every250mSeconds(void)
|
|||||||
case 3: // Every x.75 second
|
case 3: // Every x.75 second
|
||||||
if (!TasmotaGlobal.global_state.network_down) {
|
if (!TasmotaGlobal.global_state.network_down) {
|
||||||
#ifdef FIRMWARE_MINIMAL
|
#ifdef FIRMWARE_MINIMAL
|
||||||
|
|
||||||
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
if (OtaFactoryRead()) {
|
||||||
|
OtaFactoryWrite(false);
|
||||||
|
TasmotaGlobal.ota_state_flag = 3;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (1 == RtcSettings.ota_loader) {
|
if (1 == RtcSettings.ota_loader) {
|
||||||
RtcSettings.ota_loader = 0;
|
RtcSettings.ota_loader = 0;
|
||||||
TasmotaGlobal.ota_state_flag = 3;
|
TasmotaGlobal.ota_state_flag = 3;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // FIRMWARE_MINIMAL
|
#endif // FIRMWARE_MINIMAL
|
||||||
|
|
||||||
#ifdef USE_DISCOVERY
|
#ifdef USE_DISCOVERY
|
||||||
|
@ -63,9 +63,9 @@ size_t FlashWriteSubSector(uint32_t address_start, const uint8_t *data, size_t s
|
|||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Native functions mapped to Berry functions
|
* Native functions mapped to Berry functions
|
||||||
*
|
*
|
||||||
* import flash
|
* import flash
|
||||||
*
|
*
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// Berry: `flash.read(address:int[, length:int]) -> bytes()`
|
// Berry: `flash.read(address:int[, length:int]) -> bytes()`
|
||||||
@ -74,7 +74,7 @@ extern "C" {
|
|||||||
int32_t p_flash_read(struct bvm *vm);
|
int32_t p_flash_read(struct bvm *vm);
|
||||||
int32_t p_flash_read(struct bvm *vm) {
|
int32_t p_flash_read(struct bvm *vm) {
|
||||||
int32_t argc = be_top(vm); // Get the number of arguments
|
int32_t argc = be_top(vm); // Get the number of arguments
|
||||||
if (argc >= 1 && be_isint(vm, 1) &&
|
if (argc >= 1 && be_isint(vm, 1) &&
|
||||||
(argc < 2 || be_isint(vm, 2)) ) { // optional second argument must be int
|
(argc < 2 || be_isint(vm, 2)) ) { // optional second argument must be int
|
||||||
uint32_t address = be_toint(vm, 1);
|
uint32_t address = be_toint(vm, 1);
|
||||||
uint32_t length = 0x1000;
|
uint32_t length = 0x1000;
|
||||||
@ -146,6 +146,9 @@ extern "C" {
|
|||||||
esp_partition_erase_range(otadata_partition, 0, SPI_FLASH_SEC_SIZE * 2);
|
esp_partition_erase_range(otadata_partition, 0, SPI_FLASH_SEC_SIZE * 2);
|
||||||
}
|
}
|
||||||
if (force_ota) {
|
if (force_ota) {
|
||||||
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
|
OtaFactoryWrite(true);
|
||||||
|
#endif
|
||||||
RtcSettings.ota_loader = 1; // force OTA at next reboot
|
RtcSettings.ota_loader = 1; // force OTA at next reboot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user