diff --git a/SBSA-QEMU/Code/scripts/.gitignore b/SBSA-QEMU/Code/scripts/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..bcbfa4c5bf2c71fa5ace622e59221f3a326af3bc --- /dev/null +++ b/SBSA-QEMU/Code/scripts/.gitignore @@ -0,0 +1,11 @@ +# From building initramfs +linux +u-root.initramfs.linux_arm64.cpio + +# From building EDK II +sbsa-linuxboot +SBSA_FLASH0.fd +SBSA_FLASH1.fd + +# From running QEMU to boot an Architecture Compliance Suite (ACS) image +es_acs_live_image.img diff --git a/SBSA-QEMU/Code/scripts/ImageBuildscript.sh b/SBSA-QEMU/Code/scripts/ImageBuildscript.sh index 103cb42b65ecbe0a66f365636ad3a38ce1ea2a2c..70e534faaf8fe4bfdfc4a5322bc70ae9181e3a6a 100755 --- a/SBSA-QEMU/Code/scripts/ImageBuildscript.sh +++ b/SBSA-QEMU/Code/scripts/ImageBuildscript.sh @@ -34,6 +34,8 @@ # ramdisk is stored. export WORKSPACE=$PWD +export PATH=/usr/local/go/bin/:$PATH + if ! command -v go >/dev/null 2>&1; then echo "$0: You need to install Go 1.17" echo "$0: Visit https://go.dev/dl/" @@ -56,7 +58,7 @@ fi # Install u-root echo "$0: Installing u-root" GO111MODULE=off go get github.com/u-root/u-root -export PATH=$PATH:$HOME/go/bin +export PATH=$PATH:$(go env GOPATH)/bin #Generate initramfs and copy to workspace echo "$0: Building initramfs" diff --git a/SBSA-QEMU/Code/scripts/InstallGo.sh b/SBSA-QEMU/Code/scripts/InstallGo.sh deleted file mode 100755 index 400d73c5a40edfe2849786a201aa1b69a0a5c6b2..0000000000000000000000000000000000000000 --- a/SBSA-QEMU/Code/scripts/InstallGo.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# Neither the name of ARM nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific -# prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# Remove old versions of Go -echo "$0: Uninstalling old versions of Go" -sudo rm -rf /usr/local/go/ - -# Download and untar -arch=$(uname -m) -if [[ "$arch" == "aarch64" ]]; then - archive=go1.17.linux-arm64.tar.gz -elif [[ "$arch" == "x86_64" ]]; then - archive=go1.17.linux-amd64.tar.gz -else - echo "$0: Unrecognized architecture" - exit 1 -fi - -echo "$0: Downloading Go 1.17" -wget https://go.dev/dl/$archive -echo "$0: Installing Go 1.17" -sudo tar -C /usr/local/ -xzf $archive -rm -f $archive - -# Add to PATH -sed -i '\|export PATH=$PATH:/usr/local/go/bin/|d' ~/.bash_profile -echo 'export PATH=$PATH:/usr/local/go/bin/' >> ~/.bash_profile -source ~/.bash_profile diff --git a/SBSA-QEMU/Code/scripts/InstallQemu.sh b/SBSA-QEMU/Code/scripts/InstallQemu.sh deleted file mode 100755 index 6f17ba76fd644ec0073ee4745d4c88be29c6763a..0000000000000000000000000000000000000000 --- a/SBSA-QEMU/Code/scripts/InstallQemu.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# Neither the name of ARM nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific -# prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -export INSTALL_PATH=/usr/local/ -git clone https://github.com/qemu/qemu -cd qemu -mkdir -p build-native -cd build-native -../configure --target-list=aarch64-softmmu --prefix=$INSTALL_PATH -sudo make install diff --git a/SBSA-QEMU/Code/scripts/Run.sh b/SBSA-QEMU/Code/scripts/Run.sh index 9fffc4414fde901e6f3fdac00cfec28e8b9a22f9..d141d00794be88bf6c2a4935b9db1b3d0e636df5 100755 --- a/SBSA-QEMU/Code/scripts/Run.sh +++ b/SBSA-QEMU/Code/scripts/Run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2022, ARM Limited and Contributors. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -28,6 +28,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +# Change based on location of QEMU installation +export INSTALL_PATH=/usr/local + # Optionally, if an argument is given, run that image. if [[ $# -gt 0 ]]; then if [[ ! -f "$1" ]]; then @@ -57,4 +60,14 @@ else fi # `set -x` will explicitly print the command that we run -(set -x; qemu-system-aarch64 -m 1024 -M sbsa-ref -pflash SBSA_FLASH0.fd -pflash SBSA_FLASH1.fd -nographic $HDA) +# Add manual install location to PATH +( + PATH=$PATH:$INSTALL_PATH/bin/qemu-system-aarch64 + set -x + qemu-system-aarch64 \ + -m 1024 \ + -M sbsa-ref \ + -drive file=SBSA_FLASH0.fd,format=raw,if=pflash \ + -drive file=SBSA_FLASH1.fd,format=raw,if=pflash \ + -nographic $HDA +) diff --git a/SBSA-QEMU/README.md b/SBSA-QEMU/README.md index 0854a5ae2c14cc856189a51d02d7354825c80ba5..195aa1b41d3206d3012150a2c8f44d625cb1d0f1 100644 --- a/SBSA-QEMU/README.md +++ b/SBSA-QEMU/README.md @@ -5,13 +5,12 @@ [[_TOC_]] - - +## Demo Videos + ![Demo: Replacing UEFI shell](DemoMedia/ReplaceUefiShell/LinuxbootOnSbsaqemuDemo.webm) ![Demo: Using Platform Boot Manager and `uinit`](DemoMedia/PlatformBootMgrDemo/automaticRun.webm) - ## 1 Background ### 1.1 What is this guide? @@ -29,18 +28,18 @@ Help to improve this guide! Any comments or questions contact Frances Conboy at These system details purely serve as an outline of the systems this build process was validated on, they are not requirements. -x86_64: +x86_64 (as of June 22, 2023): - 64 GB of RAM - 56 threads - - Ubuntu 18.04 LTS + - Ubuntu 22.04.2 LTS - gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu cross compiler - - Go 1.14 - - QEMU emulator version 6.1.50 (v6.1.0-1446-g4d1a525dfa) + - Go 1.19 + - QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.11) -AArch64: +AArch64 (as of May 20, 2022): - - 251 GB of RAM + - 256 GB of RAM - 224 threads - Fedora Linux 36 (Server Edition) - GCC 12.1.1 (Red Hat) @@ -75,70 +74,28 @@ You should be able to install all of these using your package manager, like `apt ### 3.2 Go -It is **highly** recommended that you use Go version 1.17. We provide a script for installing Go, [`InstallGo.sh`](Code/scripts/InstallGo.sh), that will uninstall all previous versions of Go on your system and download Go 1.17, and install it. - -
-Click here for manual steps to install Go - -If you wish not to use `InstallGo.sh` or want to understand how it works, here is a breakdown of the script. - -Remove the previous versions of Go by running -``` -$ sudo rm -rf /usr/local/go/ -``` -Then, download Go 1.17 and extract it to `/usr/local/go/`: -``` -$ wget https://go.dev/dl/go1.17.linux-arm64.tar.gz -$ sudo tar -C /usr/local/ -xzf go1.17.linux-arm64.tar.gz -``` -Add Go to `PATH` by adding the following line to `~/.bash_profile`: -``` -$ export PATH=$PATH:/usr/local/go/bin/ -``` -and then running `source ~/.bash_profile`. - -
+Use a version of Go that is [recommended by u-root](https://github.com/u-root/u-root#usage). Follow the [official installation docs](https://go.dev/doc/install). -**Caution:** If you wish to keep other versions of Go on your system, do not run [`InstallGo.sh`](Code/scripts/InstallGo.sh), as this script will uninstall everything before installing Go 1.17. Instead, see [here](https://go.dev/doc/manage-install) for having multiple versions of Go installed. If you choose to do this, you will have to modify the scripts so that `go` refers to `go1.17` instead of a different version. +### 3.3 QEMU -Using a different version of Go is likely to produce problems. See [`u-root`](https://github.com/u-root/u-root) for details. +**Warning:** To use the sbsa-ref QEMU machine you need QEMU version 4.1.0 or above. However, QEMU major version 8 hangs indefinitely when invoked with `./Run.sh`. QEMU major version 6 works. -### 3.3 QEMU +On distros with apt (might work for others), the best method is to install the following package: -To use the sbsa-ref QEMU machine you need QEMU version 4.1.0 or above. To identify what version you have, run: +```sh +- qemu-system ``` + +To identify what version you have, run: +```sh $ qemu-system-aarch64 --version ``` The output should be this or similar: -``` +```sh QEMU emulator version 6.1.50 (v6.1.0-2172-gc88da1f3da) Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers ``` -If you don't have QEMU installed or don't have the right version, we provide a script to build it from source, [`InstallQemu.sh`](Code/scripts/InstallQemu.sh). You can skip this part if you do have an appropriate version of QEMU installed. - -
-Click here for manual steps to install QEMU - -If you wish not to use `InstallQemu.sh` or want to understand how it works, here is a breakdown of the script. - -Set `INSTALL_PATH` to `/usr/local` or `$HOME/local` or your preferrred location. -``` -$ export INSTALL_PATH=/usr/local -``` -Run the following to clone and install QEMU at your `INSTALL_PATH`: -``` -$ git clone git@github.com:qemu/qemu.git -$ cd qemu -qemu$ mkdir build-native -qemu$ cd build-native -build-native$ ../configure --target-list=aarch64-softmmu --prefix=$INSTALL_PATH -$ make install -``` -Make sure to add the install location to `PATH` if it isn't there already. - -
- ### 3.4 Cross-compiler If you are building Linux and EDK II on a system that isn't AArch64-based then you will need a suitable cross-compiler. @@ -277,6 +234,8 @@ The script will prompt you to choose which method of incorporating LinuxBoot int $ ./Edk2Buildscript.sh 2 ``` +The script assumes that you cloned the repository from `https://gitlab.arm.com/systemready/linuxboot-resources`. If this is not the case (e.g. you downloaded the files manually), the necessary patches might be in different locations. In that case, you should edit the lines `export PATCH="../../../uefishell.patch"` and `export PATCH="../../../bootmgrlib.patch"` to `export PATCH="/uefishell.patch"` and `export PATCH="/bootmgrlib.patch"`, respectively. +
Click here for an alternative way of incorporating LinuxBoot into EDK II @@ -352,10 +311,10 @@ You can omit the cross-compile prefix if running on AArch64. Here is a breakdown -t toolchain version, GCC5 is really GCC5+, in our case GCC 8.3 -p selects machine to compile EDK2 -The build command produces two files, `SBSA_FLASH0.fd` and `SBSA_FLASH1.fd`, as output. Copy these to the top `$WORKSPACE` directory and extend to match the machine flash file size. +The build command produces two files, `SBSA_FLASH0.fd` and `SBSA_FLASH1.fd`, as output. Copy these to the parent directory of `$WORKSPACE` (which would be the scripts directory) and extend to match the machine flash file size. ``` -$ cp Build/SbsaQemu/RELEASE_GCC5/FV/SBSA_FLASH[01].fd . -$ truncate -s 256M SBSA_FLASH[01].fd +$ cp Build/SbsaQemu/RELEASE_GCC5/FV/SBSA_FLASH[01].fd ../ +$ truncate -s 256M ../SBSA_FLASH[01].fd ```
@@ -485,6 +444,8 @@ linux: tag v5.18 ``` Our scripts reference these commits explicitly. If you want to try newer commits, you can replace tags and commit hashes in the scripts. +**Tip:** Check out the [demo videos](#demo-videos) to see if your manual patching works. +
Click here for manual steps to create patches @@ -494,12 +455,12 @@ To start, within your edk2-platforms repository you need to make a new package f ``` $ mkdir -p $WORKSPACE/edk2-platforms/Platform/Qemu/SbsaQemu/linuxboot -$ cd $WORKSAPCE/edk2-platforms/Platform/Qemu/SbsaQemu +$ cd $WORKSPACE/edk2-platforms/Platform/Qemu/SbsaQemu $ cp SbsaQemu.dsc ./linuxboot $ cp SbsaQemu.fdf ./linuxboot $ cd linuxboot $ mv SbsaQemu.dsc LbootSbsaQemu.dsc -$ mv mv SbsaQemu.fdf LbootSbsaQemu.fdf +$ mv SbsaQemu.fdf LbootSbsaQemu.fdf $ touch linuxboot.inf ``` @@ -604,7 +565,7 @@ Add the section below to the "Pcd Section - list of all EDK II PCD Entries defin #### 7.2.2 `LbootSbsaQemu.fdf` -See section [6.1.2](#612-lbootsbsaqemufdf) for details. +See section [7.1.2](#712-lbootsbsaqemufdf) for details. #### 7.2.3 `linuxboot.inf`