Skip to content

Commit cbf8594

Browse files
committed
fix limine config
1 parent d4a4e0d commit cbf8594

6 files changed

Lines changed: 128 additions & 64 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
name: CI # 工作流名称
1+
name: Build ISO
22

3-
# push到main或者有PR时触发
4-
on:
3+
on:
54
push:
6-
branches: [ main ]
75
pull_request:
86

97
jobs:
10-
build-and-boot:
11-
runs-on: ubuntu-22.04 # 在Ubuntu 22.04环境下运行
8+
build-iso:
9+
runs-on: ubuntu-latest
10+
1211
steps:
13-
# 签出到运行环境
14-
- name: Checkout
12+
- name: Checkout
1513
uses: actions/checkout@v4
1614

17-
# xorriso-制作ISO镜像; make, nasm, gcc-构建LimineOS;
18-
# qemu-system-x86-运行LimineOS
19-
- name: Install deps
15+
- name: Install dependencies
2016
run: |
2117
sudo apt-get update
22-
sudo apt-get install -y qemu-system-x86 xorriso make nasm gcc
23-
24-
- name: Setup Rust (nightly) (actions-rs)
25-
uses: actions-rs/toolchain@v1
26-
with:
27-
toolchain: nightly
28-
components: rust-src, llvm-tools-preview
29-
profile: minimal
18+
sudo apt-get install -y \
19+
xorriso \
20+
nasm \
21+
mtools \
22+
build-essential \
23+
git \
24+
curl \
25+
unzip
3026
31-
- name: Build kernel & ISO
27+
- name: Install Rust nightly toolchain
3228
run: |
33-
bash scripts/make_iso.sh
29+
rustup toolchain install nightly --profile minimal
30+
rustup default nightly
31+
rustup component add rust-src
3432
35-
- name: Boot in QEMU (headless) and check log
36-
run: |
37-
set -e
38-
timeout 20s bash -c 'qemu-system-x86_64 -machine q35 -m 256M -serial stdio -display none -cdrom build/rint-m1.iso -no-reboot | tee qemu.log || true'
39-
grep -q "RINT KERNEL: init OK" qemu.log
33+
- name: Build ISO
34+
run: bash scripts/make_iso.sh
35+
36+
- name: Upload ISO artifact
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: rint-m1.iso
40+
path: build/rint-m1.iso

kernel/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
1818
}
1919
}
2020

21-
#[unsafe(no_mangle)]
21+
#[unsafe(no_mangle)] // 禁止编译器对该函数进行名称改编,确保最终 ELF 里的符号名就是 kstart
2222
extern "C" fn kstart() -> ! {
2323
init_serial();
2424
banner();
@@ -52,8 +52,8 @@ fn banner() {
5252
kprintln!("==============================");
5353
}
5454

55-
#[doc(hidden)]
56-
pub fn kprint(args: core::fmt::Arguments) {
55+
#[doc(hidden)] //在生成文档(rustdoc)时不出现在公开 API 文档里,表示它是内部实现,用户应通过宏 kprintln! 间接调用
56+
pub fn kprint(args: core::fmt::Arguments) { // 生成一个封装好的格式化参数对象
5757
let mut lock = SERIAL1.lock();
5858
if let Some(sp) = lock.as_mut() {
5959
let _ = sp.write_fmt(args);
@@ -63,7 +63,8 @@ pub fn kprint(args: core::fmt::Arguments) {
6363

6464
#[macro_export]
6565
macro_rules! kprintln {
66-
($($arg:tt)*) => {
66+
// 接受任意格式化参数列表,等同 println! 的可变参数匹配方式
67+
($($arg:tt)*) => { // $arg:tt:匹配任意“token tree”片段;$( … )*:表示重复零次或多次
6768
$crate::kprint(core::format_args!($($arg)*))
6869
};
6970
}

kernel/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use core::arch::global_asm;
55

6-
// Minimal bootstrap: set a temporary stack and call kstart() defined in lib.rs.
7-
// Limine loads the kernel in long mode; we rely on its environment.
6+
// 以汇编形式把最小的临时栈嵌入到 ELF 中,从而让 Limine 找到入口并使用该栈
7+
// 然后把控制权交给 Rust 中定义的 kstart
88
global_asm!(
99
r#"
1010
.section .text._start

limine.cfg

Lines changed: 0 additions & 8 deletions
This file was deleted.

limine.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Global options
2+
timeout: 0
3+
default_entry: 1
4+
interface_branding: Rint Kernel
5+
6+
# Boot entry using Limine protocol
7+
/Rint Kernel
8+
protocol: limine
9+
# The kernel is copied by scripts/make_iso.sh to /boot/kernel.bin in the ISO
10+
path: boot():/boot/kernel.bin
11+
12+
# Optional examples:
13+
# resolution: 1024x768x32
14+
# kaslr: yes
15+
# cmdline: loglevel=info

scripts/make_iso.sh

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,96 @@ ISO_DIR="${BUILD_DIR}/iso"
77
KERNEL_BIN="${ROOT_DIR}/target/x86_64-rint/debug/rint-kernel"
88
LIMINE_DIR="${BUILD_DIR}/limine"
99

10-
mkdir -p "${ISO_DIR}/boot" "${LIMINE_DIR}"
10+
mkdir -p "${ISO_DIR}/boot" "${ISO_DIR}/EFI/BOOT" "${LIMINE_DIR}"
1111

12+
# 必需:xorriso
1213
if ! command -v xorriso >/dev/null; then
1314
echo "Please install xorriso (sudo apt-get install xorriso)" >&2
1415
exit 1
1516
fi
17+
18+
# 可选:QEMU(CI 中不强制)
1619
if ! command -v qemu-system-x86_64 >/dev/null; then
17-
echo "Please install QEMU (sudo apt-get install qemu-system-x86)" >&2
18-
exit 1
20+
echo "Warning: QEMU not found (sudo apt-get install qemu-system-x86). ISO build will continue without QEMU." >&2
1921
fi
2022

21-
# Build limine from upstream if missing
23+
# 获取 Limine binary release 并运行 configure
2224
if [ ! -d "${LIMINE_DIR}/.git" ]; then
23-
git clone --depth=1 https://github.com/limine-bootloader/limine.git "${LIMINE_DIR}"
24-
make -C "${LIMINE_DIR}" -j
25+
git clone https://codeberg.org/Limine/Limine.git --branch=v10.6.2-binary --depth=1 "${LIMINE_DIR}"
26+
(cd "${LIMINE_DIR}" && ./configure)
27+
fi
28+
29+
# 解析 Limine 产物路径(bin 或 share)
30+
find_limine_file() {
31+
local fname="$1"
32+
local candidates=(
33+
"${LIMINE_DIR}/bin/${fname}"
34+
"${LIMINE_DIR}/share/${fname}"
35+
"${LIMINE_DIR}/${fname}"
36+
)
37+
for p in "${candidates[@]}"; do
38+
if [ -f "$p" ]; then
39+
echo "$p"
40+
return 0
41+
fi
42+
done
43+
return 1
44+
}
45+
46+
UEFI_CD_BIN="$(find_limine_file 'limine-uefi-cd.bin')" || { echo "Missing limine-uefi-cd.bin"; exit 1; }
47+
BIOS_CD_BIN="$(find_limine_file 'limine-bios-cd.bin')" || { echo "Missing limine-bios-cd.bin"; exit 1; }
48+
BIOS_SYS_BIN="$(find_limine_file 'limine-bios.sys')" || { echo "Missing limine-bios.sys"; exit 1; }
49+
BOOTX64_EFI="$(find_limine_file 'BOOTX64.EFI')" || { echo "Missing BOOTX64.EFI"; exit 1; }
50+
51+
# 选择配置文件:优先使用 limine.conf;若只存在 limine.cfg,复制为 limine.conf 并提示
52+
CONFIG_SRC=""
53+
if [ -f "${ROOT_DIR}/limine.conf" ]; then
54+
CONFIG_SRC="${ROOT_DIR}/limine.conf"
55+
elif [ -f "${ROOT_DIR}/limine.cfg" ]; then
56+
echo "Warning: using limine.cfg as limine.conf (please migrate to limine.conf format per USAGE.md)" >&2
57+
CONFIG_SRC="${ROOT_DIR}/limine.cfg"
58+
else
59+
echo "Missing limine.conf (or limine.cfg). Please add a config per CONFIG.md." >&2
60+
exit 1
2561
fi
2662

27-
# Build kernel
63+
# 编译内核(按需改为 --release 并同步 KERNEL_BIN)
2864
cargo +nightly build -Z build-std=core,compiler_builtins,alloc --target kernel/x86_64-rint.json
2965

30-
# Prepare ISO contents
66+
# 准备 ISO 内容(对齐 USAGE.md)
3167
cp "${KERNEL_BIN}" "${ISO_DIR}/boot/kernel.bin"
32-
cp "${ROOT_DIR}/limine.cfg" "${ISO_DIR}/limine.cfg"
33-
cp "${LIMINE_DIR}/limine-bios.sys" "${ISO_DIR}/limine-bios.sys"
34-
cp "${LIMINE_DIR}/limine-bios-cd.bin" "${ISO_DIR}/limine-bios-cd.bin"
35-
cp "${LIMINE_DIR}/limine-bios-pc.bin" "${ISO_DIR}/limine-bios-pc.bin"
36-
37-
# Create ISO
38-
xorriso -as mkisofs \
39-
-b limine-bios-cd.bin \
40-
-no-emul-boot -boot-load-size 4 -boot-info-table \
41-
--efi-boot limine-bios-pc.bin \
42-
-o "${BUILD_DIR}/rint-m1.iso" "${ISO_DIR}"
43-
44-
# Deploy limine to ISO
45-
"${LIMINE_DIR}/limine-deploy" "${BUILD_DIR}/rint-m1.iso"
46-
47-
echo "ISO created: ${BUILD_DIR}/rint-m1.iso"
68+
69+
# 将 limine.conf 和 limine-bios.sys 放在 ISO 根目录(USAGE.md 支持 root/limine/boot/boot/limine)
70+
cp "${CONFIG_SRC}" "${ISO_DIR}/limine.conf"
71+
cp "${BIOS_SYS_BIN}" "${ISO_DIR}/limine-bios.sys"
72+
73+
# CD 引导镜像放到 boot/ 目录,便于在 xorriso 中用相���路径引用
74+
cp "${BIOS_CD_BIN}" "${ISO_DIR}/boot/limine-bios-cd.bin"
75+
cp "${UEFI_CD_BIN}" "${ISO_DIR}/boot/limine-uefi-cd.bin"
76+
77+
# 复制 UEFI 可执行到 EFI/BOOT
78+
cp "${BOOTX64_EFI}" "${ISO_DIR}/EFI/BOOT/BOOTX64.EFI"
79+
80+
# 生成混合 BIOS/UEFI ISO(完全按 USAGE.md 推荐参数)
81+
xorriso -as mkisofs -R -r -J \
82+
-b boot/limine-bios-cd.bin \
83+
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
84+
-apm-block-size 2048 \
85+
--efi-boot boot/limine-uefi-cd.bin \
86+
-efi-boot-part --efi-boot-image --protective-msdos-label \
87+
"${ISO_DIR}" -o "${BUILD_DIR}/rint-m1.iso"
88+
89+
# 对生成的镜像执行 bios-install(替代旧版的 limine-deploy)
90+
LIMINE_CLI=""
91+
if [ -x "${LIMINE_DIR}/bin/limine" ]; then
92+
LIMINE_CLI="${LIMINE_DIR}/bin/limine"
93+
elif command -v limine >/dev/null; then
94+
LIMINE_CLI="$(command -v limine)"
95+
else
96+
echo "Limine CLI not found. Ensure ./configure produced bin/limine or install Limine to PATH." >&2
97+
exit 1
98+
fi
99+
100+
"${LIMINE_CLI}" bios-install "${BUILD_DIR}/rint-m1.iso"
101+
102+
echo "ISO created and installed with Limine: ${BUILD_DIR}/rint-m1.iso"

0 commit comments

Comments
 (0)