]> granicus.if.org Git - esp-idf/commitdiff
parttool, otatool: accept esptool args
authorRenz Christian Bagaporo <renz@espressif.com>
Thu, 28 Mar 2019 06:07:53 +0000 (14:07 +0800)
committerbot <bot@espressif.com>
Fri, 5 Jul 2019 02:26:00 +0000 (02:26 +0000)
components/app_update/otatool.py
components/partition_table/parttool.py

index 2cfecde18b2e56ad695a5b39d07bc2df7711dcb9..9bc392c39e3cb1f4bc73e6348e26c907443be1ac 100755 (executable)
@@ -50,8 +50,11 @@ class OtatoolTarget():
 
     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)
@@ -214,11 +217,11 @@ class OtatoolTarget():
 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):
@@ -251,6 +254,10 @@ def main():
     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.
@@ -312,6 +319,18 @@ def main():
     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
index f2c005a10c1f41fa49ff6853d7ef8c126979ec0c..f82b90c3fa560fe25978ff1ca60e9cd9fbb7cf73 100755 (executable)
@@ -22,6 +22,7 @@ import os
 import sys
 import subprocess
 import tempfile
+import re
 import gen_esp32part as gen
 
 
@@ -66,11 +67,30 @@ PARTITION_BOOT_DEFAULT = _PartitionId()
 
 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:
@@ -93,7 +113,7 @@ class ParttoolTarget():
         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]
@@ -124,11 +144,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._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)
@@ -141,7 +161,7 @@ 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._call_esptool(["write_flash", str(partition.offset), input] + self.esptool_write_args)
 
 
 def _write_partition(target, partition_id, input):
@@ -191,6 +211,10 @@ def main():
     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.
@@ -264,6 +288,18 @@ def main():
     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