From: Karol Lewandowski Date: Tue, 21 May 2024 21:57:15 +0000 (+0200) Subject: sd_fusing.py: Refactor parameters writing X-Git-Tag: accepted/tizen/unified/20241126.175211~64 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec73de92ba3e09c2bdf83080ea94e694ea4f83ba;p=platform%2Fkernel%2Fu-boot.git sd_fusing.py: Refactor parameters writing This commit considerably alters when and which parameters are written to "inform" partition: - Parameters are now updated always, not only when --format has been specified (this is compatible with old sd_fusing.sh behaviour) - Initial parameters are collected from configuration and from user input to reflect actual flashing options, eg. if user chosen to update only 'a' partition script won't set the flag that both partitions are cloned Dynamic parameters generation allowed to drop a lot of duplicated params. Change-Id: I597f104b2b7972728663e2d85555407c721b7bb0 Signed-off-by: Karol Lewandowski --- diff --git a/scripts/tizen/sd_fusing.py b/scripts/tizen/sd_fusing.py index ee380ebfc8..a564c2fe16 100755 --- a/scripts/tizen/sd_fusing.py +++ b/scripts/tizen/sd_fusing.py @@ -113,6 +113,10 @@ class Label: return output class SdFusingTarget: + params = (('reboot-param.bin', 'norm'), + ('reboot-param.info', 'norm'), + ('upgrade-status.info', '0')) + def __init__(self, device, ltype): # TODO: make a copy of a sublcass part_table self.with_super = False @@ -171,10 +175,15 @@ class SdFusingTarget: sys.exit(1) return [self.binaries.get(binary, None)] - params = () def initialize_parameters(self): pass + def write_parameters(self, params = None): + pass + + def update_parameters(self): + self.write_parameters() + class SdFusingTargetAB(SdFusingTarget): def __init__(self, device, ltype): super().__init__(device, ltype) @@ -188,15 +197,30 @@ class SdFusingTargetAB(SdFusingTarget): return [self.binaries.get(binary, None)] + def update_parameters(self): + part_ab = 'a' if self.update in [None, '', 'a', 'ab'] else 'b' + part_cloned = '1' if self.update == 'ab' else '0' + params = [('partition-ab.info', part_ab), + ('partition-ab-cloned.info', part_cloned)] + if not self.update in [None, '', 'a', 'ab']: + params.append(('partition-a-status.info', 'ok')) + if self.update in ['b', 'ab']: + params.append(('partition-b-status.info', 'ok')) + self.write_parameters(self.params + tuple(params)) + class InitParams: - def initialize_parameters(self): - logging.debug("Initializing parameterss") + def find_inform(self): n = None for i, p in enumerate(self.part_table): if p['name'] == 'inform': n = i + 1; break d = "/dev/" + get_partition_device(self.device, n) + return d + + def initialize_parameters(self): + logging.debug("Initializing parameters") + d = self.find_inform() argv = ['tune2fs', '-O', '^metadata_csum', d] logging.debug(" ".join(argv)) @@ -204,6 +228,9 @@ class InitParams: stdin=subprocess.DEVNULL, stdout=None, stderr=None) + def write_parameters(self, params = None): + d = self.find_inform() + logging.debug(f"Writing parameters to {d}") with tempfile.TemporaryDirectory() as mnt: argv = ['mount', '-t', 'ext4', d, mnt] logging.debug(" ".join(argv)) @@ -213,8 +240,10 @@ class InitParams: if proc.returncode != 0: logging.error(f"Failed to mount {d} in {mnt} (Has the device been initialized with --format?)") return - for param, value in self.params: + parameters = self.params if params is None else params + for param, value in parameters: with open(os.path.join(mnt, param), 'w') as f: + logging.debug(f"Writing parameter {param}={value}") f.write(value + '\n') argv = ['umount', d] logging.debug(" ".join(argv)) @@ -245,7 +274,6 @@ class Rpi3(InitParams, SdFusingTarget): "binaries": "hal.img"}, {"size": 125, "fstype": "ext4", "name": "reserved2"}, ] - params = (('reboot-param.bin', ''),) def __init__(self, device, args): self.reserved_space = 12 @@ -285,13 +313,6 @@ class Rpi4Super(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "ext4", "name": "reserved1"}, {"size": 125, "fstype": "ext4", "name": "reserved2"} ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) def __init__(self, device, args): self.reserved_space = 8 @@ -340,13 +361,6 @@ class Rpi4(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "ext4", "name": "reserved1"}, {"size": 125, "fstype": "ext4", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) def __init__(self, device, args): self.reserved_space = 5 @@ -401,13 +415,6 @@ class Rpi4AoT(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "ext4", "name": "reserved1"}, {"size": 125, "fstype": "ext4", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) def __init__(self, device, args): self.reserved_space = 5 @@ -447,8 +454,6 @@ class RV64(InitParams, SdFusingTarget): {"size": 64, "fstype": "raw", "name": "reserved1"}, {"size": 125, "fstype": "raw", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm')) def __init__(self, device, args): self.user_partition = 6 @@ -501,13 +506,6 @@ class VF2(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "raw", "name": "reserved1"}, {"size": 125, "fstype": "raw", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) def __init__(self, device, args): self.user_partition = 6 @@ -555,13 +553,6 @@ class VF2Super(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "raw", "name": "reserved1"}, {"size": 125, "fstype": "raw", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) def __init__(self, device, args): self.user_partition = 6 @@ -613,13 +604,6 @@ class LicheePi4A(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "raw", "name": "reserved1"}, {"size": 125, "fstype": "raw", "name": "reserved2"}, ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) # bootcode written to the protective MBR, aka RV64 'J 0x4400' (sector 34) bootcode = b'\x6f\x40\x00\x40' @@ -667,13 +651,6 @@ class LicheePi4ASuper(InitParams, SdFusingTargetAB): {"size": 64, "fstype": "ext4", "name": "reserved1"}, {"size": 125, "fstype": "ext4", "name": "reserved2"} ] - params = (('reboot-param.bin', 'norm'), - ('reboot-param.info', 'norm'), - ('partition-ab.info', 'a'), - ('partition-ab-cloned.info', '1'), - ('upgrade-status.info', '0'), - ('partition-a-status.info', 'ok'), - ('partition-b-status.info', 'ok')) # bootcode written to the protective MBR, aka RV64 'J 0x4400' (sector 34) bootcode = b'\x6f\x40\x00\x40' @@ -1120,6 +1097,7 @@ def fuse_image(args, target): if target.with_super and not SuperDelivered: do_fuse_image_super(tmpd, target) + target.update_parameters() def logger_notice(self, msg, *args, **kws): if self.isEnabledFor(LOGGING_NOTICE):