drivers: flash: esp32: add flash encryption support
Add flash encryption function check to redirect flash write and read calls properly. Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
parent
6c6b688b91
commit
7022dcfd95
1 changed files with 15 additions and 2 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <hal/spi_flash_hal.h>
|
#include <hal/spi_flash_hal.h>
|
||||||
#include <soc/spi_struct.h>
|
#include <soc/spi_struct.h>
|
||||||
#include <spi_flash_defs.h>
|
#include <spi_flash_defs.h>
|
||||||
|
#include <esp_flash_encrypt.h>
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -81,8 +82,14 @@ static inline void flash_esp32_sem_give(const struct device *dev)
|
||||||
|
|
||||||
static int flash_esp32_read(const struct device *dev, off_t address, void *buffer, size_t length)
|
static int flash_esp32_read(const struct device *dev, off_t address, void *buffer, size_t length)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
flash_esp32_sem_take(dev);
|
flash_esp32_sem_take(dev);
|
||||||
int ret = spi_flash_read(address, buffer, length);
|
if (!esp_flash_encryption_enabled()) {
|
||||||
|
ret = spi_flash_read(address, buffer, length);
|
||||||
|
} else {
|
||||||
|
ret = spi_flash_read_encrypted(address, buffer, length);
|
||||||
|
}
|
||||||
flash_esp32_sem_give(dev);
|
flash_esp32_sem_give(dev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -92,8 +99,14 @@ static int flash_esp32_write(const struct device *dev,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
flash_esp32_sem_take(dev);
|
flash_esp32_sem_take(dev);
|
||||||
int ret = spi_flash_write(address, buffer, length);
|
if (!esp_flash_encryption_enabled()) {
|
||||||
|
ret = spi_flash_write(address, buffer, length);
|
||||||
|
} else {
|
||||||
|
ret = spi_flash_write_encrypted(address, buffer, length);
|
||||||
|
}
|
||||||
flash_esp32_sem_give(dev);
|
flash_esp32_sem_give(dev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue