2727#include "esp_rom_caps.h"
2828
2929#define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */
30- #define IS_MAX_REV_SET ( max_chip_rev_full ) (((max_chip_rev_full ) != 65535) && ((max_chip_rev_full ) != 0))
30+ #define IS_FIELD_SET ( rev_full ) (((rev_full ) != 65535) && ((rev_full ) != 0))
3131
3232static const char * TAG = "boot_comm" ;
3333
@@ -57,6 +57,31 @@ int bootloader_common_get_active_otadata(esp_ota_select_entry_t *two_otadata)
5757 return bootloader_common_select_otadata (two_otadata , valid_two_otadata , true);
5858}
5959
60+ #if !CONFIG_IDF_TARGET_ESP32
61+ esp_err_t bootloader_common_check_efuse_blk_validity (uint32_t min_rev_full , uint32_t max_rev_full )
62+ {
63+ esp_err_t err = ESP_OK ;
64+ #ifndef CONFIG_IDF_ENV_FPGA
65+ // Check whether the efuse block version satisfy the requirements of current image.
66+ uint32_t revision = efuse_hal_blk_version ();
67+ uint32_t major_rev = revision / 100 ;
68+ uint32_t minor_rev = revision % 100 ;
69+ if (IS_FIELD_SET (min_rev_full ) && !ESP_EFUSE_BLK_REV_ABOVE (revision , min_rev_full )) {
70+ ESP_LOGE (TAG , "Image requires efuse blk rev >= v%" PRIu32 ".%" PRIu32 ", but chip is v%" PRIu32 ".%" PRIu32 ,
71+ min_rev_full / 100 , min_rev_full % 100 , major_rev , minor_rev );
72+ err = ESP_FAIL ;
73+ }
74+ // If burnt `disable_blk_version_major` bit, skip the max version check
75+ if ((IS_FIELD_SET (max_rev_full ) && (revision > max_rev_full ) && !efuse_hal_get_disable_blk_version_major ())) {
76+ ESP_LOGE (TAG , "Image requires efuse blk rev <= v%" PRIu32 ".%" PRIu32 ", but chip is v%" PRIu32 ".%" PRIu32 ,
77+ max_rev_full / 100 , max_rev_full % 100 , major_rev , minor_rev );
78+ err = ESP_FAIL ;
79+ }
80+ #endif
81+ return err ;
82+ }
83+ #endif // !CONFIG_IDF_TARGET_ESP32
84+
6085esp_err_t bootloader_common_check_chip_validity (const esp_image_header_t * img_hdr , esp_image_type type )
6186{
6287 esp_err_t err = ESP_OK ;
@@ -80,7 +105,7 @@ esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hd
80105 }
81106 if (type == ESP_IMAGE_APPLICATION ) {
82107 unsigned max_rev = img_hdr -> max_chip_rev_full ;
83- if ((IS_MAX_REV_SET (max_rev ) && (revision > max_rev ) && !efuse_hal_get_disable_wafer_version_major ())) {
108+ if ((IS_FIELD_SET (max_rev ) && (revision > max_rev ) && !efuse_hal_get_disable_wafer_version_major ())) {
84109 ESP_LOGE (TAG , "Image requires chip rev <= v%d.%d, but chip is v%d.%d" ,
85110 max_rev / 100 , max_rev % 100 ,
86111 major_rev , minor_rev );
0 commit comments