Repository navigation
Expand file tree
/
Copy pathmakefile
More file actions
125 lines (97 loc) · 3.74 KB
/
Copy pathmakefile
File metadata and controls
125 lines (97 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
.PHONY: doc kernel build clean qemu run k210 flash
TARGET := riscv64imac-unknown-none-elf
MODE ?= release
MODE_FLAG := --target=riscv64imac-unknown-none-elf
KERNEL_FILE := target/$(TARGET)/$(MODE)/os
BIN_FILE := target/$(TARGET)/$(MODE)/kernel.bin
DEBUG_FILE ?= $(KERNEL_FILE)
FEATURES ?=
OBJDUMP := rust-objdump --arch-name=riscv64
OBJCOPY := rust-objcopy --binary-architecture=riscv64
FS_IMG := fs.img
# BOARD
BOOTLOADER := bootloader/rustsbi-qemu.bin
# BOOTLOADER := bootloader/opensbi-qemu.bin
BOOTLOADER_K210 := bootloader/rustsbi-k210.bin
K210-SERIALPORT = /dev/ttyUSB0
K210-BURNER = tools/kflash.py
LINK_FILE_DIR = kernel/src
ifeq ($(MODE), release)
MODE_FLAG += --release
endif
ifeq ($(VERBOSE), 0)
FEATURES += not_debug
endif
.PHONY: all doc kernel build clean qemu run k210 flash
all: qemu
cp $(BOOTLOADER) sbi-qemu
cp $(KERNEL_FILE) kernel-qemu
#all: k210
# @cp $(BIN_FILE) os.bin
build: kernel $(BIN_FILE)
qemu:
ifeq ($(MODE), release)
echo "release"
endif
@cp $(LINK_FILE_DIR)/linker-qemu.ld $(LINK_FILE_DIR)/linker.ld
@RUSTFLAGS="-Clink-arg=-T$(LINK_FILE_DIR)/linker.ld" cargo build $(MODE_FLAG) --features "board_qemu $(FEATURES)"
# --offline
@rm $(LINK_FILE_DIR)/linker.ld
$(OBJCOPY) $(KERNEL_FILE) --strip-all -O binary $(BIN_FILE)
asm:
@$(OBJDUMP) -d $(KERNEL_FILE) | less
# 清理编译出的文件
clean:
@cargo clean
k210:
@cp $(LINK_FILE_DIR)/linker-k210.ld $(LINK_FILE_DIR)/linker.ld
RUSTFLAGS="-Clink-arg=-T$(LINK_FILE_DIR)/linker.ld" cargo build $(MODE_FLAG) --features "board_k210 $(FEATURES)" --offline
@rm $(LINK_FILE_DIR)/linker.ld
$(OBJCOPY) $(KERNEL_FILE) --strip-all -O binary $(BIN_FILE)
@cp $(BOOTLOADER_K210) $(BOOTLOADER_K210).copy
@dd if=$(BIN_FILE) of=$(BOOTLOADER_K210).copy bs=131072 seek=1
@mv $(BOOTLOADER_K210).copy $(BIN_FILE)
flash: k210
(which $(K210-BURNER)) || (cd .. && git clone https://hub.fastgit.xyz/sipeed/kflash.py.git && mv kflash.py tools)
@sudo chmod 777 $(K210-SERIALPORT)
python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(BIN_FILE)
python3 -m serial.tools.miniterm --eol LF --dtr 0 --rts 0 --filter direct $(K210-SERIALPORT) 115200
run: qemu
@cp fs-origin.img fs.img
@qemu-system-riscv64 \
-machine virt \
-bios $(BOOTLOADER) \
-device loader,file=$(BIN_FILE),addr=0x80200000 \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-kernel $(BIN_FILE) \
-nographic \
-smp 4 -m 128m
@rm fs.img
# qemu-system-riscv64 -machine virt -bios sbi-qemu -device loader,file=kernel-qemu,addr=0x80200000 -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -kernel kernel-qemu -nographic -smp 4
debug: qemu
@cp fs-origin.img fs.img
@tmux new-session -d \
"qemu-system-riscv64 -machine virt -nographic -bios $(BOOTLOADER) -drive file=$(FS_IMG),if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -device loader,file=$(BIN_FILE),addr=0x80200000 -s -S && echo '按任意键继续' && read -n 1" && \
tmux split-window -h "riscv64-elf-gdb -ex 'file $(DEBUG_FILE)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
tmux -2 attach-session -d
@rm fs.img
gdb:
riscv64-elf-gdb \
-ex 'file $(DEBUG_FILE)' \
-ex 'set arch riscv:rv64' \
-ex 'target remote localhost:1234'
hexdump:
hexdump $(FS_IMG) -C -s 0x10F200
coredump:
cd kernel && make -f makefile FS_IMG=../$(FS_IMG) coredump || exit 1;
objdump:
rust-objdump --arch-name=riscv64 -d $(KERNEL_FILE)
clean:
rm $(KERNEL_FILE) $(BIN_FILE)
fs-img:
@rm -f $(FS_IMG)
@dd if=/dev/zero of=$(FS_IMG) count=81920 bs=512 # 40M
@mkfs.vfat $(FS_IMG) -F 32
docker:
docker run --rm -it -v ${PWD}:/mnt -w /mnt qemu:4.2.1 bash