forked from pulp-platform/pulp-freertos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_targets.mk
335 lines (281 loc) · 10.6 KB
/
default_targets.mk
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# Copyright 2020 ETH Zurich
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Author: Robert Balas (balasr@iis.ee.ethz.ch)
# This makefile fragment defines default compile rules. It expect the default
# GNU Make C compiler flags set correctly (CFLAGS, CPPFLAGS, LDFLAGS), sensible
# values for $(RTOS_SRCS) $(PULP_SRCS) $(USER_SRCS), a well defined $(SIMDIR)
# and a $(PROG) name
ifndef SIMDIR
$(error "SIMDIR is empty. Simulation and analysis targets will not work")
endif
ifndef GVSIMDIR
$(error "GVSIMDIR is empty. Simulation and analysis targets will not work")
endif
ifeq ($(strip $(PROG)),)
$(error "PROG is invalid or empty. Won't be able to compile.")
endif
# make sure we compile by default
.DEFAULT_GOAL := all
include $(SUPPORT_ROOT)/support.mk
# Get path to calling makefile. This is the user program.
MAKEFILE_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Alias for user
USER_DIR = $(MAKEFILE_DIR)
# Add the user's program root and the freertos projects root to the search path
VPATH += $(FREERTOS_PROJ_ROOT)
VPATH += $(MAKEFILE_DIR)
# derived variables for compiling
SRCS += $(RTOS_SRCS) $(USER_SRCS)
OBJS = $(addsuffix .o, $(basename $(SRCS))) # .S and .c replaced
DEPS = $(addsuffix .d, $(basename $(SRCS)))
# other possibly generated files
SU = $(addsuffix .su, $(basename $(SRCS)))
# List of directories to put the object files in. Drop duplicates and ".".
OBJS_DIRS := $(filter-out ./,$(sort $(dir $(OBJS))))
# # rules on how to create these directories
# define CREATE_OBJ_DIR =
# $(1):
# mkdir -p -- $(1)
# endef
# $(foreach dir,$(OBJS_DIRS),$(eval $(call CREATE_OBJ_DIR,$(dir))))
# define CREATE_OBJ_DEP =
# $(1): $(OBJS_DIRS)
# endef
# $(foreach obj,$(OBJS),$(eval $(call CREATE_OBJ_DEP,$(obj))))
## Compile and link executable. Obeys standard GNU variables used by implicit rules.
all: $(PROG) $(PROG).stim $(PROG).srec misc-info
%.o: %.S
@mkdir -p $(@D)
$(CC) $(CV_ASFLAGS) $(ASFLAGS) $(CV_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<
%.o: %.c
@mkdir -p $(@D)
$(CC) $(CV_CFLAGS) $(CFLAGS) $(CV_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<
$(PROG): $(OBJS)
@mkdir -p $(@D)
$(CC) $(CV_CFLAGS) $(CFLAGS) $(CV_LDFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
# objdump, listing and size of binary
misc-info: $(PROG).hex $(PROG).lst $(PROG).siz
$(PROG).srec: $(PROG)
$(OBJCOPY) -O srec $(PROG) $@
$(PROG).stim: $(PROG)
$(PLPSTIM) -o $@ $<
$(PROG).hex: $(PROG)
$(OBJCOPY) -O ihex $(PROG) $@
$(PROG).veri: $(PROG)
$(OBJCOPY) -O verilog $(PROG) $@
$(PROG).lst: $(PROG)
$(OBJDUMP) --source --all-headers --demangle --line-numbers --wide --prefix-addresses \
$(PROG) > $@
$(PROG).siz: $(PROG)
$(SIZE) --format=berkeley $<
# simulator specific targets
# make sure we have sim directory
$(shell mkdir -p $(SIMDIR))
# make sure we have gvsim directory
$(shell mkdir -p $(GVSIMDIR))
# creating symlink farm because PULP/PULPissimo relies on hardcoded paths
$(SIMDIR)/work:
ifndef VSIM_PATH
$(error "VSIM_PATH is undefined. Either call \
'source $$YOUR_HW_DIR/setup/vsim.sh' or set it manually.")
endif
ln -s $(VSIM_PATH)/work $@
$(SIMDIR)/boot:
ifndef VSIM_PATH
$(error "VSIM_PATH is undefined. Either call \
'source $$YOUR_HW_DIR/setup/vsim.sh' or set it manually.")
endif
ln -s $(VSIM_PATH)/boot $@
$(SIMDIR)/tcl_files:
ifndef VSIM_PATH
$(error "VSIM_PATH is undefined. Either call \
'source $$YOUR_HW_DIR/setup/vsim.sh' or set it manually.")
endif
ln -s $(VSIM_PATH)/tcl_files $@
$(SIMDIR)/waves:
ifndef VSIM_PATH
$(error "VSIM_PATH is undefined. Either call \
'source $$YOUR_HW_DIR/setup/vsim.sh' or set it manually.")
endif
ln -s $(VSIM_PATH)/waves $@
$(SIMDIR)/vectors/stim.txt: $(PROG).stim
mkdir -p -- "$$(dirname $@)"
ln -rs $^ $@
$(SIMDIR)/stdout:
mkdir -p -- $@
$(SIMDIR)/fs:
mkdir -p -- $@
$(SIMDIR)/preload:
mkdir -p -- $@
$(SIMDIR)/preload/private_bank_0 $(SIMDIR)/preload/private_bank_1 \
$(SIMDIR)/preload/elf.veri &: $(PROG).veri
$(MEMCONV) $(PROG).veri $(SIMDIR)/preload
# default vsim flags for simulation
VSIM_RUN_FLAGS = -permit_unmatched_virtual_intf
# Newer testbenches use plusargs for runtime settings since floatingparams are
# notoriously buggy
ifdef CONFIG_PLUSARG_SIM
# srec already has entry point information
VSIM_RUN_FLAGS += +srec=prog.srec +jtag_load_tap=pulp
else
VSIM_RUN_FLAGS += +ENTRY_POINT=0x1c000880 -gLOAD_L2=JTAG -gBAUDRATE=115200
endif
# signal to simulator to preload the binary
ifdef preload
VSIM_RUN_FLAGS += +preload=preload
# add to pre-requisites for run target
RUN_MORE = $(SIMDIR)/preload/elf.veri
endif
# vsim argument to enable dpi
ifeq ($(DPI),yes)
VSIM_DPI = $(addprefix -sv_lib ,$(basename $(DPI_LIBS)))
ifeq ($(strip $(DPI_CONFIG)),)
$(warning "DPI_CONFIG is unset, but requested DPI sim. Using default rtl_config.json")
DPI_CONFIG = "rtl_config.json"
VSIM_RUN_FLAGS += -gCONFIG_FILE=$(DPI_CONFIG)
endif
else
DPI_CONFIG = "NONE"
ifndef CONFIG_PLUSARG_SIM
VSIM_RUN_FLAGS += -gCONFIG_FILE=$(DPI_CONFIG)
endif
endif
.PHONY:
## Run RTL simulation. Append gui=1 or interactive=1 for vsim gui or vsim shell respectively
run-sim: run
.PHONY: run
run: $(SIMDIR)/boot $(SIMDIR)/tcl_files \
$(SIMDIR)/waves $(SIMDIR)/vectors/stim.txt \
$(SIMDIR)/stdout $(SIMDIR)/fs $(SIMDIR)/work \
$(DPI_LIBS) $(RUN_MORE)
ifndef VSIM_PATH
$(error "VSIM_PATH is undefined. Either call \
'source $$YOUR_HW_DIR/setup/vsim.sh' or set it manually.")
endif
cp $(PROG) $(SIMDIR)
cp $(PROG).srec $(SIMDIR)/prog.srec
cp $(PROG).lst $(SIMDIR)
cp memory.map $(SIMDIR)
if [[ -f $(PROG).veri ]]; then cp $(PROG).veri $(SIMDIR); fi;
cd $(SIMDIR) && \
export LD_LIBRARY_PATH="$(SUPPORT_LIB_DIR)" && \
export VSIM_RUNNER_FLAGS="$(VSIM_RUN_FLAGS) $(VSIM_DPI) $(VSIM_ARGS)" && \
export VOPT_ACC_ENA="YES" && \
$(VSIM) -64 $(if $(gui),,-c) -do 'source $(VSIM_PATH)/tcl_files/config/run_and_exit.tcl' \
-do $(if $(or $(gui),$(interactive)), \
'source $(VSIM_PATH)/tcl_files/run.tcl; ', \
'source $(VSIM_PATH)/tcl_files/run.tcl; run_and_exit; ') $(VSIM_ARGS)
GVSOC=$(SUPPORT_ROOT)/egvsoc.sh
.PHONY: run-gvsoc
## Run simulation using gvsoc
run-gvsoc: $(GVSIMDIR) gvsoc
cp $(PROG) $(GVSIMDIR)
cp $(PROG).lst $(GVSIMDIR)
cp memory.map $(GVSIMDIR)
PULP_RISCV_GCC_TOOLCHAIN=$(PULP_RISCV_GCC_TOOLCHAIN) \
$(GVSOC) --config-file=pulp@config_file=chips/pulp/pulp.json --platform=gvsoc \
--dir=$(CURDIR)/$(GVSIMDIR) --binary=$(PROG) prepare run $(GVSIM_ARGS)
# analysis scripts
$(SIMDIR)/trace_%_postproc.log: $(SIMDIR)/trace_core_%.log
$(PULPTRACE) --time --stats --cycles $^ $(PROG) -o $@
## Symbolize simulation instruction trace log using the the original executable
trace-symbolize: $(SIMDIR)/trace_000003e0_postproc.log
$(SIMDIR)/trace_%_simplify.log: $(SIMDIR)/trace_%_postproc.log
sed -e '/: <_start>/a [...]' -e '1,/: <_start>/d' \
-e '/: <malloc+0x[a-f0-9]\+>/d' -e '/: <malloc>/a [...]' \
-e '/: <_malloc_r+0x[a-f0-9]\+>/d' -e '/: <_malloc_r>/a [...]' \
-e '/: <memset+0x[a-f0-9]\+>/d' -e '/: <memset>/a [...]' \
-e '/: <__malloc_lock+0x[a-f0-9]\+>/d' -e '/: <__malloc_lock>/a [...]' \
-e '/: <_sbrk+0x[a-f0-9]\+>/d' -e '/: <_sbrk>/a [...]' \
-e '/: <_sbrk_r+0x[a-f0-9]\+>/d' -e '/: <_sbrk_r>/a [...]' \
-e '/: <__sfp+0x[a-f0-9]\+>/d' -e '/: <__sfp>/a [...]' \
-e '/: <__sinit+0x[a-f0-9]\+>/d' -e '/: <__sinit>/a [...]' \
-e '/: <std+0x[a-f0-9]\+>/d' -e '/: <std>/a [...]' \
-e '/: <puts+0x[a-f0-9]\+>/d' -e '/: <puts>/a [...]' \
-e '/: <_puts_r+0x[a-f0-9]\+>/d' -e '/: <_puts_r>/a [...]' \
-e '/: <_write+0x[a-f0-9]\+>/d' -e '/: <_write>/a [...]' \
-e '/: <_write_r+0x[a-f0-9]\+>/d' -e '/: <_write_r>/a [...]' \
-e '/: <__swrite+0x[a-f0-9]\+>/d' -e '/: <__swrite>/a [...]' \
-e '/: <__sflush_r+0x[a-f0-9]\+>/d' -e '/: <__sflush_r>/a [...]' \
-e '/: <_fflush_r+0x[a-f0-9]\+>/d' -e '/: <_fflush_r>/a [...]' \
-e '/: <__swbuf_r+0x[a-f0-9]\+>/d' -e '/: <__swbuf_r>/a [...]' \
-e '/: <iprintf+0x[a-f0-9]\+>/d' -e '/: <iprintf>/a [...]' \
-e '/: <_vfiprintf_r+0x[a-f0-9]\+>/d' -e '/: <_vfiprintf_r>/a [...]' \
-e '/: <_printf_i+0x[a-f0-9]\+>/d' -e '/: <_printf_i>/a [...]' \
-e '/: <_printf_common+0x[a-f0-9]\+>/d' -e '/: <_printf_common>/a [...]' \
-e '/: <__sfputc_r+0x[a-f0-9]\+>/d' -e '/: <__sfputc_r>/a [...]' \
-e '/: <__sfputs_r+0x[a-f0-9]\+>/d' -e '/: <__sfputs_r>/a [...]' \
-e '/: <memchr+0x[a-f0-9]\+>/d' -e '/: <memchr>/a [...]' \
-e '/: <__smakebuf_r+0x[a-f0-9]\+>/d' -e '/: <__smakebuf_r>/a [...]' \
-e '/: <__swsetup_r+0x[a-f0-9]\+>/d' -e '/: <__swsetup_r>/a [...]' \
$^ > $@
## Simplify simulation instruction trace log. This collapses some function calls.
trace-simplify: $(SIMDIR)/trace_000003e0_simplify.log
.PHONY: backup
## Backup current simulation folder
backup:
@STAMP=sim-$$(git rev-parse --short HEAD)-$$(date +"%Y-%m-%d-%H-%M-%S"); \
cp -r $(SIMDIR) $$STAMP; \
cp $(PROG) $(PROG).lst $$STAMP; \
echo "generated backup $$STAMP";
.PHONY: clean
## Clean object files
clean:
$(RM) $(OBJS) $(PROG) $(DEPS) $(SU) \
$(PROG).hex $(PROG).lst $(PROG).siz memory.map $(PROG).veri \
$(PROG).stim $(PROG).srec $(SIMDIR)/vectors/stim.txt
for dirs in $(OBJS_DIRS); do \
if [[ -d $$dirs ]]; then \
rmdir -p --ignore-fail-on-non-empty $$dirs; \
fi; \
done
.PHONY: distclean
## Clean object files and all support dependencies
distclean: clean
$(RM) -r $(SUPPORT_ROOT)/install/*
$(RM) -r $(SIMDIR) $(GVSIMDIR)
.PHONY: show-config
## Show current configuration
show-config:
@printf "Project settings:\n"
@printf "FREERTOS_PROJ_ROOT=$(FREERTOS_PROJ_ROOT)\n"
@printf "FREERTOS_CONFIG_FAMILY=$(FREERTOS_CONFIG)\n"
@printf "\n"
@printf "Compiler settings:\n"
@printf "CC=$(CC)\n"
@printf "CFLAGS=\"$(CFLAGS)\"\n"
@printf "CPPFLAGS=\"$(CPPFLAGS)\"\n"
@printf "\n"
@printf "Assembler settings:\n"
@printf "AS=$(CC)\n"
@printf "ASFLAGS=\"$(ASFLAGS)\"\n"
@printf "\n"
@printf "Linker settings:\n"
@printf "LDFLAGS=\"$(LDFLAGS)\"\n"
@printf "LDLIBS=\"$(LDLIBS)\"\n"
.PHONY: help
## Generate help overview
help: Makefile
@printf "Available targets\n\n"
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-15s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)