eFuse Manager¶
Introduction¶
The eFuse Manager library is designed to structure access to eFuse bits and make using these easy. This library operates eFuse bits by a structure name which is assigned in eFuse table. This sections introduces some concepts used by eFuse Manager.
Hardware description¶
The ESP32-C3 has a number of eFuses which can store system and user parameters. Each eFuse is a one-bit field which can be programmed to 1 after which it cannot be reverted back to 0. Some of system parameters are using these eFuse bits directly by hardware modules and have special place (for example EFUSE_BLK0).
For more details, see ESP32-C3 Technical Reference Manual > eFuse Controller (eFuse) [PDF]. Some eFuse bits are available for user applications.
Each block is divided into 8 32-bits registers.
eFuse Manager component¶
The component has API functions for reading and writing fields. Access to the fields is carried out through the structures that describe the location of the eFuse bits in the blocks. The component provides the ability to form fields of any length and from any number of individual bits. The description of the fields is made in a CSV file in a table form. To generate from a tabular form (CSV file) in the C-source uses the tool efuse_table_gen.py. The tool checks the CSV file for uniqueness of field names and bit intersection, in case of using a custom file from the user’s project directory, the utility will check with the common CSV file.
CSV files:
common (esp_efuse_table.csv) - contains eFuse fields which are used inside the IDF. C-source generation should be done manually when changing this file (run command
idf.py efuse_common_table
). Note that changes in this file can lead to incorrect operation.custom - (optional and can be enabled by
CONFIG_EFUSE_CUSTOM_TABLE
) contains eFuse fields that are used by the user in their application. C-source generation should be done manually when changing this file and runningidf.py efuse_custom_table
.
Description CSV file¶
The CSV file contains a description of the eFuse fields. In the simple case, one field has one line of description. Table header:
# field_name, efuse_block(EFUSE_BLK0..EFUSE_BLK3), bit_start(0..255), bit_count(1..256), comment
Individual params in CSV file the following meanings:
- field_name
Name of field. The prefix ESP_EFUSE_ will be added to the name, and this field name will be available in the code. This name will be used to access the fields. The name must be unique for all fields. If the line has an empty name, then this line is combined with the previous field. This allows you to set an arbitrary order of bits in the field, and expand the field as well (see
MAC_FACTORY
field in the common table).- efuse_block
Block number. It determines where the eFuse bits will be placed for this field. Available EFUSE_BLK0..EFUSE_BLK3.
- bit_start
Start bit number (0..255). The bit_start field can be omitted. In this case, it will be set to bit_start + bit_count from the previous record, if it has the same efuse_block. Otherwise (if efuse_block is different, or this is the first entry), an error will be generated.
- bit_count
The number of bits to use in this field (1..-). This parameter can not be omitted. This field also may be
MAX_BLK_LEN
in this case, the field length will have the maximum block length, taking into account the coding scheme (applicable forESP_EFUSE_SECURE_BOOT_KEY
andESP_EFUSE_ENCRYPT_FLASH_KEY
fields). The valueMAX_BLK_LEN
depends onCONFIG_EFUSE_MAX_BLK_LEN
, will be replaced with “None” - 256, “3/4” - 192, “REPEAT” - 128.- comment
This param is using for comment field, it also move to C-header file. The comment field can be omitted.
If a non-sequential bit order is required to describe a field, then the field description in the following lines should be continued without specifying a name, this will indicate that it belongs to one field. For example two fields MAC_FACTORY and MAC_FACTORY_CRC:
# Factory MAC address #
#######################
MAC_FACTORY, EFUSE_BLK0, 72, 8, Factory MAC addr [0]
, EFUSE_BLK0, 64, 8, Factory MAC addr [1]
, EFUSE_BLK0, 56, 8, Factory MAC addr [2]
, EFUSE_BLK0, 48, 8, Factory MAC addr [3]
, EFUSE_BLK0, 40, 8, Factory MAC addr [4]
, EFUSE_BLK0, 32, 8, Factory MAC addr [5]
MAC_FACTORY_CRC, EFUSE_BLK0, 80, 8, CRC8 for factory MAC address
This field will available in code as ESP_EFUSE_MAC_FACTORY and ESP_EFUSE_MAC_FACTORY_CRC.
efuse_table_gen.py tool¶
The tool is designed to generate C-source files from CSV file and validate fields. First of all, the check is carried out on the uniqueness of the names and overlaps of the field bits. If an additional custom file is used, it will be checked with the existing common file (esp_efuse_table.csv). In case of errors, a message will be displayed and the string that caused the error. C-source files contain structures of type esp_efuse_desc_t.
To generate a common files, use the following command idf.py efuse_common_table
or:
cd $IDF_PATH/components/efuse/
./efuse_table_gen.py esp32c3/esp_efuse_table.csv
After generation in the folder esp32c3 create:
esp_efuse_table.c file.
In include folder esp_efuse_table.c file.
To generate a custom files, use the following command idf.py efuse_custom_table
or:
cd $IDF_PATH/components/efuse/
./efuse_table_gen.py esp32c3/esp_efuse_table.csv PROJECT_PATH/main/esp_efuse_custom_table.csv
After generation in the folder PROJECT_PATH/main create:
esp_efuse_custom_table.c file.
In include folder esp_efuse_custom_table.c file.
To use the generated fields, you need to include two files:
#include "esp_efuse.h"
#include "esp_efuse_table.h" or "esp_efuse_custom_table.h"
Support coding scheme¶
eFuse have three coding schemes:
None
(value 0).3/4
(value 1).Repeat
(value 2).
The coding scheme affects only EFUSE_BLK1, EFUSE_BLK2 and EFUSE_BLK3 blocks. EUSE_BLK0 block always has a coding scheme None
.
Coding changes the number of bits that can be written into a block, the block length is constant 256, some of these bits are used for encoding and are not used.
When using a coding scheme, the length of the payload that can be written is limited (for more details 20.3.1.3 System Parameter coding_scheme
):
None 256 bits.
3/4 192 bits.
Repeat 128 bits.
You can find out the coding scheme of your chip:
run a
espefuse.py -p COM4 summary
command.from
esptool
utility logs (during flashing).calling the function in the code
esp_efuse_get_coding_scheme()
for the EFUSE_BLK3 block.
eFuse tables must always comply with the coding scheme in the chip. There is an EFUSE_CODE_SCHEME_SELECTOR
option to select the coding type for tables in a Kconfig. When generating source files, if your tables do not follow the coding scheme, an error message will be displayed. Adjust the length or offset fields.
If your program was compiled with None
encoding and 3/4
is used in the chip, then the ESP_ERR_CODING
error may occur when calling the eFuse API (the field is outside the block boundaries). If the field matches the new block boundaries, then the API will work without errors.
Also, 3/4 coding scheme imposes restrictions on writing bits belonging to one coding unit. The whole block with a length of 256 bits is divided into 4 coding units, and in each coding unit there are 6 bytes of useful data and 2 service bytes. These 2 service bytes contain the checksum of the previous 6 data bytes.
It turns out that only one field can be written into one coding unit. Repeated rewriting in one coding unit is prohibited. But if the record was made in advance or through a esp_efuse_write_block()
function, then reading the fields belonging to one coding unit is possible.
In case 3/4
coding scheme, the writing process is divided into the coding units and we can not use the usual mode of writing some fields. We can prepare all the data for writing and burn it in one time. You can also use this mode for None
coding scheme but it is not necessary. It is important for 3/4
coding scheme.
To write some fields in one time need to use the batch writing mode
. Firstly set this mode through esp_efuse_batch_write_begin()
function then write some fields as usual use the esp_efuse_write_...
functions. At the end to burn they, need to call the esp_efuse_batch_write_commit()
function. It burns prepared data to the efuse blocks and disable the batch recording mode
.
The batch writing mode
blocks esp_efuse_read_...
operations.
After changing the coding scheme, run efuse_common_table
and efuse_custom_table
commands to check the tables of the new coding scheme.
eFuse API¶
Access to the fields is via a pointer to the description structure. API functions have some basic operation:
esp_efuse_read_field_blob()
- returns an array of read eFuse bits.esp_efuse_read_field_cnt()
- returns the number of bits programmed as “1”.esp_efuse_write_field_blob()
- writes an array.esp_efuse_write_field_cnt()
- writes a required count of bits as “1”.esp_efuse_get_field_size()
- returns the number of bits by the field name.esp_efuse_read_reg()
- returns value of eFuse register.esp_efuse_write_reg()
- writes value to eFuse register.esp_efuse_get_coding_scheme()
- returns eFuse coding scheme for blocks.esp_efuse_read_block()
- reads key to eFuse block starting at the offset and the required size.esp_efuse_write_block()
- writes key to eFuse block starting at the offset and the required size.esp_efuse_batch_write_begin()
- set the batch mode of writing fields.esp_efuse_batch_write_commit()
- writes all prepared data for batch writing mode and reset the batch writing mode.esp_efuse_batch_write_cancel()
- reset the batch writing mode and prepared data.
For frequently used fields, special functions are made, like this esp_efuse_get_chip_ver()
, esp_efuse_get_pkg_ver()
.
How add a new field¶
Find a free bits for field. Show esp_efuse_table.csv file or run
idf.py show_efuse_table
or the next command:
$ ./efuse_table_gen.py esp32c3/esp_efuse_table.csv --info
eFuse coding scheme: NONE
# field_name efuse_block bit_start bit_count
1 WR_DIS_FLASH_CRYPT_CNT EFUSE_BLK0 2 1
2 WR_DIS_BLK1 EFUSE_BLK0 7 1
3 WR_DIS_BLK2 EFUSE_BLK0 8 1
4 WR_DIS_BLK3 EFUSE_BLK0 9 1
5 RD_DIS_BLK1 EFUSE_BLK0 16 1
6 RD_DIS_BLK2 EFUSE_BLK0 17 1
7 RD_DIS_BLK3 EFUSE_BLK0 18 1
8 FLASH_CRYPT_CNT EFUSE_BLK0 20 7
9 MAC_FACTORY EFUSE_BLK0 32 8
10 MAC_FACTORY EFUSE_BLK0 40 8
11 MAC_FACTORY EFUSE_BLK0 48 8
12 MAC_FACTORY EFUSE_BLK0 56 8
13 MAC_FACTORY EFUSE_BLK0 64 8
14 MAC_FACTORY EFUSE_BLK0 72 8
15 MAC_FACTORY_CRC EFUSE_BLK0 80 8
16 CHIP_VER_DIS_APP_CPU EFUSE_BLK0 96 1
17 CHIP_VER_DIS_BT EFUSE_BLK0 97 1
18 CHIP_VER_PKG EFUSE_BLK0 105 3
19 CHIP_CPU_FREQ_LOW EFUSE_BLK0 108 1
20 CHIP_CPU_FREQ_RATED EFUSE_BLK0 109 1
21 CHIP_VER_REV1 EFUSE_BLK0 111 1
22 ADC_VREF_AND_SDIO_DREF EFUSE_BLK0 136 6
23 XPD_SDIO_REG EFUSE_BLK0 142 1
24 SDIO_TIEH EFUSE_BLK0 143 1
25 SDIO_FORCE EFUSE_BLK0 144 1
26 ENCRYPT_CONFIG EFUSE_BLK0 188 4
27 CONSOLE_DEBUG_DISABLE EFUSE_BLK0 194 1
28 ABS_DONE_0 EFUSE_BLK0 196 1
29 DISABLE_JTAG EFUSE_BLK0 198 1
30 DISABLE_DL_ENCRYPT EFUSE_BLK0 199 1
31 DISABLE_DL_DECRYPT EFUSE_BLK0 200 1
32 DISABLE_DL_CACHE EFUSE_BLK0 201 1
33 ENCRYPT_FLASH_KEY EFUSE_BLK1 0 256
34 SECURE_BOOT_KEY EFUSE_BLK2 0 256
35 MAC_CUSTOM_CRC EFUSE_BLK3 0 8
36 MAC_CUSTOM EFUSE_BLK3 8 48
37 ADC1_TP_LOW EFUSE_BLK3 96 7
38 ADC1_TP_HIGH EFUSE_BLK3 103 9
39 ADC2_TP_LOW EFUSE_BLK3 112 7
40 ADC2_TP_HIGH EFUSE_BLK3 119 9
41 SECURE_VERSION EFUSE_BLK3 128 32
42 MAC_CUSTOM_VER EFUSE_BLK3 184 8
Used bits in eFuse table:
EFUSE_BLK0
[2 2] [7 9] [16 18] [20 27] [32 87] [96 97] [105 109] [111 111] [136 144] [188 191] [194 194] [196 196] [198 201]
EFUSE_BLK1
[0 255]
EFUSE_BLK2
[0 255]
EFUSE_BLK3
[0 55] [96 159] [184 191]
Note: Not printed ranges are free for using. (bits in EFUSE_BLK0 are reserved for Espressif)
Parsing eFuse CSV input file $IDF_PATH/components/efuse/esp32c3/esp_efuse_table.csv ...
Verifying eFuse table...
The number of bits not included in square brackets is free (bits in EFUSE_BLK0 are reserved for Espressif). All fields are checked for overlapping.
Fill a line for field: field_name, efuse_block, bit_start, bit_count, comment.
Run a
show_efuse_table
command to check eFuse table. To generate source files runefuse_common_table
orefuse_custom_table
command.
Debug eFuse & Unit tests¶
Virtual eFuses¶
The Kconfig option CONFIG_EFUSE_VIRTUAL
will virtualize eFuse values inside the eFuse Manager, so writes are emulated and no eFuse values are permanently changed. This can be useful for debugging app and unit tests.
espefuse.py¶
esptool includes a useful tool for reading/writing ESP32-C3 eFuse bits - espefuse.py.
espefuse.py -p COM4 summary
espefuse.py v2.3.1
Connecting........_
Security fuses:
FLASH_CRYPT_CNT Flash encryption mode counter = 0 R/W (0x0)
FLASH_CRYPT_CONFIG Flash encryption config (key tweak bits) = 0 R/W (0x0)
CONSOLE_DEBUG_DISABLE Disable ROM BASIC interpreter fallback = 1 R/W (0x1)
ABS_DONE_0 secure boot enabled for bootloader = 0 R/W (0x0)
ABS_DONE_1 secure boot abstract 1 locked = 0 R/W (0x0)
JTAG_DISABLE Disable JTAG = 0 R/W (0x0)
DISABLE_DL_ENCRYPT Disable flash encryption in UART bootloader = 0 R/W (0x0)
DISABLE_DL_DECRYPT Disable flash decryption in UART bootloader = 0 R/W (0x0)
DISABLE_DL_CACHE Disable flash cache in UART bootloader = 0 R/W (0x0)
BLK1 Flash encryption key
= 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W
BLK2 Secure boot key
= 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 R/W
BLK3 Variable Block 3
= 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fa 87 02 91 00 00 00 00 00 00 00 00 00 00 00 00 R/W
Efuse fuses:
WR_DIS Efuse write disable mask = 0 R/W (0x0)
RD_DIS Efuse read disablemask = 0 R/W (0x0)
CODING_SCHEME Efuse variable block length scheme = 1 R/W (0x1) (3/4)
KEY_STATUS Usage of efuse block 3 (reserved) = 0 R/W (0x0)
Config fuses:
XPD_SDIO_FORCE Ignore MTDI pin (GPIO12) for VDD_SDIO on reset = 0 R/W (0x0)
XPD_SDIO_REG If XPD_SDIO_FORCE, enable VDD_SDIO reg on reset = 0 R/W (0x0)
XPD_SDIO_TIEH If XPD_SDIO_FORCE & XPD_SDIO_REG, 1=3.3V 0=1.8V = 0 R/W (0x0)
SPI_PAD_CONFIG_CLK Override SD_CLK pad (GPIO6/SPICLK) = 0 R/W (0x0)
SPI_PAD_CONFIG_Q Override SD_DATA_0 pad (GPIO7/SPIQ) = 0 R/W (0x0)
SPI_PAD_CONFIG_D Override SD_DATA_1 pad (GPIO8/SPID) = 0 R/W (0x0)
SPI_PAD_CONFIG_HD Override SD_DATA_2 pad (GPIO9/SPIHD) = 0 R/W (0x0)
SPI_PAD_CONFIG_CS0 Override SD_CMD pad (GPIO11/SPICS0) = 0 R/W (0x0)
DISABLE_SDIO_HOST Disable SDIO host = 0 R/W (0x0)
Identity fuses:
MAC MAC Address
= 84:0d:8e:18:8e:44 (CRC ad OK) R/W
CHIP_VER_REV1 Silicon Revision 1 = 1 R/W (0x1)
CHIP_VERSION Reserved for future chip versions = 2 R/W (0x2)
CHIP_PACKAGE Chip package identifier = 0 R/W (0x0)
Calibration fuses:
BLK3_PART_RESERVE BLOCK3 partially served for ADC calibration data = 1 R/W (0x1)
ADC_VREF Voltage reference calibration = 1114 R/W (0x2)
ADC1_TP_LOW ADC1 150mV reading = 346 R/W (0x11)
ADC1_TP_HIGH ADC1 850mV reading = 3285 R/W (0x5)
ADC2_TP_LOW ADC2 150mV reading = 449 R/W (0x7)
ADC2_TP_HIGH ADC2 850mV reading = 3362 R/W (0x1f5)
Flash voltage (VDD_SDIO) determined by GPIO12 on reset (High for 1.8V, Low/NC for 3.3V).
To get a dump for all eFuse registers.
espefuse.py -p COM4 dump
$ espefuse.py -p COM4 dump
espefuse.py v2.3.1
Connecting........__
EFUSE block 0:
00000000 c403bb68 0082240a 00000000 00000035 00000000 00000000
EFUSE block 1:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
EFUSE block 2:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
EFUSE block 3:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Header File¶
Functions¶
-
esp_err_t
esp_efuse_read_field_blob
(const esp_efuse_desc_t *field[], void *dst, size_t dst_size_bits)¶ Reads bits from EFUSE field and writes it into an array.
The number of read bits will be limited to the minimum value from the description of the bits in “field” structure or “dst_size_bits” required size. Use “esp_efuse_get_field_size()” function to determine the length of the field.
- Note
Please note that reading in the batch mode does not show uncommitted changes.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.[out] dst
: A pointer to array that will contain the result of reading.[in] dst_size_bits
: The number of bits required to read. If the requested number of bits is greater than the field, the number will be limited to the field size.
-
bool
esp_efuse_read_field_bit
(const esp_efuse_desc_t *field[])¶ Read a single bit eFuse field as a boolean value.
- Note
The value must exist and must be a single bit wide. If there is any possibility of an error in the provided arguments, call esp_efuse_read_field_blob() and check the returned value instead.
- Note
If assertions are enabled and the parameter is invalid, execution will abort
- Note
Please note that reading in the batch mode does not show uncommitted changes.
- Return
true: The field parameter is valid and the bit is set.
false: The bit is not set, or the parameter is invalid and assertions are disabled.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.
-
esp_err_t
esp_efuse_read_field_cnt
(const esp_efuse_desc_t *field[], size_t *out_cnt)¶ Reads bits from EFUSE field and returns number of bits programmed as “1”.
If the bits are set not sequentially, they will still be counted.
- Note
Please note that reading in the batch mode does not show uncommitted changes.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.[out] out_cnt
: A pointer that will contain the number of programmed as “1” bits.
-
esp_err_t
esp_efuse_write_field_blob
(const esp_efuse_desc_t *field[], const void *src, size_t src_size_bits)¶ Writes array to EFUSE field.
The number of write bits will be limited to the minimum value from the description of the bits in “field” structure or “src_size_bits” required size. Use “esp_efuse_get_field_size()” function to determine the length of the field. After the function is completed, the writing registers are cleared.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.[in] src
: A pointer to array that contains the data for writing.[in] src_size_bits
: The number of bits required to write.
-
esp_err_t
esp_efuse_write_field_cnt
(const esp_efuse_desc_t *field[], size_t cnt)¶ Writes a required count of bits as “1” to EFUSE field.
If there are no free bits in the field to set the required number of bits to “1”, ESP_ERR_EFUSE_CNT_IS_FULL error is returned, the field will not be partially recorded. After the function is completed, the writing registers are cleared.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_CNT_IS_FULL: Not all requested cnt bits is set.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.[in] cnt
: Required number of programmed as “1” bits.
-
esp_err_t
esp_efuse_write_field_bit
(const esp_efuse_desc_t *field[])¶ Write a single bit eFuse field to 1.
For use with eFuse fields that are a single bit. This function will write the bit to value 1 if it is not already set, or does nothing if the bit is already set.
This is equivalent to calling esp_efuse_write_field_cnt() with the cnt parameter equal to 1, except that it will return ESP_OK if the field is already set to 1.
- Return
ESP_OK: The operation was successfully completed, or the bit was already set to value 1.
ESP_ERR_INVALID_ARG: Error in the passed arugments, including if the efuse field is not 1 bit wide.
- Parameters
[in] field
: Pointer to the structure describing the efuse field.
-
esp_err_t
esp_efuse_set_write_protect
(esp_efuse_block_t blk)¶ Sets a write protection for the whole block.
After that, it is impossible to write to this block. The write protection does not apply to block 0.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_CNT_IS_FULL: Not all requested cnt bits is set.
ESP_ERR_NOT_SUPPORTED: The block does not support this command.
- Parameters
[in] blk
: Block number of eFuse. (EFUSE_BLK1, EFUSE_BLK2 and EFUSE_BLK3)
-
esp_err_t
esp_efuse_set_read_protect
(esp_efuse_block_t blk)¶ Sets a read protection for the whole block.
After that, it is impossible to read from this block. The read protection does not apply to block 0.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_CNT_IS_FULL: Not all requested cnt bits is set.
ESP_ERR_NOT_SUPPORTED: The block does not support this command.
- Parameters
[in] blk
: Block number of eFuse. (EFUSE_BLK1, EFUSE_BLK2 and EFUSE_BLK3)
-
int
esp_efuse_get_field_size
(const esp_efuse_desc_t *field[])¶ Returns the number of bits used by field.
- Return
Returns the number of bits used by field.
- Parameters
[in] field
: A pointer to the structure describing the fields of efuse.
-
uint32_t
esp_efuse_read_reg
(esp_efuse_block_t blk, unsigned int num_reg)¶ Returns value of efuse register.
This is a thread-safe implementation. Example: EFUSE_BLK2_RDATA3_REG where (blk=2, num_reg=3)
- Note
Please note that reading in the batch mode does not show uncommitted changes.
- Return
Value of register
- Parameters
[in] blk
: Block number of eFuse.[in] num_reg
: The register number in the block.
-
esp_err_t
esp_efuse_write_reg
(esp_efuse_block_t blk, unsigned int num_reg, uint32_t val)¶ Write value to efuse register.
Apply a coding scheme if necessary. This is a thread-safe implementation. Example: EFUSE_BLK3_WDATA0_REG where (blk=3, num_reg=0)
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
- Parameters
[in] blk
: Block number of eFuse.[in] num_reg
: The register number in the block.[in] val
: Value to write.
-
esp_efuse_coding_scheme_t
esp_efuse_get_coding_scheme
(esp_efuse_block_t blk)¶ Return efuse coding scheme for blocks.
Note: The coding scheme is applicable only to 1, 2 and 3 blocks. For 0 block, the coding scheme is always
NONE
.- Return
Return efuse coding scheme for blocks
- Parameters
[in] blk
: Block number of eFuse.
-
esp_err_t
esp_efuse_read_block
(esp_efuse_block_t blk, void *dst_key, size_t offset_in_bits, size_t size_bits)¶ Read key to efuse block starting at the offset and the required size.
- Note
Please note that reading in the batch mode does not show uncommitted changes.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] blk
: Block number of eFuse.[in] dst_key
: A pointer to array that will contain the result of reading.[in] offset_in_bits
: Start bit in block.[in] size_bits
: The number of bits required to read.
-
esp_err_t
esp_efuse_write_block
(esp_efuse_block_t blk, const void *src_key, size_t offset_in_bits, size_t size_bits)¶ Write key to efuse block starting at the offset and the required size.
- Return
ESP_OK: The operation was successfully completed.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits
- Parameters
[in] blk
: Block number of eFuse.[in] src_key
: A pointer to array that contains the key for writing.[in] offset_in_bits
: Start bit in block.[in] size_bits
: The number of bits required to write.
-
uint8_t
esp_efuse_get_chip_ver
(void)¶ Returns chip version from efuse.
- Return
chip version
-
uint32_t
esp_efuse_get_pkg_ver
(void)¶ Returns chip package from efuse.
- Return
chip package
-
void
esp_efuse_burn_new_values
(void)¶ Permanently update values written to the efuse write registers.
After updating EFUSE_BLKx_WDATAx_REG registers with new values to write, call this function to permanently write them to efuse.
After burning new efuses, the read registers are updated to match the new efuse values.
- Note
Setting bits in efuse is permanent, they cannot be unset.
- Note
Due to this restriction you don’t need to copy values to Efuse write registers from the matching read registers, bits which are set in the read register but unset in the matching write register will be unchanged when new values are burned.
- Note
This function is not threadsafe, if calling code updates efuse values from multiple tasks then this is caller’s responsibility to serialise.
-
void
esp_efuse_reset
(void)¶ Reset efuse write registers.
Efuse write registers are written to zero, to negate any changes that have been staged here.
- Note
This function is not threadsafe, if calling code updates efuse values from multiple tasks then this is caller’s responsibility to serialise.
-
esp_err_t
esp_efuse_disable_rom_download_mode
(void)¶ Disable ROM Download Mode via eFuse.
Permanently disables the ROM Download Mode feature. Once disabled, if the SoC is booted with strapping pins set for ROM Download Mode then an error is printed instead.
- Note
Not all SoCs support this option. An error will be returned if called on an ESP32 with a silicon revision lower than 3, as these revisions do not support this option.
- Note
If ROM Download Mode is already disabled, this function does nothing and returns success.
- Return
ESP_OK If the eFuse was successfully burned, or had already been burned.
ESP_ERR_NOT_SUPPORTED (ESP32 only) This SoC is not capable of disabling UART download mode
ESP_ERR_INVALID_STATE (ESP32 only) This eFuse is write protected and cannot be written
-
esp_err_t
esp_efuse_enable_rom_secure_download_mode
(void)¶ Switch ROM Download Mode to Secure Download mode via eFuse.
Permanently enables Secure Download mode. This mode limits the use of ROM Download Mode functions to simple flash read, write and erase operations, plus a command to return a summary of currently enabled security features.
- Note
If Secure Download mode is already enabled, this function does nothing and returns success.
- Note
Disabling the ROM Download Mode also disables Secure Download Mode.
- Return
ESP_OK If the eFuse was successfully burned, or had already been burned.
ESP_ERR_INVALID_STATE ROM Download Mode has been disabled via eFuse, so Secure Download mode is unavailable.
-
void
esp_efuse_write_random_key
(uint32_t blk_wdata0_reg)¶ Write random data to efuse key block write registers.
- Note
Caller is responsible for ensuring efuse block is empty and not write protected, before calling.
- Note
Behaviour depends on coding scheme: a 256-bit key is generated and written for Coding Scheme “None”, a 192-bit key is generated, extended to 256-bits by the Coding Scheme, and then writtten for 3/4 Coding Scheme.
- Note
This function does not burn the new values, caller should call esp_efuse_burn_new_values() when ready to do this.
- Parameters
blk_wdata0_reg
: Address of the first data write register in the block
-
uint32_t
esp_efuse_read_secure_version
(void)¶ Return secure_version from efuse field.
- Return
Secure version from efuse field
-
bool
esp_efuse_check_secure_version
(uint32_t secure_version)¶ Check secure_version from app and secure_version and from efuse field.
- Return
True: If version of app is equal or more then secure_version from efuse.
- Parameters
secure_version
: Secure version from app.
-
esp_err_t
esp_efuse_update_secure_version
(uint32_t secure_version)¶ Write efuse field by secure_version value.
Update the secure_version value is available if the coding scheme is None. Note: Do not use this function in your applications. This function is called as part of the other API.
- Return
ESP_OK: Successful.
ESP_FAIL: secure version of app cannot be set to efuse field.
ESP_ERR_NOT_SUPPORTED: Anti rollback is not supported with the 3/4 and Repeat coding scheme.
- Parameters
[in] secure_version
: Secure version from app.
-
void
esp_efuse_init
(uint32_t offset, uint32_t size)¶ Initializes variables: offset and size to simulate the work of an eFuse.
Note: To simulate the work of an eFuse need to set CONFIG_BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE option and to add in the partition.csv file a line
efuse_em, data, efuse, , 0x2000,
.- Parameters
[in] offset
: The starting address of the partition where the eFuse data will be located.[in] size
: The size of the partition.
-
esp_err_t
esp_efuse_batch_write_begin
(void)¶ Set the batch mode of writing fields.
This mode allows you to write the fields in the batch mode when need to burn several efuses at one time. To enable batch mode call begin() then perform as usually the necessary operations read and write and at the end call commit() to actually burn all written efuses. The batch mode can be used nested. The commit will be done by the last commit() function. The number of begin() functions should be equal to the number of commit() functions.
Note: If batch mode is enabled by the first task, at this time the second task cannot write/read efuses. The second task will wait for the first task to complete the batch operation.
- Note
Please note that reading in the batch mode does not show uncommitted changes.
// Example of using the batch writing mode. // set the batch writing mode esp_efuse_batch_write_begin(); // use any writing functions as usual esp_efuse_write_field_blob(ESP_EFUSE_...); esp_efuse_write_field_cnt(ESP_EFUSE_...); esp_efuse_set_write_protect(EFUSE_BLKx); esp_efuse_write_reg(EFUSE_BLKx, ...); esp_efuse_write_block(EFUSE_BLKx, ...); esp_efuse_write(ESP_EFUSE_1, 3); // ESP_EFUSE_1 == 1, here we write a new value = 3. The changes will be burn by the commit() function. esp_efuse_read_...(ESP_EFUSE_1); // this function returns ESP_EFUSE_1 == 1 because uncommitted changes are not readable, it will be available only after commit. ... // esp_efuse_batch_write APIs can be called recursively. esp_efuse_batch_write_begin(); esp_efuse_set_write_protect(EFUSE_BLKx); esp_efuse_batch_write_commit(); // the burn will be skipped here, it will be done in the last commit(). ... // Write all of these fields to the efuse registers esp_efuse_batch_write_commit(); esp_efuse_read_...(ESP_EFUSE_1); // this function returns ESP_EFUSE_1 == 3.
- Return
ESP_OK: Successful.
-
esp_err_t
esp_efuse_batch_write_cancel
(void)¶ Reset the batch mode of writing fields.
It will reset the batch writing mode and any written changes.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_STATE: Tha batch mode was not set.
-
esp_err_t
esp_efuse_batch_write_commit
(void)¶ Writes all prepared data for the batch mode.
Must be called to ensure changes are written to the efuse registers. After this the batch writing mode will be reset.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_STATE: The deferred writing mode was not set.
-
const esp_efuse_desc_t **
esp_efuse_get_purpose_field
(esp_efuse_block_t block)¶ Returns a pointer to a key purpose for an efuse key block.
To get the value of this field use esp_efuse_read_field_blob() or esp_efuse_get_key_purpose().
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
- Return
Pointer: If Successful returns a pointer to the corresponding efuse field otherwise NULL.
-
const esp_efuse_desc_t **
esp_efuse_get_key
(esp_efuse_block_t block)¶ Returns a pointer to a key block.
- Return
Pointer: If Successful returns a pointer to the corresponding efuse field otherwise NULL.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
bool
esp_efuse_get_key_dis_read
(esp_efuse_block_t block)¶ Returns a read protection for the key block.
- Return
True: The key block is read protected False: The key block is readable.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
esp_err_t
esp_efuse_set_key_dis_read
(esp_efuse_block_t block)¶ Sets a read protection for the key block.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
bool
esp_efuse_get_key_dis_write
(esp_efuse_block_t block)¶ Returns a write protection for the key block.
- Return
True: The key block is write protected False: The key block is writeable.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
esp_err_t
esp_efuse_set_key_dis_write
(esp_efuse_block_t block)¶ Sets a write protection for the key block.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
esp_efuse_purpose_t
esp_efuse_get_key_purpose
(esp_efuse_block_t block)¶ Returns the current purpose set for an efuse key block.
- Return
Value: If Successful, it returns the value of the purpose related to the given key block.
ESP_EFUSE_KEY_PURPOSE_MAX: Otherwise.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
esp_err_t
esp_efuse_set_key_purpose
(esp_efuse_block_t block, esp_efuse_purpose_t purpose)¶ Sets a key purpose for an efuse key block.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX[in] purpose
: Key purpose.
-
bool
esp_efuse_get_keypurpose_dis_write
(esp_efuse_block_t block)¶ Returns a write protection of the key purpose field for an efuse key block.
- Return
True: The key purpose is write protected. False: The key purpose is writeable.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
esp_err_t
esp_efuse_set_keypurpose_dis_write
(esp_efuse_block_t block)¶ Sets a write protection of the key purpose field for an efuse key block.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] block
: A key block in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX
-
bool
esp_efuse_find_purpose
(esp_efuse_purpose_t purpose, esp_efuse_block_t *block)¶ Find a key block with the particular purpose set.
- Return
True: If found,
False: If not found (value at block pointer is unchanged).
- Parameters
[in] purpose
: Purpose to search for.[out] block
: Pointer in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX which will be set to the key block if found. Can be NULL, if only need to test the key block exists.
-
esp_efuse_block_t
esp_efuse_find_unused_key_block
(void)¶ Search for an unused key block and return the first one found.
See esp_efuse_key_block_unused for a description of an unused key block.
- Return
First unused key block, or EFUSE_BLK_KEY_MAX if no unused key block is found.
-
unsigned
esp_efuse_count_unused_key_blocks
(void)¶ Return the number of unused efuse key blocks in the range EFUSE_BLK_KEY0..EFUSE_BLK_KEY_MAX.
-
bool
esp_efuse_key_block_unused
(esp_efuse_block_t block)¶ Returns true if the key block is unused, false otherwise.
An unused key block is all zero content, not read or write protected, and has purpose 0 (ESP_EFUSE_KEY_PURPOSE_USER)
- Return
True if key block is unused,
False if key block is used or the specified block index is not a key block.
- Parameters
block
: key block to check.
-
bool
esp_efuse_get_digest_revoke
(unsigned num_digest)¶ Returns the status of the Secure Boot public key digest revocation bit.
- Return
True: If key digest is revoked,
False; If key digest is not revoked.
- Parameters
[in] num_digest
: The number of digest in range 0..2
-
esp_err_t
esp_efuse_set_digest_revoke
(unsigned num_digest)¶ Sets the Secure Boot public key digest revocation bit.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] num_digest
: The number of digest in range 0..2
-
bool
esp_efuse_get_write_protect_of_digest_revoke
(unsigned num_digest)¶ Returns a write protection of the Secure Boot public key digest revocation bit.
- Return
True: The revocation bit is write protected. False: The revocation bit is writeable.
- Parameters
[in] num_digest
: The number of digest in range 0..2
-
esp_err_t
esp_efuse_set_write_protect_of_digest_revoke
(unsigned num_digest)¶ Sets a write protection of the Secure Boot public key digest revocation bit.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] num_digest
: The number of digest in range 0..2
-
esp_err_t
esp_efuse_write_key
(esp_efuse_block_t block, esp_efuse_purpose_t purpose, const void *key, size_t key_size_bytes)¶ Program a block of key data to an efuse block.
The burn of a key, protection bits, and a purpose happens in batch mode.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_INVALID_STATE: Error in efuses state, unused block not found.
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] block
: Block to read purpose for. Must be in range EFUSE_BLK_KEY0 to EFUSE_BLK_KEY_MAX. Key block must be unused (esp_efuse_key_block_unused).[in] purpose
: Purpose to set for this key. Purpose must be already unset.[in] key
: Pointer to data to write.[in] key_size_bytes
: Bytes length of data to write.
-
esp_err_t
esp_efuse_write_keys
(esp_efuse_purpose_t purposes[], uint8_t keys[][32], unsigned number_of_keys)¶ Program keys to unused efuse blocks.
The burn of keys, protection bits, and purposes happens in batch mode.
- Return
ESP_OK: Successful.
ESP_ERR_INVALID_ARG: Error in the passed arguments.
ESP_ERR_INVALID_STATE: Error in efuses state, unused block not found.
ESP_ERR_NOT_ENOUGH_UNUSED_KEY_BLOCKS: Error not enough unused key blocks available
ESP_ERR_EFUSE_REPEATED_PROG: Error repeated programming of programmed bits is strictly forbidden.
ESP_ERR_CODING: Error range of data does not match the coding scheme.
- Parameters
[in] purposes
: Array of purposes (purpose[number_of_keys]).[in] keys
: Array of keys (uint8_t keys[number_of_keys][32]). Each key is 32 bytes long.[in] number_of_keys
: The number of keys to write (up to 6 keys).
Macros¶
-
ESP_ERR_EFUSE
¶ Base error code for efuse api.
-
ESP_OK_EFUSE_CNT
¶ OK the required number of bits is set.
-
ESP_ERR_EFUSE_CNT_IS_FULL
¶ Error field is full.
-
ESP_ERR_EFUSE_REPEATED_PROG
¶ Error repeated programming of programmed bits is strictly forbidden.
-
ESP_ERR_CODING
¶ Error while a encoding operation.
-
ESP_ERR_NOT_ENOUGH_UNUSED_KEY_BLOCKS
¶ Error not enough unused key blocks available
Enumerations¶
-
enum
esp_efuse_purpose_t
¶ Type of key purpose.
Values:
-
ESP_EFUSE_KEY_PURPOSE_USER
= 0¶
-
ESP_EFUSE_KEY_PURPOSE_RESERVED
= 1¶
-
ESP_EFUSE_KEY_PURPOSE_XTS_AES_256_KEY_1
= 2¶
-
ESP_EFUSE_KEY_PURPOSE_XTS_AES_256_KEY_2
= 3¶
-
ESP_EFUSE_KEY_PURPOSE_XTS_AES_128_KEY
= 4¶
-
ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL
= 5¶
-
ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG
= 6¶
-
ESP_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE
= 7¶
-
ESP_EFUSE_KEY_PURPOSE_HMAC_UP
= 8¶
-
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST0
= 9¶
-
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST1
= 10¶
-
ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_DIGEST2
= 11¶
-
ESP_EFUSE_KEY_PURPOSE_MAX
¶
-