Преглед изворни кода

feat(prototyper): add docs for booting ubuntu using RustSBI and edk2. (#152)

* feat(prototyper): add docs for booting ubuntu using RustSBI and edk2.

Signed-off-by: jackfiled <xcrenchangjun@outlook.com>

* fix(prototyper): use https to clone edk2 source code.

Thanks to copilot!

Signed-off-by: jackfiled <xcrenchangjun@outlook.com>

---------

Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
Ricardo Ren пре 1 месец
родитељ
комит
7754d4b339

+ 1 - 55
prototyper/docs/booting-archlinux-in-qemu-using-edk2-and-rustsbi.md

@@ -214,7 +214,7 @@ cargo prototyper
 然后拉取EDK2的源代码并编译EDK2:
 
 ```bash
-git clone --recurse-submodule git@github.com:tianocore/edk2.git -b edk2-stable202505
+git clone --recurse-submodules https://github.com/tianocore/edk2.git -b edk2-stable202505
 cd edk2
 export GCC5_RISCV64_PREFIX=riscv64-linux-gnu-
 source edksetup.sh
@@ -228,60 +228,6 @@ truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd
 truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd
 ```
 
-使用QEMU的启动指令导出启动时使用的设备树并进行修改,下面的指令会将QEMU启动之后使用的设备树导出为`virt.dtb`。
-
-```bash
-qemu-system-riscv64 \
-        -machine virt,dumpdtb=virt.dtb \
-        -smp 1 \
-        -m 4G \
-        -bios rustsbi/target/riscv64gc-unknown-none-elf/release/rustsbi-prototyper-dynamic.bin \
-        -device virtio-blk-device,drive=hd0 \
-        -drive file=rustsbi-edk2-archriscv.img,format=qcow2,id=hd0,if=none \ 
-        -object rng-random,filename=/dev/urandom,id=rng0 \
-        -device virtio-rng-device,rng=rng0 \
-        -monitor unix:/tmp/qemu-monitor,server,nowait \
-        -nographic \
-        -serial mon:stdio
-```
-
-使用`dtc`编译器将`dtb`文件还原为`dts`文件。
-
-```bash
-dtc -I dtb -o dts virt.dtb -o virt.dts
-```
-
-在`model`属性下,添加下面的`reserved-memory`属性:
-
-```dts
-    reserved-memory {
-		#address-cells = <0x00000002>;
-		#size-cells = <0x00000002>;
-		ranges;
-		mmode_resv1@80040000 {
-			reg = <0x00000000 0x80040000 0x00000000 0x00040000>;
-			no-map;
-		};
-		mmode_resv0@80000000 {
-			reg = <0x00000000 0x80000000 0x00000000 0x00040000>;
-			no-map;
-		};
-	};
-```
-
-重新将该`dts`文件编译为`dtb`文件。
-
-```bash
-dtc -I dts -O dtb virt.dts -o virt.dtb
-```
-
-重新编译RustSBI,使用上面编辑之后的设备树作为嵌入的设备树。
-
-```bash
-cd rustsbi
-cargo prototyper --fdt ../virt.dtb
-```
-
 ## 启动QEMU
 
 使用如下的指令启动QEMU:

+ 81 - 0
prototyper/docs/booting-ubuntu-24.04.3-in-qemu-using-edk2-and-rustsbi.md

@@ -0,0 +1,81 @@
+# 使用RustSBI和EDK2在QEMU中启动Ubuntu 24.04.3
+
+本教程将介绍如何使用RustSBI和EDK2在QEMU中启动Ubuntu 24.04.3。
+
+运行本教程已经在Arch Linux x86_64系统上经过测试,但理论上其他的Linux发行版亦可以参照使用。
+
+测试本教程时使用的软件版本如下:
+
+|          软件           |      版本       |
+|:---------------------:|:-------------:|
+| riscv64-linux-gnu-gcc |    15.1.0     |
+|  qemu-system-riscv64  |    10.1.0     |
+|  RustSBI Prototyper   |    master     |
+|         EDK2          | stable202505  |
+
+## 准备Ubuntu镜像
+
+访问[Download Ubuntu for RISC-V](https://ubuntu.com/download/risc-v)页面,查找当前Ubuntu针对**QEMU Emulator**平台发行的
+最新预安装镜像进行下载。
+
+本教程撰写时的最新镜像版本为[24.04.3 LTS](https://cdimage.ubuntu.com/releases/24.04.3/release/ubuntu-24.04.3-preinstalled-server-riscv64.img.xz),复制链接进行下载:
+
+```bash
+wget https://cdimage.ubuntu.com/releases/24.04.3/release/ubuntu-24.04.3-preinstalled-server-riscv64.img.xz
+xz -d ubuntu-24.04.3-preinstalled-server-riscv64.img.xz
+```
+
+## 编译RustSBI和EDK2
+
+首先拉取RustSBI的源代码并编译RustSBI:
+
+```bash
+git clone https://github.com/rustsbi/rustsbi.git --depth 1
+cd rustsbi
+cargo prototyper
+```
+
+然后拉取EDK2的源代码并编译EDK2:
+
+```bash
+git clone --recurse-submodules https://github.com/tianocore/edk2.git -b edk2-stable202505
+cd edk2
+export GCC5_RISCV64_PREFIX=riscv64-linux-gnu-
+source edksetup.sh
+build -a RISCV64 -b RELEASE -p OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc -t GCC5
+```
+
+为了符合QEMU对于PFLASH固件的要求,将编译好的UEFI固件大小扩展到32M。
+
+```bash
+truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd 
+truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd
+```
+
+## 启动系统
+
+使用如下的指令启动QEMU:
+
+```bash
+qemu-system-riscv64  \
+        -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
+        -m 4096 -smp 8 \
+        -bios rustsbi/target/riscv64gc-unknown-none-elf/release/rustsbi-prototyper-dynamic.bin \
+        -blockdev node-name=pflash0,driver=file,read-only=on,filename=edk2/Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd  \
+        -blockdev node-name=pflash1,driver=file,filename=edk2/Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd \
+        -device virtio-blk-device,drive=hd0  \
+        -drive file=ubuntu-24.04.3-preinstalled-server-riscv64.img,format=raw,id=hd0,if=none \
+        -netdev user,id=n0 -device virtio-net,netdev=n0 \
+        -monitor unix:/tmp/qemu-monitor,server,nowait \
+        -nographic \
+        -serial mon:stdio
+```
+
+启动系统的过程中需要注意,在默认情况下,EDK2启动之后会启动GRUB2作为引导程序,启动之后的默认账户和密码是`ubuntu`和`ubuntu`。
+
+启动系统并登录之后,验证是否使用UEFI启动成功:
+
+```bash
+ubuntu@ubuntu:~$ cat /sys/firmware/efi/fw_platform_size 
+64
+```