Explorar o código

fix: Fix encryption support field in flash begin

This fixes the logic determining whether the flash begin command
contains the encryption field and moves to using
target properies instead of a hardcoded check.

Closes https://github.com/espressif/esp-serial-flasher/issues/65
Djordje Nedic %!s(int64=2) %!d(string=hai) anos
pai
achega
ac2edd5206
Modificáronse 3 ficheiros con 15 adicións e 7 borrados
  1. 1 1
      idf_component.yml
  2. 10 2
      src/esp_targets.c
  3. 4 4
      src/protocol_common.c

+ 1 - 1
idf_component.yml

@@ -1,3 +1,3 @@
-version: "0.2.0"
+version: "0.2.1"
 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

+ 10 - 2
src/esp_targets.c

@@ -55,6 +55,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0,            // Not used
         .chip_magic_value  = { 0xfff0c101, 0 },
         .read_spi_config = NULL,    // Not used
+        .encryption_in_begin_flash_cmd = false,
     },
 
     // ESP32
@@ -71,6 +72,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x3ff5A000,
         .chip_magic_value  = { 0x00f01d83, 0 },
         .read_spi_config = spi_config_esp32,
+        .encryption_in_begin_flash_cmd = false,
     },
 
     // ESP32S2
@@ -87,6 +89,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x3f41A000,
         .chip_magic_value  = { 0x000007c6, 0 },
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
 
     // ESP32C3
@@ -103,6 +106,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x60008800,
         .chip_magic_value = { 0x6921506f, 0x1b31506f },
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
 
     // ESP32S3
@@ -119,6 +123,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x60007000,
         .chip_magic_value = { 0x00000009, 0 },
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
 
     // ESP32C2
@@ -135,6 +140,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x60008800,
         .chip_magic_value = { 0x6f51306f, 0x7c41a06f },
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
     // ESP32H4
     {
@@ -150,6 +156,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x6001A000,
         .chip_magic_value = {0xca26cc22, 0x6881b06f}, // ESP32H4-BETA1, ESP32H4-BETA2
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
     // ESP32H2
     {
@@ -165,6 +172,7 @@ static const esp_target_t esp_target[ESP_MAX_CHIP] = {
         .efuse_base = 0x6001A000,
         .chip_magic_value = {0xd7b73e80, 0},
         .read_spi_config = spi_config_esp32xx,
+        .encryption_in_begin_flash_cmd = true,
     },
 };
 
@@ -257,7 +265,7 @@ static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_
     return ESP_LOADER_SUCCESS;
 }
 
-bool encryption_in_begin_flash_cmd(target_chip_t target)
+bool encryption_in_begin_flash_cmd(const target_chip_t target)
 {
-    return target == ESP32_CHIP || target == ESP8266_CHIP;
+    return esp_target[target].encryption_in_begin_flash_cmd;
 }

+ 4 - 4
src/protocol_common.c

@@ -59,13 +59,11 @@ esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,
                                           uint32_t blocks_to_write,
                                           bool encryption)
 {
-    uint32_t encryption_size = encryption ? sizeof(uint32_t) : 0;
-
     flash_begin_command_t flash_begin_cmd = {
         .common = {
             .direction = WRITE_DIRECTION,
             .command = FLASH_BEGIN,
-            .size = CMD_SIZE(flash_begin_cmd) - encryption_size,
+            .size = CMD_SIZE(flash_begin_cmd) - (encryption ? 0 : sizeof(uint32_t)),
             .checksum = 0
         },
         .erase_size = erase_size,
@@ -77,7 +75,9 @@ esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,
 
     s_sequence_number = 0;
 
-    return send_cmd(&flash_begin_cmd, sizeof(flash_begin_cmd) - encryption_size, NULL);
+    return send_cmd(&flash_begin_cmd,
+                    sizeof(flash_begin_cmd) - (encryption ? 0 : sizeof(uint32_t)),
+                    NULL);
 }