Skip to content

Commit

Permalink
Tools: Improve the flashing instructions printed after "idf.py build"
Browse files Browse the repository at this point in the history
Closes #11181
  • Loading branch information
dobairoland committed Apr 20, 2023
1 parent 149fc60 commit d75b7a7
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions tools/idf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -13,8 +13,6 @@
# check_environment() function below. If possible, avoid importing
# any external libraries here - put in external script, or import in
# their specific function instead.
from __future__ import annotations

import codecs
import json
import locale
Expand Down Expand Up @@ -281,7 +279,7 @@ class Scope(object):

SCOPES = ('default', 'global', 'shared')

def __init__(self, scope: Union['Scope', str]=None) -> None:
def __init__(self, scope: Union['Scope', str]=None) -> None: # noqa: F821
if scope is None:
self._scope = 'default'
elif isinstance(scope, str) and scope in self.SCOPES:
Expand Down Expand Up @@ -468,25 +466,35 @@ def flasher_path(f: Union[str, 'os.PathLike[str]']) -> str:
for o, f in flash_items:
cmd += o + ' ' + flasher_path(f) + ' '

print('\n%s build complete. To flash, run this command:' % title)

print(
'%s %s -p %s -b %s --before %s --after %s --chip %s %s write_flash %s' % (
PYTHON,
_safe_relpath('%s/components/esptool_py/esptool/esptool.py' % os.environ['IDF_PATH']),
args.port or '(PORT)',
args.baud,
flasher_args['extra_esptool_args']['before'],
flasher_args['extra_esptool_args']['after'],
flasher_args['extra_esptool_args']['chip'],
'--no-stub' if not flasher_args['extra_esptool_args']['stub'] else '',
cmd.strip(),
))
print(
"or run 'idf.py -p %s %s'" % (
args.port or '(PORT)',
key + '-flash' if key != 'project' else 'flash',
))
flash_target = 'flash' if key == 'project' else f'{key}-flash'
print(f'{os.linesep}{title} build complete. To flash, run:')
print(f' idf.py {flash_target}')
if args.port:
print('or')
print(f' idf.py -p {args.port} {flash_target}')
print('or')
print(f' idf.py -p PORT {flash_target}')

esptool_cmd = ['python -m esptool',
'--chip {}'.format(flasher_args['extra_esptool_args']['chip']),
f'-b {args.baud}',
'--before {}'.format(flasher_args['extra_esptool_args']['before']),
'--after {}'.format(flasher_args['extra_esptool_args']['after'])]

if not flasher_args['extra_esptool_args']['stub']:
esptool_cmd += ['--no-stub']

if args.port:
esptool_cmd += [f'-p {args.port}']

esptool_cmd += ['write_flash']

print('or')
print(' {}'.format(' '.join(esptool_cmd + [cmd.strip()])))

if os.path.exists(os.path.join(args.build_dir, 'flash_args')):
print(f'or from the "{args.build_dir}" directory')
print(' {}'.format(' '.join(esptool_cmd + ['@flash_args'])))

if 'all' in actions or 'build' in actions:
print_flashing_message('Project', 'project')
Expand Down

0 comments on commit d75b7a7

Please sign in to comment.