Skip to content

Commit

Permalink
fix: erase_region with esptool.main
Browse files Browse the repository at this point in the history
  • Loading branch information
horw authored and hfudev committed Jan 15, 2024
1 parent ce045de commit c1ebd5b
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,31 +136,23 @@ def flash(self) -> None:

_args.append('write_flash')

nvs_file = None
if self.erase_nvs:
address = self.app.partition_table['nvs']['offset']
size = self.app.partition_table['nvs']['size']
nvs_file = tempfile.NamedTemporaryFile(delete=False)
nvs_file.write(b'\xff' * size)
if not isinstance(address, int):
address = int(address, 0)
_args.append(str(address))
_args.append(nvs_file.name)
esptool.main(
[
'erase_region',
str(self.app.partition_table['nvs']['offset']),
str(self.app.partition_table['nvs']['size']),
],
esp=self.esp,
)
self.esp.connect()

for k, v in self.app.flash_args['flash_files'].items():
_args.append(str(k))
_args.append(os.path.join(self.app.binary_path, str(v)))
_args.extend(self.app.flash_args['write_flash_args'])

try:
esptool.main(_args, esp=self.esp)
finally:
if nvs_file:
nvs_file.close()
try:
os.remove(nvs_file.name)
except OSError:
pass
esptool.main(_args, esp=self.esp)

if self._meta:
self._meta.set_port_app_cache(self.port, self.app)
Expand Down

0 comments on commit c1ebd5b

Please sign in to comment.