Skip to content

Commit

Permalink
fix: read_flash
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Dec 19, 2023
1 parent 434f43a commit c6b2a96
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ def _kwargs_extend_list(_items):
os.chdir(self.app.binary_path)

_kwargs_extend_list(addition_kwargs.items())

if os.path.isfile('flash_args'):
_args.extend(['write_flash', '@flash_args'])
else:
if os.path.isfile('flasher_args.json'):
flash_data = json.load(open('flasher_args.json'))
_args.append('write_flash')
for item in flash_data['flash_files'].items():
_args.extend(item)
_args.extend(flash_data['write_flash_args'])
Expand All @@ -180,6 +180,8 @@ def _kwargs_extend_list(_items):
_args.extend((address, nvs_file))

_kwargs_extend_list(write_flash_args.items())

_args = map(str, _args)
esptool.main(['-b', str(self.esptool_baud), *_args], esp=self.esp)

os.chdir(current_wk)
Expand Down Expand Up @@ -218,15 +220,12 @@ def dump_flash(
else:
raise ValueError('You must specify "partition" or ("address" and "size") to dump flash')

content = self.stub.read_flash(_addr, _size)
if output:
if isinstance(output, str):
os.makedirs(os.path.dirname(output), exist_ok=True)
with open(output, 'wb') as f:
f.write(content)
else:
output.write(content)
esptool.main(['read_flash', str(_addr), str(_size), str(output)], esp=self.esp)
else:
output = 'read_flash.tmp'
esptool.main(['read_flash', str(_addr), str(_size), output], esp=self.esp)
content = open(output, 'rb').read()
return content

@EspSerial.use_esptool()
Expand Down

0 comments on commit c6b2a96

Please sign in to comment.