From 40c360a09637fb8bce20fc3c29e8d16163db8e3c Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Mon, 19 Jul 2021 15:16:42 +0500 Subject: [PATCH] efuse: Add CUSTOM_MAC address for ESP32-C3/-S2/-S3/-H2 --- components/efuse/esp32c3/esp_efuse_table.c | 11 ++++- components/efuse/esp32c3/esp_efuse_table.csv | 3 ++ .../efuse/esp32c3/include/esp_efuse_table.h | 3 +- components/efuse/esp32h2/esp_efuse_table.c | 22 ++++++++-- components/efuse/esp32h2/esp_efuse_table.csv | 5 ++- .../efuse/esp32h2/include/esp_efuse_table.h | 4 +- components/efuse/esp32s2/esp_efuse_table.c | 11 ++++- components/efuse/esp32s2/esp_efuse_table.csv | 3 ++ .../efuse/esp32s2/include/esp_efuse_table.h | 3 +- components/efuse/esp32s3/esp_efuse_table.c | 11 ++++- components/efuse/esp32s3/esp_efuse_table.csv | 3 ++ .../efuse/esp32s3/include/esp_efuse_table.h | 3 +- components/esp_hw_support/include/esp_mac.h | 8 +++- components/esp_hw_support/mac_addr.c | 40 ++++++++++++++----- components/esptool_py/esptool | 2 +- .../system/inc/espefuse_summary_ESP32-C3.rst | 2 + .../system/inc/espefuse_summary_ESP32-S2.rst | 2 + .../system/inc/espefuse_summary_ESP32-S3.rst | 2 + docs/en/api-reference/system/system.rst | 32 +++++++++++---- 19 files changed, 140 insertions(+), 30 deletions(-) diff --git a/components/efuse/esp32c3/esp_efuse_table.c b/components/efuse/esp32c3/esp_efuse_table.c index 7615e16047..ec334281ba 100644 --- a/components/efuse/esp32c3/esp_efuse_table.c +++ b/components/efuse/esp32c3/esp_efuse_table.c @@ -9,7 +9,7 @@ #include #include "esp_efuse_table.h" -// md5_digest_table 7a50fdd084e3b80b143c5bd2a36f9c26 +// md5_digest_table 3f91b5a37afbcdf1379820626a92e69c // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -456,6 +456,10 @@ static const esp_efuse_desc_t USER_DATA[] = { {EFUSE_BLK3, 0, 256}, // User data, }; +static const esp_efuse_desc_t USER_DATA_MAC_CUSTOM[] = { + {EFUSE_BLK3, 200, 48}, // Custom MAC, +}; + static const esp_efuse_desc_t KEY0[] = { {EFUSE_BLK4, 0, 256}, // Key0 or user data, }; @@ -1062,6 +1066,11 @@ const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[] = { NULL }; +const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[] = { + &USER_DATA_MAC_CUSTOM[0], // Custom MAC + NULL +}; + const esp_efuse_desc_t* ESP_EFUSE_KEY0[] = { &KEY0[0], // Key0 or user data NULL diff --git a/components/efuse/esp32c3/esp_efuse_table.csv b/components/efuse/esp32c3/esp_efuse_table.csv index f9c4cb8e12..73c91d4328 100644 --- a/components/efuse/esp32c3/esp_efuse_table.csv +++ b/components/efuse/esp32c3/esp_efuse_table.csv @@ -146,6 +146,9 @@ ################ USER_DATA, EFUSE_BLK3, 0, 256, User data +USER_DATA.MAC_CUSTOM, EFUSE_BLK3, 200, 48, Custom MAC + +################ KEY0, EFUSE_BLK4, 0, 256, Key0 or user data KEY1, EFUSE_BLK5, 0, 256, Key1 or user data KEY2, EFUSE_BLK6, 0, 256, Key2 or user data diff --git a/components/efuse/esp32c3/include/esp_efuse_table.h b/components/efuse/esp32c3/include/esp_efuse_table.h index 96fba50913..3ebc34ac27 100644 --- a/components/efuse/esp32c3/include/esp_efuse_table.h +++ b/components/efuse/esp32c3/include/esp_efuse_table.h @@ -9,7 +9,7 @@ extern "C" { #endif -// md5_digest_table 7a50fdd084e3b80b143c5bd2a36f9c26 +// md5_digest_table 3f91b5a37afbcdf1379820626a92e69c // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -125,6 +125,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN1[]; extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN2[]; extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN3[]; extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[]; +extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY0[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY1[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY2[]; diff --git a/components/efuse/esp32h2/esp_efuse_table.c b/components/efuse/esp32h2/esp_efuse_table.c index 06060ed9d4..c67739f81a 100644 --- a/components/efuse/esp32h2/esp_efuse_table.c +++ b/components/efuse/esp32h2/esp_efuse_table.c @@ -9,7 +9,7 @@ #include #include "esp_efuse_table.h" -// md5_digest_table 54e3ee07e1f682ea20e8af0561df669c +// md5_digest_table e460a50d9f80fa56cb87cd54ff055feb // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -350,6 +350,9 @@ static const esp_efuse_desc_t MAC_FACTORY[] = { {EFUSE_BLK1, 16, 8}, // Factory MAC addr [3], {EFUSE_BLK1, 8, 8}, // Factory MAC addr [4], {EFUSE_BLK1, 0, 8}, // Factory MAC addr [5], +}; + +static const esp_efuse_desc_t MAC_EXT[] = { {EFUSE_BLK1, 123, 8}, // Factory MAC addr [6], {EFUSE_BLK1, 131, 8}, // Factory MAC addr [7], }; @@ -462,6 +465,10 @@ static const esp_efuse_desc_t USER_DATA[] = { {EFUSE_BLK3, 0, 256}, // User data, }; +static const esp_efuse_desc_t USER_DATA_MAC_CUSTOM[] = { + {EFUSE_BLK3, 200, 48}, // Custom MAC, +}; + static const esp_efuse_desc_t KEY0[] = { {EFUSE_BLK4, 0, 256}, // Key0 or user data, }; @@ -911,8 +918,12 @@ const esp_efuse_desc_t* ESP_EFUSE_MAC_FACTORY[] = { &MAC_FACTORY[3], // Factory MAC addr [3] &MAC_FACTORY[4], // Factory MAC addr [4] &MAC_FACTORY[5], // Factory MAC addr [5] - &MAC_FACTORY[6], // Factory MAC addr [6] - &MAC_FACTORY[7], // Factory MAC addr [7] + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_MAC_EXT[] = { + &MAC_EXT[6], // Factory MAC addr [6] + &MAC_EXT[7], // Factory MAC addr [7] NULL }; @@ -1051,6 +1062,11 @@ const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[] = { NULL }; +const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[] = { + &USER_DATA_MAC_CUSTOM[0], // Custom MAC + NULL +}; + const esp_efuse_desc_t* ESP_EFUSE_KEY0[] = { &KEY0[0], // Key0 or user data NULL diff --git a/components/efuse/esp32h2/esp_efuse_table.csv b/components/efuse/esp32h2/esp_efuse_table.csv index 873440b2c7..9ac3667c5d 100644 --- a/components/efuse/esp32h2/esp_efuse_table.csv +++ b/components/efuse/esp32h2/esp_efuse_table.csv @@ -116,7 +116,7 @@ , EFUSE_BLK1, 16, 8, Factory MAC addr [3] , EFUSE_BLK1, 8, 8, Factory MAC addr [4] , EFUSE_BLK1, 0, 8, Factory MAC addr [5] - , EFUSE_BLK1, 123, 8, Factory MAC addr [6] + MAC_EXT, EFUSE_BLK1, 123, 8, Factory MAC addr [6] , EFUSE_BLK1, 131, 8, Factory MAC addr [7] SPI_PAD_CONFIG_CLK, EFUSE_BLK1, 48, 6, SPI_PAD_configure CLK SPI_PAD_CONFIG_Q_D1, EFUSE_BLK1, 54, 6, SPI_PAD_configure Q(D1) @@ -150,6 +150,9 @@ ################ USER_DATA, EFUSE_BLK3, 0, 256, User data +USER_DATA.MAC_CUSTOM, EFUSE_BLK3, 200, 48, Custom MAC + +################ KEY0, EFUSE_BLK4, 0, 256, Key0 or user data KEY1, EFUSE_BLK5, 0, 256, Key1 or user data KEY2, EFUSE_BLK6, 0, 256, Key2 or user data diff --git a/components/efuse/esp32h2/include/esp_efuse_table.h b/components/efuse/esp32h2/include/esp_efuse_table.h index 84c808a15d..cde5e284eb 100644 --- a/components/efuse/esp32h2/include/esp_efuse_table.h +++ b/components/efuse/esp32h2/include/esp_efuse_table.h @@ -9,7 +9,7 @@ extern "C" { #endif -// md5_digest_table 54e3ee07e1f682ea20e8af0561df669c +// md5_digest_table e460a50d9f80fa56cb87cd54ff055feb // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -99,6 +99,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_FORCE_SEND_RESUME[]; extern const esp_efuse_desc_t* ESP_EFUSE_SECURE_VERSION[]; extern const esp_efuse_desc_t* ESP_EFUSE_BOOT_DISABLE_FAST_WAKE[]; extern const esp_efuse_desc_t* ESP_EFUSE_MAC_FACTORY[]; +extern const esp_efuse_desc_t* ESP_EFUSE_MAC_EXT[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_CLK[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_Q_D1[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D_D0[]; @@ -126,6 +127,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN1[]; extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN2[]; extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN3[]; extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[]; +extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY0[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY1[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY2[]; diff --git a/components/efuse/esp32s2/esp_efuse_table.c b/components/efuse/esp32s2/esp_efuse_table.c index 5e7ecff4a9..d5b284a62f 100644 --- a/components/efuse/esp32s2/esp_efuse_table.c +++ b/components/efuse/esp32s2/esp_efuse_table.c @@ -9,7 +9,7 @@ #include #include "esp_efuse_table.h" -// md5_digest_table bc8611ed5c3a91ac0a8ba29879968d70 +// md5_digest_table 2590bb432c70411ba365bce92ac37032 // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -412,6 +412,10 @@ static const esp_efuse_desc_t USER_DATA[] = { {EFUSE_BLK3, 0, 256}, // User data, }; +static const esp_efuse_desc_t USER_DATA_MAC_CUSTOM[] = { + {EFUSE_BLK3, 200, 48}, // Custom MAC, +}; + static const esp_efuse_desc_t KEY0[] = { {EFUSE_BLK4, 0, 256}, // Key0 or user data, }; @@ -939,6 +943,11 @@ const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[] = { NULL }; +const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[] = { + &USER_DATA_MAC_CUSTOM[0], // Custom MAC + NULL +}; + const esp_efuse_desc_t* ESP_EFUSE_KEY0[] = { &KEY0[0], // Key0 or user data NULL diff --git a/components/efuse/esp32s2/esp_efuse_table.csv b/components/efuse/esp32s2/esp_efuse_table.csv index cb0c16c6ff..ce8b594596 100644 --- a/components/efuse/esp32s2/esp_efuse_table.csv +++ b/components/efuse/esp32s2/esp_efuse_table.csv @@ -135,6 +135,9 @@ ################ USER_DATA, EFUSE_BLK3, 0, 256, User data +USER_DATA.MAC_CUSTOM, EFUSE_BLK3, 200, 48, Custom MAC + +################ KEY0, EFUSE_BLK4, 0, 256, Key0 or user data KEY1, EFUSE_BLK5, 0, 256, Key1 or user data KEY2, EFUSE_BLK6, 0, 256, Key2 or user data diff --git a/components/efuse/esp32s2/include/esp_efuse_table.h b/components/efuse/esp32s2/include/esp_efuse_table.h index 22dbec14b2..e7bddc6f73 100644 --- a/components/efuse/esp32s2/include/esp_efuse_table.h +++ b/components/efuse/esp32s2/include/esp_efuse_table.h @@ -9,7 +9,7 @@ extern "C" { #endif -// md5_digest_table bc8611ed5c3a91ac0a8ba29879968d70 +// md5_digest_table 2590bb432c70411ba365bce92ac37032 // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -114,6 +114,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART0[]; extern const esp_efuse_desc_t* ESP_EFUSE_OPTIONAL_UNIQUE_ID[]; extern const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[]; extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[]; +extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY0[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY1[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY2[]; diff --git a/components/efuse/esp32s3/esp_efuse_table.c b/components/efuse/esp32s3/esp_efuse_table.c index 7224a2ecfb..db697dc75e 100644 --- a/components/efuse/esp32s3/esp_efuse_table.c +++ b/components/efuse/esp32s3/esp_efuse_table.c @@ -9,7 +9,7 @@ #include #include "esp_efuse_table.h" -// md5_digest_table 7d78e15a6be433d8520eaf462b450cdc +// md5_digest_table 2b4b79060b04576a3d189a54f42dd462 // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -440,6 +440,10 @@ static const esp_efuse_desc_t USER_DATA[] = { {EFUSE_BLK3, 0, 256}, // User data, }; +static const esp_efuse_desc_t USER_DATA_MAC_CUSTOM[] = { + {EFUSE_BLK3, 200, 48}, // Custom MAC, +}; + static const esp_efuse_desc_t KEY0[] = { {EFUSE_BLK4, 0, 256}, // Key0 or user data, }; @@ -1002,6 +1006,11 @@ const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[] = { NULL }; +const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[] = { + &USER_DATA_MAC_CUSTOM[0], // Custom MAC + NULL +}; + const esp_efuse_desc_t* ESP_EFUSE_KEY0[] = { &KEY0[0], // Key0 or user data NULL diff --git a/components/efuse/esp32s3/esp_efuse_table.csv b/components/efuse/esp32s3/esp_efuse_table.csv index 7194f0b71a..a707ccdaee 100644 --- a/components/efuse/esp32s3/esp_efuse_table.csv +++ b/components/efuse/esp32s3/esp_efuse_table.csv @@ -141,6 +141,9 @@ ################ USER_DATA, EFUSE_BLK3, 0, 256, User data +USER_DATA.MAC_CUSTOM, EFUSE_BLK3, 200, 48, Custom MAC + +################ KEY0, EFUSE_BLK4, 0, 256, Key0 or user data KEY1, EFUSE_BLK5, 0, 256, Key1 or user data KEY2, EFUSE_BLK6, 0, 256, Key2 or user data diff --git a/components/efuse/esp32s3/include/esp_efuse_table.h b/components/efuse/esp32s3/include/esp_efuse_table.h index 5707c5585f..b07683a3cb 100644 --- a/components/efuse/esp32s3/include/esp_efuse_table.h +++ b/components/efuse/esp32s3/include/esp_efuse_table.h @@ -9,7 +9,7 @@ extern "C" { #endif -// md5_digest_table 7d78e15a6be433d8520eaf462b450cdc +// md5_digest_table 2b4b79060b04576a3d189a54f42dd462 // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -121,6 +121,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART0[]; extern const esp_efuse_desc_t* ESP_EFUSE_OPTIONAL_UNIQUE_ID[]; extern const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[]; extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[]; +extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA_MAC_CUSTOM[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY0[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY1[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY2[]; diff --git a/components/esp_hw_support/include/esp_mac.h b/components/esp_hw_support/include/esp_mac.h index 75e01ebbd1..fa1e63ce9a 100644 --- a/components/esp_hw_support/include/esp_mac.h +++ b/components/esp_hw_support/include/esp_mac.h @@ -79,6 +79,7 @@ esp_err_t esp_base_mac_addr_set(const uint8_t *mac); * 8 bytes for EUI-64(used for IEEE 802.15.4) * * @return ESP_OK on success + * ESP_ERR_INVALID_ARG mac is NULL * ESP_ERR_INVALID_MAC base MAC address has not been set */ esp_err_t esp_base_mac_addr_get(uint8_t *mac); @@ -100,8 +101,10 @@ esp_err_t esp_base_mac_addr_get(uint8_t *mac); * 8 bytes for EUI-64(used for IEEE 802.15.4) * * @return ESP_OK on success - * ESP_ERR_INVALID_VERSION An invalid MAC version field was read from BLK3 of EFUSE - * ESP_ERR_INVALID_CRC An invalid MAC CRC was read from BLK3 of EFUSE + * ESP_ERR_INVALID_ARG mac is NULL + * ESP_ERR_INVALID_MAC CUSTOM_MAC address has not been set, all zeros (for esp32-xx) + * ESP_ERR_INVALID_VERSION An invalid MAC version field was read from BLK3 of EFUSE (for esp32) + * ESP_ERR_INVALID_CRC An invalid MAC CRC was read from BLK3 of EFUSE (for esp32) */ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac); @@ -113,6 +116,7 @@ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac); * 8 bytes for EUI-64(used for IEEE 802.15.4) * * @return ESP_OK on success + * ESP_ERR_INVALID_ARG mac is NULL */ esp_err_t esp_efuse_mac_get_default(uint8_t *mac); diff --git a/components/esp_hw_support/mac_addr.c b/components/esp_hw_support/mac_addr.c index 7a722a3a24..75767c3428 100644 --- a/components/esp_hw_support/mac_addr.c +++ b/components/esp_hw_support/mac_addr.c @@ -55,9 +55,10 @@ esp_err_t esp_base_mac_addr_set(const uint8_t *mac) esp_err_t esp_base_mac_addr_get(uint8_t *mac) { - uint8_t null_mac[ESP_MAC_ADDRESS_LEN] = {0}; - - if (memcmp(base_mac_addr, null_mac, ESP_MAC_ADDRESS_LEN) == 0) { + if (mac == NULL) { + return ESP_ERR_INVALID_ARG; + } + if (base_mac_addr[0] == 0 && memcmp(base_mac_addr, &base_mac_addr[1], ESP_MAC_ADDRESS_LEN - 1) == 0) { ESP_LOGI(TAG, "Base MAC address is not set"); return ESP_ERR_INVALID_MAC; } @@ -70,7 +71,24 @@ esp_err_t esp_base_mac_addr_get(uint8_t *mac) esp_err_t esp_efuse_mac_get_custom(uint8_t *mac) { #if !CONFIG_IDF_TARGET_ESP32 - return ESP_ERR_NOT_SUPPORTED; // TODO IDF-1326 + size_t size_bits = esp_efuse_get_field_size(ESP_EFUSE_USER_DATA_MAC_CUSTOM); + assert((size_bits % 8) == 0); + esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_USER_DATA_MAC_CUSTOM, mac, size_bits); + if (err != ESP_OK) { + return err; + } + size_t size = size_bits / 8; + if (mac[0] == 0 && memcmp(mac, &mac[1], size - 1) == 0) { + ESP_LOGE(TAG, "eFuse MAC_CUSTOM is empty"); + return ESP_ERR_INVALID_MAC; + } +#if (ESP_MAC_ADDRESS_LEN == 8) + err = esp_efuse_read_field_blob(ESP_EFUSE_MAC_EXT, &mac[6], ESP_MAC_ADDRESS_LEN - size); + if (err != ESP_OK) { + return err; + } +#endif + return ESP_OK; #else uint8_t version; esp_efuse_read_field_blob(ESP_EFUSE_MAC_CUSTOM_VER, &version, 8); @@ -94,14 +112,18 @@ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac) esp_err_t esp_efuse_mac_get_default(uint8_t *mac) { - if ( esp_efuse_get_field_size(ESP_EFUSE_MAC_FACTORY) != ESP_MAC_ADDRESS_LEN * 8) { - ESP_LOGE(TAG, "mac address length is incorrect, please check the mac address length which your type of the chip is supported"); - abort(); - } - esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_MAC_FACTORY, mac, ESP_MAC_ADDRESS_LEN * 8); + size_t size_bits = esp_efuse_get_field_size(ESP_EFUSE_MAC_FACTORY); + assert((size_bits % 8) == 0); + esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_MAC_FACTORY, mac, size_bits); if (err != ESP_OK) { return err; } +#if (ESP_MAC_ADDRESS_LEN == 8) + err = esp_efuse_read_field_blob(ESP_EFUSE_MAC_EXT, &mac[6], ESP_MAC_ADDRESS_LEN - size_bits / 8); + if (err != ESP_OK) { + return err; + } +#endif #ifdef CONFIG_IDF_TARGET_ESP32 // Only ESP32 has MAC CRC in efuse uint8_t efuse_crc; diff --git a/components/esptool_py/esptool b/components/esptool_py/esptool index 5b6c6574a2..e39896e124 160000 --- a/components/esptool_py/esptool +++ b/components/esptool_py/esptool @@ -1 +1 @@ -Subproject commit 5b6c6574a2c4b7dfa6dc07e17e68461dd2a2c145 +Subproject commit e39896e1243418c7e28e4e0c4532661f3c7c5d2d diff --git a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-C3.rst b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-C3.rst index 89d1059feb..a058ac8254 100644 --- a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-C3.rst +++ b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-C3.rst @@ -50,6 +50,8 @@ OPTIONAL_UNIQUE_ID (BLOCK2)(0 errors): Optional unique 128-bit ID = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W BLOCK2_VERSION (BLOCK2) Version of BLOCK2 = No calibration R/W (0b000) + CUSTOM_MAC (BLOCK3) Custom MAC Address + = 00:00:00:00:00:00 (OK) R/W Jtag Config fuses: JTAG_SEL_ENABLE (BLOCK0) Set this bit to enable selection between usb_to_jt = False R/W (0b0) diff --git a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S2.rst b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S2.rst index b9c94b033e..ab6a8d4f10 100644 --- a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S2.rst +++ b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S2.rst @@ -66,6 +66,8 @@ OPTIONAL_UNIQUE_ID (BLOCK2)(0 errors): Optional unique 128-bit ID = 7d 33 b8 bb 0b 13 b3 c8 71 37 0e e8 7c ab d5 92 R/W BLOCK2_VERSION (BLOCK2) Version of BLOCK2 = With calibration R/W (0b001) + CUSTOM_MAC (BLOCK3) Custom MAC Address + = 00:00:00:00:00:00 (OK) R/W Security fuses: SOFT_DIS_JTAG (BLOCK0) Software disables JTAG. When software disabled, JT = False R/W (0b0) diff --git a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S3.rst b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S3.rst index 041f8abedc..c2592a7b0c 100644 --- a/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S3.rst +++ b/docs/en/api-reference/system/inc/espefuse_summary_ESP32-S3.rst @@ -66,6 +66,8 @@ OPTIONAL_UNIQUE_ID (BLOCK2)(0 errors): Optional unique 128-bit ID = 7d 33 b8 bb 0b 13 b3 c8 71 37 0e e8 7c ab d5 92 R/W BLOCK2_VERSION (BLOCK2) Version of BLOCK2 = With calibration R/W (0b001) + CUSTOM_MAC (BLOCK3) Custom MAC Address + = 00:00:00:00:00:00 (OK) R/W Security fuses: SOFT_DIS_JTAG (BLOCK0) Software disables JTAG. When software disabled, JT = False R/W (0b000) diff --git a/docs/en/api-reference/system/system.rst b/docs/en/api-reference/system/system.rst index 194a401ea7..bd64c5ca06 100644 --- a/docs/en/api-reference/system/system.rst +++ b/docs/en/api-reference/system/system.rst @@ -102,14 +102,14 @@ The custom base MAC addresses should be allocated such that derived MAC addresse It is also possible to call the function :cpp:func:`esp_netif_set_mac` to set the specific MAC used by a network interface, after network initialization. It's recommended to use the Base MAC approach documented here instead, to avoid the possibility of the original MAC address briefly appearing on the network before it is changed. -.. This API is ESP32-only, see IDF-1326 + +Custom MAC address in eFuse +@@@@@@@@@@@@@@@@@@@@@@@@@@@ + +When reading custom MAC addresses from eFuse, ESP-IDF provides a helper function :cpp:func:`esp_efuse_mac_get_custom`. This loads the MAC address from eFuse BLK3. This function assumes that the custom base MAC address is stored in the following format: + .. only:: esp32 - Custom MAC address in eFuse - @@@@@@@@@@@@@@@@@@@@@@@@@@@ - - When reading custom MAC addresses from eFuse, ESP-IDF provides a helper function :cpp:func:`esp_efuse_mac_get_custom`. This loads the MAC address from eFuse BLK3. This function assumes that the custom base MAC address is stored in the following format: - +-----------------+-----------+---------------+------------------------------+ | Field | # of bits | Range of bits | Notes | +=================+===========+===============+==============================+ @@ -122,7 +122,25 @@ The custom base MAC addresses should be allocated such that derived MAC addresse | MAC address CRC | 8 | 7:0 | CRC-8-CCITT, polynomial 0x07 | +-----------------+-----------+---------------+------------------------------+ - Once MAC address has been obtained using :cpp:func:`esp_efuse_mac_get_custom`, call :cpp:func:`esp_base_mac_addr_set` to set this MAC address as base MAC address. + .. note:: + + If the 3/4 coding scheme is enabled, all eFuse fields in this block must be burnt at the same time. + +.. only:: not esp32 + + +-----------------+-----------+---------------+ + | Field | # of bits | Range of bits | + +=================+===========+===============+ + | MAC address | 48 | 200:248 | + +-----------------+-----------+---------------+ + + .. note:: + + The eFuse BLK3 uses RS-coding during a burn operation it means that all eFuse fields in this block must be burnt at the same time. + +Once MAC address has been obtained using :cpp:func:`esp_efuse_mac_get_custom`, call :cpp:func:`esp_base_mac_addr_set` to set this MAC address as base MAC address. + + .. _local-mac-addresses: