""" Copyright 2017 Oliver Smith This file is part of pmbootstrap. pmbootstrap is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. pmbootstrap is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ import logging import os import pmb.flasher import pmb.install import pmb.chroot.other def kernel(args): # Parse the kernel flavor suffix = "rootfs_" + args.device flavor = args.flavor flavors = pmb.chroot.other.installed_kernel_flavors(args, suffix) if flavor: if flavor not in flavors: raise RuntimeError("No kernel installed with flavor " + flavor + "!" + " Run 'pmbootstrap flasher list_flavors' to get a list.") elif not len(flavors): raise RuntimeError( "No kernel flavors installed in chroot " + suffix + "!") else: flavor = flavors[0] # 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) else: logging.info("(native) flash kernel '" + flavor + "'") pmb.flasher.run(args, "flash_kernel", kernel, ramdisk) def list_flavors(args): suffix = "rootfs_" + args.device logging.info("(" + suffix + ") installed kernel flavors:") for flavor in pmb.chroot.other.installed_kernel_flavors(args, suffix): logging.info("* " + flavor) def system(args): # Generate system image, install flasher img_path = "/home/user/rootfs/" + args.device + ".img" if not os.path.exists(args.work + "/chroot_native" + img_path): setattr(args, "sdcard", None) pmb.install.install(args, False) pmb.flasher.init(args) # Run the flasher logging.info("(native) flash system image") pmb.flasher.run(args, "flash_system", image=img_path) def list_devices(args): pmb.flasher.run(args, "list_devices") def frontend(args): action = args.action_flasher if action in ["boot", "flash_kernel"]: kernel(args) if action == "flash_system": system(args) if action == "list_flavors": list_flavors(args) if action == "list_devices": list_devices(args)