2020#include <hal/spi_flash_hal.h>
2121#include <soc/spi_struct.h>
2222#include <spi_flash_defs.h>
23+ #include <esp_flash_encrypt.h>
2324
2425#include <kernel.h>
2526#include <device.h>
@@ -81,8 +82,14 @@ static inline void flash_esp32_sem_give(const struct device *dev)
8182
8283static int flash_esp32_read (const struct device * dev , off_t address , void * buffer , size_t length )
8384{
85+ int ret = 0 ;
86+
8487 flash_esp32_sem_take (dev );
85- int ret = spi_flash_read (address , buffer , length );
88+ if (!esp_flash_encryption_enabled ()) {
89+ ret = spi_flash_read (address , buffer , length );
90+ } else {
91+ ret = spi_flash_read_encrypted (address , buffer , length );
92+ }
8693 flash_esp32_sem_give (dev );
8794 return ret ;
8895}
@@ -92,8 +99,14 @@ static int flash_esp32_write(const struct device *dev,
9299 const void * buffer ,
93100 size_t length )
94101{
102+ int ret = 0 ;
103+
95104 flash_esp32_sem_take (dev );
96- int ret = spi_flash_write (address , buffer , length );
105+ if (!esp_flash_encryption_enabled ()) {
106+ ret = spi_flash_write (address , buffer , length );
107+ } else {
108+ ret = spi_flash_write_encrypted (address , buffer , length );
109+ }
97110 flash_esp32_sem_give (dev );
98111 return ret ;
99112}
0 commit comments