kopia lustrzana https://github.com/espressif/esp-idf
spiflash: Add spi_flash_read_encrypted() function
rodzic
fbe89a0833
commit
95c150fe2c
|
@ -381,6 +381,33 @@ out:
|
|||
return spi_flash_translate_rc(rc);
|
||||
}
|
||||
|
||||
#define FLASH_PAGE_SIZE 0x10000
|
||||
|
||||
esp_err_t IRAM_ATTR spi_flash_read_encrypted(size_t src, void *dstv, size_t size)
|
||||
{
|
||||
if (src + size > g_rom_flashchip.chip_size) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
if (size == 0) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t err;
|
||||
const uint8_t *map;
|
||||
spi_flash_mmap_handle_t map_handle;
|
||||
size_t map_src = src & ~(FLASH_PAGE_SIZE-1);
|
||||
size_t map_size = size + (src - map_src);
|
||||
|
||||
err = spi_flash_mmap(map_src, map_size, SPI_FLASH_MMAP_DATA, (const void **)&map, &map_handle);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
memcpy(dstv, map + (src - map_src), size);
|
||||
spi_flash_munmap(map_handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static esp_err_t spi_flash_translate_rc(SpiFlashOpResult rc)
|
||||
{
|
||||
switch (rc) {
|
||||
|
|
|
@ -116,6 +116,23 @@ esp_err_t spi_flash_write_encrypted(size_t dest_addr, const void *src, size_t si
|
|||
*/
|
||||
esp_err_t spi_flash_read(size_t src_addr, void *dest, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read data from Encrypted Flash.
|
||||
*
|
||||
* If flash encryption is enabled, this function will transparently decrypt data as it is read.
|
||||
* If flash encryption is not enabled, this function behaves the same as spi_flash_read().
|
||||
*
|
||||
* See @ref esp_flash_encryption_enabled() for a function to check if flash encryption is enabled.
|
||||
*
|
||||
* @param src source address of the data in Flash.
|
||||
* @param dest pointer to the destination buffer
|
||||
* @param size length of data
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t spi_flash_read_encrypted(size_t src, void *dstv, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Enumeration which specifies memory space requested in an mmap call
|
||||
*/
|
||||
|
|
Ładowanie…
Reference in New Issue