Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[build]
target = "riscv64gc-unknown-none-elf"
target-dir = 'build'
rustflags = ["-C", "force-unwind-tables"]

Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ jobs:
include:
- arch: riscv64
target: riscv64gc-unknown-none-elf
- arch: loongarch64
target: loongarch64-unknown-none-softfloat
platform: virt
- arch: x86_64
target: x86_64-unknown-none
platform: acpi_compat
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -30,23 +32,24 @@ jobs:

- name: Setup QEMU
run: |
sudo apt-get install -y qemu-system-${{ matrix.arch }} qemu-kvm
sudo apt-get update
sudo apt-get install -y qemu-system-${{ matrix.arch }} qemu-kvm expect

- name: Configure
run: ./configure

- name: Run build for ${{ matrix.arch }} targets
run: |
make build ARCH=${{ matrix.arch }} MODE=release
zstd -k build/boot-${{ matrix.arch }}.img
zstd -k build/boot-${{ matrix.arch }}-${{ matrix.platform }}.img

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: eonix-kernel-and-image-${{ matrix.arch }}
path: |
build/${{ matrix.target }}/release/eonix_kernel
build/boot-${{ matrix.arch }}.img.zst
build/boot-${{ matrix.arch }}-${{ matrix.platform }}.img.zst

- name: Test run for ${{ matrix.arch }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/

.idea/
.vscode/settings.json

test/

Expand Down
10 changes: 10 additions & 0 deletions .vscode/settings.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
// Uncomment and set the target you'd like to use for analysis.
//
// Available targets:
// - x86_64-unknown-none.json
// - riscv64gc-unknown-none-elf
// - loongarch64-unknown-none-softfloat
// "rust-analyzer.cargo.target": "x86_64-unknown-none.json",
}
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

36 changes: 19 additions & 17 deletions Makefile.src
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ endif

ifeq ($(ARCH),riscv64)

PLATFORM ?= virt

BINARY_DIR_BASE := build/riscv64gc-unknown-none-elf
BINARY_DIR := $(BINARY_DIR_BASE)/$(MODE)

QEMU_ARGS += \
-machine virt -kernel $(BINARY_DIR)/eonix_kernel \
-device virtio-blk-device,drive=disk0,bus=virtio-mmio-bus.0 \
-device virtio-net-device,netdev=mynet0 \
-drive id=disk0,file=build/boot-riscv64.img,format=raw,if=none \
-drive id=disk0,file=build/boot-riscv64-virt.img,format=raw,if=none \
-netdev user,id=mynet0 \
-rtc base=utc

Expand All @@ -73,19 +75,18 @@ endif

CARGO_FLAGS += --target riscv64gc-unknown-none-elf

.PHONY: build
build: $(BINARY_DIR)/eonix_kernel build/boot-riscv64.img

else ifeq ($(ARCH),loongarch64)

PLATFORM ?= virt

BINARY_DIR_BASE := build/loongarch64-unknown-none-softfloat
BINARY_DIR := $(BINARY_DIR_BASE)/$(MODE)

QEMU_ARGS += \
-machine virt -kernel $(BINARY_DIR)/eonix_kernel -m 1G \
-device virtio-blk-pci,drive=disk0 \
-device virtio-net-pci,netdev=mynet0 \
-drive id=disk0,file=build/boot-loongarch64.img,format=raw,if=none \
-drive id=disk0,file=build/boot-loongarch64-virt.img,format=raw,if=none \
-netdev user,id=mynet0,hostfwd=tcp::5555-:5555,hostfwd=udp::5555-:5555 \
-rtc base=utc

Expand All @@ -97,11 +98,10 @@ endif

CARGO_FLAGS += --target loongarch64-unknown-none-softfloat

.PHONY: build
build: $(BINARY_DIR)/eonix_kernel build/boot-loongarch64.img

else ifeq ($(ARCH),x86_64)

PLATFORM ?= acpi_compat

BINARY_DIR_BASE := build/x86_64-unknown-none
BINARY_DIR := $(BINARY_DIR_BASE)/$(MODE)

Expand All @@ -110,7 +110,7 @@ QEMU_ARGS += \
-device ahci,id=ahci \
-device ide-hd,drive=disk0,bus=ahci.0 \
-device e1000e,netdev=mynet0 \
-drive id=disk0,file=build/boot-x86_64.img,format=raw,if=none \
-drive id=disk0,file=build/boot-x86_64-acpi_compat.img,format=raw,if=none \
-netdev user,id=mynet0

ifneq ($(IMG),)
Expand All @@ -121,11 +121,13 @@ endif

CARGO_FLAGS += --target x86_64-unknown-none.json

.PHONY: build
build: $(BINARY_DIR)/eonix_kernel build/boot-x86_64.img

endif

TARGET := $(ARCH)-$(PLATFORM)

.PHONY: build
build: $(BINARY_DIR)/eonix_kernel build/boot-$(TARGET).img

.PHONY: run
run: build build/kernel.sym
$(QEMU) $(QEMU_ARGS) -display none -serial mon:stdio
Expand Down Expand Up @@ -173,8 +175,8 @@ $(BINARY_DIR)/eonix_kernel: $(KERNEL_DEPS)
build/kernel.sym: $(BINARY_DIR)/eonix_kernel
CARGO_TARGET_DIR=build cargo objcopy -q $(CARGO_FLAGS) -- --only-keep-debug build/kernel.sym

build/fs-%.img: user-programs/init_script_%.sh script/build-img.sh $(USER_PROGRAMS)
ARCH=$* OUTPUT=$@ sh script/build-img.sh
build/fs-%.img: user-programs/init_script_%.sh script/build-img/build-img $(USER_PROGRAMS)
script/build-img/build-img -t $* -o $@

build/mbr.bin: $(BINARY_DIR)/eonix_kernel
CARGO_TARGET_DIR=build cargo objcopy -q $(CARGO_FLAGS) -- -O binary -j .mbr build/mbr.bin
Expand All @@ -186,7 +188,7 @@ build/kernel.bin: $(BINARY_DIR)/eonix_kernel
CARGO_TARGET_DIR=build cargo objcopy -q $(CARGO_FLAGS) -- -O binary --strip-debug \
-R .mbr -R .stage1 build/kernel.bin

build/boot-x86_64.img: build/fs-x86_64.img build/mbr.bin build/stage1.bin build/kernel.bin
build/boot-x86_64-acpi_compat.img: build/fs-x86_64-acpi_compat.img build/mbr.bin build/stage1.bin build/kernel.bin
dd if=build/mbr.bin of=$@ bs=512 count=1 conv=notrunc 2> /dev/null
dd if=build/stage1.bin of=$@ bs=512 seek=1 conv=notrunc 2> /dev/null
dd if=build/kernel.bin of=$@ bs=4096 seek=1 conv=notrunc 2> /dev/null
Expand All @@ -195,13 +197,13 @@ build/boot-x86_64.img: build/fs-x86_64.img build/mbr.bin build/stage1.bin build/
sh -c 'echo n; echo; echo; echo 8192; echo; echo a; echo w' \
| $(FDISK) $@ 2> /dev/null > /dev/null

build/boot-riscv64.img: build/fs-riscv64.img
build/boot-riscv64-virt.img: build/fs-riscv64-virt.img
dd if=$< of=$@ bs=$(shell expr 4 \* 1024 \* 1024) \
seek=1 conv=notrunc 2> /dev/null
sh -c 'echo n; echo; echo; echo 8192; echo; echo a; echo w' \
| $(FDISK) $@ 2> /dev/null > /dev/null

build/boot-loongarch64.img: build/fs-loongarch64.img
build/boot-loongarch64-virt.img: build/fs-loongarch64-virt.img
dd if=$< of=$@ bs=$(shell expr 4 \* 1024 \* 1024) \
seek=1 conv=notrunc 2> /dev/null
sh -c 'echo n; echo; echo; echo 8192; echo; echo a; echo w' \
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2025-05-16
nightly-2026-01-09
58 changes: 0 additions & 58 deletions script/build-img.sh

This file was deleted.

94 changes: 94 additions & 0 deletions script/build-img/build-img
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/sh
# shellcheck source=./lib/lib.sh

. "$(dirname "$(realpath "$0")")/lib/lib.sh"

BASE_DIR="$(dirname "$(realpath "$0")")"

KB=1024
MB=$((1024 * KB))

TARGET=
IMAGE=
MOUNTPOINT="$(mktemp -d)"

usage() {
cat >&2 <<EOF
Usage: $0 -t <TARGET> -o <OUTPUT> [-h]

Options
-t The target building image for
[available: riscv64 x86 loongarch64]
-o Output image path
-h Show help message
EOF

exit "$1"
}

ensure_mount_macos() {
hdiutil detach "$MOUNTPOINT" > /dev/null 2>&1 || :
hdiutil attach "$IMAGE" -mountpoint "$MOUNTPOINT"
}

ensure_mount_linux() {
DEV=$(sudo losetup -f "$IMAGE" --show)
sudo mount "$DEV" "$MOUNTPOINT"
}

ensure_mount() {
if [ "$OS" = Darwin ]; then
ensure_mount_macos
return
fi

ensure_mount_linux
}

unmount_macos() {
hdiutil detach "$MOUNTPOINT"
}

unmount_linux() {
sudo umount "$MOUNTPOINT"
sudo losetup -d "$DEV"
}

cleanup() {
case "$OS" in
Darwin)
unmount_macos
;;
*)
unmount_linux
;;
esac
}

set -eu

while getopts "t:o:h" opt; do
case "$opt" in
t) TARGET="$OPTARG";;
o) IMAGE="$OPTARG";;
h) usage 0;;
?) usage 1;;
esac
done

shift $((OPTIND - 1))

[ -z "$TARGET" ] && die "ARCH is not set"
[ -z "$IMAGE" ] && die "output image path is not set"

echo "Build image with ARCH=$TARGET OUTPUT=$IMAGE MOUNTPOINT=$MOUNTPOINT"

dd if=/dev/zero of="$IMAGE" bs=$((1 * MB)) count=$((1024 - 4))
mkfs.fat -n SYSTEM "$IMAGE"

ensure_mount
trap cleanup EXIT

for name in $(iter_files_sorted "$BASE_DIR/platform/$TARGET"); do
( . "$name" )
done
39 changes: 39 additions & 0 deletions script/build-img/lib/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

OS=$(uname -s)
SUDO=$(which sudo || :)

info() {
echo "info : $1"
}

warn() {
echo "warn : $1" >&2
}

error() {
echo "fatal: $1" >&2
}

die() {
error "$1" && exit 1
}

sudo() {
"$SUDO" "$@"
}

copy_to_image() {
_prefix=sudo
[ "$OS" = Darwin ] && _prefix=

$_prefix cp "$1" "$MOUNTPOINT/$2"
}

iter_files() {
find -L "$1" -maxdepth 1 -type f
}

iter_files_sorted() {
iter_files "$@" | sort
}
5 changes: 5 additions & 0 deletions script/build-img/platform/loongarch64-virt/10-base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# shellcheck source=./../../lib/lib.sh

copy_to_image user-programs/busybox.la64 busybox
copy_to_image user-programs/init_script_loongarch64-virt.sh initsh
5 changes: 5 additions & 0 deletions script/build-img/platform/riscv64-virt/10-base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# shellcheck source=./../../lib/lib.sh

copy_to_image user-programs/busybox.static busybox
copy_to_image user-programs/init_script_riscv64-virt.sh initsh
Loading
Loading