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):
- self.target = ParttoolTarget(port, partition_table_offset, partition_table_file)
+ def __init__(self, port=None, partition_table_offset=PARTITION_TABLE_OFFSET, partition_table_file=None,
+ 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
temp_file = tempfile.NamedTemporaryFile(delete=False)
def _read_otadata(target):
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("Firmware: 0x{:8x} \t 0x{:8x} |\t0x{:8x} \t 0x{:8x}".format(otadata_info[0].seq, otadata_info[0].crc,
- otadata_info[1].seq, otadata_info[1].crc))
+ print(" {:8s} \t {:8s} | \t {:8s} \t {:8s}".format("OTA_SEQ", "CRC", "OTA_SEQ", "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))
def _erase_otadata(target):
parser = argparse.ArgumentParser("ESP-IDF OTA Partitions Tool")
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
# or a partition table CSV/binary file. These sources are mutually exclusive.
except AttributeError:
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)
# Create the operation table and execute the operation
import sys
import subprocess
import tempfile
+import re
import gen_esp32part as gen
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
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:
try:
with open(partition_table_file, "rb") as f:
self.partition_table = partition_table
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:
esptool_args += ["--port", self.port]
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._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._call_esptool(["read_flash", str(partition.offset), str(partition.size), output] + self.esptool_read_args)
def write_partition(self, partition_id, input):
self.erase_partition(partition_id)
if content_len > 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):
parser = argparse.ArgumentParser("ESP-IDF Partitions Tool")
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
# is specified, that is used instead.
if args.partition_table_offset:
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)
# Create the operation table and execute the operation