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

Commit b6b01f2

Browse files
authored
Merge pull request #12 from hanbings/feat/uefi
feat(uefi): Implement device path, simple fs and gop.
2 parents 65dfd47 + f34a3a1 commit b6b01f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2894
-132
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,11 @@ jobs:
1515
with:
1616
target: riscv64gc-unknown-none-elf
1717
toolchain: nightly-2025-03-31
18-
18+
1919
- name: Install cargo-binutils and rust-objcopy
2020
run: |
2121
rustup component add llvm-tools-preview
2222
cargo install cargo-binutils
23-
24-
- name: Prepare for Build
25-
run: |
26-
# Fix breaking update in rust dependency.
27-
cargo fetch
28-
find ~/.cargo/git/checkouts/ -type f -name '*.rs' -exec sed -i 's/#\[unsafe(naked)\]/#[naked]/g' {} +
29-
30-
# Correct incorrect build directory name in build script.
31-
sed -i '/^SBI :=/s#riscv64imac-unknown-none-elf#riscv64gc-unknown-none-elf#' Makefile
32-
sed -i '/^SBI :=/s#riscv64imac-unknown-none-elf#riscv64gc-unknown-none-elf#' scripts/make/build.mk
33-
34-
make clone-rustsbi
35-
sed -i -E '/^\s*#\[repr\(align\(16\)\)\]\s*$/d' rustsbi/prototyper/prototyper/src/sbi/early_trap.rs
3623
3724
- name: Build with Makefile
3825
run: |
@@ -51,27 +38,43 @@ jobs:
5138
5239
- name: Build EDK2
5340
run: sh scripts/test/build_edk2.sh
54-
41+
5542
- name: Generate disk image
5643
run: sh scripts/test/disk.sh
5744

58-
- name: Create EFI System Partition (ESP)
59-
run: sh scripts/test/make_esp.sh
60-
6145
- name: Set up QEMU
6246
run: |
6347
sudo apt update
6448
sudo apt install -y qemu-system-misc
6549
66-
- name: Run QEMU
67-
run: |
68-
make qemu-run > qemu.log
50+
# Test 1: HelloRiscv
51+
- name: Create ESP (HelloRiscv)
52+
run: EFI_NAME=HelloRiscv sh scripts/test/make_esp.sh
53+
54+
- name: Run QEMU (HelloRiscv)
55+
run: make qemu-run > qemu-hello.log
56+
57+
- name: Upload QEMU log (HelloRiscv)
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: log-hello
61+
path: qemu-hello.log
62+
63+
- name: Check QEMU output (HelloRiscv)
64+
run: sh scripts/test/check_hello_test.sh
65+
66+
# Test 2: AllocatePage
67+
- name: Create ESP (AllocatePage)
68+
run: EFI_NAME=AllocatePage sh scripts/test/make_esp.sh
69+
70+
- name: Run QEMU (AllocatePage)
71+
run: make qemu-run > qemu-allocate.log
6972

70-
- name: Upload QEMU log
73+
- name: Upload QEMU log (AllocatePage)
7174
uses: actions/upload-artifact@v4
7275
with:
73-
name: log
74-
path: qemu.log
76+
name: log-allocate
77+
path: qemu-allocate.log
7578

76-
- name: Check QEMU output
77-
run: sh scripts/test/check_hello_test.sh
79+
- name: Check QEMU output (AllocatePage)
80+
run: sh scripts/test/check_allocate_test.sh

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ axconfig = { git = "https://github.com/arceos-org/arceos.git" }
2525
axsync = { git = "https://github.com/arceos-org/arceos.git" }
2626
axalloc = { git = "https://github.com/arceos-org/arceos.git", optional = true }
2727
axmm = { git = "https://github.com/arceos-org/arceos.git", optional = true }
28-
axdriver = { git = "https://github.com/arceos-org/arceos.git", optional = true, features = ["virtio-blk"] }
28+
axdriver = { git = "https://github.com/arceos-org/arceos.git", optional = true, features = ["virtio-blk", "virtio-gpu"] }
2929
axfs = { git = "https://github.com/arceos-org/arceos.git", optional = true }
3030
axnet = { git = "https://github.com/arceos-org/arceos.git", optional = true }
3131
axdisplay = { git = "https://github.com/arceos-org/arceos.git", optional = true }
@@ -34,7 +34,7 @@ axio = { version = "0.1", features = ["alloc"] }
3434
crate_interface = "0.1"
3535
ctor_bare = "0.2"
3636
cfg-if = "1.0.1"
37-
object = { version = "0.37.1", default-features = false, features = [ "read" ] }
37+
object = { version = "0.37.1", default-features = false, features = [ "read", "pe" ] }
3838
chrono = { version = "0.4.38", default-features = false }
3939
uefi-raw = "0.11.0"
4040
lazyinit = "0.2.2"

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@ build: clean defconfig all
4848
qemu-run:
4949
qemu-system-riscv64 -m 128M -serial mon:stdio -bios $(SBI) -nographic -machine virt -nographic -machine virt -device virtio-blk-pci,drive=disk0 -drive id=disk0,if=none,format=raw,file=$(DISK)
5050

51+
qemu-display:
52+
qemu-system-riscv64 -m 128M -serial mon:stdio -bios $(SBI) -machine virt -device virtio-blk-pci,drive=disk0 -drive id=disk0,if=none,format=raw,file=$(DISK) -device virtio-gpu-pci,xres=1024,yres=768
53+
5154
qemu-run-ramdisknotload:
5255
qemu-system-riscv64 -m 128M -serial mon:stdio -bios $(SBI) -nographic -machine virt -nographic -machine virt -device virtio-blk-pci,drive=disk0 -drive id=disk0,if=none,format=raw,file=$(DISK) -device loader,file=$(RAMDISK_CPIO),addr=0x84000000

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# ArceBoot
22
Reuse [ArceOS](https://github.com/arceos-org/arceos) components to build a cross-platform operating system bootloader
3+
4+
# Build
5+
6+
```bash
7+
# for serial output build:
8+
$ make
9+
$ make qemu-run
10+
11+
# for qemu virtual monitor:
12+
# this may require a desktop system or graphical infrastructure
13+
# such as x11 forwarding configured on your host machine.
14+
$ make EXACT_FEATURES="display"
15+
$ make qemu-display
16+
```

scripts/make/build.mk

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ ELF := $(ROOT_DIR)/target/$(TARGET)/release/arceboot
88
BIN := $(ROOT_DIR)/target/$(TARGET)/release/arceboot.bin
99
RUSTSBI_DIR := $(ROOT_DIR)/rustsbi
1010

11+
# 用逗号或者空格分隔 feature 名称
12+
EXACT_FEATURES ?=
13+
EXACT_FEATURES_CLEANED := $(subst $(space),$(comma),$(strip $(EXACT_FEATURES)))
14+
15+
ifeq ($(strip $(EXACT_FEATURES)),)
16+
FEATURE_ARGS :=
17+
else
18+
FEATURE_ARGS := --features '$(EXACT_FEATURES_CLEANED)'
19+
endif
20+
1121
# 彩色打印
1222
define print_info
1323
@printf "\033[1;37m%s\033[0m" "[RustSBI-Arceboot Build] "
@@ -22,7 +32,7 @@ all: build-arceboot extract-bin clone-rustsbi build-rustsbi
2232

2333
build-arceboot:
2434
$(call print_info,开始编译 ArceBoot...)
25-
cargo rustc --release --target $(TARGET) -- \
35+
cargo rustc --release --target $(TARGET) $(FEATURE_ARGS) -- \
2636
-C opt-level=z \
2737
-C panic=abort \
2838
-C relocation-model=static \

scripts/test/build_edk2.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ EDK_DIR="$WORKSPACE_DIR/edk2"
77

88
mkdir -p "$WORKSPACE_DIR"
99

10-
echo "[1/3] 准备 EDK2 构建环境..."
10+
echo "[1/4] 准备 EDK2 构建环境..."
1111
cd "$WORKSPACE_DIR"
1212

1313
if [ ! -d "ToolChain/RISCV" ]; then
@@ -19,7 +19,7 @@ else
1919
echo "RISCV 工具链已存在,跳过下载。"
2020
fi
2121

22-
echo "[2/3] 克隆 EDK2 仓库..."
22+
echo "[2/4] 克隆 EDK2 仓库..."
2323
if [ ! -d "$EDK_DIR" ]; then
2424
git clone --recurse-submodule https://github.com/tianocore/edk2.git "$EDK_DIR"
2525
else
@@ -28,7 +28,7 @@ fi
2828

2929
export PATH="$WORKSPACE_DIR/ToolChain/RISCV/riscv/bin:$PATH"
3030

31-
echo "[3/3] 构建 EDK2..."
31+
echo "[3/4] 构建 EDK2..."
3232
cd "$WORKSPACE_DIR"
3333

3434
export WORKSPACE=`pwd`
@@ -40,6 +40,7 @@ export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
4040
make -C edk2/BaseTools
4141
. "$EDK_DIR/edksetup.sh" BaseTools
4242

43+
echo "[4/4] 准备 HelloRiscv 和 AllocatePage 示例..."
4344
# mkdir -p "$EDK_DIR/Hello"
4445
# cp -r "$PROJECT_ROOT/tests/edk2-Hello" "$EDK_DIR"
4546
# mv "$EDK_DIR/edk2-Hello"/* "$EDK_DIR/Hello/"
@@ -50,4 +51,8 @@ cp -r "$PROJECT_ROOT/tests/edk2-HelloRiscv" "$EDK_DIR"
5051
mv "$EDK_DIR/edk2-HelloRiscv" "$EDK_DIR/HelloRiscv/"
5152
build -a RISCV64 -t GCC5 -p "$EDK_DIR/HelloRiscv/HelloRiscv.dsc"
5253

53-
echo "EDK2 构建完成。生成的镜像位于:$WORKSPACE_DIR/Build/DEBUG_GCC5/RISCV64/HelloRiscv.efi"
54+
cp -r "$PROJECT_ROOT/tests/edk2-AllocatePage" "$EDK_DIR"
55+
mv "$EDK_DIR/edk2-AllocatePage" "$EDK_DIR/AllocatePage/"
56+
build -a RISCV64 -t GCC5 -p "$EDK_DIR/AllocatePage/AllocatePage.dsc"
57+
58+
echo "EDK2 与示例构建完成。生成的文件位于:$WORKSPACE_DIR/Build/DEBUG_GCC5/RISCV64"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
LOG_FILE="qemu-allocate.log"
5+
TARGET_STRING="EFI Output: 0xDEADBEEF12345678"
6+
7+
if [ ! -f "$LOG_FILE" ]; then
8+
echo "$LOG_FILE 不存在"
9+
exit 1
10+
fi
11+
12+
if grep -qF "$TARGET_STRING" "$LOG_FILE"; then
13+
echo "✅ 找到匹配日志行"
14+
exit 0
15+
else
16+
echo "❌ 未找到匹配日志行"
17+
exit 2
18+
fi

scripts/test/check_hello_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
LOG_FILE="qemu.log"
4+
LOG_FILE="qemu-hello.log"
55
TARGET_STRING="EFI Output: Hello, World!"
66

77
if [ ! -f "$LOG_FILE" ]; then

scripts/test/make_esp.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PROJECT_ROOT=$(pwd)
55
IMG_NAME="disk.img"
66
MOUNT_DIR="mnt_fat32"
77
ESP_DIR="$MOUNT_DIR/EFI/BOOT"
8+
EFI_NAME="${EFI_NAME:-HelloRiscv}"
9+
BUILD_FLAVOR="${BUILD_FLAVOR:-DEBUG_GCC5}"
10+
ARCH_DIR="${ARCH_DIR:-RISCV64}"
811

912
if [ ! -d "$MOUNT_DIR" ]; then
1013
mkdir "$MOUNT_DIR"
@@ -17,7 +20,9 @@ echo "[2/3] 创建 ESP 目录结构..."
1720
sudo mkdir -p "$ESP_DIR"
1821

1922
echo "[3/3] 复制 efi 文件到 ESP..."
20-
sudo cp "$PROJECT_ROOT/edk2/Build/DEBUG_GCC5/RISCV64/HelloRiscv.efi" "$ESP_DIR/BOOTRISCV64.EFI"
23+
SRC_EFI="$PROJECT_ROOT/edk2/Build/$BUILD_FLAVOR/$ARCH_DIR/${EFI_NAME}.efi"
24+
echo "源文件: $SRC_EFI"
25+
sudo cp "$SRC_EFI" "$ESP_DIR/BOOTRISCV64.EFI"
2126

2227
sudo find "$ESP_DIR" -type d | while read -r dir; do
2328
echo "$dir"

0 commit comments

Comments
 (0)