From 1efe288fe2904b89377a8a643241a606d532d8f7 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Mon, 10 Dec 2018 17:08:02 -0800 Subject: [PATCH] losetup: support building rootfs images with 4096 byte sector sizes (!1725) Adds an optional deviceinfo variable, `deviceinfo_rootfs_image_sector_size`, which specifies the logical sector size of the device's storage. Some devices made after 2016 with UFS storage uses 4096 byte sectors instead of the normal 512 bytes. The partition table in our rootfs must match, otherwise the root filesystem won't mount on the device. This change passes the sector size to `losetup` when creating the image if the deviceinfo specifies it, so the image will have the correct sector size. If the deviceinfo doesn't specify the new option, the behaviour is the same as previous versions of pmbootstrap. Note that the sector size option only works on Linux 4.14 and above, so pmbootstrap should be run on a >4.14 computer when installing to devices with non-standard sector size. To find if a device needs this parameter, run `fdisk -l` on the device. If the output shows `Note: sector size is 4096 (not 512)` then add `deviceinfo_rootfs_image_sector_size="4096"` to the deviceinfo. This is needed by the Pixel 3 XL (google-crosshatch) port. See https://gitlab.com/postmarketOS/pmbootstrap/issues/1696. --- pmb/config/__init__.py | 1 + pmb/install/losetup.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 91cf265f..4129783b 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -262,6 +262,7 @@ deviceinfo_attributes = [ "flash_fastboot_max_size", "flash_fastboot_vendor_id", "flash_sparse", + "rootfs_image_sector_size", # weston "weston_pixman_type", diff --git a/pmb/install/losetup.py b/pmb/install/losetup.py index df3dbd27..15d78f0a 100644 --- a/pmb/install/losetup.py +++ b/pmb/install/losetup.py @@ -52,7 +52,13 @@ def mount(args, img_path): # Mount and return on success init(args) - pmb.chroot.root(args, ["losetup", "-f", img_path], check=False) + + losetup_cmd = ["losetup", "-f", img_path] + sector_size = args.deviceinfo["rootfs_image_sector_size"] + if sector_size: + losetup_cmd += ["-b", str(int(sector_size))] + + pmb.chroot.root(args, losetup_cmd, check=False) if device_by_back_file(args, img_path): return