Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit 1c4f916

Browse files
authored
Merge pull request #56 from Nowherechan/main
docs: add a guide for booting Ubuntu on qemu with OpenSBI and EDK II
2 parents 9c6f149 + 3c83a54 commit 1c4f916

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# 使用 OpenSBI & EDK2 在 QEMU 中启动 Ubuntu 24.04.1
2+
3+
本教程给出了使用 OpenSBI 和 EDK II 在 QEMU 中启动 Ubuntu 24.04.1 的基本流程。
4+
5+
请读者在其主机上安装必要的软件来尝试本教程。本教程是在 Arch Linux 上开发的,建议读者使用 x86_64 平台上的 Linux 环境按照本教程进行尝试。
6+
7+
本教程使用软件版本如下:
8+
9+
| 软件 | 版本 |
10+
| :-------------------: | :----------: |
11+
| riscv64-linux-gnu-gcc | 14.2.0 |
12+
| qemu-system-riscv64 | 9.2.0 |
13+
| OpenSBI | 1.6 |
14+
| EDK II | stable202411 |
15+
16+
## 准备 Opensbi,EDK II,Ubuntu 24.04.1
17+
创建工作目录并进入该目录
18+
19+
``` shell
20+
$ mkdir workshop && cd workshop
21+
```
22+
23+
### Clone Opensbi
24+
25+
``` shell
26+
$ git clone -b v1.6 https://github.com/riscv/opensbi.git
27+
```
28+
29+
### Clone EDK II
30+
31+
``` shell
32+
$ git clone -b edk2-stable202411 --recurse-submodule [email protected]:tianocore/edk2.git
33+
```
34+
35+
### 下载 Ubuntu 24.04.1 镜像文件
36+
37+
下载链接:[Ubuntu 24.04.1](https://cdimage.ubuntu.com/releases/24.04.1/release/ubuntu-24.04.1-preinstalled-server-riscv64.img.xz)
38+
``` shell
39+
$ wget https://cdimage.ubuntu.com/releases/24.04.1/release/ubuntu-24.04.1-preinstalled-server-riscv64.img.xz
40+
$ xz -d ubuntu-24.04.1-preinstalled-server-riscv64.img.xz
41+
```
42+
43+
- The password of the default user `ubuntu` is `ubuntu`.
44+
- 登录后应会被要求更改登录密码。
45+
- 可以通过 `sudo` 更改 root 密码。
46+
47+
## 编译 EDK II
48+
49+
设置环境变量
50+
51+
``` shell
52+
$ export WORKSPACE=`pwd`
53+
$ export GCC5_RISCV64_PREFIX=riscv64-linux-gnu-
54+
$ export PACKAGES_PATH=$WORKSPACE/edk2
55+
$ export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
56+
$ source edk2/edksetup.sh --reconfig
57+
```
58+
59+
编译 BaseTools
60+
61+
``` shell
62+
$ make -C edk2/BaseTools
63+
```
64+
65+
编译 RiscVVirtQemu
66+
67+
``` shell
68+
$ source edk2/edksetup.sh BaseTools
69+
$ build -a RISCV64 --buildtarget RELEASE -p OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc -t GCC5
70+
```
71+
72+
## 编译 OpenSBI
73+
74+
``` shell
75+
$ make -C opensbi \
76+
-j $(nproc) \
77+
CROSS_COMPILE=riscv64-linux-gnu- \
78+
PLATFORM=generic
79+
```
80+
81+
## 使用 OpenSBI 和 EDK II 启动 Ubuntu 24.04.1
82+
83+
将 RISCV_VIRT_CODE.fd 和 RISCV_VIRT_VARS.fd 填充至 32M,以适应 RISC-V QEMU pflash devices 的需求
84+
85+
``` shell
86+
$ truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd
87+
$ truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd
88+
```
89+
90+
启动 qemu-system-riscv64
91+
92+
``` shell
93+
$ qemu-system-riscv64 \
94+
-M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
95+
-m 4096 -smp 2 -nographic \
96+
-bios opensbi/build/platform/generic/firmware/fw_dynamic.bin \
97+
-blockdev node-name=pflash0,driver=file,read-only=on,filename=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd \
98+
-blockdev node-name=pflash1,driver=file,filename=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd \
99+
-device virtio-blk-device,drive=hd0 \
100+
-drive file=ubuntu-24.04.1-preinstalled-server-riscv64.img,format=raw,id=hd0,if=none
101+
```

0 commit comments

Comments
 (0)