2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2017-07-19 18:05:34 +00:00
|
|
|
import pmb.config
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.flasher
|
|
|
|
import pmb.install
|
2017-06-09 17:22:25 +00:00
|
|
|
import pmb.chroot.apk
|
|
|
|
import pmb.chroot.initfs
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.chroot.other
|
2017-09-06 20:14:03 +00:00
|
|
|
import pmb.export.frontend
|
2017-09-02 03:53:58 +00:00
|
|
|
import pmb.helpers.frontend
|
2017-09-18 21:36:54 +00:00
|
|
|
import pmb.parse.kconfig
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2017-07-04 21:03:51 +00:00
|
|
|
|
|
|
|
def kernel(args):
|
2017-06-09 17:22:25 +00:00
|
|
|
# Rebuild the initramfs, just to make sure (see #69)
|
2017-09-02 03:53:58 +00:00
|
|
|
flavor = pmb.helpers.frontend._parse_flavor(args)
|
2017-06-09 17:22:25 +00:00
|
|
|
pmb.chroot.initfs.build(args, flavor, "rootfs_" + args.device)
|
|
|
|
|
2017-09-18 21:36:54 +00:00
|
|
|
# Check kernel config
|
|
|
|
pmb.parse.kconfig.check(args, flavor)
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
# Generate the paths and run the flasher
|
|
|
|
if args.action_flasher == "boot":
|
|
|
|
logging.info("(native) boot " + flavor + " kernel")
|
2017-07-04 20:47:03 +00:00
|
|
|
pmb.flasher.run(args, "boot", flavor)
|
2017-05-26 20:08:45 +00:00
|
|
|
else:
|
2017-06-09 17:22:25 +00:00
|
|
|
logging.info("(native) flash kernel " + flavor)
|
2017-07-04 20:47:03 +00:00
|
|
|
pmb.flasher.run(args, "flash_kernel", flavor)
|
2017-07-19 18:05:34 +00:00
|
|
|
logging.info("You will get an IP automatically assigned to your "
|
|
|
|
"USB interface shortly.")
|
|
|
|
logging.info("Connect to the telnet session and type your LUKS password"
|
|
|
|
" to boot postmarketOS (not necessary if full disk"
|
|
|
|
" encryption is disabled):")
|
|
|
|
logging.info("telnet " + pmb.config.default_ip)
|
|
|
|
logging.info("Then you can connect to your device using ssh:")
|
|
|
|
logging.info("ssh user@" + pmb.config.default_ip)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def list_flavors(args):
|
|
|
|
suffix = "rootfs_" + args.device
|
|
|
|
logging.info("(" + suffix + ") installed kernel flavors:")
|
2017-06-09 17:22:25 +00:00
|
|
|
for flavor in pmb.chroot.other.kernel_flavors_installed(args, suffix):
|
2017-05-26 20:08:45 +00:00
|
|
|
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):
|
2017-07-21 18:26:56 +00:00
|
|
|
raise RuntimeError("The system image has not been generated yet,"
|
|
|
|
" please run 'pmbootstrap install' first.")
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
# Run the flasher
|
|
|
|
logging.info("(native) flash system image")
|
2017-07-04 20:47:03 +00:00
|
|
|
pmb.flasher.run(args, "flash_system")
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def list_devices(args):
|
|
|
|
pmb.flasher.run(args, "list_devices")
|
|
|
|
|
|
|
|
|
2017-08-24 21:07:36 +00:00
|
|
|
def sideload(args):
|
|
|
|
# Mount the buildroot
|
|
|
|
suffix = "buildroot_" + args.deviceinfo["arch"]
|
|
|
|
mountpoint = "/mnt/" + suffix
|
|
|
|
pmb.helpers.mount.bind(args, args.work + "/chroot_" + suffix,
|
|
|
|
args.work + "/chroot_native/" + mountpoint)
|
|
|
|
|
|
|
|
# Missing recovery zip error
|
|
|
|
zip_path = ("/var/lib/postmarketos-android-recovery-installer/pmos-" +
|
|
|
|
args.device + ".zip")
|
|
|
|
if not os.path.exists(args.work + "/chroot_native" + mountpoint +
|
|
|
|
zip_path):
|
|
|
|
raise RuntimeError("The recovery zip has not been generated yet,"
|
|
|
|
" please run 'pmbootstrap install' with the"
|
|
|
|
" '--android-recovery-zip' parameter first!")
|
|
|
|
|
|
|
|
pmb.flasher.run(args, "sideload")
|
|
|
|
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
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)
|
2017-08-24 21:07:36 +00:00
|
|
|
if action == "sideload":
|
|
|
|
sideload(args)
|
2017-07-04 21:03:51 +00:00
|
|
|
if action == "export":
|
2017-09-06 20:14:03 +00:00
|
|
|
logging.info("WARNING: 'pmbootstrap flasher export' is deprecated and"
|
|
|
|
" will be removed soon. The new syntax is 'pmbootstrap"
|
|
|
|
" export'.")
|
|
|
|
pmb.export.frontend(args)
|