-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.mk
232 lines (194 loc) · 6.11 KB
/
common.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
# SPDX-License-Identifier: Apache-2.0
#
################################################################################
##
## Copyright 2018-2019 Missing Link Electronics, Inc.
##
## 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.
##
################################################################################
##
## File Name : common.mk
## Initial Author : Stefan Wiehler <[email protected]>
##
################################################################################
##
## File Summary : XSDK/Vitis common functionality
##
## Uses: bootgen cat git mkdir patch rm sed touch
##
################################################################################
################################################################################
# VCS
# user arguments
VCS_SKIP ?=
# get version control information
ifeq ($(VCS_SKIP),)
VCS_HEAD := $(shell git rev-parse --verify --short HEAD 2>/dev/null)
endif
ifneq ($(VCS_HEAD),)
VCS_DIRTY := $(shell git diff-index --name-only HEAD | head -n 1)
VCS_VER := _g$(VCS_HEAD)$(patsubst %,-dirty,$(VCS_DIRTY))
else
VCS_VER :=
endif
# get build time stamp
BSTAMP := $(shell date +%Y%m%d-%H%M%S)
# user arguments, usually provided on command line
# container for build directories (= xsdk workspaces)
CNTR ?= build
# build directory name
BLDN ?= $(CFG)_$(BSTAMP)$(VCS_VER)
# relative path to build directory
O ?= $(CNTR)/$(BLDN)
###############################################################################
# Repositories
REPOS ?=
ifneq ($(strip $(REPOS)),)
__REPOS_CCMD = $(foreach REPO,$(REPOS), \
repo -set {$(REPO)};)
endif
$(O)/.metadata/repos.stamp:
ifneq ($(strip $(REPOS)),)
$(XSCT) -eval 'setws {$(O)}; $(__REPOS_CCMD)'
else
mkdir -p $(O)/.metadata/
endif
touch $@
###############################################################################
# Source symlinking, patch and sed rules
# arg1: app name
# arg2: src file name, scheme <srcfile>
define symlink-src
rm -f $(O)/$(1)/src/$$(notdir $(2)) && \
ln -s ../../../../$(2) $(O)/$(1)/src/$$(notdir $(2)) &&
endef
# arg1: app name
# arg2: patch file name, scheme <patchfile>[;<stripnum>]
define patch-src
patch -d $(O)/$(1)/ -p$$(subst ,1,$$(word 2,$$(subst ;, ,$(2)))) \
<$$(word 1,$$(subst ;, ,$(2))) &&
endef
# arg1: app name
# arg2: src file name to edit and sed command file, scheme <srcfile>;<sedfile>
define sed-src
sed -i -f $$(lastword $$(subst ;, ,$(2))) \
$(O)/$(1)/$$(firstword $$(subst ;, ,$(2))) &&
endef
###############################################################################
# Bootgen projects
BOOTGEN ?= bootgen
BOOTGEN_PRJS ?=
# arg1: BIF file
define sanitize-rel-abs-path
$$(if $$(findstring yes,$$(if $$(patsubst /%,,$(1)),,yes)),$(1),$(O)/$(1))
endef
BIT ?= $(notdir $(HDF:.xsa=.bit))
$(O)/$(notdir $(HDF:.xsa=.bit)): $(HDF)
unzip -u -DD -o -j $^ $(notdir $@) -d $(dir $@)
# arg1: Bootgen project
# arg2: BIF attribute
define gen-init-bitfile-deprecated
ifneq (,$$(findstring destination_device=pl,$$($(1)_$(2)_BIF_ATTR)))
$(1)_$(2)_BIF_FILE ?=
ifeq ($$($(1)_$(2)_BIF_FILE),)
$(1)_$(2)_BIF_FILE = $(BIT)
endif
endif
endef
# arg1: BIF file name
# arg2: BIF attribute
define gen-bif-value
$$(if $$(findstring yes,$$($(1)_$(2)_BIF_FILE_NOTFILE)),\
$$($(1)_$(2)_BIF_FILE),\
$(call sanitize-rel-abs-path,$$($(1)_$(2)_BIF_FILE)))
endef
# arg1: BIF file name
# arg2: BIF attribute
define gen-bif-attr
$$(if $$($(1)_$(2)_BIF_ATTR),\
\t[$$($(1)_$(2)_BIF_ATTR)] $(call gen-bif-value,$(1),$(2))\n,\
\t$(call gen-bif-value,$(1),$(2))\n)
endef
# arg1: Bootgen project
# arg2: BIF attribute
define gen-bootgen-dep
$$(if $$(findstring yes,$$($(1)_$(2)_BIF_FILE_NO_DEP)),,\
$(call sanitize-rel-abs-path,$$($(1)_$(2)_BIF_FILE)))
endef
define gen-bif-rule
$(1)_FLASH_TYPE ?=
$(1)_FLASH_FSBL ?=
$(1)_FLASH_OFF ?= 0
$(1)_BOOTGEN_DEP = $$(foreach BIF_ATTR,$$($(1)_BIF_ATTRS),\
$(call gen-bootgen-dep,$(1),$$(BIF_ATTR)))
# generate make rules for bitstream extractions, multiple
# Deprecated: Ensure old behavior for A53-based setups. However, using $(BIT)
# instead is highly recommended!
$(foreach BIF_ATTR,$($(1)_BIF_ATTRS),\
$(eval $(call gen-init-bitfile-deprecated,$(1),$(BIF_ATTR))))
$(O)/$(1)/$(1).bif: $(O)/.metadata/repos.stamp $$($(1)_BOOTGEN_DEP)
mkdir -p $$(dir $$@)
printf '$(1):\n{\n' > $$@
ifneq ($$(strip $$($(1)_BIF_ATTRS)),)
printf '$$(foreach BIF_ATTR,$$($(1)_BIF_ATTRS), \
$(call gen-bif-attr,$(1),$$(BIF_ATTR)))' \
>> $$@
endif
printf '}\n' >> $$@
$(O)/$(1)/BOOT.BIN: $(O)/$(1)/$(1).bif
ifeq ($$($(1)_BIF_NO_OUTPUT),yes)
$(BOOTGEN) -arch $$($(1)_BIF_ARCH) -image $$< \
$$($(1)_BIF_ARGS_EXTRA)
else
$(BOOTGEN) -arch $$($(1)_BIF_ARCH) -image $$< \
-o $$@ -w on $$($(1)_BIF_ARGS_EXTRA)
endif
GEN_BOOTGEN_DEP += $(O)/$(1)/$(1).bif
BLD_BOOTGEN_DEP += $(O)/$(1)/BOOT.BIN
# NOTE: Target $(1)_flash is written for QSPI flashing in mind - other types
# might need more or other arguments!
$(1)_flash: $(O)/$(1)/BOOT.BIN
program_flash \
-flash_type $$($(1)_FLASH_TYPE) \
-fsbl $$($(1)_FLASH_FSBL) \
-f $$< -offset $$($(1)_FLASH_OFF) \
-verify \
-cable type xilinx_tcf url $(HW_SERVER_URL)
.PHONY: $(1)_flash
# shortcut to build bootgen project, "make <bootgen>"
$(1): $(O)/$(1)/BOOT.BIN
.PHONY: $(1)
$(1)_clean:
find $(O)/$(1)/* -not -name $(1).bif -delete
.PHONY: $(1)_clean
$(1)_distclean:
rm -fr $(O)/$(1)
.PHONY: $(1)_distclean
endef
###############################################################################
# Common targets
# show logs
metalog:
cat $(O)/.metadata/.log
sdklog:
cat $(O)/SDK.log
.PHONY: sdklog metalog
# remove workspace
distclean:
rm -fr $(O)
.PHONY: distclean
# open XSCT in interactive mode
xsct:
$(XSCT) -interactive -eval 'setws $(O)'
.PHONY: xsct