Add 'flasher flash_lk2nd' command (MR 2089)

Many Qualcomm devices need this second bootloader for booting a mainline
kernel. Add an option to flash one if it exists.
This commit is contained in:
Ultracoolguy 2021-08-03 15:37:59 -04:00 committed by Oliver Smith
parent f4990cfc7a
commit 54afa35d70
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
5 changed files with 38 additions and 2 deletions

View file

@ -788,6 +788,8 @@ flashers = {
"$BOOT/dtbo.img"]], "$BOOT/dtbo.img"]],
"boot": [["fastboot", "--cmdline", "$KERNEL_CMDLINE", "boot": [["fastboot", "--cmdline", "$KERNEL_CMDLINE",
"boot", "$BOOT/boot.img$FLAVOR"]], "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 # Some devices provide Fastboot but using Android boot images is not

View file

@ -37,6 +37,7 @@ def symlinks(args, flavor, folder):
f"{args.device}-boot.img": "Boot partition image", f"{args.device}-boot.img": "Boot partition image",
f"{args.device}-root.img": "Root partition image", f"{args.device}-root.img": "Root partition image",
f"pmos-{args.device}.zip": "Android recovery flashable zip", f"pmos-{args.device}.zip": "Android recovery flashable zip",
"lk2nd.img": "Secondary Android bootloader",
} }
# Generate a list of patterns # 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}-boot.img",
f"{path_native}/home/pmos/rootfs/{args.device}-root.img", f"{path_native}/home/pmos/rootfs/{args.device}-root.img",
f"{path_buildroot}/var/lib/postmarketos-android-recovery-" + 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 # Generate a list of files from the patterns
files = [] files = []

View file

@ -112,6 +112,19 @@ def sideload(args):
pmb.flasher.run(args, "sideload") 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): def frontend(args):
action = args.action_flasher action = args.action_flasher
method = args.flash_method or args.deviceinfo["flash_method"] method = args.flash_method or args.deviceinfo["flash_method"]
@ -120,7 +133,8 @@ def frontend(args):
if action == "flash_system": if action == "flash_system":
action = "flash_rootfs" 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.") logging.info("This device doesn't support any flash method.")
return return
@ -138,3 +152,5 @@ def frontend(args):
list_devices(args) list_devices(args)
if action == "sideload": if action == "sideload":
sideload(args) sideload(args)
if action in ["flash_lk2nd"]:
flash_lk2nd(args)

View file

@ -698,6 +698,14 @@ def print_flash_info(args):
" the kernel/initramfs directly without flashing." " the kernel/initramfs directly without flashing."
" Use 'pmbootstrap flasher boot' to do that.)") " 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 # Export information
logging.info("* If the above steps do not work, you can also create" logging.info("* If the above steps do not work, you can also create"
" symlinks to the generated files with 'pmbootstrap export'" " symlinks to the generated files with 'pmbootstrap export'"

View file

@ -217,6 +217,14 @@ def arguments_flasher(subparser):
help="partition to flash the kernel to (defaults" help="partition to flash the kernel to (defaults"
" to deviceinfo_flash_*_partition_kernel)") " 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
flash_rootfs = sub.add_parser("flash_rootfs", aliases=["flash_system"], flash_rootfs = sub.add_parser("flash_rootfs", aliases=["flash_system"],
help="flash the rootfs to a partition on the" help="flash the rootfs to a partition on the"