mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
parttool, otatool: accept esptool args
This commit is contained in:
parent
8be982f60c
commit
2360d882d9
@ -50,8 +50,11 @@ class OtatoolTarget():
|
|||||||
|
|
||||||
OTADATA_PARTITION = PartitionType("data", "ota")
|
OTADATA_PARTITION = PartitionType("data", "ota")
|
||||||
|
|
||||||
def __init__(self, port=None, partition_table_offset=PARTITION_TABLE_OFFSET, partition_table_file=None, spi_flash_sec_size=SPI_FLASH_SEC_SIZE):
|
def __init__(self, port=None, partition_table_offset=PARTITION_TABLE_OFFSET, partition_table_file=None,
|
||||||
self.target = ParttoolTarget(port, partition_table_offset, partition_table_file)
|
spi_flash_sec_size=SPI_FLASH_SEC_SIZE, esptool_args=[], esptool_write_args=[],
|
||||||
|
esptool_read_args=[], esptool_erase_args=[]):
|
||||||
|
self.target = ParttoolTarget(port, partition_table_offset, partition_table_file, esptool_args,
|
||||||
|
esptool_write_args, esptool_read_args, esptool_erase_args)
|
||||||
self.spi_flash_sec_size = spi_flash_sec_size
|
self.spi_flash_sec_size = spi_flash_sec_size
|
||||||
|
|
||||||
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
||||||
@ -214,11 +217,11 @@ class OtatoolTarget():
|
|||||||
def _read_otadata(target):
|
def _read_otadata(target):
|
||||||
target._check_otadata_partition()
|
target._check_otadata_partition()
|
||||||
|
|
||||||
otadata_info = target._get_otadata_info(target.otadata)
|
otadata_info = target._get_otadata_info()
|
||||||
|
|
||||||
print("\t\t{:11}\t{:8s}|\t{:8s}\t{:8s}".format("OTA_SEQ", "CRC", "OTA_SEQ", "CRC"))
|
print(" {:8s} \t {:8s} | \t {:8s} \t {:8s}".format("OTA_SEQ", "CRC", "OTA_SEQ", "CRC"))
|
||||||
print("Firmware: 0x{:8x} \t 0x{:8x} |\t0x{:8x} \t 0x{:8x}".format(otadata_info[0].seq, otadata_info[0].crc,
|
print("Firmware: 0x{:8x} \t0x{:8x} | \t0x{:8x} \t 0x{:8x}".format(otadata_info[0].seq, otadata_info[0].crc,
|
||||||
otadata_info[1].seq, otadata_info[1].crc))
|
otadata_info[1].seq, otadata_info[1].crc))
|
||||||
|
|
||||||
|
|
||||||
def _erase_otadata(target):
|
def _erase_otadata(target):
|
||||||
@ -251,6 +254,10 @@ def main():
|
|||||||
parser = argparse.ArgumentParser("ESP-IDF OTA Partitions Tool")
|
parser = argparse.ArgumentParser("ESP-IDF OTA Partitions Tool")
|
||||||
|
|
||||||
parser.add_argument("--quiet", "-q", help="suppress stderr messages", action="store_true")
|
parser.add_argument("--quiet", "-q", help="suppress stderr messages", action="store_true")
|
||||||
|
parser.add_argument("--esptool-args", help="additional main arguments for esptool", nargs="+")
|
||||||
|
parser.add_argument("--esptool-write-args", help="additional subcommand arguments for esptool write_flash", nargs="+")
|
||||||
|
parser.add_argument("--esptool-read-args", help="additional subcommand arguments for esptool read_flash", nargs="+")
|
||||||
|
parser.add_argument("--esptool-erase-args", help="additional subcommand arguments for esptool erase_region", nargs="+")
|
||||||
|
|
||||||
# There are two possible sources for the partition table: a device attached to the host
|
# There are two possible sources for the partition table: a device attached to the host
|
||||||
# or a partition table CSV/binary file. These sources are mutually exclusive.
|
# or a partition table CSV/binary file. These sources are mutually exclusive.
|
||||||
@ -312,6 +319,18 @@ def main():
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if args.esptool_args:
|
||||||
|
target_args["esptool_args"] = args.esptool_args
|
||||||
|
|
||||||
|
if args.esptool_write_args:
|
||||||
|
target_args["esptool_write_args"] = args.esptool_write_args
|
||||||
|
|
||||||
|
if args.esptool_read_args:
|
||||||
|
target_args["esptool_read_args"] = args.esptool_read_args
|
||||||
|
|
||||||
|
if args.esptool_erase_args:
|
||||||
|
target_args["esptool_erase_args"] = args.esptool_erase_args
|
||||||
|
|
||||||
target = OtatoolTarget(**target_args)
|
target = OtatoolTarget(**target_args)
|
||||||
|
|
||||||
# Create the operation table and execute the operation
|
# Create the operation table and execute the operation
|
||||||
|
@ -22,6 +22,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import re
|
||||||
import gen_esp32part as gen
|
import gen_esp32part as gen
|
||||||
|
|
||||||
|
|
||||||
@ -66,11 +67,30 @@ PARTITION_BOOT_DEFAULT = _PartitionId()
|
|||||||
|
|
||||||
class ParttoolTarget():
|
class ParttoolTarget():
|
||||||
|
|
||||||
def __init__(self, port=None, partition_table_offset=PARTITION_TABLE_OFFSET, partition_table_file=None):
|
def __init__(self, port=None, partition_table_offset=PARTITION_TABLE_OFFSET, partition_table_file=None,
|
||||||
|
esptool_args=[], esptool_write_args=[], esptool_read_args=[], esptool_erase_args=[]):
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
gen.offset_part_table = partition_table_offset
|
gen.offset_part_table = partition_table_offset
|
||||||
|
|
||||||
|
def parse_esptool_args(esptool_args):
|
||||||
|
results = list()
|
||||||
|
for arg in esptool_args:
|
||||||
|
pattern = re.compile(r"(.+)=(.+)")
|
||||||
|
result = pattern.match(arg)
|
||||||
|
try:
|
||||||
|
key = result.group(1)
|
||||||
|
value = result.group(2)
|
||||||
|
results.extend(["--" + key, value])
|
||||||
|
except AttributeError:
|
||||||
|
results.extend(["--" + arg])
|
||||||
|
return results
|
||||||
|
|
||||||
|
self.esptool_args = parse_esptool_args(esptool_args)
|
||||||
|
self.esptool_write_args = parse_esptool_args(esptool_write_args)
|
||||||
|
self.esptool_read_args = parse_esptool_args(esptool_read_args)
|
||||||
|
self.esptool_erase_args = parse_esptool_args(esptool_erase_args)
|
||||||
|
|
||||||
if partition_table_file:
|
if partition_table_file:
|
||||||
try:
|
try:
|
||||||
with open(partition_table_file, "rb") as f:
|
with open(partition_table_file, "rb") as f:
|
||||||
@ -93,7 +113,7 @@ class ParttoolTarget():
|
|||||||
self.partition_table = partition_table
|
self.partition_table = partition_table
|
||||||
|
|
||||||
def _call_esptool(self, args, out=None):
|
def _call_esptool(self, args, out=None):
|
||||||
esptool_args = [sys.executable, ESPTOOL_PY]
|
esptool_args = [sys.executable, ESPTOOL_PY] + self.esptool_args
|
||||||
|
|
||||||
if self.port:
|
if self.port:
|
||||||
esptool_args += ["--port", self.port]
|
esptool_args += ["--port", self.port]
|
||||||
@ -124,11 +144,11 @@ class ParttoolTarget():
|
|||||||
|
|
||||||
def erase_partition(self, partition_id):
|
def erase_partition(self, partition_id):
|
||||||
partition = self.get_partition_info(partition_id)
|
partition = self.get_partition_info(partition_id)
|
||||||
self._call_esptool(["erase_region", str(partition.offset), str(partition.size)])
|
self._call_esptool(["erase_region", str(partition.offset), str(partition.size)] + self.esptool_erase_args)
|
||||||
|
|
||||||
def read_partition(self, partition_id, output):
|
def read_partition(self, partition_id, output):
|
||||||
partition = self.get_partition_info(partition_id)
|
partition = self.get_partition_info(partition_id)
|
||||||
self._call_esptool(["read_flash", str(partition.offset), str(partition.size), output])
|
self._call_esptool(["read_flash", str(partition.offset), str(partition.size), output] + self.esptool_read_args)
|
||||||
|
|
||||||
def write_partition(self, partition_id, input):
|
def write_partition(self, partition_id, input):
|
||||||
self.erase_partition(partition_id)
|
self.erase_partition(partition_id)
|
||||||
@ -141,7 +161,7 @@ class ParttoolTarget():
|
|||||||
if content_len > partition.size:
|
if content_len > partition.size:
|
||||||
raise Exception("Input file size exceeds partition size")
|
raise Exception("Input file size exceeds partition size")
|
||||||
|
|
||||||
self._call_esptool(["write_flash", str(partition.offset), input])
|
self._call_esptool(["write_flash", str(partition.offset), input] + self.esptool_write_args)
|
||||||
|
|
||||||
|
|
||||||
def _write_partition(target, partition_id, input):
|
def _write_partition(target, partition_id, input):
|
||||||
@ -191,6 +211,10 @@ def main():
|
|||||||
parser = argparse.ArgumentParser("ESP-IDF Partitions Tool")
|
parser = argparse.ArgumentParser("ESP-IDF Partitions Tool")
|
||||||
|
|
||||||
parser.add_argument("--quiet", "-q", help="suppress stderr messages", action="store_true")
|
parser.add_argument("--quiet", "-q", help="suppress stderr messages", action="store_true")
|
||||||
|
parser.add_argument("--esptool-args", help="additional main arguments for esptool", nargs="+")
|
||||||
|
parser.add_argument("--esptool-write-args", help="additional subcommand arguments when writing to flash", nargs="+")
|
||||||
|
parser.add_argument("--esptool-read-args", help="additional subcommand arguments when reading flash", nargs="+")
|
||||||
|
parser.add_argument("--esptool-erase-args", help="additional subcommand arguments when erasing regions of flash", nargs="+")
|
||||||
|
|
||||||
# By default the device attached to the specified port is queried for the partition table. If a partition table file
|
# By default the device attached to the specified port is queried for the partition table. If a partition table file
|
||||||
# is specified, that is used instead.
|
# is specified, that is used instead.
|
||||||
@ -264,6 +288,18 @@ def main():
|
|||||||
if args.partition_table_offset:
|
if args.partition_table_offset:
|
||||||
target_args["partition_table_offset"] = int(args.partition_table_offset, 0)
|
target_args["partition_table_offset"] = int(args.partition_table_offset, 0)
|
||||||
|
|
||||||
|
if args.esptool_args:
|
||||||
|
target_args["esptool_args"] = args.esptool_args
|
||||||
|
|
||||||
|
if args.esptool_write_args:
|
||||||
|
target_args["esptool_write_args"] = args.esptool_write_args
|
||||||
|
|
||||||
|
if args.esptool_read_args:
|
||||||
|
target_args["esptool_read_args"] = args.esptool_read_args
|
||||||
|
|
||||||
|
if args.esptool_erase_args:
|
||||||
|
target_args["esptool_erase_args"] = args.esptool_erase_args
|
||||||
|
|
||||||
target = ParttoolTarget(**target_args)
|
target = ParttoolTarget(**target_args)
|
||||||
|
|
||||||
# Create the operation table and execute the operation
|
# Create the operation table and execute the operation
|
||||||
|
Loading…
Reference in New Issue
Block a user