From 9336ac087cc33cbd8c8c2abf046394ee0b9f445f Mon Sep 17 00:00:00 2001 From: Jacek Kryszyn Date: Mon, 23 Sep 2024 06:01:29 +0200 Subject: [PATCH] scripts: sd_fusing: get rid of user_partition attribute 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 --- sd_fusing.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sd_fusing.py b/sd_fusing.py index e894e01..3368dbb 100755 --- a/sd_fusing.py +++ b/sd_fusing.py @@ -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) -- 2.34.1