diff --git a/pytest-embedded-arduino/pytest_embedded_arduino/serial.py b/pytest-embedded-arduino/pytest_embedded_arduino/serial.py index 9dacaae0..a7f71989 100644 --- a/pytest-embedded-arduino/pytest_embedded_arduino/serial.py +++ b/pytest-embedded-arduino/pytest_embedded_arduino/serial.py @@ -53,7 +53,7 @@ def flash(self) -> None: try: esptool.main( - ['--chip', self.app.target, 'write_flash', *flash_files, *flash_settings, '--force'], + ['--chip', self.app.target, 'write_flash', *flash_files, *flash_settings], esp=self.esp, ) except Exception: diff --git a/pytest-embedded-idf/pytest_embedded_idf/serial.py b/pytest-embedded-idf/pytest_embedded_idf/serial.py index 22dbfefb..e1f59396 100644 --- a/pytest-embedded-idf/pytest_embedded_idf/serial.py +++ b/pytest-embedded-idf/pytest_embedded_idf/serial.py @@ -108,6 +108,12 @@ def load_ram(self) -> None: esp=self.esp, ) + def _force_flag(self): + config = self.app.sdkconfig + if any((config.get('CONFIG_SECURE_FLASH_ENC_ENABLED', False), config.get('CONFIG_SECURE_BOOT', False))): + return ['--force'] + return [] + @EspSerial.use_esptool() def flash(self) -> None: """ @@ -171,8 +177,8 @@ def flash(self) -> None: _args.extend(encrypt_files) _args.extend(self.app.flash_args['write_flash_args']) + _args.extend(self._force_flag()) - _args.append('--force') esptool.main(_args, esp=self.esp) if self._meta: @@ -232,7 +238,7 @@ def erase_partition(self, partition_name: str) -> None: address = self.app.partition_table[partition_name]['offset'] size = self.app.partition_table[partition_name]['size'] logging.info(f'Erasing the partition "{partition_name}" of size {size} at {address}') - esptool.main(['erase_region', str(address), str(size), '--force'], esp=self.esp) + esptool.main(['erase_region', str(address), str(size), *self._force_flag()], esp=self.esp) else: raise ValueError(f'partition name "{partition_name}" not found in app partition table')