Skip to content

Commit

Permalink
feat: adapt for new cargo-byteos
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Apr 29, 2024
1 parent d25558f commit ab1810e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 40 deletions.
29 changes: 10 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
SHELL := /bin/bash
ARCH := riscv64
BOARD:= qemu
byteos = $(shell byteos $(1) byteos.toml $(ARCH)-$(BOARD) $(2))
byteos_config = $(call byteos,config,get_cfg $(1))
byteos_env = $(call byteos,config,get_env $(1))
NVME := off
NET := off
ARCH := riscv64
LOG := error
BOARD:= qemu
RELEASE := release
QEMU_EXEC ?=
BUILD_ARGS :=
GDB ?= gdb-multiarch
MOUNT_IMG_PATH ?= $(shell pwd)/mount.img
ROOT_FS := fat32
ROOT_FS := $(call byteos_config,root_fs)

BUS := device
ifeq ($(ARCH), x86_64)
Expand All @@ -34,7 +35,6 @@ else ifeq ($(ARCH), aarch64)
else ifeq ($(ARCH), loongarch64)
TARGET := loongarch64-unknown-none
QEMU_EXEC += qemu-system-$(ARCH) -kernel $(KERNEL_ELF)
BUILD_ARGS += -Z build-std
BUS := pci
else
$(error "ARCH" must be one of "x86_64", "riscv64", "aarch64" or "loongarch64")
Expand All @@ -54,9 +54,6 @@ QEMU_EXEC += -m 128M\
-smp 1 \
-D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors

ifeq ($(RELEASE), release)
BUILD_ARGS += --release
endif
TESTCASE := testcase-$(ARCH)
ifeq ($(NVME), on)
QEMU_EXEC += -drive file=$(FS_IMG),if=none,id=nvm \
Expand All @@ -78,38 +75,32 @@ features += k210
endif

all: build

offline:
RUST_BACKTRACE=1 LOG=$(LOG) cargo build $(BUILD_ARGS) --features "$(features)" --offline
# cp $(SBI) sbi-qemu
# cp $(KERNEL_ELF) kernel-qemu
rust-objcopy --binary-architecture=riscv64 $(KERNEL_ELF) --strip-all -O binary os.bin

fs-img:
ifeq ($(ROOT_FS), fat32)
@echo "ROOT_FS: $(ROOT_FS)"
rm -f $(FS_IMG)
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
sync
ifeq ($(ROOT_FS), fat32)
mkfs.vfat -F 32 $(FS_IMG)
mkdir mount/ -p
sudo mount $(FS_IMG) mount/ -o uid=1000,gid=1000
sudo rm -rf mount/*
sudo cp -rf tools/$(TESTCASE)/* mount/
sudo chmod 777 $(FS_IMG)
sync
sudo umount $(FS_IMG)
else ifeq ($(ROOT_FS), ext4)
rm -f $(FS_IMG)
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
mkfs.ext4 -F -O ^metadata_csum_seed $(FS_IMG)
mkdir mount/ -p
sudo mount $(FS_IMG) mount/
endif
sudo cp -rf tools/$(TESTCASE)/* mount/
sync
sudo umount $(FS_IMG)
endif

build:
# RUST_BACKTRACE=1 LOG=$(LOG) MOUNT_IMG_PATH=$(MOUNT_IMG_PATH) cargo build --target $(TARGET) $(BUILD_ARGS) --features "$(features)"
byteos build byteos.toml $(ARCH)-$(BOARD)
rust-objcopy --binary-architecture=$(ARCH) $(KERNEL_ELF) --strip-all -O binary $(KERNEL_BIN)

Expand Down
29 changes: 8 additions & 21 deletions byteos.toml
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
# build for riscv64-qemu
[global.configs]
board = "qemu"
root_fs = "fat32"

[global.env]
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

[bin.riscv64-qemu]
target = "riscv64gc-unknown-none-elf"
[bin.riscv64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "ext4"

[bin.riscv64-qemu.env]
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

# build for x86_64-qemu
[bin.x86_64-qemu]
target = "x86_64-unknown-none"
[bin.x86_64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "ext4"

[bin.x86_64-qemu.env]
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

# build for aarch64-qemu
[bin.aarch64-qemu]
target = "aarch64-unknown-none-softfloat"
[bin.aarch64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "fat32"

[bin.aarch64-qemu.env]
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

# build for loongarch64-qemu
[bin.loongarch64-qemu]
target = "loongarch64-unknown-none"
build_std = true
[bin.loongarch64-qemu.configs]
board = "qemu"
driver = "kramdisk"
root_fs = "ext4"

[bin.loongarch64-qemu.env]
HEAP_SIZE = "0x0180_0000"
CARGO_CFG_DRIVER = "kramdisk"
MOUNT_IMG_PATH = "mount.img"

0 comments on commit ab1810e

Please sign in to comment.