]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ti-u-boot/ti-u-boot.git/blobdiff - Makefile
Prepare v2024.04
[ti-u-boot/ti-u-boot.git] / Makefile
index 079881b62ab1291a42660959c967396e37a45e63..6558415a8b5a45dc24a64cfdcfd6fe43c9b912c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-VERSION = 2021
+VERSION = 2024
 PATCHLEVEL = 04
 SUBLEVEL =
-EXTRAVERSION = -rc2
+EXTRAVERSION =
 NAME =
 
 # *DOCUMENTATION*
@@ -12,14 +12,17 @@ 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 host architecture
+# Determine target architecture for the sandbox
 include include/host_arch.h
-MK_ARCH="${shell uname -m}"
+ifeq ("", "$(CROSS_COMPILE)")
+  MK_ARCH="${shell uname -m}"
+else
+  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+endif
 unexport HOST_ARCH
 ifeq ("x86_64", $(MK_ARCH))
   export HOST_ARCH=$(HOST_ARCH_X86_64)
@@ -27,7 +30,7 @@ else ifneq (,$(findstring $(MK_ARCH), "i386" "i486" "i586" "i686"))
   export HOST_ARCH=$(HOST_ARCH_X86)
 else ifneq (,$(findstring $(MK_ARCH), "aarch64" "armv8l"))
   export HOST_ARCH=$(HOST_ARCH_AARCH64)
-else ifeq ("armv7l", $(MK_ARCH))
+else ifneq (,$(findstring $(MK_ARCH), "arm" "armv7" "armv7a" "armv7l"))
   export HOST_ARCH=$(HOST_ARCH_ARM)
 else ifeq ("riscv32", $(MK_ARCH))
   export HOST_ARCH=$(HOST_ARCH_RISCV32)
@@ -158,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
@@ -289,9 +299,7 @@ KBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
 # have older compilers as their default, so we make it explicit for
 # these that our host tools are GNU11 (i.e. C11 w/ GNU extensions).
 CSTD_FLAG := -std=gnu11
-ifeq ($(HOSTOS),linux)
 KBUILD_HOSTCFLAGS += $(CSTD_FLAG)
-endif
 
 ifeq ($(HOSTOS),cygwin)
 KBUILD_HOSTCFLAGS      += -ansi
@@ -310,26 +318,21 @@ endif
 #
 ifeq ($(HOSTOS),darwin)
 # get major and minor product version (e.g. '10' and '6' for Snow Leopard)
-DARWIN_MAJOR_VERSION   = $(shell sw_vers -productVersion | cut -f 1 -d '.')
-DARWIN_MINOR_VERSION   = $(shell sw_vers -productVersion | cut -f 2 -d '.')
+DARWIN_MAJOR_VERSION   := $(shell sw_vers -productVersion | cut -f 1 -d '.')
+DARWIN_MINOR_VERSION   := $(shell sw_vers -productVersion | cut -f 2 -d '.')
 
 os_x_before    = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
        $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
 
 os_x_after = $(shell if [ $(DARWIN_MAJOR_VERSION) -ge $(1) -a \
-       $(DARWIN_MINOR_VERSION) -ge $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)  
+       $(DARWIN_MINOR_VERSION) -ge $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
 
 # Snow Leopards build environment has no longer restrictions as described above
 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) 
+# macOS Mojave (10.14.X)
 # Undefined symbols for architecture x86_64: "_PyArg_ParseTuple"
 KBUILD_HOSTLDFLAGS += $(call os_x_after, 10, 14, "-lpython -dynamclib", "")
 endif
@@ -409,12 +412,19 @@ AWK               = awk
 PERL           = perl
 PYTHON         ?= python
 PYTHON2                = python2
-PYTHON3                = python3
-DTC            ?= $(objtree)/scripts/dtc/dtc
+PYTHON3                ?= python3
+
+# The devicetree compiler and pylibfdt are automatically built unless DTC is
+# provided. If DTC is provided, it is assumed the pylibfdt is available too.
+DTC_INTREE     := $(objtree)/scripts/dtc/dtc
+DTC            ?= $(DTC_INTREE)
+DTC_MIN_VERSION        := 010406
+
 CHECK          = sparse
 
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
-                 -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
+                 -Wbitwise -Wno-return-void -Wno-unknown-attribute \
+                 -D__CHECK_ENDIAN__ $(CF)
 
 KBUILD_CPPFLAGS := -D__KERNEL__ -D__UBOOT__
 
@@ -428,6 +438,7 @@ KBUILD_LDFLAGS  :=
 ifeq ($(cc-name),clang)
 ifneq ($(CROSS_COMPILE),)
 CLANG_TARGET   := --target=$(notdir $(CROSS_COMPILE:%-=%))
+LDPPFLAGS      += $(CLANG_TARGET)
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
 CLANG_PREFIX   := --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
@@ -474,6 +485,15 @@ export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
                         --exclude CVS --exclude .pc --exclude .hg --exclude .git
 
+export PYTHON_ENABLE
+
+# This is y if U-Boot should not build any Python tools or libraries. Typically
+# you would need to set this if those tools/libraries (typically binman and
+# pylibfdt) cannot be built by your environment and are provided separately.
+ifeq ($(NO_PYTHON),)
+PYTHON_ENABLE=y
+endif
+
 # ===========================================================================
 # Rules shared between *config targets and build targets
 
@@ -493,8 +513,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
@@ -509,10 +528,12 @@ version_h := include/generated/version_autogenerated.h
 timestamp_h := include/generated/timestamp_autogenerated.h
 defaultenv_h := include/generated/defaultenv_autogenerated.h
 dt_h := include/generated/dt.h
+env_h := include/generated/environment.h
 
 no-dot-config-targets := clean clobber mrproper distclean \
                         help %docs check% coccicheck \
-                        ubootversion backup tests check qcheck tcheck
+                        ubootversion backup tests check pcheck qcheck tcheck \
+                        pylint pylint_err _pip pip pip_test pip_release
 
 config-targets := 0
 mixed-targets  := 0
@@ -573,7 +594,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)
@@ -633,6 +654,13 @@ export CFLAGS_EFI  # Compiler flags to add when building EFI app
 export CFLAGS_NON_EFI  # Compiler flags to remove when building EFI app
 export EFI_TARGET      # binutils target if EFI is natively supported
 
+export LTO_ENABLE
+
+# This is y if LTO is enabled for this build. See NO_LTO=1 to disable LTO
+ifeq ($(NO_LTO),)
+LTO_ENABLE=$(if $(CONFIG_LTO),y)
+endif
+
 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
 # that (or fail if absent).  Otherwise, search for a linker script in a
 # standard location.
@@ -663,6 +691,15 @@ else
 include/config/auto.conf: ;
 endif # $(dot-config)
 
+ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG
+KBUILD_HOSTCFLAGS   := -Wall -Wstrict-prototypes -Og -g -fomit-frame-pointer \
+               $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
+# Avoid false positives -Wmaybe-uninitialized
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78394
+KBUILD_HOSTCFLAGS   += -Wno-maybe-uninitialized
+KBUILD_HOSTCXXFLAGS := -Og -g $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
+endif
+
 #
 # Xtensa linker script cannot be preprocessed with -ansi because of
 # preprocessor operations on strings that don't make C identifiers.
@@ -673,26 +710,73 @@ endif
 
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS  += -Os
-else
+endif
+
+ifdef CONFIG_CC_OPTIMIZE_FOR_SPEED
 KBUILD_CFLAGS  += -O2
 endif
 
+ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG
+KBUILD_CFLAGS  += -Og -Wno-maybe-uninitialized
+# Avoid false positives -Wmaybe-uninitialized
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78394
+KBUILD_CFLAGS  += -Wno-maybe-uninitialized
+endif
+
+LTO_CFLAGS :=
+LTO_FINAL_LDFLAGS :=
+export LTO_CFLAGS LTO_FINAL_LDFLAGS
+ifeq ($(LTO_ENABLE),y)
+       ifeq ($(cc-name),clang)
+               LTO_CFLAGS              += -DLTO_ENABLE -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              += -DLTO_ENABLE -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)
+KBUILD_CFLAGS += $(call cc-option,-mstack-protector-guard=global)
+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)
 
 # change __FILE__ to the relative path from the srctree
 KBUILD_CFLAGS  += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
-KBUILD_CFLAGS  += -g
+KBUILD_CFLAGS  += -gdwarf-4
 # $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
 # option to the assembler.
-KBUILD_AFLAGS  += -g
+KBUILD_AFLAGS  += -gdwarf-4
 
 # Report stack usage if supported
 # ARC tools based on GCC 7.1 has an issue with stack usage
@@ -706,7 +790,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)
@@ -718,12 +802,12 @@ 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
+KBUILD_CFLAGS += $(call cc-disable-warning, deprecated-non-prototype)
+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)
@@ -735,6 +819,9 @@ KBUILD_CPPFLAGS += $(KCPPFLAGS)
 KBUILD_AFLAGS += $(KAFLAGS)
 KBUILD_CFLAGS += $(KCFLAGS)
 
+KBUILD_LDFLAGS  += -z noexecstack
+KBUILD_LDFLAGS  += $(call ld-option,--no-warn-rwx-segments)
+
 KBUILD_HOSTCFLAGS += $(if $(CONFIG_TOOLS_DEBUG),-g)
 
 # Use UBOOTINCLUDE when you must reference the include/ directory.
@@ -762,57 +849,45 @@ c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
 
 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
 
-libs-y += lib/
+libs-$(CONFIG_API) += api/
 libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
+libs-y += boot/
+libs-$(CONFIG_CMDLINE) += cmd/
+libs-y += common/
 libs-$(CONFIG_OF_EMBED) += dts/
+libs-y += env/
+libs-y += lib/
 libs-y += fs/
 libs-y += net/
 libs-y += disk/
 libs-y += drivers/
-libs-y += drivers/dma/
-libs-y += drivers/gpio/
-libs-y += drivers/i2c/
-libs-y += drivers/net/
-libs-y += drivers/net/phy/
-libs-y += drivers/power/ \
-       drivers/power/domain/ \
-       drivers/power/fuel_gauge/ \
-       drivers/power/mfd/ \
-       drivers/power/pmic/ \
-       drivers/power/battery/ \
-       drivers/power/regulator/
-libs-y += drivers/spi/
-libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/
 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
-libs-y += drivers/serial/
 libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
 libs-y += drivers/usb/eth/
+libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
 libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
 libs-y += drivers/usb/host/
 libs-y += drivers/usb/mtu3/
 libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
+libs-y += drivers/usb/isp1760/
 libs-y += drivers/usb/phy/
 libs-y += drivers/usb/ulpi/
-libs-y += cmd/
-libs-y += common/
-libs-y += env/
-libs-$(CONFIG_API) += api/
 ifdef CONFIG_POST
 libs-y += post/
 endif
-libs-$(CONFIG_UNIT_TEST) += test/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 libs-$(CONFIG_UT_ENV) += test/env/
 libs-$(CONFIG_UT_OPTEE) += test/optee/
 libs-$(CONFIG_UT_OVERLAY) += test/overlay/
 
-libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
+libs-y += $(if $(wildcard $(srctree)/board/$(BOARDDIR)/Makefile),board/$(BOARDDIR)/)
 
 libs-y := $(sort $(libs-y))
 
@@ -830,8 +905,10 @@ u-boot-main := $(libs-y)
 ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)
 PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a
 else
+ifndef CONFIG_CC_IS_CLANG
 PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc
 endif
+endif
 PLATFORM_LIBS += $(PLATFORM_LIBGCC)
 
 ifdef CONFIG_CC_COVERAGE
@@ -872,17 +949,21 @@ else
 TPL_SIZE_CHECK =
 endif
 
+ifneq ($(CONFIG_VPL_SIZE_LIMIT),0x0)
+VPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_VPL_SIZE_LIMIT))
+else
+VPL_SIZE_CHECK =
+endif
+
 # Statically apply RELA-style relocations (currently arm64 only)
 # This is useful for arm64 where static relocation needs to be performed on
 # the raw binary, but certain simulators only accept an ELF file (but don't
 # do the relocation).
 ifneq ($(CONFIG_STATIC_RELA),)
-# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base
+# $(2) is u-boot ELF, $(3) is u-boot bin, $(4) is text base
 quiet_cmd_static_rela = RELOC   $@
 cmd_static_rela = \
-       start=$$($(NM) $(2) | grep __rel_dyn_start | cut -f 1 -d ' '); \
-       end=$$($(NM) $(2) | grep __rel_dyn_end | cut -f 1 -d ' '); \
-       tools/relocate-rela $(3) $(4) $$start $$end
+       tools/relocate-rela $(3) $(2)
 else
 quiet_cmd_static_rela =
 cmd_static_rela =
@@ -891,7 +972,6 @@ endif
 # Always append INPUTS so that arch config.mk's can add custom ones
 INPUTS-y += u-boot.srec u-boot.bin u-boot.sym System.map binary_size_check
 
-INPUTS-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin
 ifeq ($(CONFIG_SPL_FSL_PBL),y)
 INPUTS-$(CONFIG_RAMBOOT_PBL) += u-boot-with-spl-pbl.bin
 else
@@ -912,11 +992,14 @@ INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
 endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
-INPUTS-$(CONFIG_OF_SEPARATE) += u-boot.dtb
+INPUTS-$(CONFIG_VPL) += vpl/u-boot-vpl.bin
+
+# Allow omitting the .dtb output if it is not normally used
+INPUTS-$(CONFIG_OF_SEPARATE) += $(if $(CONFIG_OF_OMIT_DTB),dts/dt.dtb,u-boot.dtb)
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
-INPUTS-$(CONFIG_OF_HOSTFILE) += u-boot.dtb
+INPUTS-$(CONFIG_SANDBOX) += u-boot.dtb
 ifneq ($(CONFIG_SPL_TARGET),)
 INPUTS-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
 endif
@@ -938,23 +1021,8 @@ ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy)
 INPUTS-y += init_sp_bss_offset_check
 endif
 
-ifeq ($(CONFIG_MPC85xx)$(CONFIG_OF_SEPARATE),yy)
-INPUTS-y += u-boot-with-dtb.bin
-endif
-
-ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
-# On ARM64 this target is produced by binman so we don't need this dep
-ifeq ($(CONFIG_ARM64),y)
-ifeq ($(CONFIG_SPL),y)
-# TODO: Get binman to generate this too
-INPUTS-y += u-boot-rockchip.bin
-endif
-else
-ifeq ($(CONFIG_SPL),y)
-# Generate these inputs for binman which will create the output files
-INPUTS-y += idbloader.img u-boot.img
-endif
-endif
+ifeq ($(CONFIG_ARCH_ROCKCHIP)_$(CONFIG_SPL_FRAMEWORK),y_)
+INPUTS-y += u-boot.img
 endif
 
 INPUTS-$(CONFIG_X86) += u-boot-x86-start16.bin u-boot-x86-reset16.bin \
@@ -966,10 +1034,18 @@ 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)
 
+# ld.lld support
+LDFLAGS_u-boot += -z notext $(call ld-option,--apply-dynamic-relocs)
+
+LDFLAGS_u-boot += --build-id=none
+
 ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),)
-LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
+LDFLAGS_u-boot += -Ttext $(CONFIG_TEXT_BASE)
 endif
 
+# make the checker run with the right architecture
+CHECKFLAGS += --arch=$(ARCH)
+
 # insure the checker run with the right endianness
 CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
 
@@ -1012,139 +1088,57 @@ cmd_lzma = lzma -c -z -k -9 $< > $@
 
 cfg: u-boot.cfg
 
-quiet_cmd_cfgcheck = CFGCHK  $2
-cmd_cfgcheck = $(srctree)/scripts/check-config.sh $2 \
-               $(srctree)/scripts/config_whitelist.txt $(srctree)
+quiet_cmd_ofcheck = OFCHK   $2
+cmd_ofcheck = $(srctree)/scripts/check-of.sh $2 \
+               $(srctree)/scripts/of_allowlist.txt
 
-PHONY += inputs
-inputs: $(INPUTS-y)
+# Concat the value of all the CONFIGs (result is 'y' or 'yy', etc. )
+got = $(foreach cfg,$(1),$($(cfg)))
 
-all: .binman_stamp inputs
+# expected value 'y for each one
+expect = $(foreach cfg,$(1),y)
+
+# Show a deprecation message
+# Args:
+# 1: List of options 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/develop/driver-model/migration.rst for more info."; \
+               echo >&2 "===================================================="; \
+       fi; fi
+
+endef
+
+# Timestamp file to make sure that binman always runs
+.binman_stamp: $(INPUTS-y) FORCE
 ifeq ($(CONFIG_BINMAN),y)
        $(call if_changed,binman)
 endif
-
-# Timestamp file to make sure that binman always runs
-.binman_stamp: FORCE
        @touch $@
 
+all: .binman_stamp
+
 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)
+ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
        @echo >&2 "===================== WARNING ======================"
        @echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
        @echo >&2 "be used for debugging purposes. Please use"
        @echo >&2 "CONFIG_OF_SEPARATE for boards in mainline."
-       @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 "See doc/develop/devicetree/control.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"
@@ -1152,10 +1146,17 @@ ifneq ($(CONFIG_SPL_FIT_GENERATOR),)
        @echo >&2 "arch-specific scripts with no tests."
        @echo >&2 "===================================================="
 endif
-       @# 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.
-       $(call cmd,cfgcheck,u-boot.cfg)
+       $(call deprecated,CONFIG_WDT,DM watchdog,v2019.10,\
+               $(CONFIG_WATCHDOG)$(CONFIG_HW_WATCHDOG))
+       $(call deprecated,CONFIG_DM_I2C,I2C drivers,v2022.04,$(CONFIG_SYS_I2C_LEGACY))
+       @# CFG_SYS_TIMER_RATE has brackets in it for some boards which
+       @# confuses this rule. Use if() to send just a single character which
+       @# is enable to tell 'deprecated' that one of these symbols exists
+       $(call deprecated,CONFIG_TIMER,Timer drivers,v2023.01,$(if $(strip $(CFG_SYS_TIMER_RATE)$(CFG_SYS_TIMER_COUNTER)),x))
+       $(call deprecated,CONFIG_DM_SERIAL,Serial drivers,v2023.04,$(CONFIG_SERIAL))
+       @# Check that this build does not override OF_HAS_PRIOR_STAGE by
+       @# disabling OF_BOARD.
+       $(call cmd,ofcheck,$(KCONFIG_CONFIG))
 
 PHONY += dtbs
 dtbs: dts/dt.dtb
@@ -1193,6 +1194,8 @@ MKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
        -a 0 -e 0 -E \
        $(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null
 
+MKIMAGEFLAGS_fit-dtb.blob += -B 0x8
+
 ifneq ($(EXT_DTB),)
 u-boot-fit-dtb.bin: u-boot-nodtb.bin $(EXT_DTB)
                $(call if_changed,cat)
@@ -1204,15 +1207,21 @@ endif
 u-boot.bin: u-boot-fit-dtb.bin FORCE
        $(call if_changed,copy)
 
+ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
        $(call if_changed,cat)
+endif
 
-else ifeq ($(CONFIG_OF_SEPARATE),y)
+else ifeq ($(CONFIG_OF_SEPARATE).$(CONFIG_OF_OMIT_DTB),y.)
+
+ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
 u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
        $(call if_changed,cat)
+endif
 
 u-boot.bin: u-boot-dtb.bin FORCE
        $(call if_changed,copy)
+
 else
 u-boot.bin: u-boot-nodtb.bin FORCE
        $(call if_changed,copy)
@@ -1257,16 +1266,11 @@ spl/u-boot-spl.srec: spl/u-boot-spl FORCE
        $(call if_changed,objcopy)
 
 %.scif: %.srec
-       $(Q)$(MAKE) $(build)=arch/arm/mach-rmobile $@
+       $(Q)$(MAKE) $(build)=arch/arm/mach-renesas $@
 
 OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \
                $(if $(CONFIG_X86_16BIT_INIT),-R .start16 -R .resetvec) \
-               $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR),-R .bootpg -R .resetvec)
-
-OBJCOPYFLAGS_u-boot-spl.hex = $(OBJCOPYFLAGS_u-boot.hex)
-
-spl/u-boot-spl.hex: spl/u-boot-spl FORCE
-       $(call if_changed,objcopy)
+               $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR),$(if $(CONFIG_OF_SEPARATE),-R .bootpg -R .resetvec))
 
 binary_size_check: u-boot-nodtb.bin FORCE
        @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \
@@ -1279,11 +1283,11 @@ binary_size_check: u-boot-nodtb.bin FORCE
                        echo "u-boot.map shows a binary size of $$map_size" >&2 ; \
                        echo "  but u-boot-nodtb.bin shows $$file_size" >&2 ; \
                        exit 1; \
-               fi \
+               fi; \
        fi
 
 ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy)
-ifneq ($(CONFIG_SYS_MALLOC_F_LEN),)
+ifneq ($(CONFIG_SYS_MALLOC_F),)
 subtract_sys_malloc_f_len = space=$$(($${space} - $(CONFIG_SYS_MALLOC_F_LEN)))
 else
 subtract_sys_malloc_f_len = true
@@ -1313,7 +1317,7 @@ shell_cmd = { $(call echo-cmd,$(1)) $(cmd_$(1)); }
 
 quiet_cmd_objcopy_uboot = OBJCOPY $@
 ifdef cmd_static_rela
-cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || { rm -f $@; false; }
+cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_TEXT_BASE)) || { rm -f $@; false; }
 else
 cmd_objcopy_uboot = $(cmd_objcopy)
 endif
@@ -1330,17 +1334,31 @@ u-boot.ldr:     u-boot
 # binman
 # ---------------------------------------------------------------------------
 # Use 'make BINMAN_DEBUG=1' to enable debugging
+# Use 'make BINMAN_VERBOSE=3' to set vebosity level
 default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE))
+
 quiet_cmd_binman = BINMAN  $@
 cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
+               $(foreach f,$(BINMAN_TOOLPATHS),--toolpath $(f)) \
                 --toolpath $(objtree)/tools \
                $(if $(BINMAN_VERBOSE),-v$(BINMAN_VERBOSE)) \
-               build -u -d u-boot.dtb -O . -m --allow-missing \
+               build -u -d u-boot.dtb -O . -m \
+               --allow-missing $(if $(BINMAN_ALLOW_MISSING),--ignore-missing) \
                -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
                -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
+               $(foreach f,$(BINMAN_INDIRS),-I $(f)) \
                -a atf-bl31-path=${BL31} \
+               -a tee-os-path=${TEE} \
+               -a ti-dm-path=${TI_DM} \
+               -a opensbi-path=${OPENSBI} \
                -a default-dt=$(default_dt) \
                -a scp-path=$(SCP) \
+               -a rockchip-tpl-path=$(ROCKCHIP_TPL) \
+               -a spl-bss-pad=$(if $(CONFIG_SPL_SEPARATE_BSS),,1) \
+               -a tpl-bss-pad=$(if $(CONFIG_TPL_SEPARATE_BSS),,1) \
+               -a spl-dtb=$(CONFIG_SPL_OF_REAL) \
+               -a tpl-dtb=$(CONFIG_TPL_OF_REAL) \
+               -a pre-load-key-path=${PRE_LOAD_KEY_PATH} \
                $(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
@@ -1350,14 +1368,6 @@ OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
 u-boot.ldr.hex u-boot.ldr.srec: u-boot.ldr FORCE
        $(call if_changed,objcopy)
 
-#
-# U-Boot entry point, needed for booting of full-blown U-Boot
-# from the SPL U-Boot version.
-#
-ifndef CONFIG_SYS_UBOOT_START
-CONFIG_SYS_UBOOT_START := $(CONFIG_SYS_TEXT_BASE)
-endif
-
 # Boards with more complex image requirements can provide an .its source file
 # or a generator script
 # NOTE: Please do not use this. We are migrating away from Makefile rules to use
@@ -1369,12 +1379,6 @@ $(U_BOOT_ITS): $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
 else
 ifneq ($(CONFIG_USE_SPL_FIT_GENERATOR),)
 U_BOOT_ITS := u-boot.its
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-imx/mkimage_fit_atf.sh")
-U_BOOT_ITS_DEPS += u-boot-nodtb.bin
-endif
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-rockchip/make_fit_atf.py")
-U_BOOT_ITS_DEPS += u-boot
-endif
 $(U_BOOT_ITS): $(U_BOOT_ITS_DEPS) FORCE
        $(srctree)/$(CONFIG_SPL_FIT_GENERATOR) \
        $(patsubst %,arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) > $@
@@ -1383,7 +1387,7 @@ endif
 
 ifdef CONFIG_SPL_LOAD_FIT
 MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
-       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+       -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
        -p $(CONFIG_FIT_EXTERNAL_OFFSET) \
        -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board" -E \
        $(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(DEVICE_TREE))) \
@@ -1391,10 +1395,10 @@ MKIMAGEFLAGS_u-boot.img = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
        $(patsubst %,-b arch/$(ARCH)/dts/%.dtbo,$(subst ",,$(CONFIG_OF_OVERLAY_LIST)))
 else
 MKIMAGEFLAGS_u-boot.img = -A $(ARCH) -T firmware -C none -O u-boot \
-       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+       -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
        -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
 MKIMAGEFLAGS_u-boot-ivt.img = -A $(ARCH) -T firmware_ivt -C none -O u-boot \
-       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+       -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
        -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
 u-boot-ivt.img: MKIMAGEOUTPUT = u-boot-ivt.img.log
 endif
@@ -1413,23 +1417,19 @@ KWD_CONFIG_FILE = $(shell \
        fi)
 
 MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \
-       -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
+       -T kwbimage -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE)
 
-MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \
-       -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
+MKIMAGEFLAGS_u-boot-with-spl.kwb = -n $(KWD_CONFIG_FILE) \
+       -T kwbimage -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE) \
        $(if $(KEYDIR),-k $(KEYDIR))
 
 MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
-               -R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -T pblimage
+               -R $(srctree)/$(CONFIG_SYS_FSL_PBL_PBI:"%"=%) -A $(ARCH) -T pblimage
 
-ifeq ($(CONFIG_MPC85xx)$(CONFIG_OF_SEPARATE),yy)
-UBOOT_BIN := u-boot-with-dtb.bin
-else
 UBOOT_BIN := u-boot.bin
-endif
 
 MKIMAGEFLAGS_u-boot-lzma.img = -A $(ARCH) -T standalone -C lzma -O u-boot \
-       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+       -a $(CONFIG_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
        -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
 
 u-boot.bin.lzma: u-boot.bin FORCE
@@ -1440,7 +1440,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_SANDBOX),dts/dt.dtb) \
                ,$(UBOOT_BIN)) FORCE
        $(call if_changed,mkimage)
        $(BOARD_SIZE_CHECK)
@@ -1450,20 +1450,20 @@ MKIMAGEFLAGS_u-boot.itb =
 else
 MKIMAGEFLAGS_u-boot.itb = -E
 endif
+MKIMAGEFLAGS_u-boot.itb += -B 0x8
 
 ifdef U_BOOT_ITS
 u-boot.itb: 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_SANDBOX),dts/dt.dtb) \
+               $(if $(CONFIG_MULTI_DTB_FIT),$(FINAL_DTB_CONTAINER)) \
                $(U_BOOT_ITS) FORCE
        $(call if_changed,mkfitimage)
        $(BOARD_SIZE_CHECK)
 endif
 
-u-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE
+u-boot-with-spl.kwb: u-boot.bin spl/u-boot-spl.bin FORCE
        $(call if_changed,mkimage)
-
-u-boot.sha1:   u-boot.bin
-               tools/ubsha1 u-boot.bin
+       $(BOARD_SIZE_CHECK)
 
 u-boot.dis:    u-boot
                $(OBJDUMP) -d $< > $@
@@ -1481,30 +1481,6 @@ OBJCOPYFLAGS_u-boot-with-spl.bin = -I binary -O binary \
 u-boot-with-spl.bin: $(SPL_IMAGE) $(SPL_PAYLOAD) FORCE
        $(call if_changed,pad_cat)
 
-ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
-
-# TPL + SPL
-ifeq ($(CONFIG_SPL)$(CONFIG_TPL),yy)
-MKIMAGEFLAGS_u-boot-tpl-rockchip.bin = -n $(CONFIG_SYS_SOC) -T rksd
-tpl/u-boot-tpl-rockchip.bin: tpl/u-boot-tpl.bin FORCE
-       $(call if_changed,mkimage)
-idbloader.img: tpl/u-boot-tpl-rockchip.bin spl/u-boot-spl.bin FORCE
-       $(call if_changed,cat)
-else
-MKIMAGEFLAGS_idbloader.img = -n $(CONFIG_SYS_SOC) -T rksd
-idbloader.img: spl/u-boot-spl.bin FORCE
-       $(call if_changed,mkimage)
-endif
-
-ifeq ($(CONFIG_ARM64),y)
-OBJCOPYFLAGS_u-boot-rockchip.bin = -I binary -O binary \
-       --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff
-u-boot-rockchip.bin: idbloader.img u-boot.itb FORCE
-       $(call if_changed,pad_cat)
-endif # CONFIG_ARM64
-
-endif # CONFIG_ARCH_ROCKCHIP
-
 ifeq ($(CONFIG_ARCH_LPC32XX)$(CONFIG_SPL),yy)
 MKIMAGEFLAGS_lpc32xx-spl.img = -T lpc32xximage -a $(CONFIG_SPL_TEXT_BASE)
 
@@ -1534,7 +1510,7 @@ tpl/u-boot-with-tpl.bin: tpl/u-boot-tpl.bin u-boot.bin FORCE
 SPL: spl/u-boot-spl.bin FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 
-ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y)
+#ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y)
 ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y)
 u-boot.cnt: u-boot.bin FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
@@ -1542,21 +1518,31 @@ 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)
+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 $@
 
-u-boot-with-spl.imx u-boot-with-nand-spl.imx: SPL u-boot.bin FORCE
+u-boot-nand.imx: u-boot.imx FORCE
        $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
 
-MKIMAGEFLAGS_u-boot.ubl = -n $(UBL_CONFIG) -T ublimage -e $(CONFIG_SYS_TEXT_BASE)
+u-boot-with-spl.imx u-boot-with-nand-spl.imx: SPL $(if $(CONFIG_OF_SEPARATE),u-boot.img,u-boot.uim) FORCE
+       $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
+
+MKIMAGEFLAGS_u-boot.ubl = -n $(UBL_CONFIG) -T ublimage -e $(CONFIG_TEXT_BASE)
 
 u-boot.ubl: u-boot-with-spl.bin FORCE
        $(call if_changed,mkimage)
 
-MKIMAGEFLAGS_u-boot-spl.ais = -s -n $(if $(CONFIG_AIS_CONFIG_FILE), \
-       $(srctree)/$(CONFIG_AIS_CONFIG_FILE:"%"=%),"/dev/null") \
+MKIMAGEFLAGS_u-boot-spl.ais = -s -n "/dev/null" \
        -T aisimage -e $(CONFIG_SPL_TEXT_BASE)
 spl/u-boot-spl.ais: spl/u-boot-spl.bin FORCE
        $(call if_changed,mkimage)
@@ -1570,22 +1556,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           \
@@ -1618,17 +1593,14 @@ u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
 
 endif
 
-ifeq ($(CONFIG_MPC85xx)$(CONFIG_OF_SEPARATE),yy)
-u-boot-with-dtb.bin: u-boot.bin u-boot.dtb \
-       $(if $(CONFIG_MPC85XX_HAVE_RESET_VECTOR), u-boot-br.bin) FORCE
+ifeq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
+u-boot-dtb.bin: u-boot-nodtb.bin u-boot.dtb u-boot-br.bin FORCE
        $(call if_changed,binman)
 
-ifeq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR),y)
 OBJCOPYFLAGS_u-boot-br.bin := -O binary -j .bootpg -j .resetvec
 u-boot-br.bin: u-boot FORCE
        $(call if_changed,objcopy)
 endif
-endif
 
 quiet_cmd_ldr = LD      $@
 cmd_ldr = $(LD) $(LDFLAGS_$(@F)) \
@@ -1685,12 +1657,8 @@ spl/u-boot-spl.pbl: spl/u-boot-spl.bin FORCE
 ifeq ($(ARCH),arm)
 UBOOT_BINLOAD := u-boot.img
 else
-ifeq ($(CONFIG_MPC85xx)$(CONFIG_OF_SEPARATE),yy)
-UBOOT_BINLOAD := u-boot-with-dtb.bin
-else
 UBOOT_BINLOAD := u-boot.bin
 endif
-endif
 
 OBJCOPYFLAGS_u-boot-with-spl-pbl.bin = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
                          --gap-fill=0xff
@@ -1698,21 +1666,11 @@ OBJCOPYFLAGS_u-boot-with-spl-pbl.bin = -I binary -O binary --pad-to=$(CONFIG_SPL
 u-boot-with-spl-pbl.bin: spl/u-boot-spl.pbl $(UBOOT_BINLOAD) FORCE
        $(call if_changed,pad_cat)
 
-# PPC4xx needs the SPL at the end of the image, since the reset vector
-# is located at 0xfffffffc. So we can't use the "u-boot-img.bin" target
-# and need to introduce a new build target with the full blown U-Boot
-# at the start padded up to the start of the SPL image. And then concat
-# the SPL image to the end.
-
-OBJCOPYFLAGS_u-boot-img-spl-at-end.bin := -I binary -O binary \
-       --pad-to=$(CONFIG_UBOOT_PAD_TO) --gap-fill=0xff
-u-boot-img-spl-at-end.bin: u-boot.img spl/u-boot-spl.bin FORCE
-       $(call if_changed,pad_cat)
-
 quiet_cmd_u-boot-elf ?= LD      $@
        cmd_u-boot-elf ?= $(LD) u-boot-elf.o -o $@ \
-       -T u-boot-elf.lds --defsym=$(CONFIG_PLATFORM_ELFENTRY)=$(CONFIG_SYS_TEXT_BASE) \
-       -Ttext=$(CONFIG_SYS_TEXT_BASE)
+       $(if $(CONFIG_SYS_BIG_ENDIAN),-EB,-EL) \
+       -T u-boot-elf.lds --defsym=$(CONFIG_PLATFORM_ELFENTRY)=$(CONFIG_TEXT_BASE) \
+       -Ttext=$(CONFIG_TEXT_BASE)
 u-boot.elf: u-boot.bin u-boot-elf.lds
        $(Q)$(OBJCOPY) -I binary $(PLATFORM_ELFFLAGS) $< u-boot-elf.o
        $(call if_changed,u-boot-elf)
@@ -1728,9 +1686,12 @@ u-boot-elf.lds: arch/u-boot-elf.lds prepare FORCE
 
 ifeq ($(CONFIG_SPL),y)
 spl/u-boot-spl-mtk.bin: spl/u-boot-spl
+
+u-boot-mtk.bin: u-boot-with-spl.bin
+       $(call if_changed,copy)
 else
 MKIMAGEFLAGS_u-boot-mtk.bin = -T mtk_image \
-       -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
+       -a $(CONFIG_TEXT_BASE) -e $(CONFIG_TEXT_BASE) \
        -n "$(patsubst "%",%,$(CONFIG_MTK_BROM_HEADER_INFO))"
 
 u-boot-mtk.bin: u-boot.bin FORCE
@@ -1745,14 +1706,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
+ifeq ($(LTO_ENABLE),y)
+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 = \
+       $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@
+
+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
+ifeq ($(LTO_ENABLE),y)
+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 = \
@@ -1761,7 +1762,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)
@@ -1769,7 +1770,7 @@ ifeq ($(CONFIG_KALLSYMS),y)
 endif
 
 ifeq ($(CONFIG_RISCV),y)
-       @tools/prelink-riscv $@ 0
+       @tools/prelink-riscv $@
 endif
 
 quiet_cmd_sym ?= SYM     $@
@@ -1777,6 +1778,72 @@ quiet_cmd_sym ?= SYM     $@
 u-boot.sym: u-boot FORCE
        $(call if_changed,sym)
 
+# Environment processing
+# ---------------------------------------------------------------------------
+
+# Directory where we expect the .env file, if it exists
+ENV_DIR := $(srctree)/board/$(BOARDDIR)
+
+# Basename of .env file, stripping quotes
+ENV_SOURCE_FILE := $(CONFIG_ENV_SOURCE_FILE:"%"=%)
+
+# Filename of .env file
+ENV_FILE_CFG := $(ENV_DIR)/$(ENV_SOURCE_FILE).env
+
+# Default filename, if CONFIG_ENV_SOURCE_FILE is empty
+ENV_FILE_BOARD := $(ENV_DIR)/$(CONFIG_SYS_BOARD:"%"=%).env
+
+# Select between the CONFIG_ENV_SOURCE_FILE and the default one
+ENV_FILE := $(if $(ENV_SOURCE_FILE),$(ENV_FILE_CFG),$(wildcard $(ENV_FILE_BOARD)))
+
+# Run the environment text file through the preprocessor, but only if it is
+# non-empty, to save time and possible build errors if something is wonky with
+# the board.
+# If there is no ENV_FILE, produce an empty output file, to prevent a previous
+# build's file being used in the case of in-tree builds.
+quiet_cmd_gen_envp = ENVP    $@
+      cmd_gen_envp = \
+       if [ -s "$(ENV_FILE)" ]; then \
+               $(CPP) -P $(CFLAGS) -x assembler-with-cpp -D__ASSEMBLY__ \
+                       -D__UBOOT_CONFIG__ \
+                       -I . -I include -I $(srctree)/include \
+                       -include linux/kconfig.h -include include/config.h \
+                       -I$(srctree)/arch/$(ARCH)/include \
+                       $< -o $@; \
+       else \
+               rm -f $@; \
+               touch $@ ; \
+       fi
+include/generated/env.in: include/generated/env.txt
+       $(call cmd,gen_envp)
+
+# Regenerate the environment if it changes
+# We use 'wildcard' since the file is not required to exist (at present), in
+# which case we don't want this dependency, but instead should create an empty
+# file
+# This rule is useful since it shows the source file for the environment
+quiet_cmd_envc = ENVC    $@
+      cmd_envc = \
+       if [ -f "$<" ]; then \
+               cat $< > $@; \
+       elif [ -n "$(ENV_SOURCE_FILE)" ]; then \
+               echo "Missing file $(ENV_FILE_CFG)"; \
+       else \
+               touch $@ ; \
+       fi
+
+include/generated/env.txt: $(wildcard $(ENV_FILE)) include/generated/autoconf.h
+       $(call cmd,envc)
+
+# Write out the resulting environment, converted to a C string
+quiet_cmd_gen_envt = ENVT    $@
+      cmd_gen_envt = \
+       awk -f $(srctree)/scripts/env2string.awk $< >$@
+$(env_h): include/generated/env.in
+       $(call cmd,gen_envt)
+
+# ---------------------------------------------------------------------------
+
 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
 $(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs) ;
@@ -1832,7 +1899,7 @@ endif
 # prepare2 creates a makefile if using a separate output directory
 prepare2: prepare3 outputmakefile cfg
 
-prepare1: prepare2 $(version_h) $(timestamp_h) $(dt_h) \
+prepare1: prepare2 $(version_h) $(timestamp_h) $(dt_h) $(env_h) \
                    include/config/auto.conf
 ifeq ($(wildcard $(LDSCRIPT)),)
        @echo >&2 "  Could not find linker script."
@@ -1841,6 +1908,8 @@ endif
 
 ifeq ($(CONFIG_USE_DEFAULT_ENV_FILE),y)
 prepare1: $(defaultenv_h)
+
+envtools: $(defaultenv_h)
 endif
 
 archprepare: prepare1 scripts_basic
@@ -1880,8 +1949,6 @@ define filechk_timestamp.h
                        LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DATE "%b %d %C%y"'; \
                        LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TIME "%T"'; \
                        LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TZ "%z"'; \
-                       LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; \
-                       LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_BUILD_DATE 0x%Y%m%d'; \
                        LC_ALL=C $${DATE} -u -d "$${SOURCE_DATE}" +'#define U_BOOT_EPOCH %s'; \
                else \
                        return 42; \
@@ -1890,18 +1957,15 @@ define filechk_timestamp.h
                LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"'; \
                LC_ALL=C date +'#define U_BOOT_TIME "%T"'; \
                LC_ALL=C date +'#define U_BOOT_TZ "%z"'; \
-               LC_ALL=C date +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; \
-               LC_ALL=C date +'#define U_BOOT_BUILD_DATE 0x%Y%m%d'; \
                LC_ALL=C date +'#define U_BOOT_EPOCH %s'; \
        fi)
 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
@@ -1924,6 +1988,51 @@ $(dt_h): $(srctree)/Makefile FORCE
 $(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)
+
+endif
+
+# Check dtc and pylibfdt, if DTC is provided, else build them
+PHONY += scripts_dtc
+scripts_dtc: scripts_basic
+       $(Q)if test "$(DTC)" = "$(DTC_INTREE)"; then \
+               $(MAKE) $(build)=scripts/dtc; \
+       else \
+               if ! $(DTC) -v >/dev/null; then \
+                       echo '*** Failed to check dtc version: $(DTC)'; \
+                       false; \
+               else \
+                       if test "$(call dtc-version)" -lt $(DTC_MIN_VERSION); then \
+                               echo '*** Your dtc is too old, please upgrade to dtc $(DTC_MIN_VERSION) or newer'; \
+                               false; \
+                       else \
+                               if [ -n "$(CONFIG_PYLIBFDT)" ]; then \
+                                       if ! echo "import libfdt" | $(PYTHON3) 2>/dev/null; then \
+                                               echo '*** pylibfdt does not seem to be available with $(PYTHON3)'; \
+                                               false; \
+                                       fi; \
+                               fi; \
+                       fi; \
+               fi; \
+       fi
+
 # ---------------------------------------------------------------------------
 quiet_cmd_cpp_lds = LDS     $@
 cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \
@@ -1936,9 +2045,13 @@ spl/u-boot-spl.bin: spl/u-boot-spl
        @:
        $(SPL_SIZE_CHECK)
 
-spl/u-boot-spl: tools prepare \
-               $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb) \
-               $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_TPL_OF_PLATDATA),dts/dt.dtb)
+spl/u-boot-spl-dtb.bin: spl/u-boot-spl
+       @:
+
+spl/u-boot-spl-dtb.hex: spl/u-boot-spl
+       @:
+
+spl/u-boot-spl: tools prepare $(if $(CONFIG_SPL_OF_CONTROL),dts/dt.dtb)
        $(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all
 
 spl/sunxi-spl.bin: spl/u-boot-spl
@@ -1953,11 +2066,20 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
        @:
 
-tpl/u-boot-tpl.bin: tools prepare \
-               $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
-       $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+tpl/u-boot-tpl.bin: tpl/u-boot-tpl
+       @:
        $(TPL_SIZE_CHECK)
 
+tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+       $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+
+vpl/u-boot-vpl.bin: vpl/u-boot-vpl
+       @:
+       $(VPL_SIZE_CHECK)
+
+vpl/u-boot-vpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+       $(Q)$(MAKE) obj=vpl -f $(srctree)/scripts/Makefile.spl all
+
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
 FIND := find
@@ -2003,7 +2125,7 @@ tools/version.h: include/version.h
        $(Q)mkdir -p $(dir $@)
        $(call if_changed,copy)
 
-envtools: scripts_basic $(version_h) $(timestamp_h) tools/version.h
+envtools: u-boot-initial-env scripts_basic $(version_h) $(timestamp_h) tools/version.h
        $(Q)$(MAKE) $(build)=tools/env
 
 tools-only: export TOOLS_ONLY=y
@@ -2032,21 +2154,28 @@ CHANGELOG:
 
 # Directories & files removed with 'make clean'
 CLEAN_DIRS  += $(MODVERDIR) \
-              $(foreach d, spl tpl, $(patsubst %,$d/%, \
+              $(foreach d, spl tpl vpl, $(patsubst %,$d/%, \
                        $(filter-out include, $(shell ls -1 $d 2>/dev/null))))
 
-CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h tools/version.h \
-              boot* u-boot* MLO* SPL System.map fit-dtb.blob* \
+CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h include/bmp_logo_data.h \
+              include/config.h include/generated/env.* drivers/video/u_boot_logo.S \
+              tools/version.h 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 \
+              mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
+              itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
+              mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
+              idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
 
 # Directories & files removed with 'make mrproper'
-MRPROPER_DIRS  += include/config include/generated spl tpl \
-                 .tmp_objdiff doc/output
+MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
+                 .tmp_objdiff doc/output include/asm
+
+# 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
 #
@@ -2067,12 +2196,15 @@ clean: $(clean-dirs)
        @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
                \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
                -o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \
+               -o -name '*.dtb' -o -name '*.dtbo' \
+               -o -name '*.dtb.S' -o -name '*.dtbo.S' \
                -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
                -o -name '*.lex.c' -o -name '*.tab.[ch]' \
                -o -name '*.asn1.[ch]' \
                -o -name '*.symtypes' -o -name 'modules.order' \
                -o -name modules.builtin -o -name '.tmp_*.o.*' \
-               -o -name 'dsdt.aml' -o -name 'dsdt.asl.tmp' -o -name 'dsdt.c' \
+               -o -name 'dsdt_generated.aml' -o -name 'dsdt_generated.asl.tmp' \
+               -o -name 'dsdt_generated.c' \
                -o -name '*.efi' -o -name '*.gcno' -o -name '*.so' \) \
                -type f -print | xargs rm -f
 
@@ -2104,10 +2236,73 @@ distclean: mrproper
                -type f -print | xargs rm -f
        @rm -f boards.cfg CHANGELOG
 
+# See doc/develop/python_cq.rst
+PHONY += pylint pylint_err
+PYLINT_BASE := scripts/pylint.base
+PYLINT_CUR := pylint.cur
+PYLINT_DIFF := pylint.diff
+pylint:
+       $(Q)echo "Running pylint on all files (summary in $(PYLINT_CUR); output in pylint.out/)"
+       $(Q)mkdir -p pylint.out
+       $(Q)rm -f pylint.out/out*
+       $(Q)find tools test -name "*.py" \
+               | xargs -n1 -P$(shell nproc 2>/dev/null || echo 1) \
+                       sh -c 'pylint --reports=y --exit-zero -f parseable --ignore-imports=yes $$@ > pylint.out/$$(echo $$@ | tr / _ | sed s/.py//)' _
+       $(Q)rm -f $(PYLINT_CUR)
+       $(Q)( cd pylint.out; for f in *; do \
+               sed -ne "s/Your code has been rated at \([-0-9.]*\).*/$$f \1/p" $$f; \
+       done ) | sort > $(PYLINT_CUR)
+       $(Q)base=$$(mktemp) cur=$$(mktemp); cut -d' ' -f1 $(PYLINT_BASE) >$$base; \
+               cut -d' ' -f1 $(PYLINT_CUR) >$$cur; \
+               comm -3 $$base $$cur > $(PYLINT_DIFF); \
+               if [ -s $(PYLINT_DIFF) ]; then \
+                       echo "Files have been added/removed. Try:\n\tcp $(PYLINT_CUR) $(PYLINT_BASE)"; \
+                       echo; \
+                       echo "Added files:"; \
+                       comm -13 $$base $$cur; \
+                       echo; \
+                       echo "Removed files:"; \
+                       comm -23 $$base $$cur; \
+                       false; \
+               else \
+                       rm $$base $$cur $(PYLINT_DIFF); \
+               fi
+       $(Q)bad=false; while read base_file base_val <&3 && read cur_file cur_val <&4; do \
+               if awk "BEGIN {exit !($$cur_val < $$base_val)}"; then \
+                       echo "$$base_file: Score was $$base_val, now $$cur_val"; \
+                       bad=true; fi; \
+               done 3<$(PYLINT_BASE) 4<$(PYLINT_CUR); \
+               if $$bad; then \
+                       echo "Some files have regressed, please fix"; \
+                       false; \
+               else \
+                       echo "No pylint regressions"; \
+               fi
+
+# Check for errors only
+pylint_err:
+       $(Q)pylint -E  -j 0 --ignore-imports=yes \
+               $(shell find tools test -name "*.py")
+
 backup:
        F=`basename $(srctree)` ; cd .. ; \
        gtar --force-local -zcvf `LC_ALL=C date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
 
+PHONY += _pip pip pip_release
+
+pip_release: PIP_ARGS="--real"
+pip_test: PIP_ARGS=""
+pip: PIP_ARGS="-n"
+
+pip pip_test pip_release: _pip
+
+_pip:
+       scripts/make_pip.sh u_boot_pylib ${PIP_ARGS}
+       scripts/make_pip.sh patman ${PIP_ARGS}
+       scripts/make_pip.sh buildman ${PIP_ARGS}
+       scripts/make_pip.sh dtoc ${PIP_ARGS}
+       scripts/make_pip.sh binman ${PIP_ARGS}
+
 help:
        @echo  'Cleaning targets:'
        @echo  '  clean           - Remove most generated files but keep the config'
@@ -2120,8 +2315,10 @@ help:
        @echo  'Test targets:'
        @echo  ''
        @echo  '  check           - Run all automated tests that use sandbox'
+       @echo  '  pcheck          - Run quick automated tests in parallel'
        @echo  '  qcheck          - Run quick automated tests that use sandbox'
        @echo  '  tcheck          - Run quick automated tests on tools'
+       @echo  '  pylint          - Run pylint on all Python files'
        @echo  ''
        @echo  'Other generic targets:'
        @echo  '  all             - Build all necessary images depending on configuration'
@@ -2139,6 +2336,11 @@ help:
        @echo  "  cfg             - Don't build, just create the .cfg files"
        @echo  "  envtools        - Build only the target-side environment tools"
        @echo  ''
+       @echo  'PyPi / pip targets:'
+       @echo  '  pip             - Check building of PyPi packages'
+       @echo  '  pip_test        - Build PyPi pakages and upload to test server'
+       @echo  '  pip_release     - Build PyPi pakages and upload to release server'
+       @echo  ''
        @echo  'Static analysers'
        @echo  '  checkstack      - Generate a list of stack hogs'
        @echo  '  coccicheck      - Execute static code analysis with Coccinelle'
@@ -2164,6 +2366,9 @@ help:
 tests check:
        $(srctree)/test/run
 
+pcheck:
+       $(srctree)/test/run parallel
+
 qcheck:
        $(srctree)/test/run quick
 
@@ -2173,14 +2378,11 @@ tcheck:
 # Documentation targets
 # ---------------------------------------------------------------------------
 DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
-              linkcheckdocs dochelp refcheckdocs
+              linkcheckdocs dochelp refcheckdocs texinfodocs infodocs
 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:
@@ -2242,11 +2444,14 @@ endif
        $(build)=$(build-dir) $(@:.ko=.o)
        $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
-quiet_cmd_genenv = GENENV $@
-cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-       sed --in-place -e 's/\x00/\x0A/g' $@
+quiet_cmd_genenv = GENENV  $@
+cmd_genenv = \
+       $(objtree)/tools/printinitialenv | \
+       sed -e '/^\s*$$/d' | \
+       sort -t '=' -k 1,1 -s -o $@
 
-u-boot-initial-env: u-boot.bin
+u-boot-initial-env: scripts_basic $(env_h) FORCE
+       $(Q)$(MAKE) $(build)=tools $(objtree)/tools/printinitialenv
        $(call if_changed,genenv)
 
 # Consistency checks
@@ -2268,13 +2473,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