]> granicus.if.org Git - esp-idf/commitdiff
esp_partition: disable encrypted reads/writes if flash encryption is disabled
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 10 Jan 2019 13:51:09 +0000 (21:51 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 10 Jan 2019 13:51:09 +0000 (21:51 +0800)
Saves 400 bytes of IRAM.

components/spi_flash/partition.c

index 4d39d15005db0ed789ef724c8890bcc4d078daf4..7f546e99334ffcdbac09b6e2b07633a395578fc4 100644 (file)
@@ -241,6 +241,7 @@ esp_err_t esp_partition_read(const esp_partition_t* partition,
     if (!partition->encrypted) {
         return spi_flash_read(partition->address + src_offset, dst, size);
     } else {
+#if CONFIG_FLASH_ENCRYPTION_ENABLED
         /* Encrypted partitions need to be read via a cache mapping */
         const void *buf;
         spi_flash_mmap_handle_t handle;
@@ -254,6 +255,9 @@ esp_err_t esp_partition_read(const esp_partition_t* partition,
         memcpy(dst, buf, size);
         spi_flash_munmap(handle);
         return ESP_OK;
+#else
+        return ESP_ERR_NOT_SUPPORTED;
+#endif // CONFIG_FLASH_ENCRYPTION_ENABLED
     }
 }
 
@@ -268,10 +272,14 @@ esp_err_t esp_partition_write(const esp_partition_t* partition,
         return ESP_ERR_INVALID_SIZE;
     }
     dst_offset = partition->address + dst_offset;
-    if (partition->encrypted) {
-        return spi_flash_write_encrypted(dst_offset, src, size);
-    } else {
+    if (!partition->encrypted) {
         return spi_flash_write(dst_offset, src, size);
+    } else {
+#if CONFIG_FLASH_ENCRYPTION_ENABLED
+        return spi_flash_write_encrypted(dst_offset, src, size);
+#else
+        return ESP_ERR_NOT_SUPPORTED;
+#endif // CONFIG_FLASH_ENCRYPTION_ENABLED
     }
 }