Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/esp32s3_partition: Read data from SPI Flash with decryption #15470

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions arch/xtensa/src/esp32s3/esp32s3_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,54 @@ int esp32s3_partition_read(const char *label, size_t offset, void *buf,
return OK;
}

/****************************************************************************
* Name: esp32s3_partition_read_decrypt
*
* Description:
* Read data from SPI Flash at designated address (with decryption)
*
* Input Parameters:
* label - Partition label
* offset - Offset in SPI Flash
* buf - Data buffer pointer
* size - Data number
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/

int esp32s3_partition_read_decrypt(const char *label, size_t offset,
void *buf, size_t size)
{
int ret;
int partion_offset;
DEBUGASSERT(label != NULL && buf != NULL);
struct mtd_dev_s *mtd = esp32s3_spiflash_encrypt_mtd();
if (!mtd)
{
ferr("ERROR: Failed to get SPI flash MTD\n");
return -ENOSYS;
}

partion_offset = partition_get_offset(label, strlen(label));
if (partion_offset < 0)
{
ferr("ERROR: Failed to get partition: %s offset\n", label);
return partion_offset;
}

ret = MTD_READ(mtd, partion_offset + offset,
size, (uint8_t *)buf);
if (ret != size)
{
ferr("ERROR: Failed to get read data from MTD\n");
return -EIO;
}

return OK;
}

/****************************************************************************
* Name: esp32s3_partition_write
*
Expand Down
Loading