Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6f5cee8
fix(uefi): Split the efi loading logic in uefi runtime.
hanbings Aug 4, 2025
7118439
feat(uefi): supports pe file reloc segment mapping.
hanbings Aug 4, 2025
ea50b28
fix(uefi): fix access that caused a page fault exception.
hanbings Aug 6, 2025
e2dd1e3
feat(uefi): declare necessary ffi for the protocols.
hanbings Aug 7, 2025
918e158
refactor(main): centralize in main.rs
hanbings Aug 7, 2025
882c236
feat(uefi): declare necessary ffi for the protocols.
hanbings Aug 8, 2025
4dd66a3
feat(uefi): initialize axdisplay and drawing colors.
hanbings Aug 9, 2025
b6d20d4
feat(uefi): added stub functions in the boot and runtime services.
hanbings Sep 15, 2025
8084a0d
fix(uefi): fix build.
hanbings Sep 15, 2025
fc8edcc
feat(uefi): added initialization for boot_service and runtime_service.
hanbings Sep 15, 2025
979b178
refactor(uefi): adjust the code structure of uefi service.
hanbings Sep 16, 2025
24318b6
refactor(memory): adjust the memory manager interface according to th…
hanbings Sep 22, 2025
84e0f0d
chore(uefi): run cargo fmt.
hanbings Sep 22, 2025
8588762
feat(fs): implements the file protocol v1 in the simple file protocol…
hanbings Sep 23, 2025
32af3b4
feat(gop): implements the graphics output protocol via axdisplay. (#3)
hanbings Sep 26, 2025
b9e05a0
test(allocate): added test program for allocate_page(). (#4)
hanbings Sep 27, 2025
c4776dc
feat(device): impl utilities to assist in managing device path. (#5)
hanbings Sep 27, 2025
bfbab66
feat(uefi): impl crc calculation and memory utility tools.
hanbings Sep 27, 2025
abaa268
chore(uefi): clean code.
hanbings Sep 27, 2025
2ee6475
feat(ci): added script for allocate_page() test. (#6)
hanbings Sep 27, 2025
36e7fec
fix: resolve code conflicts.
hanbings Oct 12, 2025
f34a3a1
fix(uefi): add feature cfg! for ramdisk functionality.
hanbings Oct 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,11 @@ jobs:
with:
target: riscv64gc-unknown-none-elf
toolchain: nightly-2025-03-31

- name: Install cargo-binutils and rust-objcopy
run: |
rustup component add llvm-tools-preview
cargo install cargo-binutils

- name: Prepare for Build
run: |
# Fix breaking update in rust dependency.
cargo fetch
find ~/.cargo/git/checkouts/ -type f -name '*.rs' -exec sed -i 's/#\[unsafe(naked)\]/#[naked]/g' {} +

# Correct incorrect build directory name in build script.
sed -i '/^SBI :=/s#riscv64imac-unknown-none-elf#riscv64gc-unknown-none-elf#' Makefile
sed -i '/^SBI :=/s#riscv64imac-unknown-none-elf#riscv64gc-unknown-none-elf#' scripts/make/build.mk

make clone-rustsbi
sed -i -E '/^\s*#\[repr\(align\(16\)\)\]\s*$/d' rustsbi/prototyper/prototyper/src/sbi/early_trap.rs

- name: Build with Makefile
run: |
Expand All @@ -51,27 +38,43 @@ jobs:

- name: Build EDK2
run: sh scripts/test/build_edk2.sh

- name: Generate disk image
run: sh scripts/test/disk.sh

- name: Create EFI System Partition (ESP)
run: sh scripts/test/make_esp.sh

- name: Set up QEMU
run: |
sudo apt update
sudo apt install -y qemu-system-misc

- name: Run QEMU
run: |
make qemu-run > qemu.log
# Test 1: HelloRiscv
- name: Create ESP (HelloRiscv)
run: EFI_NAME=HelloRiscv sh scripts/test/make_esp.sh

- name: Run QEMU (HelloRiscv)
run: make qemu-run > qemu-hello.log

- name: Upload QEMU log (HelloRiscv)
uses: actions/upload-artifact@v4
with:
name: log-hello
path: qemu-hello.log

- name: Check QEMU output (HelloRiscv)
run: sh scripts/test/check_hello_test.sh

# Test 2: AllocatePage
- name: Create ESP (AllocatePage)
run: EFI_NAME=AllocatePage sh scripts/test/make_esp.sh

- name: Run QEMU (AllocatePage)
run: make qemu-run > qemu-allocate.log

- name: Upload QEMU log
- name: Upload QEMU log (AllocatePage)
uses: actions/upload-artifact@v4
with:
name: log
path: qemu.log
name: log-allocate
path: qemu-allocate.log

- name: Check QEMU output
run: sh scripts/test/check_hello_test.sh
- name: Check QEMU output (AllocatePage)
run: sh scripts/test/check_allocate_test.sh
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ axconfig = { git = "https://github.com/arceos-org/arceos.git" }
axsync = { git = "https://github.com/arceos-org/arceos.git" }
axalloc = { git = "https://github.com/arceos-org/arceos.git", optional = true }
axmm = { git = "https://github.com/arceos-org/arceos.git", optional = true }
axdriver = { git = "https://github.com/arceos-org/arceos.git", optional = true, features = ["virtio-blk"] }
axdriver = { git = "https://github.com/arceos-org/arceos.git", optional = true, features = ["virtio-blk", "virtio-gpu"] }
axfs = { git = "https://github.com/arceos-org/arceos.git", optional = true }
axnet = { git = "https://github.com/arceos-org/arceos.git", optional = true }
axdisplay = { git = "https://github.com/arceos-org/arceos.git", optional = true }
Expand All @@ -34,7 +34,7 @@ axio = { version = "0.1", features = ["alloc"] }
crate_interface = "0.1"
ctor_bare = "0.2"
cfg-if = "1.0.1"
object = { version = "0.37.1", default-features = false, features = [ "read" ] }
object = { version = "0.37.1", default-features = false, features = [ "read", "pe" ] }
chrono = { version = "0.4.38", default-features = false }
uefi-raw = "0.11.0"
lazyinit = "0.2.2"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ build: clean defconfig all
qemu-run:
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)

qemu-display:
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

qemu-run-ramdisknotload:
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# ArceBoot
Reuse [ArceOS](https://github.com/arceos-org/arceos) components to build a cross-platform operating system bootloader

# Build

```bash
# for serial output build:
$ make
$ make qemu-run

# for qemu virtual monitor:
# this may require a desktop system or graphical infrastructure
# such as x11 forwarding configured on your host machine.
$ make EXACT_FEATURES="display"
$ make qemu-display
```
12 changes: 11 additions & 1 deletion scripts/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ ELF := $(ROOT_DIR)/target/$(TARGET)/release/arceboot
BIN := $(ROOT_DIR)/target/$(TARGET)/release/arceboot.bin
RUSTSBI_DIR := $(ROOT_DIR)/rustsbi

# 用逗号或者空格分隔 feature 名称
EXACT_FEATURES ?=
EXACT_FEATURES_CLEANED := $(subst $(space),$(comma),$(strip $(EXACT_FEATURES)))

ifeq ($(strip $(EXACT_FEATURES)),)
FEATURE_ARGS :=
else
FEATURE_ARGS := --features '$(EXACT_FEATURES_CLEANED)'
endif

# 彩色打印
define print_info
@printf "\033[1;37m%s\033[0m" "[RustSBI-Arceboot Build] "
Expand All @@ -22,7 +32,7 @@ all: build-arceboot extract-bin clone-rustsbi build-rustsbi

build-arceboot:
$(call print_info,开始编译 ArceBoot...)
cargo rustc --release --target $(TARGET) -- \
cargo rustc --release --target $(TARGET) $(FEATURE_ARGS) -- \
-C opt-level=z \
-C panic=abort \
-C relocation-model=static \
Expand Down
13 changes: 9 additions & 4 deletions scripts/test/build_edk2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EDK_DIR="$WORKSPACE_DIR/edk2"

mkdir -p "$WORKSPACE_DIR"

echo "[1/3] 准备 EDK2 构建环境..."
echo "[1/4] 准备 EDK2 构建环境..."
cd "$WORKSPACE_DIR"

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

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

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

echo "[3/3] 构建 EDK2..."
echo "[3/4] 构建 EDK2..."
cd "$WORKSPACE_DIR"

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

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

echo "EDK2 构建完成。生成的镜像位于:$WORKSPACE_DIR/Build/DEBUG_GCC5/RISCV64/HelloRiscv.efi"
cp -r "$PROJECT_ROOT/tests/edk2-AllocatePage" "$EDK_DIR"
mv "$EDK_DIR/edk2-AllocatePage" "$EDK_DIR/AllocatePage/"
build -a RISCV64 -t GCC5 -p "$EDK_DIR/AllocatePage/AllocatePage.dsc"

echo "EDK2 与示例构建完成。生成的文件位于:$WORKSPACE_DIR/Build/DEBUG_GCC5/RISCV64"
18 changes: 18 additions & 0 deletions scripts/test/check_allocate_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

LOG_FILE="qemu-allocate.log"
TARGET_STRING="EFI Output: 0xDEADBEEF12345678"

if [ ! -f "$LOG_FILE" ]; then
echo "❌ $LOG_FILE 不存在"
exit 1
fi

if grep -qF "$TARGET_STRING" "$LOG_FILE"; then
echo "✅ 找到匹配日志行"
exit 0
else
echo "❌ 未找到匹配日志行"
exit 2
fi
2 changes: 1 addition & 1 deletion scripts/test/check_hello_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

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

if [ ! -f "$LOG_FILE" ]; then
Expand Down
7 changes: 6 additions & 1 deletion scripts/test/make_esp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ PROJECT_ROOT=$(pwd)
IMG_NAME="disk.img"
MOUNT_DIR="mnt_fat32"
ESP_DIR="$MOUNT_DIR/EFI/BOOT"
EFI_NAME="${EFI_NAME:-HelloRiscv}"
BUILD_FLAVOR="${BUILD_FLAVOR:-DEBUG_GCC5}"
ARCH_DIR="${ARCH_DIR:-RISCV64}"

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

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

sudo find "$ESP_DIR" -type d | while read -r dir; do
echo "$dir"
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(test), no_std)]
#![no_main]
#![allow(dead_code)]
#![feature(c_variadic)]

#[macro_use]
extern crate axlog;
Expand Down Expand Up @@ -41,7 +42,7 @@ pub extern "C" fn rust_main(_cpu_id: usize, dtb: usize) -> ! {
info!("Initialize platform devices...");
axhal::platform_init();

#[cfg(any(feature = "fs", feature = "net"))]
#[cfg(any(feature = "fs", feature = "net", feature = "display"))]
{
#[allow(unused_variables)]
let all_devices = axdriver::init_drivers();
Expand All @@ -53,6 +54,9 @@ pub extern "C" fn rust_main(_cpu_id: usize, dtb: usize) -> ! {

#[cfg(feature = "net")]
axnet::init_network(all_devices.net);

#[cfg(feature = "display")]
axdisplay::init_display(all_devices.display);
}
ctor_bare::call_ctors();

Expand All @@ -62,6 +66,7 @@ pub extern "C" fn rust_main(_cpu_id: usize, dtb: usize) -> ! {
}

// ramdisk check
#[cfg(feature = "ramdisk_cpio")]
crate::medium::ramdisk_cpio::check_ramdisk();

crate::shell::shell_main();
Expand Down
2 changes: 1 addition & 1 deletion src/medium/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod ramdisk_cpio;
pub mod virtio_disk;
pub mod virtio_disk;
2 changes: 1 addition & 1 deletion src/medium/ramdisk_cpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ pub fn check_ramdisk() {
}
}
info!("Checking for ramdisk is done!");
}
}
4 changes: 2 additions & 2 deletions src/medium/virtio_disk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axio::{self as io};
use alloc::{string::String, vec::Vec};
use axio::{self as io};

/// Returns the current working directory as a [`String`].
pub fn current_dir() -> io::Result<String> {
Expand All @@ -14,4 +14,4 @@ pub fn read(path: &str) -> io::Result<Vec<u8>> {
/// Read the entire contents of a file into a string.
pub fn read_to_string(path: &str) -> io::Result<String> {
axfs::api::read_to_string(path)
}
}
11 changes: 11 additions & 0 deletions src/runtime/entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub type EfiMainFn =
extern "efiapi" fn(image_handle: *mut core::ffi::c_void, system_table: *mut SystemTable) -> u64;

use core::mem::transmute;

use uefi_raw::table::system::SystemTable;

pub fn resolve_entry_func(mapping: *const u8, entry: u64, base_va: u64) -> EfiMainFn {
let func_addr = (mapping as usize + (entry - base_va) as usize) as *const ();
unsafe { transmute(func_addr) }
}
Empty file added src/runtime/event/mod.rs
Empty file.
Empty file added src/runtime/image/mod.rs
Empty file.
Loading
Loading