]> granicus.if.org Git - esp-idf/commitdiff
bootloader: shrink bin size
authorsuda-morris <362953310@qq.com>
Fri, 27 Sep 2019 02:58:30 +0000 (10:58 +0800)
committerbot <bot@espressif.com>
Tue, 8 Oct 2019 02:45:36 +0000 (02:45 +0000)
1. write a bootloader version of "getting chip revision" function.
2. reduce wordy log.

components/bootloader_support/include/bootloader_common.h
components/bootloader_support/src/bootloader_common.c
components/bootloader_support/src/bootloader_init.c
components/efuse/src/esp_efuse_fields.c

index 47733210ef674a3eec84a3d82a8b088496818f0e..e9577c83e775e3076fc614be882da2cf12b67f95 100644 (file)
@@ -142,6 +142,13 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata,
  */
 esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t *partition, esp_app_desc_t *app_desc);
 
+/**
+ * @brief Get chip revision
+ *
+ * @return Chip revision number
+ */
+uint8_t bootloader_common_get_chip_revision(void);
+
 /**
  * @brief Check if the image (bootloader and application) has valid chip ID and revision
  *
index 7d972214004f4c27ba0e78f41410942f7e40400b..9251331e76984c404286508e143e8bc4f1270728 100644 (file)
 #include "bootloader_common.h"
 #include "soc/gpio_periph.h"
 #include "soc/rtc.h"
+#include "soc/efuse_reg.h"
+#include "soc/apb_ctrl_reg.h"
 #include "esp_image_format.h"
 #include "bootloader_sha.h"
 #include "sys/param.h"
-#include "esp_efuse.h"
 
 #define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */
 
@@ -272,22 +273,50 @@ void bootloader_common_vddsdio_configure()
 #endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
 }
 
+#ifdef CONFIG_IDF_TARGET_ESP32
+uint8_t bootloader_common_get_chip_revision(void)
+{
+    uint8_t eco_bit0, eco_bit1, eco_bit2;
+    eco_bit0 = (REG_READ(EFUSE_BLK0_RDATA3_REG) & 0xF000) >> 15;
+    eco_bit1 = (REG_READ(EFUSE_BLK0_RDATA5_REG) & 0x100000) >> 20;
+    eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 0x80000000) >> 31;
+    uint32_t combine_value = (eco_bit2 << 2) | (eco_bit1 << 1) | eco_bit0;
+    uint8_t chip_ver = 0;
+    switch (combine_value) {
+    case 0:
+        chip_ver = 0;
+        break;
+    case 1:
+        chip_ver = 1;
+        break;
+    case 3:
+        chip_ver = 2;
+        break;
+    case 7:
+        chip_ver = 3;
+        break;
+    default:
+        chip_ver = 0;
+        break;
+    }
+    return chip_ver;
+}
+#endif
+
 esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr)
 {
     esp_err_t err = ESP_OK;
     esp_chip_id_t chip_id = CONFIG_IDF_FIRMWARE_CHIP_ID;
     if (chip_id != img_hdr->chip_id) {
-        ESP_LOGE(TAG, "image has invalid chip ID, expected at least %d, found %d", chip_id, img_hdr->chip_id);
+        ESP_LOGE(TAG, "mismatch chip ID, expect %d, found %d", chip_id, img_hdr->chip_id);
         err = ESP_FAIL;
     }
-    uint8_t revision = esp_efuse_get_chip_ver();
+    uint8_t revision = bootloader_common_get_chip_revision();
     if (revision < img_hdr->min_chip_rev) {
-        ESP_LOGE(TAG, "image has invalid chip revision, expected at least %d, found %d", revision, img_hdr->min_chip_rev);
+        ESP_LOGE(TAG, "can't run on lower chip revision, expect %d, found %d", revision, img_hdr->min_chip_rev);
         err = ESP_FAIL;
     } else if (revision != img_hdr->min_chip_rev) {
-        ESP_LOGI(TAG, "This chip is revision %d but project was configured for minimum revision %d. "\
-                 "Suggest setting project minimum revision to %d if safe to do so.",
-                 revision, img_hdr->min_chip_rev, revision);
+        ESP_LOGI(TAG, "mismatch chip revision, expect %d, found %d", revision, img_hdr->min_chip_rev);
     }
     return err;
 }
index 6239d3c9208257f823589aae221e807a09d80bfb..5c61122fc51ebc47c723a170e9a161f84478307a 100644 (file)
@@ -41,7 +41,6 @@
 #include "soc/spi_periph.h"
 
 #include "sdkconfig.h"
-#include "esp_efuse.h"
 #include "esp_image_format.h"
 #include "esp_secure_boot.h"
 #include "esp_flash_encrypt.h"
@@ -130,7 +129,7 @@ static esp_err_t bootloader_main()
     }
 
     /* Check chip ID and minimum chip revision that supported by this image */
-    uint8_t revision = esp_efuse_get_chip_ver();
+    uint8_t revision = bootloader_common_get_chip_revision();
     ESP_LOGI(TAG, "Chip Revision: %d", revision);
     if (bootloader_common_check_chip_validity(&fhdr) != ESP_OK) {
         return ESP_FAIL;
index 39a38f274481d467908e6e357a5f3b77f3c9cc33..8e3cdc79927b70969eb5f7bb40d93e1be87aa871 100644 (file)
@@ -35,7 +35,7 @@ uint8_t esp_efuse_get_chip_ver(void)
     uint8_t eco_bit0, eco_bit1, eco_bit2;
     esp_efuse_read_field_blob(ESP_EFUSE_CHIP_VER_REV1, &eco_bit0, 1);
     esp_efuse_read_field_blob(ESP_EFUSE_CHIP_VER_REV2, &eco_bit1, 1);
-    eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 80000000) >> 31;
+    eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 0x80000000) >> 31;
     uint32_t combine_value = (eco_bit2 << 2) | (eco_bit1 << 1) | eco_bit0;
     uint8_t chip_ver = 0;
     switch (combine_value) {