forked from pulp-platform/cva6-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
199 lines (165 loc) · 6.65 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# 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 := $(ROOT)/install$(XLEN)
DEST := $(abspath $(RISCV))
PATH := $(DEST)/bin:$(PATH)
GZIP_BIN ?= gzip
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/cheshire
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=rv64gc 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_BIN) -9 --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 $< $@
# Also bring ELF and build annotated dump into install DIR
cp u-boot/u-boot $(RISCV)/
$(TOOLCHAIN_PREFIX)objdump -d -S u-boot/u-boot > $(RISCV)/u-boot.dump
$(MKIMAGE) u-boot/u-boot.bin: $(CC)
make -C u-boot pulp-platform_cheshire_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
# Also bring in dump
$(TOOLCHAIN_PREFIX)objdump -d -S opensbi/build/platform/$(PLATFORM)/firmware/fw_payload.elf > $(RISCV)/fw_payload.dump
# 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
DT_SECTORSTART := 2048
DT_SECTOREND := 264191 # 2048 + 128M
FW_SECTORSTART := 264192
FW_SECTOREND := 526335 # 264192 + 128M
UIMAGE_SECTORSTART := 526336
UIMAGE_SECTOREND := 1050623 # 526336 + 256M
ROOT_SECTORSTART := 1050624
ROOT_SECTOREND := 0
flash-sdcard: $(RISCV)/fw_payload.bin $(RISCV)/uImage format-sd
dd if=$(RISCV)/fw_payload.bin of=$(SDDEVICE)2 status=progress oflag=sync bs=1M
dd if=$(RISCV)/uImage of=$(SDDEVICE)3 status=progress oflag=sync bs=1M
mkfs.fat -F32 -n "CHESHIRE" $(SDDEVICE)4
@echo "Don't forget to flash the device tree binary to $(SDDEVICE)1 :)"
format-sd: $(SDDEVICE)
@test "$(shell whoami)" = "root" || (echo 'This has to be run with sudo or as root, Ex: sudo -E make flash-sdcard SDDEVICE=/dev/sdc' && exit 1)
@test -n "$(SDDEVICE)" || (echo 'SDDEVICE must be set, Ex: make flash-sdcard SDDEVICE=/dev/sdc' && exit 1)
sgdisk --clear -g --new=1:$(DT_SECTORSTART):$(DT_SECTOREND) --new=2:$(FW_SECTORSTART):$(FW_SECTOREND) --new=3:$(UIMAGE_SECTORSTART):$(UIMAGE_SECTOREND) --new=4:$(ROOT_SECTORSTART):$(ROOT_SECTOREND) --typecode=1:b000 --typecode=2:3000 --typecode=3:8300 --typecode=4:8200 $(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 "flash firmware and linux images to sd card"
@echo " has to be run as root or with sudo -E:"
@echo " make flash-sdcard SDDEVICE=/dev/sdX"
@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"