install: add a --sector-size flag (MR 2391)

This can be used when building images for generic device targets that
support devices with different sector size requirements.

For example, trailblazer prebuilts are currently expected to be flashed
to a USB drive where a 4096 sector size would be unsuitable since the
bootloader wouldn't detect it. But when building for a Qualcomm phone,
one would use --split and --sector-size to build the root and boot
partitions with a 4k sector size which is appropriate to the UFS
storage.

This flag could also be used by BPO to build both variants.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-08-15 18:31:12 +02:00
parent 84c512ea6a
commit f6f503035b
No known key found for this signature in database
GPG key ID: 0583312B195F64B6
4 changed files with 15 additions and 3 deletions

View file

@ -116,7 +116,7 @@ def create_and_mount_image(args: PmbArgs, size_boot, size_root, size_reserve, sp
for img_path, mount_point in mount_image_paths.items():
logging.info(f"(native) mount {mount_point} ({img_path.name})")
pmb.install.losetup.mount(img_path)
pmb.install.losetup.mount(img_path, args.sector_size)
device = pmb.install.losetup.device_by_back_file(img_path)
pmb.helpers.mount.bind_file(device, Chroot.native() / mount_point)

View file

@ -22,7 +22,7 @@ def init():
pmb.helpers.mount.bind_file(loopdevice, Chroot.native() / loopdevice)
def mount(img_path: Path):
def mount(img_path: Path, _sector_size: int | None = None):
"""
:param img_path: Path to the img file inside native chroot.
"""
@ -38,8 +38,12 @@ def mount(img_path: Path):
# Mount and return on success
init()
sector_size = None
if _sector_size:
sector_size = str(_sector_size)
sector_size = sector_size or pmb.parse.deviceinfo().rootfs_image_sector_size
losetup_cmd: list[PathString] = ["losetup", "-f", img_path]
sector_size = pmb.parse.deviceinfo().rootfs_image_sector_size
if sector_size:
losetup_cmd += ["-b", str(int(sector_size))]

View file

@ -102,6 +102,13 @@ def arguments_install(subparser):
default=True,
)
ret.add_argument("--zap", help="zap chroots before installing", action="store_true")
ret.add_argument(
"--sector-size",
help="set the sector size for the image file",
type=int,
default=None,
choices=[512, 2048, 4096],
)
# Image type
group_desc = ret.add_argument_group(

View file

@ -152,6 +152,7 @@ class PmbArgs(Namespace):
rsync: bool
scripts: str
second_storage: str
sector_size: int | None
selected_providers: dict[str, str]
sparse: bool
split: bool