Merge branch '2021-07-14-build-and-host-updates'
[platform/kernel/u-boot.git] / Makefile
index 5cfbfa9..bc404c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 VERSION = 2021
-PATCHLEVEL = 04
+PATCHLEVEL = 07
 SUBLEVEL =
-EXTRAVERSION = -rc4
+EXTRAVERSION =
 NAME =
 
 # *DOCUMENTATION*
@@ -12,10 +12,9 @@ NAME =
 # Comments in this file are targeted only to the developer, do not
 # expect to learn how to build the kernel reading this file.
 
-# o Do not use make's built-in rules and variables
-#   (this increases performance and avoids hard-to-debug behaviour);
-# o Look for make include files relative to root of kernel src
-MAKEFLAGS += -rR --include-dir=$(CURDIR)
+# Do not use make's built-in rules and variables
+# (this increases performance and avoids hard-to-debug behaviour)
+MAKEFLAGS += -rR
 
 # Determine target architecture for the sandbox
 include include/host_arch.h
@@ -162,6 +161,13 @@ KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
 $(if $(KBUILD_OUTPUT),, \
      $(error failed to create output directory "$(saved-output)"))
 
+# Look for make include files relative to root of kernel src
+#
+# This does not become effective immediately because MAKEFLAGS is re-parsed
+# once after the Makefile is read.  It is OK since we are going to invoke
+# 'sub-make' below.
+MAKEFLAGS += --include-dir=$(CURDIR)
+
 PHONY += $(MAKECMDGOALS) sub-make
 
 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
@@ -328,11 +334,6 @@ HOSTCC       = $(call os_x_before, 10, 5, "cc", "gcc")
 KBUILD_HOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
 KBUILD_HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
 
-# since Lion (10.7) ASLR is on by default, but we use linker generated lists
-# in some host tools which is a problem then ... so disable ASLR for these
-# tools
-KBUILD_HOSTLDFLAGS += $(call os_x_before, 10, 7, "", "-Xlinker -no_pie")
-
 # macOS Mojave (10.14.X) 
 # Undefined symbols for architecture x86_64: "_PyArg_ParseTuple"
 KBUILD_HOSTLDFLAGS += $(call os_x_after, 10, 14, "-lpython -dynamclib", "")
@@ -413,7 +414,7 @@ AWK         = awk
 PERL           = perl
 PYTHON         ?= python
 PYTHON2                = python2
-PYTHON3                = python3
+PYTHON3                ?= python3
 DTC            ?= $(objtree)/scripts/dtc/dtc
 CHECK          = sparse
 
@@ -497,8 +498,7 @@ PHONY += outputmakefile
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
-       $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
-           $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
+       $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
 endif
 
 # To make sure we do not include .config for any of the *config targets
@@ -577,7 +577,7 @@ else
 # Carefully list dependencies so we do not try to build scripts twice
 # in parallel
 PHONY += scripts
-scripts: scripts_basic include/config/auto.conf
+scripts: scripts_basic scripts_dtc include/config/auto.conf
        $(Q)$(MAKE) $(build)=$(@)
 
 ifeq ($(dot-config),1)
@@ -681,12 +681,49 @@ else
 KBUILD_CFLAGS  += -O2
 endif
 
+LTO_CFLAGS :=
+LTO_FINAL_LDFLAGS :=
+export LTO_CFLAGS LTO_FINAL_LDFLAGS
+ifdef CONFIG_LTO
+       ifeq ($(cc-name),clang)
+               LTO_CFLAGS              += -flto
+               LTO_FINAL_LDFLAGS       += -flto
+
+               AR                      = $(shell $(CC) -print-prog-name=llvm-ar)
+               NM                      = $(shell $(CC) -print-prog-name=llvm-nm)
+       else
+               NPROC                   := $(shell nproc 2>/dev/null || echo 1)
+               LTO_CFLAGS              += -flto=$(NPROC)
+               LTO_FINAL_LDFLAGS       += -fuse-linker-plugin -flto=$(NPROC)
+
+               # use plugin aware tools
+               AR                      = $(CROSS_COMPILE)gcc-ar
+               NM                      = $(CROSS_COMPILE)gcc-nm
+       endif
+
+       CFLAGS_NON_EFI                  += $(LTO_CFLAGS)
+
+       KBUILD_CFLAGS                   += $(LTO_CFLAGS)
+endif
+
+ifeq ($(CONFIG_STACKPROTECTOR),y)
+KBUILD_CFLAGS += $(call cc-option,-fstack-protector-strong)
+CFLAGS_EFI += $(call cc-option,-fno-stack-protector)
+else
 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
+endif
 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
 
+# disable pointer signed / unsigned warnings in gcc 4.0
+KBUILD_CFLAGS += -Wno-pointer-sign
+
 # disable stringop warnings in gcc 8+
 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 
+KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
+KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds)
+KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
+
 # Enabled with W=2, disabled by default as noisy
 KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
 
@@ -710,7 +747,7 @@ endif
 KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
 KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
@@ -722,12 +759,11 @@ KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
 # See modpost pattern 2
 KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
 KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
-else
+endif
 
 # These warnings generated too much noise in a regular build.
 # Use make W=1 to enable them (see scripts/Makefile.extrawarn)
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
-endif
 
 # Prohibit date/time macros, which would make the build non-deterministic
 KBUILD_CFLAGS   += $(call cc-option,-Werror=date-time)
@@ -918,6 +954,7 @@ endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot.dtb
+INPUTS-$(CONFIG_BINMAN_STANDALONE_FDT) += u-boot.dtb
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
@@ -971,6 +1008,8 @@ LDFLAGS_u-boot += $(LDFLAGS_FINAL)
 # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
 LDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker)
 
+LDFLAGS_u-boot += --build-id=none
+
 ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),)
 LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
 endif
@@ -1021,6 +1060,33 @@ quiet_cmd_cfgcheck = CFGCHK  $2
 cmd_cfgcheck = $(srctree)/scripts/check-config.sh $2 \
                $(srctree)/scripts/config_whitelist.txt $(srctree)
 
+# Concat the value of all the CONFIGs (result is 'y' or 'yy', etc. )
+got = $(foreach cfg,$(1),$($(cfg)))
+
+# expected value 'y for each one
+expect = $(foreach cfg,$(1),y)
+
+# Show a deprecation message
+# Args:
+# 1: List of CONFIG_DM_... to migrate to (e.g. "CONFIG_DM_MMC CONFIG_BLK")
+# 2: Name of component (e.g . "Ethernet drivers")
+# 3: Release deadline (e.g. "v202.07")
+# 4: Condition to require before checking (e.g. "$(CONFIG_NET)")
+# Note: Script avoids bash construct, hence the strange double 'if'
+# (patches welcome!)
+define deprecated
+       @if [ -n "$(strip $(4))" ]; then if [ "$(got)" != "$(expect)" ]; then \
+               echo >&2 "===================== WARNING ======================"; \
+               echo >&2 "This board does not use $(firstword $(1)) (Driver Model"; \
+               echo >&2 "for $(2)). Please update the board to use"; \
+               echo >&2 "$(firstword $(1)) before the $(3) release. Failure to"; \
+               echo >&2 "update by the deadline may result in board removal."; \
+               echo >&2 "See doc/driver-model/migration.rst for more info."; \
+               echo >&2 "===================================================="; \
+       fi; fi
+
+endef
+
 PHONY += inputs
 inputs: $(INPUTS-y)
 
@@ -1035,80 +1101,6 @@ endif
 
 ifeq ($(CONFIG_DEPRECATED),y)
        $(warning "You have deprecated configuration options enabled in your .config! Please check your configuration.")
-ifeq ($(CONFIG_SPI),y)
-ifneq ($(CONFIG_DM_SPI)$(CONFIG_OF_CONTROL),yy)
-       $(warning "The relevant config item with associated code will remove in v2019.07 release.")
-endif
-endif
-endif
-ifneq ($(CONFIG_DM),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM. CONFIG_DM will be"
-       @echo >&2 "compulsory starting with the v2020.01 release."
-       @echo >&2 "Failure to update may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-ifeq ($(CONFIG_MMC),y)
-ifneq ($(CONFIG_DM_MMC)$(CONFIG_BLK),yy)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_MMC. Please update"
-       @echo >&2 "the board to use CONFIG_DM_MMC before the v2019.04 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifeq ($(CONFIG_USB),y)
-ifneq ($(CONFIG_DM_USB)$(CONFIG_OF_CONTROL)$(CONFIG_BLK),yyy)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_USB. Please update"
-       @echo >&2 "the board to use CONFIG_DM_USB before the v2019.07 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifeq ($(CONFIG_MVSATA_IDE),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does use CONFIG_MVSATA_IDE which is not"
-       @echo >&2 "ported to driver-model (DM) yet. Please update the storage"
-       @echo >&2 "controller driver to use CONFIG_AHCI before the v2019.07"
-       @echo >&2 "release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-ifeq ($(CONFIG_LIBATA),y)
-ifneq ($(CONFIG_AHCI),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does use CONFIG_LIBATA but has CONFIG_AHCI not"
-       @echo >&2 "enabled. Please update the storage controller driver to use"
-       @echo >&2 "CONFIG_AHCI before the v2019.07 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifeq ($(CONFIG_PCI),y)
-ifneq ($(CONFIG_DM_PCI),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_PCI Please update"
-       @echo >&2 "the board to use CONFIG_DM_PCI before the v2019.07 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifneq ($(CONFIG_LCD)$(CONFIG_VIDEO),)
-ifneq ($(CONFIG_DM_VIDEO),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_VIDEO Please update"
-       @echo >&2 "the board to use CONFIG_DM_VIDEO before the v2019.07 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
 endif
 ifeq ($(CONFIG_OF_EMBED),y)
        @echo >&2 "===================== WARNING ======================"
@@ -1118,38 +1110,6 @@ ifeq ($(CONFIG_OF_EMBED),y)
        @echo >&2 "See doc/README.fdt-control for more info."
        @echo >&2 "===================================================="
 endif
-ifeq ($(CONFIG_SPI_FLASH),y)
-ifneq ($(CONFIG_DM_SPI_FLASH)$(CONFIG_OF_CONTROL),yy)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_SPI_FLASH. Please update"
-       @echo >&2 "the board to use CONFIG_SPI_FLASH before the v2019.07 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifneq ($(CONFIG_WATCHDOG)$(CONFIG_HW_WATCHDOG),)
-ifneq ($(CONFIG_WDT),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_WDT (DM watchdog support)."
-       @echo >&2 "Please update the board to use CONFIG_WDT before the"
-       @echo >&2 "v2019.10 release."
-       @echo >&2 "Failure to update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
-ifneq ($(CONFIG_NET),)
-ifneq ($(CONFIG_DM_ETH),y)
-       @echo >&2 "===================== WARNING ======================"
-       @echo >&2 "This board does not use CONFIG_DM_ETH (Driver Model"
-       @echo >&2 "for Ethernet drivers). Please update the board to use"
-       @echo >&2 "CONFIG_DM_ETH before the v2020.07 release. Failure to"
-       @echo >&2 "update by the deadline may result in board removal."
-       @echo >&2 "See doc/driver-model/migration.rst for more info."
-       @echo >&2 "===================================================="
-endif
-endif
 ifneq ($(CONFIG_SPL_FIT_GENERATOR),)
        @echo >&2 "===================== WARNING ======================"
        @echo >&2 "This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate"
@@ -1157,6 +1117,25 @@ ifneq ($(CONFIG_SPL_FIT_GENERATOR),)
        @echo >&2 "arch-specific scripts with no tests."
        @echo >&2 "===================================================="
 endif
+ifneq ($(CONFIG_DM),y)
+       @echo >&2 "===================== WARNING ======================"
+       @echo >&2 "This board does not use CONFIG_DM. CONFIG_DM will be"
+       @echo >&2 "compulsory starting with the v2020.01 release."
+       @echo >&2 "Failure to update may result in board removal."
+       @echo >&2 "See doc/driver-model/migration.rst for more info."
+       @echo >&2 "===================================================="
+endif
+       $(call deprecated,CONFIG_DM_USB CONFIG_OF_CONTROL CONFIG_BLK,\
+               USB,v2019.07,$(CONFIG_USB))
+       $(call deprecated,CONFIG_DM_PCI,PCI,v2019.07,$(CONFIG_PCI))
+       $(call deprecated,CONFIG_DM_VIDEO,video,v2019.07,\
+               $(CONFIG_LCD)$(CONFIG_VIDEO))
+       $(call deprecated,CONFIG_DM_SPI_FLASH,SPI flash,v2019.07,\
+               $(CONFIG_SPI_FLASH))
+       $(call deprecated,CONFIG_WDT,DM watchdog,v2019.10,\
+               $(CONFIG_WATCHDOG)$(CONFIG_HW_WATCHDOG))
+       $(call deprecated,CONFIG_DM_ETH,Ethernet drivers,v2020.07,$(CONFIG_NET))
+       $(call deprecated,CONFIG_DM_I2C,I2C drivers,v2022.04,$(CONFIG_I2C))
        @# Check that this build does not use CONFIG options that we do not
        @# know about unless they are in Kconfig. All the existing CONFIG
        @# options are whitelisted, so new ones should not be added.
@@ -1345,6 +1324,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
                -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
                -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
                -a atf-bl31-path=${BL31} \
+               -a opensbi-path=${OPENSBI} \
                -a default-dt=$(default_dt) \
                -a scp-path=$(SCP) \
                -a spl-bss-pad=$(if $(CONFIG_SPL_SEPARATE_BSS),,1) \
@@ -1449,7 +1429,7 @@ u-boot-lzma.img: u-boot.bin.lzma FORCE
 
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
                $(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
-                       $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
+                       $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE)$(CONFIG_BINMAN_STANDALONE_FDT),dts/dt.dtb) \
                ,$(UBOOT_BIN)) FORCE
        $(call if_changed,mkimage)
        $(BOARD_SIZE_CHECK)
@@ -1551,10 +1531,16 @@ u-boot.cnt: u-boot.bin FORCE
 flash.bin: spl/u-boot-spl.bin u-boot.cnt FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 else
+ifeq ($(CONFIG_BINMAN),y)
+flash.bin: spl/u-boot-spl.bin $(INPUTS-y) FORCE
+       $(call if_changed,binman)
+       $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
+else
 flash.bin: spl/u-boot-spl.bin u-boot.itb FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 endif
 endif
+endif
 
 u-boot.uim: u-boot.bin FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
@@ -1582,22 +1568,11 @@ u-boot-signed.sb: u-boot.bin spl/u-boot-spl.bin
 u-boot.sb: u-boot.bin spl/u-boot-spl.bin
        $(Q)$(MAKE) $(build)=arch/arm/cpu/arm926ejs/mxs u-boot.sb
 
-# On x600 (SPEAr600) U-Boot is appended to U-Boot SPL.
-# Both images are created using mkimage (crc etc), so that the ROM
-# bootloader can check its integrity. Padding needs to be done to the
-# SPL image (with mkimage header) and not the binary. Otherwise the resulting image
-# which is loaded/copied by the ROM bootloader to SRAM doesn't fit.
-# The resulting image containing both U-Boot images is called u-boot.spr
 MKIMAGEFLAGS_u-boot-spl.img = -A $(ARCH) -T firmware -C none \
        -a $(CONFIG_SPL_TEXT_BASE) -e $(CONFIG_SPL_TEXT_BASE) -n XLOADER
 spl/u-boot-spl.img: spl/u-boot-spl.bin FORCE
        $(call if_changed,mkimage)
 
-OBJCOPYFLAGS_u-boot.spr = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
-                         --gap-fill=0xff
-u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
-       $(call if_changed,pad_cat)
-
 ifneq ($(CONFIG_ARCH_SOCFPGA),)
 quiet_cmd_gensplx4 = GENSPLX4 $@
 cmd_gensplx4 = $(OBJCOPY) -I binary -O binary --gap-fill=0x0           \
@@ -1760,14 +1735,54 @@ u-boot-swap.bin: u-boot.bin FORCE
 
 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink)
 
+# Generate linker list symbols references to force compiler to not optimize
+# them away when compiling with LTO
+ifdef CONFIG_LTO
+u-boot-keep-syms-lto := keep-syms-lto.o
+u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto))
+
+quiet_cmd_keep_syms_lto = KSL     $@
+      cmd_keep_syms_lto = \
+       NM=$(NM) $(srctree)/scripts/gen_ll_addressable_symbols.sh $^ >$@
+
+quiet_cmd_keep_syms_lto_cc = KSLCC   $@
+      cmd_keep_syms_lto_cc = \
+       $(CC) $(filter-out $(LTO_CFLAGS),$(c_flags)) -c -o $@ $<
+
+$(u-boot-keep-syms-lto_c): $(u-boot-main)
+       $(call if_changed,keep_syms_lto)
+$(u-boot-keep-syms-lto): $(u-boot-keep-syms-lto_c)
+       $(call if_changed,keep_syms_lto_cc)
+else
+u-boot-keep-syms-lto :=
+endif
+
 # Rule to link u-boot
 # May be overridden by arch/$(ARCH)/config.mk
+ifdef CONFIG_LTO
+quiet_cmd_u-boot__ ?= LTO     $@
+      cmd_u-boot__ ?=                                                          \
+               $(CC) -nostdlib -nostartfiles                                   \
+               $(LTO_FINAL_LDFLAGS) $(c_flags)                                 \
+               $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_u-boot:%=-Wl,%) -o $@       \
+               -T u-boot.lds $(u-boot-init)                                    \
+               -Wl,--whole-archive                                             \
+                       $(u-boot-main)                                          \
+                       $(u-boot-keep-syms-lto)                                 \
+                       $(PLATFORM_LIBS)                                        \
+               -Wl,--no-whole-archive                                          \
+               -Wl,-Map,u-boot.map;                                            \
+               $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+else
 quiet_cmd_u-boot__ ?= LD      $@
-      cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
-      -T u-boot.lds $(u-boot-init)                             \
-      --start-group $(u-boot-main) --end-group                 \
-      $(PLATFORM_LIBS) -Map u-boot.map;                        \
-      $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+      cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@          \
+               -T u-boot.lds $(u-boot-init)                                    \
+               --whole-archive                                                 \
+                       $(u-boot-main)                                          \
+               --no-whole-archive                                              \
+               $(PLATFORM_LIBS) -Map u-boot.map;                               \
+               $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+endif
 
 quiet_cmd_smap = GEN     common/system_map.o
 cmd_smap = \
@@ -1776,7 +1791,7 @@ cmd_smap = \
        $(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
                -c $(srctree)/common/system_map.c -o common/system_map.o
 
-u-boot:        $(u-boot-init) $(u-boot-main) u-boot.lds FORCE
+u-boot:        $(u-boot-init) $(u-boot-main) $(u-boot-keep-syms-lto) u-boot.lds FORCE
        +$(call if_changed,u-boot__)
 ifeq ($(CONFIG_KALLSYMS),y)
        $(call cmd,smap)
@@ -1856,6 +1871,8 @@ endif
 
 ifeq ($(CONFIG_USE_DEFAULT_ENV_FILE),y)
 prepare1: $(defaultenv_h)
+
+envtools: $(defaultenv_h)
 endif
 
 archprepare: prepare1 scripts_basic
@@ -1912,11 +1929,10 @@ define filechk_timestamp.h
 endef
 
 define filechk_defaultenv.h
-       (grep -v '^#' | \
-        grep -v '^$$' | \
+       ( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \
         tr '\n' '\0' | \
         sed -e 's/\\\x0\s*//g' | \
-        xxd -i ; echo ", 0x00" ; )
+        xxd -i ; )
 endef
 
 define filechk_dt.h
@@ -1940,6 +1956,35 @@ $(defaultenv_h): $(CONFIG_DEFAULT_ENV_FILE:"%"=%) FORCE
        $(call filechk,defaultenv.h)
 
 # ---------------------------------------------------------------------------
+# Devicetree files
+
+ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
+dtstree := arch/$(SRCARCH)/boot/dts
+endif
+
+ifneq ($(dtstree),)
+
+%.dtb: prepare3 scripts_dtc
+       $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
+
+PHONY += dtbs dtbs_install
+dtbs: prepare3 scripts_dtc
+       $(Q)$(MAKE) $(build)=$(dtstree)
+
+dtbs_install:
+       $(Q)$(MAKE) $(dtbinst)=$(dtstree)
+
+ifdef CONFIG_OF_EARLY_FLATTREE
+all: dtbs
+endif
+
+endif
+
+PHONY += scripts_dtc
+scripts_dtc: scripts_basic
+       $(Q)$(MAKE) $(build)=scripts/dtc
+
+# ---------------------------------------------------------------------------
 quiet_cmd_cpp_lds = LDS     $@
 cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \
                -D__ASSEMBLY__ -x assembler-with-cpp -std=c99 -P -o $@ $<
@@ -2060,14 +2105,16 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \
               boot* u-boot* MLO* SPL System.map fit-dtb.blob* \
               u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
               lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
-              idbloader.img flash.bin flash.log defconfig
+              idbloader.img flash.bin flash.log defconfig keep-syms-lto.c
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl \
                  .tmp_objdiff doc/output
+
+# Remove include/asm symlink created by U-Boot before v2014.01
 MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
                  ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
-                 drivers/video/fonts/*.S
+                 drivers/video/fonts/*.S include/asm
 
 # clean - Delete most, but leave enough to build external modules
 #
@@ -2199,9 +2246,6 @@ PHONY += $(DOC_TARGETS)
 $(DOC_TARGETS): scripts_basic FORCE
        $(Q)$(MAKE) $(build)=doc $@
 
-endif #ifeq ($(config-targets),1)
-endif #ifeq ($(mixed-targets),1)
-
 PHONY += checkstack ubootrelease ubootversion
 
 checkstack:
@@ -2263,7 +2307,7 @@ endif
        $(build)=$(build-dir) $(@:.ko=.o)
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
-quiet_cmd_genenv = GENENV $@
+quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
        sed --in-place -e 's/\x00/\x0A/g' $@
 
@@ -2289,13 +2333,15 @@ quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files))
 
 # read all saved command lines
 
-cmd_files := $(wildcard .*.cmd $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
+cmd_files := $(wildcard .*.cmd)
 
 ifneq ($(cmd_files),)
   $(cmd_files): ;      # Do not try to update included dependency files
   include $(cmd_files)
 endif
 
+endif    #ifeq ($(config-targets),1)
+endif    #ifeq ($(mixed-targets),1)
 endif  # skip-makefile
 
 PHONY += FORCE