OTA Flash erase bug... erased. release

This commit is contained in:
Sebastien
2019-11-12 18:00:49 -05:00
parent 1391897a3a
commit 7a3f78d8d2
4 changed files with 33 additions and 12 deletions

View File

@@ -102,6 +102,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
return ESP_OK; return ESP_OK;
} }
#endif #endif
esp_err_t err = ESP_OK;
bool bFound=false; bool bFound=false;
ESP_LOGI(TAG, "Looking for partition type %u",partition_subtype); ESP_LOGI(TAG, "Looking for partition type %u",partition_subtype);
const esp_partition_t *partition; const esp_partition_t *partition;
@@ -115,11 +116,18 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
{ {
partition = (esp_partition_t *) esp_partition_get(it); partition = (esp_partition_t *) esp_partition_get(it);
if(partition != NULL){ if(partition != NULL){
ESP_LOGI(TAG, "Found partition type %u",partition_subtype); ESP_LOGI(TAG, "Found application partition sub type %u",partition_subtype);
esp_ota_set_boot_partition(partition); err=esp_ota_set_boot_partition(partition);
if(err!=ESP_OK){
ESP_LOGE(TAG,"Unable to set partition as active for next boot. %s",esp_err_to_name(err));
set_status_message(ERROR, "Unable to select partition for reboot.");
}
else{
bFound=true; bFound=true;
set_status_message(WARNING, "Rebooting!"); set_status_message(WARNING, "Rebooting!");
} }
}
else else
{ {
ESP_LOGE(TAG,"partition type %u not found! Unable to reboot to recovery.",partition_subtype); ESP_LOGE(TAG,"partition type %u not found! Unable to reboot to recovery.",partition_subtype);

View File

@@ -6,6 +6,7 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_system.h" #include "esp_system.h"
@@ -37,7 +38,7 @@
#include "esp_ota_ops.h" #include "esp_ota_ops.h"
#define OTA_FLASH_ERASE_BLOCK (1024*100) #define OTA_FLASH_ERASE_BLOCK (4096*100)
static const char *TAG = "squeezelite-ota"; static const char *TAG = "squeezelite-ota";
extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start"); extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end"); extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
@@ -205,6 +206,7 @@ esp_err_t _erase_last_boot_app_partition(void)
{ {
uint16_t num_passes=0; uint16_t num_passes=0;
uint16_t remain_size=0; uint16_t remain_size=0;
uint16_t single_pass_size=0;
const esp_partition_t *ota_partition=NULL; const esp_partition_t *ota_partition=NULL;
const esp_partition_t *ota_data_partition=NULL; const esp_partition_t *ota_data_partition=NULL;
esp_err_t err=ESP_OK; esp_err_t err=ESP_OK;
@@ -246,14 +248,17 @@ esp_err_t _erase_last_boot_app_partition(void)
} }
ESP_LOGI(TAG,"Erasing flash "); ESP_LOGI(TAG,"Erasing flash ");
num_passes=ota_partition->size/OTA_FLASH_ERASE_BLOCK; num_passes=ota_partition->size/OTA_FLASH_ERASE_BLOCK;
single_pass_size= ota_partition->size/num_passes;
remain_size=ota_partition->size-(num_passes*OTA_FLASH_ERASE_BLOCK); remain_size=ota_partition->size-(num_passes*OTA_FLASH_ERASE_BLOCK);
for(uint16_t i=0;i<num_passes;i++){ for(uint16_t i=0;i<num_passes;i++){
err=esp_partition_erase_range(ota_partition, 0, ota_partition->size); err=esp_partition_erase_range(ota_partition, i*single_pass_size, single_pass_size);
ESP_LOGD(TAG,"Erasing flash (%u%%)",i/num_passes);
triggerStatusJsonRefresh(i%5==0?true:false,"Erasing flash (%u/%u)",i,num_passes);
taskYIELD();
if(err!=ESP_OK) return err; if(err!=ESP_OK) return err;
ESP_LOGD(TAG,"Erasing flash (%u%%)",i/num_passes);
ESP_LOGD(TAG,"Pass %d of %d, with chunks of %d bytes, from %d to %d", i+1, num_passes,single_pass_size,i*single_pass_size,i*single_pass_size+single_pass_size);
triggerStatusJsonRefresh(i%2==0?true:false,"Erasing flash (%u/%u)",i,num_passes);
taskYIELD();
} }
if(remain_size>0){ if(remain_size>0){
err=esp_partition_erase_range(ota_partition, ota_partition->size-remain_size, remain_size); err=esp_partition_erase_range(ota_partition, ota_partition->size-remain_size, remain_size);

View File

@@ -437,7 +437,7 @@ bool wait_for_commit(){
ESP_LOGI(TAG,"Config committed!"); ESP_LOGI(TAG,"Config committed!");
} }
} }
return commit_pending; return !commit_pending;
} }
bool config_lock(TickType_t xTicksToWait) { bool config_lock(TickType_t xTicksToWait) {
@@ -564,6 +564,12 @@ void config_delete_key(const char *key){
if(entry !=NULL){ if(entry !=NULL){
ESP_LOGI(TAG, "Removing config key [%s]", entry->string); ESP_LOGI(TAG, "Removing config key [%s]", entry->string);
cJSON_Delete(entry); cJSON_Delete(entry);
char * struc_str = cJSON_PrintUnformatted(nvs_json);
if(struc_str!=NULL){
ESP_LOGV(TAG, "Structure after delete \n%s", struc_str);
free(struc_str);
}
} }
else { else {
ESP_LOGW(TAG, "Unable to remove config key [%s]: not found.", key); ESP_LOGW(TAG, "Unable to remove config key [%s]: not found.", key);

View File

@@ -232,7 +232,6 @@ void app_main()
ESP_LOGD(TAG,"Clearing CONNECTED_BIT from wifi group"); ESP_LOGD(TAG,"Clearing CONNECTED_BIT from wifi group");
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
ESP_LOGI(TAG,"Starting app_main"); ESP_LOGI(TAG,"Starting app_main");
initialize_nvs(); initialize_nvs();
ESP_LOGI(TAG,"Setting up config subsystem."); ESP_LOGI(TAG,"Setting up config subsystem.");
@@ -275,15 +274,18 @@ void app_main()
wifi_manager_set_callback(EVENT_STA_GOT_IP, &cb_connection_got_ip); wifi_manager_set_callback(EVENT_STA_GOT_IP, &cb_connection_got_ip);
wifi_manager_set_callback(WIFI_EVENT_STA_DISCONNECTED, &cb_connection_sta_disconnected); wifi_manager_set_callback(WIFI_EVENT_STA_DISCONNECTED, &cb_connection_sta_disconnected);
} }
console_start(); console_start();
if(fwurl && strlen(fwurl)>0){ if(fwurl && strlen(fwurl)>0){
#if RECOVERY_APPLICATION
while(!bWifiConnected){ while(!bWifiConnected){
wait_for_wifi(); wait_for_wifi();
taskYIELD(); taskYIELD();
} }
ESP_LOGI(TAG,"Updating firmware from link: %s",fwurl); ESP_LOGI(TAG,"Updating firmware from link: %s",fwurl);
start_ota(fwurl, true); start_ota(fwurl, true);
#else
ESP_LOGE(TAG,"Restarted to application partition. We're not going to perform OTA!");
#endif
free(fwurl); free(fwurl);
} }
} }