mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-21 08:49:25 +00:00
fix(bootloader): self encryption workflow in bootloader not working on C5
Added explicit wait for key manager state to be idle before configuring the register for flash encryption key usage from efuse. This now ensures that flash contents are encrypted using efuse programmed key. Also refactored code a bit to move into target specific directory.
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
#include "esp_efuse_table.h"
|
||||
#include "esp_log.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/keymng_reg.h"
|
||||
#include "soc/pcr_reg.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
|
||||
static __attribute__((unused)) const char *TAG = "flash_encrypt";
|
||||
|
||||
@@ -58,3 +61,31 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// TODO: Update to use LL APIs once key manager support added in IDF-8621
|
||||
esp_err_t esp_flash_encryption_enable_key_mgr(void)
|
||||
{
|
||||
// Set the force power down bit to 0 to enable key manager
|
||||
PCR.km_pd_ctrl.km_mem_force_pd = 0;
|
||||
// Reset the key manager
|
||||
PCR.km_conf.km_clk_en = 1;
|
||||
PCR.km_conf.km_rst_en = 1;
|
||||
PCR.km_conf.km_rst_en = 0;
|
||||
|
||||
// Wait for key manager to be ready
|
||||
while (!PCR.km_conf.km_ready) {
|
||||
};
|
||||
|
||||
// Wait for key manager state machine to be idle
|
||||
while (REG_READ(KEYMNG_STATE_REG) != 0) {
|
||||
};
|
||||
|
||||
// Set the key manager to use efuse key
|
||||
REG_SET_FIELD(KEYMNG_STATIC_REG, KEYMNG_USE_EFUSE_KEY, 2);
|
||||
|
||||
// Reset MSPI to re-load the flash encryption key
|
||||
REG_SET_BIT(PCR_MSPI_CLK_CONF_REG, PCR_MSPI_AXI_RST_EN);
|
||||
REG_CLR_BIT(PCR_MSPI_CLK_CONF_REG, PCR_MSPI_AXI_RST_EN);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user