]> git.ipfire.org Git - thirdparty/u-boot.git/blob - Makefile
c10bf71b9acaef97ff0ad7fa0c7f6b4e7c113f1f
[thirdparty/u-boot.git] / Makefile
1 # SPDX-License-Identifier: GPL-2.0+
2
3 VERSION = 2026
4 PATCHLEVEL = 01
5 SUBLEVEL =
6 EXTRAVERSION = -rc1
7 NAME =
8
9 # *DOCUMENTATION*
10 # To see a list of typical targets execute "make help"
11 # More info can be located in ./README
12 # Comments in this file are targeted only to the developer, do not
13 # expect to learn how to build the kernel reading this file.
14
15 # That's our default target when none is given on the command line
16 PHONY := _all
17 _all:
18
19 # Determine target architecture for the sandbox
20 include include/host_arch.h
21 ifeq ("", "$(CROSS_COMPILE)")
22 MK_ARCH="${shell uname -m}"
23 else
24 MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^\(.*ccache\)\{0,1\}[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\3/p'}"
25 endif
26 unexport HOST_ARCH
27 ifeq ("x86_64", $(MK_ARCH))
28 export HOST_ARCH=$(HOST_ARCH_X86_64)
29 else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" "i586" "i686"))
30 export HOST_ARCH=$(HOST_ARCH_X86)
31 else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
32 export HOST_ARCH=$(HOST_ARCH_AARCH64)
33 else ifneq (,$(findstring $(MK_ARCH), "arm" "armv5tel" "armv6l" "armv7" "armv7a" "armv7l"))
34 export HOST_ARCH=$(HOST_ARCH_ARM)
35 else ifeq ("riscv32", $(MK_ARCH))
36 export HOST_ARCH=$(HOST_ARCH_RISCV32)
37 else ifeq ("riscv64", $(MK_ARCH))
38 export HOST_ARCH=$(HOST_ARCH_RISCV64)
39 endif
40 undefine MK_ARCH
41
42 # We are using a recursive build, so we need to do a little thinking
43 # to get the ordering right.
44 #
45 # Most importantly: sub-Makefiles should only ever modify files in
46 # their own directory. If in some directory we have a dependency on
47 # a file in another dir (which doesn't happen often, but it's often
48 # unavoidable when linking the built-in.a targets which finally
49 # turn into vmlinux), we will call a sub make in that other dir, and
50 # after that we are sure that everything which is in that other dir
51 # is now up to date.
52 #
53 # The only cases where we need to modify files which have global
54 # effects are thus separated out and done before the recursive
55 # descending is started. They are now explicitly listed as the
56 # prepare rule.
57
58 ifneq ($(sub_make_done),1)
59
60 # Do not use make's built-in rules and variables
61 # (this increases performance and avoids hard-to-debug behaviour)
62 MAKEFLAGS += -rR
63
64 # Avoid funny character set dependencies
65 unexport LC_ALL
66 LC_COLLATE=C
67 LC_NUMERIC=C
68 export LC_COLLATE LC_NUMERIC
69
70 # Avoid interference with shell env settings
71 unexport GREP_OPTIONS
72
73 # Beautify output
74 # ---------------------------------------------------------------------------
75 #
76 # Normally, we echo the whole command before executing it. By making
77 # that echo $($(quiet)$(cmd)), we now have the possibility to set
78 # $(quiet) to choose other forms of output instead, e.g.
79 #
80 # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
81 # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
82 #
83 # If $(quiet) is empty, the whole command will be printed.
84 # If it is set to "quiet_", only the short version will be printed.
85 # If it is set to "silent_", nothing will be printed at all, since
86 # the variable $(silent_cmd_cc_o_c) doesn't exist.
87 #
88 # A simple variant is to prefix commands with $(Q) - that's useful
89 # for commands that shall be hidden in non-verbose mode.
90 #
91 # $(Q)ln $@ :<
92 #
93 # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
94 # If KBUILD_VERBOSE equals 1 then the above command is displayed.
95 #
96 # To put more focus on warnings, be less verbose as default
97 # Use 'make V=1' to see the full commands
98
99 ifeq ("$(origin V)", "command line")
100 KBUILD_VERBOSE = $(V)
101 endif
102 ifndef KBUILD_VERBOSE
103 KBUILD_VERBOSE = 0
104 endif
105
106 ifeq ($(KBUILD_VERBOSE),1)
107 quiet =
108 Q =
109 else
110 quiet=quiet_
111 Q = @
112 endif
113
114 # If the user is running make -s (silent mode), suppress echoing of
115 # commands
116 ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
117 ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
118 quiet=silent_
119 endif
120 else # make-3.8x
121 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
122 quiet=silent_
123 endif
124 endif
125
126 export quiet Q KBUILD_VERBOSE
127
128 # kbuild supports saving output files in a separate directory.
129 # To locate output files in a separate directory two syntaxes are supported.
130 # In both cases the working directory must be the root of the kernel src.
131 # 1) O=
132 # Use "make O=dir/to/store/output/files/"
133 #
134 # 2) Set KBUILD_OUTPUT
135 # Set the environment variable KBUILD_OUTPUT to point to the directory
136 # where the output files shall be placed.
137 # export KBUILD_OUTPUT=dir/to/store/output/files/
138 # make
139 #
140 # The O= assignment takes precedence over the KBUILD_OUTPUT environment
141 # variable.
142
143 # KBUILD_SRC is not intended to be used by the regular user (for now),
144 # it is set on invocation of make with KBUILD_OUTPUT or O= specified.
145
146 # OK, Make called in directory where kernel src resides
147 # Do we want to locate output files in a separate directory?
148 ifeq ("$(origin O)", "command line")
149 KBUILD_OUTPUT := $(O)
150 endif
151
152 ifneq ($(words $(subst :, ,$(CURDIR))), 1)
153 $(error main directory cannot contain spaces nor colons)
154 endif
155
156 ifneq ($(KBUILD_OUTPUT),)
157 # check that the output directory actually exists
158 saved-output := $(KBUILD_OUTPUT)
159 KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
160 && pwd)
161 $(if $(KBUILD_OUTPUT),, \
162 $(error failed to create output directory "$(saved-output)"))
163
164 # Look for make include files relative to root of kernel src
165 #
166 # This does not become effective immediately because MAKEFLAGS is re-parsed
167 # once after the Makefile is read. It is OK since we are going to invoke
168 # 'sub-make' below.
169 MAKEFLAGS += --include-dir=$(CURDIR)
170
171 need-sub-make := 1
172 else
173
174 # Do not print "Entering directory ..." at all for in-tree build.
175 MAKEFLAGS += --no-print-directory
176
177 endif # ifneq ($(KBUILD_OUTPUT),)
178
179 ifneq ($(filter 3.%,$(MAKE_VERSION)),)
180 # 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
181 # We need to invoke sub-make to avoid implicit rules in the top Makefile.
182 need-sub-make := 1
183 # Cancel implicit rules for this Makefile.
184 $(lastword $(MAKEFILE_LIST)): ;
185 endif
186
187 export sub_make_done := 1
188
189 ifeq ($(need-sub-make),1)
190
191 PHONY += $(MAKECMDGOALS) sub-make
192
193 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
194 @:
195
196 # Invoke a second make in the output directory, passing relevant variables
197 sub-make:
198 $(Q)$(MAKE) \
199 $(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
200 -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
201
202 endif # need-sub-make
203 endif # sub_make_done
204
205 # We process the rest of the Makefile if this is the final invocation of make
206 ifeq ($(need-sub-make),)
207
208 # Do not print "Entering directory ...",
209 # but we want to display it when entering to the output directory
210 # so that IDEs/editors are able to understand relative filenames.
211 MAKEFLAGS += --no-print-directory
212
213 # Call a source code checker (by default, "sparse") as part of the
214 # C compilation.
215 #
216 # Use 'make C=1' to enable checking of only re-compiled files.
217 # Use 'make C=2' to enable checking of *all* source files, regardless
218 # of whether they are re-compiled or not.
219 #
220 # See the file "Documentation/dev-tools/sparse.rst" for more details,
221 # including where to get the "sparse" utility.
222
223 ifeq ("$(origin C)", "command line")
224 KBUILD_CHECKSRC = $(C)
225 endif
226 ifndef KBUILD_CHECKSRC
227 KBUILD_CHECKSRC = 0
228 endif
229
230 # Use make M=dir to specify directory of external module to build
231 # Old syntax make ... SUBDIRS=$PWD is still supported
232 # Setting the environment variable KBUILD_EXTMOD take precedence
233 ifdef SUBDIRS
234 $(warning ================= WARNING ================)
235 $(warning 'SUBDIRS' will be removed after Linux 5.3)
236 $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
237 $(warning ==========================================)
238 KBUILD_EXTMOD ?= $(SUBDIRS)
239 endif
240
241 ifeq ("$(origin M)", "command line")
242 KBUILD_EXTMOD := $(M)
243 endif
244
245 ifeq ($(KBUILD_SRC),)
246 # building in the source tree
247 srctree := .
248 else
249 ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
250 # building in a subdirectory of the source tree
251 srctree := ..
252 else
253 srctree := $(KBUILD_SRC)
254 endif
255 endif
256
257 export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
258
259 objtree := .
260 src := $(srctree)
261 obj := $(objtree)
262
263 VPATH := $(srctree)
264
265 export srctree objtree VPATH
266
267 # To make sure we do not include .config for any of the *config targets
268 # catch them early, and hand them over to scripts/kconfig/Makefile
269 # It is allowed to specify more targets when calling make, including
270 # mixing *config targets and build targets.
271 # For example 'make oldconfig all'.
272 # Detect when mixed targets is specified, and make a second invocation
273 # of make so .config is not included in this case either (for *config).
274
275 version_h := include/generated/version_autogenerated.h
276 timestamp_h := include/generated/timestamp_autogenerated.h
277 defaultenv_h := include/generated/defaultenv_autogenerated.h
278 dt_h := include/generated/dt.h
279 env_h := include/generated/environment.h
280
281 clean-targets := %clean mrproper cleandocs
282 no-dot-config-targets := $(clean-targets) \
283 clobber distclean \
284 help %docs check% coccicheck \
285 ubootversion backup tests check pcheck qcheck tcheck \
286 pylint pylint_err _pip pip pip_test pip_release
287 no-sync-config-targets := $(no-dot-config-targets) install %install \
288 kernelrelease
289
290 config-targets := 0
291 mixed-targets := 0
292 dot-config := 1
293 may-sync-config := 1
294
295 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
296 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
297 dot-config := 0
298 endif
299 endif
300
301 ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
302 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
303 may-sync-config := 0
304 endif
305 endif
306
307 ifneq ($(KBUILD_EXTMOD),)
308 may-sync-config := 0
309 endif
310
311 ifeq ($(KBUILD_EXTMOD),)
312 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
313 config-targets := 1
314 ifneq ($(words $(MAKECMDGOALS)),1)
315 mixed-targets := 1
316 endif
317 endif
318 endif
319
320 # For "make -j clean all", "make -j mrproper defconfig all", etc.
321 ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
322 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
323 mixed-targets := 1
324 endif
325 endif
326
327 # install and modules_install need also be processed one by one
328 ifneq ($(filter install,$(MAKECMDGOALS)),)
329 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
330 mixed-targets := 1
331 endif
332 endif
333
334 ifeq ($(mixed-targets),1)
335 # ===========================================================================
336 # We're called with mixed targets (*config and build targets).
337 # Handle them one by one.
338
339 PHONY += $(MAKECMDGOALS) __build_one_by_one
340
341 $(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
342 @:
343
344 __build_one_by_one:
345 $(Q)set -e; \
346 for i in $(MAKECMDGOALS); do \
347 $(MAKE) -f $(srctree)/Makefile $$i; \
348 done
349
350 else
351
352 include scripts/Kbuild.include
353
354 # Read UBOOTRELEASE from include/config/uboot.release (if it exists)
355 UBOOTRELEASE = $(shell cat include/config/uboot.release 2> /dev/null)
356 UBOOTVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
357 export VERSION PATCHLEVEL SUBLEVEL UBOOTRELEASE UBOOTVERSION
358
359 # Modified for U-Boot
360 -include scripts/subarch.include
361
362 # Cross compiling and selecting different set of gcc/bin-utils
363 # ---------------------------------------------------------------------------
364 #
365 # When performing cross compilation for other architectures ARCH shall be set
366 # to the target architecture. (See arch/* for the possibilities).
367 # ARCH can be set during invocation of make:
368 # make ARCH=ia64
369 # Another way is to have ARCH set in the environment.
370 # The default ARCH is the host where make is executed.
371
372 # CROSS_COMPILE specify the prefix used for all executables used
373 # during compilation. Only gcc and related bin-utils executables
374 # are prefixed with $(CROSS_COMPILE).
375 # CROSS_COMPILE can be set on the command line
376 # make CROSS_COMPILE=ia64-linux-
377 # Alternatively CROSS_COMPILE can be set in the environment.
378 # Default value for CROSS_COMPILE is not to prefix executables
379 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
380 ARCH ?= $(SUBARCH)
381
382 # Architecture as present in compile.h
383 UTS_MACHINE := $(ARCH)
384 SRCARCH := $(ARCH)
385
386 # Additional ARCH settings for x86
387 ifeq ($(ARCH),i386)
388 SRCARCH := x86
389 endif
390 ifeq ($(ARCH),x86_64)
391 SRCARCH := x86
392 endif
393
394 # Additional ARCH settings for sparc
395 ifeq ($(ARCH),sparc32)
396 SRCARCH := sparc
397 endif
398 ifeq ($(ARCH),sparc64)
399 SRCARCH := sparc
400 endif
401
402 # Additional ARCH settings for sh
403 ifeq ($(ARCH),sh64)
404 SRCARCH := sh
405 endif
406
407 KCONFIG_CONFIG ?= .config
408 export KCONFIG_CONFIG
409
410 # SHELL used by kbuild
411 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
412 else if [ -x /bin/bash ]; then echo /bin/bash; \
413 else echo sh; fi ; fi)
414
415 HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
416 HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
417 HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
418
419 HOSTCC = cc
420 HOSTCXX = c++
421 KBUILD_HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 \
422 -fomit-frame-pointer -std=gnu11 $(HOST_LFS_CFLAGS) \
423 $(HOSTCFLAGS) #-Wmissing-prototypes Enable it and fix warnings
424 KBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
425 KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
426 KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
427
428 # Check ths size of a binary:
429 # Args:
430 # $1: File to check
431 # #2: Size limit in bytes (decimal or 0xhex)
432 define size_check
433 actual=$$( wc -c $1 | awk '{print $$1}'); \
434 limit=$$( printf "%d" $2 ); \
435 if test $$actual -gt $$limit; then \
436 echo "$1 exceeds file size limit:" >&2; \
437 echo " limit: $$(printf %#x $$limit) bytes" >&2; \
438 echo " actual: $$(printf %#x $$actual) bytes" >&2; \
439 echo " excess: $$(printf %#x $$((actual - limit))) bytes" >&2;\
440 exit 1; \
441 fi
442 endef
443 export size_check
444
445 export KBUILD_MODULES KBUILD_BUILTIN
446 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
447
448 # Make variables (CC, etc...)
449 AS = $(CROSS_COMPILE)as
450 LD = $(CROSS_COMPILE)ld
451 CC = $(CROSS_COMPILE)gcc
452 CPP = $(CC) -E
453 AR = $(CROSS_COMPILE)ar
454 NM = $(CROSS_COMPILE)nm
455 LDR = $(CROSS_COMPILE)ldr
456 STRIP = $(CROSS_COMPILE)strip
457 OBJCOPY = $(CROSS_COMPILE)objcopy
458 OBJDUMP = $(CROSS_COMPILE)objdump
459 READELF = $(CROSS_COMPILE)readelf
460 LEX = flex
461 YACC = bison
462 AWK = awk
463 INSTALLKERNEL := installkernel
464 DEPMOD = /sbin/depmod
465 PERL = perl
466 PYTHON = python
467 PYTHON2 = python2
468 PYTHON3 = python3
469
470 # The devicetree compiler and pylibfdt are automatically built unless DTC is
471 # provided. If DTC is provided, it is assumed the pylibfdt is available too.
472 DTC_INTREE := $(objtree)/scripts/dtc/dtc
473 DTC ?= $(DTC_INTREE)
474 DTC_MIN_VERSION := 010406
475
476 CHECK = sparse
477
478 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
479 -Wbitwise -Wno-return-void -Wno-unknown-attribute -D__CHECK_ENDIAN__ $(CF)
480 NOSTDINC_FLAGS :=
481 CFLAGS_MODULE =
482 AFLAGS_MODULE =
483 LDFLAGS_MODULE =
484 CFLAGS_KERNEL =
485 AFLAGS_KERNEL =
486 LDFLAGS_vmlinux =
487
488 # Use USERINCLUDE when you must reference the UAPI directories only.
489 USERINCLUDE := \
490 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
491 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
492 -I$(srctree)/include/uapi \
493 -I$(objtree)/include/generated/uapi \
494 -include $(srctree)/include/linux/kconfig.h
495
496 # Use UBOOTINCLUDE when you must reference the include/ directory.
497 # Needed to be compatible with the O= option
498 UBOOTINCLUDE := \
499 -Iinclude \
500 $(if $(KBUILD_SRC), -I$(srctree)/include) \
501 $(if $(CONFIG_$(XPL_)MBEDTLS_LIB), \
502 "-DMBEDTLS_CONFIG_FILE=\"mbedtls_def_config.h\"" \
503 -I$(srctree)/lib/mbedtls \
504 -I$(srctree)/lib/mbedtls/port \
505 -I$(srctree)/lib/mbedtls/external/mbedtls \
506 -I$(srctree)/lib/mbedtls/external/mbedtls/include) \
507 $(if $(CONFIG_$(PHASE_)SYS_THUMB_BUILD), \
508 $(if $(CONFIG_HAS_THUMB2), \
509 $(if $(CONFIG_CPU_V7M), \
510 -I$(srctree)/arch/arm/thumb1/include), \
511 -I$(srctree)/arch/arm/thumb1/include)) \
512 -I$(srctree)/arch/$(ARCH)/include \
513 -include $(srctree)/include/linux/kconfig.h \
514 -I$(srctree)/dts/upstream/include \
515 $(if $(CONFIG_NET_LWIP), -I$(srctree)/lib/lwip/lwip/src/include \
516 -I$(srctree)/lib/lwip/u-boot)
517
518
519 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
520 KBUILD_CFLAGS := -Wall -Werror=strict-prototypes -Wno-trigraphs \
521 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
522 -Werror=implicit-function-declaration -Werror=implicit-int \
523 -Wno-format-security -std=gnu11 #-Wundef Enable it and fix warnings
524 UBOOT_CFLAGS := -ffreestanding -fno-builtin
525 KBUILD_CFLAGS += $(UBOOT_CFLAGS)
526
527 KBUILD_CPPFLAGS := -D__KERNEL__ -D__UBOOT__
528 KBUILD_AFLAGS_KERNEL :=
529 KBUILD_CFLAGS_KERNEL :=
530 KBUILD_AFLAGS_MODULE := -DMODULE
531 KBUILD_CFLAGS_MODULE := -DMODULE
532 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
533 KBUILD_LDFLAGS :=
534 GCC_PLUGINS_CFLAGS :=
535
536 export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
537 export CPP AR NM STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
538 export MAKE LEX YACC AWK INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
539 export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
540
541 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
542 export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
543 export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
544 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
545 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
546 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
547 export KBUILD_ARFLAGS
548
549 export LDR
550 export CPU BOARD VENDOR SOC CPUDIR BOARDDIR
551 export UBOOTINCLUDE
552 export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1)
553
554 # When compiling out-of-tree modules, put MODVERDIR in the module
555 # tree rather than in the kernel tree. The kernel tree might
556 # even be read-only.
557 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
558
559 # Files to ignore in find ... statements
560
561 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
562 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
563 -prune -o
564 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
565 --exclude CVS --exclude .pc --exclude .hg --exclude .git
566
567 export PYTHON_ENABLE
568
569 # This is y if U-Boot should not build any Python tools or libraries. Typically
570 # you would need to set this if those tools/libraries (typically binman and
571 # pylibfdt) cannot be built by your environment and are provided separately.
572 ifeq ($(NO_PYTHON),)
573 PYTHON_ENABLE=y
574 endif
575
576 # ===========================================================================
577 # Rules shared between *config targets and build targets
578
579 # Basic helpers built in scripts/basic/
580 PHONY += scripts_basic
581 scripts_basic:
582 $(Q)$(MAKE) $(build)=scripts/basic
583 $(Q)rm -f .tmp_quiet_recordmcount
584
585 PHONY += outputmakefile
586 # outputmakefile generates a Makefile in the output directory, if using a
587 # separate output directory. This allows convenient use of make in the
588 # output directory.
589 # At the same time when output Makefile generated, generate .gitignore to
590 # ignore whole output directory
591 outputmakefile:
592 ifneq ($(KBUILD_SRC),)
593 $(Q)ln -fsn $(srctree) source
594 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
595 $(Q)test -e .gitignore || \
596 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
597 endif
598
599 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
600 ifneq ($(CROSS_COMPILE),)
601 CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
602 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
603 CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
604 GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
605 endif
606 ifneq ($(GCC_TOOLCHAIN),)
607 CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
608 endif
609 CLANG_FLAGS += -no-integrated-as
610 KBUILD_CFLAGS += $(CLANG_FLAGS)
611 KBUILD_CPPFLAGS += $(CLANG_FLAGS)
612 KBUILD_AFLAGS += $(CLANG_FLAGS)
613 export CLANG_FLAGS
614 endif
615
616 RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
617 RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register
618 RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
619 RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline
620 RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
621 RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG)))
622 export RETPOLINE_CFLAGS
623 export RETPOLINE_VDSO_CFLAGS
624
625 # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
626 # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
627 # CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
628 # and from include/config/auto.conf.cmd to detect the compiler upgrade.
629 CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
630
631 ifeq ($(config-targets),1)
632 # ===========================================================================
633 # *config targets only - make sure prerequisites are updated, and descend
634 # in scripts/kconfig to make the *config target
635
636 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
637 # KBUILD_DEFCONFIG may point out an alternative default configuration
638 # used for 'make defconfig'
639 # Modified for U-Boot: we don't include arch/$(SRCARCH)/Makefile for config
640 # targets, which is useless since U-Boot has no architecture defining its own
641 # KBUILD_{DEF,K}CONFIG, or CROSS_COMPILE.
642 export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
643
644 config: scripts_basic outputmakefile FORCE
645 $(Q)$(MAKE) $(build)=scripts/kconfig $@
646
647 %config: scripts_basic outputmakefile FORCE
648 $(Q)$(MAKE) $(build)=scripts/kconfig $@
649
650 else
651 # ===========================================================================
652 # Build targets only - this includes vmlinux, arch specific targets, clean
653 # targets and others. In general all targets except *config targets.
654
655 # If building an external module we do not care about the all: rule
656 # but instead _all depend on modules
657 PHONY += all
658 ifeq ($(KBUILD_EXTMOD),)
659 _all: all
660 else
661 _all: modules
662 endif
663
664 # Decide whether to build built-in, modular, or both.
665 # Normally, just do built-in.
666
667 KBUILD_MODULES :=
668 KBUILD_BUILTIN := 1
669
670 # If we have only "make modules", don't compile built-in objects.
671 # When we're building modules with modversions, we need to consider
672 # the built-in objects during the descend as well, in order to
673 # make sure the checksums are up to date before we record them.
674
675 ifeq ($(MAKECMDGOALS),modules)
676 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
677 endif
678
679 # If we have "make <whatever> modules", compile modules
680 # in addition to whatever we do anyway.
681 # Just "make" or "make all" shall build modules as well
682
683 ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
684 KBUILD_MODULES := 1
685 endif
686
687 ifeq ($(MAKECMDGOALS),)
688 KBUILD_MODULES := 1
689 endif
690
691 export KBUILD_MODULES KBUILD_BUILTIN
692
693 ifeq ($(KBUILD_EXTMOD),)
694 # Objects we will link into vmlinux / subdirs we need to visit
695 init-y := init/
696 drivers-y := drivers/ sound/
697 net-y := net/
698 libs-y := lib/
699 core-y := usr/
700 virt-y := virt/
701 endif # KBUILD_EXTMOD
702
703 ifeq ($(dot-config),1)
704 # Modified for U-Boot
705 -include include/config/auto.conf
706 endif
707
708 # The all: target is the default when no target is given on the
709 # command line.
710 # This allow a user to issue only 'make' to build a kernel including modules
711 # Defaults to vmlinux, but the arch makefile usually adds further targets
712 all: u-boot
713
714 CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
715 $(call cc-option,-fno-tree-loop-im) \
716 $(call cc-disable-warning,maybe-uninitialized,)
717 export CFLAGS_GCOV
718
719 # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
720 ifdef CONFIG_FUNCTION_TRACER
721 CC_FLAGS_FTRACE := -pg
722 endif
723
724 # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
725 # values of the respective KBUILD_* variables
726 ARCH_CPPFLAGS :=
727 ARCH_AFLAGS :=
728 ARCH_CFLAGS :=
729 # Modified for U-Boot: we put off the include of arch/$(SRCARCH)/Makefile until
730 # making sure include/config/auto.conf is up-to-date and include of config.mk,
731 # because the architecture-specific Makefile may make use of variables defined
732 # in config.mk. See also the comment about autoconf_is_old.
733
734 ifeq ($(dot-config),1)
735 ifeq ($(may-sync-config),1)
736 # Read in dependencies to all Kconfig* files, make sure to run syncconfig if
737 # changes are detected. This should be included after arch/$(SRCARCH)/Makefile
738 # because some architectures define CROSS_COMPILE there.
739 -include include/config/auto.conf.cmd
740
741 $(KCONFIG_CONFIG):
742 @echo >&2 '***'
743 @echo >&2 '*** Configuration file "$@" not found!'
744 @echo >&2 '***'
745 @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
746 @echo >&2 '*** "make menuconfig" or "make xconfig").'
747 @echo >&2 '***'
748 @/bin/false
749
750 # If .config is newer than include/config/auto.conf, someone tinkered
751 # with it and forgot to run make oldconfig.
752 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
753 # we execute the config step to be sure to catch updated Kconfig files
754 include/config/%.conf: $(KCONFIG_CONFIG) #include/config/auto.conf.cmd
755 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
756 @# If the following part fails, include/config/auto.conf should be
757 @# deleted so "make silentoldconfig" will be re-run on the next build.
758 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.autoconf || \
759 { rm -f include/config/auto.conf; false; }
760 @# include/config.h has been updated after "make silentoldconfig".
761 @# We need to touch include/config/auto.conf so it gets newer
762 @# than include/config.h.
763 @# Otherwise, 'make silentoldconfig' would be invoked twice.
764 $(Q)touch include/config/auto.conf
765
766 u-boot.cfg spl/u-boot.cfg tpl/u-boot.cfg vpl/u-boot.cfg:
767 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.autoconf $(@)
768
769 -include include/autoconf.mk
770 -include include/autoconf.mk.dep
771
772 # We want to include arch/$(ARCH)/config.mk only when include/config/auto.conf
773 # is up-to-date. When we switch to a different board configuration, old CONFIG
774 # macros are still remaining in include/config/auto.conf. Without the following
775 # gimmick, wrong config.mk would be included leading nasty warnings/errors.
776 ifneq ($(wildcard $(KCONFIG_CONFIG)),)
777 ifneq ($(wildcard include/config/auto.conf),)
778 autoconf_is_old := $(shell find . -path ./$(KCONFIG_CONFIG) -newer \
779 include/config/auto.conf)
780 ifeq ($(autoconf_is_old),)
781 include config.mk
782 include arch/$(ARCH)/Makefile
783 endif
784 endif
785 endif
786
787 # These are set by the arch-specific config.mk. Make sure they are exported
788 # so they can be used when building an EFI application.
789 export EFI_LDS # Filename of EFI link script in arch/$(ARCH)/lib
790 export EFI_CRT0 # Filename of EFI CRT0 in arch/$(ARCH)/lib
791 export EFI_RELOC # Filename of EFU relocation code in arch/$(ARCH)/lib
792 export CFLAGS_EFI # Compiler flags to add when building EFI app
793 export CFLAGS_NON_EFI # Compiler flags to remove when building EFI app
794 export EFI_TARGET # binutils target if EFI is natively supported
795
796 export LTO_ENABLE
797
798 # This is y if LTO is enabled for this build. See NO_LTO=1 to disable LTO
799 ifeq ($(NO_LTO),)
800 LTO_ENABLE=$(if $(CONFIG_LTO),y)
801 endif
802
803 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
804 # that (or fail if absent). Otherwise, search for a linker script in a
805 # standard location.
806
807 ifndef LDSCRIPT
808 #LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot.lds.debug
809 ifdef CONFIG_SYS_LDSCRIPT
810 # need to strip off double quotes
811 LDSCRIPT := $(srctree)/$(CONFIG_SYS_LDSCRIPT:"%"=%)
812 endif
813 endif
814
815 # If there is no specified link script, we look in a number of places for it
816 ifndef LDSCRIPT
817 ifeq ($(wildcard $(LDSCRIPT)),)
818 LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot.lds
819 endif
820 ifeq ($(wildcard $(LDSCRIPT)),)
821 LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot.lds
822 endif
823 ifeq ($(wildcard $(LDSCRIPT)),)
824 LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot.lds
825 endif
826 endif
827
828 else
829 # External modules and some install targets need include/generated/autoconf.h
830 # and include/config/auto.conf but do not care if they are up-to-date.
831 # Use auto.conf to trigger the test
832 PHONY += include/config/auto.conf
833
834 include/config/auto.conf:
835 $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \
836 echo >&2; \
837 echo >&2 " ERROR: Kernel configuration is invalid."; \
838 echo >&2 " include/generated/autoconf.h or $@ are missing.";\
839 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
840 echo >&2 ; \
841 /bin/false)
842
843 endif # may-sync-config
844 endif # $(dot-config)
845
846 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
847 KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
848 KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
849 KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
850 KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
851 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
852
853 ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG
854 KBUILD_HOSTCFLAGS := -Wall -Wstrict-prototypes -Og -g -fomit-frame-pointer \
855 $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
856 # Avoid false positives -Wmaybe-uninitialized
857 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78394
858 KBUILD_HOSTCFLAGS += -Wno-maybe-uninitialized
859 KBUILD_HOSTCXXFLAGS := -Og -g $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
860 endif
861
862 #
863 # Xtensa linker script cannot be preprocessed with -ansi because of
864 # preprocessor operations on strings that don't make C identifiers.
865 #
866 ifeq ($(CONFIG_XTENSA),)
867 LDPPFLAGS += -ansi
868 endif
869
870 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
871 KBUILD_CFLAGS += -Os
872 else
873 KBUILD_CFLAGS += -O2
874 endif
875
876 ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
877 KBUILD_CFLAGS += -Wno-maybe-uninitialized
878 endif
879
880 # Tell gcc to never replace conditional load with a non-conditional one
881 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
882
883 include scripts/Makefile.kcov
884 include scripts/Makefile.gcc-plugins
885 LTO_CFLAGS :=
886 LTO_FINAL_LDFLAGS :=
887 export LTO_CFLAGS LTO_FINAL_LDFLAGS
888 ifeq ($(LTO_ENABLE),y)
889 ifeq ($(cc-name),clang)
890 LTO_CFLAGS += -DLTO_ENABLE -flto
891 LTO_FINAL_LDFLAGS += -flto
892
893 AR = $(shell $(CC) -print-prog-name=llvm-ar)
894 NM = $(shell $(CC) -print-prog-name=llvm-nm)
895 else
896 NPROC := $(shell nproc 2>/dev/null || echo 1)
897 LTO_CFLAGS += -DLTO_ENABLE -flto=$(NPROC)
898 LTO_FINAL_LDFLAGS += -fuse-linker-plugin -flto=$(NPROC)
899
900 # use plugin aware tools
901 AR = $(CROSS_COMPILE)gcc-ar
902 NM = $(CROSS_COMPILE)gcc-nm
903 endif
904
905 CFLAGS_NON_EFI += $(LTO_CFLAGS)
906
907 KBUILD_CFLAGS += $(LTO_CFLAGS)
908 endif
909
910 ifeq ($(CONFIG_STACKPROTECTOR),y)
911 KBUILD_CFLAGS += $(call cc-option,-fstack-protector-strong)
912 KBUILD_CFLAGS += $(call cc-option,-mstack-protector-guard=global)
913 CFLAGS_EFI += $(call cc-option,-fno-stack-protector)
914 else
915 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
916 endif
917 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
918
919 KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
920 KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds)
921 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
922
923 # Enabled with W=2, disabled by default as noisy
924 KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
925
926 # change __FILE__ to the relative path from the srctree
927 KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
928
929 KBUILD_CFLAGS += -gdwarf-4
930 # $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
931 # option to the assembler.
932 KBUILD_AFLAGS += -gdwarf-4
933
934 # Report stack usage if supported
935 # ARC tools based on GCC 7.1 has an issue with stack usage
936 # with naked functions, see commit message for more details
937 ifndef CONFIG_ARC
938 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-stack-usage.sh $(CC)),y)
939 KBUILD_CFLAGS += -fstack-usage
940 endif
941 endif
942
943 KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
944 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
945
946 ifdef CONFIG_CC_IS_CLANG
947 KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
948 KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
949 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
950 # Quiet clang warning: comparison of unsigned expression < 0 is always false
951 KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
952 # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
953 # source of a reference will be _MergedGlobals and not on of the whitelisted names.
954 # See modpost pattern 2
955 KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
956 KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
957 KBUILD_CFLAGS += $(call cc-disable-warning, deprecated-non-prototype)
958 else
959
960 # These warnings generated too much noise in a regular build.
961 # Use make W=1 to enable them (see scripts/Makefile.extrawarn)
962 KBUILD_CFLAGS += -Wno-unused-but-set-variable
963 endif
964
965 # These warnings generated too much noise in a regular build.
966 # Use make W=1 to enable them (see scripts/Makefile.extrawarn)
967 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
968
969 # Prohibit date/time macros, which would make the build non-deterministic
970 KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
971
972 include scripts/Makefile.extrawarn
973
974 # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
975 KBUILD_CPPFLAGS += $(KCPPFLAGS)
976 KBUILD_AFLAGS += $(KAFLAGS)
977 KBUILD_CFLAGS += $(KCFLAGS)
978
979 KBUILD_LDFLAGS += -z noexecstack
980 KBUILD_LDFLAGS += -z norelro
981 KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
982
983 KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g)
984
985 # Use UBOOTINCLUDE when you must reference the include/ directory.
986 # Needed to be compatible with the O= option
987 UBOOTINCLUDE := \
988 -Iinclude \
989 $(if $(KBUILD_SRC), -I$(srctree)/include) \
990 $(if $(CONFIG_$(XPL_)MBEDTLS_LIB), \
991 "-DMBEDTLS_CONFIG_FILE=\"mbedtls_def_config.h\"" \
992 -I$(srctree)/lib/mbedtls \
993 -I$(srctree)/lib/mbedtls/port \
994 -I$(srctree)/lib/mbedtls/external/mbedtls \
995 -I$(srctree)/lib/mbedtls/external/mbedtls/include) \
996 $(if $(CONFIG_$(PHASE_)SYS_THUMB_BUILD), \
997 $(if $(CONFIG_HAS_THUMB2), \
998 $(if $(CONFIG_CPU_V7M), \
999 -I$(srctree)/arch/arm/thumb1/include), \
1000 -I$(srctree)/arch/arm/thumb1/include)) \
1001 -I$(srctree)/arch/$(ARCH)/include \
1002 -include $(srctree)/include/linux/kconfig.h \
1003 -I$(srctree)/dts/upstream/include \
1004 $(if $(CONFIG_NET_LWIP), -I$(srctree)/lib/lwip/lwip/src/include \
1005 -I$(srctree)/lib/lwip/u-boot)
1006
1007 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
1008
1009 # FIX ME
1010 cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
1011 $(NOSTDINC_FLAGS)
1012 c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
1013
1014
1015 #########################################################################
1016 # U-Boot objects....order is important (i.e. start must be first)
1017
1018 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
1019
1020 libs-$(CONFIG_API) += api/
1021 libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
1022 libs-y += boot/
1023 libs-$(CONFIG_CMDLINE) += cmd/
1024 libs-y += common/
1025 libs-$(CONFIG_OF_EMBED) += dts/
1026 libs-y += env/
1027 libs-y += lib/
1028 libs-y += fs/
1029 libs-$(filter y,$(CONFIG_NET) $(CONFIG_NET_LWIP)) += net/
1030 libs-y += disk/
1031 libs-y += drivers/
1032 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
1033 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
1034 libs-$(CONFIG_$(PHASE_)ALTERA_SDRAM) += drivers/ddr/altera/
1035 libs-y += drivers/usb/cdns3/
1036 libs-y += drivers/usb/dwc3/
1037 libs-y += drivers/usb/common/
1038 libs-y += drivers/usb/emul/
1039 libs-y += drivers/usb/eth/
1040 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
1041 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
1042 libs-y += drivers/usb/host/
1043 libs-y += drivers/usb/mtu3/
1044 libs-y += drivers/usb/musb/
1045 libs-y += drivers/usb/musb-new/
1046 libs-y += drivers/usb/isp1760/
1047 libs-y += drivers/usb/phy/
1048 libs-y += drivers/usb/tcpm/
1049 libs-y += drivers/usb/ulpi/
1050 ifdef CONFIG_POST
1051 libs-y += post/
1052 endif
1053 libs-$(CONFIG_$(PHASE_)UNIT_TEST) += test/
1054
1055 libs-y += $(if $(wildcard $(srctree)/board/$(BOARDDIR)/Makefile),board/$(BOARDDIR)/)
1056
1057 libs-y := $(sort $(libs-y))
1058
1059 u-boot-dirs := $(patsubst %/,%,$(filter %/, $(libs-y))) tools examples
1060
1061 u-boot-alldirs := $(sort $(u-boot-dirs) $(patsubst %/,%,$(filter %/, $(libs-))))
1062
1063 libs-y := $(patsubst %/, %/built-in.a, $(libs-y))
1064 # Not needed in U-Boot
1065 #init-y := $(patsubst %/, %/built-in.a, $(init-y))
1066 #core-y := $(patsubst %/, %/built-in.a, $(core-y))
1067 drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y))
1068 #net-y := $(patsubst %/, %/built-in.a, $(net-y))
1069 libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
1070 libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))
1071 #virt-y := $(patsubst %/, %/built-in.a, $(virt-y))
1072
1073 u-boot-init := $(head-y)
1074 u-boot-main := $(libs-y)
1075
1076
1077 # Add GCC lib
1078 ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
1079 PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
1080 else
1081 ifndef CONFIG_CC_IS_CLANG
1082 PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc
1083 endif
1084 endif
1085 PLATFORM_LIBS += $(PLATFORM_LIBGCC)
1086
1087 ifdef CONFIG_CC_COVERAGE
1088 KBUILD_CFLAGS += --coverage
1089 PLATFORM_LIBGCC += -lgcov
1090 endif
1091
1092 export PLATFORM_LIBS
1093 export PLATFORM_LIBGCC
1094
1095 # Special flags for CPP when processing the linker script.
1096 # Pass the version down so we can handle backwards compatibility
1097 # on the fly.
1098 LDPPFLAGS += \
1099 -include $(srctree)/include/u-boot/u-boot.lds.h \
1100 -DCPUDIR=$(CPUDIR) \
1101 $(shell $(LD) --version | \
1102 sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
1103
1104 #########################################################################
1105 #########################################################################
1106
1107 ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
1108 BOARD_SIZE_CHECK= @ $(call size_check,$@,$(CONFIG_BOARD_SIZE_LIMIT))
1109 else
1110 BOARD_SIZE_CHECK =
1111 endif
1112
1113 ifneq ($(CONFIG_SPL_SIZE_LIMIT),0x0)
1114 SPL_SIZE_CHECK = @$(call size_check,$@,$$(tools/spl_size_limit))
1115 else
1116 SPL_SIZE_CHECK =
1117 endif
1118
1119 ifneq ($(CONFIG_TPL_SIZE_LIMIT),0x0)
1120 TPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_TPL_SIZE_LIMIT))
1121 else
1122 TPL_SIZE_CHECK =
1123 endif
1124
1125 ifneq ($(CONFIG_VPL_SIZE_LIMIT),0x0)
1126 VPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_VPL_SIZE_LIMIT))
1127 else
1128 VPL_SIZE_CHECK =
1129 endif
1130
1131 # Statically apply RELA-style relocations (currently arm64 only)
1132 # This is useful for arm64 where static relocation needs to be performed on
1133 # the raw binary, but certain simulators only accept an ELF file (but don't
1134 # do the relocation).
1135 ifneq ($(CONFIG_STATIC_RELA),)
1136 # $(2) is u-boot ELF, $(3) is u-boot bin, $(4) is text base
1137 quiet_cmd_static_rela = RELOC $@
1138 cmd_static_rela = \
1139 tools/relocate-rela $(3) $(2)
1140 else
1141 quiet_cmd_static_rela =
1142 cmd_static_rela =
1143 endif
1144
1145 # Always append INPUTS so that arch config.mk's can add custom ones
1146 INPUTS-y += u-boot.srec u-boot.bin u-boot.sym System.map binary_size_check
1147
1148 ifeq ($(CONFIG_SPL_FSL_PBL),y)
1149 INPUTS-$(CONFIG_RAMBOOT_PBL) += u-boot-with-spl-pbl.bin
1150 else
1151 ifneq ($(CONFIG_NXP_ESBC), y)
1152 # For Secure Boot The Image needs to be signed and Header must also
1153 # be included. So The image has to be built explicitly
1154 INPUTS-$(CONFIG_RAMBOOT_PBL) += u-boot.pbl
1155 endif
1156 endif
1157 INPUTS-$(CONFIG_SPL) += spl/u-boot-spl.bin
1158 ifeq ($(CONFIG_MX6)$(CONFIG_IMX_HAB), yy)
1159 INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot-ivt.img
1160 else
1161 ifeq ($(CONFIG_MX7)$(CONFIG_IMX_HAB), yy)
1162 INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot-ivt.img
1163 else
1164 INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
1165 endif
1166 endif
1167 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
1168 INPUTS-$(CONFIG_VPL) += vpl/u-boot-vpl.bin
1169
1170 # Allow omitting the .dtb output if it is not normally used
1171 INPUTS-$(CONFIG_OF_SEPARATE) += $(if $(CONFIG_OF_OMIT_DTB),dts/dt.dtb,u-boot.dtb)
1172 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
1173 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
1174 endif
1175 INPUTS-$(CONFIG_SANDBOX) += u-boot.dtb
1176 ifneq ($(CONFIG_SPL_TARGET),)
1177 INPUTS-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
1178 endif
1179 INPUTS-$(CONFIG_REMAKE_ELF) += u-boot.elf
1180 INPUTS-$(CONFIG_EFI_APP) += u-boot-app.efi
1181 INPUTS-$(CONFIG_EFI_STUB) += u-boot-payload.efi
1182
1183 # Generate this input file for binman
1184 ifeq ($(CONFIG_SPL),)
1185 ifneq ($(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO)),)
1186 INPUTS-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
1187 endif
1188 endif
1189
1190 ifdef CONFIG_FUNCTION_TRACER
1191 ifdef CONFIG_FTRACE_MCOUNT_RECORD
1192 # gcc 5 supports generating the mcount tables directly
1193 ifeq ($(call cc-option-yn,-mrecord-mcount),y)
1194 CC_FLAGS_FTRACE += -mrecord-mcount
1195 export CC_USING_RECORD_MCOUNT := 1
1196 endif
1197 ifdef CONFIG_HAVE_NOP_MCOUNT
1198 ifeq ($(call cc-option-yn, -mnop-mcount),y)
1199 CC_FLAGS_FTRACE += -mnop-mcount
1200 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
1201 endif
1202 endif
1203 endif
1204 ifdef CONFIG_HAVE_FENTRY
1205 ifeq ($(call cc-option-yn, -mfentry),y)
1206 CC_FLAGS_FTRACE += -mfentry
1207 CC_FLAGS_USING += -DCC_USING_FENTRY
1208 endif
1209 endif
1210 export CC_FLAGS_FTRACE
1211 KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
1212 KBUILD_AFLAGS += $(CC_FLAGS_USING)
1213 ifdef CONFIG_DYNAMIC_FTRACE
1214 ifdef CONFIG_HAVE_C_RECORDMCOUNT
1215 BUILD_C_RECORDMCOUNT := y
1216 export BUILD_C_RECORDMCOUNT
1217 endif
1218 endif
1219 endif
1220
1221 # Add optional build target if defined in board/cpu/soc headers
1222 ifneq ($(CONFIG_BUILD_TARGET),)
1223 INPUTS-y += $(CONFIG_BUILD_TARGET:"%"=%)
1224 endif
1225
1226 ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy)
1227 INPUTS-y += init_sp_bss_offset_check
1228 endif
1229
1230 ifeq ($(CONFIG_ARCH_ROCKCHIP)_$(CONFIG_SPL_FRAMEWORK),y_)
1231 INPUTS-y += u-boot.img
1232 endif
1233
1234 INPUTS-$(CONFIG_X86) += u-boot-x86-start16.bin u-boot-x86-reset16.bin \
1235 $(if $(CONFIG_SPL_X86_16BIT_INIT),spl/u-boot-spl.bin) \
1236 $(if $(CONFIG_TPL_X86_16BIT_INIT),tpl/u-boot-tpl.bin)
1237
1238 LDFLAGS_u-boot += $(LDFLAGS_FINAL)
1239
1240 # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
1241 LDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker)
1242
1243 # ld.lld support
1244 LDFLAGS_u-boot += -z notext $(call ld-option,--apply-dynamic-relocs)
1245
1246 LDFLAGS_u-boot += --build-id=none
1247
1248 ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),)
1249 LDFLAGS_u-boot += -Ttext $(CONFIG_TEXT_BASE)
1250 endif
1251
1252 # make the checker run with the right architecture
1253 CHECKFLAGS += --arch=$(ARCH)
1254
1255 # insure the checker run with the right endianness
1256 CHECKFLAGS += $(if $(CONFIG_SYS_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1257
1258 # the checker needs the correct machine size
1259 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1260
1261 # Normally we fill empty space with 0xff
1262 quiet_cmd_objcopy = OBJCOPY $@
1263 cmd_objcopy = $(OBJCOPY) --gap-fill=0xff $(OBJCOPYFLAGS) \
1264 $(OBJCOPYFLAGS_$(@F)) $< $@
1265
1266 # disable pointer signed / unsigned warnings in gcc 4.0
1267 KBUILD_CFLAGS += -Wno-pointer-sign
1268
1269 # disable stringop warnings in gcc 8+
1270 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
1271
1272 # disable invalid "can't wrap" optimizations for signed / pointers
1273 KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
1274
1275 # Provide a version which does not do this, for use by EFI and hex/srec
1276 quiet_cmd_zobjcopy = OBJCOPY $@
1277 cmd_zobjcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
1278
1279 quiet_cmd_efipayload = OBJCOPY $@
1280 cmd_efipayload = $(OBJCOPY) -I binary -O $(EFIPAYLOAD_BFDTARGET) -B $(EFIPAYLOAD_BFDARCH) $< $@
1281
1282 MKIMAGEOUTPUT ?= /dev/null
1283
1284 quiet_cmd_mkimage = MKIMAGE $@
1285 cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
1286 >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
1287
1288 quiet_cmd_mkfitimage = MKIMAGE $@
1289 cmd_mkfitimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) \
1290 -f $(U_BOOT_ITS) -p $(CONFIG_FIT_EXTERNAL_OFFSET) $@ \
1291 >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
1292
1293 quiet_cmd_cat = CAT $@
1294 cmd_cat = cat $(filter-out $(PHONY), $^) > $@
1295
1296 append = cat $(filter-out $< $(PHONY), $^) >> $@
1297
1298 quiet_cmd_pad_cat = CAT $@
1299 cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
1300
1301 quiet_cmd_lzma = LZMA $@
1302 cmd_lzma = lzma -c -z -k -9 $< > $@
1303
1304 cfg: u-boot.cfg
1305
1306 quiet_cmd_ofcheck = OFCHK $2
1307 cmd_ofcheck = $(srctree)/scripts/check-of.sh $2 \
1308 $(srctree)/scripts/of_allowlist.txt
1309
1310 # Concat the value of all the CONFIGs (result is 'y' or 'yy', etc. )
1311 got = $(foreach cfg,$(1),$($(cfg)))
1312
1313 # expected value 'y for each one
1314 expect = $(foreach cfg,$(1),y)
1315
1316 # Show a deprecation message
1317 # Args:
1318 # 1: List of options to migrate to (e.g. "CONFIG_DM_MMC CONFIG_BLK")
1319 # 2: Name of component (e.g . "Ethernet drivers")
1320 # 3: Release deadline (e.g. "v202.07")
1321 # 4: Condition to require before checking (e.g. "$(CONFIG_NET)")
1322 # Note: Script avoids bash construct, hence the strange double 'if'
1323 # (patches welcome!)
1324 define deprecated
1325 @if [ -n "$(strip $(4))" ]; then if [ "$(got)" != "$(expect)" ]; then \
1326 echo >&2 "===================== WARNING ======================"; \
1327 echo >&2 "This board does not use $(firstword $(1)) (Driver Model"; \
1328 echo >&2 "for $(2)). Please update the board to use"; \
1329 echo >&2 "$(firstword $(1)) before the $(3) release. Failure to"; \
1330 echo >&2 "update by the deadline may result in board removal."; \
1331 echo >&2 "See doc/develop/driver-model/migration.rst for more info."; \
1332 echo >&2 "===================================================="; \
1333 fi; fi
1334
1335 endef
1336
1337 # Timestamp file to make sure that binman always runs
1338 .binman_stamp: $(INPUTS-y) FORCE
1339 ifeq ($(CONFIG_BINMAN),y)
1340 $(call if_changed,binman)
1341 endif
1342 @touch $@
1343
1344 all: .binman_stamp
1345
1346 ifeq ($(CONFIG_DEPRECATED),y)
1347 $(warning "You have deprecated configuration options enabled in your .config! Please check your configuration.")
1348 endif
1349 ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
1350 @echo >&2 "===================== WARNING ======================"
1351 @echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
1352 @echo >&2 "be used for debugging purposes. Please use"
1353 @echo >&2 "CONFIG_OF_SEPARATE for boards in mainline."
1354 @echo >&2 "See doc/develop/devicetree/control.rst for more info."
1355 @echo >&2 "===================================================="
1356 endif
1357 $(call deprecated,CONFIG_WDT,DM watchdog,v2019.10,\
1358 $(CONFIG_WATCHDOG)$(CONFIG_HW_WATCHDOG))
1359 $(call deprecated,CONFIG_DM_I2C,I2C drivers,v2022.04,$(CONFIG_SYS_I2C_LEGACY))
1360 @# CFG_SYS_TIMER_RATE has brackets in it for some boards which
1361 @# confuses this rule. Use if() to send just a single character which
1362 @# is enable to tell 'deprecated' that one of these symbols exists
1363 $(call deprecated,CONFIG_TIMER,Timer drivers,v2023.01,$(if $(strip $(CFG_SYS_TIMER_RATE)$(CFG_SYS_TIMER_COUNTER)),x))
1364 $(call deprecated,CONFIG_DM_SERIAL,Serial drivers,v2023.04,$(CONFIG_SERIAL))
1365 @# Check that this build does not override OF_HAS_PRIOR_STAGE by
1366 @# disabling OF_BOARD.
1367 $(call cmd,ofcheck,$(KCONFIG_CONFIG))
1368
1369 PHONY += dtbs dtbs_check
1370 dtbs: dts/dt.dtb
1371 @:
1372 dts/dt.dtb: dtbs_prepare u-boot
1373 $(Q)$(MAKE) $(build)=dts dtbs
1374
1375 dtbs_prepare: prepare3
1376
1377 ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
1378 export CHECK_DTBS=y
1379 endif
1380
1381 ifneq ($(CHECK_DTBS),)
1382 dtbs_prepare: dt_binding_check
1383 endif
1384
1385 dtbs_check: dt_binding_check dtbs
1386
1387 DT_BINDING_DIR := dts/upstream/Bindings
1388 dt_binding_check: scripts_dtc
1389 $(Q)$(MAKE) $(build)=$(DT_BINDING_DIR) $(DT_BINDING_DIR)/processed-schema.json
1390
1391 quiet_cmd_copy = COPY $@
1392 cmd_copy = cp $< $@
1393
1394 ifeq ($(CONFIG_OF_UPSTREAM),y)
1395 ifeq ($(CONFIG_ARM64),y)
1396 dt_dir := dts/upstream/src/arm64
1397 else
1398 dt_dir := dts/upstream/src/$(ARCH)
1399 endif
1400 else
1401 dt_dir := arch/$(ARCH)/dts
1402 endif
1403
1404 ifeq ($(CONFIG_MULTI_DTB_FIT),y)
1405
1406 ifeq ($(CONFIG_MULTI_DTB_FIT_LZO),y)
1407 FINAL_DTB_CONTAINER = fit-dtb.blob.lzo
1408 else ifeq ($(CONFIG_MULTI_DTB_FIT_GZIP),y)
1409 FINAL_DTB_CONTAINER = fit-dtb.blob.gz
1410 else
1411 FINAL_DTB_CONTAINER = fit-dtb.blob
1412 endif
1413
1414 fit-dtb.blob.gz: fit-dtb.blob
1415 @gzip -nkf9 $< > $@
1416
1417 fit-dtb.blob.lzo: fit-dtb.blob
1418 @lzop -f9 $< > $@
1419
1420 fit-dtb.blob: dts/dt.dtb FORCE
1421 $(call if_changed,mkimage)
1422 ifneq ($(SOURCE_DATE_EPOCH),)
1423 touch -d @$(SOURCE_DATE_EPOCH) fit-dtb.blob
1424 chmod 0600 fit-dtb.blob
1425 endif
1426
1427 MKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
1428 -a 0 -e 0 -E \
1429 $(patsubst %,-b $(dt_dir)/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null
1430
1431 MKIMAGEFLAGS_fit-dtb.blob += -B 0x8
1432
1433 ifneq ($(EXT_DTB),)
1434 u-boot-fit-dtb.bin: u-boot-nodtb.bin $(EXT_DTB)
1435 $(call if_changed,cat)
1436 else
1437 u-boot-fit-dtb.bin: u-boot-nodtb.bin $(FINAL_DTB_CONTAINER)
1438 $(call if_changed,cat)
1439 endif
1440
1441 u-boot.bin: u-boot-fit-dtb.bin FORCE
1442 $(call if_changed,copy)
1443
1444 ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
1445 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
1446 $(call if_changed,cat)
1447 endif
1448
1449 else ifeq ($(CONFIG_OF_SEPARATE).$(CONFIG_OF_OMIT_DTB),y.)
1450
1451 ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
1452 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
1453 $(call if_changed,cat)
1454 endif
1455
1456 u-boot.bin: u-boot-dtb.bin FORCE
1457 $(call if_changed,copy)
1458
1459 else
1460 u-boot.bin: u-boot-nodtb.bin FORCE
1461 $(call if_changed,copy)
1462 endif
1463
1464 # we call Makefile in arch/arm/mach-imx which
1465 # has targets which are dependent on targets defined
1466 # here. make could not resolve them and we must ensure
1467 # that they are finished before calling imx targets
1468 ifeq ($(CONFIG_MULTI_DTB_FIT),y)
1469 IMX_DEPS = u-boot-fit-dtb.bin
1470 endif
1471
1472 %.imx: $(IMX_DEPS) %.bin
1473 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1474 $(BOARD_SIZE_CHECK)
1475
1476 %.vyb: %.imx
1477 $(Q)$(MAKE) $(build)=arch/arm/cpu/armv7/vf610 $@
1478
1479 quiet_cmd_copy = COPY $@
1480 cmd_copy = cp $< $@
1481
1482 u-boot.dtb: dts/dt.dtb
1483 $(call cmd,copy)
1484
1485 OBJCOPYFLAGS_u-boot.hex := -O ihex
1486
1487 OBJCOPYFLAGS_u-boot.srec := -O srec
1488
1489 u-boot.hex u-boot.srec: u-boot FORCE
1490 $(call if_changed,zobjcopy)
1491
1492 OBJCOPYFLAGS_u-boot-elf.srec := $(OBJCOPYFLAGS_u-boot.srec)
1493
1494 ifeq ($(CONFIG_POSITION_INDEPENDENT)$(CONFIG_RCAR_GEN3),yy)
1495 # The flash_writer tool and previous recovery tools
1496 # require the SREC load address to be 0x5000_0000 .
1497 # The PIE U-Boot build sets the address to 0x0, so
1498 # override the address back to make u-boot-elf.srec
1499 # compatible with the recovery tools.
1500 OBJCOPYFLAGS_u-boot-elf.srec += --change-addresses=0x50000000
1501 endif
1502
1503 u-boot-elf.srec: u-boot.elf FORCE
1504 $(call if_changed,zobjcopy)
1505
1506 OBJCOPYFLAGS_u-boot-spl.srec = $(OBJCOPYFLAGS_u-boot.srec)
1507
1508 spl/u-boot-spl.srec: spl/u-boot-spl FORCE
1509 $(call if_changed,zobjcopy)
1510
1511 %.scif: %.srec
1512 $(Q)$(MAKE) $(build)=arch/arm/mach-renesas $@
1513
1514 OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \
1515 $(if $(CONFIG_X86_16BIT_INIT),-R .start16 -R .resetvec) \
1516 $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR),$(if $(CONFIG_OF_SEPARATE),-R .bootpg -R .resetvec))
1517
1518 binary_size_check: u-boot-nodtb.bin FORCE
1519 @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{ print $$1 }') ; \
1520 map_size=$(shell cat u-boot.map | \
1521 awk ' \
1522 /_image_copy_start/ { start = $$1 } \
1523 /_image_binary_end/ { end = $$1 } \
1524 END { \
1525 if (start != "" && end != "") \
1526 print end " " start; \
1527 }' \
1528 | sh -c 'read end start && echo $$((end - start))'); \
1529 if [ -n "$$map_size" ]; then \
1530 if test $$map_size -ne $$file_size; then \
1531 echo "u-boot.map shows a binary size of $$map_size" >&2 ; \
1532 echo " but u-boot-nodtb.bin shows $$file_size" >&2 ; \
1533 exit 1; \
1534 fi; \
1535 fi
1536
1537 ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy)
1538 ifneq ($(CONFIG_SYS_MALLOC_F),)
1539 subtract_sys_malloc_f_len = space=$$(($${space} - $(CONFIG_SYS_MALLOC_F_LEN)))
1540 else
1541 subtract_sys_malloc_f_len = true
1542 endif
1543 # The 1/4 margin below is somewhat arbitrary. The likely initial SP usage is
1544 # so low that the DTB could probably use 90%+ of the available space, for
1545 # current values of CONFIG_SYS_INIT_SP_BSS_OFFSET at least. However, let's be
1546 # safe for now and tweak this later if space becomes tight.
1547 # A rejected alternative would be to check that some absolute minimum stack
1548 # space was available. However, since CONFIG_SYS_INIT_SP_BSS_OFFSET is
1549 # deliberately build-specific, to take account of build-to-build stack usage
1550 # differences due to different feature sets, there is no common absolute value
1551 # to check against.
1552 init_sp_bss_offset_check: u-boot.dtb FORCE
1553 @dtb_size=$(shell wc -c u-boot.dtb | awk '{print $$1}') ; \
1554 space=$(CONFIG_SYS_INIT_SP_BSS_OFFSET) ; \
1555 $(subtract_sys_malloc_f_len) ; \
1556 quarter_space=$$(($${space} / 4)) ; \
1557 if [ $${dtb_size} -gt $${quarter_space} ]; then \
1558 echo "u-boot.dtb is larger than 1 quarter of " >&2 ; \
1559 echo "(CONFIG_SYS_INIT_SP_BSS_OFFSET - CONFIG_SYS_MALLOC_F_LEN)" >&2 ; \
1560 exit 1 ; \
1561 fi
1562 endif
1563
1564 shell_cmd = { $(call echo-cmd,$(1)) $(cmd_$(1)); }
1565
1566 quiet_cmd_objcopy_uboot = OBJCOPY $@
1567 ifdef cmd_static_rela
1568 cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_TEXT_BASE)) || { rm -f $@; false; }
1569 else
1570 cmd_objcopy_uboot = $(cmd_objcopy)
1571 endif
1572
1573 u-boot-nodtb.bin: u-boot FORCE
1574 $(call if_changed,objcopy_uboot)
1575 $(BOARD_SIZE_CHECK)
1576
1577 u-boot.ldr: u-boot
1578 $(LDR) -T $(CONFIG_LDR_CPU) -c $@ $< $(LDR_FLAGS)
1579 $(BOARD_SIZE_CHECK)
1580
1581 # binman
1582 # ---------------------------------------------------------------------------
1583 # Use 'make BINMAN_DEBUG=1' to enable debugging
1584 # Use 'make BINMAN_VERBOSE=3' to set vebosity level
1585
1586 ifneq ($(EXT_DTB),)
1587 ext_dtb_list := $(basename $(notdir $(EXT_DTB)))
1588 default_dt := $(firstword $(ext_dtb_list))
1589 of_list := "$(ext_dtb_list)"
1590 of_list_dirs := $(dir $(EXT_DTB)) $(dt_dir)
1591 else
1592 of_list := $(CONFIG_OF_LIST)
1593 of_list_dirs := $(dt_dir)
1594 default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE))
1595 endif
1596
1597 ifneq ($(CONFIG_OF_UPSTREAM_INCLUDE_LOCAL_FALLBACK_DTBOS),)
1598 of_list_dirs += arch/$(ARCH)/dts
1599 endif
1600
1601 binman_dtb := $(shell echo $(CONFIG_BINMAN_DTB))
1602 ifeq ($(strip $(binman_dtb)),)
1603 ifeq ($(CONFIG_OF_EMBED),y)
1604 binman_dtb = ./dts/dt.dtb
1605 else
1606 binman_dtb = ./u-boot.dtb
1607 endif
1608 endif
1609
1610 quiet_cmd_binman = BINMAN $@
1611 cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
1612 $(foreach f,$(BINMAN_TOOLPATHS),--toolpath $(f)) \
1613 --toolpath $(objtree)/tools \
1614 $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
1615 build -u -d $(binman_dtb) -O . -m \
1616 --allow-missing --fake-ext-blobs \
1617 $(if $(BINMAN_ALLOW_MISSING),--ignore-missing) \
1618 -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
1619 $(foreach f,$(of_list_dirs),-I $(f)) -a of-list=$(of_list) \
1620 $(foreach f,$(BINMAN_INDIRS),-I $(f)) \
1621 -a atf-bl1-path=${BL1} \
1622 -a atf-bl31-path=${BL31} \
1623 -a tee-os-path=${TEE} \
1624 -a ti-dm-path=${TI_DM} \
1625 -a opensbi-path=${OPENSBI} \
1626 -a default-dt=$(default_dt) \
1627 -a scp-path=$(SCP) \
1628 -a rockchip-tpl-path=$(ROCKCHIP_TPL) \
1629 -a spl-bss-pad=$(if $(CONFIG_SPL_SEPARATE_BSS),,1) \
1630 -a tpl-bss-pad=$(if $(CONFIG_TPL_SEPARATE_BSS),,1) \
1631 -a vpl-bss-pad=$(if $(CONFIG_VPL_SEPARATE_BSS),,1) \
1632 -a spl-dtb=$(CONFIG_SPL_OF_REAL) \
1633 -a tpl-dtb=$(CONFIG_TPL_OF_REAL) \
1634 -a vpl-dtb=$(CONFIG_VPL_OF_REAL) \
1635 -a pre-load-key-path=${PRE_LOAD_KEY_PATH} \
1636 -a of-spl-remove-props=$(CONFIG_OF_SPL_REMOVE_PROPS) \
1637 $(BINMAN_$(@F))
1638
1639 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
1640
1641 OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
1642
1643 u-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE
1644 $(call if_changed,zobjcopy)
1645
1646 ifdef CONFIG_SPL_LOAD_FIT
1647 MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
1648 -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
1649 -p $(CONFIG_FIT_EXTERNAL_OFFSET) \
1650 -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board" -E \
1651 $(patsubst %,-b $(dt_dir)/%.dtb,$(subst ",,$(DEVICE_TREE))) \
1652 $(patsubst %,-b $(dt_dir)/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) \
1653 $(patsubst %,-b $(dt_dir)/%.dtbo,$(subst ",,$(CONFIG_OF_OVERLAY_LIST)))
1654 else
1655 MKIMAGEFLAGS_u-boot.img = -A $(ARCH) -T firmware -C none -O u-boot \
1656 -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
1657 -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
1658 MKIMAGEFLAGS_u-boot-ivt.img = -A $(ARCH) -T firmware_ivt -C none -O u-boot \
1659 -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
1660 -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
1661 u-boot-ivt.img: MKIMAGEOUTPUT = u-boot-ivt.img.log
1662 endif
1663
1664 MKIMAGEFLAGS_u-boot-dtb.img = $(MKIMAGEFLAGS_u-boot.img)
1665
1666 # Some boards have the kwbimage.cfg file written in advance, while some
1667 # other boards generate it on the fly during the build in the build tree.
1668 # Let's check if the file exists in the build tree first, otherwise we
1669 # fall back to use the one in the source tree.
1670 KWD_CONFIG_FILE = $(shell \
1671 if [ -f $(objtree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%) ]; then \
1672 echo -n $(objtree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%); \
1673 else \
1674 echo -n $(srctree)/$(CONFIG_SYS_KWD_CONFIG:"%"=%); \
1675 fi)
1676
1677 MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \
1678 -T kwbimage -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE)
1679
1680 MKIMAGEFLAGS_u-boot-with-spl.kwb = -n $(KWD_CONFIG_FILE) \
1681 -T kwbimage -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE) \
1682 $(if $(KEYDIR),-k $(KEYDIR))
1683
1684 MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
1685 -R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -A $(ARCH) -T pblimage
1686
1687 UBOOT_BIN := u-boot.bin
1688
1689 MKIMAGEFLAGS_u-boot-lzma.img = -A $(ARCH) -T standalone -C lzma -O u-boot \
1690 -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
1691 -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
1692
1693 u-boot.bin.lzma: u-boot.bin FORCE
1694 $(call if_changed,lzma)
1695
1696 u-boot-lzma.img: u-boot.bin.lzma FORCE
1697 $(call if_changed,mkimage)
1698
1699 fit_image := $(if $(CONFIG_SANDBOX_VPL),u-boot,u-boot-nodtb.bin)
1700
1701 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
1702 $(if $(CONFIG_SPL_LOAD_FIT),$(fit_image) \
1703 $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
1704 ,$(UBOOT_BIN)) FORCE
1705 $(call if_changed,mkimage)
1706 $(BOARD_SIZE_CHECK)
1707
1708 ifeq ($(CONFIG_SPL_LOAD_FIT_FULL),y)
1709 MKIMAGEFLAGS_u-boot.itb =
1710 else
1711 MKIMAGEFLAGS_u-boot.itb = -E
1712 endif
1713 MKIMAGEFLAGS_u-boot.itb += -B 0x8
1714
1715 ifdef U_BOOT_ITS
1716 u-boot.itb: u-boot-nodtb.bin \
1717 $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
1718 $(if $(CONFIG_MULTI_DTB_FIT),$(FINAL_DTB_CONTAINER)) \
1719 $(U_BOOT_ITS) FORCE
1720 $(call if_changed,mkfitimage)
1721 $(BOARD_SIZE_CHECK)
1722 endif
1723
1724 u-boot-with-spl.kwb: u-boot.bin spl/u-boot-spl.bin FORCE
1725 $(call if_changed,mkimage)
1726 $(BOARD_SIZE_CHECK)
1727
1728 u-boot.dis: u-boot
1729 $(OBJDUMP) -d $< > $@
1730
1731 ifneq ($(CONFIG_SPL_PAYLOAD),)
1732 SPL_PAYLOAD := $(CONFIG_SPL_PAYLOAD:"%"=%)
1733 else
1734 SPL_PAYLOAD := u-boot.bin
1735 endif
1736
1737 SPL_IMAGE := $(CONFIG_SPL_IMAGE:"%"=%)
1738
1739 OBJCOPYFLAGS_u-boot-with-spl.bin = -I binary -O binary \
1740 --pad-to=$(CONFIG_SPL_PAD_TO)
1741 u-boot-with-spl.bin: $(SPL_IMAGE) $(SPL_PAYLOAD) FORCE
1742 $(call if_changed,pad_cat)
1743
1744 ifeq ($(CONFIG_ARCH_LPC32XX)$(CONFIG_SPL),yy)
1745 MKIMAGEFLAGS_lpc32xx-spl.img = -T lpc32xximage -a $(CONFIG_SPL_TEXT_BASE)
1746
1747 lpc32xx-spl.img: spl/u-boot-spl.bin FORCE
1748 $(call if_changed,mkimage)
1749
1750 OBJCOPYFLAGS_lpc32xx-boot-0.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1751
1752 lpc32xx-boot-0.bin: lpc32xx-spl.img FORCE
1753 $(call if_changed,objcopy)
1754
1755 OBJCOPYFLAGS_lpc32xx-boot-1.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1756
1757 lpc32xx-boot-1.bin: lpc32xx-spl.img FORCE
1758 $(call if_changed,objcopy)
1759
1760 lpc32xx-full.bin: lpc32xx-boot-0.bin lpc32xx-boot-1.bin u-boot.img FORCE
1761 $(call if_changed,cat)
1762
1763 endif
1764
1765 OBJCOPYFLAGS_u-boot-with-tpl.bin = -I binary -O binary \
1766 --pad-to=$(CONFIG_TPL_PAD_TO)
1767 tpl/u-boot-with-tpl.bin: tpl/u-boot-tpl.bin u-boot.bin FORCE
1768 $(call if_changed,pad_cat)
1769
1770 SPL: spl/u-boot-spl.bin FORCE
1771 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1772
1773 #ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y)
1774 ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y)
1775 u-boot.cnt: u-boot.bin FORCE
1776 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1777
1778 flash.bin: spl/u-boot-spl.bin u-boot.cnt FORCE
1779 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1780 else
1781 ifeq ($(CONFIG_BINMAN),y)
1782 flash.bin: spl/u-boot-spl.bin $(INPUTS-y) FORCE
1783 $(call if_changed,binman)
1784 else
1785 flash.bin: spl/u-boot-spl.bin u-boot.itb FORCE
1786 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1787 endif
1788 endif
1789 #endif
1790
1791 u-boot.uim: u-boot.bin FORCE
1792 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1793
1794 u-boot-nand.imx: u-boot.imx FORCE
1795 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1796
1797 u-boot-with-spl.imx u-boot-with-nand-spl.imx: SPL $(if $(CONFIG_OF_SEPARATE),u-boot.img,u-boot.uim) FORCE
1798 $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
1799
1800 MKIMAGEFLAGS_u-boot.ubl = -n $(UBL_CONFIG) -T ublimage -e $(CONFIG_TEXT_BASE)
1801
1802 u-boot.ubl: u-boot-with-spl.bin FORCE
1803 $(call if_changed,mkimage)
1804
1805 MKIMAGEFLAGS_u-boot-spl.ais = -s -n "/dev/null" \
1806 -T aisimage -e $(CONFIG_SPL_TEXT_BASE)
1807 spl/u-boot-spl.ais: spl/u-boot-spl.bin FORCE
1808 $(call if_changed,mkimage)
1809
1810 OBJCOPYFLAGS_u-boot.ais = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO)
1811 u-boot.ais: spl/u-boot-spl.ais u-boot.img FORCE
1812 $(call if_changed,pad_cat)
1813
1814 u-boot-signed.sb: u-boot.bin spl/u-boot-spl.bin
1815 $(Q)$(MAKE) $(build)=arch/arm/cpu/arm926ejs/mxs u-boot-signed.sb
1816 u-boot.sb: u-boot.bin spl/u-boot-spl.bin
1817 $(Q)$(MAKE) $(build)=arch/arm/cpu/arm926ejs/mxs u-boot.sb
1818
1819 MKIMAGEFLAGS_u-boot-spl.img = -A $(ARCH) -T firmware -C none \
1820 -a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) -n XLOADER
1821 spl/u-boot-spl.img: spl/u-boot-spl.bin FORCE
1822 $(call if_changed,mkimage)
1823
1824 ifneq ($(CONFIG_ARCH_SOCFPGA),)
1825 quiet_cmd_gensplx4 = GENSPLX4 $@
1826 cmd_gensplx4 = $(OBJCOPY) -I binary -O binary --gap-fill=0x0 \
1827 --pad-to=$(CONFIG_SPL_PAD_TO) \
1828 spl/u-boot-spl.sfp spl/u-boot-spl.sfp && \
1829 cat spl/u-boot-spl.sfp spl/u-boot-spl.sfp \
1830 spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || { rm -f $@; false; }
1831 spl/u-boot-splx4.sfp: spl/u-boot-spl.sfp FORCE
1832 $(call if_changed,gensplx4)
1833
1834 quiet_cmd_socboot = SOCBOOT $@
1835 cmd_socboot = cat spl/u-boot-splx4.sfp u-boot.img > $@ || { rm -f $@; false; }
1836 u-boot-with-spl.sfp: spl/u-boot-splx4.sfp u-boot.img FORCE
1837 $(call if_changed,socboot)
1838
1839 quiet_cmd_gensplpadx4 = GENSPLPADX4 $@
1840 cmd_gensplpadx4 = dd if=/dev/zero of=spl/u-boot-spl.pad bs=64 count=1024 ; \
1841 cat spl/u-boot-spl.sfp spl/u-boot-spl.pad \
1842 spl/u-boot-spl.sfp spl/u-boot-spl.pad \
1843 spl/u-boot-spl.sfp spl/u-boot-spl.pad \
1844 spl/u-boot-spl.sfp spl/u-boot-spl.pad > $@ || \
1845 { rm -f $@ spl/u-boot-spl.pad; false; }
1846 u-boot-spl-padx4.sfp: spl/u-boot-spl.sfp FORCE
1847 $(call if_changed,gensplpadx4)
1848
1849 quiet_cmd_socnandboot = SOCNANDBOOT $@
1850 cmd_socnandboot = cat u-boot-spl-padx4.sfp u-boot.img > $@ || { rm -f $@; false; }
1851 u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
1852 $(call if_changed,socnandboot)
1853
1854 endif
1855
1856 ifeq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
1857 u-boot-dtb.bin: u-boot-nodtb.bin u-boot.dtb u-boot-br.bin FORCE
1858 $(call if_changed,binman)
1859
1860 OBJCOPYFLAGS_u-boot-br.bin := -O binary -j .bootpg -j .resetvec
1861 u-boot-br.bin: u-boot FORCE
1862 $(call if_changed,objcopy)
1863 endif
1864
1865 quiet_cmd_ldr = LD $@
1866 cmd_ldr = $(LD) $(LDFLAGS_$(@F)) \
1867 $(filter-out FORCE,$^) -o $@
1868
1869 ifdef CONFIG_X86
1870 OBJCOPYFLAGS_u-boot-x86-start16.bin := -O binary -j .start16
1871 u-boot-x86-start16.bin: u-boot FORCE
1872 $(call if_changed,objcopy)
1873
1874 OBJCOPYFLAGS_u-boot-x86-reset16.bin := -O binary -j .resetvec
1875 u-boot-x86-reset16.bin: u-boot FORCE
1876 $(call if_changed,objcopy)
1877
1878 endif # CONFIG_X86
1879
1880 OBJCOPYFLAGS_u-boot-app.efi := $(OBJCOPYFLAGS_EFI)
1881 u-boot-app.efi: u-boot FORCE
1882 $(call if_changed,zobjcopy)
1883
1884 u-boot.bin.o: u-boot.bin FORCE
1885 $(call if_changed,efipayload)
1886
1887 u-boot-payload.lds: $(LDSCRIPT_EFI) FORCE
1888 $(call if_changed_dep,cpp_lds)
1889
1890 # Rule to link the EFI payload which contains a stub and a U-Boot binary
1891 quiet_cmd_u-boot_payload ?= LD $@
1892 cmd_u-boot_payload ?= $(LD) $(LDFLAGS_EFI_PAYLOAD) -o $@ \
1893 -T u-boot-payload.lds arch/x86/cpu/call32.o \
1894 lib/efi_client/efi.o lib/efi_client/efi_stub.o u-boot.bin.o \
1895 $(addprefix arch/$(ARCH)/lib/,$(EFISTUB))
1896
1897 u-boot-payload: u-boot.bin.o u-boot-payload.lds FORCE
1898 $(call if_changed,u-boot_payload)
1899
1900 OBJCOPYFLAGS_u-boot-payload.efi := $(OBJCOPYFLAGS_EFI)
1901 u-boot-payload.efi: u-boot-payload FORCE
1902 $(call if_changed,zobjcopy)
1903
1904 u-boot-img.bin: spl/u-boot-spl.bin u-boot.img FORCE
1905 $(call if_changed,cat)
1906
1907 #Add a target to create boot binary having SPL binary in PBI format
1908 #concatenated with u-boot binary. It is need by PowerPC SoC having
1909 #internal SRAM <= 512KB.
1910 MKIMAGEFLAGS_u-boot-spl.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
1911 -R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -T pblimage \
1912 -A $(ARCH) -a $(CONFIG_SPL_TEXT_BASE)
1913
1914 spl/u-boot-spl.pbl: spl/u-boot-spl.bin FORCE
1915 $(call if_changed,mkimage)
1916
1917 ifeq ($(ARCH),arm)
1918 UBOOT_BINLOAD := u-boot.img
1919 else
1920 UBOOT_BINLOAD := u-boot.bin
1921 endif
1922
1923 OBJCOPYFLAGS_u-boot-with-spl-pbl.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
1924 --gap-fill=0xff
1925
1926 u-boot-with-spl-pbl.bin: spl/u-boot-spl.pbl $(UBOOT_BINLOAD) FORCE
1927 $(call if_changed,pad_cat)
1928
1929 quiet_cmd_u-boot-elf ?= LD $@
1930 cmd_u-boot-elf ?= $(LD) u-boot-elf.o -o $@ \
1931 $(if $(CONFIG_SYS_BIG_ENDIAN),-EB,-EL) \
1932 -T u-boot-elf.lds --defsym=$(CONFIG_PLATFORM_ELFENTRY)=$(CONFIG_TEXT_BASE) \
1933 -Ttext=$(CONFIG_TEXT_BASE)
1934 u-boot.elf: u-boot.bin u-boot-elf.lds
1935 $(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o
1936 $(call if_changed,u-boot-elf)
1937
1938 u-boot-elf.lds: arch/u-boot-elf.lds prepare FORCE
1939 $(call if_changed_dep,cpp_lds)
1940
1941 PHONY += prepare0
1942 # MediaTek's ARM-based u-boot needs a header to contains its load address
1943 # which is parsed by the BootROM.
1944 # If the SPL build is enabled, the header will be added to the spl binary,
1945 # and the spl binary and the u-boot.img will be combined into one file.
1946 # Otherwise the header will be added to the u-boot.bin directly.
1947
1948 ifeq ($(CONFIG_SPL),y)
1949 spl/u-boot-spl-mtk.bin: spl/u-boot-spl
1950
1951 u-boot-mtk.bin: u-boot-with-spl.bin
1952 $(call if_changed,copy)
1953 else
1954 MKIMAGEFLAGS_u-boot-mtk.bin = -T mtk_image \
1955 -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE) \
1956 -n "$(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO))"
1957
1958 u-boot-mtk.bin: u-boot.bin FORCE
1959 $(call if_changed,mkimage)
1960 endif
1961
1962 quiet_cmd_endian_swap = SWAP $@
1963 cmd_endian_swap = $(srctree)/tools/endian-swap.py $< $@
1964
1965 u-boot-swap.bin: u-boot.bin FORCE
1966 $(call if_changed,endian_swap)
1967
1968 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink)
1969
1970 # Generate linker list symbols references to force compiler to not optimize
1971 # them away when compiling with LTO
1972 ifeq ($(LTO_ENABLE),y)
1973 u-boot-keep-syms-lto := keep-syms-lto.o
1974 u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto))
1975
1976 quiet_cmd_keep_syms_lto = KSL $@
1977 cmd_keep_syms_lto = \
1978 $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@
1979
1980 quiet_cmd_keep_syms_lto_cc = KSLCC $@
1981 cmd_keep_syms_lto_cc = \
1982 $(CC) $(filter-out $(LTO_CFLAGS),$(c_flags)) -c -o $@ $<
1983
1984 $(u-boot-keep-syms-lto_c): $(u-boot-main)
1985 $(call if_changed,keep_syms_lto)
1986 $(u-boot-keep-syms-lto): $(u-boot-keep-syms-lto_c)
1987 $(call if_changed,keep_syms_lto_cc)
1988 else
1989 u-boot-keep-syms-lto :=
1990 endif
1991
1992 # Rule to link u-boot
1993 # May be overridden by arch/$(ARCH)/config.mk
1994 ifeq ($(LTO_ENABLE),y)
1995 quiet_cmd_u-boot__ ?= LTO $@
1996 cmd_u-boot__ ?= \
1997 touch $(u-boot-main) ; \
1998 $(CC) -nostdlib -nostartfiles \
1999 $(LTO_FINAL_LDFLAGS) $(c_flags) \
2000 $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_u-boot:%=-Wl,%) -o $@ \
2001 -T u-boot.lds $(u-boot-init) \
2002 -Wl,--whole-archive \
2003 $(u-boot-main) \
2004 $(u-boot-keep-syms-lto) \
2005 $(PLATFORM_LIBS) \
2006 -Wl,--no-whole-archive \
2007 -Wl,-Map,u-boot.map; \
2008 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
2009 else
2010 quiet_cmd_u-boot__ ?= LD $@
2011 cmd_u-boot__ ?= \
2012 touch $(u-boot-main) ; \
2013 $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
2014 -T u-boot.lds $(u-boot-init) \
2015 --whole-archive \
2016 $(u-boot-main) \
2017 --no-whole-archive \
2018 $(PLATFORM_LIBS) -Map u-boot.map; \
2019 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
2020 endif
2021
2022 quiet_cmd_smap = GEN common/system_map.o
2023 cmd_smap = \
2024 smap=`$(call SYSTEM_MAP,u-boot) | \
2025 awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
2026 $(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
2027 -c $(srctree)/common/system_map.c -o common/system_map.o
2028
2029 u-boot: $(u-boot-init) $(u-boot-main) $(u-boot-keep-syms-lto) u-boot.lds FORCE
2030 +$(call if_changed,u-boot__)
2031 ifeq ($(CONFIG_KALLSYMS),y)
2032 $(call cmd,smap)
2033 $(call cmd,u-boot__) common/system_map.o
2034 endif
2035
2036 ifeq ($(CONFIG_RISCV),y)
2037 @tools/prelink-riscv $@
2038 endif
2039
2040 quiet_cmd_sym ?= SYM $@
2041 cmd_sym ?= $(OBJDUMP) -t $< > $@
2042 u-boot.sym: u-boot FORCE
2043 $(call if_changed,sym)
2044
2045 # Environment processing
2046 # ---------------------------------------------------------------------------
2047
2048 # Directory where we expect the .env file, if it exists
2049 ENV_DIR := $(srctree)/board/$(BOARDDIR)
2050
2051 # Basename of .env file, stripping quotes
2052 ENV_SOURCE_FILE := $(CONFIG_ENV_SOURCE_FILE:"%"=%)
2053
2054 # Filename of .env file
2055 ENV_FILE_CFG := $(ENV_DIR)/$(ENV_SOURCE_FILE).env
2056
2057 # Default filename, if CONFIG_ENV_SOURCE_FILE is empty
2058 ENV_FILE_BOARD := $(ENV_DIR)/$(CONFIG_SYS_BOARD:"%"=%).env
2059
2060 # Select between the CONFIG_ENV_SOURCE_FILE and the default one
2061 ENV_FILE := $(if $(ENV_SOURCE_FILE),$(ENV_FILE_CFG),$(wildcard $(ENV_FILE_BOARD)))
2062
2063 # Run the environment text file through the preprocessor, but only if it is
2064 # non-empty, to save time and possible build errors if something is wonky with
2065 # the board.
2066 # If there is no ENV_FILE, produce an empty output file, to prevent a previous
2067 # build's file being used in the case of in-tree builds.
2068 quiet_cmd_gen_envp = ENVP $@
2069 cmd_gen_envp = \
2070 if [ -s "$(ENV_FILE)" ]; then \
2071 $(CPP) -P $(cpp_flags) -x assembler-with-cpp -undef \
2072 -D__ASSEMBLY__ \
2073 -D__UBOOT_CONFIG__ \
2074 -DDEFAULT_DEVICE_TREE=$(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE)) \
2075 -I . -I include -I $(srctree)/include \
2076 -include linux/kconfig.h -include include/config.h \
2077 -I$(srctree)/arch/$(ARCH)/include \
2078 $< -o $@; \
2079 else \
2080 rm -f $@; \
2081 touch $@ ; \
2082 fi
2083 include/generated/env.in: include/generated/env.txt
2084 $(call cmd,gen_envp)
2085
2086 # Regenerate the environment if it changes
2087 # We use 'wildcard' since the file is not required to exist (at present), in
2088 # which case we don't want this dependency, but instead should create an empty
2089 # file
2090 # This rule is useful since it shows the source file for the environment
2091 quiet_cmd_envc = ENVC $@
2092 cmd_envc = \
2093 if [ -f "$<" ]; then \
2094 cat $< > $@; \
2095 elif [ -n "$(ENV_SOURCE_FILE)" ]; then \
2096 echo "Missing file $(ENV_FILE_CFG)"; \
2097 else \
2098 touch $@ ; \
2099 fi
2100
2101 include/generated/env.txt: $(wildcard $(ENV_FILE)) include/generated/autoconf.h
2102 $(call cmd,envc)
2103
2104 # Write out the resulting environment, converted to a C string
2105 quiet_cmd_gen_envt = ENVT $@
2106 cmd_gen_envt = \
2107 awk -f $(srctree)/scripts/env2string.awk $< >$@
2108 $(env_h): include/generated/env.in
2109 $(call cmd,gen_envt)
2110
2111 # ---------------------------------------------------------------------------
2112
2113 # The actual objects are generated when descending,
2114 # make sure no implicit rule kicks in
2115 $(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;
2116
2117 # Handle descending into subdirectories listed in $(u-boot-dirs)
2118 # Preset locale variables to speed up the build process. Limit locale
2119 # tweaks to this spot to avoid wrong language settings when running
2120 # make menuconfig etc.
2121 # Error messages still appears in the original language
2122
2123 PHONY += $(u-boot-dirs)
2124 $(u-boot-dirs): prepare
2125 $(Q)$(MAKE) $(build)=$@ need-builtin=1
2126
2127 tools: prepare
2128 # The "tools" are needed early
2129 $(filter-out tools, $(u-boot-dirs)): tools
2130 # The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
2131 # is "yes"), so compile examples after U-Boot is compiled.
2132 examples: $(filter-out examples, $(u-boot-dirs))
2133
2134 ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
2135 # lib/efi_loader apps depend on arch/$(ARCH)/lib for lib.a
2136 lib: $(filter arch/$(ARCH)/lib, $(u-boot-dirs))
2137 endif
2138
2139 # The setlocalversion script comes from linux and expects a
2140 # KERNELVERSION variable in the environment for figuring out which
2141 # annotated tags are relevant. Pass UBOOTVERSION.
2142 define filechk_uboot.release
2143 KERNELVERSION=$(UBOOTVERSION) $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree)
2144 endef
2145
2146 # Store (new) UBOOTRELEASE string in include/config/uboot.release
2147 include/config/uboot.release: include/config/auto.conf FORCE
2148 $(call filechk,uboot.release)
2149 # Additional helpers built in scripts/
2150 # Carefully list dependencies so we do not try to build scripts twice
2151 # in parallel
2152 PHONY += scripts
2153 scripts: scripts_basic scripts_dtc
2154 $(Q)$(MAKE) $(build)=$(@)
2155
2156 # Things we need to do before we recursively start building the kernel
2157 # or the modules are listed in "prepare".
2158 # A multi level approach is used. prepareN is processed before prepareN-1.
2159 # archprepare is used in arch Makefiles and when processed asm symlink,
2160 # version.h and scripts_basic is processed / created.
2161
2162 PHONY += prepare archprepare prepare1 prepare3
2163
2164 # prepare3 is used to check if we are building in a separate output directory,
2165 # and if so do:
2166 # 1) Check that make has not been executed in the kernel src $(srctree)
2167 prepare3: include/config/uboot.release
2168 ifneq ($(KBUILD_SRC),)
2169 @$(kecho) ' Using $(srctree) as source for U-Boot'
2170 $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
2171 echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \
2172 echo >&2 " in the '$(srctree)' directory.";\
2173 /bin/false; \
2174 fi;
2175 endif
2176
2177 prepare1: prepare3 outputmakefile cfg $(version_h) $(timestamp_h) $(dt_h) $(env_h) \
2178 include/config/auto.conf
2179 ifeq ($(wildcard $(LDSCRIPT)),)
2180 @echo >&2 " Could not find linker script."
2181 @/bin/false
2182 endif
2183
2184 ifeq ($(CONFIG_ENV_USE_DEFAULT_ENV_TEXT_FILE),y)
2185 prepare1: $(defaultenv_h)
2186
2187 envtools: $(defaultenv_h)
2188 endif
2189 archprepare: prepare1 scripts
2190
2191 prepare0: archprepare
2192 $(Q)$(MAKE) $(build)=.
2193
2194 # All the preparing..
2195 prepare: prepare0 prepare-objtool
2196
2197 # Support for using generic headers in asm-generic
2198 asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
2199
2200 PHONY += asm-generic uapi-asm-generic
2201 asm-generic: uapi-asm-generic
2202 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
2203 generic=include/asm-generic
2204 uapi-asm-generic:
2205 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
2206 generic=include/uapi/asm-generic
2207
2208 PHONY += prepare-objtool
2209 prepare-objtool: $(objtool_target)
2210 ifeq ($(SKIP_STACK_VALIDATION),1)
2211 ifdef CONFIG_UNWINDER_ORC
2212 @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
2213 @false
2214 else
2215 @echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
2216 endif
2217 endif
2218
2219 # Generate some files
2220 # ---------------------------------------------------------------------------
2221
2222 # Use sed to remove leading zeros from PATCHLEVEL to avoid using octal numbers
2223 define filechk_version.h
2224 (echo \#define PLAIN_VERSION \"$(UBOOTRELEASE)\"; \
2225 echo \#define U_BOOT_VERSION \"U-Boot \" PLAIN_VERSION; \
2226 echo \#define U_BOOT_VERSION_NUM $(VERSION); \
2227 echo \#define U_BOOT_VERSION_NUM_PATCH $$(echo $(PATCHLEVEL) | \
2228 sed -e "s/^0*//"); \
2229 echo \#define HOST_ARCH $(HOST_ARCH); \
2230 echo \#define CC_VERSION_STRING \"$$(LC_ALL=C $(CC) --version | head -n 1)\"; \
2231 echo \#define LD_VERSION_STRING \"$$(LC_ALL=C $(LD) --version | head -n 1)\"; )
2232 endef
2233
2234 # The SOURCE_DATE_EPOCH mechanism requires a date that behaves like GNU date.
2235 # The BSD date on the other hand behaves different and would produce errors
2236 # with the misused '-d' switch. Respect that and search a working date with
2237 # well known pre- and suffixes for the GNU variant of date.
2238 define filechk_timestamp.h
2239 (if test -n "$${SOURCE_DATE_EPOCH}"; then \
2240 SOURCE_DATE="@$${SOURCE_DATE_EPOCH}"; \
2241 DATE=""; \
2242 for date in gdate date.gnu date; do \
2243 $${date} -u -d "$${SOURCE_DATE}" >/dev/null 2>&1 && DATE="$${date}"; \
2244 done; \
2245 if test -n "$${DATE}"; then \
2246 LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DATE "%b %d %C%y"'; \
2247 LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TIME "%T"'; \
2248 LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TZ "%z"'; \
2249 LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_EPOCH %s'; \
2250 else \
2251 return 42; \
2252 fi; \
2253 else \
2254 LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"'; \
2255 LC_ALL=C date +'#define U_BOOT_TIME "%T"'; \
2256 LC_ALL=C date +'#define U_BOOT_TZ "%z"'; \
2257 LC_ALL=C date +'#define U_BOOT_EPOCH %s'; \
2258 fi)
2259 endef
2260
2261 define filechk_defaultenv.h
2262 ( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \
2263 tr '\n' '\0' | \
2264 sed -e 's/\\\x0\s*//g' | \
2265 xxd -i ; )
2266 endef
2267
2268 define filechk_dt.h
2269 (if test -n "$${DEVICE_TREE}"; then \
2270 echo \#define DEVICE_TREE \"$(DEVICE_TREE)\"; \
2271 else \
2272 echo \#define DEVICE_TREE CONFIG_DEFAULT_DEVICE_TREE; \
2273 fi)
2274 endef
2275
2276 $(version_h): include/config/uboot.release FORCE
2277 $(call filechk,version.h)
2278
2279 $(timestamp_h): $(srctree)/Makefile FORCE
2280 $(call filechk,timestamp.h)
2281
2282 $(dt_h): $(srctree)/Makefile FORCE
2283 $(call filechk,dt.h)
2284
2285 $(defaultenv_h): $(CONFIG_ENV_DEFAULT_ENV_TEXT_FILE:"%"=%) FORCE
2286 $(call filechk,defaultenv.h)
2287
2288 # ---------------------------------------------------------------------------
2289 # Devicetree files
2290
2291 ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
2292 dtstree := arch/$(SRCARCH)/boot/dts
2293 endif
2294
2295 ifneq ($(dtstree),)
2296
2297 %.dtb: prepare3 scripts_dtc
2298 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
2299
2300 PHONY += dtbs dtbs_install dt_binding_check
2301 dtbs dtbs_check: prepare3 scripts_dtc
2302 $(Q)$(MAKE) $(build)=$(dtstree)
2303
2304 dtbs_check: export CHECK_DTBS=1
2305 dtbs_check: dt_binding_check
2306
2307 dtbs_install:
2308 $(Q)$(MAKE) $(dtbinst)=$(dtstree)
2309
2310 ifdef CONFIG_OF_EARLY_FLATTREE
2311 all: dtbs
2312 endif
2313
2314 endif
2315
2316 # Check dtc and pylibfdt, if DTC is provided, else build them
2317 PHONY += scripts_dtc
2318 scripts_dtc: scripts_basic
2319 $(Q)if test "$(DTC)" = "$(DTC_INTREE)"; then \
2320 $(MAKE) $(build)=scripts/dtc; \
2321 else \
2322 if ! $(DTC) -v >/dev/null; then \
2323 echo '*** Failed to check dtc version: $(DTC)'; \
2324 false; \
2325 else \
2326 if test "$(call dtc-version)" -lt $(DTC_MIN_VERSION); then \
2327 echo '*** Your dtc is too old, please upgrade to dtc $(DTC_MIN_VERSION) or newer'; \
2328 false; \
2329 else \
2330 if [ -n "$(CONFIG_PYLIBFDT)" ]; then \
2331 if ! echo "import libfdt" | $(PYTHON3) 2>/dev/null; then \
2332 echo '*** pylibfdt does not seem to be available with $(PYTHON3)'; \
2333 false; \
2334 fi; \
2335 fi; \
2336 fi; \
2337 fi; \
2338 fi
2339
2340 # ---------------------------------------------------------------------------
2341 quiet_cmd_cpp_lds = LDS $@
2342 cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \
2343 -D__ASSEMBLY__ -x assembler-with-cpp -std=c99 -P -o $@ $<
2344
2345 u-boot.lds: $(LDSCRIPT) prepare FORCE
2346 $(call if_changed_dep,cpp_lds)
2347
2348 spl/u-boot-spl.bin: spl/u-boot-spl
2349 @:
2350 $(SPL_SIZE_CHECK)
2351
2352 spl/u-boot-spl-dtb.bin: spl/u-boot-spl
2353 @:
2354
2355 spl/u-boot-spl-dtb.hex: spl/u-boot-spl
2356 @:
2357
2358 spl/u-boot-spl: tools prepare $(if $(CONFIG_SPL_OF_CONTROL),dts/dt.dtb)
2359 $(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.xpl all
2360
2361 spl/sunxi-spl.bin: spl/u-boot-spl
2362 @:
2363
2364 spl/sunxi-spl-with-ecc.bin: spl/sunxi-spl.bin
2365 @:
2366
2367 spl/u-boot-spl.sfp: spl/u-boot-spl
2368 @:
2369
2370 spl/boot.bin: spl/u-boot-spl
2371 @:
2372
2373 tpl/u-boot-tpl.bin: tpl/u-boot-tpl
2374 @:
2375 $(TPL_SIZE_CHECK)
2376
2377 tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
2378 $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.xpl all
2379
2380 vpl/u-boot-vpl.bin: vpl/u-boot-vpl
2381 @:
2382 $(VPL_SIZE_CHECK)
2383
2384 vpl/u-boot-vpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
2385 $(Q)$(MAKE) obj=vpl -f $(srctree)/scripts/Makefile.xpl all
2386
2387 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
2388
2389 FIND := find
2390 FINDFLAGS := -L
2391
2392 tags ctags:
2393 ctags -w -o ctags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
2394 -name '*.[chS]' -print`
2395 ln -s ctags tags
2396
2397 etags:
2398 etags -a -o etags `$(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) \
2399 -name '*.[chS]' -print`
2400 cscope:
2401 $(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \
2402 cscope.files
2403 @find $(TAG_SUBDIRS) -name '*.[chS]' -type l -print | \
2404 grep -xvf - cscope.files > cscope.files.no-symlinks; \
2405 mv cscope.files.no-symlinks cscope.files
2406 cscope -b -q -k
2407
2408 SYSTEM_MAP = \
2409 $(NM) $1 | \
2410 grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
2411 LC_ALL=C sort
2412 System.map: u-boot
2413 @$(call SYSTEM_MAP,$<) > $@
2414
2415 # ARM relocations should all be R_ARM_RELATIVE (32-bit) or
2416 # R_AARCH64_RELATIVE (64-bit).
2417 checkarmreloc: u-boot
2418 @RELOC="`$(READELF) -r -W $< | cut -d ' ' -f 4 | \
2419 grep R_A | sort -u`"; \
2420 if test "$$RELOC" != "R_ARM_RELATIVE" -a \
2421 "$$RELOC" != "R_AARCH64_RELATIVE"; then \
2422 echo "$< contains unexpected relocations: $$RELOC"; \
2423 false; \
2424 fi
2425
2426 tools/version.h: include/version.h
2427 $(Q)mkdir -p $(dir $@)
2428 $(call if_changed,copy)
2429
2430 envtools: u-boot-initial-env scripts_basic $(version_h) $(timestamp_h) tools/version.h
2431 $(Q)$(MAKE) $(build)=tools/env
2432
2433 tools-only: export TOOLS_ONLY=y
2434 tools-only: scripts_basic $(version_h) $(timestamp_h) tools/version.h
2435 $(Q)$(MAKE) $(build)=tools
2436
2437 tools-all: export HOST_TOOLS_ALL=y
2438 tools-all: envtools tools ;
2439
2440 cross_tools: export CROSS_BUILD_TOOLS=y
2441 cross_tools: tools ;
2442
2443 .PHONY : CHANGELOG
2444 CHANGELOG:
2445 git log --no-merges U-Boot-1_1_5.. | \
2446 unexpand -a | sed -e 's/\s\s*$$//' > $@
2447
2448 #########################################################################
2449
2450 ###
2451 # Cleaning is done on three levels.
2452 # make clean Delete most generated files
2453 # Leave enough to build external modules
2454 # make mrproper Delete the current configuration, and all generated files
2455 # make distclean Remove editor backup files, patch leftover files and the like
2456
2457 # Directories & files removed with 'make clean'
2458 CLEAN_DIRS += $(MODVERDIR) \
2459 $(foreach d, spl tpl vpl, $(patsubst %,$d/%, \
2460 $(filter-out include, $(shell ls -1 $d 2>/dev/null))))
2461
2462 CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h include/bmp_logo_data.h \
2463 include/config.h include/generated/env.* drivers/video/u_boot_logo.S \
2464 tools/version.h u-boot* MLO* SPL System.map fit-dtb.blob* \
2465 u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
2466 lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
2467 idbloader.img flash.bin flash.log defconfig keep-syms-lto.c \
2468 mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
2469 itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
2470 mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
2471 idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
2472 Test* capsule*.*.efi-capsule capsule*.map mkimage.imx-boot.spl \
2473 mkimage.imx-boot.u-boot mkimage-out.imx-boot.spl mkimage-out.imx-boot.u-boot \
2474 imx9image* m33-oei-ddrfw*
2475
2476 # Directories & files removed with 'make mrproper'
2477 MRPROPER_DIRS += include/config include/generated spl tpl vpl \
2478 .tmp_objdiff doc/output include/asm
2479
2480 # Remove include/asm symlink created by U-Boot before v2014.01
2481 MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
2482 ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
2483 drivers/video/fonts/*.S include/asm *imx8mimage* *imx8mcst*
2484
2485 # clean - Delete most, but leave enough to build external modules
2486 #
2487 clean: rm-dirs := $(CLEAN_DIRS)
2488 clean: rm-files := $(CLEAN_FILES)
2489 clean-dirs := $(foreach f,$(u-boot-alldirs),$(if $(wildcard $(srctree)/$f/Makefile),$f))
2490 clean-dirs := $(addprefix _clean_, $(clean-dirs))
2491
2492 PHONY += $(clean-dirs) clean archclean
2493 $(clean-dirs):
2494 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
2495
2496 clean: $(clean-dirs)
2497 $(call cmd,rmdirs)
2498 $(call cmd,rmfiles)
2499 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
2500 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
2501 -o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \
2502 -o -name '*.dtb' -o -name '*.dtbo' \
2503 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
2504 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
2505 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
2506 -o -name '*.asn1.[ch]' \
2507 -o -name '*.symtypes' -o -name 'modules.order' \
2508 -o -name modules.builtin -o -name '.tmp_*.o.*' \
2509 -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \
2510 -o -name 'dsdt_generated.c' \
2511 -o -name 'generated_defconfig' \
2512 -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \
2513 -type f -print | xargs rm -f
2514
2515 # mrproper - Delete all generated files, including .config
2516 #
2517 mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
2518 mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
2519 mrproper-dirs := $(addprefix _mrproper_,scripts)
2520
2521 PHONY += $(mrproper-dirs) mrproper
2522 $(mrproper-dirs):
2523 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
2524
2525 mrproper: clean $(mrproper-dirs)
2526 $(call cmd,rmdirs)
2527 $(call cmd,rmfiles)
2528 @rm -f arch/*/include/asm/arch
2529
2530 # distclean
2531 #
2532 PHONY += distclean
2533
2534 distclean: mrproper
2535 @find $(srctree) $(RCS_FIND_IGNORE) \
2536 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
2537 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
2538 -o -name '.*.rej' -o -name '*%' -o -name 'core' \
2539 -o -name '*.pyc' \) \
2540 -type f -print | xargs rm -f
2541 @rm -f boards.cfg CHANGELOG .binman_stamp
2542
2543 # See doc/develop/python_cq.rst
2544 PHONY += pylint pylint_err
2545 PYLINT_BASE := scripts/pylint.base
2546 PYLINT_CUR := pylint.cur
2547 PYLINT_DIFF := pylint.diff
2548 pylint:
2549 $(Q)echo "Running pylint on all files (summary in $(PYLINT_CUR); output in pylint.out/)"
2550 $(Q)mkdir -p pylint.out
2551 $(Q)rm -f pylint.out/out*
2552 $(Q)find tools test -name "*.py" \
2553 | xargs -n1 -P$(shell nproc 2>/dev/null || echo 1) \
2554 sh -c 'pylint --reports=y --exit-zero -f parseable --ignore-imports=yes $$@ > pylint.out/$$(echo $$@ | tr / _ | sed s/.py//)' _
2555 $(Q)rm -f $(PYLINT_CUR)
2556 $(Q)( cd pylint.out; for f in *; do \
2557 sed -ne "s/Your code has been rated at \([-0-9.]*\).*/$$f \1/p" $$f; \
2558 done ) | sort > $(PYLINT_CUR)
2559 $(Q)base=$$(mktemp) cur=$$(mktemp); cut -d' ' -f1 $(PYLINT_BASE) >$$base; \
2560 cut -d' ' -f1 $(PYLINT_CUR) >$$cur; \
2561 comm -3 $$base $$cur > $(PYLINT_DIFF); \
2562 if [ -s $(PYLINT_DIFF) ]; then \
2563 echo "Files have been added/removed. Try:\n\tcp $(PYLINT_CUR) $(PYLINT_BASE)"; \
2564 echo; \
2565 echo "Added files:"; \
2566 comm -13 $$base $$cur; \
2567 echo; \
2568 echo "Removed files:"; \
2569 comm -23 $$base $$cur; \
2570 false; \
2571 else \
2572 rm $$base $$cur $(PYLINT_DIFF); \
2573 fi
2574 $(Q)bad=false; while read base_file base_val <&3 && read cur_file cur_val <&4; do \
2575 if awk "BEGIN {exit !($$cur_val < $$base_val)}"; then \
2576 echo "$$base_file: Score was $$base_val, now $$cur_val"; \
2577 bad=true; fi; \
2578 done 3<$(PYLINT_BASE) 4<$(PYLINT_CUR); \
2579 if $$bad; then \
2580 echo "Some files have regressed, please fix"; \
2581 false; \
2582 else \
2583 echo "No pylint regressions"; \
2584 fi
2585
2586 # Check for errors only
2587 pylint_err:
2588 $(Q)pylint -E -j 0 --ignore-imports=yes \
2589 $(shell find tools test -name "*.py")
2590
2591 backup:
2592 F=`basename $(srctree)` ; cd .. ; \
2593 gtar --force-local -zcvf `LC_ALL=C date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
2594
2595 PHONY += _pip pip pip_release
2596
2597 pip_release: PIP_ARGS="--real"
2598 pip_test: PIP_ARGS=""
2599 pip: PIP_ARGS="-n"
2600
2601 pip pip_test pip_release: _pip
2602
2603 _pip:
2604 scripts/make_pip.sh u_boot_pylib ${PIP_ARGS}
2605 scripts/make_pip.sh patman ${PIP_ARGS}
2606 scripts/make_pip.sh buildman ${PIP_ARGS}
2607 scripts/make_pip.sh dtoc ${PIP_ARGS}
2608 scripts/make_pip.sh binman ${PIP_ARGS}
2609
2610 help:
2611 @echo 'Cleaning targets:'
2612 @echo ' clean - Remove most generated files but keep the config'
2613 @echo ' mrproper - Remove all generated files + config + various backup files'
2614 @echo ' distclean - mrproper + remove editor backup and patch files'
2615 @echo ''
2616 @echo 'Configuration targets:'
2617 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
2618 @echo ''
2619 @echo 'Test targets:'
2620 @echo ''
2621 @echo ' check - Run all automated tests that use sandbox'
2622 @echo ' pcheck - Run quick automated tests in parallel'
2623 @echo ' qcheck - Run quick automated tests that use sandbox'
2624 @echo ' tcheck - Run quick automated tests on tools'
2625 @echo ' pylint - Run pylint on all Python files'
2626 @echo ''
2627 @echo 'Other generic targets:'
2628 @echo ' all - Build all necessary images depending on configuration'
2629 @echo ' tests - Build U-Boot for sandbox and run tests'
2630 @echo '* u-boot - Build the bare u-boot'
2631 @echo ' dir/ - Build all files in dir and below'
2632 @echo ' dir/file.[oisS] - Build specified target only'
2633 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
2634 @echo ' (requires a recent binutils and recent build (System.map))'
2635 @echo ' tags/ctags - Generate ctags file for editors'
2636 @echo ' etags - Generate etags file for editors'
2637 @echo ' cscope - Generate cscope index'
2638 @echo ' ubootrelease - Output the release version string (use with make -s)'
2639 @echo ' ubootversion - Output the version stored in Makefile (use with make -s)'
2640 @echo " cfg - Don't build, just create the .cfg files"
2641 @echo " envtools - Build only the target-side environment tools"
2642 @echo ''
2643 @echo 'PyPi / pip targets:'
2644 @echo ' pip - Check building of PyPi packages'
2645 @echo ' pip_test - Build PyPi pakages and upload to test server'
2646 @echo ' pip_release - Build PyPi pakages and upload to release server'
2647 @echo ''
2648 @echo 'Static analysers'
2649 @echo ' checkstack - Generate a list of stack hogs'
2650 @echo ' coccicheck - Execute static code analysis with Coccinelle'
2651 @echo ''
2652 @echo 'Documentation targets:'
2653 @$(MAKE) -f $(srctree)/doc/Makefile dochelp
2654 @echo ''
2655 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
2656 @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
2657 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
2658 @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)'
2659 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
2660 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
2661 @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where'
2662 @echo ' 1: warnings which may be relevant and do not occur too often'
2663 @echo ' 2: warnings which occur quite often but may still be relevant'
2664 @echo ' 3: more obscure warnings, can most likely be ignored'
2665 @echo ' Multiple levels can be combined with W=12 or W=123'
2666 @echo ''
2667 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
2668 @echo 'For further info see the ./README file'
2669
2670 ifneq ($(filter tests pcheck qcheck tcheck,$(MAKECMDGOALS)),)
2671 export sub_make_done := 0
2672 endif
2673
2674 tests check:
2675 $(srctree)/test/run
2676
2677 pcheck:
2678 $(srctree)/test/run parallel
2679
2680 qcheck:
2681 $(srctree)/test/run quick
2682
2683 tcheck:
2684 $(srctree)/test/run tools
2685
2686 # Documentation targets
2687 # ---------------------------------------------------------------------------
2688 DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
2689 linkcheckdocs dochelp refcheckdocs texinfodocs infodocs
2690 PHONY += $(DOC_TARGETS)
2691 $(DOC_TARGETS): scripts_basic FORCE
2692 $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \
2693 $(MAKE) $(build)=doc $@
2694
2695 PHONY += checkstack ubootrelease ubootversion
2696
2697 checkstack:
2698 $(OBJDUMP) -d u-boot $$(find . -name u-boot-spl) | \
2699 $(PERL) $(src)/scripts/checkstack.pl $(ARCH)
2700
2701 ubootversion:
2702 @echo $(UBOOTVERSION)
2703
2704 ubootrelease:
2705 @$(filechk_uboot.release)
2706
2707 # Clear a bunch of variables before executing the submake
2708
2709 ifeq ($(quiet),silent_)
2710 tools_silent=s
2711 endif
2712
2713 tools/: FORCE
2714 $(Q)mkdir -p $(objtree)/tools
2715 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/
2716
2717 tools/%: FORCE
2718 $(Q)mkdir -p $(objtree)/tools
2719 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ $*
2720
2721 # Single targets
2722 # ---------------------------------------------------------------------------
2723 # Single targets are compatible with:
2724 # - build with mixed source and output
2725 # - build with separate output dir 'make O=...'
2726 # - external modules
2727 #
2728 # target-dir => where to store outputfile
2729 # build-dir => directory in kernel source tree to use
2730
2731 build-target = $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD)/)$@
2732 build-dir = $(patsubst %/,%,$(dir $(build-target)))
2733
2734 %.i: prepare FORCE
2735 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2736 %.ll: prepare FORCE
2737 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2738 %.lst: prepare FORCE
2739 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2740 %.o: prepare FORCE
2741 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2742 %.s: prepare FORCE
2743 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2744 %.symtypes: prepare FORCE
2745 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
2746 %.ko: %.o
2747 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
2748
2749 # Modules
2750 PHONY += /
2751 /: ./
2752
2753 # Make sure the latest headers are built for Documentation
2754 Documentation/ samples/: headers_install
2755 %/: prepare FORCE
2756 $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir)
2757
2758 quiet_cmd_genenv = GENENV $@
2759 cmd_genenv = \
2760 $(objtree)/tools/printinitialenv | \
2761 sed -e '/^\s*$$/d' | \
2762 sort -t '=' -k 1,1 -s -o $@
2763
2764 u-boot-initial-env: scripts_basic $(version_h) $(env_h) include/config.h FORCE
2765 $(Q)$(MAKE) $(build)=tools $(objtree)/tools/printinitialenv
2766 $(call if_changed,genenv)
2767
2768 # Consistency checks
2769 # ---------------------------------------------------------------------------
2770
2771 PHONY += coccicheck
2772
2773 coccicheck:
2774 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@
2775
2776 # FIXME Should go into a make.lib or something
2777 # ===========================================================================
2778
2779 quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
2780 cmd_rmdirs = rm -rf $(rm-dirs)
2781
2782 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
2783 cmd_rmfiles = rm -f $(rm-files)
2784
2785 # Run depmod only if we have System.map and depmod is executable
2786 quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
2787 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
2788 $(KERNELRELEASE)
2789
2790 # Create temporary dir for module support files
2791 # clean it up only when building all modules
2792 cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
2793 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
2794
2795 # read saved command lines for existing targets
2796 existing-targets := $(wildcard $(sort $(targets)))
2797
2798 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
2799
2800 endif # ifeq ($(config-targets),1)
2801 endif # ifeq ($(mixed-targets),1)
2802 endif # need-sub-make
2803
2804 PHONY += FORCE
2805 FORCE:
2806
2807 # Declare the contents of the PHONY variable as phony. We keep that
2808 # information in a variable so we can use it in if_changed and friends.
2809 .PHONY: $(PHONY)