tizen: sd_fusing.py: Allow updating a & b partitions in one invocation 39/310339/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 25 Apr 2024 20:47:53 +0000 (22:47 +0200)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 29 Apr 2024 09:08:39 +0000 (09:08 +0000)
This commit adds '--update ab' option, allowing both partition sets to
be updated at once.

Change-Id: I007392f0978753589a05d9e8586877c463ac1798
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
scripts/tizen/sd_fusing.py

index 7de9cae..b89c63a 100755 (executable)
@@ -15,7 +15,7 @@ import sys
 import tarfile
 import tempfile
 
-__version__ = "1.0.2"
+__version__ = "1.0.3"
 
 Format = False
 Device = ""
@@ -162,13 +162,13 @@ class SdFusingTarget:
                     binaries[f] = i + 1
         return binaries
 
-    def get_partition_index(self, binary):
+    def get_partition_index_list(self, binary):
         if hasattr(self, 'update'):
             logging.error("You have requested to update the {} partition set. "
                           "This target does not support A/B partition sets."
                           .format(self.update.upper()))
             sys.exit(1)
-        return self.binaries.get(binary, None)
+        return [self.binaries.get(binary, None)]
 
     params = ()
     def initialize_parameters(self):
@@ -179,10 +179,13 @@ class SdFusingTargetAB(SdFusingTarget):
         super().__init__(device, ltype)
         self.binaries_b = self._get_binaries('binaries_b')
 
-    def get_partition_index(self, binary):
+    def get_partition_index_list(self, binary):
         if self.update == 'b':
-            return self.binaries_b.get(binary, None)
-        return self.binaries.get(binary, None)
+            return [self.binaries_b.get(binary, None)]
+        elif self.update == 'ab':
+            return [self.binaries.get(binary, None), self.binaries_b.get(binary, None)]
+
+        return [self.binaries.get(binary, None)]
 
 class InitParams:
     def initialize_parameters(self):
@@ -984,30 +987,34 @@ def get_device_kname(device):
     return None
 
 def do_fuse_file(f, name, target):
-    idx = target.get_partition_index(name)
-    if idx is None:
+    indexes = target.get_partition_index_list(name)
+    if len(indexes) == 0:
         logging.info(f"No partition defined for {name}, skipping.")
         return
-    pdevice = "/dev/" + get_partition_device(Device, idx)
-    argv = ['dd', 'bs=4M',
-            'oflag=direct',
-            'iflag=fullblock',
-            'conv=nocreat',
-            'status=progress',
-            f"of={pdevice}"]
-    logging.debug(" ".join(argv))
-    proc_dd = subprocess.Popen(argv,
-                               bufsize=(4 << 20),
-                               stdin=subprocess.PIPE,
-                               stdout=None, stderr=None)
-    logging.notice(f"Writing {name} to {pdevice}")
-    buf = f.read(4 << 20)
-    while len(buf) > 0:
-        proc_dd.stdin.write(buf)
+    for idx in indexes:
+        if idx is None:
+            logging.info(f"No partition defined for {name}, skipping.")
+            continue
+        pdevice = "/dev/" + get_partition_device(Device, idx)
+        argv = ['dd', 'bs=4M',
+                'oflag=direct',
+                'iflag=fullblock',
+                'conv=nocreat',
+                'status=progress',
+                f"of={pdevice}"]
+        logging.debug(" ".join(argv))
+        proc_dd = subprocess.Popen(argv,
+                                   bufsize=(4 << 20),
+                                   stdin=subprocess.PIPE,
+                                   stdout=None, stderr=None)
+        logging.notice(f"Writing {name} to {pdevice}")
         buf = f.read(4 << 20)
-    proc_dd.communicate()
-    logging.info("Done")
-    #TODO: verification
+        while len(buf) > 0:
+            proc_dd.stdin.write(buf)
+            buf = f.read(4 << 20)
+        proc_dd.communicate()
+        logging.info("Done")
+        #TODO: verification
 
 #TODO: functions with the target argument should probably
 #      be part of some class
@@ -1139,8 +1146,8 @@ if __name__ == '__main__':
     parser.add_argument("-t", "--target", required=True,
                         help="Target device model. Use `--target list`"
                         " to show supported devices.")
-    parser.add_argument("--update", choices=['a', 'b'], default=None,
-                        help="Choose partition set to update: a or b.")
+    parser.add_argument("--update", choices=['a', 'b', 'ab'], default=None,
+                        help="Choose partition set to update: a or b or ab.")
     parser.add_argument("--version", action="version",
                         version=f"%(prog)s {__version__}")
     parser.add_argument("--YES", action="store_true",