tizen: sd_fusing.py: Catch kernel not being able to re-read partition table
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 4 Apr 2024 12:15:27 +0000 (14:15 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 28 Oct 2024 11:28:44 +0000 (20:28 +0900)
sfdisk(8) by default request kernel to reread partition table but does not
seem to return error code when it fails to do so.  This commit fixes followig
error:

    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Re-reading the partition table failed.: Permission denied
    The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or partx(8).
    Syncing disks.
    Traceback (most recent call last):
      File "/usr/local/bin/sd_fusing.py", line 958, in <module>
        check_partition_format(args, target)
      File "/usr/local/bin/sd_fusing.py", line 711, in check_partition_format
        mkpart(args, target)
      File "/usr/local/bin/sd_fusing.py", line 596, in mkpart
        d = "/dev/" + get_partition_device(target.device, i+1)
            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    TypeError: can only concatenate str (not "NoneType") to str

Change-Id: I32e6636f0d374e5f4327d425373d8e38f48b7916
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
scripts/tizen/sd_fusing.py

index a34c203b30f54d4f4223a913b566415dea0014c7..925d9f5e6e1f81a2b72fc19bfa4f64d25e4940f5 100755 (executable)
@@ -667,7 +667,7 @@ def mkpart(args, target):
             sys.exit(1)
 
     logging.debug("New partition table:\n" + str(target.label))
-    argv = ['sfdisk', '--wipe-partitions', 'always', Device]
+    argv = ['sfdisk', '--no-reread', '--wipe-partitions', 'always', Device]
     logging.debug(" ".join(argv))
     proc = subprocess.run(argv,
                           stdout=None,
@@ -678,6 +678,16 @@ def mkpart(args, target):
         logging.error(f"New partition table:\n" + str(target.label))
         sys.exit(1)
 
+    logging.debug("Requesting kernel to re-read partition table:\n" + str(target.label))
+    argv = ['blockdev', '--rereadpt', Device]
+    logging.debug(" ".join(argv))
+    proc = subprocess.run(argv,
+                          stdout=None,
+                          stderr=None)
+    if proc.returncode != 0:
+        logging.error(f"Failed to request kernel to reread partition table on {Device}. (Insufficient permissions?)")
+        sys.exit(1)
+
     if target.bootcode:
         logging.debug("Writing bootcode\n")
         with open(Device, "wb") as f: