diff --git a/image/boot.py b/image/boot.py index 07a0f35..a24e2e5 100644 --- a/image/boot.py +++ b/image/boot.py @@ -24,13 +24,14 @@ TYPES = [LK2ND, JUMPDRIVE, ABOOT] @click.command(name='boot') @profile_option @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.""" enforce_wrap() device = get_profile_device(profile) flavour = get_profile_flavour(profile).name deviceinfo = device.parse_deviceinfo() - sector_size = deviceinfo.flash_pagesize + sector_size = sector_size or deviceinfo.flash_pagesize if not sector_size: raise Exception(f"Device {device.name} has no flash_pagesize specified") image_path = get_image_path(device, flavour) diff --git a/image/flash.py b/image/flash.py index f68a1d8..591bc9e 100644 --- a/image/flash.py +++ b/image/flash.py @@ -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('--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('-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('location', type=str, required=False) def cmd_flash( @@ -73,6 +74,7 @@ def cmd_flash( split_size: Optional[str] = None, profile: Optional[str] = None, 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""" enforce_wrap() @@ -81,7 +83,7 @@ def cmd_flash( device_image_path = get_image_path(device, flavour) deviceinfo = device.parse_deviceinfo() - sector_size = deviceinfo.flash_pagesize + sector_size = sector_size or deviceinfo.flash_pagesize method = method or deviceinfo.flash_method if not sector_size: raise Exception(f"Device {device.name} has no flash_pagesize specified") diff --git a/image/image.py b/image/image.py index bdc3200..84b265d 100644 --- a/image/image.py +++ b/image/image.py @@ -342,33 +342,61 @@ def cmd_image(): """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') @click.argument('profile_name', required=False) -@click.option('--local-repos/--no-local-repos', - '-l/-L', - default=True, - show_default=True, - help='Whether to use local package repos at all or only use HTTPS repos.') -@click.option('--build-pkgs/--no-build-pkgs', - '-p/-P', - 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, - 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, - default=False, - help='Skip creating image files for the partitions and directly work on the target block device.') -def cmd_build(profile_name: Optional[str] = None, - local_repos: bool = True, - build_pkgs: bool = True, - no_download_pkgs=False, - block_target: Optional[str] = None, - skip_part_images: bool = False): +@click.option( + '--local-repos/--no-local-repos', + '-l/-L', + help='Whether to use local package repos at all or only use HTTPS repos.', + default=True, + show_default=True, + is_flag=True, +) +@click.option( + '--build-pkgs/--no-build-pkgs', + '-p/-P', + help='Whether to build missing/outdated local packages if local repos are enabled.', + default=True, + show_default=True, + is_flag=True, +) +@click.option( + '--no-download-pkgs', + help='Disable trying to download packages instead of building if building is enabled.', + default=False, + 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, + is_flag=True, +) +@sectorsize_option +def cmd_build( + profile_name: Optional[str] = None, + local_repos: bool = True, + build_pkgs: bool = True, + no_download_pkgs=False, + block_target: Optional[str] = None, + sector_size: Optional[int] = None, + skip_part_images: bool = False, +): """ 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) deviceinfo = device.parse_deviceinfo() - sector_size = deviceinfo.flash_pagesize + sector_size = sector_size or deviceinfo.flash_pagesize if not sector_size: 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') -@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) -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.""" config.enforce_profile_device_set() config.enforce_profile_flavour_set() @@ -464,7 +493,7 @@ def cmd_inspect(profile: Optional[str] = None, shell: bool = False): arch = device.arch flavour = get_profile_flavour(profile).name deviceinfo = device.parse_deviceinfo() - sector_size = deviceinfo.flash_pagesize + sector_size = sector_size or deviceinfo.flash_pagesize if not sector_size: raise Exception(f"Device {device.name} has no flash_pagesize specified")