From 7d1c8d29dfdef702aa3c2a75d04bc9a60d247a1b Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 14 Dec 2020 18:48:09 +0100 Subject: [PATCH] pmbootstrap qemu: add --second-storage (MR 2008) Create a second storage to test installing from SD card to eMMC with the on-device installer. --- pmb/parse/arguments.py | 5 +++++ pmb/qemu/run.py | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 940e68bd..160e10ff 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -276,6 +276,11 @@ def arguments_qemu(subparser): ret.add_argument("--cmdline", help="override kernel commandline") ret.add_argument("--image-size", default="4G", help="set rootfs size, e.g. 2048M or 2G (default: 4G)") + ret.add_argument("--second-storage", metavar="IMAGE_SIZE", + help="add a second storage with the given size (default:" + " 4G), gets created if it does not exist. Use to" + " test install from SD to eMMC", + nargs="?", default=None, const="4G") ret.add_argument("-m", "--memory", type=int, default=1024, help="guest RAM (default: 1024)") ret.add_argument("-p", "--port", type=int, default=2222, diff --git a/pmb/qemu/run.py b/pmb/qemu/run.py index 9bb5dfc4..14f32f11 100644 --- a/pmb/qemu/run.py +++ b/pmb/qemu/run.py @@ -31,6 +31,18 @@ def system_image(args): return path +def create_second_storage(args): + """ + Generate a second storage image if it does not exist. + :returns: path to the image or None + """ + path = f"{args.work}/chroot_native/home/pmos/rootfs/{args.device}-2nd.img" + pmb.helpers.run.root(args, ["touch", path]) + pmb.helpers.run.root(args, ["chmod", "a+w", path]) + resize_image(args, args.second_storage, path) + return path + + def which_qemu(args, arch): """ Finds the qemu executable or raises an exception otherwise @@ -67,7 +79,7 @@ def create_gdk_loader_cache(args): return rootfs_native + custom_cache_path -def command_qemu(args, arch, img_path): +def command_qemu(args, arch, img_path, img_path_2nd=None): """ Generate the full qemu command with arguments to run postmarketOS """ @@ -137,7 +149,11 @@ def command_qemu(args, arch, img_path): command += ["-m", str(args.memory)] command += ["-serial", "stdio"] + command += ["-drive", "file=" + img_path + ",format=raw,if=virtio"] + if img_path_2nd: + command += ["-drive", "file=" + img_path_2nd + ",format=raw,if=virtio"] + if args.qemu_tablet: command += ["-device", "virtio-tablet-pci"] else: @@ -271,11 +287,15 @@ def run(args): arch = pmb.parse.arch.alpine_to_qemu(args.deviceinfo["arch"]) img_path = system_image(args) + img_path_2nd = None + if args.second_storage: + img_path_2nd = create_second_storage(args) + if not args.host_qemu: install_depends(args, arch) logging.info("Running postmarketOS in QEMU VM (" + arch + ")") - qemu, env = command_qemu(args, arch, img_path) + qemu, env = command_qemu(args, arch, img_path, img_path_2nd) # Workaround: QEMU runs as local user and needs write permissions in the # rootfs, which is owned by root