Skip to content

Commit

Permalink
efuse: Fix load_efuses_from_flash when FE is on
Browse files Browse the repository at this point in the history
esp_efuse_utility_load_efuses_from_flash() read emul_efuse
as an encrypted partition, but that is not correct,
this partition was never encrypted.
Need to read it as not encrypted partition.

Fxed the case: If FE is already on then EFUSE VIRT mode can work with it.

Closes espressif/esp-idf#10929
  • Loading branch information
KonstantinKondrashov committed Mar 23, 2023
1 parent c52b175 commit 310bf94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/efuse/src/esp_efuse_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ bool esp_efuse_utility_load_efuses_from_flash(void)
}
uint32_t efuses_in_flash[sizeof(virt_blocks)];

esp_err_t err = bootloader_flash_read(esp_efuse_flash_offset, &efuses_in_flash, sizeof(efuses_in_flash), true);
esp_err_t err = bootloader_flash_read(esp_efuse_flash_offset, &efuses_in_flash, sizeof(efuses_in_flash), false);
if (err != ESP_OK) {
ESP_EARLY_LOGE(TAG, "[Virtual] Can not read eFuse partition from flash (err=0x%x)", err);
abort();
Expand Down
13 changes: 13 additions & 0 deletions components/hal/efuse_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ IRAM_ATTR uint32_t efuse_hal_chip_revision(void)
{
return efuse_hal_get_major_chip_version() * 100 + efuse_hal_get_minor_chip_version();
}

IRAM_ATTR bool efuse_hal_flash_encryption_enabled(void)
{
uint32_t flash_crypt_cnt = efuse_ll_get_flash_crypt_cnt();
bool enabled = false;
while (flash_crypt_cnt) {
if (flash_crypt_cnt & 1) {
enabled = !enabled;
}
flash_crypt_cnt >>= 1;
}
return enabled;
}
9 changes: 9 additions & 0 deletions components/hal/include/hal/efuse_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ void efuse_hal_get_mac(uint8_t *mac);
*/
uint32_t efuse_hal_chip_revision(void);

/**
* @brief Is flash encryption currently enabled in hardware?
*
* Flash encryption is enabled if the FLASH_CRYPT_CNT efuse has an odd number of bits set.
*
* @return true if flash encryption is enabled.
*/
bool efuse_hal_flash_encryption_enabled(void);

/**
* @brief Returns major chip version
*/
Expand Down

0 comments on commit 310bf94

Please sign in to comment.