Convert CONFIG_SPL_PAD_TO et al to Kconfig
[platform/kernel/u-boot.git] / scripts / Makefile.spl
index 4c2c056..c1d32f5 100644 (file)
@@ -22,24 +22,43 @@ include $(srctree)/scripts/Kbuild.include
 -include include/config/auto.conf
 -include $(obj)/include/autoconf.mk
 
+UBOOTINCLUDE := -I$(obj)/include $(UBOOTINCLUDE)
+
 KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
 ifeq ($(CONFIG_TPL_BUILD),y)
 KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
+else
+ifeq ($(CONFIG_VPL_BUILD),y)
+KBUILD_CPPFLAGS += -DCONFIG_VPL_BUILD
+endif
 endif
 
+ifeq ($(CONFIG_VPL_BUILD),y)
+SPL_BIN := u-boot-vpl
+SPL_NAME := vpl
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 SPL_BIN := u-boot-tpl
+SPL_NAME := tpl
 else
 SPL_BIN := u-boot-spl
+SPL_NAME := spl
+endif
 endif
 
+export SPL_NAME
+
 ifdef CONFIG_SPL_BUILD
 SPL_ := SPL_
+ifeq ($(CONFIG_VPL_BUILD),y)
+SPL_TPL_ := VPL_
+else
 ifeq ($(CONFIG_TPL_BUILD),y)
 SPL_TPL_ := TPL_
 else
 SPL_TPL_ := SPL_
 endif
+endif
 else
 SPL_ :=
 SPL_TPL_ :=
@@ -51,6 +70,9 @@ endif
 ifeq ($(obj)$(CONFIG_SUPPORT_TPL),tpl)
 $(error You cannot build TPL without enabling CONFIG_SUPPORT_TPL)
 endif
+ifeq ($(obj)$(CONFIG_SUPPORT_VPL),vpl)
+$(error You cannot build VPL without enabling CONFIG_SUPPORT_VPL)
+endif
 
 include $(srctree)/config.mk
 include $(srctree)/arch/$(ARCH)/Makefile
@@ -61,6 +83,12 @@ include $(srctree)/scripts/Makefile.lib
 KBUILD_CFLAGS += -ffunction-sections -fdata-sections
 LDFLAGS_FINAL += --gc-sections
 
+ifeq ($(CONFIG_$(SPL_TPL_)STACKPROTECTOR),y)
+KBUILD_CFLAGS += -fstack-protector-strong
+else
+KBUILD_CFLAGS += -fno-stack-protector
+endif
+
 # FIX ME
 cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
                                                        $(NOSTDINC_FLAGS)
@@ -78,17 +106,12 @@ libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
 endif
 libs-y += common/init/
 
-# Special handling for a few options which support SPL/TPL
-ifeq ($(CONFIG_TPL_BUILD),y)
-libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
-libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/
-else
-libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ env/
-libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
+# Special handling for a few options which support SPL/TPL/VPL
+libs-$(CONFIG_$(SPL_TPL_)LIBCOMMON_SUPPORT) += boot/ common/ cmd/ env/
+libs-$(CONFIG_$(SPL_TPL_)LIBGENERIC_SUPPORT) += lib/
 ifdef CONFIG_SPL_FRAMEWORK
 libs-$(CONFIG_PARTITIONS) += disk/
 endif
-endif
 
 libs-y += drivers/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
@@ -96,7 +119,8 @@ libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
 libs-y += dts/
 libs-y += fs/
 libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
-libs-$(CONFIG_SPL_NET_SUPPORT) += net/
+libs-$(CONFIG_SPL_NET) += net/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 
 head-y         := $(addprefix $(obj)/,$(head-y))
 libs-y         := $(addprefix $(obj)/,$(libs-y))
@@ -113,9 +137,25 @@ endif
 u-boot-spl-init := $(head-y)
 u-boot-spl-main := $(libs-y)
 ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
-u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
+platdata-hdr := include/generated/dt-structs-gen.h include/generated/dt-decl.h
+platdata-inst := $(obj)/dts/dt-uclass.o $(obj)/dts/dt-device.o
+platdata-noinst := $(obj)/dts/dt-plat.o
+
+ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA_INST
+u-boot-spl-platdata := $(platdata-inst)
+u-boot-spl-old-platdata := $(platdata-noinst)
+else
+u-boot-spl-platdata := $(platdata-noinst)
+u-boot-spl-old-platdata := $(platdata-inst)
 endif
 
+# Files we need to generate
+u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
+
+# Files we won't generate and should remove
+u-boot-spl-old-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-old-platdata))
+endif  # OF_PLATDATA
+
 # Linker Script
 # First test whether there's a linker-script for the specific stage defined...
 ifneq ($(CONFIG_$(SPL_TPL_)LDSCRIPT),)
@@ -153,8 +193,8 @@ LDPPFLAGS += \
          sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
 
 # Turn various CONFIG symbols into IMAGE symbols for easy reuse of
-# the scripts between SPL and TPL.
-ifneq ($(CONFIG_$(SPL_TPL_)MAX_SIZE),)
+# the scripts between SPL, TPL and VPL.
+ifneq ($(CONFIG_$(SPL_TPL_)MAX_SIZE),0x0)
 LDPPFLAGS += -DIMAGE_MAX_SIZE=$(CONFIG_$(SPL_TPL_)MAX_SIZE)
 endif
 ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
@@ -211,42 +251,46 @@ spl/boot.bin: $(obj)/$(SPL_BIN)-align.bin FORCE
        $(call if_changed,mkimage)
 endif
 
-ALL-y  += $(obj)/$(SPL_BIN).bin
+INPUTS-y       += $(obj)/$(SPL_BIN).bin $(obj)/$(SPL_BIN).sym
 
 ifdef CONFIG_SAMSUNG
-ALL-y  += $(obj)/$(BOARD)-spl.bin
+INPUTS-y       += $(obj)/$(BOARD)-spl.bin
 endif
 
 ifneq ($(CONFIG_TARGET_SOCFPGA_GEN5)$(CONFIG_TARGET_SOCFPGA_ARRIA10),)
-ALL-y  += $(obj)/$(SPL_BIN).sfp
+INPUTS-y       += $(obj)/$(SPL_BIN).sfp
 endif
 
+INPUTS-$(CONFIG_TARGET_SOCFPGA_SOC64) += $(obj)/u-boot-spl-dtb.hex
+
 ifdef CONFIG_ARCH_SUNXI
-ALL-y  += $(obj)/sunxi-spl.bin
+INPUTS-y       += $(obj)/sunxi-spl.bin
 
 ifdef CONFIG_NAND_SUNXI
-ALL-y  += $(obj)/sunxi-spl-with-ecc.bin
+INPUTS-y       += $(obj)/sunxi-spl-with-ecc.bin
 endif
 endif
 
 ifeq ($(CONFIG_SYS_SOC),"at91")
-ALL-y  += $(obj)/boot.bin
+INPUTS-y       += $(obj)/boot.bin
 endif
 
+ifndef CONFIG_VPL_BUILD
 ifdef CONFIG_TPL_BUILD
-ALL-$(CONFIG_TPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-tpl.bin \
+INPUTS-$(CONFIG_TPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-tpl.bin \
        $(obj)/u-boot-x86-reset16-tpl.bin
 else
-ALL-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-spl.bin \
+INPUTS-$(CONFIG_SPL_X86_16BIT_INIT) += $(obj)/u-boot-x86-start16-spl.bin \
        $(obj)/u-boot-x86-reset16-spl.bin
 endif
+endif
 
-ALL-$(CONFIG_ARCH_ZYNQ)                += $(obj)/boot.bin
-ALL-$(CONFIG_ARCH_ZYNQMP)      += $(obj)/boot.bin
+INPUTS-$(CONFIG_ARCH_ZYNQ)             += $(obj)/boot.bin
+INPUTS-$(CONFIG_ARCH_ZYNQMP)   += $(obj)/boot.bin
 
-ALL-$(CONFIG_ARCH_MEDIATEK)    += $(obj)/u-boot-spl-mtk.bin
+INPUTS-$(CONFIG_ARCH_MEDIATEK) += $(obj)/u-boot-spl-mtk.bin
 
-all:   $(ALL-y)
+all:   $(INPUTS-y)
 
 quiet_cmd_cat = CAT     $@
 cmd_cat = cat $(filter-out $(PHONY), $^) > $@
@@ -264,22 +308,19 @@ else
 FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit
 endif
 
-# Build the .dtb file if:
-#   - we are not using OF_PLATDATA
-#   - we are using OF_CONTROL
+# Build the .dtb file if needed
+#   - OF_REAL is enabled
 #   - we have either OF_SEPARATE or OF_HOSTFILE
 build_dtb :=
-ifeq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA),)
-ifneq ($(CONFIG_$(SPL_TPL_)OF_CONTROL),)
-ifeq ($(CONFIG_OF_SEPARATE)$(CONFIG_OF_HOSTFILE),y)
+ifneq ($(CONFIG_$(SPL_TPL_)OF_REAL),)
+ifeq ($(CONFIG_OF_SEPARATE)$(CONFIG_SANDBOX),y)
 build_dtb := y
 endif
 endif
-endif
 
 ifneq ($(build_dtb),)
 $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
-               $(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
+               $(if $(CONFIG_$(SPL_TPL_)SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
                $(FINAL_DTB_CONTAINER)  FORCE
        $(call if_changed,cat)
 
@@ -295,34 +336,36 @@ $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN)
        @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \
        dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null;
 
-$(obj)/$(SPL_BIN).dtb: dts/dt-spl.dtb FORCE
+$(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE
        $(call if_changed,copy)
 
 pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 
-quiet_cmd_dtocc = DTOC C  $@
-cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
+DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
+       -d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
+
+ifneq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA_INST),)
+DTOC_ARGS += -i
+endif
 
-quiet_cmd_dtoch = DTOC H  $@
-cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct
+quiet_cmd_dtoc = DTOC    $@
+cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
 
 quiet_cmd_plat = PLAT    $@
 cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@)
 
-targets += $(obj)/dts/dt-platdata.o
-$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \
-               include/generated/dt-structs-gen.h FORCE
+$(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c $(platdata-hdr)
        $(call if_changed,plat)
 
-PHONY += dts_dir
-dts_dir:
-       $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
-
-include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
-       $(call if_changed,dtoch)
-
-$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
-       $(call if_changed,dtocc)
+# Don't use dts_dir here, since it forces running this expensive rule every time
+$(platdata-hdr) $(u-boot-spl-platdata_c) &: $(obj)/$(SPL_BIN).dtb
+       @[ -d $(obj)/dts ] || mkdir -p $(obj)/dts
+       @# Remove old files since which ones we generate depends on the setting
+       @# of OF_PLATDATA_INST and this might change between builds. Leaving old
+       @# ones around is confusing and it is possible that switching the
+       @# setting again will use the old one instead of regenerating it.
+       @rm -f $(u-boot-spl-all-platdata_c) $(u-boot-spl-all-platdata)
+       $(call if_changed,dtoc)
 
 ifdef CONFIG_SAMSUNG
 ifdef CONFIG_VAR_SIZE_SPL
@@ -366,7 +409,9 @@ LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
 # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
 LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker)
 
-# Pick the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
+LDFLAGS_$(SPL_BIN) += --build-id=none
+
+# Pick the best match (e.g. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
 ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),)
 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE)
 endif
@@ -379,11 +424,19 @@ endif
 $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
        $(call if_changed,mkimage)
 
-quiet_cmd_mksunxiboot = MKSUNXI $@
-cmd_mksunxiboot = $(objtree)/tools/mksunxiboot \
-                       --default-dt $(CONFIG_DEFAULT_DEVICE_TREE) $< $@
+MKIMAGEFLAGS_sunxi-spl.bin = \
+       -A $(ARCH) \
+       -T $(CONFIG_SPL_IMAGE_TYPE) \
+       -a $(CONFIG_SPL_TEXT_BASE) \
+       -n $(CONFIG_DEFAULT_DEVICE_TREE)
+
+OBJCOPYFLAGS_u-boot-spl-dtb.hex := -I binary -O ihex --change-address=$(CONFIG_SPL_TEXT_BASE)
+
+$(obj)/u-boot-spl-dtb.hex: $(obj)/u-boot-spl-dtb.bin FORCE
+       $(call if_changed,objcopy)
+
 $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE
-       $(call if_changed,mksunxiboot)
+       $(call if_changed,mkimage)
 
 quiet_cmd_sunxi_spl_image_builder = SUNXI_SPL_IMAGE_BUILDER $@
 cmd_sunxi_spl_image_builder = $(objtree)/tools/sunxi-spl-image-builder \
@@ -405,26 +458,82 @@ MKIMAGEFLAGS_u-boot-spl-mtk.bin = -T mtk_image \
 $(obj)/u-boot-spl-mtk.bin: $(obj)/u-boot-spl.bin FORCE
        $(call if_changed,mkimage)
 
+quiet_cmd_sym ?= SYM     $@
+      cmd_sym ?= $(OBJDUMP) -t $< > $@
+$(obj)/$(SPL_BIN).sym: $(obj)/$(SPL_BIN) FORCE
+       $(call if_changed,sym)
+
+# Generate linker list symbols references to force compiler to not optimize
+# them away when compiling with LTO
+ifdef CONFIG_LTO
+u-boot-spl-keep-syms-lto := $(obj)/keep-syms-lto.o
+u-boot-spl-keep-syms-lto_c := \
+       $(patsubst $(obj)/%.o,$(obj)/%.c,$(u-boot-spl-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-spl-keep-syms-lto_c): $(u-boot-spl-main) $(u-boot-spl-platdata)
+       $(call if_changed,keep_syms_lto)
+$(u-boot-spl-keep-syms-lto): $(u-boot-spl-keep-syms-lto_c)
+       $(call if_changed,keep_syms_lto_cc)
+else
+u-boot-spl-keep-syms-lto :=
+endif
+
 # Rule to link u-boot-spl
 # May be overridden by arch/$(ARCH)/config.mk
+ifdef CONFIG_LTO
+quiet_cmd_u-boot-spl ?= LTO     $@
+      cmd_u-boot-spl ?= \
+       (                                                                       \
+               cd $(obj) &&                                                    \
+               $(CC) -nostdlib -nostartfiles $(LTO_FINAL_LDFLAGS) $(c_flags)   \
+               $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_$(@F):%=-Wl,%)              \
+               $(patsubst $(obj)/%,%,$(u-boot-spl-init))                       \
+               -Wl,--whole-archive                                             \
+                       $(patsubst $(obj)/%,%,$(u-boot-spl-main))               \
+                       $(patsubst $(obj)/%,%,$(u-boot-spl-platdata))           \
+                       $(patsubst $(obj)/%,%,$(u-boot-spl-keep-syms-lto))      \
+                       $(PLATFORM_LIBS)                                        \
+               -Wl,--no-whole-archive                                          \
+               -Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)                           \
+       )
+else
 quiet_cmd_u-boot-spl ?= LD      $@
-      cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F)) \
-                      $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
-                      $(patsubst $(obj)/%,%,$(u-boot-spl-main))  \
-                      $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
-                      --end-group \
-                      $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
+      cmd_u-boot-spl ?= \
+       (                                                               \
+               cd $(obj) &&                                            \
+               $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F))                \
+               $(patsubst $(obj)/%,%,$(u-boot-spl-init))               \
+               --whole-archive                                         \
+                       $(patsubst $(obj)/%,%,$(u-boot-spl-main))       \
+                       $(patsubst $(obj)/%,%,$(u-boot-spl-platdata))   \
+               --no-whole-archive                                      \
+               $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)      \
+       )
+endif
 
 $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
-               $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
+               $(u-boot-spl-main) $(u-boot-spl-keep-syms-lto) \
+               $(obj)/u-boot-spl.lds FORCE
        $(call if_changed,u-boot-spl)
 
 $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
 
 PHONY += $(u-boot-spl-dirs)
-$(u-boot-spl-dirs): $(u-boot-spl-platdata)
+$(u-boot-spl-dirs): $(u-boot-spl-platdata) prepare
        $(Q)$(MAKE) $(build)=$@
 
+PHONY += prepare
+prepare:
+       $(Q)$(MAKE) $(build)=$(obj)/.
+
 quiet_cmd_cpp_lds = LDS     $@
 cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
                -D__ASSEMBLY__ -x assembler-with-cpp -std=c99 -P -o $@ $<
@@ -445,19 +554,25 @@ endif
 PHONY += FORCE
 FORCE:
 
-PHONY += dtbs
-dtbs:
-       $(Q)$(MAKE) $(build)=dts dtbs
+$(obj)/dts/dt-$(SPL_NAME).dtb: dts/dt.dtb
+       $(Q)$(MAKE) $(build)=$(obj)/dts spl_dtbs
+
+PHONY += dts_dir
+dts_dir:
+       $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
 
 # Declare the contents of the .PHONY variable as phony.  We keep that
 # information in a variable so we can use it in if_changed and friends.
 .PHONY: $(PHONY)
 
-SHRUNK_ARCH_DTB = $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
+SPL_OF_LIST_TARGETS = $(patsubst %,dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST)))
+SHRUNK_ARCH_DTB = $(addprefix $(obj)/,$(SPL_OF_LIST_TARGETS))
 .SECONDEXPANSION:
-$(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, arch/$(ARCH)/dts/%, $$@)
+$(SHRUNK_ARCH_DTB): $$(patsubst $(obj)/dts/%, arch/$(ARCH)/dts/%, $$@) dts_dir
        $(call if_changed,fdtgrep)
 
+targets += $(SPL_OF_LIST_TARGETS)
+
 MKIMAGEFLAGS_$(SPL_BIN).multidtb.fit = -f auto -A $(ARCH) -T firmware -C none -O u-boot \
        -n "Multi DTB fit image for $(SPL_BIN)" -E \
        $(patsubst %,-b %,$(SHRUNK_ARCH_DTB))