Merge branch 'feature/add_eui64_for_esp32h2_efuse' into 'master'

efuse: add mac extension address for esp32h2

See merge request espressif/esp-idf!14363
This commit is contained in:
Shu Chen 2021-07-21 03:46:58 +00:00
commit dadaf30d17
6 changed files with 80 additions and 100 deletions

View File

@ -484,7 +484,7 @@ def main():
global idf_target
parser = argparse.ArgumentParser(description='ESP32 eFuse Manager')
parser.add_argument('--idf_target', '-t', help='Target chip type', choices=['esp32', 'esp32s2', 'esp32s3', 'esp32c3'], default='esp32')
parser.add_argument('--idf_target', '-t', help='Target chip type', choices=['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32h2'], default='esp32')
parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true')
parser.add_argument('--debug', help='Create header file with debug info', default=False, action='store_false')
parser.add_argument('--info', help='Print info about range of used bits', default=False, action='store_true')

View File

@ -9,7 +9,7 @@
#include <assert.h>
#include "esp_efuse_table.h"
// md5_digest_table 9e42b2f9dd879191ca75ad0cf50841a1
// md5_digest_table aa238a3a131bf64a9386d3d4ce86a237
// 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.
@ -339,6 +339,10 @@ static const esp_efuse_desc_t SECURE_VERSION[] = {
{EFUSE_BLK0, 142, 16}, // Secure version for anti-rollback,
};
static const esp_efuse_desc_t BOOT_DISABLE_FAST_WAKE[] = {
{EFUSE_BLK0, 158, 1}, // Fast verify on wake option in ROM for Secure Boot,
};
static const esp_efuse_desc_t MAC_FACTORY[] = {
{EFUSE_BLK1, 40, 8}, // Factory MAC addr [0],
{EFUSE_BLK1, 32, 8}, // Factory MAC addr [1],
@ -346,6 +350,8 @@ 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],
{EFUSE_BLK1, 123, 8}, // Factory MAC addr [6],
{EFUSE_BLK1, 131, 8}, // Factory MAC addr [7],
};
static const esp_efuse_desc_t SPI_PAD_CONFIG_CLK[] = {
@ -484,30 +490,6 @@ static const esp_efuse_desc_t SYS_DATA_PART2[] = {
{EFUSE_BLK10, 0, 256}, // System configuration,
};
static const esp_efuse_desc_t K_RTC_LDO[] = {
{EFUSE_BLK1, 135, 7}, // BLOCK1 K_RTC_LDO,
};
static const esp_efuse_desc_t K_DIG_LDO[] = {
{EFUSE_BLK1, 142, 7}, // BLOCK1 K_DIG_LDO,
};
static const esp_efuse_desc_t V_RTC_DBIAS20[] = {
{EFUSE_BLK1, 149, 8}, // BLOCK1 voltage of rtc dbias20,
};
static const esp_efuse_desc_t V_DIG_DBIAS20[] = {
{EFUSE_BLK1, 157, 8}, // BLOCK1 voltage of digital dbias20,
};
static const esp_efuse_desc_t DIG_DBIAS_HVT[] = {
{EFUSE_BLK1, 165, 5}, // BLOCK1 digital dbias when hvt,
};
static const esp_efuse_desc_t THRES_HVT[] = {
{EFUSE_BLK1, 170, 10}, // BLOCK1 pvt threshold when hvt,
};
@ -917,6 +899,11 @@ const esp_efuse_desc_t* ESP_EFUSE_SECURE_VERSION[] = {
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_BOOT_DISABLE_FAST_WAKE[] = {
&BOOT_DISABLE_FAST_WAKE[0], // Fast verify on wake option in ROM for Secure Boot
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_MAC_FACTORY[] = {
&MAC_FACTORY[0], // Factory MAC addr [0]
&MAC_FACTORY[1], // Factory MAC addr [1]
@ -924,6 +911,8 @@ 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
};
@ -988,7 +977,7 @@ const esp_efuse_desc_t* ESP_EFUSE_WAFER_VERSION[] = {
};
const esp_efuse_desc_t* ESP_EFUSE_PKG_VERSION[] = {
&PKG_VERSION[0], // Package version 0:ESP32C3
&PKG_VERSION[0], // Package version 0:ESP32H2
NULL
};
@ -1096,33 +1085,3 @@ const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART2[] = {
&SYS_DATA_PART2[0], // System configuration
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_K_RTC_LDO[] = {
&K_RTC_LDO[0], // BLOCK1 K_RTC_LDO
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_K_DIG_LDO[] = {
&K_DIG_LDO[0], // BLOCK1 K_DIG_LDO
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_V_RTC_DBIAS20[] = {
&V_RTC_DBIAS20[0], // BLOCK1 voltage of rtc dbias20
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_V_DIG_DBIAS20[] = {
&V_DIG_DBIAS20[0], // BLOCK1 voltage of digital dbias20
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_DIG_DBIAS_HVT[] = {
&DIG_DBIAS_HVT[0], // BLOCK1 digital dbias when hvt
NULL
};
const esp_efuse_desc_t* ESP_EFUSE_THRES_HVT[] = {
&THRES_HVT[0], // BLOCK1 pvt threshold when hvt
NULL
};

View File

@ -103,6 +103,7 @@
FLASH_ECC_EN, EFUSE_BLK0, 140, 1, Enable ECC for flash boot
FORCE_SEND_RESUME, EFUSE_BLK0, 141, 1, Force ROM code to send a resume command during SPI boot
SECURE_VERSION, EFUSE_BLK0, 142, 16, Secure version for anti-rollback
BOOT_DISABLE_FAST_WAKE, EFUSE_BLK0, 158, 1, Fast verify on wake option in ROM for Secure Boot
# EFUSE_RD_REPEAT_DATA4_REG #
@ -115,6 +116,8 @@
, 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]
, 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)
SPI_PAD_CONFIG_D_D0, EFUSE_BLK1, 60, 6, SPI_PAD_configure D(D0)
@ -154,12 +157,3 @@ KEY3, EFUSE_BLK7, 0, 256, Key3 or us
KEY4, EFUSE_BLK8, 0, 256, Key4 or user data
KEY5, EFUSE_BLK9, 0, 256, Key5 or user data
SYS_DATA_PART2, EFUSE_BLK10, 0, 256, System configuration
# AUTO CONFIG DIG&RTC DBIAS#
################
K_RTC_LDO, EFUSE_BLK1, 135, 7, BLOCK1 K_RTC_LDO
K_DIG_LDO, EFUSE_BLK1, 142, 7, BLOCK1 K_DIG_LDO
V_RTC_DBIAS20, EFUSE_BLK1, 149, 8, BLOCK1 voltage of rtc dbias20
V_DIG_DBIAS20, EFUSE_BLK1, 157, 8, BLOCK1 voltage of digital dbias20
DIG_DBIAS_HVT, EFUSE_BLK1, 165, 5, BLOCK1 digital dbias when hvt
THRES_HVT, EFUSE_BLK1, 170, 10, BLOCK1 pvt threshold when hvt

Can't render this file because it contains an unexpected character in line 7 and column 87.

View File

@ -9,7 +9,7 @@ extern "C" {
#endif
// md5_digest_table 9e42b2f9dd879191ca75ad0cf50841a1
// md5_digest_table aa238a3a131bf64a9386d3d4ce86a237
// 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.
@ -97,6 +97,7 @@ extern const esp_efuse_desc_t* ESP_EFUSE_FLASH_PAGE_SIZE[];
extern const esp_efuse_desc_t* ESP_EFUSE_FLASH_ECC_EN[];
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_SPI_PAD_CONFIG_CLK[];
extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_Q_D1[];
@ -132,12 +133,6 @@ extern const esp_efuse_desc_t* ESP_EFUSE_KEY3[];
extern const esp_efuse_desc_t* ESP_EFUSE_KEY4[];
extern const esp_efuse_desc_t* ESP_EFUSE_KEY5[];
extern const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART2[];
extern const esp_efuse_desc_t* ESP_EFUSE_K_RTC_LDO[];
extern const esp_efuse_desc_t* ESP_EFUSE_K_DIG_LDO[];
extern const esp_efuse_desc_t* ESP_EFUSE_V_RTC_DBIAS20[];
extern const esp_efuse_desc_t* ESP_EFUSE_V_DIG_DBIAS20[];
extern const esp_efuse_desc_t* ESP_EFUSE_DIG_DBIAS_HVT[];
extern const esp_efuse_desc_t* ESP_EFUSE_THRES_HVT[];
#ifdef __cplusplus
}

View File

@ -60,7 +60,9 @@ typedef enum {
* @note If not using a valid OUI, set the "locally administered" bit
* (bit value 0x02 in the first byte) to avoid collisions.
*
* @param mac base MAC address, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 8 bytes for EUI-64(used for IEEE 802.15.4)
*
* @return ESP_OK on success
* ESP_ERR_INVALID_ARG If mac is NULL or is not a unicast MAC
@ -72,7 +74,9 @@ esp_err_t esp_base_mac_addr_set(const uint8_t *mac);
*
* @note If no custom Base MAC has been set, this returns the pre-programmed Espressif base MAC address.
*
* @param mac base MAC address, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 8 bytes for EUI-64(used for IEEE 802.15.4)
*
* @return ESP_OK on success
* ESP_ERR_INVALID_MAC base MAC address has not been set
@ -91,7 +95,9 @@ esp_err_t esp_base_mac_addr_get(uint8_t *mac);
*
* @note This function is currently only supported on ESP32.
*
* @param mac base MAC address, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 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
@ -102,7 +108,9 @@ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac);
/**
* @brief Return base MAC address which is factory-programmed by Espressif in EFUSE.
*
* @param mac base MAC address, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 8 bytes for EUI-64(used for IEEE 802.15.4)
*
* @return ESP_OK on success
*/
@ -115,12 +123,14 @@ esp_err_t esp_efuse_mac_get_default(uint8_t *mac);
* Then calculates the MAC address of the specific interface requested,
* refer to ESP-IDF Programming Guide for the algorithm.
*
* @param mac MAC address of the interface, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 8 bytes for EUI-64(used for IEEE 802.15.4)
* @param type Type of MAC address to return
*
* @return ESP_OK on success
*/
esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type);
esp_err_t esp_read_mac(uint8_t *mac, esp_mac_type_t type);
/**
* @brief Derive local MAC address from universal MAC address.
@ -133,12 +143,14 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type);
* address, then the first octet is XORed with 0x4 in order to create a different
* locally administered MAC address.
*
* @param local_mac Derived local MAC address, length: 6 bytes.
* @param mac base MAC address, length: 6 bytes/8 bytes.
* length: 6 bytes for MAC-48
* 8 bytes for EUI-64(used for IEEE 802.15.4)
* @param universal_mac Source universal MAC address, length: 6 bytes.
*
* @return ESP_OK on success
*/
esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac);
esp_err_t esp_derive_local_mac(uint8_t *local_mac, const uint8_t *universal_mac);
#ifdef __cplusplus
}

View File

@ -28,9 +28,14 @@
#define MAC_ADDR_UNIVERSE_BT_OFFSET 1
#endif
static const char* TAG = "system_api";
#if CONFIG_IEEE802154_ENABLED
#define ESP_MAC_ADDRESS_LEN 8
#else
#define ESP_MAC_ADDRESS_LEN 6
#endif
static const char *TAG = "system_api";
static uint8_t base_mac_addr[6] = { 0 };
static uint8_t base_mac_addr[ESP_MAC_ADDRESS_LEN] = { 0 };
esp_err_t esp_base_mac_addr_set(const uint8_t *mac)
{
@ -43,21 +48,21 @@ esp_err_t esp_base_mac_addr_set(const uint8_t *mac)
return ESP_ERR_INVALID_ARG;
}
memcpy(base_mac_addr, mac, 6);
memcpy(base_mac_addr, mac, ESP_MAC_ADDRESS_LEN);
return ESP_OK;
}
esp_err_t esp_base_mac_addr_get(uint8_t *mac)
{
uint8_t null_mac[6] = {0};
uint8_t null_mac[ESP_MAC_ADDRESS_LEN] = {0};
if (memcmp(base_mac_addr, null_mac, 6) == 0) {
if (memcmp(base_mac_addr, null_mac, ESP_MAC_ADDRESS_LEN) == 0) {
ESP_LOGI(TAG, "Base MAC address is not set");
return ESP_ERR_INVALID_MAC;
}
memcpy(mac, base_mac_addr, 6);
memcpy(mac, base_mac_addr, ESP_MAC_ADDRESS_LEN);
return ESP_OK;
}
@ -87,9 +92,13 @@ esp_err_t esp_efuse_mac_get_custom(uint8_t *mac)
#endif
}
esp_err_t esp_efuse_mac_get_default(uint8_t* mac)
esp_err_t esp_efuse_mac_get_default(uint8_t *mac)
{
esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_MAC_FACTORY, mac, 48);
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);
if (err != ESP_OK) {
return err;
}
@ -100,8 +109,8 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac)
uint8_t calc_crc = esp_rom_efuse_mac_address_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.
// Small range of MAC addresses are accepted even if CRC is invalid.
// These addresses are reserved for Espressif internal use.
uint32_t mac_high = ((uint32_t)mac[0] << 8) | mac[1];
uint32_t mac_low = ((uint32_t)mac[2] << 24) | ((uint32_t)mac[3] << 16) | ((uint32_t)mac[4] << 8) | mac[5];
if (((mac_high & 0xFFFF) == 0x18fe) && (mac_low >= 0x346a85c7) && (mac_low <= 0x346a85f8)) {
@ -115,7 +124,7 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac)
return ESP_OK;
}
esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac)
esp_err_t esp_derive_local_mac(uint8_t *local_mac, const uint8_t *universal_mac)
{
if (local_mac == NULL || universal_mac == NULL) {
ESP_LOGE(TAG, "mac address param is NULL");
@ -136,16 +145,19 @@ esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac)
return ESP_OK;
}
esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
esp_err_t esp_read_mac(uint8_t *mac, esp_mac_type_t type)
{
uint8_t efuse_mac[6];
uint8_t efuse_mac[ESP_MAC_ADDRESS_LEN];
if (mac == NULL) {
ESP_LOGE(TAG, "mac address param is NULL");
return ESP_ERR_INVALID_ARG;
}
#if CONFIG_IEEE802154_ENABLED
if (type < ESP_MAC_WIFI_STA || type > ESP_MAC_IEEE802154) {
#else
if (type < ESP_MAC_WIFI_STA || type > ESP_MAC_ETH) {
#endif
ESP_LOGE(TAG, "mac type is incorrect");
return ESP_ERR_INVALID_ARG;
}
@ -164,14 +176,14 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
case ESP_MAC_WIFI_SOFTAP:
#if CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP
memcpy(mac, efuse_mac, 6);
// as a result of some esp32s2 chips burned with one MAC address by mistake,
// there are some MAC address are reserved for this bug fix.
// related mistake MAC address is 0x7cdfa1003000~0x7cdfa1005fff,
// reserved MAC address is 0x7cdfa1020000~0x7cdfa1022fff (MAC address + 0x1d000).
// as a result of some esp32s2 chips burned with one MAC address by mistake,
// there are some MAC address are reserved for this bug fix.
// related mistake MAC address is 0x7cdfa1003000~0x7cdfa1005fff,
// reserved MAC address is 0x7cdfa1020000~0x7cdfa1022fff (MAC address + 0x1d000).
#ifdef CONFIG_IDF_TARGET_ESP32S2
uint8_t mac_begin[6] = { 0x7c, 0xdf, 0xa1, 0x00, 0x30, 0x00 };
uint8_t mac_end[6] = { 0x7c, 0xdf, 0xa1, 0x00, 0x5f, 0xff };
if(memcmp(mac,mac_begin,6) >= 0 && memcmp(mac_end,mac,6) >=0 ){
if (memcmp(mac, mac_begin, 6) >= 0 && memcmp(mac_end, mac, 6) >= 0 ) {
mac[3] += 0x02; // contain carry bit
mac[4] += 0xd0;
} else {
@ -187,7 +199,10 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
case ESP_MAC_BT:
#if CONFIG_ESP_MAC_ADDR_UNIVERSE_BT
memcpy(mac, efuse_mac, 6);
#if !CONFIG_IDF_TARGET_ESP32H2
// esp32h2 chips do not have wifi module, so the mac address do not need to add the BT offset
mac[5] += MAC_ADDR_UNIVERSE_BT_OFFSET;
#endif //!CONFIG_IDF_TARGET_ESP32H2
#else
return ESP_ERR_NOT_SUPPORTED;
#endif // CONFIG_ESP_MAC_ADDR_UNIVERSE_BT
@ -201,6 +216,11 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
esp_derive_local_mac(mac, efuse_mac);
#endif // CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH
break;
#if CONFIG_IEEE802154_ENABLED
case ESP_MAC_IEEE802154:
memcpy(mac, efuse_mac, 8);
break;
#endif
default:
ESP_LOGE(TAG, "unsupported mac type");
break;