-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathMakefile
79 lines (63 loc) · 3.26 KB
/
Makefile
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
# (C) 2025, Cornell University
# All rights reserved.
# BOARD can be a7_35t or a7_100t
BOARD = a7_35t
QEMU = qemu-system-riscv32
# TOOLCHAIN can be XPACK or GNU
TOOLCHAIN = XPACK
ifeq ($(TOOLCHAIN), XPACK)
# Pre-compiled GNU toolchain binaries from xPack
# https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases
RISCV_CC = riscv-none-elf-gcc
OBJDUMP = riscv-none-elf-objdump
OBJCOPY = riscv-none-elf-objcopy
endif
ifeq ($(TOOLCHAIN), GNU)
# The official GNU toolchain
# https://github.com/riscv-collab/riscv-gnu-toolchain
RISCV_CC = riscv32-unknown-elf-gcc
OBJDUMP = riscv32-unknown-elf-objdump
OBJCOPY = riscv32-unknown-elf-objcopy
endif
DEBUG = build/debug
RELEASE = build/release
APPS_DEPS = apps/*.* library/egos.h library/*/* Makefile
EGOS_DEPS = earth/* grass/* library/egos.h library/*/* Makefile
FILESYS = 1
LDFLAGS = -nostdlib -lc -lgcc
INCLUDE = -Ilibrary -Ilibrary/elf -Ilibrary/file -Ilibrary/libc -Ilibrary/syscall
CFLAGS = -march=rv32ima_zicsr -mabi=ilp32 -Wl,--gc-sections -ffunction-sections -fdata-sections -fdiagnostics-show-option
DEBUG_FLAGS = --source --all-headers --demangle --line-numbers --wide
SYSAPP_ELFS = $(patsubst %.c, $(RELEASE)/%.elf, $(notdir $(wildcard apps/system/*.c)))
USRAPP_ELFS = $(patsubst %.c, $(RELEASE)/user/%.elf, $(notdir $(wildcard apps/user/*.c)))
egos: $(USRAPP_ELFS) $(SYSAPP_ELFS) $(RELEASE)/egos.elf
$(RELEASE)/egos.elf: $(EGOS_DEPS)
@echo "$(YELLOW)-------- Compile EGOS --------$(END)"
$(RISCV_CC) $(CFLAGS) $(INCLUDE) -DKERNEL $(filter %.s, $(wildcard $^)) $(filter %.c, $(wildcard $^)) -Tlibrary/elf/egos.lds $(LDFLAGS) -o $@
@$(OBJDUMP) $(DEBUG_FLAGS) $@ > $(DEBUG)/egos.lst
$(SYSAPP_ELFS): $(RELEASE)/%.elf : apps/system/%.c $(APPS_DEPS)
@echo "Compile app$(CYAN)" $(patsubst %.c, %, $(notdir $<)) "$(END)=>" $@
@$(RISCV_CC) $(CFLAGS) $(INCLUDE) -DFILESYS=$(FILESYS) -DKERNEL -Iapps apps/app.s $(filter %.c, $(wildcard $^)) -Tlibrary/elf/app.lds $(LDFLAGS) -o $@
@$(OBJDUMP) $(DEBUG_FLAGS) $@ > $(patsubst %.c, $(DEBUG)/%.lst, $(notdir $<))
$(USRAPP_ELFS): $(RELEASE)/user/%.elf : apps/user/%.c $(APPS_DEPS)
@mkdir -p $(DEBUG) $(RELEASE) $(RELEASE)/user
@echo "Compile app$(CYAN)" $(patsubst %.c, %, $(notdir $<)) "$(END)=>" $@
@$(RISCV_CC) $(CFLAGS) $(INCLUDE) -Iapps apps/app.s $(filter %.c, $(wildcard $^)) -Tlibrary/elf/app.lds $(LDFLAGS) -o $@
@$(OBJDUMP) $(DEBUG_FLAGS) $@ > $(patsubst %.c, $(DEBUG)/%.lst, $(notdir $<))
install: egos
@echo "$(GREEN)-------- Create the Disk & BootROM Image --------$(END)"
$(OBJCOPY) -O binary $(RELEASE)/egos.elf tools/qemu/egos.bin
$(CC) tools/mkfs.c library/file/file$(FILESYS).c -DMKFS -DFILESYS=$(FILESYS) -DCPU_BIN_FILE="\"fpga/vexriscv/vexriscv_cpu_$(BOARD).bin\"" $(INCLUDE) -o tools/mkfs
cd tools; rm -f disk.img bootROM.bin; ./mkfs
qemu: install
@echo "$(YELLOW)-------- Simulate on QEMU-RISCV --------$(END)"
$(QEMU) -nographic -readconfig tools/qemu/config.toml
program: install
@echo "$(YELLOW)-------- Program the Arty $(BOARD) on-board ROM --------$(END)"
cd tools/fpga/openocd; time openocd -f 7series_$(BOARD).txt
clean:
rm -rf build earth/kernel_entry.lds tools/mkfs tools/mkrom tools/qemu/egos.bin tools/disk.img tools/bootROM.bin
GREEN = \033[1;32m
YELLOW = \033[1;33m
CYAN = \033[1;36m
END = \033[0m