net: remove unused CONFIG_DRIVER_AT91EMAC_*
[platform/kernel/u-boot.git] / scripts / Makefile.spl
index ea4e045..7f8c5f0 100644 (file)
@@ -67,6 +67,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)
@@ -102,7 +108,7 @@ 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_UNIT_TEST) += test/
 
 head-y         := $(addprefix $(obj)/,$(head-y))
@@ -120,10 +126,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-plat.o
-u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
+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),)
@@ -229,6 +250,8 @@ ifneq ($(CONFIG_TARGET_SOCFPGA_GEN5)$(CONFIG_TARGET_SOCFPGA_ARRIA10),)
 INPUTS-y       += $(obj)/$(SPL_BIN).sfp
 endif
 
+INPUTS-$(CONFIG_TARGET_SOCFPGA_SOC64) += $(obj)/u-boot-spl-dtb.hex
+
 ifdef CONFIG_ARCH_SUNXI
 INPUTS-y       += $(obj)/sunxi-spl.bin
 
@@ -309,7 +332,11 @@ $(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE
 pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 
 DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
-       -d $(obj)/$(SPL_BIN).dtb
+       -d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
+
+ifneq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA_INST),)
+DTOC_ARGS += -i
+endif
 
 quiet_cmd_dtoc = DTOC    $@
 cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
@@ -317,18 +344,17 @@ 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 += $(u-boot-spl-platdata)
-
-$(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c \
-               include/generated/dt-structs-gen.h prepare 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 $(u-boot-spl-platdata_c) &: \
-               $(obj)/$(SPL_BIN).dtb dts_dir FORCE
+# 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
@@ -373,6 +399,8 @@ 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)
 
+LDFLAGS_$(SPL_BIN) += --build-id=none
+
 # Pick the best-match (i.e. 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)
@@ -389,6 +417,11 @@ $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
 MKIMAGEFLAGS_sunxi-spl.bin = -T sunxi_egon \
        -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,mkimage)
 
@@ -417,18 +450,65 @@ quiet_cmd_sym ?= SYM     $@
 $(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) ;
@@ -464,6 +544,10 @@ FORCE:
 $(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)