From 615880e1615a1b01ec3973b82a87f2b86d31056c Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 4 Jul 2017 22:47:03 +0200 Subject: [PATCH] pmbootstrap flasher: use boot.img file with fastboot --- pmb/config/__init__.py | 34 +++++++++++++++++++--------------- pmb/flasher/frontend.py | 9 +++------ pmb/flasher/run.py | 21 ++++++++++++++------- pmb/install/install.py | 7 ++++++- 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index e4caef2d..3ceb38a2 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -192,29 +192,31 @@ flash_mount_bind = [ "/dev/bus/usb/" ] -# Allowed variables: -# $KERNEL, $RAMDISK, $IMAGE (system partition image), $BOOTPARAM +""" +Flasher abstraction. Allowed variables: + +$BOOT: Path to the /boot partition +$FLAVOR: Kernel flavor +$IMAGE: Path to the system partition image +$KERNEL_CMDLINE: Kernel commandline + +Fastboot specific: $OFFSET_KERNEL, $OFFSET_RAMDISK, $OFFSET_TAGS, $PAGE_SIZE +""" flashers = { "fastboot": { "depends": ["android-tools"], "actions": { "list_devices": [["fastboot", "devices", "-l"]], - "flash_system": [["fastboot", "flash", "system", "$IMAGE"]], - "flash_kernel": [["fastboot", - "--base", "$OFFSET_BASE", + "flash_system": [["fastboot", "flash", "system", "$IMAGE"]], + "flash_kernel": [["fastboot", "flash" "boot", "$BOOT/boot.img-$FLAVOR"]], + "boot": [["fastboot", "--kernel-offset", "$OFFSET_KERNEL", "--ramdisk-offset", "$OFFSET_RAMDISK", "--tags-offset", "$OFFSET_TAGS", "--page-size", "$PAGE_SIZE", - "flash:raw", "$KERNEL", "$RAMDISK"]], - "boot": [["fastboot", - "--base", "$OFFSET_BASE", - "--kernel-offset", "$OFFSET_KERNEL", - "--ramdisk-offset", "$OFFSET_RAMDISK", - "--tags-offset", "$OFFSET_TAGS", - "--page-size", "$PAGE_SIZE", - "boot", "$KERNEL", "$RAMDISK"]], + "-c", "$KERNEL_CMDLINE", + "boot", "$BOOT/vmlinuz-$FLAVOR", "$BOOT/initramfs-$FLAVOR"]], } }, "heimdall": { @@ -222,10 +224,12 @@ flashers = { "actions": { "list_devices": [["heimdall", "detect"]], - "flash_system": [ + "flash_system": [ ["heimdall_wait_for_device.sh"], ["heimdall", "flash", "--SYSTEM", "$IMAGE"]], - "flash_kernel": [["heimdall_flash_kernel.sh", "$RAMDISK", "$KERNEL"]] + "flash_kernel": [["heimdall_flash_kernel.sh", + "$BOOT/initramfs-$FLAVOR", + "$BOOT/vmlinuz-$FLAVOR"]] }, }, } diff --git a/pmb/flasher/frontend.py b/pmb/flasher/frontend.py index 4f3145bb..80c5fc7c 100644 --- a/pmb/flasher/frontend.py +++ b/pmb/flasher/frontend.py @@ -50,15 +50,12 @@ def kernel(args): # Generate the paths and run the flasher pmb.flasher.init(args) - mnt = "/mnt/rootfs_" + args.device - kernel = mnt + "/boot/vmlinuz-" + flavor - ramdisk = mnt + "/boot/initramfs-" + flavor if args.action_flasher == "boot": logging.info("(native) boot " + flavor + " kernel") - pmb.flasher.run(args, "boot", kernel, ramdisk) + pmb.flasher.run(args, "boot", flavor) else: logging.info("(native) flash kernel " + flavor) - pmb.flasher.run(args, "flash_kernel", kernel, ramdisk) + pmb.flasher.run(args, "flash_kernel", flavor) def list_flavors(args): @@ -78,7 +75,7 @@ def system(args): # Run the flasher logging.info("(native) flash system image") - pmb.flasher.run(args, "flash_system", image=img_path) + pmb.flasher.run(args, "flash_system") def list_devices(args): diff --git a/pmb/flasher/run.py b/pmb/flasher/run.py index 97595a13..3f57f589 100644 --- a/pmb/flasher/run.py +++ b/pmb/flasher/run.py @@ -20,7 +20,7 @@ import pmb.flasher import pmb.chroot.initfs -def run(args, action, kernel=None, ramdisk=None, image=None): +def run(args, action, flavor): pmb.flasher.init(args) # Verify action @@ -30,12 +30,18 @@ def run(args, action, kernel=None, ramdisk=None, image=None): raise RuntimeError("action " + action + " is not" " configured for method " + method + "!") + # Kernel commandline is optional + # Optional variables + cmdline = "" + if "kernel_cmdline" in args.deviceinfo: + cmdline = args.deviceinfo["kernel_cmdline"] + # Variable setup vars = { - "$KERNEL": kernel, - "$RAMDISK": ramdisk, - "$IMAGE": image, - "$OFFSET_BASE": args.deviceinfo["flash_offset_base"], + "$BOOT": "/mnt/rootfs_" + args.device + "/boot", + "$FLAVOR": flavor, + "$IMAGE": "/home/user/rootfs/" + args.device + ".img", + "$KERNEL_CMDLINE": cmdline, "$OFFSET_KERNEL": args.deviceinfo["flash_offset_kernel"], "$OFFSET_RAMDISK": args.deviceinfo["flash_offset_ramdisk"], "$OFFSET_SECOND": args.deviceinfo["flash_offset_second"], @@ -49,10 +55,11 @@ def run(args, action, kernel=None, ramdisk=None, image=None): for key, value in vars.items(): for i in range(len(command)): if key in command[i]: - if not value: + if not value and key != "$KERNEL_CMDLINE": raise RuntimeError("Variable " + key + " found in" " action " + action + " for method " + method + "," - " but the value for this variable is None!") + " but the value for this variable is None! Is that" + " missing in your deviceinfo?") command[i] = command[i].replace(key, value) # Run the action diff --git a/pmb/install/install.py b/pmb/install/install.py index 58c89b43..29aded1d 100644 --- a/pmb/install/install.py +++ b/pmb/install/install.py @@ -129,7 +129,12 @@ def install(args, show_flash_msg=True): " target device:") logging.info("* pmbootstrap flasher flash_kernel") logging.info(" Flashes the kernel + initramfs to your device:") - logging.info(" " + args.work + "/chroot_rootfs_" + args.device + "/boot") + logging.info( + " " + + args.work + + "/chroot_rootfs_" + + args.device + + "/boot") method = args.deviceinfo["flash_methods"] if (method in pmb.config.flashers and "boot" in pmb.config.flashers[method]["actions"]):