Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a wrong flag (--without-default-devices). Test the binary with oreboot/mainboard/sifive/hifive #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
qemu/
test/qemu-system-riscv64
21 changes: 17 additions & 4 deletions README.qemu
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
This qemu was create as follows:
git clone https://github.com/qemu/qemu && cd qemu
git checkout v4.2.0-rc3
git clone https://github.com/qemu/qemu && cd qemu
# this is an old version, use the recent one
# git checkout v4.2.0-rc3

git checkout v5.1.0

mkdir build-riscv64 && cd build-riscv64
# force useless shit off
# force useless shit off - the following applies when target os is Linux, see the configure script
rminnich@xcpu:~/projects/oreboot/qemu$ git diff
diff --git a/configure b/configure
index 6099be1d84..b8376dce77 100755
Expand All @@ -20,9 +24,18 @@ index 6099be1d84..b8376dce77 100755
supported_os="yes"
- libudev="yes"
+ libudev="no"
../configure --target-list=riscv64-softmmu --static --audio-drv-list="" --without-default-devices --disable-vnc
../configure --target-list=riscv64-softmmu --static --audio-drv-list="" --without-default-devices --disable-vnc
make -j16

The following problems were encountered when building on Ubuntu 18.04.
- had to use use this patch as a workaround to a Sphinx-related problem
which terminated the build:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg723079.html

- make sure to install libmount-dev, libselinux1-dev on Ubuntu, or
similar packages for other systems. Also see the part of build.sh that
tweaks the automatically generate config-host.mak.

qemu LICENSE

The QEMU distribution includes both the QEMU emulator and
Expand Down
26 changes: 26 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

git clone https://github.com/qemu/qemu && cd qemu
git checkout v5.1.0

# Apply a patch as a workaround to fix Qemu Sphinx-related problem
git apply ../fix_qemu_sphinx_warning.patch

# Now tweak the build options for Linux target OS. We maintain a patch
# for that purpose.
git apply ../tweak_linux_config_options.patch

echo 'Successfully applied the required patches. Configuring now...'
# Most importantly, note '--static'
mkdir build-riscv64 && cd build-riscv64

../configure --target-list=riscv64-softmmu --static --audio-drv-list="" --disable-vnc

echo "Successfully configured. Building now..."
# On my machine, configuration step did not collect all the dependencies
# required to build Qemu. So manually appending them here, even if they
# are present already.
sudo apt install libblkid-dev libselinux1-dev uuid-dev libmount-dev
awk -F '=' -i inplace '{ if ($1 == "GIO_LIBS") { print $0 " -lblkid -luuid" } else { print $0 } }' config-host.mak

make -j4
31 changes: 31 additions & 0 deletions fix_qemu_sphinx_warning.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/docs/qemu-option-trace.rst.inc b/docs/qemu-option-trace.rst.inc
index 7e09773a9c..e79b0b43fc 100644
--- a/docs/qemu-option-trace.rst.inc
+++ b/docs/qemu-option-trace.rst.inc
@@ -1,7 +1,7 @@

Specify tracing options.

-.. option:: [enable=]PATTERN
+.. option:: -trace [enable=]PATTERN

Immediately enable events matching *PATTERN*
(either event name or a globbing pattern). This option is only
@@ -11,7 +11,7 @@ Specify tracing options.

Use :option:`-trace help` to print a list of names of trace points.

-.. option:: events=FILE
+.. option:: -trace events=FILE

Immediately enable events listed in *FILE*.
The file must contain one event name (as listed in the ``trace-events-all``
@@ -19,7 +19,7 @@ Specify tracing options.
available if QEMU has been compiled with the ``simple``, ``log`` or
``ftrace`` tracing backend.

-.. option:: file=FILE
+.. option:: -trace file=FILE

Log output traces to *FILE*.
This option is only available if QEMU has been compiled with
28 changes: 28 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
~~We can't build softmmu-* targets with --static flag, here is a
[thread](https://lists.gnu.org/archive/html/qemu-devel/2011-11/msg02878.html)
from QEMU mailing list that shows why (and I have experienced more or
less the same - qemu would just not build and complain about missing
libraries). In other words, running programs which are not intended to
be run in user mode is not possible with --static binaries. I have also
found this
[Debian wiki page](https://wiki.debian.org/RISC-V#Manual_qemu-user_installation)
that talks about static qemu-riscv binaries,
and they only mention linux-user target (not softmmu, and we need the
latter).~~ Turns out it is still possible to do so (why - no idea, but it
works and thank QEMU for that)

- A *-linux-user target is for running programs in user mode, for
example, it will run an example from test/usermode/data.

The origial PR failed because device loader was not found. However, it
used a flag --without-default-devices, or something like that, which
could just disable that device.

- [x] Try removing that flag. (Worked)

Also anyway need to update QEMU to version 5.1.0, so all the builds
should be executed with that version.

I thought that using softmmut-* target requries that we also copy
the qemu-img binary to usr/bin, but now seems like that is not a
requirement with --static flag.
Binary file removed qemu-system-riscv64
Binary file not shown.
3 changes: 3 additions & 0 deletions test/example_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

./qemu-system-riscv64 -m 1g -machine sifive_u,start-in-flash=true -nographic -device loader,addr=0x20000000,file=softmmu/hifive -bios none -smp 4
1 change: 1 addition & 0 deletions test/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run ./example_run.sh
Binary file added test/softmmu/hifive
Binary file not shown.
2 changes: 2 additions & 0 deletions test/softmmu/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
These binaries must be successfully run by the static qemu in order
to close the PR.
Binary file added test/softmmu/qemu-riscv
Binary file not shown.
Binary file added test/usermode/date
Binary file not shown.
1 change: 1 addition & 0 deletions test/usermode/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example was taken from u-root project.
23 changes: 23 additions & 0 deletions tweak_linux_config_options.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/configure b/configure
index 2acc4d1465..adbf541c2f 100755
--- a/configure
+++ b/configure
@@ -907,14 +907,14 @@ Haiku)
LIBS="-lposix_error_mapper -lnetwork -lbsd $LIBS"
;;
Linux)
- audio_drv_list="try-pa oss"
- audio_possible_drivers="oss alsa sdl pa"
+ audio_drv_list=""
+ audio_possible_drivers=""
linux="yes"
linux_user="yes"
- kvm="yes"
+ kvm="no"
QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -isystem $PWD/linux-headers $QEMU_INCLUDES"
supported_os="yes"
- libudev="yes"
+ libudev="no"
;;
esac