-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
72 lines (56 loc) · 1.69 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
MAKEFLAGS += -r
MAKEFLAGS += -R
ROM_DEPTH := 256
ifndef PREFIX
PREFIX := $(shell if riscv64-unknown-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-unknown-elf-'; \
elif riscv64-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-linux-gnu-'; \
else echo "***" 1>&2; \
echo "*** Error: Couldn't find an riscv64 version of GCC/binutils." 1>&2; \
echo "*** To turn off this error, run 'make PREFIX= ...'." 1>&2; \
echo "***" 1>&2; exit 1; fi)
endif
CC := $(PREFIX)gcc
AS := $(PREFIX)as
LD := $(PREFIX)ld
OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
CFLAGS := -O2 -march=rv32i -mabi=ilp32 -fdata-sections -ffunction-sections -ffreestanding
ASFLAGS := -march=rv32i -mabi=ilp32
OBJDUMPFLAGS := --disassemble-all --source --section-headers --demangle
LDFLAGS := -melf32lriscv -nostdlib
BIN2COEFLAGS := --width 32 --depth $(ROM_DEPTH) --fill 0
.PHONY: all
all: soc.rkt verify
.PHONY: clean
clean:
rm -rf \
fw/*.o fw/*.bin fw/*.lst fw/*.elf \
hw/*.mem hw/*.smt2 \
soc.rkt \
compiled
# firmware
%.bin: %.elf
$(OBJCOPY) $< -O binary $@
%.o: %.s
$(AS) $(ASFLAGS) -c $< -o $@
%.lst: %.elf
$(OBJDUMP) $(OBJDUMPFLAGS) $< > $@
fw/firmware.elf: fw/rom.ld fw/firmware.o
$(LD) $(LDFLAGS) -T $^ -o $@
# soc
hw/firmware.mem: fw/firmware.bin
bin2coe $(BIN2COEFLAGS) --mem -i $< -o $@
hw/soc.smt2: $(shell find hw -name '*.v') hw/firmware.mem
cd hw; yosys \
-p 'read_verilog -defer $(shell cd hw; find . -name '*.v')' \
-p 'prep -flatten -top soc -nordff' \
-p 'write_smt2 -stdt soc.smt2'
soc.rkt: hw/soc.smt2
echo '#lang yosys' > $@
cat $< >> $@
# run verification script
.PHONY: verify
verify: soc.rkt verify.rkt
raco make verify.rkt