diff --git a/scripts/west_commands/runners/esp32.py b/scripts/west_commands/runners/esp32.py index e2f7a3c3c7e..f483fbf2954 100644 --- a/scripts/west_commands/runners/esp32.py +++ b/scripts/west_commands/runners/esp32.py @@ -16,12 +16,13 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): '''Runner front-end for espidf.''' def __init__(self, cfg, device, boot_address, part_table_address, - app_address, baud=921600, flash_size='detect', + app_address, erase=False, baud=921600, flash_size='detect', flash_freq='40m', flash_mode='dio', espidf='espidf', bootloader_bin=None, partition_table_bin=None): super().__init__(cfg) self.elf = cfg.elf_file self.app_bin = cfg.bin_file + self.erase = bool(erase) self.device = device self.boot_address = boot_address self.part_table_address = part_table_address @@ -40,7 +41,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): @classmethod def capabilities(cls): - return RunnerCaps(commands={'flash'}) + return RunnerCaps(commands={'flash'}, erase=True) @classmethod def do_add_parser(cls, parser): @@ -84,16 +85,22 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): return Esp32BinaryRunner( cfg, args.esp_device, boot_address=args.esp_boot_address, part_table_address=args.esp_partition_table_address, - app_address=args.esp_app_address, baud=args.esp_baud_rate, - flash_size=args.esp_flash_size, flash_freq=args.esp_flash_freq, - flash_mode=args.esp_flash_mode, espidf=espidf, - bootloader_bin=args.esp_flash_bootloader, + app_address=args.esp_app_address, erase=args.erase, + baud=args.esp_baud_rate, flash_size=args.esp_flash_size, + flash_freq=args.esp_flash_freq, flash_mode=args.esp_flash_mode, + espidf=espidf, bootloader_bin=args.esp_flash_bootloader, partition_table_bin=args.esp_flash_partition_table) def do_run(self, command, **kwargs): self.require(self.espidf) - cmd_flash = [self.espidf, '--chip', 'auto'] + # Add Python interpreter + cmd_flash = [sys.executable, self.espidf, '--chip', 'auto'] + + if self.erase is True: + cmd_erase = cmd_flash + ['erase_flash'] + self.check_call(cmd_erase) + if self.device is not None: cmd_flash.extend(['--port', self.device]) cmd_flash.extend(['--baud', self.baud]) @@ -103,10 +110,6 @@ class Esp32BinaryRunner(ZephyrBinaryRunner): cmd_flash.extend(['--flash_freq', self.flash_freq]) cmd_flash.extend(['--flash_size', self.flash_size]) - # Execute Python interpreter if calling a Python script - if self.espidf.lower().endswith(".py") and sys.executable: - cmd_flash.insert(0, sys.executable) - if self.bootloader_bin: cmd_flash.extend([self.boot_address, self.bootloader_bin]) cmd_flash.extend([self.part_table_address, self.partition_table_bin])