From 862fa815ff1ff79481ef113a9af7d9092e6f3583 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 3 Apr 2020 18:50:05 +0800 Subject: [PATCH 1/2] esptool: add quotes to allow complicated serial port path Especially for Windows COM format: \\\.\COMx, introduced in b00cea250f71c3d1167eb10f570e3abba6c19186 --- components/esptool_py/Makefile.projbuild | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/esptool_py/Makefile.projbuild b/components/esptool_py/Makefile.projbuild index 261938ff1a..07dab73f55 100644 --- a/components/esptool_py/Makefile.projbuild +++ b/components/esptool_py/Makefile.projbuild @@ -15,7 +15,7 @@ PYTHON ?= $(call dequote,$(CONFIG_SDK_PYTHON)) # ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32 -ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER) +ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port '$(ESPPORT)' --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER) # Supporting esptool command line tools ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py @@ -89,7 +89,7 @@ endif ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT encrypted-flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies $(eval MONITOR_OPTS += --encrypted) - @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..." + @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..." ifdef CONFIG_SECURE_BOOT @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)" endif @@ -101,20 +101,20 @@ encrypted-flash: endif flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies - @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..." + @echo "Flashing binaries to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..." ifdef CONFIG_SECURE_BOOT @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)" endif $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS) app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies - @echo "Flashing app to serial port $(ESPPORT), offset $(APP_OFFSET)..." + @echo "Flashing app to serial port '$(ESPPORT)', offset $(APP_OFFSET)..." $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN) ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT encrypted-app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) partition_table_get_info | check_python_dependencies $(eval MONITOR_OPTS += --encrypted) - @echo "Flashing encrypted app binary to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..." + @echo "Flashing encrypted app binary to serial port '$(ESPPORT)' (app at offset $(APP_OFFSET))..." $(ESPTOOLPY_WRITE_FLASH_ENCRYPT) $(APP_OFFSET) $(APP_BIN) else encrypted-app-flash: @@ -144,7 +144,7 @@ endif # miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm' # is to allow for the $(PYTHON) variable overriding the python path. simple_monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies - $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw $(ESPPORT) $(MONITORBAUD) + $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw '$(ESPPORT)' $(MONITORBAUD) PRINT_FILTER ?= @@ -154,7 +154,7 @@ ifneq ("$(MONITOR_CORE_DUMP_DECODE)","") MONITOR_CORE_DUMP_DECODE_ARG = --decode-coredumps $(MONITOR_CORE_DUMP_DECODE) endif -MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)" $(MONITOR_CORE_DUMP_DECODE_ARG) +MONITOR_OPTS := --baud $(MONITORBAUD) --port '$(ESPPORT)' --toolchain-prefix $(CONFIG_SDK_TOOLPREFIX) --make "$(MAKE)" --print_filter "$(PRINT_FILTER)" $(MONITOR_CORE_DUMP_DECODE_ARG) monitor: $(call prereq_if_explicit,%flash) | check_python_dependencies $(summary) MONITOR From 8aafb6b5133c341e24a3e27c57eb0ffedbffc0ba Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 7 Apr 2020 01:44:23 +0800 Subject: [PATCH 2/2] idf_monitor: support to re-flash with the using port This commit make idf_monitor overwrite the ESPPORT environment variable with the port it's using, and re-run make with the modified environment variable. In this way, the make invoked will inherit the idf_monitor's port. Closes https://github.com/espressif/esp-idf/issues/4591 --- tools/idf_monitor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/idf_monitor.py b/tools/idf_monitor.py index ce55327bbd..19c36f1315 100755 --- a/tools/idf_monitor.py +++ b/tools/idf_monitor.py @@ -649,7 +649,7 @@ class Monitor(object): else: popen_args = [self.make, target] yellow_print("Running %s..." % " ".join(popen_args)) - p = subprocess.Popen(popen_args) + p = subprocess.Popen(popen_args, env=os.environ) try: p.wait() except KeyboardInterrupt: @@ -967,6 +967,13 @@ def main(): except KeyError: pass # not running a make jobserver + # Pass the actual used port to callee of idf_monitor (e.g. make) through `ESPPORT` environment + # variable + # To make sure the key as well as the value are str type, by the requirements of subprocess + espport_key = str("ESPPORT") + espport_val = str(args.port) + os.environ.update({espport_key: espport_val}) + monitor = Monitor(serial_instance, args.elf_file.name, args.print_filter, args.make, args.encrypted, args.toolchain_prefix, args.eol, args.decode_coredumps)