Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 8039a19

Browse files
committed
Handle the case when image copy fails
1 parent 83ea2cb commit 8039a19

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

esp32/ftp/updater.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ STATIC char *updater_read_file (const char *file_path, vstr_t *vstr) {
134134
return vstr->buf;
135135
}
136136

137-
void update_to_factory_partition(void) {
137+
bool update_to_factory_partition(void) {
138138

139+
// Size of the image used in 1.18.2r7 version
139140
updater_data.size = (1536*1024);
140141
updater_data.offset = IMG_FACTORY_OFFSET;
141142
updater_data.offset_start_upd = updater_data.offset;
@@ -144,10 +145,12 @@ void update_to_factory_partition(void) {
144145

145146
// erase the first 2 sectors
146147
if (ESP_OK != spi_flash_erase_sector(updater_data.offset / SPI_FLASH_SEC_SIZE)) {
147-
ESP_LOGE(TAG, "Erasing first sector failed!\n");
148+
ESP_LOGE(TAG, "Copying image from OTA_0 partition to Factory partition failed, erasing first sector failed!\n");
149+
return false;
148150
}
149151
if (ESP_OK != spi_flash_erase_sector((updater_data.offset + SPI_FLASH_SEC_SIZE) / SPI_FLASH_SEC_SIZE)) {
150-
ESP_LOGE(TAG, "Erasing second sector failed!\n");
152+
ESP_LOGE(TAG, "Copying image from OTA_0 partition to Factory partition failed, erasing second sector failed!\n");
153+
return false;
151154
}
152155

153156
uint32_t bytes_read = 0;
@@ -158,11 +161,14 @@ void update_to_factory_partition(void) {
158161
updater_spi_flash_read(IMG_UPDATE1_OFFSET_OLD + bytes_read, buf, SPI_FLASH_SEC_SIZE, false);
159162
bytes_read += SPI_FLASH_SEC_SIZE;
160163
if(false == updater_write(buf, SPI_FLASH_SEC_SIZE)){
161-
printf("update_to_factory_partition, updater_write returned FALSE\n");
164+
ESP_LOGE(TAG, "Copying image from OTA_0 partition to Factory partition failed!\n");
165+
return false;
162166
}
163167
}
164168

165169
updater_finish();
170+
171+
return true;
166172
}
167173

168174
bool updater_start (void) {

esp32/mptask.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static uint8_t *gc_pool_upy;
116116
static char fresh_main_py[] = "# main.py -- put your code here!\r\n";
117117
static char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n";
118118

119-
extern void update_to_factory_partition(void);
119+
extern bool update_to_factory_partition(void);
120120

121121
/******************************************************************************
122122
DEFINE PUBLIC FUNCTIONS
@@ -145,8 +145,10 @@ void TASK_Micropython (void *pvParameters) {
145145
}
146146
if(boot_info_local.ActiveImg != IMG_ACT_FACTORY) {
147147
printf("Copying image from OTA_0 partition to Factory partition, please wait...\n");
148-
update_to_factory_partition();
149-
printf("Image copy finished!\n");
148+
if(true == update_to_factory_partition()) {
149+
printf("Image copy finished successfully!\n");
150+
}
151+
150152
//Restart the system
151153
machine_wdt_start(100);
152154
for ( ; ; );

0 commit comments

Comments
 (0)