feat: Update esptool to v5

This commit is contained in:
Peter Dragun
2025-08-11 16:11:49 +02:00
parent 053fb47e78
commit e3198fff3c
129 changed files with 1237 additions and 1318 deletions

View File

@@ -17,7 +17,6 @@ import gen_esp32part as gen
__version__ = '2.2'
COMPONENTS_PATH = os.path.expandvars(os.path.join('$IDF_PATH', 'components'))
ESPTOOL_PY = os.path.join(COMPONENTS_PATH, 'esptool_py', 'esptool', 'esptool.py')
PARTITION_TABLE_OFFSET = 0x8000
@@ -100,7 +99,7 @@ class ParttoolTarget:
try:
self._call_esptool(
['read_flash', str(partition_table_offset), str(gen.MAX_PARTITION_LENGTH), temp_file.name]
['read-flash', str(partition_table_offset), str(gen.MAX_PARTITION_LENGTH), temp_file.name]
)
with open(temp_file.name, 'rb') as f:
partition_table = gen.PartitionTable.from_binary(f.read())
@@ -113,7 +112,7 @@ class ParttoolTarget:
# otherwise set `out` to file descriptor
# beware that the method does not close the file descriptor
def _call_esptool(self, args, out=None):
esptool_args = [sys.executable, ESPTOOL_PY] + self.esptool_args
esptool_args = [sys.executable, '-m', 'esptool'] + self.esptool_args
if self.port:
esptool_args += ['--port', self.port]
@@ -123,7 +122,7 @@ class ParttoolTarget:
esptool_args += args
print('Running %s...' % (' '.join(esptool_args)))
print(f'Running {" ".join(esptool_args)}...')
try:
subprocess.check_call(esptool_args, stdout=out, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
@@ -140,7 +139,7 @@ class ParttoolTarget:
if not partition_id.part_list:
partition = partition[0]
else: # default boot partition
search = ['factory'] + ['ota_{}'.format(d) for d in range(16)]
search = ['factory'] + [f'ota_{d}' for d in range(16)]
for subtype in search:
partition = next(self.partition_table.find_by_type('app', subtype), None)
if partition:
@@ -153,11 +152,11 @@ class ParttoolTarget:
def erase_partition(self, partition_id):
partition = self.get_partition_info(partition_id)
self._call_esptool(['erase_region', str(partition.offset), str(partition.size)] + self.esptool_erase_args)
self._call_esptool(['erase-region', str(partition.offset), str(partition.size)] + self.esptool_erase_args)
def read_partition(self, partition_id, output):
partition = self.get_partition_info(partition_id)
self._call_esptool(['read_flash', str(partition.offset), str(partition.size), output] + self.esptool_read_args)
self._call_esptool(['read-flash', str(partition.offset), str(partition.size), output] + self.esptool_read_args)
def write_partition(self, partition_id, input, ignore_readonly=False): # noqa: A002
partition = self.get_partition_info(partition_id)
@@ -173,29 +172,27 @@ class ParttoolTarget:
if content_len > partition.size:
raise Exception('Input file size exceeds partition size')
self._call_esptool(['write_flash', str(partition.offset), input] + self.esptool_write_args)
self._call_esptool(['write-flash', str(partition.offset), input] + self.esptool_write_args)
def _write_partition(target, partition_id, input, ignore_readonly=False): # noqa: A002
target.write_partition(partition_id, input, ignore_readonly)
partition = target.get_partition_info(partition_id)
status("Written contents of file '{}' at offset 0x{:x}".format(input, partition.offset))
status(f"Written contents of file '{input}' at offset 0x{partition.offset:x}")
def _read_partition(target, partition_id, output):
target.read_partition(partition_id, output)
partition = target.get_partition_info(partition_id)
status(
"Read partition '{}' contents from device at offset 0x{:x} to file '{}'".format(
partition.name, partition.offset, output
)
f"Read partition '{partition.name}' contents from device at offset 0x{partition.offset:x} to file '{output}'"
)
def _erase_partition(target, partition_id):
target.erase_partition(partition_id)
partition = target.get_partition_info(partition_id)
status("Erased partition '{}' at offset 0x{:x}".format(partition.name, partition.offset))
status(f"Erased partition '{partition.name}' at offset 0x{partition.offset:x}")
def _get_partition_info(target, partition_id, info):
@@ -211,18 +208,18 @@ def _get_partition_info(target, partition_id, info):
try:
for p in partitions:
info_dict = {
'name': '{}'.format(p.name),
'type': '{}'.format(p.type),
'subtype': '{}'.format(p.subtype),
'offset': '0x{:x}'.format(p.offset),
'size': '0x{:x}'.format(p.size),
'encrypted': '{}'.format(p.encrypted),
'readonly': '{}'.format(p.readonly),
'name': f'{p.name}',
'type': f'{p.type}',
'subtype': f'{p.subtype}',
'offset': f'0x{p.offset:x}',
'size': f'0x{p.size:x}',
'encrypted': f'{p.encrypted}',
'readonly': f'{p.readonly}',
}
for i in info:
infos += [info_dict[i]]
except KeyError:
raise RuntimeError('Request for unknown partition info {}'.format(i))
raise RuntimeError(f'Request for unknown partition info {i}')
print(' '.join(infos))