forked from openhwgroup/cva6-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
147 lines (121 loc) · 4.44 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Makefile for RISC-V toolchain; run 'make help' for usage. set XLEN here to 32 or 64.
XLEN := 64
ROOT := $(patsubst %/,%, $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
RISCV := $(PWD)/install$(XLEN)
DEST := $(abspath $(RISCV))
PATH := $(DEST)/bin:$(PATH)
TOOLCHAIN_PREFIX := $(ROOT)/buildroot/output/host/bin/riscv$(XLEN)-buildroot-linux-gnu-
CC := $(TOOLCHAIN_PREFIX)gcc
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
READELF := $(TOOLCHAIN_PREFIX)readelf
NR_CORES := $(shell nproc)
# default configure flags
fesvr-co = --prefix=$(RISCV) --target=riscv$(XLEN)-buildroot-linux-gnu
tests-co = --prefix=$(RISCV)/target
# specific flags and rules for 32 / 64 version
ifeq ($(XLEN), 32)
isa-sim-co = --prefix=$(RISCV) --with-isa=RV32IMA --with-priv=MSU
pk-co = --prefix=$(RISCV) --host=riscv$(XLEN)-buildroot-linux-gnu CC=$(CC) OBJDUMP=$(OBJDUMP) OBJCOPY=$(OBJCOPY) --enable-32bit
else
isa-sim-co = --prefix=$(RISCV) --with-fesvr=$(DEST)
pk-co = --prefix=$(RISCV) --host=riscv$(XLEN)-buildroot-linux-gnu CC=$(CC) OBJDUMP=$(OBJDUMP) OBJCOPY=$(OBJCOPY)
endif
# default make flags
fesvr-mk = -j$(NR_CORES)
isa-sim-mk = -j$(NR_CORES)
pk-mk = -j$(NR_CORES)
tests-mk = -j$(NR_CORES)
# linux image
buildroot_defconfig = configs/buildroot$(XLEN)_defconfig
linux_defconfig = configs/linux$(XLEN)_defconfig
busybox_defconfig = configs/busybox$(XLEN).config
install-dir:
mkdir -p $(RISCV)
fesvr: install-dir $(CC)
mkdir -p riscv-fesvr/build
cd riscv-fesvr/build;\
../configure $(fesvr-co);\
make $(fesvr-mk);\
make install;\
cd $(ROOT)
isa-sim: install-dir $(CC)
mkdir -p riscv-isa-sim/build
cd riscv-isa-sim/build;\
../configure $(isa-sim-co);\
make $(isa-sim-mk);\
make install;\
cd $(ROOT)
tests: install-dir $(CC)
mkdir -p riscv-tests/build
cd riscv-tests/build;\
autoconf;\
../configure $(tests-co);\
make $(tests-mk);\
make install;\
cd $(ROOT)
pk: install-dir $(CC)
mkdir -p riscv-pk/build
cd riscv-pk/build;\
../configure $(pk-co);\
make $(pk-mk);\
make install;\
cd $(ROOT)
$(CC): $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig)
make -C buildroot defconfig BR2_DEFCONFIG=../$(buildroot_defconfig)
make -C buildroot host-gcc-final
all: $(CC) fesvr isa-sim
# benchmark for the cache subsystem
rootfs/cachetest.elf: $(CC)
cd ./cachetest/ && $(CC) cachetest.c -o cachetest.elf
cp ./cachetest/cachetest.elf $@
# cool command-line tetris
rootfs/tetris: $(CC)
cd ./vitetris/ && make clean && ./configure CC=$(CC) && make
cp ./vitetris/tetris $@
$(RISCV)/vmlinux: $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig) $(CC) rootfs/cachetest.elf rootfs/tetris
mkdir -p build
make -C buildroot
cp buildroot/output/images/vmlinux build/vmlinux
cp build/vmlinux $@
$(RISCV)/bbl: $(RISCV)/vmlinux
cd build && ../riscv-pk/configure --host=riscv$(XLEN)-buildroot-linux-gnu READELF=$(READELF) OBJCOPY=$(OBJCOPY) CC=$(CC) OBJDUMP=$(OBJDUMP) --with-payload=vmlinux --enable-logo --with-logo=../configs/logo.txt CFLAGS=-fno-stack-protector
make -C build
cp build/bbl $@
$(RISCV)/bbl_binary: $(RISCV)/bbl
$(OBJCOPY) -O binary $< $@
$(RISCV)/bbl.bin: $(RISCV)/bbl
$(OBJCOPY) -S -O binary --change-addresses -0x80000000 $< $@
# specific recipes
gcc: $(CC)
vmlinux: $(RISCV)/vmlinux
bbl: $(RISCV)/bbl
bbl.bin: $(RISCV)/bbl.bin
bbl_binary: $(RISCV)/bbl_binary
images: $(CC) $(RISCV)/bbl $(RISCV)/bbl.bin $(RISCV)/bbl_binary
clean:
rm -rf $(RISCV)/vmlinux $(RISCV)/bbl $(RISCV)/bbl.bin $(RISCV)/bbl_binary build riscv-pk/build/vmlinux riscv-pk/build/bbl cachetest/*.elf rootfs/tetris rootfs/cachetest.elf
make -C buildroot clean
clean-all: clean
rm -rf $(RISCV) riscv-fesvr/build riscv-isa-sim/build riscv-tests/build riscv-pk/build
.PHONY: gcc vmlinux bbl bbl.bin bbl_binary images help
help:
@echo "usage: $(MAKE) [tool/img] ..."
@echo ""
@echo "install compiler with"
@echo " make gcc"
@echo ""
@echo "install [tool] with compiler"
@echo " where tool can be any one of:"
@echo " gcc fesvr isa-sim tests pk"
@echo ""
@echo "build linux images for cva6"
@echo " make images"
@echo " for specific artefact"
@echo " make [vmlinux/bbl/bbl.bin]"
@echo ""
@echo "There are two clean targets:"
@echo " Clean only build object"
@echo " make clean"
@echo " Clean everything (including toolchain etc)"
@echo " make clean-all"