1.. _espefuse:
2
3espefuse.py
4===========
5
6``espefuse.py`` is a tool for communicating with Espressif chips for the purpose of reading/writing ("burning") the one-time-programmable eFuses. Burning occurs only in one direction from 0 to 1 (never cleared 1->0).
7
8.. warning::
9
10    Because eFuse is one-time-programmable, it is possible to permanently damage or "brick" your {IDF_TARGET_NAME} using this tool. Use it with great care.
11
12For more details about Espressif chips eFuse features, see the `Technical Reference Manual <https://www.espressif.com/en/support/documents/technical-documents>`__.
13
14``espefuse.py`` is installed alongside ``esptool.py``, so if ``esptool.py`` (v2.0 or newer) is available on the PATH then ``espefuse.py`` should be as well.
15
16Initial State of Efuses
17-----------------------
18
19On relatively new chip, most eFuses are unburned (value 0). Some eFuses are already burned at the factory stage:
20
21- MAC (Factory MAC Address).
22- ADC calibration
23- Chip package and revision.
24- etc.
25
26Supported Commands
27------------------
28
29.. toctree::
30   :maxdepth: 1
31
32   dump <dump-cmd>
33   summary <summary-cmd>
34   burn_efuse <burn-efuse-cmd>
35   burn_block_data <burn-block-data-cmd>
36   burn_bit <burn-bit-cmd>
37   read_protect_efuse and write_protect_efuse <read-write-protections-cmd>
38   burn_key <burn-key-cmd>
39   burn_key_digest <burn-key-digest-cmd>
40   burn_custom_mac <burn-custom-mac-cmd>
41   get_custom_mac <get-custom-mac-cmd>
42   adc_info <adc-info-cmd>
43   set_flash_voltage <set-flash-voltage-cmd>
44   execute_scripts <execute-scripts-cmd>
45   check_error <check-error-cmd>
46
47Optional General Arguments Of Commands
48--------------------------------------
49
50- ``-h``, ``--help`` - Show help message and exit. Use ``-h`` to see a summary of all available commands and command line options. To see all options for a particular chip and command, add ``-c {IDF_TARGET_NAME}`` and ``-h`` to the command name, i.e. ``espefuse.py -c {IDF_TARGET_NAME} burn_key -h``.
51- ``--chip``, ``-c`` - Target chip type. If this argument is omitted, the tool automatically detects the chip type when connected. But if the command has a help option, the chip is not connected, and the default chip is ``esp32``, please specify the specific type of chip to get the correct help. Example of usage: ``-c esp32``, ``-c esp32c3``, ``-c esp32s2`` and others.
52- ``--baud``, ``-b`` - Serial port baud rate, the same as for esptool.
53- ``--port``, ``-p`` - Serial port device, ``-p /dev/ttyUSB0`` (Linux and macOS) or ``-p COM1`` (Windows).
54- ``--before`` -  What to do before connecting to the chip: ``default_reset``, ``no_reset``, ``esp32r1``, ``no_reset_no_sync``.
55- ``--debug``, ``-d`` - Show debugging information.
56- ``--virt`` - For host tests. The tool will work in the virtual mode (without connecting to a chip).
57- ``--path-efuse-file`` - For host tests. Use it together with ``--virt`` option. The tool will work in the virtual mode (without connecting to a chip) and save eFuse memory to a given file. If the file does not exists the tool creates it. To reset written eFuses just delete the file. Usage: ``--path-efuse-file efuse_memory.bin``.
58- ``--do-not-confirm`` - Do not pause for confirmation before permanently writing eFuses. Use with caution. If this option is not used, a manual confirmation step is required, you need to enter the word ``BURN`` to continue burning.
59
60Virtual mode
61^^^^^^^^^^^^
62
63This mode is enabled with the ``--virt`` flag (need to specify chip with ``--chip``). This helps to test commands without physical access to the chip. Burned data is not saved between commands. Using ``--path-efuse-file``, you can save the written data to a file. Delete the file to clear eFuses.
64
65Confirmation
66^^^^^^^^^^^^
67
68Each burn operation requires manual confirmation, you need to type the word ``BURN`` to continue burning. Using the ``--do-not-confirm`` option allows to skip it.
69
70Coding Scheme
71-------------
72
73The coding scheme helps the eFuse controller to detect an error of the eFuse blocks. There are special registers that indicate that there is an error in the block.
74
75{IDF_TARGET_NAME} supports the following coding schemes:
76
77.. only:: esp32
78
79    * ``None`` no need any special encoding data. BLOCK0 is always None.
80    * ``3/4``, requires encoding data. The BLOCK length is reduced from 256 bits to 192 bits.
81    * ``Repeat`` not supported by this tool and IDF. The BLOCK length is reduced from 256 bits to 128 bits.
82
83    BLOCK1-3 can have any of this coding scheme. It depends on the ``CODING_SCHEME`` eFuse.
84
85.. only:: not esp32
86
87    * ``None`` no need any special encoding data, but internally it copies data four times. BLOCK0.
88    * ``RS`` (Reed-Solomon), it uses 6 bytes of automatic error correction.
89
90   Rest eFuse blocks from BLOCK1 to BLOCK(max) have ``RS`` coding scheme.
91
92This tool automatically adds encoding data to the burning data if it requires. Encoded data is calculated individually for each block.
93
94All coding schemes (except ``None``) require additional encoding data to be provided at write time. Due to the encoding data, such blocks cannot be overwritten again without breaking the block's coding scheme. Use the :ref:`perform-multiple-operations` feature or list multiple eFuses/keys.
95
96Burning Efuse
97-------------
98
99Burning occurs in order from BLOCK(max) to BLOCK0. This prevents read/write protection from being set before the data is set. After burning, the tool reads the written data back and compares the original data, and additionally checks the status of the coding scheme, if there are any errors, it re-burns the data again to correct it.
100
101.. _perform-multiple-operations:
102
103Perform Multiple Operations In A Single Espefuse Run
104----------------------------------------------------
105
106Some eFuse blocks have an encoding scheme (Reed-Solomon or 3/4) that requires encoded data, making these blocks only writable once. If you need to write multiple keys/eFuses to one block using different commands, you can use this feature - multiple commands. This feature burns given data once at the end of all commands. All commands supported by version v3.2 or later are supported to be chained together.
107
108The example below shows how to use the two commands ``burn_key_digest`` and ``burn_key`` to write the Secure Boot key and Flash Encryption key into one BLOCK3 for the ``ESP32-C2`` chip. Using these commands individually will result in only one key being written correctly.
109
110.. code-block:: none
111
112    > espefuse.py -c esp32c2  \
113                            burn_key_digest secure_images/ecdsa256_secure_boot_signing_key_v2.pem \
114                            burn_key BLOCK_KEY0 images/efuse/128bit_key.bin XTS_AES_128_KEY_DERIVED_FROM_128_EFUSE_BITS
115
116Recommendations
117---------------
118
1191. The `Technical Reference Manual <https://www.espressif.com/en/support/documents/technical-documents>`__ has a recommendation for reducing the number of burn operations as much as possible. The tool supports several ways to do this:
120
121    - Combine multiple commands into one with this :ref:`perform-multiple-operations` feature.
122    - Most commands support getting a list of arguments (eFuse names, keys).
123
1243. Make sure the power supply is stable because this may cause burning problems.
125