Skip to content

Commit

Permalink
fix: make the force flag dependent on the config
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Feb 7, 2024
1 parent 8707fa8 commit 53022b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pytest-embedded-arduino/pytest_embedded_arduino/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 53022b9

Please sign in to comment.