-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (114 loc) · 4.15 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
# Define default variables
OPENOCD ?= openocd
OPENOCD_SCRIPTS ?= $(abspath $(dir $(shell which $(OPENOCD)))/../share/openocd/scripts)
GDB ?= riscv64-unknown-elf-gdb
ADAPTER_SPEED ?= 1000
INTERFACE ?= ftdi
DEVICE ?= olimex-arm-usb-ocd-h
ID ?=
TARGET ?= smp
export OPENOCD_SCRIPTS
# CVA6 SDK variables
CVA6_SDK_DIR ?= cva6-sdk
IMAGES_DIR ?= $(CVA6_SDK_DIR)/install64
PAYLOAD ?= $(IMAGES_DIR)/fw_payload.elf
DTB_FILE ?= $(CVA6_SDK_DIR)/alsaqr.dtb
DTB_ADDR ?= 0x81800000
MEM_BASE_ADDR ?= 0x80000000
# Hyperram config
HYPERRAM_SIZE ?= 0x2000000
HYPERRAM_LATENCY_ACCESS ?= 0x6
HYPERRAM_ADDRESS_SPACE ?= 0
HYPPERAM_NO_OF_CHIPS ?= 4
HYPERRAM_WHICH_PHY ?= 0
HYPERRAM_PHYS_IN_USE ?= 1
HYPERRAM_CFG_BASE_ADDR ?= 0x1a101000
HYPERRAM_CFG_FILE ?= generated/hyperram_config.cfg
OPENOCD_DEPS :=
GDB_DEPS := $(PAYLOAD)
# Set NUM_HARTS and TARGET_FREQ
NUM_HARTS ?= 2
TARGET_FREQ ?= 50000000 # Hz
export NUM_HARTS TARGET_FREQ
# OpenOCD directory
OPENOCD_DIR ?= openocd
# Initialize OpenOCD command arguments
OPENOCD_ARGS = -s "$(OPENOCD_DIR)"
# Initialize OpenOCD commands
OPENOCD_CMDS = -c "adapter speed $(ADAPTER_SPEED)" \
-c "set _INTERFACE $(INTERFACE); echo \"Interface: $(INTERFACE)\"" \
-c "set _DEVICE $(DEVICE); echo \"Device: $(DEVICE)\""
ifneq ($(ID), )
OPENOCD_CMDS += -c "set _ID $(ID); echo \"ID: $(ID)\""
endif
OPENOCD_CMDS += -c "set _NUM_CORES $(NUM_HARTS); echo \"Number of cores: $(NUM_HARTS)\"" \
-c "set _TARGET $(TARGET); echo \"Target: $(TARGET)\"" \
-f "openocd.cfg" \
-c "init" \
-c "reset halt"
# Use LLC in SPM mode (experimental)
ifeq ($(LLC_SPM), 1)
OPENOCD_CMDS += -c "mww 0x10401000 0xffffffff"
OPENOCD_CMDS += -c "mww 0x10401004 0xffffffff"
OPENOCD_CMDS += -c "mww 0x10401010 0x1"
endif
# Conditional programming of Hyperram interface
ifeq ($(USE_HYPER),1)
OPENOCD_CMDS += -f $(HYPERRAM_CFG_FILE)
OPENOCD_DEPS += $(HYPERRAM_CFG_FILE)
export USE_HYPER
endif
# Conditional load of DTB file
ifeq ($(PAYLOAD), $(IMAGES_DIR)/fw_payload.elf)
GDB_DEPS += $(DTB_FILE)
endif
# Append OpenOCD commands to arguments
OPENOCD_ARGS += $(OPENOCD_CMDS)
$(HYPERRAM_CFG_FILE):
mkdir -p $(dir $@)
python3 utils/hyperram_cfg.py --hyperram_size $(HYPERRAM_SIZE) \
--hyperram_t_latency_access $(HYPERRAM_LATENCY_ACCESS) \
--hypperam_no_of_chips $(HYPPERAM_NO_OF_CHIPS) \
--hyperram_which_phy $(HYPERRAM_WHICH_PHY) \
--hyperram_address_space $(HYPERRAM_ADDRESS_SPACE) \
--hyperram_phys_in_use $(HYPERRAM_PHYS_IN_USE) \
--hyperbus_cfg_base_addr $(HYPERRAM_CFG_BASE_ADDR) \
--memory_base_addr $(MEM_BASE_ADDR) \
--output_file $@
# CVA6 SDK targets
.PHONY: $(CVA6_SDK_DIR)
$(CVA6_SDK_DIR):
if [ ! -d "$(CVA6_SDK_DIR)/.git" ] || [ -z "$(shell ls -A $(CVA6_SDK_DIR))" ]; then \
git submodule update --init --recursive $@; \
fi
$(DTB_FILE): $(CVA6_SDK_DIR)
make -C $(CVA6_SDK_DIR) $(notdir $@)
$(IMAGES_DIR)/fw_payload.elf: $(CVA6_SDK_DIR)
make -C $(CVA6_SDK_DIR) images
# Run OpenOCD to set up a GDB server
.PHONY: openocd
openocd: $(OPENOCD_DEPS)
$(OPENOCD) $(OPENOCD_ARGS) -c "echo \"Ready for Remote Connections\""
# Run GDB to load the payload and execute it
.PHONY: gdb gdb-load-payload
gdb:
$(GDB) \
-ex "target extended-remote :3333"
gdb-load-payload: $(GDB_DEPS)
$(eval INITIAL_PC := $(shell LC_ALL=C riscv64-unknown-elf-objdump -f $(PAYLOAD) | awk '/start address/ {print $$NF}'))
$(GDB) $(PAYLOAD) \
-ex "target extended-remote :3333" \
$(if $(filter $(IMAGES_DIR)/fw_payload.elf,$(PAYLOAD)), \
-ex "monitor load_image $(DTB_FILE) $(DTB_ADDR)",) \
$(foreach i, $(shell seq 1 $(NUM_HARTS)), -ex "thread $(i)" -ex "set \$$pc=$(INITIAL_PC)" -ex "info registers pc") \
-ex "load" \
-ex "continue"
.PHONY: clean deep-clean
clean:
make -C $(CVA6_SDK_DIR) clean
make -C $(CVA6_SDK_DIR)/opensbi clean
rm -f generated/* $(DTB_FILE) $(IMAGES_DIR)/*
deep-clean: clean
make -C $(CVA6_SDK_DIR)/buildroot clean
.PHONY: init
init: $(CVA6_SDK_DIR)