scripts: add --partition-size feat to sd_fusing.py 87/300287/1
authorLeonid <l.sawin@samsung.com>
Fri, 13 Oct 2023 07:18:40 +0000 (09:18 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Fri, 20 Oct 2023 03:59:17 +0000 (03:59 +0000)
The idea is to alter partition sizes via
overriding part_table prior to SdFusingTarget.__init__
to avoid hardcoding it every time you need such a change.

Implemented in SdFusingTarget.apply_partition_sizes

Currently only called (and tested) for RV64 target

Change-Id: Ia070359b47b9c3bfbbdb7881ddf43fb16d2df4a3
Signed-off-by: Leonid <l.sawin@samsung.com>
(cherry picked from commit 304aa532036b5c81553787dfcb33dc6376ad6e91)

scripts/tizen/sd_fusing.py

index bf2428d..7cd72be 100755 (executable)
@@ -106,6 +106,23 @@ class SdFusingTarget:
         self.label = Label(self.part_table, ltype)
         self.binaries = self._get_binaries('binaries')
 
+    def apply_partition_sizes(self, partition_sizes):
+        if partition_sizes is None or len(partition_sizes) == 0:
+            return 0
+        resized_total = 0
+        for name, size in partition_sizes.items():
+            resized_count = 0
+            for part in self.part_table:
+                if part['name'] == name:
+                    psize = part['size']
+                    part['size'] = size
+                    logging.debug(f"overriding partition:{name}, old-size:{psize} MiB new-size:{size} MiB")
+                    resized_count = resized_count + 1
+            if resized_count == 0:
+                logging.error(f"partition:{name} not found when attempting to apply_partition_sizes")
+            resized_total = resized_total + resized_count
+        return resized_total
+
     def _get_binaries(self, key):
         binaries = {}
         for i, p in enumerate(self.part_table):
@@ -338,6 +355,7 @@ class RV64(SdFusingTarget):
     def __init__(self, device, args):
         self.user_partition = 6
         self.reserved_space = 5
+        self.apply_partition_sizes(args.partition_sizes)
         super().__init__(device, 'gpt')
 
 class VF2(RV64):
@@ -717,6 +735,10 @@ if __name__ == '__main__':
     parser.add_argument("--log-level", dest="log_level", default="warning",
                         help="Verbosity, possible values: debug, info, warning, "
                         "error, critical (default: warning)")
+    parser.add_argument("--partition-size", type=str, action="extend", dest="partition_sizes",
+                        nargs='*',
+                        help="override default partition size (in MiB) (used with --format), "
+                        "may be used multiple times, for example: --partition-size hal_a=256")
     parser.add_argument("--size", type=int, default=8192,
                         help="size of the backing file to create (in MiB)")
     parser.add_argument("-t", "--target", required=True,
@@ -739,6 +761,18 @@ if __name__ == '__main__':
     if args.device is None:
         parser.error('-d/--device argument is required for normal operation')
 
+    if args.partition_sizes is not None:
+        partition_sizes = {}
+        for eqstr in args.partition_sizes:
+            ptstr = eqstr.split('=')
+            if len(ptstr) == 2:
+                name = ptstr[0]
+                size = int(ptstr[1])
+                partition_sizes[name] = size
+            else:
+                parser.error('--partition-size must follow the name=size pattern')
+        args.partition_sizes = partition_sizes
+
     conh = ColorStreamHandler(format='%(asctime)s.%(msecs)d %(debuginfo)s%(levelname)-8s %(message)s',
                               cformat='%(asctime)s.%(msecs)d %(debuginfo)s%(levelcolor)s%(message)s',
                               datefmt='%Y-%m-%dT%H:%M:%S')