Просмотр исходного кода

Merge branch 'feature/add_block_write_retries' into 'master'

feature: Add block write retries

Closes ESF-73

See merge request espressif/esp-serial-flasher!79
Roland Dobai 2 лет назад
Родитель
Сommit
98e75da303
7 измененных файлов с 54 добавлено и 6 удалено
  1. 18 1
      CMakeLists.txt
  2. 4 0
      Kconfig
  3. 6 0
      README.md
  4. 1 1
      idf_component.yml
  5. 18 4
      src/esp_loader.c
  6. 1 0
      test/CMakeLists.txt
  7. 6 0
      zephyr/CMakeLists.txt

+ 18 - 1
CMakeLists.txt

@@ -116,4 +116,21 @@ else()
             SERIAL_FLASHER_BOOT_HOLD_TIME_MS=50
             SERIAL_FLASHER_BOOT_HOLD_TIME_MS=50
         )
         )
     endif()
     endif()
-endif()
+endif()
+
+if (DEFINED CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES)
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
+    )
+elseif (DEFINED SERIAL_FLASHER_WRITE_BLOCK_RETRIES)
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
+    )
+else()
+    target_compile_definitions(${target}
+    PUBLIC
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=3
+    )
+endif()

+ 4 - 0
Kconfig

@@ -31,4 +31,8 @@ menu "ESP serial flasher"
         bool "Enable debug tracing output (only transfer data tracing is supported at the time)"
         bool "Enable debug tracing output (only transfer data tracing is supported at the time)"
         default n
         default n
 
 
+    config SERIAL_FLASHER_WRITE_BLOCK_RETRIES
+        int "Number of retries when writing blocks either to target flash or RAM"
+        default 3
+
 endmenu
 endmenu

+ 6 - 0
README.md

@@ -69,6 +69,12 @@ If enabled, `esp-serial-flasher` is capable of verifying flash integrity after w
 Default: Enabled
 Default: Enabled
 > Warning: As ROM bootloader of the ESP8266 does not support MD5_CHECK, this option has to be disabled!
 > Warning: As ROM bootloader of the ESP8266 does not support MD5_CHECK, this option has to be disabled!
 
 
+* `SERIAL_FLASHER_WRITE_BLOCK_RETRIES`
+
+This configures the amount of retries for writing blocks either to target flash or RAM.
+
+Default: 3
+
 * `SERIAL_FLASHER_RESET_HOLD_TIME_MS`
 * `SERIAL_FLASHER_RESET_HOLD_TIME_MS`
 
 
 This is the time for which the reset pin is asserted when doing a hard reset in milliseconds.
 This is the time for which the reset pin is asserted when doing a hard reset in milliseconds.

+ 1 - 1
idf_component.yml

@@ -1,3 +1,3 @@
-version: "0.3.1"
+version: "0.4.0"
 description: Serial flasher component provides portable library for flashing or loading ram loadble app to Espressif SoCs from other host microcontroller
 description: Serial flasher component provides portable library for flashing or loading ram loadble app to Espressif SoCs from other host microcontroller
 url: https://github.com/espressif/esp-serial-flasher
 url: https://github.com/espressif/esp-serial-flasher

+ 18 - 4
src/esp_loader.c

@@ -292,9 +292,15 @@ esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size)
 
 
     md5_update(payload, (size + 3) & ~3);
     md5_update(payload, (size + 3) & ~3);
 
 
-    loader_port_start_timer(DEFAULT_TIMEOUT);
+    unsigned int attempt = 0;
+    esp_loader_error_t result = ESP_LOADER_ERROR_FAIL;
+    do {
+        loader_port_start_timer(DEFAULT_TIMEOUT);
+        result = loader_flash_data_cmd(data, s_flash_write_size);
+        attempt++;
+    } while (result != ESP_LOADER_SUCCESS && attempt < SERIAL_FLASHER_WRITE_BLOCK_RETRIES);
 
 
-    return loader_flash_data_cmd(data, s_flash_write_size);
+    return result;
 }
 }
 
 
 
 
@@ -317,8 +323,16 @@ esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t
 esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size)
 esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size)
 {
 {
     const uint8_t *data = (const uint8_t *)payload;
     const uint8_t *data = (const uint8_t *)payload;
-    loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB));
-    return loader_mem_data_cmd(data, size);
+    
+    unsigned int attempt = 0;
+    esp_loader_error_t result = ESP_LOADER_ERROR_FAIL;
+    do {
+        loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB));
+        result = loader_mem_data_cmd(data, size);
+        attempt++;
+    } while (result != ESP_LOADER_SUCCESS && attempt < SERIAL_FLASHER_WRITE_BLOCK_RETRIES);
+    
+    return result;
 }
 }
 
 
 
 

+ 1 - 0
test/CMakeLists.txt

@@ -26,4 +26,5 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
 	MD5_ENABLED=1
 	MD5_ENABLED=1
 	SERIAL_FLASHER_INTERFACE_UART
 	SERIAL_FLASHER_INTERFACE_UART
 	SERIAL_FLASHER_DEBUG_TRACE
 	SERIAL_FLASHER_DEBUG_TRACE
+	SERIAL_FLASHER_WRITE_BLOCK_RETRIES=1
 )
 )

+ 6 - 0
zephyr/CMakeLists.txt

@@ -27,4 +27,10 @@ if (CONFIG_ESP_SERIAL_FLASHER)
     if(DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
     if(DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
         target_compile_definitions(esp_flasher INTERFACE -DMD5_ENABLED=1)
         target_compile_definitions(esp_flasher INTERFACE -DMD5_ENABLED=1)
     endif()
     endif()
+
+    target_compile_definitions(esp_flasher
+    INTERFACE
+        SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
+    )
+
 endif()
 endif()