From d06b2a3598168ba1bc39281e06ece734fa216f36 Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Wed, 19 Jun 2019 17:59:32 +0800 Subject: [PATCH] esp32s2beta: Add support esp32s2beta Added reading MAC address Closes: IDF-756 --- components/esp32s2beta/cpu_start.c | 10 +++++-- components/esp32s2beta/system_api.c | 41 +++-------------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/components/esp32s2beta/cpu_start.c b/components/esp32s2beta/cpu_start.c index 4f3bdc37fa..ac8c73d14e 100644 --- a/components/esp32s2beta/cpu_start.c +++ b/components/esp32s2beta/cpu_start.c @@ -68,9 +68,7 @@ #include "esp_pm.h" #include "esp_private/pm_impl.h" #include "trax.h" -#if CONFIG_IDF_TARGET_ESP32 #include "esp_efuse.h" -#endif #define STRINGIFY(s) STRINGIFY2(s) #define STRINGIFY2(s) #s @@ -390,6 +388,14 @@ static void main_task(void* args) #ifndef CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE rtc_wdt_disable(); #endif + +#ifdef CONFIG_BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE + const esp_partition_t *efuse_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_EFUSE_EM, NULL); + if (efuse_partition) { + esp_efuse_init(efuse_partition->address, efuse_partition->size); + } +#endif + app_main(); vTaskDelete(NULL); } diff --git a/components/esp32s2beta/system_api.c b/components/esp32s2beta/system_api.c index 285a83ef69..851bdba5fa 100644 --- a/components/esp32s2beta/system_api.c +++ b/components/esp32s2beta/system_api.c @@ -25,7 +25,6 @@ #include "esp32s2beta/rom/uart.h" #include "soc/dport_reg.h" #include "soc/gpio_reg.h" -#include "soc/efuse_reg.h" #include "soc/rtc_cntl_reg.h" #include "soc/timer_group_reg.h" #include "soc/timer_group_struct.h" @@ -37,6 +36,8 @@ #include "freertos/xtensa_api.h" #include "esp_heap_caps.h" #include "soc/syscon_reg.h" +#include "esp_efuse.h" +#include "esp_efuse_table.h" static const char* TAG = "system_api"; @@ -77,46 +78,12 @@ esp_err_t esp_base_mac_addr_get(uint8_t *mac) esp_err_t esp_efuse_mac_get_custom(uint8_t *mac) { - return ESP_ERR_NOT_SUPPORTED; // TODO: read from MAC block in efuse + return ESP_ERR_NOT_SUPPORTED; } esp_err_t esp_efuse_mac_get_default(uint8_t* mac) { -// TODO: implememt esp_efuse_mac_get_default for esp32s2beta - IDF-756 - uint32_t mac_low; - uint32_t mac_high; - // uint8_t efuse_crc; - // uint8_t calc_crc; - -// mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG); -// mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG); - mac_low = REG_READ(EFUSE_RD_MAC_SPI_8M_0_REG); - mac_high = REG_GET_BIT(EFUSE_RD_MAC_SPI_8M_1_REG,EFUSE_MAC_1); - - mac[0] = mac_high >> 8; - mac[1] = mac_high; - mac[2] = mac_low >> 24; - mac[3] = mac_low >> 16; - mac[4] = mac_low >> 8; - mac[5] = mac_low; - - //efuse_crc = mac_high >> 16; - - //calc_crc = esp_crc8(mac, 6); - - //if (efuse_crc != calc_crc) { - // Small range of MAC addresses are accepted even if CRC is invalid. - // These addresses are reserved for Espressif internal use. - // if ((mac_high & 0xFFFF) == 0x18fe) { - // if ((mac_low >= 0x346a85c7) && (mac_low <= 0x346a85f8)) { - // return ESP_OK; - // } - // } else { - // ESP_LOGE(TAG, "Base MAC address from BLK0 of EFUSE CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc); - // abort(); - // } - //} - return ESP_OK; + return esp_efuse_read_field_blob(ESP_EFUSE_MAC_FACTORY, mac, 48); } esp_err_t system_efuse_read_mac(uint8_t *mac) __attribute__((alias("esp_efuse_mac_get_default")));