Skip to content

Commit

Permalink
tools: set baudrate and port with otatool.
Browse files Browse the repository at this point in the history
Bugfix: Allow setting options port -p and baudrate -b, with idf.py otatool commands.

Closes #8317
  • Loading branch information
Marek Fiala committed Mar 11, 2022
1 parent c29343e commit fdee1fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
22 changes: 0 additions & 22 deletions tools/idf_py_actions/core_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,28 +451,6 @@ def get_default_language():
'order_dependencies': ['reconfigure'],
'options': global_options,
},
'erase_otadata': {
'callback': build_target,
'hidden': True,
'help': 'Erase otadata partition.',
'options': global_options,
},
'erase-otadata': {
'callback': build_target,
'help': 'Erase otadata partition. Deprecated alias: "erase_otadata".',
'options': global_options,
},
'read_otadata': {
'callback': build_target,
'hidden': True,
'help': 'Read otadata partition.',
'options': global_options,
},
'read-otadata': {
'callback': build_target,
'help': 'Read otadata partition. Deprecated alias: "read_otadata".',
'options': global_options,
},
'build-system-targets': {
'callback': list_build_system_targets,
'help': 'Print list of build system targets.',
Expand Down
48 changes: 41 additions & 7 deletions tools/idf_py_actions/serial_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ def global_callback(ctx, global_args, tasks):
task.action_args['encrypted'] = True
break

def ota_targets(target_name, ctx, args):
"""
Execute the target build system to build target 'target_name'.
Additionally set global variables for baud and port.
Calls ensure_build_directory() which will run cmake to generate a build
directory (with the specified generator) as needed.
"""
args.port = args.port or _get_default_serial_port(args)
ensure_build_directory(args, ctx.info_name)
run_target(target_name, args, {'ESPBAUD': str(args.baud), 'ESPPORT': args.port})

baud_rate = {
'names': ['-b', '--baud'],
'help': 'Baud rate for flashing.',
Expand All @@ -185,19 +196,20 @@ def global_callback(ctx, global_args, tasks):
'default': None,
}

BAUD_AND_PORT = [baud_rate, port]
serial_actions = {
'global_action_callbacks': [global_callback],
'actions': {
'flash': {
'callback': flash,
'help': 'Flash the project.',
'options': global_options + [baud_rate, port],
'options': global_options + BAUD_AND_PORT,
'order_dependencies': ['all', 'erase-flash'],
},
'erase-flash': {
'callback': erase_flash,
'help': 'Erase entire flash chip. Deprecated alias: "erase_flash"',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
},
'erase_flash': {
'callback': erase_flash,
Expand All @@ -207,7 +219,7 @@ def global_callback(ctx, global_args, tasks):
},
'hidden': True,
'help': 'Erase entire flash chip.',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
},
'monitor': {
'callback':
Expand Down Expand Up @@ -269,26 +281,26 @@ def global_callback(ctx, global_args, tasks):
'partition-table-flash': {
'callback': flash,
'help': 'Flash partition table only. Deprecated alias: "partition_table-flash".',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
'order_dependencies': ['partition-table', 'erase-flash'],
},
'partition_table-flash': {
'callback': flash,
'hidden': True,
'help': 'Flash partition table only.',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
'order_dependencies': ['partition-table', 'erase-flash'],
},
'bootloader-flash': {
'callback': flash,
'help': 'Flash bootloader only.',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
'order_dependencies': ['bootloader', 'erase-flash'],
},
'app-flash': {
'callback': flash,
'help': 'Flash the app only.',
'options': [baud_rate, port],
'options': BAUD_AND_PORT,
'order_dependencies': ['app', 'erase-flash'],
},
'encrypted-app-flash': {
Expand All @@ -301,6 +313,28 @@ def global_callback(ctx, global_args, tasks):
'help': 'Flash the encrypted project.',
'order_dependencies': ['all', 'erase-flash'],
},
'erase_otadata': {
'callback': ota_targets,
'hidden': True,
'help': 'Erase otadata partition.',
'options': global_options + BAUD_AND_PORT,
},
'erase-otadata': {
'callback': ota_targets,
'help': 'Erase otadata partition. Deprecated alias: "erase_otadata".',
'options': global_options + BAUD_AND_PORT,
},
'read_otadata': {
'callback': ota_targets,
'hidden': True,
'help': 'Read otadata partition.',
'options': global_options + BAUD_AND_PORT,
},
'read-otadata': {
'callback': ota_targets,
'help': 'Read otadata partition. Deprecated alias: "read_otadata".',
'options': global_options + BAUD_AND_PORT,
},
},
}

Expand Down

0 comments on commit fdee1fa

Please sign in to comment.