Skip to content

Commit

Permalink
Merge branch 'feature/esp32p4_efuse' into 'master'
Browse files Browse the repository at this point in the history
feat(efuse): Support eFuses for ESP32P4

Closes IDF-7512 and IDF-7759

See merge request espressif/esp-idf!25923
  • Loading branch information
KonstantinKondrashov committed Sep 13, 2023
2 parents 054d494 + b29f6d5 commit 82cb4d5
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 32 deletions.
1 change: 1 addition & 0 deletions components/efuse/esp32p4/include/esp_efuse_chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef enum {
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST0 = 9, /**< SECURE_BOOT_DIGEST0 (Secure Boot key digest) */
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST1 = 10, /**< SECURE_BOOT_DIGEST1 (Secure Boot key digest) */
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST2 = 11, /**< SECURE_BOOT_DIGEST2 (Secure Boot key digest) */
ESP_EFUSE_KEY_PURPOSE_KM_INIT_KEY = 12, /**< KM_INIT_KEY */
ESP_EFUSE_KEY_PURPOSE_MAX, /**< MAX PURPOSE */
} esp_efuse_purpose_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ esp_err_t esp_efuse_write_key(esp_efuse_block_t block, esp_efuse_purpose_t purpo
#endif //#ifdef SOC_EFUSE_SUPPORT_XTS_AES_256_KEYS
#if SOC_ECDSA_SUPPORTED
purpose == ESP_EFUSE_KEY_PURPOSE_ECDSA_KEY ||
#endif
#if SOC_KEY_MANAGER_SUPPORTED
purpose == ESP_EFUSE_KEY_PURPOSE_KM_INIT_KEY ||
#endif
purpose == ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL ||
purpose == ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -290,7 +290,7 @@ TEST_CASE("Test esp_efuse_write_keys", "[efuse]")
#else
esp_efuse_purpose_t purpose1[BLOCKS_NEEDED1] = {
ESP_EFUSE_KEY_PURPOSE_XTS_AES_128_KEY,
ESP_EFUSE_KEY_PURPOSE_RESERVED
ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL
};
#endif
uint8_t keys1[BLOCKS_NEEDED1][32] = {{0xEE}};
Expand Down Expand Up @@ -437,19 +437,24 @@ TEST_CASE("Test set_write_protect_of_digest_revoke", "[efuse]")
TEST_ESP_OK(esp_efuse_set_write_protect_of_digest_revoke(2));
TEST_ASSERT_TRUE(esp_efuse_get_write_protect_of_digest_revoke(2));

#if CONFIG_EFUSE_VIRTUAL
TEST_ESP_OK(esp_efuse_set_digest_revoke(0));
TEST_ESP_OK(esp_efuse_set_digest_revoke(1));
TEST_ESP_OK(esp_efuse_set_digest_revoke(2));

TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(0));
TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(1));
TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(2));
#endif // CONFIG_EFUSE_VIRTUAL

#if CONFIG_EFUSE_FPGA_TEST && !CONFIG_EFUSE_VIRTUAL
TEST_ESP_ERR(ESP_FAIL, esp_efuse_set_digest_revoke(0));
TEST_ESP_ERR(ESP_FAIL, esp_efuse_set_digest_revoke(1));
TEST_ESP_ERR(ESP_FAIL, esp_efuse_set_digest_revoke(2));
// the write protection bits are set and the revocation bits will not be changed.
TEST_ASSERT_FALSE(esp_efuse_get_digest_revoke(0));
TEST_ASSERT_FALSE(esp_efuse_get_digest_revoke(1));
TEST_ASSERT_FALSE(esp_efuse_get_digest_revoke(2));
#else
TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(0));
TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(1));
TEST_ASSERT_TRUE(esp_efuse_get_digest_revoke(2));
#endif // CONFIG_EFUSE_FPGA_TEST && !CONFIG_EFUSE_VIRTUAL
}
#endif // SOC_SUPPORT_SECURE_BOOT_REVOKE_KEY
Expand Down
5 changes: 4 additions & 1 deletion components/esp_rom/include/esp32p4/rom/efuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ extern "C" {

typedef enum {
ETS_EFUSE_KEY_PURPOSE_USER = 0,
ETS_EFUSE_KEY_PURPOSE_RESERVED = 1,
ETS_EFUSE_KEY_PURPOSE_ECDSA_KEY = 1,
ETS_EFUSE_KEY_PURPOSE_XTS_AES_256_KEY_1 = 2,
ETS_EFUSE_KEY_PURPOSE_XTS_AES_256_KEY_2 = 3,
ETS_EFUSE_KEY_PURPOSE_XTS_AES_128_KEY = 4,
ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL = 5,
ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG = 6,
Expand All @@ -36,6 +38,7 @@ typedef enum {
ETS_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST0 = 9,
ETS_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST1 = 10,
ETS_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST2 = 11,
ETS_EFUSE_KEY_PURPOSE_KM_INIT_KEY = 12,
ETS_EFUSE_KEY_PURPOSE_MAX,
} ets_efuse_purpose_t;

Expand Down
2 changes: 1 addition & 1 deletion components/hal/esp32p4/efuse_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void)
void efuse_hal_set_timing(uint32_t apb_freq_hz)
{
(void) apb_freq_hz;
efuse_ll_set_pwr_off_num(0x190);
/* keep timing settings by default */
}

void efuse_hal_read(void)
Expand Down
4 changes: 1 addition & 3 deletions components/hal/esp32p4/include/hal/efuse_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ extern "C" {

// Always inline these functions even no gcc optimization is applied.

//TODO: IDF-7549

/******************* eFuse fields *************************/

__attribute__((always_inline)) static inline uint32_t efuse_ll_get_flash_crypt_cnt(void)
Expand Down Expand Up @@ -67,7 +65,7 @@ __attribute__((always_inline)) static inline bool efuse_ll_get_disable_wafer_ver

__attribute__((always_inline)) static inline uint32_t efuse_ll_get_blk_version_major(void)
{
return EFUSE.rd_sys_part1_data4.val;
return 0;
}

__attribute__((always_inline)) static inline uint32_t efuse_ll_get_blk_version_minor(void)
Expand Down
5 changes: 0 additions & 5 deletions docs/docs_not_updated/esp32p4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ api-reference/system/perfmon.rst
api-reference/system/ulp-lp-core.rst
api-reference/system/ulp.rst
api-reference/system/esp_function_with_shared_stack.rst
api-reference/system/efuse.rst
api-reference/system/chip_revision.rst
api-reference/system/ulp_instruction_set.rst
api-reference/system/async_memcpy.rst
api-reference/system/random.rst
Expand All @@ -182,10 +180,7 @@ api-reference/system/power_management.rst
api-reference/system/mem_alloc.rst
api-reference/system/misc_system_api.rst
api-reference/system/bootloader_image_format.rst
api-reference/system/inc/espefuse_summary_ESP32-P4.rst
api-reference/system/inc/power_management_esp32p4.rst
api-reference/system/inc/show-efuse-table_ESP32-P4.rst
api-reference/system/inc/revisions_ESP32-P4.rst
api-reference/system/heap_debug.rst
api-reference/system/mm.rst
api-reference/system/ipc.rst
Expand Down
Loading

0 comments on commit 82cb4d5

Please sign in to comment.