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