Failed to fetch fork details. Try again later.
-
CsUxYq authoredd6f83cc6
Forked from
破败王者之剑 / OSKernel2022-LOS
Source project has a limited visibility.
TARGET := riscv64gc-unknown-none-elf
MODE := release
KERNEL_ELF := ./target/$(TARGET)/$(MODE)/os
KERNEL_BIN := $(KERNEL_ELF).bin
BOOTLOADER := ./bootloader/rustsbi-qemu.bin
export CPU_NUMS = 2
export LOG = ERROR
USER_PATH := ./user/target/$(TARGET)/$(MODE)/
FS_IMG := ./fs.img
# board and bootloader
BOARD ?= qemu
SBI ?= rustsbi
BOOTLOADER := ./bootloader/$(SBI)-$(BOARD).bin
BOOTLOADER_SIZE = 131072 # 0x20000
# kernel entry
ifeq ($(BOARD), qemu)
KERNEL_ENTRY := 0x80200000
else ifeq ($(BOARD), k210)
KERNEL_ENTRY := 0x80020000
endif
# Run k210
K210_SERIALPORT := /dev/tty.usbserial-1420
k210_BURNER := ./tools/kflash.py
all: switch-check user
@echo Platform: $(BOARD)
@cp os/link-$(BOARD).ld os/link.ld
@cd ./os && cargo build --release --features "board_$(BOARD)"
@rm os/link.ld
@rust-objcopy --binary-architecture=riscv64 $(KERNEL_ELF) \
--strip-all \
-O binary $(KERNEL_BIN)
test:
@cross test --target riscv64gc-unknown-linux-gnu
switch-check:
ifeq ($(BOARD), qemu)
@(which last-qemu) || (touch last-qemu && make clean)
else ifeq ($(BOARD), k210)
@(which last-k210) || (touch last-k210 && make clean)
endif
user:
@cd ./user && python build.py && cargo build --release --features "board_$(BOARD)"
fs-img:
@dd if=/dev/zero of=$(FS_IMG) bs=512 count=1024
run: fs-img
ifeq ($(BOARD),qemu)
@qemu-system-riscv64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
-device loader,file=$(KERNEL_BIN),addr=0x80200000 \
-smp $(CPU_NUMS) \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
else
@cp $(BOOTLOADER) $(BOOTLOADER).copy
dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(BOOTLOADER_SIZE) seek=1
@mv $(BOOTLOADER).copy $(KERNEL_BIN)
@sudo chmod 777 $(K210_SERIALPORT)
python3 ./tools/kflash.py -p $(K210_SERIALPORT) -b 1500000 $(KERNEL_BIN)
python3 -m serial.tools.miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210_SERIALPORT) 115200
7172737475767778798081828384858687888990
endif
debug:
@echo "you should run command below in another terminal(same path):"
@echo "riscv64-unknown-elf-gdb $(KERNEL_ELF)"
@qemu-system-riscv64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
-device loader,file=$(KERNEL_BIN),addr=0x80200000 \
-s -S \
-smp $(CPU_NUMS) \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
clean:
@cargo clean
.PHONY: all test switch-check user run debug clean