Skip to content

Commit ff72b26

Browse files
committed
feat(espefuse): Replace execute-scripts with public API
BREAKING CHANGE: - execute-scripts command is removed
1 parent d7da0f8 commit ff72b26

18 files changed

+208
-453
lines changed

docs/en/espefuse/execute-scripts-cmd.rst

Lines changed: 0 additions & 119 deletions
This file was deleted.

docs/en/espefuse/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Supported Commands
4141
get-custom-mac <get-custom-mac-cmd>
4242
adc-info <adc-info-cmd>
4343
set-flash-voltage <set-flash-voltage-cmd>
44-
execute-scripts <execute-scripts-cmd>
4544
check-error <check-error-cmd>
4645

4746
Optional General Arguments Of Commands

docs/en/migration-guide.rst

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ Choices for the ``--before`` and ``--after`` options have been renamed to use ``
225225

226226
1. Replace all underscores in the ``--before`` and ``--after`` options with ``-`` in your scripts.
227227

228-
229228
espsecure.py ``v5`` Migration Guide
230229
***********************************
231230

@@ -268,9 +267,9 @@ The public API of ``espsecure.py`` has been updated to provide a more consistent
268267
**Migration Steps:**
269268

270269
1. Update function calls to pass individual parameters instead of the ``args`` object. For example:
271-
``sign_data(args)`` -> ``sign_data(data=args.data, key=args.key, ...)``
272-
or if you were mocking the args object, now you don't have to do that and you can pass parameters directly to the function like:
273-
``sign_data(data=data, key=key, ...)``.
270+
``sign_data(args)`` -> ``sign_data(data=args.data, key=args.key, ...)``
271+
or if you were mocking the args object, now you don't have to do that and you can pass parameters directly to the function like:
272+
``sign_data(data=data, key=key, ...)``.
274273
2. Replace the ``custom_commandline`` parameter with ``argv`` in the ``main`` function call.
275274

276275
espefuse.py ``v5`` Migration Guide
@@ -307,3 +306,69 @@ The ``--port`` option is now required for all commands (except when using ``--vi
307306
**Migration Steps:**
308307

309308
1. Add the ``--port`` option to all your espefuse commands.
309+
310+
311+
``execute-scripts`` Command Removal
312+
###################################
313+
314+
The ``execute-scripts`` command has been **removed in v5**. This command was used to execute custom eFuses scripts. It was deprecated in favor of using ``espefuse.py`` as a Python module (see :ref:`here <espefuse-scripting>`).
315+
316+
**Migration Steps:**
317+
318+
1. Refactor any workflows using the deprecated ``execute-scripts`` to use the public API.
319+
2. Make sure to use the ``batch_mode`` argument for ``init_commands`` to avoid burning eFuses one by one.
320+
3. Variables ``idx`` and ``configfiles`` are no longer supported. These can be replaced with simple for loops in Python.
321+
322+
For example, the following commands and script (using ESP32):
323+
324+
.. code-block:: bash
325+
326+
> espefuse.py --port /dev/ttyUSB0 execute_scripts efuse_script.py --do-not-confirm
327+
328+
.. code-block:: python
329+
330+
espefuse(esp, efuses, args, "burn_efuse JTAG_DISABLE 1 DISABLE_SDIO_HOST 1 CONSOLE_DEBUG_DISABLE 1")
331+
espefuse(esp, efuses, args, "burn_key flash_encryption ../../images/efuse/256bit --no-protect-key")
332+
espefuse(esp, efuses, args, "burn_key_digest ../../secure_images/rsa_secure_boot_signing_key.pem")
333+
espefuse(esp, efuses, args, "burn_bit BLOCK3 64 66 69 72 78 82 83 90")
334+
espefuse(esp, efuses, args, "burn_custom_mac AA:BB:CC:DD:EE:88")
335+
336+
efuses.burn_all()
337+
338+
espefuse(esp, efuses, args, "summary")
339+
espefuse(esp, efuses, args, "adc_info")
340+
espefuse(esp, efuses, args, "get_custom_mac")
341+
342+
if not efuses["BLOCK1"].is_readable() or not efuses["BLOCK1"].is_writeable():
343+
raise Exception("BLOCK1 should be readable and writeable")
344+
345+
Can be replaced with public API:
346+
347+
.. code-block:: python
348+
349+
from espefuse import init_commands
350+
351+
with init_commands(port="/dev/ttyUSB0", batch_mode=True, do_not_confirm=True) as espefuse:
352+
espefuse.burn_efuse({"JTAG_DISABLE": "1", "DISABLE_SDIO_HOST": "1", "CONSOLE_DEBUG_DISABLE": "1"})
353+
with open("../../images/efuse/256bit", "rb") as f:
354+
espefuse.burn_key(["flash_encryption"], [f], no_protect_key=True)
355+
with open("../../secure_images/rsa_secure_boot_signing_key.pem", "rb") as f:
356+
espefuse.burn_key_digest([f])
357+
espefuse.burn_bit("BLOCK3", [64, 66, 69, 72, 78, 82, 83, 90])
358+
espefuse.burn_custom_mac(b"\xaa\xbb\xcc\xdd\xee\x88")
359+
360+
espefuse.burn_all()
361+
362+
espefuse.summary()
363+
espefuse.adc_info()
364+
espefuse.get_custom_mac()
365+
366+
if not espefuse.efuses["BLOCK1"].is_readable() or not espefuse.efuses["BLOCK1"].is_writeable():
367+
raise Exception("BLOCK1 should be readable and writeable")
368+
369+
.. note::
370+
371+
Please note that the ``batch_mode`` argument for ``init_commands`` is required to avoid burning eFuses one by one. This was previously
372+
the default behavior for ``execute-scripts`` command.
373+
374+
For more details on the public API, see :ref:`espefuse-scripting`.

espefuse/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from espefuse.cli_util import Group
1414
from espefuse.efuse.base_operations import BaseCommands
1515
from espefuse.efuse_interface import (
16+
DEPRECATED_COMMANDS,
1617
get_esp,
1718
init_commands,
1819
SUPPORTED_COMMANDS,
@@ -118,6 +119,10 @@ def cli(
118119
esp = ctx.obj.get("esp", None)
119120
external_esp = esp is not None
120121
is_help = ctx.obj.get("is_help", False)
122+
used_cmds = ctx.obj.get("used_cmds", [])
123+
124+
if any(cmd.replace("_", "-") in DEPRECATED_COMMANDS for cmd in used_cmds):
125+
return # do not connect to ESP if any command is deprecated
121126

122127
if not port and not external_esp and not is_help and not virt:
123128
raise click.BadOptionUsage(
@@ -159,7 +164,6 @@ def close_port():
159164
commands.efuses.postpone = postpone
160165
commands.add_cli_commands(cli)
161166

162-
used_cmds = ctx.obj["used_cmds"]
163167
multiple_burn_commands = (
164168
sum(cmd.replace("_", "-") in SUPPORTED_BURN_COMMANDS for cmd in used_cmds) > 1
165169
)
@@ -180,6 +184,20 @@ def process_result(result, *args, **kwargs):
180184
print("Successful")
181185

182186

187+
@cli.command("execute-scripts", hidden=True)
188+
@click.argument("scripts", nargs=-1, type=click.UNPROCESSED)
189+
@click.option("--index", type=click.UNPROCESSED)
190+
@click.option("--configfiles", type=click.UNPROCESSED)
191+
def execute_scripts_cli(scripts, index, configfiles):
192+
"""REMOVED: See Migration guide in documentation for details."""
193+
log.error(
194+
"REMOVED: `execute_scripts` was replaced with the public API in v5. "
195+
"Please see Migration Guide in documentation for details: "
196+
"https://docs.espressif.com/projects/esptool/en/latest/migration-guide.html#espefuse-py-v5-migration-guide"
197+
)
198+
sys.exit(2)
199+
200+
183201
def main(argv: list[str] | None = None, esp: esptool.ESPLoader | None = None):
184202
"""
185203
Main function for espefuse

espefuse/cli_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from esptool.logger import log
1111

1212
from espefuse.efuse_interface import (
13+
DEPRECATED_COMMANDS,
1314
init_commands,
1415
SUPPORTED_BURN_COMMANDS,
1516
SUPPORTED_READ_COMMANDS,
@@ -224,7 +225,7 @@ def parse_args(self, ctx: click.Context, args: list[str]):
224225
def get_help(self, ctx: click.Context) -> str:
225226
# help was called without any commands, so we need to add the commands for the
226227
# default chip
227-
if not self.list_commands(ctx):
228+
if not (set(self.list_commands(ctx)) - set(DEPRECATED_COMMANDS)):
228229
chip = ctx.obj["chip"]
229230
if chip == "auto":
230231
log.note(

espefuse/efuse/base_operations.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,6 @@ def summary_cli(format, file, efuses_to_show=[]):
355355
"""Print human-readable summary of eFuse values."""
356356
self.summary(efuses_to_show, format, file)
357357

358-
@cli.command("execute-scripts")
359-
@click.argument("scripts", nargs=-1, type=click.File("r"), required=True)
360-
@click.option(
361-
"--index",
362-
type=int,
363-
help="integer index. It allows to retrieve unique data per chip "
364-
"from configfiles and then burn them (ex. CUSTOM_MAC, UNIQUE_ID).",
365-
)
366-
@click.option(
367-
"--configfiles",
368-
type=click.File("r"),
369-
multiple=True,
370-
help="List of configfiles with data",
371-
)
372-
@click.pass_context
373-
def execute_scripts_cli(ctx, scripts, index, configfiles):
374-
"""Executes scripts to burn at one time."""
375-
self.execute_scripts(scripts, ctx.obj["debug"], configfiles, index)
376-
377358
@cli.command("check-error")
378359
@click.option(
379360
"--recovery", is_flag=True, help="Recovery of BLOCKs after encoding errors"
@@ -1151,9 +1132,6 @@ def check_error(self, recovery: bool = False, do_not_confirm: bool = False):
11511132
raise esptool.FatalError("Error(s) were detected in eFuses")
11521133
print("No errors detected")
11531134

1154-
def execute_scripts(self, scripts, debug, configfiles, index):
1155-
raise NotImplementedError("execute_scripts is not implemented")
1156-
11571135
def burn_custom_mac(self, mac: str | bytes):
11581136
"""
11591137
Burn a 48-bit Custom MAC Address.

espefuse/efuse_interface.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class DefChip:
4141
"burn-key-digest",
4242
"burn-custom-mac",
4343
"set-flash-voltage",
44-
"execute-scripts",
4544
]
4645

4746
SUPPORTED_READ_COMMANDS = [
@@ -52,7 +51,11 @@ class DefChip:
5251
"check-error",
5352
]
5453

55-
SUPPORTED_COMMANDS = SUPPORTED_READ_COMMANDS + SUPPORTED_BURN_COMMANDS
54+
DEPRECATED_COMMANDS = ["execute-scripts"]
55+
56+
SUPPORTED_COMMANDS = (
57+
SUPPORTED_READ_COMMANDS + SUPPORTED_BURN_COMMANDS + DEPRECATED_COMMANDS
58+
)
5659

5760
SUPPORTED_CHIPS = {
5861
"esp32": DefChip(esp32_efuse, esptool.targets.ESP32ROM),

test/efuse_scripts/efuse_burn1.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/efuse_scripts/efuse_burn2.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/efuse_scripts/esp32/config1.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)