diff --git a/components/bootloader/Kconfig.projbuild b/components/bootloader/Kconfig.projbuild index 323cebad92..4579fd41c9 100644 --- a/components/bootloader/Kconfig.projbuild +++ b/components/bootloader/Kconfig.projbuild @@ -449,8 +449,8 @@ menu "Security features" config SECURE_BOOT_V2_RSA_SUPPORTED bool default y - # RSA secure boot is supported in ESP32 revision >= ECO3 - depends on (IDF_TARGET_ESP32 && ESP32_REV_MIN >= 3) || SOC_SECURE_BOOT_V2_RSA + # RSA secure boot is supported in ESP32 revision >= v3.0 + depends on (IDF_TARGET_ESP32 && ESP32_REV_MIN_FULL >= 300) || SOC_SECURE_BOOT_V2_RSA config SECURE_BOOT_V2_ECC_SUPPORTED bool @@ -465,7 +465,7 @@ menu "Security features" config SECURE_BOOT_V2_PREFERRED bool default y - depends on ESP32_REV_MIN >= 3 + depends on ESP32_REV_MIN_FULL >= 300 config SECURE_BOOT_V2_ECDSA_ENABLED bool @@ -586,8 +586,8 @@ menu "Security features" config SECURE_BOOT bool "Enable hardware Secure Boot in bootloader (READ DOCS FIRST)" default n - # Secure boot is not supported for ESP32-C3 revision < ECO3 - depends on SOC_SECURE_BOOT_SUPPORTED && !(IDF_TARGET_ESP32C3 && ESP32C3_REV_MIN < 3) + # Secure boot is not supported for ESP32-C3 revision < v0.3 + depends on SOC_SECURE_BOOT_SUPPORTED && !(IDF_TARGET_ESP32C3 && ESP32C3_REV_MIN_FULL < 3) select ESPTOOLPY_NO_STUB if !IDF_TARGET_ESP32 && !IDF_TARGET_ESP32S2 help Build a bootloader which enables Secure Boot on first boot. @@ -971,7 +971,7 @@ menu "Security features" default SECURE_ENABLE_SECURE_ROM_DL_MODE if SECURE_ROM_DL_MODE_ENABLED # NOERROR default SECURE_INSECURE_ALLOW_DL_MODE depends on SECURE_BOOT_V2_ENABLED || SECURE_FLASH_ENC_ENABLED - depends on !IDF_TARGET_ESP32 || ESP32_REV_MIN_3 + depends on !(IDF_TARGET_ESP32 && ESP32_REV_MIN_FULL < 300) config SECURE_DISABLE_ROM_DL_MODE bool "UART ROM download mode (Permanently disabled (recommended))" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c index c687fd7a42..9bda18434d 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c @@ -17,6 +17,7 @@ #include "soc/spi_reg.h" #include "soc/soc_caps.h" #include "soc/soc_pins.h" +#include "soc/chip_revision.h" #include "hal/efuse_hal.h" #include "hal/gpio_hal.h" #include "flash_qio_mode.h" @@ -168,16 +169,13 @@ int bootloader_flash_get_wp_pin(void) return CONFIG_SPIRAM_SPIWP_SD3_PIN; // can be set for app when DIO or DOUT config used for PSRAM only #else // no custom value, find it based on the package eFuse value - uint8_t chip_ver; - uint32_t pkg_ver = bootloader_common_get_chip_ver_pkg(); - switch(pkg_ver) { + switch(bootloader_common_get_chip_ver_pkg()) { case EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH: case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5: return ESP32_D2WD_WP_GPIO; case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4: /* Same package IDs are used for ESP32-PICO-V3 and ESP32-PICO-D4, silicon version differentiates */ - chip_ver = efuse_hal_get_major_chip_version(); - return (chip_ver < 3) ? ESP32_D2WD_WP_GPIO : ESP32_PICO_V3_GPIO; + return !ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300) ? ESP32_D2WD_WP_GPIO : ESP32_PICO_V3_GPIO; case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302: return ESP32_PICO_V3_GPIO; default: diff --git a/components/bootloader_support/include/esp_app_format.h b/components/bootloader_support/include/esp_app_format.h index 5fa0975ee1..74fc46c880 100644 --- a/components/bootloader_support/include/esp_app_format.h +++ b/components/bootloader_support/include/esp_app_format.h @@ -83,8 +83,15 @@ typedef struct { * pin and sets this field to 0xEE=disabled) */ uint8_t spi_pin_drv[3]; /*!< Drive settings for the SPI flash pins (read by ROM bootloader) */ esp_chip_id_t chip_id; /*!< Chip identification number */ - uint8_t min_chip_rev; /*!< Minimum chip revision supported by image */ - uint8_t reserved[8]; /*!< Reserved bytes in additional header space, currently unused */ + uint8_t min_chip_rev; /*!< Minimal chip revision supported by image + * After the Major and Minor revision eFuses were introduced into the chips, this field is no longer used. + * But for compatibility reasons, we keep this field and the data in it. + * Use min_chip_rev_full instead. + * The software interprets this as a Major version for most of the chips and as a Minor version for the ESP32-C3. + */ + uint16_t min_chip_rev_full; /*!< Minimal chip revision supported by image, in format: major * 100 + minor */ + uint16_t max_chip_rev_full; /*!< Maximal chip revision supported by image, in format: major * 100 + minor */ + uint8_t reserved[4]; /*!< Reserved bytes in additional header space, currently unused */ uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum. * Included in image length. This digest * is separate to secure boot and only used for detecting corruption. diff --git a/components/bootloader_support/include/esp_secure_boot.h b/components/bootloader_support/include/esp_secure_boot.h index f4b2e79c57..95ccf39000 100644 --- a/components/bootloader_support/include/esp_secure_boot.h +++ b/components/bootloader_support/include/esp_secure_boot.h @@ -191,7 +191,7 @@ typedef struct { */ esp_err_t esp_secure_boot_verify_ecdsa_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest); -#if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_3 +#if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_FULL >= 300 /** * @brief Structure to hold public key digests calculated from the signature blocks of a single image. * @@ -202,7 +202,7 @@ typedef struct { unsigned num_digests; /* Number of valid digests, starting at index 0 */ } esp_image_sig_public_key_digests_t; -#endif // !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_3 +#endif // !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_FULL >= 300 /** @brief Legacy ECDSA verification function * diff --git a/components/bootloader_support/private_include/bootloader_signature.h b/components/bootloader_support/private_include/bootloader_signature.h index fceb9eb49a..623dff7748 100644 --- a/components/bootloader_support/private_include/bootloader_signature.h +++ b/components/bootloader_support/private_include/bootloader_signature.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,7 +23,7 @@ #include "esp32c2/rom/secure_boot.h" #endif -#if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_3 +#if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_FULL >= 300 /** @brief Verify the secure boot signature block for Secure Boot V2. * diff --git a/components/bootloader_support/src/bootloader_clock_init.c b/components/bootloader_support/src/bootloader_clock_init.c index 35b1e08952..6a10be32ab 100644 --- a/components/bootloader_support/src/bootloader_clock_init.c +++ b/components/bootloader_support/src/bootloader_clock_init.c @@ -6,6 +6,7 @@ #include "sdkconfig.h" #include "soc/soc.h" #include "soc/rtc.h" +#include "soc/chip_revision.h" #include "hal/efuse_hal.h" #include "soc/rtc_cntl_reg.h" #if CONFIG_IDF_TARGET_ESP32 @@ -32,7 +33,7 @@ __attribute__((weak)) void bootloader_clock_configure(void) * document). For rev. 0, switch to 240 instead if it has been enabled * previously. */ - if (efuse_hal_get_major_chip_version() == 0 && + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 100) && clk_ll_cpu_get_freq_mhz_from_pll() == CLK_LL_PLL_240M_FREQ_MHZ) { cpu_freq_mhz = 240; } diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index 53f43bd694..f4dfcbb232 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -17,7 +17,9 @@ #include "soc/gpio_periph.h" #include "soc/rtc.h" #include "soc/efuse_reg.h" +#include "soc/chip_revision.h" #include "hal/efuse_hal.h" +#include "hal/efuse_ll.h" #include "hal/gpio_ll.h" #include "esp_image_format.h" #include "bootloader_sha.h" @@ -25,6 +27,7 @@ #include "bootloader_flash_priv.h" #define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */ +#define IS_MAX_REV_SET(max_chip_rev_full) (((max_chip_rev_full) != 65535) && ((max_chip_rev_full) != 0)) static const char* TAG = "boot_comm"; @@ -61,27 +64,31 @@ esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hd if (chip_id != img_hdr->chip_id) { ESP_LOGE(TAG, "mismatch chip ID, expected %d, found %d", chip_id, img_hdr->chip_id); err = ESP_FAIL; - } - + } else { #ifndef CONFIG_IDF_ENV_FPGA -#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32H2) - uint8_t revision = efuse_hal_get_major_chip_version(); - // min_chip_rev keeps the MAJOR wafer version for these chips -#else - uint8_t revision = efuse_hal_get_minor_chip_version(); - // min_chip_rev keeps the MINOR wafer version for these chips -#endif - if (revision < img_hdr->min_chip_rev) { - /* To fix this error, please update mininum supported chip revision from configuration, - * located in TARGET (e.g. ESP32) specific options under "Component config" menu */ - ESP_LOGE(TAG, "This chip is revision %d but the application is configured for minimum revision %d. Can't run.", revision, img_hdr->min_chip_rev); - err = ESP_FAIL; - } else if (revision != img_hdr->min_chip_rev) { -#ifdef BOOTLOADER_BUILD - ESP_LOGI(TAG, "chip revision: %d, min. %s chip revision: %d", revision, type == ESP_IMAGE_BOOTLOADER ? "bootloader" : "application", img_hdr->min_chip_rev); -#endif - } + unsigned revision = efuse_hal_chip_revision(); + unsigned int major_rev = revision / 100; + unsigned int minor_rev = revision % 100; + unsigned min_rev = img_hdr->min_chip_rev_full; + if (type == ESP_IMAGE_BOOTLOADER || type == ESP_IMAGE_APPLICATION) { + if (!ESP_CHIP_REV_ABOVE(revision, min_rev)) { + ESP_LOGE(TAG, "Image requires chip rev >= v%d.%d, but chip is v%d.%d", + min_rev / 100, min_rev % 100, + major_rev, minor_rev); + err = ESP_FAIL; + } + } + if (type == ESP_IMAGE_APPLICATION) { + unsigned max_rev = img_hdr->max_chip_rev_full; + if ((IS_MAX_REV_SET(max_rev) && (revision > max_rev) && !efuse_ll_get_disable_wafer_version_major())) { + ESP_LOGE(TAG, "Image requires chip rev <= v%d.%d, but chip is v%d.%d", + max_rev / 100, max_rev % 100, + major_rev, minor_rev); + err = ESP_FAIL; + } + } #endif // CONFIG_IDF_ENV_FPGA + } return err; } diff --git a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c index c1c3108d7b..c67c9aefe3 100644 --- a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c +++ b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c @@ -25,6 +25,7 @@ #include "soc/extmem_reg.h" #include "soc/io_mux_reg.h" #include "soc/system_reg.h" +#include "soc/chip_revision.h" #include "esp32c3/rom/efuse.h" #include "esp32c3/rom/ets_sys.h" #include "bootloader_common.h" @@ -252,7 +253,7 @@ static inline void bootloader_hardware_init(void) { // This check is always included in the bootloader so it can // print the minimum revision error message later in the boot - if (efuse_hal_get_minor_chip_version() < 3) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 3)) { REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_FORCE_XPD_IPH, 1); REGI2C_WRITE_MASK(I2C_BIAS, I2C_BIAS_DREG_1P1_PVT, 12); } @@ -265,8 +266,7 @@ static inline void bootloader_ana_reset_config(void) For ECO2: fix brownout reset bug, support swt & brownout reset; For ECO3: fix clock glitch reset bug, support all reset, include: swt & brownout & clock glitch reset. */ - uint8_t chip_version = efuse_hal_get_minor_chip_version(); - switch (chip_version) { + switch (efuse_hal_chip_revision()) { case 0: case 1: //Enable WDT reset. Disable BOR and GLITCH reset diff --git a/components/efuse/esp32/esp_efuse_fields.c b/components/efuse/esp32/esp_efuse_fields.c index 447dac2dc7..2981e7e33a 100644 --- a/components/efuse/esp32/esp_efuse_fields.c +++ b/components/efuse/esp32/esp_efuse_fields.c @@ -13,6 +13,7 @@ #include "esp_err.h" #include "esp_log.h" #include "soc/efuse_periph.h" +#include "soc/chip_revision.h" #include "hal/efuse_hal.h" #include "bootloader_random.h" #include "sys/param.h" @@ -41,9 +42,9 @@ void esp_efuse_disable_basic_rom_console(void) esp_err_t esp_efuse_disable_rom_download_mode(void) { -#ifndef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL < 300 /* Check if we support this revision at all */ - if (efuse_hal_get_major_chip_version() < 3) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300)) { return ESP_ERR_NOT_SUPPORTED; } #endif diff --git a/components/efuse/include/esp_efuse.h b/components/efuse/include/esp_efuse.h index 3842fd4551..80db72a608 100644 --- a/components/efuse/include/esp_efuse.h +++ b/components/efuse/include/esp_efuse.h @@ -46,7 +46,7 @@ typedef enum { ESP_EFUSE_ROM_LOG_ALWAYS_OFF /**< Disable ROM logging permanently */ } esp_efuse_rom_log_scheme_t; -#if CONFIG_ESP32_REV_MIN_3 || !CONFIG_IDF_TARGET_ESP32 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 || !CONFIG_IDF_TARGET_ESP32 /** * @brief Pointers to the trusted key digests. * @@ -742,7 +742,7 @@ esp_err_t esp_efuse_write_key(esp_efuse_block_t block, esp_efuse_purpose_t purpo esp_err_t esp_efuse_write_keys(const esp_efuse_purpose_t purposes[], uint8_t keys[][32], unsigned number_of_keys); -#if CONFIG_ESP32_REV_MIN_3 || !CONFIG_IDF_TARGET_ESP32 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 || !CONFIG_IDF_TARGET_ESP32 /** * @brief Read key digests from efuse. Any revoked/missing digests will be marked as NULL * diff --git a/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c b/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c index ead5b1fbd9..688a19f66d 100644 --- a/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c +++ b/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c @@ -240,7 +240,7 @@ err_exit: return err; } -#if CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 esp_err_t esp_secure_boot_read_key_digests(esp_secure_boot_key_digests_t *trusted_keys) { if (trusted_keys == NULL) { @@ -249,4 +249,4 @@ esp_err_t esp_secure_boot_read_key_digests(esp_secure_boot_key_digests_t *truste trusted_keys->key_digests[0] = (const void *)esp_efuse_utility_get_read_register_address(EFUSE_BLK_SECURE_BOOT); return ESP_OK; } -#endif // CONFIG_ESP32_REV_MIN_3 +#endif // CONFIG_ESP32_REV_MIN_FULL >= 300 diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 65d4719f02..80b0774974 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -1,4 +1,10 @@ menu "Hardware Settings" + + menu "Chip revision" + # Insert chip-specific HW config + orsource "./port/$IDF_TARGET/Kconfig.hw_support" + endmenu + orsource "./port/$IDF_TARGET/Kconfig.spiram" menu "MAC Config" @@ -181,9 +187,6 @@ menu "Hardware Settings" default 0x10000 if MMU_PAGE_SIZE_64KB endmenu - # Insert chip-specific HW config - orsource "./port/$IDF_TARGET/Kconfig.hw_support" - menu "GDMA Configuration" depends on SOC_GDMA_SUPPORTED config GDMA_CTRL_FUNC_IN_IRAM diff --git a/components/esp_hw_support/port/esp32/Kconfig.hw_support b/components/esp_hw_support/port/esp32/Kconfig.hw_support index 26ff2dcbcc..81eb5f3ded 100644 --- a/components/esp_hw_support/port/esp32/Kconfig.hw_support +++ b/components/esp_hw_support/port/esp32/Kconfig.hw_support @@ -2,25 +2,67 @@ choice ESP32_REV_MIN prompt "Minimum Supported ESP32 Revision" default ESP32_REV_MIN_0 help - Minimum revision that ESP-IDF would support. - ESP-IDF performs different strategy on different esp32 revision. + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). + + The complied binary will only support chips above this revision, + this will also help to reduce binary size. config ESP32_REV_MIN_0 - bool "Rev 0" + bool "Rev v0.0 (ECO0)" # Brownout on Rev 0 is bugged, must use interrupt select ESP_SYSTEM_BROWNOUT_INTR config ESP32_REV_MIN_1 - bool "Rev 1" + bool "Rev v1.0 (ECO1)" + config ESP32_REV_MIN_1_1 + bool "Rev v1.1 (ECO1.1)" config ESP32_REV_MIN_2 - bool "Rev 2" + bool "Rev v2.0 (ECO2)" config ESP32_REV_MIN_3 - bool "Rev 3" + bool "Rev v3.0 (ECO3)" + select ESP_INT_WDT if ESP32_ECO3_CACHE_LOCK_FIX + config ESP32_REV_MIN_3_1 + bool "Rev v3.1 (ECO4)" select ESP_INT_WDT if ESP32_ECO3_CACHE_LOCK_FIX endchoice config ESP32_REV_MIN + # we keep it for compatibility. Use ESP32_REV_MIN_FULL instead. int default 0 if ESP32_REV_MIN_0 - default 1 if ESP32_REV_MIN_1 + default 1 if ESP32_REV_MIN_1 || ESP32_REV_MIN_1_1 default 2 if ESP32_REV_MIN_2 - default 3 if ESP32_REV_MIN_3 + default 3 if ESP32_REV_MIN_3 || ESP32_REV_MIN_3_1 + +config ESP32_REV_MIN_FULL + int + default 0 if ESP32_REV_MIN_0 + default 100 if ESP32_REV_MIN_1 + default 101 if ESP32_REV_MIN_1_1 + default 200 if ESP32_REV_MIN_2 + default 300 if ESP32_REV_MIN_3 + default 301 if ESP32_REV_MIN_3_1 + +config ESP_REV_MIN_FULL + int + default ESP32_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32 Revision (Rev v3.99)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32_REV_MIN_FULL to ESP32_REV_MAX_FULL + +config ESP32_REV_MAX_FULL + int + default 399 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32_REV_MAX_FULL diff --git a/components/esp_hw_support/port/esp32/Kconfig.rtc b/components/esp_hw_support/port/esp32/Kconfig.rtc index dec9cf28aa..a2dd64dfb6 100644 --- a/components/esp_hw_support/port/esp32/Kconfig.rtc +++ b/components/esp_hw_support/port/esp32/Kconfig.rtc @@ -36,7 +36,7 @@ endchoice choice RTC_EXT_CRYST_ADDIT_CURRENT_METHOD prompt "Additional current for external 32kHz crystal" depends on RTC_CLK_SRC_EXT_CRYS - depends on ESP32_REV_MIN <= 1 + depends on ESP32_REV_MIN_FULL < 200 default RTC_EXT_CRYST_ADDIT_CURRENT_NONE help With some 32kHz crystal configurations, the X32N and X32P pins may not have enough diff --git a/components/esp_hw_support/port/esp32/chip_info.c b/components/esp_hw_support/port/esp32/chip_info.c index 05b2dc38fd..23131f0ceb 100644 --- a/components/esp_hw_support/port/esp32/chip_info.c +++ b/components/esp_hw_support/port/esp32/chip_info.c @@ -7,6 +7,7 @@ #include #include "esp_chip_info.h" #include "soc/soc.h" +#include "soc/chip_revision.h" #include "soc/efuse_reg.h" #include "hal/efuse_ll.h" #include "hal/efuse_hal.h" @@ -42,6 +43,7 @@ void esp_chip_info(esp_chip_info_t* out_info) #if CONFIG_ESP32_ECO3_CACHE_LOCK_FIX inline bool soc_has_cache_lock_bug(void) { - return (efuse_hal_get_major_chip_version() == 3); + unsigned rev = efuse_hal_chip_revision(); + return ESP_CHIP_REV_ABOVE(rev, 300); } #endif diff --git a/components/esp_hw_support/port/esp32/rtc_clk.c b/components/esp_hw_support/port/esp32/rtc_clk.c index 17ee028d72..acdde51d68 100644 --- a/components/esp_hw_support/port/esp32/rtc_clk.c +++ b/components/esp_hw_support/port/esp32/rtc_clk.c @@ -12,6 +12,7 @@ #include "soc/rtc_periph.h" #include "soc/sens_periph.h" #include "soc/soc_caps.h" +#include "soc/chip_revision.h" #include "hal/efuse_ll.h" #include "hal/efuse_hal.h" #include "soc/gpio_struct.h" @@ -44,9 +45,8 @@ static void rtc_clk_32k_enable_common(clk_ll_xtal32k_enable_mode_t mode) SET_PERI_REG_MASK(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL | RTC_IO_X32P_MUX_SEL); #ifdef CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT - uint8_t chip_ver = efuse_hal_get_major_chip_version(); // version0 and version1 need provide additional current to external XTAL. - if(chip_ver == 0 || chip_ver == 1) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 200)) { /* TOUCH sensor can provide additional current to external XTAL. In some case, X32N and X32P PAD don't have enough drive capability to start XTAL */ SET_PERI_REG_MASK(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS_M); @@ -60,8 +60,7 @@ static void rtc_clk_32k_enable_common(clk_ll_xtal32k_enable_mode_t mode) SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD9_REG, RTC_IO_TOUCH_PAD9_XPD_M); } #elif defined CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT_V2 - uint8_t chip_ver = efuse_hal_get_major_chip_version(); - if(chip_ver == 0 || chip_ver == 1) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 200)) { /* TOUCH sensor can provide additional current to external XTAL. In some case, X32N and X32P PAD don't have enough drive capability to start XTAL */ SET_PERI_REG_MASK(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS_M); @@ -94,14 +93,12 @@ void rtc_clk_32k_enable(bool enable) CLEAR_PERI_REG_MASK(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL | RTC_IO_X32P_MUX_SEL); #ifdef CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT - uint8_t chip_ver = efuse_hal_get_major_chip_version(); - if(chip_ver == 0 || chip_ver == 1) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 200)) { /* Power down TOUCH */ CLEAR_PERI_REG_MASK(RTC_IO_TOUCH_PAD9_REG, RTC_IO_TOUCH_PAD9_XPD_M); } #elif defined CONFIG_RTC_EXT_CRYST_ADDIT_CURRENT_V2 - uint8_t chip_ver = efuse_hal_get_major_chip_version(); - if(chip_ver == 0 || chip_ver == 1) { + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 200)) { /* Power down TOUCH */ CLEAR_PERI_REG_MASK(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_XPD_BIAS_M); SET_PERI_REG_BITS(RTC_IO_TOUCH_CFG_REG, RTC_IO_TOUCH_DCUR, 0, RTC_IO_TOUCH_DCUR_S); diff --git a/components/esp_hw_support/port/esp32c2/Kconfig.hw_support b/components/esp_hw_support/port/esp32c2/Kconfig.hw_support new file mode 100644 index 0000000000..99c8595e41 --- /dev/null +++ b/components/esp_hw_support/port/esp32c2/Kconfig.hw_support @@ -0,0 +1,44 @@ +choice ESP32C2_REV_MIN + prompt "Minimum Supported ESP32-C2 Revision" + default ESP32C2_REV_MIN_1 + help + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). + + The complied binary will only support chips above this revision, + this will also help to reduce binary size. + + config ESP32C2_REV_MIN_1 + bool "Rev v1.0 (ECO1)" + config ESP32C2_REV_MIN_2 + bool "Rev v2.0 (ECO2)" +endchoice + +config ESP32C2_REV_MIN_FULL + int + default 100 if ESP32C2_REV_MIN_1 + default 200 if ESP32C2_REV_MIN_2 + +config ESP_REV_MIN_FULL + int + default ESP32C2_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32-C2 Revision (Rev v2.9)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32C2_REV_MIN_FULL to ESP32C2_REV_MAX_FULL + +config ESP32C2_REV_MAX_FULL + int + default 299 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32C2_REV_MAX_FULL diff --git a/components/esp_hw_support/port/esp32c3/Kconfig.hw_support b/components/esp_hw_support/port/esp32c3/Kconfig.hw_support index c9c8ef9a84..050f392399 100644 --- a/components/esp_hw_support/port/esp32c3/Kconfig.hw_support +++ b/components/esp_hw_support/port/esp32c3/Kconfig.hw_support @@ -2,26 +2,52 @@ choice ESP32C3_REV_MIN prompt "Minimum Supported ESP32-C3 Revision" default ESP32C3_REV_MIN_3 help - Minimum revision that ESP-IDF would support. + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). - Only supporting higher chip revisions can reduce binary size. + The complied binary will only support chips above this revision, + this will also help to reduce binary size. config ESP32C3_REV_MIN_0 - bool "Rev 0" + bool "Rev v0.0 (ECO0)" config ESP32C3_REV_MIN_1 - bool "Rev 1" + bool "Rev v0.1 (ECO1)" config ESP32C3_REV_MIN_2 - bool "Rev 2" + bool "Rev v0.2 (ECO2)" config ESP32C3_REV_MIN_3 - bool "Rev 3" + bool "Rev v0.3 (ECO3)" config ESP32C3_REV_MIN_4 - bool "Rev 4" + bool "Rev v0.4 (ECO4)" endchoice -config ESP32C3_REV_MIN +config ESP32C3_REV_MIN_FULL int default 0 if ESP32C3_REV_MIN_0 default 1 if ESP32C3_REV_MIN_1 default 2 if ESP32C3_REV_MIN_2 default 3 if ESP32C3_REV_MIN_3 default 4 if ESP32C3_REV_MIN_4 + +config ESP_REV_MIN_FULL + int + default ESP32C3_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32-C3 Revision (Rev v0.99)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32C3_REV_MIN_FULL to ESP32C3_REV_MAX_FULL + +config ESP32C3_REV_MAX_FULL + int + default 99 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32C3_REV_MAX_FULL diff --git a/components/esp_hw_support/port/esp32c3/rtc_init.c b/components/esp_hw_support/port/esp32c3/rtc_init.c index 6884aff4d1..3f2b46e33c 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_init.c +++ b/components/esp_hw_support/port/esp32c3/rtc_init.c @@ -317,7 +317,7 @@ static void set_rtc_dig_dbias() 3. a reasonable rtc_dbias can be calculated by a certion formula. */ uint32_t rtc_dbias = 28, dig_dbias = 28; - uint8_t chip_version = efuse_hal_get_minor_chip_version(); + unsigned chip_version = efuse_hal_chip_revision(); if (chip_version >= 3) { dig_dbias = get_dig_dbias_by_efuse(chip_version); if (dig_dbias != 0) { diff --git a/components/esp_hw_support/port/esp32c3/rtc_sleep.c b/components/esp_hw_support/port/esp32c3/rtc_sleep.c index b1bc5d81fb..179f6e93dd 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_sleep.c +++ b/components/esp_hw_support/port/esp32c3/rtc_sleep.c @@ -16,6 +16,7 @@ #include "soc/fe_reg.h" #include "soc/timer_group_reg.h" #include "soc/system_reg.h" +#include "soc/chip_revision.h" #include "esp32c3/rom/ets_sys.h" #include "esp32c3/rom/rtc.h" #include "regi2c_ctrl.h" @@ -76,8 +77,8 @@ void rtc_sleep_get_default_config(uint32_t sleep_flags, rtc_sleep_config_t *out_ if (sleep_flags & RTC_SLEEP_PD_DIG) { unsigned atten_deep_sleep = RTC_CNTL_DBG_ATTEN_DEEPSLEEP_DEFAULT; -#if CONFIG_ESP32C3_REV_MIN < 3 - if (efuse_hal_get_minor_chip_version() < 3) { +#if CONFIG_ESP32C3_REV_MIN_FULL < 3 + if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 3)) { atten_deep_sleep = 0; /* workaround for deep sleep issue in high temp on ECO2 and below */ } #endif diff --git a/components/esp_hw_support/port/esp32h2/Kconfig.hw_support b/components/esp_hw_support/port/esp32h2/Kconfig.hw_support new file mode 100644 index 0000000000..bcb9bff200 --- /dev/null +++ b/components/esp_hw_support/port/esp32h2/Kconfig.hw_support @@ -0,0 +1,41 @@ +choice ESP32H2_REV_MIN + prompt "Minimum Supported ESP32-H2 Revision" + default ESP32H2_REV_MIN_0 + help + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). + + The complied binary will only support chips above this revision, + this will also help to reduce binary size. + + config ESP32H2_REV_MIN_0 + bool "Rev v0.0 (ECO0)" +endchoice + +config ESP32H2_REV_MIN_FULL + int + default 0 if ESP32H2_REV_MIN_0 + +config ESP_REV_MIN_FULL + int + default ESP32H2_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32-H2 Revision (Rev v1.99)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32H2_REV_MIN_FULL to ESP32H2_REV_MAX_FULL + +config ESP32H2_REV_MAX_FULL + int + default 199 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32H2_REV_MAX_FULL diff --git a/components/esp_hw_support/port/esp32s2/Kconfig.hw_support b/components/esp_hw_support/port/esp32s2/Kconfig.hw_support new file mode 100644 index 0000000000..de3d319f20 --- /dev/null +++ b/components/esp_hw_support/port/esp32s2/Kconfig.hw_support @@ -0,0 +1,44 @@ +choice ESP32S2_REV_MIN + prompt "Minimum Supported ESP32-S2 Revision" + default ESP32S2_REV_MIN_0 + help + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). + + The complied binary will only support chips above this revision, + this will also help to reduce binary size. + + config ESP32S2_REV_MIN_0 + bool "Rev v0.0 (ECO0)" + config ESP32S2_REV_MIN_1 + bool "Rev v1.0 (ECO1)" +endchoice + +config ESP32S2_REV_MIN_FULL + int + default 0 if ESP32S2_REV_MIN_0 + default 100 if ESP32S2_REV_MIN_1 + +config ESP_REV_MIN_FULL + int + default ESP32S2_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32-S2 Revision (Rev v1.99)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32S2_REV_MIN_FULL to ESP32S2_REV_MAX_FULL + +config ESP32S2_REV_MAX_FULL + int + default 199 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32S2_REV_MAX_FULL diff --git a/components/esp_hw_support/port/esp32s3/Kconfig.hw_support b/components/esp_hw_support/port/esp32s3/Kconfig.hw_support new file mode 100644 index 0000000000..5b2401e399 --- /dev/null +++ b/components/esp_hw_support/port/esp32s3/Kconfig.hw_support @@ -0,0 +1,47 @@ +choice ESP32S3_REV_MIN + prompt "Minimum Supported ESP32-S3 Revision" + default ESP32S3_REV_MIN_0 + help + Required minimum chip revision. ESP-IDF will check for it and + reject to boot if the chip revision fails the check. + This ensures the chip used will have some modifications (features, or bugfixes). + + The complied binary will only support chips above this revision, + this will also help to reduce binary size. + + config ESP32S3_REV_MIN_0 + bool "Rev v0.0 (ECO0)" + config ESP32S3_REV_MIN_1 + bool "Rev v0.1 (ECO1)" + config ESP32S3_REV_MIN_2 + bool "Rev v0.2 (ECO2)" +endchoice + +config ESP32S3_REV_MIN_FULL + int + default 0 if ESP32S3_REV_MIN_0 + default 1 if ESP32S3_REV_MIN_1 + default 2 if ESP32S3_REV_MIN_2 + +config ESP_REV_MIN_FULL + int + default ESP32S3_REV_MIN_FULL + + # + # MAX Revision + # + + comment "Maximum Supported ESP32-S3 Revision (Rev v0.99)" + # Maximum revision that IDF supports. + # It can not be changed by user. + # Only Espressif can change it when a new version will be supported in IDF. + # Supports all chips starting from ESP32S3_REV_MIN_FULL to ESP32S3_REV_MAX_FULL + +config ESP32S3_REV_MAX_FULL + int + default 99 + # keep in sync the "Maximum Supported Revision" description with this value + +config ESP_REV_MAX_FULL + int + default ESP32S3_REV_MAX_FULL diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 52e1a20240..ca9c7d0a6e 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -675,7 +675,7 @@ void esp_phy_load_cal_and_init(void) ESP_LOGI(TAG, "phy_version %s", phy_version); #if CONFIG_IDF_TARGET_ESP32S2 - phy_eco_version_sel(efuse_hal_get_major_chip_version()); + phy_eco_version_sel(efuse_hal_chip_revision() / 100); #endif esp_phy_calibration_data_t* cal_data = (esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1); diff --git a/components/esp_psram/esp32/Kconfig.spiram b/components/esp_psram/esp32/Kconfig.spiram index 10803a814e..262e69dfd0 100644 --- a/components/esp_psram/esp32/Kconfig.spiram +++ b/components/esp_psram/esp32/Kconfig.spiram @@ -63,7 +63,7 @@ menu "SPI RAM config" config SPIRAM_CACHE_WORKAROUND bool "Enable workaround for bug in SPI RAM cache for Rev1 ESP32s" - depends on (SPIRAM_USE_MEMMAP || SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC) && (ESP32_REV_MIN < 3) + depends on (SPIRAM_USE_MEMMAP || SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC) && (ESP32_REV_MIN_FULL < 300) default "y" help Revision 1 of the ESP32 has a bug that can cause a write to PSRAM not to take place in some situations diff --git a/components/esp_psram/esp32/esp_psram_impl_quad.c b/components/esp_psram/esp32/esp_psram_impl_quad.c index 5f65464354..69b3982da8 100644 --- a/components/esp_psram/esp32/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32/esp_psram_impl_quad.c @@ -25,6 +25,7 @@ #include "soc/efuse_periph.h" #include "soc/soc_caps.h" #include "soc/spi_periph.h" +#include "soc/chip_revision.h" #include "driver/gpio.h" #include "hal/efuse_hal.h" #include "hal/gpio_hal.h" @@ -832,7 +833,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra } psram_io.psram_clk_io = D2WD_PSRAM_CLK_IO; psram_io.psram_cs_io = D2WD_PSRAM_CS_IO; - } else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 && efuse_hal_get_major_chip_version() >= 3) { + } else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 && ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300)) { ESP_EARLY_LOGE(TAG, "This chip is ESP32-PICO-V3. It does not support PSRAM (disable it in Kconfig)"); abort(); } else if ((pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) || (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4)) { diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index de4858f7e1..f007067ee6 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -84,7 +84,7 @@ if(BOOTLOADER_BUILD) if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH) rom_linker_script("spiflash") endif() - if(CONFIG_ESP32_REV_MIN_3) + if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300) rom_linker_script("eco3") endif() @@ -133,7 +133,7 @@ else() # Regular app build rom_linker_script("spiflash") endif() - if(CONFIG_ESP32_REV_MIN_3) + if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300) rom_linker_script("eco3") endif() @@ -186,7 +186,7 @@ else() # Regular app build endif() endif() - if(CONFIG_ESP32C3_REV_MIN_3 OR CONFIG_ESP32C3_REV_MIN_4) + if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3) rom_linker_script("eco3") endif() diff --git a/components/esp_rom/include/esp32/rom/rsa_pss.h b/components/esp_rom/include/esp32/rom/rsa_pss.h index bfc1e68cda..9c6979484d 100644 --- a/components/esp_rom/include/esp32/rom/rsa_pss.h +++ b/components/esp_rom/include/esp32/rom/rsa_pss.h @@ -1,21 +1,13 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include "sdkconfig.h" -#ifdef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 #include #include @@ -47,4 +39,4 @@ bool ets_emsa_pss_verify(const uint8_t *encoded_message, const uint8_t *mhash, u } #endif -#endif // CONFIG_ESP32_REV_MIN_3 +#endif // CONFIG_ESP32_REV_MIN_FULL >= 300 diff --git a/components/esp_rom/include/esp32/rom/secure_boot.h b/components/esp_rom/include/esp32/rom/secure_boot.h index 50a3fcd494..a34993a25f 100644 --- a/components/esp_rom/include/esp32/rom/secure_boot.h +++ b/components/esp_rom/include/esp32/rom/secure_boot.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,7 +33,7 @@ bool ets_secure_boot_check_start(uint8_t abs_index, uint32_t iv_addr); int ets_secure_boot_check_finish(uint32_t *abstract); -#ifdef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 #include "rsa_pss.h" #define SECURE_BOOT_NUM_BLOCKS 1 @@ -114,7 +114,7 @@ bool ets_use_secure_boot_v2(void); #else #define SECURE_BOOT_NUM_BLOCKS 0 -#endif /* CONFIG_ESP32_REV_MIN_3 */ +#endif /* CONFIG_ESP32_REV_MIN_FULL >= 300 */ #ifdef __cplusplus } diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 0feda4e9f5..44b3ce7cd8 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -19,6 +19,7 @@ #include "hal/wdt_hal.h" #include "hal/uart_types.h" #include "hal/uart_ll.h" +#include "hal/efuse_hal.h" #include "esp_heap_caps_init.h" #include "spi_flash_mmap.h" @@ -444,6 +445,12 @@ static void start_cpu0_default(void) esp_app_get_elf_sha256(buf, sizeof(buf)); ESP_EARLY_LOGI(TAG, "ELF file SHA256: %s...", buf); ESP_EARLY_LOGI(TAG, "ESP-IDF: %s", app_desc->idf_ver); + + ESP_EARLY_LOGI(TAG, "Min chip rev: v%d.%d", CONFIG_ESP_REV_MIN_FULL / 100, CONFIG_ESP_REV_MIN_FULL % 100); + ESP_EARLY_LOGI(TAG, "Max chip rev: v%d.%d %s",CONFIG_ESP_REV_MAX_FULL / 100, CONFIG_ESP_REV_MAX_FULL % 100, + efuse_ll_get_disable_wafer_version_major() ? "(constraint ignored)" : ""); + unsigned revision = efuse_hal_chip_revision(); + ESP_EARLY_LOGI(TAG, "Chip rev: v%d.%d", revision / 100, revision % 100); } #endif diff --git a/components/esp_system/test/test_reset_reason.c b/components/esp_system/test/test_reset_reason.c index 60b1c343a4..984d790059 100644 --- a/components/esp_system/test/test_reset_reason.c +++ b/components/esp_system/test/test_reset_reason.c @@ -21,11 +21,11 @@ #define INT_WDT_PANIC "Interrupt wdt timeout on CPU0" #define INT_WDT "TG1WDT_SYS_RESET" #define RTC_WDT "RTCWDT_RTC_RESET" -#ifdef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 #define BROWNOUT "RTCWDT_BROWN_OUT_RESET" #else #define BROWNOUT "SW_CPU_RESET" -#endif // CONFIG_ESP32_REV_MIN_3 +#endif // CONFIG_ESP32_REV_MIN_FULL >= 300 #define STORE_ERROR "StoreProhibited" #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index 72f5aabab4..9ffe0f45ea 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -60,22 +60,25 @@ if(NOT CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION AND endif() endif() -if(CONFIG_ESP32_REV_MIN) - set(min_rev ${CONFIG_ESP32_REV_MIN}) +# We still set "--min-rev" to keep the app compatible with older booloaders where this field is controlled. +if(CONFIG_IDF_TARGET_ESP32) + # for this chip min_rev is major revision + math(EXPR min_rev "${CONFIG_ESP_REV_MIN_FULL} / 100") endif() -if(CONFIG_ESP32C3_REV_MIN) - set(min_rev ${CONFIG_ESP32C3_REV_MIN}) -endif() -if(CONFIG_IDF_TARGET_ESP32C2) - set(min_rev 1) +if(CONFIG_IDF_TARGET_ESP32C3) + # for this chip min_rev is minor revision + math(EXPR min_rev "${CONFIG_ESP_REV_MIN_FULL} % 100") endif() if(min_rev) list(APPEND esptool_elf2image_args --min-rev ${min_rev}) - set(monitor_rev_args "--revision;${min_rev}") - unset(min_rev) endif() +list(APPEND esptool_elf2image_args --min-rev-full ${CONFIG_ESP_REV_MIN_FULL}) +list(APPEND esptool_elf2image_args --max-rev-full ${CONFIG_ESP_REV_MAX_FULL}) + +set(monitor_rev_args "--revision;${CONFIG_ESP_REV_MIN_FULL}") + if(CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE) # Set ESPFLASHSIZE to 'detect' *after* esptool_elf2image_args are generated, # as elf2image can't have 'detect' as an option... diff --git a/components/hal/efuse_hal.c b/components/hal/efuse_hal.c index ae584110f7..8bcf30c635 100644 --- a/components/hal/efuse_hal.c +++ b/components/hal/efuse_hal.c @@ -10,6 +10,7 @@ #include "hal/efuse_ll.h" #include "hal/assert.h" #include "hal/efuse_hal.h" +#include "esp_attr.h" void efuse_hal_get_mac(uint8_t *mac) @@ -18,7 +19,7 @@ void efuse_hal_get_mac(uint8_t *mac) *((uint16_t*)&mac[4]) = (uint16_t) efuse_ll_get_mac1(); } -uint32_t efuse_hal_chip_revision(void) +IRAM_ATTR uint32_t efuse_hal_chip_revision(void) { return efuse_hal_get_major_chip_version() * 100 + efuse_hal_get_minor_chip_version(); } diff --git a/components/hal/esp32/efuse_hal.c b/components/hal/esp32/efuse_hal.c index 40df370240..e25cbd8135 100644 --- a/components/hal/esp32/efuse_hal.c +++ b/components/hal/esp32/efuse_hal.c @@ -11,8 +11,9 @@ #include "hal/assert.h" #include "hal/efuse_hal.h" #include "soc/syscon_reg.h" +#include "esp_attr.h" -uint32_t efuse_hal_get_major_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) { uint8_t eco_bit0 = efuse_ll_get_chip_ver_rev1(); uint8_t eco_bit1 = efuse_ll_get_chip_ver_rev2(); @@ -44,7 +45,7 @@ uint32_t efuse_hal_get_major_chip_version(void) return chip_ver; } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { return efuse_ll_get_chip_wafer_version_minor(); } diff --git a/components/hal/esp32c2/efuse_hal.c b/components/hal/esp32c2/efuse_hal.c index 2bf6908baa..4d5cb8b089 100644 --- a/components/hal/esp32c2/efuse_hal.c +++ b/components/hal/esp32c2/efuse_hal.c @@ -11,15 +11,16 @@ #include "hal/efuse_hal.h" #include "hal/efuse_ll.h" #include "hal/clk_tree_ll.h" +#include "esp_attr.h" #define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block)))) -uint32_t efuse_hal_get_major_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) { return efuse_ll_get_chip_wafer_version_major(); } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { return efuse_ll_get_chip_wafer_version_minor(); } diff --git a/components/hal/esp32c3/efuse_hal.c b/components/hal/esp32c3/efuse_hal.c index ff700c2490..c951c38e8c 100644 --- a/components/hal/esp32c3/efuse_hal.c +++ b/components/hal/esp32c3/efuse_hal.c @@ -10,16 +10,17 @@ #include "hal/assert.h" #include "hal/efuse_hal.h" #include "hal/efuse_ll.h" +#include "esp_attr.h" #define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x08 << (4 * (block)))) #define ESP_EFUSE_BLOCK_ERROR_NUM_BITS(error_reg, block) ((error_reg) & (0x07 << (4 * (block)))) -uint32_t efuse_hal_get_major_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) { return efuse_ll_get_chip_wafer_version_major(); } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { return efuse_ll_get_chip_wafer_version_minor(); } diff --git a/components/hal/esp32h2/efuse_hal.c b/components/hal/esp32h2/efuse_hal.c index e962e3cc3e..11aabfd4fb 100644 --- a/components/hal/esp32h2/efuse_hal.c +++ b/components/hal/esp32h2/efuse_hal.c @@ -10,15 +10,16 @@ #include "hal/assert.h" #include "hal/efuse_hal.h" #include "hal/efuse_ll.h" +#include "esp_attr.h" #define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block)))) -uint32_t efuse_hal_get_major_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) { return efuse_ll_get_chip_wafer_version_major(); } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { return efuse_ll_get_chip_wafer_version_minor(); } diff --git a/components/hal/esp32s2/efuse_hal.c b/components/hal/esp32s2/efuse_hal.c index a62b225668..59911c5189 100644 --- a/components/hal/esp32s2/efuse_hal.c +++ b/components/hal/esp32s2/efuse_hal.c @@ -11,15 +11,16 @@ #include "hal/efuse_hal.h" #include "hal/efuse_ll.h" #include "esp32s2/rom/efuse.h" +#include "esp_attr.h" #define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block)))) -uint32_t efuse_hal_get_major_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) { return efuse_ll_get_chip_wafer_version_major(); } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { return efuse_ll_get_chip_wafer_version_minor(); } diff --git a/components/hal/esp32s3/efuse_hal.c b/components/hal/esp32s3/efuse_hal.c index 5b5a1a7e08..e7503b2696 100644 --- a/components/hal/esp32s3/efuse_hal.c +++ b/components/hal/esp32s3/efuse_hal.c @@ -35,7 +35,7 @@ IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) return efuse_ll_get_chip_wafer_version_major(); } -uint32_t efuse_hal_get_minor_chip_version(void) +IRAM_ATTR uint32_t efuse_hal_get_minor_chip_version(void) { uint32_t minor_raw = efuse_ll_get_chip_wafer_version_minor(); diff --git a/components/hal/include/hal/twai_types.h b/components/hal/include/hal/twai_types.h index f4d5ef5286..f7721dd4bf 100644 --- a/components/hal/include/hal/twai_types.h +++ b/components/hal/include/hal/twai_types.h @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -65,7 +57,7 @@ extern "C" { #define TWAI_TIMING_CONFIG_5KBITS() {.brp = 800, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false} #define TWAI_TIMING_CONFIG_10KBITS() {.brp = 400, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false} #endif -#if (SOC_TWAI_BRP_MAX > 128) || (CONFIG_ESP32_REV_MIN >= 2) +#if (SOC_TWAI_BRP_MAX > 128) || (CONFIG_ESP32_REV_MIN_FULL >= 200) #define TWAI_TIMING_CONFIG_12_5KBITS() {.brp = 256, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false} #define TWAI_TIMING_CONFIG_16KBITS() {.brp = 200, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false} #define TWAI_TIMING_CONFIG_20KBITS() {.brp = 200, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false} diff --git a/components/soc/esp32/include/soc/Kconfig.soc_caps.in b/components/soc/esp32/include/soc/Kconfig.soc_caps.in index a75cba4bc8..fbbc877e42 100644 --- a/components/soc/esp32/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32/include/soc/Kconfig.soc_caps.in @@ -17,7 +17,7 @@ config SOC_DPORT_WORKAROUND config SOC_CAPS_ECO_VER_MAX int - default 3 + default 301 config SOC_ADC_SUPPORTED bool diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 8f276f697f..22aacb1444 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -42,7 +42,7 @@ #ifdef __has_include # if __has_include("sdkconfig.h") # include "sdkconfig.h" -# define SOC_CAPS_ECO_VER CONFIG_ESP32_REV_MIN +# define SOC_CAPS_ECO_VER CONFIG_ESP32_REV_MIN_FULL # endif #endif @@ -62,7 +62,7 @@ #endif /*-------------------------- COMMON CAPS ---------------------------------------*/ -#define SOC_CAPS_ECO_VER_MAX 3 +#define SOC_CAPS_ECO_VER_MAX 301 #define SOC_ADC_SUPPORTED 1 #define SOC_DAC_SUPPORTED 1 @@ -90,9 +90,9 @@ #define SOC_SECURE_BOOT_SUPPORTED 1 #define SOC_TOUCH_SENSOR_SUPPORTED 1 -#if SOC_CAPS_ECO_VER < 2 +#if SOC_CAPS_ECO_VER < 200 #define SOC_DPORT_WORKAROUND 1 -#endif // SOC_CAPS_ECO_VER < 2 +#endif // SOC_CAPS_ECO_VER < 200 #define SOC_DPORT_WORKAROUND_DIS_INTERRUPT_LVL (5U) /*-------------------------- XTAL CAPS ---------------------------------------*/ @@ -127,7 +127,7 @@ #define SOC_RTC_SLOW_CLOCK_SUPPORT_8MD256 (1) /*-------------------------- BROWNOUT CAPS -----------------------------------*/ -#if SOC_CAPS_ECO_VER >= 1 +#if SOC_CAPS_ECO_VER >= 100 #define SOC_BROWNOUT_RESET_SUPPORTED 1 #endif @@ -301,7 +301,7 @@ /*-------------------------- TWAI CAPS ---------------------------------------*/ #define SOC_TWAI_BRP_MIN 2 -#if SOC_CAPS_ECO_VER >= 2 +#if SOC_CAPS_ECO_VER >= 200 # define SOC_TWAI_BRP_MAX 256 # define SOC_TWAI_BRP_DIV_SUPPORTED 1 # define SOC_TWAI_BRP_DIV_THRESH 128 diff --git a/components/soc/include/soc/chip_revision.h b/components/soc/include/soc/chip_revision.h new file mode 100644 index 0000000000..d944d71cf1 --- /dev/null +++ b/components/soc/include/soc/chip_revision.h @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "sdkconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convenient macros to check current wafer version against a version where some changes are introduced. + * Use `ESP_CHIP_REV_ABOVE` for a change introduced before any major versions. + * Use `ESP_CHIP_REV_MAJOR_AND_ABOVE` for changes introduced after a major version is added. + * For example, on ESP32 we have wafer versions: + * + * 0.0 -> 1.0 -> 2.0 -> 3.0 -> 3.1 -> N.A. + * |->1.1 + * + * - If we are adding code for a change on 1.1, we should use `ESP_CHIP_REV_MAJOR_AND_ABOVE` + * because there is already major version 2 existing. The condition will be met from 1.1 to 1.99, + * while not inherited by 2.0 and above. + * + * - If we are adding code for a change on 3.1, we should use `ESP_CHIP_REV_ABOVE` + * because there is no major version 4. The condition will be met from 3.1 to 3.99 and 4.0 and above. + * Even if we add revision 4.0 on this version, the logic will be inherited. + */ + +#define ESP_CHIP_REV_ABOVE(rev, min_rev) ((min_rev) <= (rev)) +#define ESP_CHIP_REV_MAJOR_AND_ABOVE(rev, min_rev) (((rev) / 100 == (min_rev) / 100) && ((rev) >= (min_rev))) + +_Static_assert(CONFIG_ESP_REV_MIN_FULL <= CONFIG_ESP_REV_MAX_FULL); + +#ifdef __cplusplus +} +#endif diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index feb254b16c..47b8d19ae7 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -171,6 +171,7 @@ INPUT = \ $(PROJECT_PATH)/components/hal/include/hal/touch_sensor_types.h \ $(PROJECT_PATH)/components/hal/include/hal/twai_types.h \ $(PROJECT_PATH)/components/hal/include/hal/uart_types.h \ + $(PROJECT_PATH)/components/hal/include/hal/efuse_hal.h \ $(PROJECT_PATH)/components/heap/include/esp_heap_caps.h \ $(PROJECT_PATH)/components/heap/include/esp_heap_caps_init.h \ $(PROJECT_PATH)/components/heap/include/esp_heap_trace.h \ diff --git a/docs/en/api-reference/system/chip_revision.rst b/docs/en/api-reference/system/chip_revision.rst new file mode 100644 index 0000000000..8d6d4101dd --- /dev/null +++ b/docs/en/api-reference/system/chip_revision.rst @@ -0,0 +1,129 @@ +Chip Revision +============= + +Overview +-------- + +A new chip versioning logic was introduced in new chips. Chips have several eFuse version fields: + +- Major wafer version (``WAFER_VERSION_MAJOR`` eFuse) +- Minor wafer version (``WAFER_VERSION_MINOR`` eFuse) +- Ignore maximal revision (``DISABLE_WAFER_VERSION_MAJOR`` eFuse) + +The new versioning logic is being introduced to distinguish changes in chips as breaking changes and non-breaking changes. Chips with non-breaking changes can run the same software as the previous chip. The previous chip means that the major version is the same. + +If the newly released chip does not have breaking changes, that means it can run the same software as the previous chip, then in that chip we keep the same major version and increment the minor version by 1. Otherwise, if there is a breaking change in the newly released chip, meaning it can not run the same software as the previous chip, then in that chip we increase the major version and set the minor version to 0. + +The software supports a number of revisions, from the minimum to the maximum (the min/max configs are defined in Kconfig). If the software is unaware of a new chip (when the chip version is out of range), it will refuse to run on it unless the Ignore maximum revision restrictions bit is set. This bit removes the upper revision limit. + +Minimum versions limits the software to only run on a chip revision that is high enough to support some features. Maximum version is the maximum version that is well-supported by current software. When chip version is above the maximum version, software will reject to boot, because it may not work on, or work with risk on the chip. + +Adding the major and minor wafer revision make the versioning logic is branchable. + +.. note:: + + The previous versioning logic was based on a single eFuse version field (``WAFER_VERSION``). This approach makes it impossible to mark chips as breaking or non-breaking changes, and the versioning logic becomes linear. + +Using the branched versioning scheme allows us to support more chips in the software without updating the software when a new released compatible chip is used. Thus, the software will be compatible with as many new chip revisions as possible. If the software is no longer compatible with a new chip with breaking changes, the software will abort. + +Revisions +--------- + +.. include:: inc/revisions_{IDF_TARGET_NAME}.rst + +Chip Revision ``vX.Y``, where: + +- ``X`` means Major wafer version. If it is changed, it means that the current software version is not compatible with this released chip and the software must be updated to use this chip. +- ``Y`` means Minor wafer version. If it is changed that means the current software version is compatible with the released chip, and there is no need to update the software. + +The ``vX.Y`` chip version format will be used further instead of the ECO number. + +Representing Revision Requirement Of A Binary Image +--------------------------------------------------- + +The 2nd stage bootloader and the application binary images have the :cpp:type:`esp_image_header_t` header, which stores the revision numbers of the chip on which the software can be run. This header has 3 fields related to revisions: + +- ``min_chip_rev`` - Minimal chip MAJOR revision required by image (but for ESP32-C3 it is MINOR revision). Its value is determined by :ref:`CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN`. +- ``min_chip_rev_full`` - Minimal chip MINOR revision required by image in format: ``major * 100 + minor``. Its value is determined by :ref:`CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN`. +- ``max_chip_rev_full`` - Maximal chip revision required by image in format: ``major * 100 + minor``. Its value is determined by ``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MAX_FULL``. It can not be changed by user. Only Espressif can change it when a new version will be supported in IDF. + +Chip Revision APIs +------------------ + +These APIs helps to get chip revision from eFuses: + +- :cpp:func:`efuse_hal_chip_revision`. It returns revision in the ``major * 100 + minor`` format. +- :cpp:func:`efuse_hal_get_major_chip_version`. It returns Major revision. +- :cpp:func:`efuse_hal_get_minor_chip_version`. It returns Minor revision. + +The following Kconfig definitions (in ``major * 100 + minor`` format) that can help add the chip revision dependency to the code: + +- ``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN_FULL`` +- ``CONFIG_ESP_REV_MIN_FULL`` +- ``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MAX_FULL`` +- ``CONFIG_ESP_REV_MAX_FULL`` + +Maximal And Minimal Revision Restrictions +----------------------------------------- + +The order for checking the minimum and maximum revisions: + +1. The 1st stage bootloader (ROM bootloader) does not check minimal and maximal revision fields from :cpp:type:`esp_image_header_t` before running the 2nd stage bootloader. + +2. The 2nd stage bootloader checks at the initialization phase that bootloader itself can be launched on the chip of this revision. It extracts the minimum revision from the header of the bootloader image and checks against the chip revision from eFuses. If the chip revision is less than the minimum revision, the bootloader refuses to boot up and aborts. The maximum revision is not checked at this phase. + +3. Then the 2nd stage bootloader checks the revision requirements of the application. It extracts the minimum and maximum revisions from the header of the application image and checks against the chip revision from eFuses. If the chip revision is less than the minimum revision or higher than the maximum revision, the bootloader refuses to boot up and aborts. However, if the Ignore maximal revision bit is set, the maximum revision constraint can be ignored. The ignore bit is set by the customer themself when there is confirmation that the software is able to work with this chip revision. + +4. Further, at the OTA update stage, the running application checks if the new software matches the chip revision. It extracts the minimum and maximum revisions from the header of the new application image and checks against the chip revision from eFuses. It checks for revision matching in the same way that the bootloader does, so that the chip revision is between the min and max revisions (logic of ignoring max revision also applies). + +Issues +------ + +1. If the 2nd stage bootloader is run on the chip revision < minimum revision shown in the image, a reboot occurs. The following message will be printed: + +.. code-block:: none + + Image requires chip rev >= v3.0, but chip is v1.0 + +To resolve this issue: + +- make sure the chip you are using is suitable for the software, or use a chip with the required minimum revision or higher. +- update the software with :ref:`CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN` to get it ``<=`` the revision of chip being used + +2. If application does not match minimal and maximal chip revisions, a reboot occurs. The following message will be printed: + +.. code-block:: none + + Image requires chip rev <= v2.99, but chip is v3.0 + +To resolve this issue, update the IDF to a newer version that supports the used chip (``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MAX_FULL``). Another way to fix this is to set the ``Ignore maximal revision`` bit in eFuse or use a chip that is suitable for the software. + +Backward Compatible With Bootloaders Built By Older ESP-IDF Versions +-------------------------------------------------------------------- + +.. only:: esp32 or esp32c3 or esp32s2 or esp32s3 + + The old bootloaders (IDF < 5.0) do not know about Major and Minor wafer version eFuses. They use one single eFuse for this - wafer version. + +.. only:: esp32 + + The old bootloaders did not read the minor wafer version eFuse, the major version can be only <= 3. So it means that the old bootloader can detect correctly only chip version in range v0.0 - v3.0, where the minor version is always 0. + +.. only:: esp32c2 + + {IDF_TARGET_NAME} chip support was added in IDF 5.0. The bootloader is able to detect any chip versions in range v0.0 - v3.15. + +.. only:: esp32c3 + + {IDF_TARGET_NAME} chip support was added in IDF 4.3. The old bootloaders can not read all bits of the wafer version eFuse, it can read only the first 3 low bits. So it means that the old bootloader can not detect chip version correctly. Chips v0.0 - v0.8 will be detected correctly, but other chip versions will be recognized as a version from this range. + +.. only:: esp32s2 or esp32s3 + + {IDF_TARGET_NAME} chip support was added in IDF 4.2. {IDF_TARGET_NAME} chips have ``rev_min`` in :cpp:type:`esp_image_header_t` header = 0 because ``Minimum Supported ESP32-S2 Revision`` Kconfig option was not introduced, it means that the old bootloader does not check the chip revision. Any app can be loaded by such bootloader in range v0.0 - v3.15. + +Please check the chip version using ``esptool chip_id`` command. + +API Reference +------------- + +.. include-build-file:: inc/efuse_hal.inc diff --git a/docs/en/api-reference/system/inc/revisions_ESP32-C2.rst b/docs/en/api-reference/system/inc/revisions_ESP32-C2.rst new file mode 100644 index 0000000000..afc2fd488b --- /dev/null +++ b/docs/en/api-reference/system/inc/revisions_ESP32-C2.rst @@ -0,0 +1,8 @@ + ++--------+------------------------+ +| ECO | Revision (Major.Minor) | ++--------+------------------------+ +| ECO0 | v0.0 | ++--------+------------------------+ +| ECO1 | v1.0 | ++--------+------------------------+ diff --git a/docs/en/api-reference/system/inc/revisions_ESP32-C3.rst b/docs/en/api-reference/system/inc/revisions_ESP32-C3.rst new file mode 100644 index 0000000000..2f5630b1ad --- /dev/null +++ b/docs/en/api-reference/system/inc/revisions_ESP32-C3.rst @@ -0,0 +1,12 @@ + ++--------+------------------------+ +| ECO | Revision (Major.Minor) | ++--------+------------------------+ +| ECO1 | v0.1 | ++--------+------------------------+ +| ECO2 | v0.2 | ++--------+------------------------+ +| ECO3 | v0.3 | ++--------+------------------------+ +| ECO4 | v0.4 | ++--------+------------------------+ diff --git a/docs/en/api-reference/system/inc/revisions_ESP32-S2.rst b/docs/en/api-reference/system/inc/revisions_ESP32-S2.rst new file mode 100644 index 0000000000..afc2fd488b --- /dev/null +++ b/docs/en/api-reference/system/inc/revisions_ESP32-S2.rst @@ -0,0 +1,8 @@ + ++--------+------------------------+ +| ECO | Revision (Major.Minor) | ++--------+------------------------+ +| ECO0 | v0.0 | ++--------+------------------------+ +| ECO1 | v1.0 | ++--------+------------------------+ diff --git a/docs/en/api-reference/system/inc/revisions_ESP32-S3.rst b/docs/en/api-reference/system/inc/revisions_ESP32-S3.rst new file mode 100644 index 0000000000..7bb4949df1 --- /dev/null +++ b/docs/en/api-reference/system/inc/revisions_ESP32-S3.rst @@ -0,0 +1,10 @@ + ++--------+------------------------+ +| ECO | Revision (Major.Minor) | ++--------+------------------------+ +| ECO0 | v0.0 | ++--------+------------------------+ +| ECO1 | v0.1 | ++--------+------------------------+ +| ECO2 | v0.2 | ++--------+------------------------+ diff --git a/docs/en/api-reference/system/inc/revisions_ESP32.rst b/docs/en/api-reference/system/inc/revisions_ESP32.rst new file mode 100644 index 0000000000..b729ef5a64 --- /dev/null +++ b/docs/en/api-reference/system/inc/revisions_ESP32.rst @@ -0,0 +1,16 @@ + ++--------+------------------------+ +| ECO | Revision (Major.Minor) | ++--------+------------------------+ +| ECO0 | v0.0 | ++--------+------------------------+ +| ECO1 | v1.0 | ++--------+------------------------+ +| ECO1.1 | v1.1 | ++--------+------------------------+ +| ECO2 | v2.0 | ++--------+------------------------+ +| ECO3 | v3.0 | ++--------+------------------------+ +| ECO4 | v3.1 | ++--------+------------------------+ diff --git a/docs/en/api-reference/system/index.rst b/docs/en/api-reference/system/index.rst index d3ce17cff2..f25867a653 100644 --- a/docs/en/api-reference/system/index.rst +++ b/docs/en/api-reference/system/index.rst @@ -9,6 +9,7 @@ System API app_image_format app_trace esp_function_with_shared_stack + chip_revision console efuse esp_err diff --git a/docs/en/migration-guides/release-5.x/system.rst b/docs/en/migration-guides/release-5.x/system.rst index 88d49cb9f4..c5efed9a71 100644 --- a/docs/en/migration-guides/release-5.x/system.rst +++ b/docs/en/migration-guides/release-5.x/system.rst @@ -163,3 +163,10 @@ Bootloader Support - The :cpp:type:`esp_app_desc_t` structure, which used to be declared in :component_file:`esp_app_format.h `, is now declared in :component_file:`esp_app_desc.h `. - The function :cpp:func:`bootloader_common_get_partition_description` has now been made private. Please use the alternative function :cpp:func:`esp_ota_get_partition_description`. Note that this function takes :cpp:type:`esp_partition_t` as its first argument instead of :cpp:type:`esp_partition_pos_t`. + +Chip Revision +^^^^^^^^^^^^^ + +The bootloader checks the chip revision at the beginning of the application loading. The application can only be loaded if the version is ``>=`` :ref:`CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN` and `<` ``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MAX_FULL``. + +The application checks the chip revision in the OTA update. The application can only be updated if the version is ``>=`` :ref:`CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MIN` and `<` ``CONFIG_{IDF_TARGET_CFG_PREFIX}_REV_MAX_FULL``. diff --git a/docs/zh_CN/api-reference/system/chip_revision.rst b/docs/zh_CN/api-reference/system/chip_revision.rst new file mode 100644 index 0000000000..71903a0dfd --- /dev/null +++ b/docs/zh_CN/api-reference/system/chip_revision.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/chip_revision.rst diff --git a/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C2.rst b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C2.rst new file mode 100644 index 0000000000..13245073b9 --- /dev/null +++ b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C2.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/inc/revisions_ESP32-C2.rst diff --git a/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C3.rst b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C3.rst new file mode 100644 index 0000000000..a02582a151 --- /dev/null +++ b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-C3.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/inc/revisions_ESP32-C3.rst diff --git a/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S2.rst b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S2.rst new file mode 100644 index 0000000000..4ca30773ef --- /dev/null +++ b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S2.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/inc/revisions_ESP32-S2.rst diff --git a/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S3.rst b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S3.rst new file mode 100644 index 0000000000..6690aa320b --- /dev/null +++ b/docs/zh_CN/api-reference/system/inc/revisions_ESP32-S3.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/inc/revisions_ESP32-S3.rst diff --git a/docs/zh_CN/api-reference/system/inc/revisions_ESP32.rst b/docs/zh_CN/api-reference/system/inc/revisions_ESP32.rst new file mode 100644 index 0000000000..fb4822a834 --- /dev/null +++ b/docs/zh_CN/api-reference/system/inc/revisions_ESP32.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/system/inc/revisions_ESP32.rst diff --git a/docs/zh_CN/api-reference/system/index.rst b/docs/zh_CN/api-reference/system/index.rst index e0a8c3f4f5..c118b721d4 100644 --- a/docs/zh_CN/api-reference/system/index.rst +++ b/docs/zh_CN/api-reference/system/index.rst @@ -9,6 +9,7 @@ System API app_image_format app_trace esp_function_with_shared_stack + chip_revision console efuse esp_err diff --git a/tools/cmake/project_description.json.in b/tools/cmake/project_description.json.in index 8ed6c197ce..330c5190a9 100644 --- a/tools/cmake/project_description.json.in +++ b/tools/cmake/project_description.json.in @@ -10,6 +10,8 @@ "git_revision": "${IDF_VER}", "target": "${CONFIG_IDF_TARGET}", "rev": "${CONFIG_ESP32_REV_MIN}", + "min_rev": "${CONFIG_ESP_REV_MIN_FULL}", + "max_rev": "${CONFIG_ESP_REV_MAX_FULL}", "phy_data_partition": "${CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION}", "monitor_baud" : "${CONFIG_ESPTOOLPY_MONITOR_BAUD}", "monitor_toolprefix": "${_CMAKE_TOOLCHAIN_PREFIX}", diff --git a/tools/idf_monitor_base/chip_specific_config.py b/tools/idf_monitor_base/chip_specific_config.py index 2184c4977c..87bb3c2ad9 100644 --- a/tools/idf_monitor_base/chip_specific_config.py +++ b/tools/idf_monitor_base/chip_specific_config.py @@ -27,7 +27,7 @@ conf = { 'enter_boot_set': 1.3, 'enter_boot_unset': 0.45, }, - 1: { + 100: { 'reset': 0.2, 'enter_boot_set': 0.1, 'enter_boot_unset': 0.05, diff --git a/tools/test_apps/security/secure_boot/main/secure_boot_main_esp32.c b/tools/test_apps/security/secure_boot/main/secure_boot_main_esp32.c index b4c8cf7a4e..0fd5c264a9 100644 --- a/tools/test_apps/security/secure_boot/main/secure_boot_main_esp32.c +++ b/tools/test_apps/security/secure_boot/main/secure_boot_main_esp32.c @@ -59,7 +59,7 @@ static void example_print_chip_info(void) static void example_secure_boot_status(void) { -#ifdef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 uint8_t efuse_trusted_digest[DIGEST_LEN] = {0}, i; ESP_LOGI(TAG, "Checking for secure boot v2.."); if(efuse_ll_get_secure_boot_v2_en()) { @@ -81,7 +81,7 @@ static void example_secure_boot_status(void) ESP_LOGI(TAG, "Checking for secure boot v1.."); if (efuse_ll_get_secure_boot_v1_en()) { ESP_LOGI(TAG, "ABS_DONE_0 is set. Secure Boot V1 enabled"); -#ifdef CONFIG_ESP32_REV_MIN_3 +#if CONFIG_ESP32_REV_MIN_FULL >= 300 ESP_LOGW(TAG, "This chip version supports Secure Boot V2. It is recommended to use Secure Boot V2."); #endif ESP_LOGI(TAG, "Checking the integrityof the key in BLK2..");