~postmarketos/pmbootstrap

e0e3e213ba24720afa431b13f0f878c6fd9dd108 — Andras Sebok 8 months ago 59898f5
flasher: heimdall-bootimg: add support for '--no-reboot' and '--resume'

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C170534361606.26168.17672643433174186875-0@git.sr.ht%3E
4 files changed, 41 insertions(+), 5 deletions(-)

M pmb/config/__init__.py
M pmb/flasher/run.py
M pmb/flasher/variables.py
M pmb/parse/arguments.py
M pmb/config/__init__.py => pmb/config/__init__.py +7 -4
@@ 998,20 998,23 @@ flashers = {
            "list_devices": [["heimdall", "detect"]],
            "flash_rootfs": [
                ["heimdall_wait_for_device.sh"],
                ["heimdall", "flash", "--$PARTITION_ROOTFS", "$IMAGE"]],
                ["heimdall", "flash", "--$PARTITION_ROOTFS", "$IMAGE",
                 "$NO_REBOOT", "$RESUME"]],
            "flash_kernel": [
                ["heimdall_wait_for_device.sh"],
                ["heimdall", "flash", "--$PARTITION_KERNEL",
                 "$BOOT/boot.img$FLAVOR"]],
                 "$BOOT/boot.img$FLAVOR", "$NO_REBOOT", "$RESUME"]],
            "flash_vbmeta": [
                ["avbtool", "make_vbmeta_image", "--flags", "2",
                    "--padding_size", "$FLASH_PAGESIZE",
                    "--output", "/vbmeta.img"],
                ["heimdall", "flash", "--$PARTITION_VBMETA", "/vbmeta.img"],
                ["heimdall", "flash", "--$PARTITION_VBMETA", "/vbmeta.img",
                 "$NO_REBOOT", "$RESUME"],
                ["rm", "-f", "/vbmeta.img"]],
            "flash_lk2nd": [
                ["heimdall_wait_for_device.sh"],
                ["heimdall", "flash", "--$PARTITION_KERNEL", "$BOOT/lk2nd.img"]]
                ["heimdall", "flash", "--$PARTITION_KERNEL", "$BOOT/lk2nd.img",
                 "$NO_REBOOT", "$RESUME"]]
        },
    },
    "adb": {

M pmb/flasher/run.py => pmb/flasher/run.py +10 -0
@@ 50,6 50,14 @@ def run(args, action, flavor=None):
                           " in deviceinfo file. See also:"
                           " <https://wiki.postmarketos.org/wiki/"
                           "Deviceinfo_reference>")
    
    if args.no_reboot and ("flash" not in action or method != "heimdall-bootimg"):
        raise RuntimeError("The '--no-reboot' option is only"
                           " supported when flashing with heimall-bootimg.")
    
    if args.resume and ("flash" not in action or method != "heimdall-bootimg"):
        raise RuntimeError("The '--resume' option is only"
                           " supported when flashing with heimall-bootimg.")

    # Run the commands of each action
    for command in cfg["actions"][action]:


@@ 66,5 74,7 @@ def run(args, action, flavor=None):
                    check_partition_blacklist(args, key, value)
                    command[i] = command[i].replace(key, value)

        # Remove empty strings
        command = [x for x in command if x != '']
        # Run the action
        pmb.chroot.root(args, command, output="interactive")

M pmb/flasher/variables.py => pmb/flasher/variables.py +11 -1
@@ 61,6 61,14 @@ def variables(args, flavor, method):
    _dtb = ""
    if args.deviceinfo["append_dtb"] == "true":
        _dtb = "-dtb"
    
    _no_reboot = ""
    if args.no_reboot:
        _no_reboot = "--no-reboot"

    _resume = ""
    if args.resume:
        _resume = "--resume"

    vars = {
        "$BOOT": "/mnt/rootfs_" + args.device + "/boot",


@@ 80,7 88,9 @@ def variables(args, flavor, method):
                         "/var/lib/postmarketos-android-recovery-installer"
                         "/pmos-" + args.device + ".zip",
        "$UUU_SCRIPT": "/mnt/rootfs_" + args.deviceinfo["codename"] +
                       "/usr/share/uuu/flash_script.lst"
                       "/usr/share/uuu/flash_script.lst",
        "$NO_REBOOT": _no_reboot,
        "$RESUME": _resume
    }

    # Backwards compatibility with old mkinitfs (pma#660)

M pmb/parse/arguments.py => pmb/parse/arguments.py +13 -0
@@ 289,6 289,19 @@ def arguments_flasher(subparser):
                   " inside the device rootfs chroot on this computer")
    sub.add_parser("list_devices", help="show connected devices")

    group = ret.add_argument_group("heimdall options", \
                                   "With heimdall as"
                                   " flash method, the device automatically"
                                   " reboots after each flash command. Use"
                                   " --no-reboot and --resume for multiple"
                                   " flash actions without reboot.")
    group.add_argument("--no-reboot", dest="no_reboot",
                       help="don't automatically reboot after flashing",
                       action="store_true")
    group.add_argument("--resume", dest="resume",
                       help="resume flashing after using --no-reboot",
                       action="store_true")

    return ret