Skip to content

Commit

Permalink
feat(esptool): allow to set force for write_flash
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdragun committed Apr 17, 2023
1 parent 96f2d21 commit faa82b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions components/esptool_py/run_serial_tool.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ else()
list(APPEND serial_tool_cmd -b ${ESPBAUD})
endif()

# SERIAL_TOOL_ARGS is defined during the first cmake run
# SERIAL_TOOL_EXTRA_ARGS is used for additional arguments from the command line during run-time
list(APPEND serial_tool_cmd ${SERIAL_TOOL_ARGS})
list(APPEND serial_tool_cmd $ENV{SERIAL_TOOL_EXTRA_ARGS})

if(${SERIAL_TOOL_SILENT})
execute_process(COMMAND ${serial_tool_cmd}
Expand Down
35 changes: 29 additions & 6 deletions tools/idf_py_actions/serial_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import os
import shlex
import signal
import sys
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -166,7 +167,7 @@ def monitor(action: str, ctx: click.core.Context, args: PropertyDict, print_filt
finally:
signal.signal(signal.SIGINT, old_handler)

def flash(action: str, ctx: click.core.Context, args: PropertyDict) -> None:
def flash(action: str, ctx: click.core.Context, args: PropertyDict, force: bool, extra_args: str) -> None:
"""
Run esptool to flash the entire project, from an argfile generated by the build system
"""
Expand All @@ -177,7 +178,13 @@ def flash(action: str, ctx: click.core.Context, args: PropertyDict) -> None:
return

args.port = args.port or get_default_serial_port()
run_target(action, args, {'ESPBAUD': str(args.baud), 'ESPPORT': args.port})
extra = list()
if force:
extra.append('--force')
if extra_args:
extra += shlex.split(extra_args)
env = {'ESPBAUD': str(args.baud), 'ESPPORT': args.port, 'SERIAL_TOOL_EXTRA_ARGS': ';'.join(extra)}
run_target(action, args, env)

def erase_flash(action: str, ctx: click.core.Context, args: PropertyDict) -> None:
ensure_build_directory(args, ctx.info_name)
Expand Down Expand Up @@ -205,13 +212,27 @@ def ota_targets(target_name: str, ctx: click.core.Context, args: PropertyDict) -
run_target(target_name, args, {'ESPBAUD': str(args.baud), 'ESPPORT': args.port})

BAUD_AND_PORT = [BAUD_RATE, PORT]
flash_options = BAUD_AND_PORT + [
{
'names': ['--force'],
'is_flag': True,
'help': 'Force write, skip security and compatibility checks. Use with caution!',
},
{
'names': ['--extra-args'],
'help': (
'Pass extra arguments to esptool separated by space. For more details see `esptool.py write_flash --help`. '
'For example to compress and verify data use: `idf.py flash --extra-args="--compress --verify"`. Use with caution!'
)
}
]
serial_actions = {
'global_action_callbacks': [global_callback],
'actions': {
'flash': {
'callback': flash,
'help': 'Flash the project.',
'options': global_options + BAUD_AND_PORT,
'options': global_options + flash_options,
'order_dependencies': ['all', 'erase-flash'],
},
'erase-flash': {
Expand Down Expand Up @@ -300,29 +321,31 @@ def ota_targets(target_name: str, ctx: click.core.Context, args: PropertyDict) -
'partition-table-flash': {
'callback': flash,
'help': 'Flash partition table only.',
'options': BAUD_AND_PORT,
'options': flash_options,
'order_dependencies': ['partition-table', 'erase-flash'],
},
'bootloader-flash': {
'callback': flash,
'help': 'Flash bootloader only.',
'options': BAUD_AND_PORT,
'options': flash_options,
'order_dependencies': ['bootloader', 'erase-flash'],
},
'app-flash': {
'callback': flash,
'help': 'Flash the app only.',
'options': BAUD_AND_PORT,
'options': flash_options,
'order_dependencies': ['app', 'erase-flash'],
},
'encrypted-app-flash': {
'callback': flash,
'help': 'Flash the encrypted app only.',
'options': flash_options,
'order_dependencies': ['app', 'erase-flash'],
},
'encrypted-flash': {
'callback': flash,
'help': 'Flash the encrypted project.',
'options': flash_options,
'order_dependencies': ['all', 'erase-flash'],
},
'erase-otadata': {
Expand Down

0 comments on commit faa82b0

Please sign in to comment.