rCore-Tutorial-v3/os/Makefile

91 lines
2.5 KiB
Makefile
Raw Normal View History

2020-11-11 12:50:00 +04:00
# Building
TARGET := riscv64gc-unknown-none-elf
MODE := release
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
KERNEL_BIN := $(KERNEL_ELF).bin
2020-11-11 12:59:44 +04:00
KERNEL_ENTRY_PA := 0x80020000
2020-11-11 12:50:00 +04:00
DISASM_TMP := target/$(TARGET)/$(MODE)/asm
FS_IMG := ../user/target/$(TARGET)/$(MODE)/fs.img
SDCARD := /dev/sdb
2020-12-20 09:52:38 +04:00
APPS := ../user/src/bin
2020-11-11 12:50:00 +04:00
# BOARD
BOARD ?= qemu
SBI ?= rustsbi
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
2020-11-11 12:50:00 +04:00
# Run K210
K210-SERIALPORT = /dev/ttyUSB0
K210-BURNER = ../tools/kflash.py
2020-11-11 12:50:00 +04:00
# Binutils
OBJDUMP := rust-objdump --arch-name=riscv64
OBJCOPY := rust-objcopy --binary-architecture=riscv64
# Disassembly
DISASM ?= -x
build: env $(KERNEL_BIN) $(FS_IMG)
env:
(rustup target list | grep "riscv64gc-unknown-none-elf (installed)") || rustup target add $(TARGET)
cargo install cargo-binutils
rustup component add rust-src
rustup component add llvm-tools-preview
sdcard: $(FS_IMG)
2021-01-20 20:26:56 +04:00
@echo "Are you sure write to $(SDCARD) ? [y/N] " && read ans && [ $${ans:-N} = y ]
@sudo dd if=/dev/zero of=$(SDCARD) bs=1048576 count=16
@sudo dd if=$(FS_IMG) of=$(SDCARD)
2020-11-11 12:50:00 +04:00
$(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
2020-12-20 09:52:38 +04:00
$(FS_IMG): $(APPS)
@cd ../user && make build
@cd ../easy-fs && cargo run --release
2020-12-20 09:52:38 +04:00
$(APPS):
2020-11-11 12:50:00 +04:00
kernel:
@cargo build --release --features "board_$(BOARD)"
2020-11-11 12:50:00 +04:00
clean:
@cargo clean
disasm: kernel
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) | less
disasm-vim: kernel
@$(OBJDUMP) $(DISASM) $(KERNEL_ELF) > $(DISASM_TMP)
@vim $(DISASM_TMP)
@rm $(DISASM_TMP)
run: run-inner
run-inner: build
ifeq ($(BOARD),qemu)
@qemu-system-riscv64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
2020-12-16 06:18:38 +04:00
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
2020-11-11 12:50:00 +04:00
else
@cp $(BOOTLOADER) $(BOOTLOADER).copy
2021-01-20 20:26:56 +04:00
@dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=131072 seek=1
2020-11-11 12:50:00 +04:00
@mv $(BOOTLOADER).copy $(KERNEL_BIN)
@sudo chmod 777 $(K210-SERIALPORT)
python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(KERNEL_BIN)
2021-01-20 20:26:56 +04:00
python3 -m serial.tools.miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210-SERIALPORT) 115200
2020-11-11 12:50:00 +04:00
endif
2020-11-11 12:59:44 +04:00
debug: build
@tmux new-session -d \
"qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -s -S" && \
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
tmux -2 attach-session -d
.PHONY: build env kernel clean disasm disasm-vim run-inner