scripts: sd_fusing: get rid of user_partition attribute
authorJacek Kryszyn <j.kryszyn@samsung.com>
Mon, 23 Sep 2024 04:01:29 +0000 (06:01 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 28 Oct 2024 11:28:47 +0000 (20:28 +0900)
The SdFusingTarget class has the user_partition
attribute which informs about the index of the user
partition in the part_table. It has to be set manually
for each target. This change removes the attribute and
adds calculation of the index.

Change-Id: I2a0827dac255bd4715ab04cd050e8fd9d14edb40
Signed-off-by: Jacek Kryszyn <j.kryszyn@samsung.com>
scripts/tizen/sd_fusing.py

index e894e01af7faceb018cabf3bd97bf9647aea0270..3368dbbe90c1c80bf27f1b7468021b5aac0b6c19 100755 (executable)
@@ -125,14 +125,20 @@ class SdFusingTarget:
         self.device = device
         total_size = device_size(device)
 
-        if hasattr(self, 'user_partition'):
+        # find user partition and calculate its size
+        n = None
+        for i, p in enumerate(self.part_table):
+            if p['name'] == 'user':
+                n = i;
+                break
+
+        if n is not None:
             self.user_size = total_size - self.reserved_space - \
                 reduce(lambda x, y: x + (y["size"] or 0), self.part_table, 0)
             if self.user_size < 100:
                 logging.error(f"Not enough space for user data ({self.user_size}). Use larger storage.")
                 raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC), device)
-            # self.user_partition counts from 0
-            self.part_table[self.user_partition]["size"] = self.user_size
+            self.part_table[n]["size"] = self.user_size
 
         self.label = Label(self.part_table, ltype)
         self.binaries = self._get_binaries('binaries')
@@ -295,7 +301,6 @@ class Rpi3(InitParams, SdFusingTarget):
 
     def __init__(self, device, args):
         self.reserved_space = 12
-        self.user_partition = 4
         super().__init__(device, "dos")
 
 class OdroidC4(InitParams, SdFusingTarget):
@@ -329,7 +334,6 @@ class OdroidC4(InitParams, SdFusingTarget):
 
     def __init__(self, device, args):
         self.reserved_space = 12
-        self.user_partition = 4
         super().__init__(device, "dos")
 
 class Rpi4Super(InitParams, SdFusingTargetAB):
@@ -368,7 +372,6 @@ class Rpi4Super(InitParams, SdFusingTargetAB):
 
     def __init__(self, device, args):
         self.reserved_space = 8
-        self.user_partition = 4
         self.update = args.update
         super().__init__(device, "gpt")
         self.with_super = True
@@ -415,7 +418,6 @@ class Rpi4(InitParams, SdFusingTargetAB):
 
     def __init__(self, device, args):
         self.reserved_space = 5
-        self.user_partition = 4
         self.update = args.update
         super().__init__(device, "gpt")
 
@@ -469,7 +471,6 @@ class Rpi4AoT(InitParams, SdFusingTargetAB):
 
     def __init__(self, device, args):
         self.reserved_space = 5
-        self.user_partition = 4
         self.update = args.update
         super().__init__(device, "gpt")
 
@@ -507,7 +508,6 @@ class RV64(InitParams, 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')
@@ -559,7 +559,6 @@ class VF2(InitParams, SdFusingTargetAB):
     ]
 
     def __init__(self, device, args):
-        self.user_partition = 6
         self.reserved_space = 5
         self.update = args.update
         self.apply_partition_sizes(args.partition_sizes)
@@ -606,7 +605,6 @@ class VF2Super(InitParams, SdFusingTargetAB):
     ]
 
     def __init__(self, device, args):
-        self.user_partition = 6
         self.reserved_space = 5
         self.update = args.update
         super().__init__(device, 'gpt')
@@ -661,7 +659,6 @@ class LicheePi4A(InitParams, SdFusingTargetAB):
     ]
 
     def __init__(self, device, args):
-        self.user_partition = 4
         self.reserved_space = 5
         self.update = args.update
         self.apply_partition_sizes(args.partition_sizes)
@@ -711,7 +708,6 @@ class LicheePi4ASuper(InitParams, SdFusingTargetAB):
 
     def __init__(self, device, args):
         self.reserved_space = 8
-        self.user_partition = 4
         self.update = args.update
         super().__init__(device, 'gpt')
         self.with_super = True
@@ -796,7 +792,6 @@ class BpiF3(InitParams, SdFusingTargetAB):
     ]
 
     def __init__(self, device, args):
-        self.user_partition = 6
         self.reserved_space = 5
         self.update = args.update
         self.apply_partition_sizes(args.partition_sizes)