summaryrefslogtreecommitdiff
path: root/altera-socfpga/hardware-handoff/spl_bsp/Makefile
blob: ec12f3491ae974dcc885a7ba860c938ee8017a28 (plain)
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
###############################################################################
#
# Altera SoC EDS Preloader/UBoot Build System
#
# Copyright (c) 2013,2014 Altera Corporation
# All Rights Reserved
#
###############################################################################


###############################################################################
#
# Generated Variables
#

PRELOADER_SETTINGS_DIR := ../../hps_isw_handoff/hps_hps_0

TGZ := $(SOCEDS_DEST_ROOT)/host_tools/altera/preloader/uboot-socfpga.tar.gz

CROSS_COMPILE := arm-altera-eabi-

DEVICE_FAMILY := cyclone5

###############################################################################


###############################################################################
#
# Derived Variables
#

MAKE_ARGS += CROSS_COMPILE=$(CROSS_COMPILE)

PRELOADER_SRC_DIR := $(patsubst %.tar.gz,%,$(shell basename $(TGZ)))

PRELOADER_UPDATE_DIR := $(PRELOADER_SRC_DIR)/board/altera/socfpga

SOCFPGA_BOARD_CONFIG := socfpga_$(DEVICE_FAMILY)_config

###############################################################################


###############################################################################
#
# Tools
#

CAT := cat
CHMOD := chmod
CP := cp -rf
DIFF := diff
ECHO := echo
PATCH := patch
MKDIR := mkdir -p
RM := rm -rf
TOUCH := touch
UNTAR := tar zxf

###############################################################################


###############################################################################
#
# Helper Variables and Functions
#

STAMP_DIR ?= $(PRELOADER_SRC_DIR)

define stamp
@$(MKDIR) $(@D)
@$(TOUCH) $@
endef

define untar_recipe
$(UNTAR) $(if $1,$1,$(if $<,$<,$(error ERROR: no input provided to gnu make function untar_recipe)))
endef

# Stamps
UNTAR_SRC := $(STAMP_DIR)/.untar
CONFIG := $(STAMP_DIR)/.config
PATCH_APPLY := $(STAMP_DIR)/.patch

###############################################################################


###############################################################################
#
# Windows Support
#
#
HOSTOS := $(shell uname -o 2>/dev/null | tr [:upper:] [:lower:])

ifeq ($(HOSTOS),cygwin)

# When using UBoot build system on Windows it's good idea to use cygwin's GNU make
MAKE := $(shell cygpath -m "/bin/make")
MAKE_ARGS += MAKE=/bin/make

CYGPATH := $(shell cygpath -m "$(shell which cygpath)")
MAKE_ARGS += CYGPATH=$(CYGPATH)

UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
HOST_CROSS_COMPILE := x86_64-w64-mingw32-
else
HOST_CROSS_COMPILE := i686-pc-mingw32-
endif

MAKE_ARGS += HOSTCC=$(HOST_CROSS_COMPILE)gcc HOSTSTRIP=$(HOST_CROSS_COMPILE)strip

# Under cygwin, overload the untar_recipe function to use unix stype paths. This is required for cygwin tar
define untar_recipe
$(UNTAR) $(shell cygpath --unix "$(if $1,$1,$(if $<,$<,$(error ERROR: no input provided to gnu make function untar_recipe)))")
endef

else # if HOSTOS != cygwin

ifdef WINDIR
$(error ERROR: Windows build of preloader requires cygwin build environment. Ensure this makefile is executed from the SoC EDS Command Shell)
endif
ifdef windir
$(error ERROR: Windows build of preloader requires cygwin build environment. Ensure this makefile is executed from the SoC EDS Command Shell)
endif

endif # HOSTOS == cygwin
###############################################################################


###############################################################################
#
# Source Files
#

SDRAM_SOURCE_FILES := \
	alt_types.h \
	sdram_io.h \
	sequencer_auto_ac_init.c \
	sequencer_auto.h \
	sequencer_auto_inst_init.c \
	sequencer.c \
	sequencer_defines.h \
	sequencer.h \
	system.h \
	tclrpt.c \
	tclrpt.h

GENERATED_SOURCE_FILES := \
	build.h \
	iocsr_config_$(DEVICE_FAMILY).c \
	iocsr_config_$(DEVICE_FAMILY).h \
	reset_config.h \
	pll_config.h \
	pinmux_config_$(DEVICE_FAMILY).c \
	pinmux_config.h \
	sdram/sdram_config.h


UPDATE_SDRAM_SOURCE_FILES := $(patsubst %,$(PRELOADER_UPDATE_DIR)/sdram/%,$(SDRAM_SOURCE_FILES))

UPDATE_GENERATED_SOURCE_FILES := $(patsubst %,$(PRELOADER_UPDATE_DIR)/%,$(GENERATED_SOURCE_FILES))

###############################################################################


###############################################################################
#
# Main build targets 
#

PRELOADER.BINARY := $(PRELOADER_SRC_DIR)/spl/u-boot-spl.bin
PRELOADER.MKPIMAGE_BINARY := preloader-mkpimage.bin
UBOOT.BINARY := $(PRELOADER_SRC_DIR)/u-boot.bin

.PHONY: all
all: spl mkpimage-spl

.PHONY: uboot
uboot: $(UBOOT.BINARY)

$(UBOOT.BINARY): $(CONFIG)
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR)

.PHONY: spl
spl: $(PRELOADER.BINARY)

$(PRELOADER.BINARY): $(CONFIG)
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) spl/u-boot-spl.bin

.PHONY: mkpimage-spl
mkpimage-spl: $(PRELOADER.MKPIMAGE_BINARY)

$(PRELOADER.MKPIMAGE_BINARY): $(PRELOADER.BINARY)
	mkpimage --header-version 0 -o $@ $< $< $< $<

.PHONY: tools
tools: $(CONFIG)
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) tools


###############################################################################


###############################################################################
#
# Untar, Update, & Configure Preloader Source
#


#####
# Untar
.PHONY: src
src: $(UNTAR_SRC)

$(UNTAR_SRC): $(TGZ)
	@$(RM) $(PRELOADER_SRC_DIR)
	$(untar_recipe)
	@$(CHMOD) -R 755 $(PRELOADER_SRC_DIR)
	$(stamp)

#####
# Update
.PHONY: update-src
update-src: $(UPDATE_SRC)

UPDATE_SRC += $(UPDATE_GENERATED_SOURCE_FILES) $(UPDATE_SDRAM_SOURCE_FILES)

$(UPDATE_SDRAM_SOURCE_FILES): $(PRELOADER_UPDATE_DIR)/sdram/%: $(PRELOADER_SETTINGS_DIR)/% $(UNTAR_SRC) $(PATCH.APPLY_TARGETS)
	@$(MKDIR) $(@D)
	@$(CP) -v $< $@

$(UPDATE_GENERATED_SOURCE_FILES): $(PRELOADER_UPDATE_DIR)/%: generated/% $(UNTAR_SRC) $(PATCH.APPLY_TARGETS)
	@$(MKDIR) $(@D)
	@$(CP) -v $< $@

#####
# Configure
.PHONY: config
config: $(CONFIG)

$(CONFIG): $(UPDATE_SRC) $(UNTAR_SRC) $(PATCH_APPLY)
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) $(SOCFPGA_BOARD_CONFIG)
	$(stamp)

###############################################################################


###############################################################################
#
# Cleaning up
#

.PHONY: clean
clean:
ifneq ($(wildcard $(PRELOADER_SRC_DIR)),)
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) mrproper
endif
	$(RM) $(PRELOADER.MKPIMAGE_BINARY) $(CONFIG)

.PHONY: clean-all
clean-all:
	$(RM) $(PRELOADER_SRC_DIR) $(PRELOADER.MKPIMAGE_BINARY) $(CONFIG) $(PATCH_APPLY) $(UNTAR_SRC)

###############################################################################


###############################################################################
#
# Applying patch files
#

# GNU MAKE >= 3.81 is required to apply patch files correctly
.SECONDEXPANSION:

# Patch files are discovered in current directory and in the directory adjacent
# to the tarball (TGZ) directory

PATCH.FILES := $(strip \
	$(sort $(wildcard $(patsubst %.tar.gz,%.patch,$(TGZ))/*.patch)) \
	$(sort $(wildcard $(patsubst %.tar.gz,%.patch,$(TGZ))/$(HOSTOS)/*.patch)) \
	$(sort $(wildcard $(abspath .)/*.patch)) \
	$(EXTRA_PATCH_FILES))

PATCH.APPLY_TARGETS := $(strip $(foreach patchfile,$(PATCH.FILES), \
 $(eval patchfile_target := $(notdir $(basename $(patchfile)))) \
 $(eval $(patchfile_target).PATCH_FILE := $(patchfile)) \
 $(PRELOADER_SRC_DIR)/.applypatch.$(patchfile_target) \
))

.PHONY: patch-apply
patch-apply: $(PATCH_APPLY)

$(PATCH_APPLY): $(PATCH.APPLY_TARGETS)
	$(stamp)

$(PATCH.APPLY_TARGETS): $(PRELOADER_SRC_DIR)/.applypatch.%: $$(%.PATCH_FILE) $(UNTAR_SRC)
	@$(ECHO) Applying Patch: $<
	$(PATCH) -p1 --directory=$(PRELOADER_SRC_DIR) --input=$<
	$(stamp)

###############################################################################


###############################################################################
#
# Creating a patch file
#

PATCH.USER_FILE := user.patch

.PHONY: patch-create
patch-create: $(if $(PATCH.SKIP_CLEAN),,clean)
ifeq ($(wildcard $(PRELOADER_SRC_DIR).orig),)
	$(error ERROR: $(PRELOADER_SRC_DIR).orig does not exist)
endif
	$(DIFF) -rupN $(PRELOADER_SRC_DIR).orig/ $(PRELOADER_SRC_DIR)/ > $(PATCH.USER_FILE) || true
ifeq ($(HOSTOS),cygwin)
	dos2unix $(PATCH.USER_FILE)
endif
	$(CAT) $(PATCH.USER_FILE)

###############################################################################