You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "sdc-g (via GitHub)" <gi...@apache.org> on 2025/01/02 08:48:53 UTC
[PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
sdc-g opened a new pull request, #15399:
URL: https://github.com/apache/nuttx/pull/15399
## Summary
porting of spi_flash_chip_generic_write_encrypted from ESP-IDF
## Impact
Use spi_flash_write_encrypted_manu(...) instead of ROM Func spi_flash_write_encrypted(...)
## Testing
tested by case of CONFIG_ESP32S3_SPIFLASH_ENCRYPTION_TEST, for <16MB and >16MB cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "sdc-g (via GitHub)" <gi...@apache.org>.
sdc-g commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2574282437
Hi @xiaoxiang781216
Thanks for your comment, just align the indent rule. Pleas check, thanks for your time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#discussion_r1904300087
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -286,7 +795,7 @@ static void esp32s3_spiflash_work(void *arg)
}
else if (work_arg->op_code == SPIFLASH_OP_CODE_ENCRYPT_WRITE)
{
- work_arg->ret = spi_flash_write_encrypted(work_arg->op_arg.addr,
+ work_arg->ret = spi_flash_write_encrypted_manu(work_arg->op_arg.addr,
work_arg->op_arg.buffer,
Review Comment:
align
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
+ {
Review Comment:
ditto
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
+ {
+ .flash_encryption_enable = spi_flash_encryption_hal_enable,
+ .flash_encryption_disable = spi_flash_encryption_hal_disable,
+ .flash_encryption_data_prepare = spi_flash_encryption_hal_prepare,
+ .flash_encryption_done = spi_flash_encryption_hal_done,
+ .flash_encryption_destroy = spi_flash_encryption_hal_destroy,
+ .flash_encryption_check = spi_flash_encryption_hal_check,
+ };
+
+/****************************************************************************
+ * Name: spi_flash_write_encrypted_manu
+ *
+ * Description:
+ * Workaround of spi_flash_write_encrypted
+ * by using of spi_flash_chip_generic_write_encrypted
+ *
+ * Input Parameters:
+ * address - Destination address in Flash. Must be a multiple of 16
+ * bytes.
+ * buffer - Pointer to the source buffer.
+ * length - Length of data, in bytes. Must be a multiple of 16 bytes.
+ *
+ * Returned Values:
+ * Zero (OK) is returned or a negative error.
+ *
+ ****************************************************************************/
+
+int spi_flash_write_encrypted_manu(uint32_t address, const void *buffer,
+ uint32_t length)
Review Comment:
align
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
+ {
+ .flash_encryption_enable = spi_flash_encryption_hal_enable,
+ .flash_encryption_disable = spi_flash_encryption_hal_disable,
+ .flash_encryption_data_prepare = spi_flash_encryption_hal_prepare,
+ .flash_encryption_done = spi_flash_encryption_hal_done,
+ .flash_encryption_destroy = spi_flash_encryption_hal_destroy,
+ .flash_encryption_check = spi_flash_encryption_hal_check,
+ };
+
+/****************************************************************************
+ * Name: spi_flash_write_encrypted_manu
+ *
+ * Description:
+ * Workaround of spi_flash_write_encrypted
+ * by using of spi_flash_chip_generic_write_encrypted
+ *
+ * Input Parameters:
+ * address - Destination address in Flash. Must be a multiple of 16
+ * bytes.
+ * buffer - Pointer to the source buffer.
+ * length - Length of data, in bytes. Must be a multiple of 16 bytes.
+ *
+ * Returned Values:
+ * Zero (OK) is returned or a negative error.
+ *
+ ****************************************************************************/
+
+int spi_flash_write_encrypted_manu(uint32_t address, const void *buffer,
+ uint32_t length)
+{
+ spi_flash_encryption_t *esp_flash_encryption =
+ &esp_flash_encryption_default;
+ esp_err_t err = ESP_OK;
+
+ /* Check if the buffer and length can qualify the requirements */
+
+ if (esp_flash_encryption->flash_encryption_check(address, length) != true)
+ {
+ return ESP_ERR_NOT_SUPPORTED;
+ }
+
+ const uint8_t *data_bytes = (const uint8_t *)buffer;
+ esp_flash_encryption->flash_encryption_enable();
+ while (length > 0)
+ {
+ int block_size;
+
+ /* Write the largest block if possible */
+
+ if (address % 64 == 0 && length >= 64)
+ {
+ block_size = 64;
+ }
+ else if (address % 32 == 0 && length >= 32)
+ {
+ block_size = 32;
+ }
+ else
+ {
+ block_size = 16;
+ }
+
+ /**
+ * Prepare the flash chip (same time as AES operation, for performance)
+ */
+
+ esp_flash_encryption->flash_encryption_data_prepare(address,
+ (uint32_t *)data_bytes,
+ block_size);
+
+ /* err = chip->chip_drv->set_chip_write_protect(chip, false); */
+
+ if (err != ESP_OK)
+ {
+ return err;
+ }
+
+ /**
+ * Waiting for encrypting buffer to finish and
+ * making result visible for SPI1
+ */
+
+ esp_flash_encryption->flash_encryption_done();
+
+ /**
+ * Note: For encryption function, after write flash command is sent.
+ * The hardware will write the encrypted buffer
+ * prepared in XTS_FLASH_ENCRYPTION register
+ * in function `flash_encryption_data_prepare`, instead of the origin
+ * buffer named `data_bytes`.
+ */
+
+ /**
+ * err = chip->chip_drv->write(chip, (uint32_t *)data_bytes,
+ * address, length);
+ */
+
+ if (err != ESP_OK)
+ {
+ return err;
+ }
+
+ /**
+ * err = chip->chip_drv->wait_idle(chip,
+ * chip->chip_drv->timeout->page_program_timeout);
Review Comment:
algin
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
+ {
+ .flash_encryption_enable = spi_flash_encryption_hal_enable,
+ .flash_encryption_disable = spi_flash_encryption_hal_disable,
+ .flash_encryption_data_prepare = spi_flash_encryption_hal_prepare,
+ .flash_encryption_done = spi_flash_encryption_hal_done,
+ .flash_encryption_destroy = spi_flash_encryption_hal_destroy,
+ .flash_encryption_check = spi_flash_encryption_hal_check,
Review Comment:
two spaces indent
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
Review Comment:
remove spaces before __attribute__
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
+ spi_flash_encrypt_ll_done();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_destroy(void)
+{
+ spi_flash_encrypt_ll_destroy();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_destroy
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+bool spi_flash_encryption_hal_check(uint32_t address, uint32_t length)
+{
+ return spi_flash_encrypt_ll_check(address, length);
+}
+
+/**
+ * These are the pointer to HW flash encryption.
+ * Default using hardware encryption.
+ *
+ * esp-idf/components/spi_flash/spi_flash_chip_generic.c
+ *
+ */
+
+DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default
+ __attribute__((__unused__)) =
+ {
+ .flash_encryption_enable = spi_flash_encryption_hal_enable,
+ .flash_encryption_disable = spi_flash_encryption_hal_disable,
+ .flash_encryption_data_prepare = spi_flash_encryption_hal_prepare,
+ .flash_encryption_done = spi_flash_encryption_hal_done,
+ .flash_encryption_destroy = spi_flash_encryption_hal_destroy,
+ .flash_encryption_check = spi_flash_encryption_hal_check,
+ };
+
+/****************************************************************************
+ * Name: spi_flash_write_encrypted_manu
+ *
+ * Description:
+ * Workaround of spi_flash_write_encrypted
+ * by using of spi_flash_chip_generic_write_encrypted
+ *
+ * Input Parameters:
+ * address - Destination address in Flash. Must be a multiple of 16
+ * bytes.
+ * buffer - Pointer to the source buffer.
+ * length - Length of data, in bytes. Must be a multiple of 16 bytes.
+ *
+ * Returned Values:
+ * Zero (OK) is returned or a negative error.
+ *
+ ****************************************************************************/
+
+int spi_flash_write_encrypted_manu(uint32_t address, const void *buffer,
+ uint32_t length)
+{
+ spi_flash_encryption_t *esp_flash_encryption =
+ &esp_flash_encryption_default;
+ esp_err_t err = ESP_OK;
+
+ /* Check if the buffer and length can qualify the requirements */
+
+ if (esp_flash_encryption->flash_encryption_check(address, length) != true)
+ {
+ return ESP_ERR_NOT_SUPPORTED;
+ }
+
+ const uint8_t *data_bytes = (const uint8_t *)buffer;
+ esp_flash_encryption->flash_encryption_enable();
+ while (length > 0)
+ {
+ int block_size;
+
+ /* Write the largest block if possible */
+
+ if (address % 64 == 0 && length >= 64)
+ {
+ block_size = 64;
+ }
+ else if (address % 32 == 0 && length >= 32)
+ {
+ block_size = 32;
+ }
+ else
+ {
+ block_size = 16;
+ }
+
+ /**
+ * Prepare the flash chip (same time as AES operation, for performance)
+ */
+
+ esp_flash_encryption->flash_encryption_data_prepare(address,
+ (uint32_t *)data_bytes,
Review Comment:
align
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,515 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ *
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_enable
+ *
+ * Description:
+ * Enable the flash encryption function under spi boot mode and
+ * download boot mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_disable
+ *
+ * Description:
+ * Disable the flash encryption mode.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_type
+ *
+ * Description:
+ * Choose type of chip you want to encrypt manully
+ *
+ * Input Parameters:
+ * type - The type of chip to be encrypted
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_buffer_length
+ *
+ * Description:
+ * Configure the data size of a single encryption.
+ *
+ * Input Parameters:
+ * size - Size of the desired block.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_plaintext_save
+ *
+ * Description:
+ * Save 32-bit piece of plaintext.
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * buffer - Buffer to store the input data.
+ * size - Buffer size.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ DEBUGASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_address_save
+ *
+ * Description:
+ * Copy the flash address to XTS_AES physical address
+ *
+ * Input Parameters:
+ * flash_addr - flash address to write.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_start
+ *
+ * Description:
+ * Start flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_calculate_wait_idle
+ *
+ * Description:
+ * Wait for flash encryption termination
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_done
+ *
+ * Description:
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_destroy
+ *
+ * Description:
+ * Set to destroy encrypted result
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encrypt_ll_check
+ *
+ * Description:
+ * Check if is qualified to encrypt the buffer
+ *
+ * Input Parameters:
+ * address - the address of written flash partition.
+ * length - Buffer size.
+ *
+ * Returned Value:
+ * True if the address is qualified.
+ *
+ ****************************************************************************/
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_enable
+ *
+ * Description:
+ * Enable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_disable
+ *
+ * Description:
+ * Disable flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_prepare
+ *
+ * Description:
+ * Prepare flash encryption
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_prepare(uint32_t address,
+ const uint32_t * buffer, uint32_t size)
+{
+ spi_flash_encrypt_ll_buffer_length(size);
+ spi_flash_encrypt_ll_address_save(address);
+ spi_flash_encrypt_ll_plaintext_save(address, buffer, size);
+ spi_flash_encrypt_ll_calculate_start();
+}
+
+/****************************************************************************
+ * Name: spi_flash_encryption_hal_done
+ *
+ * Description:
+ * wait flash encryption and mark down
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void spi_flash_encryption_hal_done(void)
+{
+ spi_flash_encrypt_ll_calculate_wait_idle();
Review Comment:
should use two sapce indent in ALL places
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on code in PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#discussion_r1901764127
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,322 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * From: esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ */
+
+/**
+ * Choose type of chip you want to encrypt manully
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/**
+ * Enable the flash encryption function under spi boot mode and download boot
+ * mode.
+ */
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Disable the flash encryption mode.
+ */
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * @param type The type of chip to be encrypted
+ *
+ * @note The hardware currently support flash encryption.
+ */
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ HAL_ASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
Review Comment:
This macro shouldn't be used in NuttX. Use DEBUGASSERT, instead.:
```suggestion
DEBUGASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
```
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,322 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * From: esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ */
+
+/**
+ * Choose type of chip you want to encrypt manully
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/**
+ * Enable the flash encryption function under spi boot mode and download boot
+ * mode.
+ */
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Disable the flash encryption mode.
+ */
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * @param type The type of chip to be encrypted
+ *
+ * @note The hardware currently support flash encryption.
+ */
Review Comment:
Same here. Please check other occurences.
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,322 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * From: esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ */
+
+/**
+ * Choose type of chip you want to encrypt manully
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/**
+ * Enable the flash encryption function under spi boot mode and download boot
+ * mode.
+ */
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Disable the flash encryption mode.
+ */
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * @param type The type of chip to be encrypted
+ *
+ * @note The hardware currently support flash encryption.
+ */
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ HAL_ASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
+ REG_WRITE(AES_XTS_DESTINATION_REG, type);
+}
+
+/**
+ * Configure the data size of a single encryption.
+ *
+ * @param block_size Size of the desired block.
+ */
+
+static inline void spi_flash_encrypt_ll_buffer_length(uint32_t size)
+{
+ REG_WRITE(AES_XTS_SIZE_REG, size >> 5); /* Desired block should not be larger than the block size. */
+}
+
+/**
+ * Save 32-bit piece of plaintext.
+ *
+ * @param address the address of written flash partition.
+ * @param buffer Buffer to store the input data.
+ * @param size Buffer size.
+ *
+ */
+
+static inline
+void spi_flash_encrypt_ll_plaintext_save(uint32_t address,
+ const uint32_t * buffer,
+ uint32_t size)
+{
+ uint32_t plaintext_offs =
+ (address % SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ HAL_ASSERT(
+ plaintext_offs + size <= SOC_FLASH_ENCRYPTED_XTS_AES_BLOCK_MAX);
+ memcpy((void *)(AES_XTS_PLAIN_BASE + plaintext_offs), buffer, size);
+}
+
+/**
+ * Copy the flash address to XTS_AES physical address
+ *
+ * @param flash_addr flash address to write.
+ */
+
+static inline void spi_flash_encrypt_ll_address_save(uint32_t flash_addr)
+{
+ REG_WRITE(AES_XTS_PHYSICAL_ADDR_REG, flash_addr);
+}
+
+/**
+ * Start flash encryption
+ */
+
+static inline void spi_flash_encrypt_ll_calculate_start(void)
+{
+ REG_WRITE(AES_XTS_TRIGGER_REG, 1);
+}
+
+/**
+ * Wait for flash encryption termination
+ */
+
+static inline void spi_flash_encrypt_ll_calculate_wait_idle(void)
+{
+ while (REG_READ(AES_XTS_STATE_REG) == 0x1)
+ {
+ }
+}
+
+/**
+ * Finish the flash encryption and make encrypted result accessible to SPI.
+ */
+
+static inline void spi_flash_encrypt_ll_done(void)
+{
+ REG_WRITE(AES_XTS_RELEASE_REG, 1);
+ while (REG_READ(AES_XTS_STATE_REG) != 0x3)
+ {
+ }
+}
+
+/**
+ * Set to destroy encrypted result
+ */
+
+static inline void spi_flash_encrypt_ll_destroy(void)
+{
+ REG_WRITE(AES_XTS_DESTROY_REG, 1);
+}
+
+/**
+ * Check if is qualified to encrypt the buffer
+ *
+ * @param address the address of written flash partition.
+ * @param length Buffer size.
+ */
+
+static inline bool spi_flash_encrypt_ll_check(uint32_t address,
+ uint32_t length)
+{
+ return ((address % length) == 0) ? true : false;
+}
+
+/**
+ * from: esp-idf/components/hal/spi_flash_encrypt_hal_iram.c
+ */
+
+void spi_flash_encryption_hal_enable(void)
+{
+ spi_flash_encrypt_ll_enable();
+ spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU);
+}
+
+void spi_flash_encryption_hal_disable(void)
+{
+ spi_flash_encrypt_ll_disable();
+}
Review Comment:
Please insert function header. Check for other occurrences.
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,322 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * From: esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ */
+
+/**
+ * Choose type of chip you want to encrypt manully
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/**
+ * Enable the flash encryption function under spi boot mode and download boot
+ * mode.
+ */
Review Comment:
This function header is not compliant with NuttX coding standards. Please check the [`Function header sections. `](https://nuttx.apache.org/docs/latest/contributing/coding_style.html#function-headers) section.
##########
arch/xtensa/src/esp32s3/esp32s3_spiflash_mtd.c:
##########
@@ -235,6 +235,322 @@ static inline bool IRAM_ATTR stack_is_psram(void)
}
#endif
+/**
+ * From: esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h
+ */
+
+/**
+ * Choose type of chip you want to encrypt manully
+ */
+
+typedef enum
+{
+ FLASH_ENCRYPTION_MANU = 0, /* !< Manually encrypt the flash chip. */
+ PSRAM_ENCRYPTION_MANU = 1 /* !< Manually encrypt the psram chip. */
+} flash_encrypt_ll_type_t;
+
+/**
+ * Enable the flash encryption function under spi boot mode and download boot
+ * mode.
+ */
+
+static inline void spi_flash_encrypt_ll_enable(void)
+{
+ REG_SET_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_DOWNLOAD_MANUAL_ENCRYPT |
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Disable the flash encryption mode.
+ */
+
+static inline void spi_flash_encrypt_ll_disable(void)
+{
+ REG_CLR_BIT(SYSTEM_EXTERNAL_DEVICE_ENCRYPT_DECRYPT_CONTROL_REG,
+ SYSTEM_ENABLE_SPI_MANUAL_ENCRYPT);
+}
+
+/**
+ * Choose type of chip you want to encrypt manully
+ *
+ * @param type The type of chip to be encrypted
+ *
+ * @note The hardware currently support flash encryption.
+ */
+
+static inline void spi_flash_encrypt_ll_type(flash_encrypt_ll_type_t type)
+{
+ HAL_ASSERT(type == FLASH_ENCRYPTION_MANU); /* Our hardware only support flash encryption */
Review Comment:
Please check other occurrences.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2569183748
> > > > Hello, Did you try to use already implemented functions on `esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h` with using `#include "hal/spi_flash_encrypted_ll.h" `?
> > >
> > >
> > > Hello Yes, instead of including header file, port the code directly with slight style change. Please check the code after the comment "esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h"
> >
> >
> > Up to you but instead of making a copy paste you can just include the header file, which will be better I guess. If you don't want to do that, you can remove/change some macros with nuttx version (e.g change HAL_ASSERT with debugassert or remove CONFIG_IDF_TARGET_ESP32S2 and CONFIG_IDF_TARGET_ESP32 macros because this code will only work on S3).
>
> Thanks for your comment, just remove the config of CONFIG_IDF_TARGET_ESP32 and CONFIG_IDF_TARGET_ESP32S2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "eren-terzioglu (via GitHub)" <gi...@apache.org>.
eren-terzioglu commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2568822674
> > Hello, Did you try to use already implemented functions on `esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h` with using `#include "hal/spi_flash_encrypted_ll.h" `?
>
> Hello Yes, instead of including header file, port the code directly with slight style change. Please check the code after the comment "esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h"
Up to you but instead of making a copy paste you can just include the header file, which will be better I guess. If you don't want to do that, you can remove/change some macros with nuttx version (e.g change HAL_ASSERT with debugassert or remove CONFIG_IDF_TARGET_ESP32S2 and CONFIG_IDF_TARGET_ESP32 macros because this code will only work on S3).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "sdc-g (via GitHub)" <gi...@apache.org>.
sdc-g commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2572176320
Hi @tmedicci
Thanks for your comment, I just checked and update all comments.
It looks better now, please check. Thanks for your time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #15399:
URL: https://github.com/apache/nuttx/pull/15399
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2567444787
[**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+13552&type=issues)
__Fill In The Commit Message:__ This PR contains a Commit with an Empty Commit Message. Please fill in the Commit Message with the PR Summary.
No, this PR does not fully meet the NuttX requirements based on the information provided. Here's why:
* **Summary:** While it mentions the source of the ported code, it lacks crucial details. It doesn't explain *why* this change is necessary. What problem does it solve? What benefit does it bring to NuttX? How does the encryption mechanism work? It also needs to specify the functional part of the code being changed (e.g., SPI driver, flash subsystem).
* **Impact:** The provided impact assessment is insufficient. While it mentions using a different function, it doesn't describe the broader impact. All "Impact on..." points should be addressed specifically (even with a "NO" if not applicable). For example:
* **Impact on user:** Does this require any configuration changes for users?
* **Impact on build:** Are any new Kconfig options introduced?
* **Impact on hardware:** Is this specific to ESP32S3, or does it affect other architectures?
* **Impact on documentation:** Does this require any documentation updates? Especially crucial for a security-related feature.
* **Impact on security:** This is a security feature, so a detailed explanation of its implications is *essential*. What encryption algorithm is used? What are the key management considerations?
* **Impact on compatibility:** Does this break any existing functionality?
* **Testing:** The testing information is inadequate. While it mentions the test case used, it doesn't provide:
* **Build Host details:** OS, CPU architecture, compiler version.
* **Target details:** Full board configuration used for testing (not just "arch:config").
* **Actual logs:** "your testing logs here" needs to be replaced with *actual* logs showing the behavior before and after the change. This is crucial for verifying the functionality and demonstrating the improvement or fix.
In short, the PR description needs significant expansion to meet the NuttX requirements. It needs to provide more context, explain the rationale behind the change, thoroughly assess the impact, and include detailed testing information.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "eren-terzioglu (via GitHub)" <gi...@apache.org>.
eren-terzioglu commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2567589074
Hello,
Did you try to use already implemented functions on `esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h` with using `#include "hal/spi_flash_encrypted_ll.h" `?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "sdc-g (via GitHub)" <gi...@apache.org>.
sdc-g commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2568875811
> > > Hello, Did you try to use already implemented functions on `esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h` with using `#include "hal/spi_flash_encrypted_ll.h" `?
> >
> >
> > Hello Yes, instead of including header file, port the code directly with slight style change. Please check the code after the comment "esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h"
>
> Up to you but instead of making a copy paste you can just include the header file, which will be better I guess. If you don't want to do that, you can remove/change some macros with nuttx version (e.g change HAL_ASSERT with debugassert or remove CONFIG_IDF_TARGET_ESP32S2 and CONFIG_IDF_TARGET_ESP32 macros because this code will only work on S3).
Thanks for your comment, just remove the config of CONFIG_IDF_TARGET_ESP32 and CONFIG_IDF_TARGET_ESP32S2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2569190344
Hi @sdc-g
Just curious: why not use the functions provided by HAL?
Please note that by using the HAL we can avoid code duplication and we can rely on the most recent bugfixes (if found) that can be related to the register's handling.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci closed pull request #15399: xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted
URL: https://github.com/apache/nuttx/pull/15399
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] xtensa/esp32s3: porting of spi_flash_chip_generic_write_encrypted [nuttx]
Posted by "sdc-g (via GitHub)" <gi...@apache.org>.
sdc-g commented on PR #15399:
URL: https://github.com/apache/nuttx/pull/15399#issuecomment-2568598533
> Hello, Did you try to use already implemented functions on `esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h` with using `#include "hal/spi_flash_encrypted_ll.h" `?
Hello
Yes, instead of including header file, port the code directly with slight style change.
Please check the code after the comment "esp-idf/components/hal/esp32s3/include/hal/spi_flash_encrypted_ll.h"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org