diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 0f13fa84..61063d36 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -788,6 +788,8 @@ flashers = { "$BOOT/dtbo.img"]], "boot": [["fastboot", "--cmdline", "$KERNEL_CMDLINE", "boot", "$BOOT/boot.img$FLAVOR"]], + "flash_lk2nd": [["fastboot", "flash", "$PARTITION_KERNEL", + "$BOOT/lk2nd.img"]] }, }, # Some devices provide Fastboot but using Android boot images is not diff --git a/pmb/export/symlinks.py b/pmb/export/symlinks.py index b37f4269..8c5ae2aa 100644 --- a/pmb/export/symlinks.py +++ b/pmb/export/symlinks.py @@ -37,6 +37,7 @@ def symlinks(args, flavor, folder): f"{args.device}-boot.img": "Boot partition image", f"{args.device}-root.img": "Root partition image", f"pmos-{args.device}.zip": "Android recovery flashable zip", + "lk2nd.img": "Secondary Android bootloader", } # Generate a list of patterns @@ -53,7 +54,8 @@ def symlinks(args, flavor, folder): f"{path_native}/home/pmos/rootfs/{args.device}-boot.img", f"{path_native}/home/pmos/rootfs/{args.device}-root.img", f"{path_buildroot}/var/lib/postmarketos-android-recovery-" + - f"installer/pmos-{args.device}.zip"] + f"installer/pmos-{args.device}.zip", + f"{path_boot}/lk2nd.img"] # Generate a list of files from the patterns files = [] diff --git a/pmb/flasher/frontend.py b/pmb/flasher/frontend.py index 75175df2..248a0a00 100644 --- a/pmb/flasher/frontend.py +++ b/pmb/flasher/frontend.py @@ -112,6 +112,19 @@ def sideload(args): pmb.flasher.run(args, "sideload") +def flash_lk2nd(args): + chroot_path = args.work + "/chroot_rootfs_" + args.device + lk2nd_path = "/boot/lk2nd.img" + if not os.path.exists(chroot_path + lk2nd_path): + raise RuntimeError(f"{chroot_path+lk2nd_path} doesn't exist. Your" + " device may not support lk2nd.") + + logging.info(lk2nd_path) + logging.info("It's normal if fastboot warns" + " \"Image not signed or corrupt\" or a similar warning") + pmb.flasher.run(args, "flash_lk2nd") + + def frontend(args): action = args.action_flasher method = args.flash_method or args.deviceinfo["flash_method"] @@ -120,7 +133,8 @@ def frontend(args): if action == "flash_system": action = "flash_rootfs" - if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs"]: + if method == "none" and action in ["boot", "flash_kernel", "flash_rootfs", + "flash_lk2nd"]: logging.info("This device doesn't support any flash method.") return @@ -138,3 +152,5 @@ def frontend(args): list_devices(args) if action == "sideload": sideload(args) + if action in ["flash_lk2nd"]: + flash_lk2nd(args) diff --git a/pmb/install/_install.py b/pmb/install/_install.py index 78d5f1e8..7ce52bcf 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -698,6 +698,14 @@ def print_flash_info(args): " the kernel/initramfs directly without flashing." " Use 'pmbootstrap flasher boot' to do that.)") + if "flash_lk2nd" in flasher_actions and \ + os.path.exists(args.work + "/chroot_rootfs_" + args.device + + "/boot/lk2nd.img"): + logging.info(" * Your device supports and may even require" + " flashing lk2nd. You should flash it before" + " flashing anything else. Use 'pmbootstrap flasher" + " flash_lk2nd' to do that.") + # Export information logging.info("* If the above steps do not work, you can also create" " symlinks to the generated files with 'pmbootstrap export'" diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 18ccff8d..a32efae5 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -217,6 +217,14 @@ def arguments_flasher(subparser): help="partition to flash the kernel to (defaults" " to deviceinfo_flash_*_partition_kernel)") + # Flash lk2nd + flash_lk2nd = sub.add_parser("flash_lk2nd", + help="flash lk2nd, a secondary bootloader" + " needed for various Android devices") + flash_lk2nd.add_argument("--partition", default=None, + help="partition to flash lk2nd to (defaults to" + " default boot image partition ") + # Flash rootfs flash_rootfs = sub.add_parser("flash_rootfs", aliases=["flash_system"], help="flash the rootfs to a partition on the"