From 03e2618d3597516fc3c9287814567e78fee6824c Mon Sep 17 00:00:00 2001 From: XiaXiaotian Date: Mon, 17 Apr 2017 21:16:16 +0800 Subject: [PATCH] Add customer MAC address that read from efuse --- components/esp32/Kconfig | 7 +++++++ components/esp32/system_api.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 0db76f3d59..a8470c2c92 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -105,6 +105,13 @@ config MEMMAP_SPISRAM main memory map. Enable this if you have this hardware and want to use it in the same way as on-chip RAM. +config CUSTOMER_MAC_ADDRESS + bool "Customer MAC address" + default n + help + Customers can define their own mac address in efuse. + Set to 'y' if you decide to use the mac address that you defined in efuse. + choice NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE bool "Number of MAC address generated from the hardware MAC address in efuse" default FOUR_MAC_ADDRESS_FROM_EFUSE diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 028513718e..f43e2251a0 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -42,10 +42,14 @@ void system_init() esp_err_t esp_efuse_read_mac(uint8_t* mac) { + uint32_t mac_low; + uint32_t mac_high; uint8_t efuse_crc; uint8_t calc_crc; - uint32_t mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG); - uint32_t mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG); + +#ifndef CONFIG_CUSTOMER_MAC_ADDRESS + mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG); + mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG); mac[0] = mac_high >> 8; mac[1] = mac_high; @@ -55,6 +59,27 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac) mac[5] = mac_low; efuse_crc = mac_high >> 16; +#else + uint8_t version = REG_READ(EFUSE_BLK3_RDATA5_REG) >> 24; + + if (version != 1) { + ESP_LOGE(TAG, "Customer efuse MAC address version error, version = %d", version); + abort(); + } + + mac_low = REG_READ(EFUSE_BLK3_RDATA1_REG); + mac_high = REG_READ(EFUSE_BLK3_RDATA0_REG); + + mac[0] = mac_high >> 8; + mac[1] = mac_high >> 16; + mac[2] = mac_high >> 24; + mac[3] = mac_low; + mac[4] = mac_low >> 8; + mac[5] = mac_low >> 16; + + efuse_crc = mac_high; +#endif //CONFIG_CUSTOMER_DEFINED_MAC_ADDR + calc_crc = esp_crc8(mac, 6); if (efuse_crc != calc_crc) { -- 2.40.0