Project

General

Profile

RE: U-boot not bringing Linux kernel up correctly ยป Makefile

Chris Weinman, 01/23/2015 04:21 AM

 
1
###############################################################################
2
#
3
# Altera SoC EDS Preloader/UBoot Build System
4
#
5
# Copyright (c) 2013 Altera Corporation
6
# All Rights Reserved
7
#
8
###############################################################################
9

    
10

    
11
###############################################################################
12
#
13
# Generated Variables
14
#
15

    
16
PRELOADER_SETTINGS_DIR := ../../hps_isw_handoff/mitysom_5csx_dev_board_hps_0/
17

    
18
TGZ := uboot-socfpga.tar.gz
19

    
20
CROSS_COMPILE := arm-altera-eabi-
21

    
22
DEVICE_FAMILY := cyclone5
23

    
24
###############################################################################
25

    
26

    
27
###############################################################################
28
#
29
# Derived Variables
30
#
31

    
32
MAKE_ARGS += CROSS_COMPILE=$(CROSS_COMPILE)
33

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

    
36
PRELOADER_UPDATE_DIR := $(PRELOADER_SRC_DIR)/board/cl/mitysom-5csx
37
PRELOADER_UPDATE_DIR_ALT := $(PRELOADER_SRC_DIR)/board/altera/socfpga
38

    
39

    
40
SOCFPGA_BOARD_CONFIG := mitysom-5csx_config
41

    
42
###############################################################################
43

    
44

    
45
###############################################################################
46
#
47
# Tools
48
#
49

    
50
CAT := cat
51
CHMOD := chmod
52
CP := cp -rf
53
DIFF := diff
54
ECHO := echo
55
PATCH := patch
56
MKDIR := mkdir -p
57
RM := rm -rf
58
TOUCH := touch
59
UNTAR := tar zxf
60

    
61
###############################################################################
62

    
63

    
64
###############################################################################
65
#
66
# Helper Variables and Functions
67
#
68

    
69
STAMP_DIR ?= $(PRELOADER_SRC_DIR)
70

    
71
define stamp
72
@$(MKDIR) $(@D)
73
@$(TOUCH) $@
74
endef
75

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

    
80
###############################################################################
81

    
82

    
83
###############################################################################
84
#
85
# Windows Support [BETA]
86
#   --> The preloader build on Windows is experimental!!!
87
#       Altera makes no guarantees that we will support a Windows build in 
88
#       future releases of SoC EDS.
89
#
90
HOSTOS := $(shell uname -o 2>/dev/null | tr [:upper:] [:lower:])
91

    
92
ifeq ($(HOSTOS),cygwin)
93

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

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

    
101
UNAME_M := $(shell uname -m)
102
ifeq ($(UNAME_M),x86_64)
103
HOST_CROSS_COMPILE := x86_64-w64-mingw32-
104
else
105
HOST_CROSS_COMPILE := i686-pc-mingw32-
106
endif
107

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

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

    
115
else # if HOSTOS != cygwin
116

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

    
124
endif # HOSTOS == cygwin
125
###############################################################################
126

    
127

    
128
###############################################################################
129
#
130
# Source Files
131
#
132

    
133
SDRAM_SOURCE_FILES := \
134
	alt_types.h \
135
	sdram_io.h \
136
	sequencer_auto_ac_init.c \
137
	sequencer_auto.h \
138
	sequencer_auto_inst_init.c \
139
	sequencer.c \
140
	sequencer_defines.h \
141
	sequencer.h \
142
	system.h \
143
	tclrpt.c \
144
	tclrpt.h
145

    
146
GENERATED_SOURCE_FILES := \
147
	build.h \
148
	iocsr_config_$(DEVICE_FAMILY).c \
149
	iocsr_config_$(DEVICE_FAMILY).h \
150
	reset_config.h \
151
	pll_config.h \
152
	pinmux_config_$(DEVICE_FAMILY).c \
153
	pinmux_config.h \
154
	sdram/sdram_config.h
155

    
156

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

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

    
161
UPDATE_SDRAM_SOURCE_FILES_ALT := $(patsubst %,$(PRELOADER_UPDATE_DIR_ALT)/sdram/%,$(SDRAM_SOURCE_FILES))
162
UPDATE_GENERATED_SOURCE_FILES_ALT := $(patsubst %,$(PRELOADER_UPDATE_DIR_ALT)/%,$(GENERATED_SOURCE_FILES))
163

    
164

    
165

    
166
###############################################################################
167

    
168

    
169
###############################################################################
170
#
171
# Main build targets 
172
#
173

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

    
177
.PHONY: all
178
all: spl mkpimage-spl
179

    
180
.PHONY: uboot
181
uboot: config
182
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR)
183

    
184
.PHONY: spl
185
spl: $(PRELOADER.BINARY)
186

    
187
$(PRELOADER.BINARY): config
188
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) spl/u-boot-spl.bin
189

    
190
.PHONY: mkpimage-spl
191
mkpimage-spl: $(PRELOADER.MKPIMAGE_BINARY)
192

    
193
$(PRELOADER.MKPIMAGE_BINARY): $(PRELOADER.BINARY)
194
	mkpimage -o $@ $< $< $< $<
195

    
196
.PHONY: tools
197
tools: config
198
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) tools
199

    
200

    
201
###############################################################################
202

    
203

    
204
###############################################################################
205
#
206
# Untar, Update, & Configure Preloader Source
207
#
208

    
209

    
210
#####
211
# Untar
212
UNTAR_SRC := $(STAMP_DIR)/.untar
213

    
214
.PHONY: src
215
src: $(UNTAR_SRC)
216

    
217
$(UNTAR_SRC): $(TGZ)
218
	@$(RM) $(PRELOADER_SRC_DIR)
219
	$(untar_recipe)
220
	@$(CHMOD) -R 755 $(PRELOADER_SRC_DIR)
221
	$(stamp)
222

    
223
#####
224
# Update
225
.PHONY: update-src
226
update-src: $(UPDATE_GENERATED_SOURCE_FILES) $(UPDATE_SDRAM_SOURCE_FILES) $(UPDATE_GENERATED_SOURCE_FILES_ALT) $(UPDATE_SDRAM_SOURCE_FILES_ALT)
227

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

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

    
236
$(UPDATE_SDRAM_SOURCE_FILES_ALT): $(PRELOADER_UPDATE_DIR_ALT)/sdram/%: $(PRELOADER_SETTINGS_DIR)/% $(UNTAR_SRC) $(PATCH.APPLY_TARGETS)
237
	        @$(MKDIR) $(@D)
238
		        @$(CP) -v $< $@
239

    
240
$(UPDATE_GENERATED_SOURCE_FILES_ALT): $(PRELOADER_UPDATE_DIR_ALT)/%: generated/% $(UNTAR_SRC) $(PATCH.APPLY_TARGETS)
241
	        @$(MKDIR) $(@D)
242
		        @$(CP) -v $< $@
243

    
244

    
245
#####
246
# Configure
247
.PHONY: config
248
config: update-src src patch-apply
249
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) $(SOCFPGA_BOARD_CONFIG)
250

    
251
###############################################################################
252

    
253

    
254
###############################################################################
255
#
256
# Cleaning up
257
#
258

    
259
.PHONY: clean
260
clean:
261
ifneq ($(wildcard $(PRELOADER_SRC_DIR)),)
262
	$(MAKE) $(MAKE_ARGS) -C $(PRELOADER_SRC_DIR) mrproper
263
endif
264
	$(RM) $(PRELOADER.MKPIMAGE_BINARY)
265

    
266
.PHONY: clean-all
267
clean-all:
268
	$(RM) $(PRELOADER_SRC_DIR) $(PRELOADER.MKPIMAGE_BINARY)
269

    
270
###############################################################################
271

    
272

    
273
###############################################################################
274
#
275
# Applying patch files
276
#
277

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

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

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

    
290
PATCH.APPLY_TARGETS := $(strip $(foreach patchfile,$(PATCH.FILES), \
291
 $(eval patchfile_target := $(notdir $(basename $(patchfile)))) \
292
 $(eval $(patchfile_target).PATCH_FILE := $(patchfile)) \
293
 $(PRELOADER_SRC_DIR)/.applypatch.$(patchfile_target) \
294
))
295

    
296
.PHONY: patch-apply
297
patch-apply: $(PATCH.APPLY_TARGETS)
298

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

    
304
###############################################################################
305

    
306

    
307
###############################################################################
308
#
309
# Creating a patch file
310
#
311

    
312
PATCH.USER_FILE := user.patch
313

    
314
.PHONY: patch-create
315
patch-create: $(if $(PATCH.SKIP_CLEAN),,clean)
316
ifeq ($(wildcard $(PRELOADER_SRC_DIR).orig),)
317
	$(error ERROR: $(PRELOADER_SRC_DIR).orig does not exist)
318
endif
319
	$(DIFF) -rupN $(PRELOADER_SRC_DIR).orig/ $(PRELOADER_SRC_DIR)/ > $(PATCH.USER_FILE) || true
320
ifeq ($(HOSTOS),cygwin)
321
	dos2unix $(PATCH.USER_FILE)
322
endif
323
	$(CAT) $(PATCH.USER_FILE)
324

    
325
###############################################################################
326

    
327

    
    (1-1/1)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)