]> granicus.if.org Git - esp-idf/commitdiff
esp32: cpu_start: read binary image header via cache
authorchenjianqiang <chenjianqiang@espressif.com>
Wed, 11 Sep 2019 08:40:08 +0000 (16:40 +0800)
committerbot <bot@espressif.com>
Wed, 9 Oct 2019 06:25:26 +0000 (06:25 +0000)
When flash encryption is enabled, reading via cache also decrypts the
data, whereas spi_flash_read does not.

components/esp32/cpu_start.c

index f691abb9e5d7b5a0bf6d462843fb5cc8fb1b23fd..a03a3102612ec586c602df0e09f84297462076bc 100644 (file)
@@ -433,10 +433,13 @@ void start_cpu0_default(void)
 #endif
 
     bootloader_flash_update_id();
-#if !CONFIG_SPIRAM_BOOT_INIT  // If psram is uninitialized, we need to improve some flash configuration.
-    esp_image_header_t fhdr;
-    const esp_partition_t *partition = esp_ota_get_running_partition();
-    spi_flash_read(partition->address, &fhdr, sizeof(esp_image_header_t));
+#if !CONFIG_SPIRAM_BOOT_INIT
+    // Read the application binary image header. This will also decrypt the header if the image is encrypted.
+    esp_image_header_t fhdr = {0};
+    // This assumes that DROM is the first segment in the application binary, i.e. that we can read
+    // the binary header through cache by accessing SOC_DROM_LOW address.
+    memcpy(&fhdr, (void*) SOC_DROM_LOW, sizeof(fhdr));
+    // If psram is uninitialized, we need to improve some flash configuration.
     bootloader_flash_clock_config(&fhdr);
     bootloader_flash_gpio_config(&fhdr);
     bootloader_flash_dummy_config(&fhdr);