From 3042c942d871b40a3d7dbb06079d29babefb780d Mon Sep 17 00:00:00 2001 From: Emanuel Sprung Date: Mon, 11 Nov 2019 13:58:18 +0100 Subject: [PATCH] Toolchain: Add QEMU build script and improve documentation Added a script to build QEMU from source as part of the Toolchain. The script content could be in BuildIt.sh but has been put in a seperate file to make the build optional. Added PATH=$PATH to sudo calls to hand over the Toolchain's PATH setup by UseIt.sh. This enabled the script's to use the QEMU contained in the SerenityOS toolchain. Deleted old documentation in Meta and replaced it by a new documentation in the Toolchain folder. --- Kernel/makeall.sh | 2 +- Kernel/sync.sh | 2 +- Meta/BuildInstructions.md | 101 -------------------------- Toolchain/.gitignore | 3 + Toolchain/BuildQemu.sh | 66 +++++++++++++++++ Toolchain/README.md | 144 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 215 insertions(+), 103 deletions(-) delete mode 100644 Meta/BuildInstructions.md create mode 100644 Toolchain/.gitignore create mode 100755 Toolchain/BuildQemu.sh create mode 100644 Toolchain/README.md diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index 5e40c726089..f594fdbc2c4 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -105,4 +105,4 @@ for targ in $build_targets; do fi done -sudo -E ./build-image-qemu.sh +sudo -E PATH=$PATH ./build-image-qemu.sh diff --git a/Kernel/sync.sh b/Kernel/sync.sh index bb30ba4a832..1deccd8090d 100755 --- a/Kernel/sync.sh +++ b/Kernel/sync.sh @@ -1,3 +1,3 @@ #!/bin/sh -sudo -E ./build-image-qemu.sh +sudo -E PATH=$PATH ./build-image-qemu.sh diff --git a/Meta/BuildInstructions.md b/Meta/BuildInstructions.md deleted file mode 100644 index b24d3cc33dc..00000000000 --- a/Meta/BuildInstructions.md +++ /dev/null @@ -1,101 +0,0 @@ -# Building the Serenity operating system - -Let's start with a quick guide to building the i686-pc-serenity toolchain. - -I keep my toolchain in /opt/cross (so /opt/cross/bin needs to be in $PATH) and my Serenity sources are in $HOME/src/serenity - -You need to adjust these so they fit your system. - -## Dependencies: - -First off, GCC needs MPFR, MPC and GMP. On Ubuntu, this is as simple as: - - sudo apt install libmpfr-dev libmpc-dev libgmp-dev - -For Serenity, we will need e2fsprogs and QEMU: - - sudo apt install e2fsprogs qemu-system-i386 - -Note: there is a problem with the PS/2 keyboard/mouse emulation in QEMU 2.11.1 as packaged in Ubuntu's LTS releases. If you have any strange behaviour with missing keyboard inputs or jittery mouse movement, try building QEMU from source. 2.12.1, 3.0.1, 3.1.0, and 4.0.0 are all confirmed as working when built from source. - -## Binutils: - -Download GNU binutils-2.32 and apply the patch serenity/Meta/binutils-2.32-serenity.patch - -Make a build directory next to the binutils source directory. - -In the build directory, run configure: - - ../binutils-2.32/configure \ - --prefix=/opt/cross \ - --target=i686-pc-serenity \ - --with-sysroot=$HOME/src/serenity/Root \ - --disable-nls - - -Then build and install: - - make - sudo make install - -## Serenity LibC and LibM headers: - -Before we can build GCC, we need to put the Serenity LibC headers where GCC can find them. So go into serenity/LibC/ and install them: - - ./install.sh - -Then do the same in serenity/LibM/: - - ./install.sh - -Don't worry about any error messages from the above commands. We only care about copying the headers to the right place at this time. - -## GCC (part 1): - -Okay, then let's build GCC. - -Download GNU GCC-8.3.0 and apply the patch serenity/Meta/gcc-8.3.0-serenity.patch - -Make a build directory next to the GCC source directory. - -In the build directory, run configure: - - ../gcc-8.3.0/configure \ - --prefix=/opt/cross \ - --target=i686-pc-serenity \ - --with-sysroot=$HOME/src/serenity/Root \ - --with-newlib \ - --enable-languages=c,c++ - -Then build and install: - - make all-gcc all-target-libgcc - sudo make install-gcc install-target-libgcc - -## Serenity LibC for GCC: - -Now let's go into serenity/LibC/ and build the C library. This is required in order to complete the GCC build. - - make - ./install.sh - -The C library is now installed in serenity/Root/ and we can build GCC's libstdc++... - -## GCC (part 2): - -Go back to the GCC build directory and finish building libstdc++: - - make all-target-libstdc++-v3 - sudo make install-target-libstdc++-v3 - -## Serenity (Full build) - -If everything worked out, you now have the i686-pc-serenity toolchain ready and we can build Serenity. - -Go into serenity/Kernel and build it: - - ./makeall.sh - -Then take it for a spin: - - ./run diff --git a/Toolchain/.gitignore b/Toolchain/.gitignore new file mode 100644 index 00000000000..0146895ec6b --- /dev/null +++ b/Toolchain/.gitignore @@ -0,0 +1,3 @@ +# Created by QEMU build +config-temp +config.log diff --git a/Toolchain/BuildQemu.sh b/Toolchain/BuildQemu.sh new file mode 100755 index 00000000000..d43dea9ec7d --- /dev/null +++ b/Toolchain/BuildQemu.sh @@ -0,0 +1,66 @@ +#!/bin/bash +set -e + +# This file will need to be run in bash, for now. + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +echo "$DIR" + +TARGET=i686-pc-serenity +PREFIX="$DIR/Local" +SYSROOT="$DIR/../Root" + +QEMU300_MD5SUM="6a5c8df583406ea24ef25b239c3243e0" +QEMU410_MD5SUM="cdf2b5ca52b9abac9bacb5842fa420f8" + +QEMU_VERSION="qemu-4.1.0" +QEMU_MD5SUM="${QEMU410_MD5SUM}" + +echo PREFIX is "$PREFIX" +echo SYSROOT is "$SYSROOT" + +mkdir -p "$DIR/Tarballs" + +source "$DIR/UseIt.sh" + +pushd "$DIR/Tarballs" + + md5="$(md5sum $QEMU_VERSION.tar.xz | cut -f1 -d' ')" + echo "qemu md5='$md5'" + if [ ! -e "$QEMU_VERSION.tar.xz" ] || [ "$md5" != "$QEMU_MD5SUM" ] ; then + rm -f qemu-3.0.0.tar.xz + curl -O "https://download.qemu.org/$QEMU_VERSION.tar.xz" + + if [ "$md5" != "$QEMU_MD5SUM" ] ; then + echo "qemu md5 sum mismatching, please run script again." + exit 1 + fi + else + echo "Skipped downloading $QEMU_VERSION" + fi + + if [ ! -d "$QEMU_VERSION" ]; then + echo "Extracting qemu..." + tar -xf "$QEMU_VERSION.tar.xz" + else + echo "Skipped extracting qemu" + fi +popd + +mkdir -p "$PREFIX" +mkdir -p "$DIR/Build/qemu" + +if [ -z "$MAKEJOBS" ]; then + MAKEJOBS=$(nproc) +fi + +pushd "$DIR/Build/" + pushd qemu + "$DIR"/Tarballs/$QEMU_VERSION/configure --prefix="$PREFIX" \ + --target-list=i386-softmmu \ + --enable-gtk || exit 1 + make -j "$MAKEJOBS" || exit 1 + make install || exit 1 + popd +popd diff --git a/Toolchain/README.md b/Toolchain/README.md new file mode 100644 index 00000000000..92dafa5374e --- /dev/null +++ b/Toolchain/README.md @@ -0,0 +1,144 @@ +# Serenity Toolchain - Building the Serenity operating system + +This directory contains all toolchain related files. E.g. build scripts for +the cross compilation toolchain and build toolchain for ports. + +- [Serenity Toolchain - Building the Serenity operating system](#serenity-toolchain---building-the-serenity-operating-system) + - [Cross Compile Toolchain](#cross-compile-toolchain) + - [Dependencies](#dependencies) + - [Serenity (Full build)](#serenity-full-build) + - [Running SerenityOS in an emulator](#running-serenityos-in-an-emulator) + - [QEMU installation / compilation](#qemu-installation--compilation) + - [Passing custom arguments to QEMU](#passing-custom-arguments-to-qemu) + +## Cross Compile Toolchain + +The cross compile toolchain contains + +- binutils 2.32 + +- GCC 8.3.0 + +These are built from source with some patches applied. + +### Dependencies + +- Build Essentials + + ```bash + sudo apt install build-essential curl libmpfr-dev libmpc-dev libgmp-dev + ``` + +- GCC 8 + + ```bash + sudo add-apt-repository ppa:ubuntu-toolchain-r/test + sudo apt-get install gcc-8 g++-8 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8 + ``` + +- e2fsprogs + + ```bash + sudo apt install e2fsprogs + ``` + +## Serenity (Full build) + +If everything worked out, you now have the **i686-pc-serenity** toolchain ready and we can build Serenity. + +Go into `Kernel/` folder and build it: + +```bash +./makeall.sh +``` + +Then take it for a spin: + +```bash +./run +``` + +See next chapter for more options on running SerenityOS in an emulator. + +## Running SerenityOS in an emulator + +To run SerenityOS in a specific emulator, call the `./run` command in the `Kernel/` folder: + +```bash +./run +``` + +There are several emulators supported to run SerenityOS in: + +- Bochs + + ```bash + sudo apt install bochs + ``` + + Add the `b` argument to the run script, to use bochs emulator: + + ```bash + ./run b + ``` + +- QEMU + QEMU with networking enabled is used by default, when no extra argument is passed to the run script. + There are some extra arguments to run QEMU emulator with specific settings: + + Add the `qn` argument to the run script to use QEMU without networking: + + ```bash + ./run qn + ``` + + Add the `qgrub` argument to the run script to use QEMU with grub bootloader: + + ```bash + ./run qgrub + ``` + + Add the `qtext` argument to the run script to use QEMU with textmode: + + ```bash + ./run qtext + ``` + + Note: there is a problem with the PS/2 keyboard/mouse emulation in QEMU 2.11.1 as packaged in Ubuntu's LTS releases. + If you have any strange behaviour with missing keyboard inputs or jittery mouse movement, try building QEMU from + source as described in [QEMU](#qemu-installation--compilation). 2.12.1, 3.0.1, 3.1.0, and 4.0.0 are all confirmed as working when built from source. + +### QEMU installation / compilation + +If your distribution contains a QEMU version > 2.11.1, then you can just install it via + +```bash +sudo apt install qemu-system-i386 qemu-utils +``` + +If that is not the case, you can build QEMU from sources with the provided script `BuildQemu.sh`. +To do so, some build dependencies have to be installed first: + +```bash +sudo apt-get build-dep qemu +sudo apt-get install libgtk-3-dev +``` + +The source-repositories of your distribution have to be enabled to install the build-dep's. + +`BuildQemu.sh` has been tested with QEMU 3.0.0 and 4.1.0 (which is default). If you +want to build QEMU 3.0.0, change the variable `QEMU_VERSION` and `QEMU_MD5SUM` accordingly: + +```bash +QEMU_VERSION="qemu-3.0.0" +QEMU_MD5SUM="${QEMU300_MD5SUM}" +``` + +### Passing custom arguments to QEMU + +You can modify the environment variable `SERENITY_EXTRA_QEMU_ARGS` to your needs or hand it over directly before the run command: + +```bash +SERENITY_EXTRA_QEMU_ARGS="-nographic" ./run qtext +```