diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70b481c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +qemu/ +test/qemu-system-riscv64 \ No newline at end of file diff --git a/README.qemu b/README.qemu index 1eade08..59e8308 100644 --- a/README.qemu +++ b/README.qemu @@ -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 @@ -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 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..46a722b --- /dev/null +++ b/build.sh @@ -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 diff --git a/fix_qemu_sphinx_warning.patch b/fix_qemu_sphinx_warning.patch new file mode 100644 index 0000000..463800b --- /dev/null +++ b/fix_qemu_sphinx_warning.patch @@ -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 diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..304a920 --- /dev/null +++ b/notes.md @@ -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. \ No newline at end of file diff --git a/qemu-system-riscv64 b/qemu-system-riscv64 deleted file mode 100755 index bf8c4f2..0000000 Binary files a/qemu-system-riscv64 and /dev/null differ diff --git a/test/example_run.sh b/test/example_run.sh new file mode 100755 index 0000000..1429aaa --- /dev/null +++ b/test/example_run.sh @@ -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 diff --git a/test/notes.md b/test/notes.md new file mode 100644 index 0000000..756429b --- /dev/null +++ b/test/notes.md @@ -0,0 +1 @@ +run ./example_run.sh \ No newline at end of file diff --git a/test/softmmu/hifive b/test/softmmu/hifive new file mode 100755 index 0000000..da6213b Binary files /dev/null and b/test/softmmu/hifive differ diff --git a/test/softmmu/notes.md b/test/softmmu/notes.md new file mode 100644 index 0000000..8dfcc4a --- /dev/null +++ b/test/softmmu/notes.md @@ -0,0 +1,2 @@ +These binaries must be successfully run by the static qemu in order +to close the PR. \ No newline at end of file diff --git a/test/softmmu/qemu-riscv b/test/softmmu/qemu-riscv new file mode 100755 index 0000000..7390a1c Binary files /dev/null and b/test/softmmu/qemu-riscv differ diff --git a/test/usermode/date b/test/usermode/date new file mode 100755 index 0000000..e2a08cb Binary files /dev/null and b/test/usermode/date differ diff --git a/test/usermode/notes.md b/test/usermode/notes.md new file mode 100644 index 0000000..6fa6ce5 --- /dev/null +++ b/test/usermode/notes.md @@ -0,0 +1 @@ +This example was taken from u-root project. \ No newline at end of file diff --git a/tweak_linux_config_options.patch b/tweak_linux_config_options.patch new file mode 100644 index 0000000..a3ed73e --- /dev/null +++ b/tweak_linux_config_options.patch @@ -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 +