summaryrefslogtreecommitdiff
path: root/Platform/Qemu/RiscVServerRef/Readme.md
blob: f2f7c2ad7b7d88316743a1face9c2bad916b0f1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Overview

This directory holds the UEFI implementation for the RiscVServerRef machine,
which is a fully software emulated RISC-V server platform. It implements the
RISC-V Server Platform Specification v1.0.0 [1], and aims to emulate real
hardware as closely as possible. Its purpose is to enable new feature
development when hardware for RISC-V server platform is not yet available. It
allows firmware-to-hardware interaction simulations and debugging that would be
difficult or impossible on real hardware.

Keep in mind that all of the above is possible because this machine is fully
emulated in software. RiscVServerRef does not use any hardware acceleration
of your platform, even if you run it on a RISC-V platform.

[1] https://github.com/riscv/riscv-server-platform-specification

# How to build (Linux Environment)

## Prerequisites

The build process for RiscVServerRef uses an FDF file for flash image
composition. Two flash images are produced:
- `RISCV_SERVER_REF_CODE.fd` — firmware code (SEC + PEI + DXE)
- `RISCV_SERVER_REF_VARS.fd` — UEFI variable store

## Obtaining source code

Create a directory `$WORKSPACE` to hold the source code of the components.

  1. [qemu](https://gitlab.com/qemu-project/qemu.git)
  2. [edk2](https://github.com/tianocore/edk2)
  3. [edk2-platforms](https://github.com/tianocore/edk2-platforms)
  4. [edk2-non-osi](https://github.com/tianocore/edk2-non-osi)

## Manual building

1. Compile QEMU

  Support for the `riscv-server-ref` machine used as the basis for this platform
  is available in QEMU commit d29412cca and later. If your distribution provides an
  earlier version, compile QEMU from source.

  Set `$INSTALL_PATH` to `/usr/local`, `~/local`, or any preferred location.

  ```
  cd $WORKSPACE/qemu
  mkdir -p build-native
  cd build-native
  ../configure --target-list=riscv64-softmmu --prefix=$INSTALL_PATH
  make install
  ```

  QEMU should now be installed in `$INSTALL_PATH`.

2. Compile UEFI for the RiscVServerRef platform

  Detailed build instructions can be found at:
  https://github.com/tianocore/edk2-platforms

  The following is a short description to build for the RiscVServerRef platform.

  Compile BaseTools and prepare the environment:

  ```
  cd $WORKSPACE
  export PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-platforms:$WORKSPACE/edk2-non-osi
  make -C edk2/BaseTools
  . edk2/edksetup.sh
  ```

  Now compile UEFI for RiscVServerRef:

  ```
  cd $WORKSPACE
  build -b RELEASE -a RISCV64 -t GCC -p edk2-platforms/Platform/Qemu/RiscVServerRef/RiscVServerRef.dsc
  ```

  Copy the flash images to the top `$WORKSPACE` directory:

  ```
  cp Build/RiscVServerRef/RELEASE_GCC/FV/RISCV_SERVER_REF_CODE.fd .
  cp Build/RiscVServerRef/RELEASE_GCC/FV/RISCV_SERVER_REF_VARS.fd .
  truncate -s 32M ./RISCV_SERVER_REF_CODE.fd
  truncate -s 32M ./RISCV_SERVER_REF_VARS.fd
  ```

# Running

  The resulting `RISCV_SERVER_REF_CODE.fd` file contains the firmware code
  image and `RISCV_SERVER_REF_VARS.fd` contains the UEFI variable store.

  Start TPM service with the folloing command:
  ```
  #!/bin/bash

  mkdir -p /tmp/mytpm1
  swtpm socket --tpmstate dir=/tmp/mytpm1 --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock --tpm2 --log level=20 --daemon
  ```

  Then run QEMU with the following command:
  ```
  $INSTALL_PATH/qemu-system-riscv64 \
    -nographic \
    -machine riscv-server-ref \
    -smp 2 \
    -m 4G \
    -drive file=RISCV_SERVER_REF_CODE.fd,if=pflash,format=raw,unit=0 \
    -drive file=RISCV_SERVER_REF_VARS.fd,if=pflash,format=raw,unit=1 \
    -drive file=ubuntu-xx.xx-riscv64.img,format=raw,if=none,id=hd0 -device ahci,id=ahci -device ide-hd,drive=hd0,bus=ahci.0 \
    -netdev user,id=net0 -device e1000,netdev=net0 \
    -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0
  ```