Add customer MAC address that read from efuse

This commit is contained in:
XiaXiaotian 2017-04-17 21:16:16 +08:00
parent 0ea4c3c06b
commit 03e2618d35
2 changed files with 34 additions and 2 deletions

View file

@ -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

View file

@ -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) {