include $(SPLDIR)/config.mk
include $(TOPDIR)/include/autoconf.mk
include $(TOPDIR)/include/autoconf.mk.dep


export ARCH CPU BOARD SOC

MAKEFLAGS +=  --no-print-directory
include $(SPLDIR)/config.mk

all:


spl_lib: $(TIMESTAMP_FILE) $(VERSION_FILE)
		@echo $(ARCH) $(CPU) $(BOARD) $(SOC)
		@echo nand=$(CONFIG_STORAGE_MEDIA_NAND) mmc=$(CONFIG_STORAGE_MEDIA_MMC) nor=$(CONFIG_STORAGE_MEDIA_SPINOR)
		$(MAKE)  -C  $(SPLDIR)/spl all

ifdef CONFIG_SUPPORT_DDR4

fes:
		$(MAKE) -C $(SPLDIR)/fes_init all
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/fes_init/fes1_ddr3.bin fes1_$(CONFIG_SYS_BOARD)_ddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/fes_init/fes1_lpddr3.bin fes1_$(CONFIG_SYS_BOARD)_lpddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/fes_init/fes1_ddr4.bin fes1_$(CONFIG_SYS_BOARD)_ddr4.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/fes_init/fes1_lpddr4.bin fes1_$(CONFIG_SYS_BOARD)_lpddr4.bin > /dev/null
		@cp -v fes1_$(CONFIG_SYS_BOARD)_*ddr*.bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/

boot0:
		$(MAKE)  -C  $(SPLDIR)/boot0 all
ifdef CONFIG_STORAGE_MEDIA_NAND
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_nand_ddr3.bin boot0_nand_$(CONFIG_SYS_BOARD)_ddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_nand_lpddr3.bin boot0_nand_$(CONFIG_SYS_BOARD)_lpddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_nand_ddr4.bin boot0_nand_$(CONFIG_SYS_BOARD)_ddr4.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_nand_lpddr4.bin boot0_nand_$(CONFIG_SYS_BOARD)_lpddr4.bin > /dev/null
		@cp -v boot0_nand_$(CONFIG_SYS_BOARD)_*ddr*.bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/
endif
ifdef CONFIG_STORAGE_MEDIA_MMC
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_sdcard_ddr3.bin boot0_sdcard_$(CONFIG_SYS_BOARD)_ddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_sdcard_lpddr3.bin boot0_sdcard_$(CONFIG_SYS_BOARD)_lpddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_sdcard_ddr4.bin boot0_sdcard_$(CONFIG_SYS_BOARD)_ddr4.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_sdcard_lpddr4.bin boot0_sdcard_$(CONFIG_SYS_BOARD)_lpddr4.bin > /dev/null
		@cp -v boot0_sdcard_$(CONFIG_SYS_BOARD)_*ddr*.bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/
endif
ifdef CONFIG_STORAGE_MEDIA_SPINOR
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_spinor_ddr3.bin boot0_spinor_$(CONFIG_SYS_BOARD)_ddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_spinor_lpddr3.bin boot0_spinor_$(CONFIG_SYS_BOARD)_lpddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_spinor_ddr4.bin boot0_spinor_$(CONFIG_SYS_BOARD)_ddr4.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_spinor_lpddr4.bin boot0_spinor_$(CONFIG_SYS_BOARD)_lpddr4.bin > /dev/null
		@cp -v boot0_spinor_$(CONFIG_SYS_BOARD)_*ddr*.bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/
endif
sboot:
		$(MAKE) -C $(SPLDIR)/sbrom all
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/sbrom/sboot_ddr3.bin sboot_$(CONFIG_SYS_BOARD)_ddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/sbrom/sboot_lpddr3.bin sboot_$(CONFIG_SYS_BOARD)_lpddr3.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/sbrom/sboot_ddr4.bin sboot_$(CONFIG_SYS_BOARD)_ddr4.bin > /dev/null
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/sbrom/sboot_lpddr4.bin sboot_$(CONFIG_SYS_BOARD)_lpddr4.bin > /dev/null
		@cp -v sboot_$(CONFIG_SYS_BOARD)_*ddr*.bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/

else # the ddr3 build

fes:
		$(MAKE) -C $(SPLDIR)/fes_init all
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/fes_init/fes1.bin fes1_$(CONFIG_SYS_BOARD).bin > /dev/null
		@if [ "x$(TINA_BUILD_SYS)" = "xYocto" ] ; then \
			cp -v fes1_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../../sources/meta-tina/recipes-bsp/tina-board/$(TARGET_PLATFORM)-common/bin/fes1_$(CONFIG_SYS_BOARD).bin; \
		else \
			cp -v fes1_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/fes1_$(CONFIG_SYS_BOARD).bin; \
		fi

boot0:
		$(MAKE)  -C  $(SPLDIR)/boot0 all
ifdef CONFIG_STORAGE_MEDIA_NAND
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_nand.bin boot0_nand_$(CONFIG_SYS_BOARD).bin > /dev/null
		@if [ "x$(TINA_BUILD_SYS)" = "xYocto" ] ; then \
			cp -v boot0_nand_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../../sources/meta-tina/recipes-bsp/tina-board/$(TARGET_PLATFORM)-common/bin/boot0_nand_$(CONFIG_SYS_BOARD).bin; \
		else \
			cp -v boot0_nand_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/boot0_nand_$(CONFIG_SYS_BOARD).bin; \
		fi
endif
ifdef CONFIG_STORAGE_MEDIA_MMC
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_sdcard.bin boot0_sdcard_$(CONFIG_SYS_BOARD).bin > /dev/null
		@if [ "x$(TINA_BUILD_SYS)" = "xYocto" ] ; then \
			cp -v boot0_sdcard_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../../sources/meta-tina/recipes-bsp/tina-board/$(TARGET_PLATFORM)-common/bin/boot0_sdcard_$(CONFIG_SYS_BOARD).bin; \
		else \
			cp -v boot0_sdcard_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/boot0_sdcard_$(CONFIG_SYS_BOARD).bin; \
		fi
endif
ifdef CONFIG_STORAGE_MEDIA_SPINOR
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/boot0/boot0_spinor.bin boot0_spinor_$(CONFIG_SYS_BOARD).bin > /dev/null
		@if [ "x$(TINA_BUILD_SYS)" = "xYocto" ] ; then \
			cp -v boot0_spinor_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../../sources/meta-tina/recipes-bsp/tina-board/$(TARGET_PLATFORM)-common/bin/boot0_spinor_$(CONFIG_SYS_BOARD).bin; \
		else \
			cp -v boot0_spinor_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/boot0_spinor_$(CONFIG_SYS_BOARD).bin; \
		fi
endif
sboot:
		$(MAKE) -C $(SPLDIR)/sbrom all
		@$(TOPDIR)/tools/gen_check_sum $(SPLDIR)/sbrom/sboot.bin sboot_$(CONFIG_SYS_BOARD).bin > /dev/null
		@if [ "x$(TINA_BUILD_SYS)" = "xYocto" ] ; then \
			cp -v sboot_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../../sources/meta-tina/recipes-bsp/tina-board/$(TARGET_PLATFORM)-common/bin/sboot_$(CONFIG_SYS_BOARD).bin; \
		else \
			cp -v sboot_$(CONFIG_SYS_BOARD).bin $(TOPDIR)/../../../target/allwinner/$(TARGET_PLATFORM)-common/bin/sboot_$(CONFIG_SYS_BOARD).bin; \
		fi
endif

ifeq ($(CONFIG_SUNXI_SECURE_SYSTEM),y)
spl:    fes boot0 sboot
else
spl:    fes boot0
endif



mkdepend :


depend:

#
# Auto-generate the autoconf.mk file (which is included by all makefiles)
#
# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
# the dep file is only include in this top level makefile to determine when
# to regenerate the autoconf.mk file.


$(SPLDIR)/autoconf.mk: $(obj)include/config.h $(obj)include/configs/$(SOC).h
	@echo Generating $@ ; \
    set -e ; \
    : Extract the config macros ; \
    $(CPP) $(ALL_CFLAGS) -DDO_DEPS_ONLY -dM $(SRCTREE)/include/common.h > $@.tmp && \
	sed -n -f $(SRCTREE)/tools/scripts/define2mk.sed $@.tmp > $@; \
	rm $@.tmp