sd_fusing.py: Ensure selected flashing target actually matches what is on device
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 23 May 2024 09:14:40 +0000 (11:14 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 4 Dec 2024 11:00:01 +0000 (12:00 +0100)
Currently only partition label and filesystem type are checked, if available.

Change-Id: I64c43c7b80843e70876ce16ee7de24a7dc76378d
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
sd_fusing.py

index 8aafc8aef3c1aff9b111b876b0a87377d3dd87dd..a4c35c24c17aae6d34f723c093d5e8b1f1683559 100755 (executable)
@@ -178,6 +178,17 @@ class SdFusingTarget:
             sys.exit(1)
         return [self.binaries.get(binary, None)]
 
+    def ensure_parttable(self):
+        logging.notice(f"Verifying that partition table on {Device} matches target specification")
+        for partnum, part in enumerate(self.part_table, 1):
+            bo = subprocess.check_output(["blkid", "-o", "export", Device + str(partnum)]).decode('utf-8')
+            if "PARTLABEL=" in bo and f"PARTLABEL={part['name']}" not in bo:
+                logging.error(f'On-device partition label mismatch with selected target: partlabel={part["name"]}, on-device:\n{bo}')
+                sys.exit(1)
+            if part['fstype'] not in 'raw' and f"TYPE={part['fstype']}" not in bo:
+                logging.error(f'On-device partition mismatch with selected target: fstype={part["fstype"]}, on-device:\n{bo}')
+                sys.exit(1)
+
     def initialize_parameters(self):
         pass
 
@@ -942,6 +953,7 @@ def check_partition_format(args, target):
 
     if not Format:
         logging.info(f"Skip formatting of {Device}".format(Device))
+        target.ensure_parttable()
         return
     logging.info(f"Start formatting of {Device}")
     mkpart(args, target)