Skip to content

Commit

Permalink
fix: Fix board initialization dependencies.
Browse files Browse the repository at this point in the history
if we don't enable 'ramfs' feature, the vf2 board will use sd driver.
  • Loading branch information
Godones committed Jan 11, 2024
1 parent a7776a3 commit bfc27b4
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 153 deletions.
39 changes: 15 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NET ?=y

APPS_NAME := $(shell cd apps && ls -d */ | cut -d '/' -f 1)
VF2 ?=n
CV1811h ?=n
UNMATCHED ?=n
FEATURES :=
QEMU_ARGS :=
MEMORY_SIZE := 1024M
Expand All @@ -30,8 +30,6 @@ comma:= ,
empty:=
space:= $(empty) $(empty)

CARGO_FLAGS := -Zbuild-std=core,compiler_builtins,alloc \
-Zbuild-std-features=compiler-builtins-mem

ifeq ($(GUI),y)
QEMU_ARGS += -device virtio-gpu-device \
Expand All @@ -43,11 +41,9 @@ endif


ifeq ($(VF2),y)
FEATURES += vf2
else ifeq ($(CV1811h),y)
FEATURES += cv1811h
FEATURES += vf2 ramfs
else ifeq ($(UNMATCHED),y)
FEATURES += hifive
FEATURES += hifive ramfs
else
FEATURES += qemu
endif
Expand Down Expand Up @@ -80,7 +76,7 @@ define boot_qemu
-serial mon:stdio
endef

all:
all:run

install:
ifeq (, $(shell which $(TRACE_EXE)))
Expand All @@ -104,10 +100,11 @@ compile:
trace_info:
@(nm -n ${KERNEL_FILE} | $(TRACE_EXE) > kernel/src/trace/kernel_symbol.S)

user:
@cd apps && make all

sdcard:fat32 testelf user
sdcard:fat32
@if [ -d "tests/testbin-second-stage" ]; then \
sudo cp tests/testbin-second-stage/* /fat -r; \
fi
@make -C apps
@sudo umount /fat

run:sdcard install compile
Expand All @@ -125,26 +122,26 @@ board:install compile
@cp $(OUTPUT)/testos.bin /home/godones/projects/tftpboot/
@cp $(OUTPUT)/testos.bin ./alien.bin

qemu:
@rust-objcopy --strip-all $(OUTPUT)/boot -O binary $(OUTPUT)/testos.bin
@cp $(OUTPUT)/testos.bin /home/godones/projects/tftpboot/
@cp $(OUTPUT)/testos.bin ./alien.bin
qemu:install compile

vf2:board
@mkimage -f ./tools/vf2.its ./alien-vf2.itb
@rm ./kernel-qemu
@cp ./alien-vf2.itb /home/godones/projects/tftpboot/
@rm ./alien-vf2.itb


cv1811h:board
@mkimage -f ./tools/cv1811h.its ./alien-cv1811h.itb
@rm ./kernel-qemu
@cp ./alien-cv1811h.itb /home/godones/projects/tftpboot/
@rm ./alien-cv1811h.itb

unmatched:board
@mkimage -f ./tools/fu740.its ./alien-unmatched.itb
@rm ./kernel-qemu
@cp ./alien-unmatched.itb /home/godones/projects/tftpboot/
@rm ./alien-unmatched.itb

f_test:
qemu-system-riscv64 \
Expand All @@ -157,10 +154,6 @@ f_test:
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-device virtio-net-device,netdev=net -netdev user,id=net

testelf:
@if [ -d "tests/testbin-second-stage" ]; then \
sudo cp tests/testbin-second-stage/* /fat -r; \
fi

dtb:
$(call boot_qemu, -machine dumpdtb=riscv.dtb)
Expand All @@ -175,9 +168,7 @@ SecondFile:
#创建64MB大小空白文件
@dd if=/dev/zero of=$(IMG1) bs=1M count=64

ZeroFile:
#创建空白文件
@dd if=/dev/zero of=$(IMG) bs=1M count=64


fat32:
@-touch $(IMG)
Expand Down Expand Up @@ -217,11 +208,11 @@ kernel_asm:
@vim kernel.asm
@rm kernel.asm


docs:
cargo doc --open -p kernel --target riscv64gc-unknown-none-elf --features $(FEATURES)
clean:
@cargo clean
@rm riscv.*
@rm kernel-qemu
@rm alien-*

Expand Down
4 changes: 2 additions & 2 deletions boot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ kernel = { version = "0.1.0", path = "../kernel" }
[features]
default = []
vf2 = ["kernel/vf2"]
cv1811h = ["kernel/cv1811h"]
qemu = ["kernel/qemu"]
hifive = ["kernel/hifive"]

slab = ["kernel/slab"]
talloc = ["kernel/talloc"]
buddy = ["kernel/buddy"]

[build-dependencies]
ramfs= ["kernel/ramfs"]

2 changes: 1 addition & 1 deletion boot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn main(_: usize, _: usize) -> ! {
// init device tree
#[cfg(feature = "qemu")]
init_dtb(Some(device_tree_addr));
#[cfg(feature = "vf2")]
#[cfg(any(feature = "hifive", feature = "vf2"))]
init_dtb(None);
// init plic associate board
init_plic();
Expand Down
8 changes: 8 additions & 0 deletions docs/doc/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ sudo apt-get install uboot-mkimage

制作镜像的流程与上面的一致。





## minicom: cannot open /dev/ttyUSB0: No such file or directory 解决

remove any packages on your system with `brltty` in name

## 参考资料

[Adventures in RISC-V | writes (matrix89.github.io)](https://matrix89.github.io/writes/writes/experiments-in-riscv/)
Expand Down
7 changes: 5 additions & 2 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ features = [
]

[features]
default = ["pager_bitmap","test"]
default = ["pager_bitmap","test",]
vf2 = ["visionfive2-sd", "uart8250"]
cv1811h = []
hifive = ["uart16550"]
qemu = ["uart16550"]


net_test = []

slab = ["rslab"]
Expand All @@ -87,3 +88,5 @@ test = ["loopback"]

debug-eh-frame = []
debug-frame-pointer = []

ramfs = []
39 changes: 21 additions & 18 deletions kernel/src/board/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,32 @@ cfg_if! {
}
}

cfg_if! {
if #[cfg(any(feature = "vf2", feature = "hifive"))]{
core::arch::global_asm!(r#"
#[cfg(feature = "ramfs")]
core::arch::global_asm!(
r#"
.section .data
.global img_start
.global img_end
.align 12
img_start:
.incbin "./tools/sdcard.img"
img_end:
"#);
extern "C" {
pub fn img_start();
pub fn img_end();
}
pub fn checkout_fs_img() {
let img_start = img_start as usize;
let img_end = img_end as usize;
let img_size = img_end - img_start;
println!(
"img_start: {:#x}, img_end: {:#x}, img_size: {:#x}",
img_start, img_end, img_size
);
}
}
"#
);

#[cfg(feature = "ramfs")]
extern "C" {
pub fn img_start();
pub fn img_end();
}

#[cfg(feature = "ramfs")]
pub fn checkout_fs_img() {
let img_start = img_start as usize;
let img_end = img_end as usize;
let img_size = img_end - img_start;
println!(
"img_start: {:#x}, img_end: {:#x}, img_size: {:#x}",
img_start, img_end, img_size
);
}
Loading

0 comments on commit bfc27b4

Please sign in to comment.