2018-12-08 20:19:54 +00:00
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
MK_FILE_PATH = $(lastword $(MAKEFILE_LIST))
|
|
|
|
PRJ_DIR = $(abspath $(dir $(MK_FILE_PATH)))
|
|
|
|
|
|
|
|
# Hardcoded paths
|
|
|
|
OPENOCD_BIN := /usr/bin/riscv-openocd
|
|
|
|
RISCV_SDK_DIR := $(abspath $(PRJ_DIR)/../../riscv-sdk)
|
|
|
|
OUT_DIR := bin
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
SDK_INC := $(RISCV_SDK_DIR)/include
|
|
|
|
SDK_WRAP := $(RISCV_SDK_DIR)/libwrap
|
|
|
|
SDK_OPENOCD_CFG := $(RISCV_SDK_DIR)/openocd.cfg
|
|
|
|
|
|
|
|
# libwrap config
|
|
|
|
include $(SDK_WRAP)/libwrap.mk
|
|
|
|
|
|
|
|
# SDK sources
|
|
|
|
SDK_SRC_ASM := \
|
|
|
|
$(RISCV_SDK_DIR)/entry.S \
|
|
|
|
$(RISCV_SDK_DIR)/start.S
|
|
|
|
|
|
|
|
SDK_SRC_C := \
|
|
|
|
$(RISCV_SDK_DIR)/init.c
|
|
|
|
SDK_LINK_SCRIPT := \
|
|
|
|
$(RISCV_SDK_DIR)/flash.lds
|
|
|
|
|
|
|
|
# Variable used by libwrap.mk
|
|
|
|
INCLUDES := -I$(RISCV_SDK_DIR)/include
|
|
|
|
|
|
|
|
# Platform specific: HiFive1
|
|
|
|
|
|
|
|
#Name of variable required by libwrap.mk
|
|
|
|
ARCH_FLAGS += \
|
|
|
|
-march=rv32imac -mabi=ilp32 -mcmodel=medany
|
|
|
|
|
|
|
|
CFLAGS += \
|
|
|
|
-O3 -fno-builtin-printf \
|
|
|
|
-Wall -Wextra -Wshadow -fno-common \
|
2018-12-08 20:35:40 +00:00
|
|
|
-include sys/cdefs.h \
|
2018-12-08 20:19:54 +00:00
|
|
|
$(ARCH_FLAGS) \
|
2018-12-08 20:35:40 +00:00
|
|
|
$(LOCAL_CFLAGS)
|
2018-12-08 20:19:54 +00:00
|
|
|
|
|
|
|
LDFLAGS += \
|
|
|
|
-static \
|
|
|
|
-L$(RISCV_SDK_DIR) \
|
|
|
|
-T$(SDK_LINK_SCRIPT) \
|
|
|
|
-nostartfiles \
|
|
|
|
--specs=nano.specs \
|
|
|
|
-Wl,--gc-sections \
|
|
|
|
$(LOCAL_LDFLAGS)
|
|
|
|
|
|
|
|
# Common targets
|
|
|
|
OBJ_S := \
|
|
|
|
$(LOCAL_SRC_S:.S=.o) \
|
|
|
|
$(SDK_SRC_ASM:.S=.o)
|
|
|
|
OBJ_C := \
|
|
|
|
$(LOCAL_SRC_C:.c=.o) \
|
|
|
|
$(SDK_SRC_C:.c=.o)
|
|
|
|
|
|
|
|
# Compilation targets
|
|
|
|
$(OBJ_S): %.o: %.S
|
|
|
|
mkdir -p $(OUT_DIR)/$(dir $@)
|
|
|
|
$(CC) $(ARCH_FLAGS) -I$(SDK_INC) $(OPT) -c -o $(OUT_DIR)/$@ $<
|
|
|
|
|
|
|
|
$(OBJ_C): %.o: %.c
|
|
|
|
mkdir -p $(OUT_DIR)/$(dir $@)
|
|
|
|
$(CC) -I$(SDK_INC) $(CFLAGS) $(OPT) -c -o $(OUT_DIR)/$@ $<
|
|
|
|
|
|
|
|
$(TARGET): $(OBJ_C) $(OBJ_S) $(LIBWRAP)
|
|
|
|
$(CC) -I$(SDK_INC) $(CFLAGS) $(OPT) \
|
|
|
|
$(addprefix $(OUT_DIR)/,$(OBJ_S)) \
|
|
|
|
$(addprefix $(OUT_DIR)/,$(OBJ_C)) \
|
|
|
|
-o $(OUT_DIR)/$@ $(LDFLAGS)
|
|
|
|
clean:
|
|
|
|
rm -rf $(OUT_DIR)
|
|
|
|
rm -rf $(LIBWRAP)
|
|
|
|
|
|
|
|
run:
|
|
|
|
$(OPENOCD_BIN) -s "sdk" -f $(SDK_OPENOCD_CFG) & \
|
|
|
|
$(GDB) \
|
|
|
|
"$(OUT_DIR)/$(TARGET)" \
|
|
|
|
--batch \
|
|
|
|
-ex "set remotetimeout 240" \
|
|
|
|
-ex "target extended-remote localhost:3333" \
|
|
|
|
-ex "monitor reset halt" \
|
|
|
|
-ex "monitor flash protect 0 64 last off" \
|
|
|
|
-ex "load" \
|
|
|
|
-ex "monitor resume" \
|
|
|
|
-ex "monitor shutdown" \
|
|
|
|
-ex "quit"
|
|
|
|
|
|
|
|
.PHONY: clean all run
|