-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
65 lines (47 loc) · 1.98 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
# When you change the memory size below, make sure to also change it in:
#
# ./sw/sections.lds
# ./sw/start.S
# ./rtl/top.v
MEM_WORDS = 1024
MEM_BYTES = 4096
MARCH = rv32ic
CPU_FREQ_MHZ = 50
CC_OPT = -Os
OBJ_FILES = start.o main.o lib.o trap.o semihosting.o printf.o
#OPENOCD_DIR ?= ~/tools/openocd_riscv
#OPENOCD ?= $(OPENOCD_DIR)/src/openocd
OPENOCD_DIR ?= /opt/openocd_vex
OPENOCD ?= $(OPENOCD_DIR)/bin/openocd
# Downloaded from https://github.com/sifive/freedom-tools/releases
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),Linux)
TOOLS_PREFIX = /opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin
endif
ifeq ($(UNAME_S),Darwin)
TOOLS_PREFIX = /opt/riscv64-unknown-elf-gcc-10.1.0-2020.08.2-x86_64-apple-darwin/bin
endif
TARGET = $(TOOLS_PREFIX)/riscv64-unknown-elf
DEFINES = -DCPU_FREQ=$(CPU_FREQ_MHZ)000000
DEFINES += -DPRINTF_INCLUDE_CONFIG_H
AS = $(TARGET)-as
ASFLAGS = -march=$(MARCH) -mabi=ilp32
LD = $(TARGET)-gcc
LDFLAGS = -march=$(MARCH) -g -ggdb -mabi=ilp32 -Wl,-Tsections.lds,-Map,progmem.map -ffreestanding -nostartfiles -Wl,--no-relax -Wl,--start-group,--end-group
CC = $(TARGET)-gcc
CFLAGS = -march=$(MARCH) -g -ggdb -mno-div -mabi=ilp32 -ffunction-sections -fdata-sections -Wall -Wextra -pedantic $(DEFINES) $(CC_OPT)
OBJCOPY = $(TARGET)-objcopy
OBJDUMP = $(TARGET)-objdump
READELF = $(TARGET)-readelf
CREATE_MIF = ../misc/create_mif.rb
.PHONY: all clean
all: progmem.dis progmem.bin
progmem.dis: progmem.elf
$(OBJDUMP) -s -D $< > $@
progmem.bin: progmem.elf
$(OBJCOPY) -O binary $< $@
progmem.elf: $(OBJ_FILES) top_defines.h sections.lds Makefile
$(LD) $(LDFLAGS) -o $@ $(OBJ_FILES) -lm
$(OBJ_FILES): top_defines.h riscv.h semihosting.h reg.h printf.h printf_config.h lib.h
clean:
\rm -fr *.o *.hex *.elf *.dis *.bin *.coe *.map *.mif *.mem *.funcs *.globs