image/cli: add --sector-size option

This commit is contained in:
InsanePrawn 2023-01-09 05:47:24 +01:00
parent 69b7ea9db2
commit 6648a77822
3 changed files with 64 additions and 32 deletions

View file

@ -24,13 +24,14 @@ TYPES = [LK2ND, JUMPDRIVE, ABOOT]
@click.command(name='boot') @click.command(name='boot')
@profile_option @profile_option
@click.argument('type', required=False, default=ABOOT, type=click.Choice(TYPES)) @click.argument('type', required=False, default=ABOOT, type=click.Choice(TYPES))
def cmd_boot(type: str, profile: Optional[str] = None): @click.option('-b', '--sector-size', type=int, help="Override the device's sector size", default=None)
def cmd_boot(type: str, profile: Optional[str] = None, sector_size: Optional[int] = None):
"""Boot JumpDrive or the Kupfer aboot image. Erases Android DTBO in the process.""" """Boot JumpDrive or the Kupfer aboot image. Erases Android DTBO in the process."""
enforce_wrap() enforce_wrap()
device = get_profile_device(profile) device = get_profile_device(profile)
flavour = get_profile_flavour(profile).name flavour = get_profile_flavour(profile).name
deviceinfo = device.parse_deviceinfo() deviceinfo = device.parse_deviceinfo()
sector_size = deviceinfo.flash_pagesize sector_size = sector_size or deviceinfo.flash_pagesize
if not sector_size: if not sector_size:
raise Exception(f"Device {device.name} has no flash_pagesize specified") raise Exception(f"Device {device.name} has no flash_pagesize specified")
image_path = get_image_path(device, flavour) image_path = get_image_path(device, flavour)

View file

@ -64,6 +64,7 @@ def prepare_minimal_image(source_path: str, sector_size: int) -> str:
@click.option('-m', '--method', type=click.Choice(FLASH_METHODS)) @click.option('-m', '--method', type=click.Choice(FLASH_METHODS))
@click.option('--split-size', help='Chunk size when splitting the image into sparse files via fastboot') @click.option('--split-size', help='Chunk size when splitting the image into sparse files via fastboot')
@click.option('--shrink/--no-shrink', is_flag=True, default=True, help="Don't copy and shrink the image file to minimal size") @click.option('--shrink/--no-shrink', is_flag=True, default=True, help="Don't copy and shrink the image file to minimal size")
@click.option('-b', '--sector-size', type=int, help="Override the device's sector size", default=None)
@click.argument('what', type=click.Choice(list(FLASH_PARTS.values()))) @click.argument('what', type=click.Choice(list(FLASH_PARTS.values())))
@click.argument('location', type=str, required=False) @click.argument('location', type=str, required=False)
def cmd_flash( def cmd_flash(
@ -73,6 +74,7 @@ def cmd_flash(
split_size: Optional[str] = None, split_size: Optional[str] = None,
profile: Optional[str] = None, profile: Optional[str] = None,
shrink: bool = True, shrink: bool = True,
sector_size: Optional[int] = None,
): ):
"""Flash a partition onto a device. `location` takes either a path to a block device or one of emmc, sdcard""" """Flash a partition onto a device. `location` takes either a path to a block device or one of emmc, sdcard"""
enforce_wrap() enforce_wrap()
@ -81,7 +83,7 @@ def cmd_flash(
device_image_path = get_image_path(device, flavour) device_image_path = get_image_path(device, flavour)
deviceinfo = device.parse_deviceinfo() deviceinfo = device.parse_deviceinfo()
sector_size = deviceinfo.flash_pagesize sector_size = sector_size or deviceinfo.flash_pagesize
method = method or deviceinfo.flash_method method = method or deviceinfo.flash_method
if not sector_size: if not sector_size:
raise Exception(f"Device {device.name} has no flash_pagesize specified") raise Exception(f"Device {device.name} has no flash_pagesize specified")

View file

@ -342,33 +342,61 @@ def cmd_image():
"""Build, flash and boot device images""" """Build, flash and boot device images"""
sectorsize_option = click.option(
'-b',
'--sector-size',
help="Override the device's sector size",
type=int,
default=None,
)
@cmd_image.command(name='build') @cmd_image.command(name='build')
@click.argument('profile_name', required=False) @click.argument('profile_name', required=False)
@click.option('--local-repos/--no-local-repos', @click.option(
'--local-repos/--no-local-repos',
'-l/-L', '-l/-L',
help='Whether to use local package repos at all or only use HTTPS repos.',
default=True, default=True,
show_default=True, show_default=True,
help='Whether to use local package repos at all or only use HTTPS repos.') is_flag=True,
@click.option('--build-pkgs/--no-build-pkgs', )
@click.option(
'--build-pkgs/--no-build-pkgs',
'-p/-P', '-p/-P',
help='Whether to build missing/outdated local packages if local repos are enabled.',
default=True, default=True,
show_default=True, show_default=True,
help='Whether to build missing/outdated local packages if local repos are enabled.')
@click.option('--no-download-pkgs',
is_flag=True, is_flag=True,
)
@click.option(
'--no-download-pkgs',
help='Disable trying to download packages instead of building if building is enabled.',
default=False, default=False,
help='Disable trying to download packages instead of building if building is enabled.')
@click.option('--block-target', type=click.Path(), default=None, help='Override the block device file to write the final image to')
@click.option('--skip-part-images',
is_flag=True, is_flag=True,
)
@click.option(
'--block-target',
help='Override the block device file to write the final image to',
type=click.Path(),
default=None,
)
@click.option(
'--skip-part-images',
help='Skip creating image files for the partitions and directly work on the target block device.',
default=False, default=False,
help='Skip creating image files for the partitions and directly work on the target block device.') is_flag=True,
def cmd_build(profile_name: Optional[str] = None, )
@sectorsize_option
def cmd_build(
profile_name: Optional[str] = None,
local_repos: bool = True, local_repos: bool = True,
build_pkgs: bool = True, build_pkgs: bool = True,
no_download_pkgs=False, no_download_pkgs=False,
block_target: Optional[str] = None, block_target: Optional[str] = None,
skip_part_images: bool = False): sector_size: Optional[int] = None,
skip_part_images: bool = False,
):
""" """
Build a device image. Build a device image.
@ -400,7 +428,7 @@ def cmd_build(profile_name: Optional[str] = None,
build_packages(pkgbuilds, arch, try_download=not no_download_pkgs) build_packages(pkgbuilds, arch, try_download=not no_download_pkgs)
deviceinfo = device.parse_deviceinfo() deviceinfo = device.parse_deviceinfo()
sector_size = deviceinfo.flash_pagesize sector_size = sector_size or deviceinfo.flash_pagesize
if not sector_size: if not sector_size:
raise Exception(f"Device {device.name} has no flash_pagesize specified") raise Exception(f"Device {device.name} has no flash_pagesize specified")
@ -453,9 +481,10 @@ def cmd_build(profile_name: Optional[str] = None,
@cmd_image.command(name='inspect') @cmd_image.command(name='inspect')
@click.option('--shell', '-s', help="Open a shell in the image's rootfs", is_flag=True) @click.option('--shell', '-s', is_flag=True)
@sectorsize_option
@click.argument('profile', required=False) @click.argument('profile', required=False)
def cmd_inspect(profile: Optional[str] = None, shell: bool = False): def cmd_inspect(profile: Optional[str] = None, shell: bool = False, sector_size: Optional[int] = None):
"""Loop-mount the device image for inspection.""" """Loop-mount the device image for inspection."""
config.enforce_profile_device_set() config.enforce_profile_device_set()
config.enforce_profile_flavour_set() config.enforce_profile_flavour_set()
@ -464,7 +493,7 @@ def cmd_inspect(profile: Optional[str] = None, shell: bool = False):
arch = device.arch arch = device.arch
flavour = get_profile_flavour(profile).name flavour = get_profile_flavour(profile).name
deviceinfo = device.parse_deviceinfo() deviceinfo = device.parse_deviceinfo()
sector_size = deviceinfo.flash_pagesize sector_size = sector_size or deviceinfo.flash_pagesize
if not sector_size: if not sector_size:
raise Exception(f"Device {device.name} has no flash_pagesize specified") raise Exception(f"Device {device.name} has no flash_pagesize specified")