forked from openhwgroup/cva6-sdk
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
184 lines (152 loc) · 6.03 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# 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
MKIMAGE := u-boot/tools/mkimage
NR_CORES := $(shell nproc)
# SBI options
PLATFORM := fpga/ariane
FW_FDT_PATH ?=
sbi-mk = PLATFORM=$(PLATFORM) CROSS_COMPILE=$(TOOLCHAIN_PREFIX) $(if $(FW_FDT_PATH),FW_FDT_PATH=$(FW_FDT_PATH),)
ifeq ($(XLEN), 32)
sbi-mk += PLATFORM_RISCV_ISA=rv32ima PLATFORM_RISCV_XLEN=32
else
sbi-mk += PLATFORM_RISCV_ISA=rv64imafdc PLATFORM_RISCV_XLEN=64
endif
# U-Boot options
ifeq ($(XLEN), 32)
UIMAGE_LOAD_ADDRESS := 0x80400000
UIMAGE_ENTRY_POINT := 0x80400000
else
UIMAGE_LOAD_ADDRESS := 0x80200000
UIMAGE_ENTRY_POINT := 0x80200000
endif
# default configure flags
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
else
isa-sim-co = --prefix=$(RISCV)
endif
# default make flags
isa-sim-mk = -j$(NR_CORES)
tests-mk = -j$(NR_CORES)
buildroot-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)
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)
$(CC): $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig)
make -C buildroot defconfig BR2_DEFCONFIG=../$(buildroot_defconfig)
make -C buildroot host-gcc-final $(buildroot-mk)
all: $(CC) 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 $(RISCV)
make -C buildroot $(buildroot-mk)
cp buildroot/output/images/vmlinux $@
$(RISCV)/Image: $(RISCV)/vmlinux
$(OBJCOPY) -O binary -R .note -R .comment -S $< $@
$(RISCV)/Image.gz: $(RISCV)/Image
gzip -9 -k --force $< > $@
# U-Boot-compatible Linux image
$(RISCV)/uImage: $(RISCV)/Image.gz $(MKIMAGE)
$(MKIMAGE) -A riscv -O linux -T kernel -a $(UIMAGE_LOAD_ADDRESS) -e $(UIMAGE_ENTRY_POINT) -C gzip -n "CV$(XLEN)A6Linux" -d $< $@
$(RISCV)/u-boot.bin: u-boot/u-boot.bin
mkdir -p $(RISCV)
cp $< $@
$(MKIMAGE) u-boot/u-boot.bin: $(CC)
make -C u-boot openhwgroup_cv$(XLEN)a6_genesysII_defconfig
make -C u-boot CROSS_COMPILE=$(TOOLCHAIN_PREFIX)
# OpenSBI with u-boot as payload
$(RISCV)/fw_payload.bin: $(RISCV)/u-boot.bin
make -C opensbi FW_PAYLOAD_PATH=$< $(sbi-mk)
cp opensbi/build/platform/$(PLATFORM)/firmware/fw_payload.elf $(RISCV)/fw_payload.elf
cp opensbi/build/platform/$(PLATFORM)/firmware/fw_payload.bin $(RISCV)/fw_payload.bin
# OpenSBI for Spike with Linux as payload
$(RISCV)/spike_fw_payload.elf: PLATFORM=generic
$(RISCV)/spike_fw_payload.elf: $(RISCV)/Image
make -C opensbi FW_PAYLOAD_PATH=$< $(sbi-mk)
cp opensbi/build/platform/$(PLATFORM)/firmware/fw_payload.elf $(RISCV)/spike_fw_payload.elf
cp opensbi/build/platform/$(PLATFORM)/firmware/fw_payload.bin $(RISCV)/spike_fw_payload.bin
# need to run flash-sdcard with sudo -E, be careful to set the correct SDDEVICE
# Number of sector required for FWPAYLOAD partition (each sector is 512B)
FWPAYLOAD_SECTORSTART := 2048
FWPAYLOAD_SECTORSIZE = $(shell ls -l --block-size=512 $(RISCV)/fw_payload.bin | cut -d " " -f5 )
FWPAYLOAD_SECTOREND = $(shell echo $(FWPAYLOAD_SECTORSTART)+$(FWPAYLOAD_SECTORSIZE) | bc)
SDDEVICE_PART1 = $(shell lsblk $(SDDEVICE) -no PATH | head -2 | tail -1)
SDDEVICE_PART2 = $(shell lsblk $(SDDEVICE) -no PATH | head -3 | tail -1)
# Always flash uImage at 512M, easier for u-boot boot command
UIMAGE_SECTORSTART := 512M
flash-sdcard: format-sd
dd if=$(RISCV)/fw_payload.bin of=$(SDDEVICE_PART1) status=progress oflag=sync bs=1M
dd if=$(RISCV)/uImage of=$(SDDEVICE_PART2) status=progress oflag=sync bs=1M
format-sd: $(SDDEVICE)
@test -n "$(SDDEVICE)" || (echo 'SDDEVICE must be set, Ex: make flash-sdcard SDDEVICE=/dev/sdc' && exit 1)
sgdisk --clear -g --new=1:$(FWPAYLOAD_SECTORSTART):$(FWPAYLOAD_SECTOREND) --new=2:$(UIMAGE_SECTORSTART):0 --typecode=1:3000 --typecode=2:8300 $(SDDEVICE)
# specific recipes
gcc: $(CC)
vmlinux: $(RISCV)/vmlinux
fw_payload.bin: $(RISCV)/fw_payload.bin
uImage: $(RISCV)/uImage
spike_payload: $(RISCV)/spike_fw_payload.elf
images: $(CC) $(RISCV)/fw_payload.bin $(RISCV)/uImage
clean:
rm -rf $(RISCV)/vmlinux cachetest/*.elf rootfs/tetris rootfs/cachetest.elf
rm -rf $(RISCV)/fw_payload.bin $(RISCV)/uImage $(RISCV)/Image.gz
make -C u-boot clean
make -C opensbi distclean
clean-all: clean
rm -rf $(RISCV) riscv-isa-sim/build riscv-tests/build
make -C buildroot clean
.PHONY: gcc vmlinux images help fw_payload.bin uImage
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 isa-sim tests"
@echo ""
@echo "build linux images for cva6"
@echo " make images"
@echo " for specific artefact"
@echo " make [vmlinux|uImage|fw_payload.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"