Commit Graph

67 Commits

Author SHA1 Message Date
Alexey Min 0664a38190
pmb.qemu.run: workaround for new mkinitfs requirements (MR 2138)
It's been 3 months since we switched to new mkinitfs
and we are still fixing consequences.

linux-lts and linux-virt used by qemu-amd64 device package
install vmlinuz-lts (vmlinuz-virt). And qemu run cmdline
passed -kernel vmlinuz which makes it impossible to run
qemu without this change.

With this change proper kernel arg is passed to qemu.

Co-Authored-By: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: Alexey Min <alexeymin@postmarketos.org>
2021-11-06 13:36:34 +01:00
bo41 caf7973e24
args.arch_native: remove (MR 2130)
Replace "args.arch_native" with the direct function call in order to
avoid passing "args" to all functions. This is a step to get rid of this
args-passed-to-all-functions pattern in pmbootstrap.
2021-10-24 14:34:30 +02:00
BO41 58922142ac
pmb.qemu.run.which_qemu: remove args argument (MR 2114)
Drop the argument, as it is not used.
2021-10-10 16:59:21 +02:00
Clayton Craft 45ce639aca
pmb/qemu: add support for single kernel 'flavor' (MR 2093) 2021-09-02 18:18:14 -07:00
Clayton Craft 09794ef832
chroot/other/kernel_flavor_installed: support generic kernel name (MR 2093)
kernel is named /boot/vmlinuz now, looking at the filename will no
longer tell us what flavor it is. This now will look at
/usr/share/kernel, which has always contained the kernel 'flavor', and
since we currently only install 1 kernel these days, guarding this with
pmaports.cfg should be unnecessary. In the worst case (if there are
multiple kernel 'flavors' installed), it'll just grab the first one and
return it.
2021-09-02 18:18:13 -07:00
Caio Fontes aaece05bb7
enforce E501 in pmb/__init__.py and pmb/qemu (MR 2058) 2021-06-06 19:21:30 +02:00
Oliver Smith 59736b601f
pmb.qemu.run: get rid of -show-cursor (MR 2053)
Qemu has been upgraded to 6.0.0 in Alpine edge. This version doesn't
only warn about -show-cursor, it refuses to start up with the option
set.

Fixes: issue 1995
2021-05-02 19:13:35 +02:00
Mark Hargreaves f758812f64
pmbootstrap qemu: fix on systems with more than 8 CPUs (MR 2045)
Fix error when CPU count is more than 8 while emulating a non-native
platform:
  qemu-system-aarch64: Number of SMP CPUs requested (12) exceeds max CPUs supported by machine 'mach-virt' (8)

Signed-off-by: Mark Hargreaves <clashclanacc2602@gmail.coM>
2021-04-04 20:43:40 +02:00
Oliver Smith 7d1c8d29df
pmbootstrap qemu: add --second-storage (MR 2008)
Create a second storage to test installing from SD card to eMMC with the
on-device installer.
2021-01-27 15:01:53 +01:00
Oliver Smith 61f5c20ebb
pmbootstrap qemu: tweak resize_image messages (MR 2008)
Replace "rootfs" with generic image, because the function will be used
for a second storage too. Refer to IMAGE_SIZE, as it is shown in the
help output.
2021-01-27 15:01:52 +01:00
Oliver Smith 1c791da482
treewide: bump copyright to 2021 2021-01-07 23:30:47 +01:00
Oliver Smith 6a4f012bf9
pmb.run.qemu.install_depends: fix with v20.05 (MR 2009)
Don't try to install the recently split up packages if the pmaports
branch is based on Alpine 3.12.

Fixes: 61845c93 ("pmb.run.qemu.install_depends: add new depends (MR 2007)")
2021-01-02 11:23:51 +01:00
Oliver Smith 61845c934b
pmb.run.qemu.install_depends: add new depends (MR 2007)
Alpine's qemu packaging has been split up into more subpackages, so
install them too.

Related: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/15554
2020-12-16 23:20:51 +01:00
Oliver Smith c140912eed
pmb.run.qemu.install_depends: put each on new line (MR 2007) 2020-12-16 23:20:50 +01:00
yarl 864469531c
pmbootstrap qemu: add aarch64 big/little hack (MR 1983)
Workaround for qemu failing with:
  kvm_arm_vcpu_init failed: invalid argument.

Related: https://bugs.linaro.org/show_bug.cgi?id=1443
2020-10-20 22:34:08 +02:00
Daniele Debernardi 5f6b8eaf0e
pmb.qemu: set output="tui" to avoid logging the stdout (!1886) 2020-03-14 08:05:57 +01:00
Daniele Debernardi 9718320829
pmb.qemu: drop --flavor option (!1886)
Since we ask for the kernel flavor during init, only the chosen kernel is
installed, hence there's no need to specify a different one.
2020-03-14 08:05:57 +01:00
Minecrell 7bbc507416
pmb.qemu: use -cpu host for KVM, make configurable with --cpu (!1886)
For KVM the code is run pretty much natively on the host CPU, so all
CPU extensions available on the host CPU can be also used inside the VM.
To expose that information to the VM we should pass "-cpu host", so the
VM is aware of which CPU is in use.

For CPU emulation, QEMU uses a rather minimal CPU on x86_64 by default.
It does not have support for SSE3/4 etc, which may be required for some
applications to work properly (e.g. Android in Anbox). Add a --cpu flag
to make the emulated CPU configurable. Useful values are for example
--cpu max to emulate all implemented CPU features.
2020-03-14 08:05:32 +01:00
Minecrell 76dcf8aa0b
pmb.qemu: add --no-kvm to disable KVM even when available (!1886)
To test QEMU's CPU emulation it is useful to have a switch to disable
KVM, even when it is available (and potentially working fine).

Add --no-kvm for that purpose.
2020-03-14 08:05:32 +01:00
Minecrell b4678f0882
pmb.qemu: make video resolution configurable + consistent (!1886)
For some reason, the SDL display backend changes the video resolution
to 1024x768, while the GTK display keeps it at 640x480.
This is annoying, because at the moment we can only set one display
resolution for a device in postmarketOS (e.g. for the splash screen).

At the moment, the resolution for the splash screen is set to 640x480,
which therefore shows up too small with the default SDL display.

It seems like the display resolution can be only changed in the guest
directly. Linux has a video= kernel parameter that can be used to
implement this. (See: https://www.kernel.org/doc/html/latest/fb/modedb.html)

Let's set 1024x768 by default, but make it configurable through --video.
2020-03-14 08:05:32 +01:00
Minecrell f602df0140
pmb.qemu: add --tablet option for QEMU tablet input device (!1886)
The QEMU 'tablet' input device reports absolute positions instead
of relative mouse pointer movements. This can be used to automatically
grab/release the mouse pointer when entering/leaving the QEMU window,
instead of having to release it with CTRL + ALT + G manually.

This is quite convenient and should be the default option normally,
but at least on my PC the mouse pointer is reported with some vertical
offset for some reason (you can't reach the top and it extends below
the QEMU window...). Let's add it as an optional --tablet option for now.
2020-03-14 08:05:32 +01:00
Minecrell 240e10816d
pmb.qemu: use consistent hardware for all architectures (!1886)
To ensure consistent behavior for QEMU on all architectures,
it is helpful to try to use the same hardware elements where possible.

A few examples of current inconsistent behavior:
  - x86_64 uses a SCSI disk, while aarch64 uses virtio-blk
  - x86_64 uses e1000 network, while aarch64 uses virtio-net-device
  - x86_64 uses PS/2 mouse, while aarch64 uses usb-mouse
  - only x86_64 prints serial output to console

At least the virtio components are usually independent of the selected
architecture, so we can use them for both architectures.

This commit makes most of the hardware configuration shared:
  - Redirect serial output to stdio
  - virtio-blk for the disk image
  - virtio-gpu-pci (this was already implicit for both architectures)
  - virtio-net-pci for the network interface
  - virtio-mouse-pci/virtio-keyboard-pci as input devices
  - intel-hda for audio

We also set -nodefaults to avoid setting up unneeded devices
especially for x86_64.
2020-03-14 08:05:32 +01:00
Minecrell 81b3aade07
pmb.qemu: drop telnet port forwarding (!1886)
Now that we try to use the IP assigned by QEMU via DHCP,
the debug-shell is no longer working via telnet.
This is because the VM does not have any IP assigned when it is running.

We would need to start a DHCP client from the initfs to make it work.
busybox provides both udhcpc (client) and udhcpd (server) so this is
not a big problem. But the question is: Is it worth it?

The debug-shell will be only used for debugging, and NetworkManager
handles starting a proper DHCP client once the rootfs is mounted.
Meanwhile the debug-shell can be also accessed via serial output/input,
(available in the pmbootstrap stdout/stdin). So overall it does not
seem worth the effort. Let's just recommend using serial instead.
2020-03-14 08:05:32 +01:00
Minecrell 79a8d04835
pmb.qemu: do not try to change default IP range (!1886)
The current network setup has weird side effects.
Normally, QEMU would automatically make the guest set up necessary
IP routes through its integrated DHCP server.
When running QEMU through pmbootstrap they are missing.

First, we change the DHCP range in a way that could potentially
conflict with default IPs used for QEMU's own services:
QEMU has the default gateway at <network>.2, and DNS at <network>.3.
We set the DHCP range to start at <network>.1, and will therefore
potentially give out one of these addresses (QEMU's default starts at
<network>.15).
See: https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29

In practice this does not cause immediate problems because there is
just one guest in the network, and it will get <network>.1, which is
not used by QEMU.

More problematic is that we start a DHCP server from postmarketOS
at the same time (normally used for the USB network) and there are
actually two DHCP servers running at the same time.

QEMU's user networking is local to the process, therefore it is not
possible to access the QEMU guest through its IP from the host.
That's why we have the port forwardings so you can access SSH at
localhost:2222 for example.

In practice the network interface in the QEMU guest is only used to
access the Internet. For that, we don't care which IP address we get,
we just want to get a working setup (IP + routes + DNS) automatically
through DHCP.

To make this work nicely we just need to stop trying to fit QEMU's
network setup into our usual setup for USB networking. When we remove
the custom DHCP option, and avoid starting a DHCP server from postmarketOS
(deviceinfo_disable_dhcpd) everything is suddenly working fine. :)
2020-03-14 08:05:32 +01:00
Minecrell c7455f7a21
pmb.qemu: drop vexpress (armv7) support (!1886)
device-qemu-vexpress appears to be completely broken at the moment.
I was not able to make it show anything, get a log or even just get
any indication that it is actually doing something.

In general, it does also not fit well to the other QEMU ports.
The vexpress machine type in QEMU seems to be quite limited,
e.g. it has no PCIe bus and therefore it is impossible to configure it
with virtio-gpu. (Unlike already configured for x86_64 and aarch64).

I had some success with a setup similar to aarch64 with -M virt,highmem=off
but was unable to make it work in the end:

  - Alpine's virt kernel was missing some options preventing boot completely
  - Alpine's lts kernel was missing PCI support for virtio-gpu
  - Even after adding the options the VM usually freezed after boot

Overall it does not quite seem worth the effort at the moment,
compared to how well x86_64 and aarch64 are working.

In any case, vexpress is too different (and broken) to continue maintaining it.
2020-03-14 08:05:32 +01:00
Minecrell f536fd9cb9
pmb.qemu: use current device instead of requiring --arch (!1886)
When using pmbootstrap, you usually select the device you want to work
on using 'pmbootstrap init', generate the rootfs and can then run more
commands in the context of the device.

The same needs to be done before using QEMU (to generate the rootfs).
But for some reason 'pmbootstrap qemu' requires setting the --arch
parameter when running QEMU for a foreign architecture, even when the
device is still selected in pmbootstrap.

Even more confusing is that setting "--arch arm" always selects
device-qemu-vexpress, but this is not immediately clear from the name.

Let's make this a lot more intuitive by making sure there is a QEMU
device selected when running 'pmbootstrap qemu'. We can then use the
device information to infer the architecture automatically.
2020-03-14 08:05:32 +01:00
Minecrell 32dca18eb6
pmb.qemu: simplify --display by introducing --no-gl (!1886)
At the moment, the --display argument is a bit complicated to use.
A common use would be to switch between the UIs (sdl, gtk, none)
or to enable the software rasterizer. Split the two use cases
to separate arguments to make it more intuitive.
2020-03-14 08:05:32 +01:00
Minecrell d1f5753c89
pmb.qemu: always use virtio-gpu (!1886)
So far we tried to configure virtio-gpu using "-vga virtio" only
when the target architecture matches the host architecture.
But that's actually not what it depends on.

virtio-gpu and virgl can be also used when emulating a foreign
architecture. In fact, we already force usage of virtio-gpu for
aarch64 through "-device virtio-gpu-pci".

However, the "-vga virtio" parameter does not exist on aarch64,
no matter if we run QEMU natively on aarch64 or emulate it on x86_64.

(Apparently, -vga is mainly about legacy VGA framebuffer stuff that
we don't necessarily need. This is quite visible since the display
stays uninitialized on aarch64 until the kernel driver loads,
whereas on x86_64 it is initialized by the BIOS...)

In other words, "-vga virtio" belongs to the parameters specific to x86_64.

Now that we have removed the setup question for the Mesa driver to use
(since it was ineffective), it would still be nice to have some way to
choose if you want to use virtio-gpu/virgl or not.

But actually virtio-gpu can be also used with swrast, without virgl.
This happens automatically when QEMU is started without GL support.
We already have a --display parameter for this, so it is possible to
force swrast by using "--display sdl" (instead of the default sdl,gl=on).

Overall this allows simplifying the QEMU package setup because there is
only a single GPU driver in use (virtio-gpu) instead of the 3 we had before
(virtio, qxl, bochs).
2020-03-14 08:05:32 +01:00
Minecrell 320b2faa4c
pmb.qemu: remove QEMU mesa driver setup question (!1886)
mesa-dri-swrast and mesa-dri-virtio are both provided by mesa-dri-gallium
now, so this option does not have much use anymore. With both selections,
exactly the same packages are installed.
2020-03-14 08:05:32 +01:00
Minecrell cb1f68817f
pmb.qemu: drop spice support (!1886)
The SPICE UI option tends to be broken (see #1836), and even when it is
working, it is not working particularly well. QXL requires special handling
in our QEMU packages, when now virtio-gpu (virgl) is working quite well overall.

Apparently it is possible to use virgl with SPICE; but only when using
a Unix socket instead of a TCP port. That again is a bit complicated
because we run QEMU outside the chroot and the SPICE client within.

Overall it does no longer seem to be worth the effort.
The default QEMU UI is working just fine (for the purposes of testing
postmarketOS at least).
2020-03-14 08:05:32 +01:00
Oliver Smith f21c216a26
Cosmetic: use SPDX license header (!1877)
While at it, also remove unnecessary "#!/usr/bin/env python3" in files
that only get imported, and adjust other empty/comment lines in the
beginnings of the files for consistency.

This makes files easier to read, and makes the pmbootstrap codebase more
consistent with the build.postmarketos.org codebase.
2020-02-24 03:11:10 +03:00
Minecrell d3fede3262
pmb.qemu.run.install_depends: Fix Mesa Gallium DRI depends (!1867)
Commit 43520967 ("pmb.qemu.run.install_depends: adjust to mesa pkgs (!1865)")
replaced mesa-dri-swrast, mesa-dri-virtio and mesa-dri-vmwgfx with
mesa-va-gallium. But the Gallium DRI drivers are actually provided by
mesa-dri-gallium. mesa-va-gallium contains libva drivers for hardware
video acceleration.

Fortunately this did not break anything because mesa-dri-gallium
was still installed as dependency of mesa-dri-ati/intel/nouveau.

QEMU does not make use of libva, so lets just replace mesa-va-gallium
with mesa-dri-gallium. While we are at it, stop depending on the
deprecated mesa-dri-ati/intel/nouveau packages. Those are only kept
for compatibility reasons and install more dependencies than necessary.
2020-01-31 04:10:50 +01:00
Oliver Smith 4352096783
pmb.qemu.run.install_depends: adjust to mesa pkgs (!1865)
Adjust the mesa related packages installed for running in qemu, after
the mesa APKBUILD in Alpine was changed. Install mesa-va-gallium instead
of:
* mesa-dri-freedreno
* mesa-dri-swrast
* mesa-dri-virtio
* mesa-dri-vmwgfx

Fix error in pmbootstrap-qemu CI test:
ERROR: Could not find dependency 'mesa-dri-freedreno' in any aports folder or APKINDEX.

Related: 298e20d04f
2020-01-26 21:05:42 +01:00
Minecrell 66fdb74b5b
qemu: Make QEMU audio backend configurable (!1859)
At the moment we assume that everyone running QEMU is either using
ALSA, or has the ALSA PulseAudio plugin configured on the host system.
(Since we run QEMU outside of the chroot at the moment, configuration
files are read from the host system instead of the chroot...)

Other distributions have much wider support for PulseAudio,
so not everyone will actually have the ALSA PulseAudio plugin configured.
In that case, it is better to use QEMU's PulseAudio backend since that
does not require any configuration. It also lets us drop the alsa-lib
fork, since that was only needed for loading the ALSA PulseAudio plugin.

In general, it seems difficult to detect which audio backend the user
wants to run (if any). Selecting the wrong one results in ugly warnings
when running QEMU. So let's not assume any by default, and add a
--audio option instead which accepts one of QEMU's audio backends
(alsa, pa or sdl).
2020-01-20 00:53:52 +03:00
Oliver Smith 948e3f931f
Change copyright to 2020 2020-01-06 02:43:00 +01:00
Daniele Debernardi d145f88276
pmb/qemu/run.py: add audio support (!1840)
Changes:
  * Added the ALSA_PLUGIN_DIRS environment variable otherwise it tries
    to load the plugins of the host pc and they fails.
  * Added the /usr/lib/pulseaudio path to the library-path argument
  * Added the audiodev and soundhw parameters to the qemu command
  * Added the required packages necessary to be installed in the chroot
2019-12-28 01:42:40 +01:00
Daniele Debernardi b33894c197
qemu/spice: use virt-viewer client directly from chroot (!1793) 2019-07-05 20:51:01 +02:00
Luca Weiss 2ad8b66ccc
Fix case sensitivity: Qemu => QEMU (!1800) 2019-07-05 20:27:12 +02:00
Martijn Braam 75411694ff
qemu: limit cores to 4 in qemu-vexpress (!1797)
qemu-system-vexpress supports 1-4 cores, this clamps the smp core count
to 4 on host machines with more cores.
2019-07-03 22:43:30 +02:00
Robert Yang ab4f3f4004 qemu: Load GTK modules/resources from chroot (!1749)
We are running qemu that is installed in the chroot. The GTK framework
needs to be configured to load resources from the chroot as well.

https://developer.gnome.org/gtk3/stable/gtk-running.html
2019-02-15 16:39:07 +01:00
Robert Yang 8896209afc
qemu: enable keyboard and mouse for aarch64 (!1750)
Tested keyboard and mouse with weston and mate interface. MATE suffers
from the invisible cursor bug though.
2019-02-11 21:15:02 +01:00
Robert Yang ff4c35a025
qemu: set smp flag to CPU core count (!1751)
The default is single core. Modern PCs have many cores so use them.
2019-02-11 21:03:13 +01:00
Robert Yang bd7ea8330e qemu: Use QEMU_MODULE_DIR env variable (!1736)
The upstream patch uses this environment variable. With pmaports temp/qemu
removed, qemu should be run with the env var used in upstream.
2019-01-02 16:48:15 -05:00
Oliver Smith f16bdaf0ca
Update copyright to 2019
Happy new year \o/
2019-01-02 09:31:20 +01:00
raingloom 3eb80a3e55 don't install qemu when using --host-qemu 2018-09-01 13:14:52 +02:00
ryang e82b7e427d qemu: Don't use chroot based env variables when running spice client
We are running the Spice client installed on the host system. It doesn't
need to be run with env variables that point to chroot libraries.
2018-08-01 22:24:34 +00:00
Oliver Smith 0d7802d7ef
s/system partition/rootfs: fix remaining mentions
Follow-up to !1373, where `pmbootstrap flasher flash_system` was
replaced with `pmbootstrap flasher flash_rootfs`. We still had used
terms like "system partition" in a lot of places.

This commit replaces it everywhere, so it's clear that we're talking
about the pmOS rootfs (which may or may not be installed to Android's
system partition).
2018-07-15 23:41:31 +02:00
Oliver Smith 8268dc0e3d pmbootstrap: kill process if silent for 5 minutes (rewrite logging) 2018-07-14 01:13:28 +00:00
Oliver Smith b56e5cf281 pmb qemu: Properly escape kernel commandline 2018-07-11 19:09:34 +00:00
Oliver Smith f6dcfbfe56 Use Alpine's QEMU rather than host system QEMU (v2) 2018-07-06 19:50:59 +00:00