mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-02 07:16:00 +00:00
idf.py: add linux target support for idf.py flash and idf.py monitor
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import click
|
||||
from idf_monitor_base.output_helpers import yellow_print
|
||||
from idf_py_actions.errors import FatalError, NoSerialPortFoundError
|
||||
from idf_py_actions.global_options import global_options
|
||||
from idf_py_actions.tools import ensure_build_directory, get_sdkconfig_value, run_target, run_tool
|
||||
@@ -11,6 +15,14 @@ PYTHON = sys.executable
|
||||
|
||||
|
||||
def action_extensions(base_actions, project_path):
|
||||
def _get_project_desc(ctx, args):
|
||||
desc_path = os.path.join(args.build_dir, 'project_description.json')
|
||||
if not os.path.exists(desc_path):
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
with open(desc_path, 'r') as f:
|
||||
project_desc = json.load(f)
|
||||
return project_desc
|
||||
|
||||
def _get_default_serial_port(args):
|
||||
# Import is done here in order to move it after the check_environment() ensured that pyserial has been installed
|
||||
try:
|
||||
@@ -75,27 +87,25 @@ def action_extensions(base_actions, project_path):
|
||||
"""
|
||||
Run idf_monitor.py to watch build output
|
||||
"""
|
||||
|
||||
desc_path = os.path.join(args.build_dir, 'project_description.json')
|
||||
if not os.path.exists(desc_path):
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
with open(desc_path, 'r') as f:
|
||||
project_desc = json.load(f)
|
||||
|
||||
project_desc = _get_project_desc(ctx, args)
|
||||
elf_file = os.path.join(args.build_dir, project_desc['app_elf'])
|
||||
if not os.path.exists(elf_file):
|
||||
raise FatalError("ELF file '%s' not found. You need to build & flash the project before running 'monitor', "
|
||||
'and the binary on the device must match the one in the build directory exactly. '
|
||||
"Try '%s flash monitor'." % (elf_file, ctx.info_name), ctx)
|
||||
|
||||
idf_monitor = os.path.join(os.environ['IDF_PATH'], 'tools/idf_monitor.py')
|
||||
monitor_args = [PYTHON, idf_monitor]
|
||||
esp_port = args.port or _get_default_serial_port(args)
|
||||
monitor_args += ['-p', esp_port]
|
||||
|
||||
if not monitor_baud:
|
||||
monitor_baud = os.getenv('IDF_MONITOR_BAUD') or os.getenv('MONITORBAUD') or project_desc['monitor_baud']
|
||||
if project_desc['target'] != 'linux':
|
||||
esp_port = args.port or _get_default_serial_port(args)
|
||||
monitor_args += ['-p', esp_port]
|
||||
|
||||
if not monitor_baud:
|
||||
monitor_baud = os.getenv('IDF_MONITOR_BAUD') or os.getenv('MONITORBAUD') or project_desc['monitor_baud']
|
||||
|
||||
monitor_args += ['-b', monitor_baud]
|
||||
|
||||
monitor_args += ['-b', monitor_baud]
|
||||
monitor_args += ['--toolchain-prefix', project_desc['monitor_toolprefix']]
|
||||
|
||||
coredump_decode = get_sdkconfig_value(project_desc['config_file'], 'CONFIG_ESP_COREDUMP_DECODE')
|
||||
@@ -137,8 +147,13 @@ def action_extensions(base_actions, project_path):
|
||||
Run esptool to flash the entire project, from an argfile generated by the build system
|
||||
"""
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
project_desc = _get_project_desc(ctx, args)
|
||||
if project_desc['target'] == 'linux':
|
||||
yellow_print('skipping flash since running on linux...')
|
||||
return
|
||||
|
||||
esp_port = args.port or _get_default_serial_port(args)
|
||||
run_target(action, args, {'ESPBAUD': str(args.baud),'ESPPORT': esp_port})
|
||||
run_target(action, args, {'ESPBAUD': str(args.baud), 'ESPPORT': esp_port})
|
||||
|
||||
def erase_flash(action, ctx, args):
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
|
||||
Reference in New Issue
Block a user