• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public License
5# as published by the Free Software Foundation; either version 2
6# of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17sinclude $(TOPDIR)/arch/arm/cpu/$(CPU)/config.mk       # include architecture dependend rules
18################################################################################
19
20PWD      := $(shell pwd)
21OPPDIR   := $(subst $(TOPDIR),,$(PWD))
22
23CC       := $(CROSS_COMPILE)gcc
24AR       := $(CROSS_COMPILE)ar
25LD       := $(CROSS_COMPILE)ld
26OBJCOPY  := $(CROSS_COMPILE)objcopy
27OBJDUMP  := $(CROSS_COMPILE)objdump
28
29
30################################################################################
31DDR_CMD     := ddr_cmd
32
33CMD_TEXT_BASE := $(shell grep '^\#define.*DDR_TRAINING_RUN_STACK' $(TOPDIR)/drivers/ddr/hisilicon/$(SOC)/ddr_training_custom.h|awk '{print $$3}')
34STACK_POINT   := $(CMD_TEXT_BASE)
35
36COBJS       := ddr_training_uart.o ddr_training_custom.o ddr_training_cmd.o ddr_training_impl.o ddr_training_ctl.o ddr_training_console.o
37DEPS        := $(COBJS:.o=.d) $(START:.o=.d)
38SSRC        := ddr_training_impl.c ddr_training_ctl.c ddr_training_console.c
39
40CFLAGS   := -Os -pipe  \
41	-DCMD_TEXT_BASE=$(CMD_TEXT_BASE) -DSTACK_POINT=$(STACK_POINT) \
42	-fno-builtin -ffreestanding -I./ -I$(TOPDIR)/include -I../ \
43	-DDDR_TRAINING_CMD -I$(TOPDIR)/drivers/ddr/hisilicon/$(SOC)/
44
45CFLAGS += $(PLATFORM_RELFLAGS) $(PLATFORM_CPPFLAGS)
46
47ifeq ("$(CONFIG_ARM64)","y")
48START       := cmd_entry_64.o
49LDS_SCRIPT := ddr_cmd_64.lds
50CFLAGS += -DCONFIG_ARM64
51else
52START       := cmd_entry_32.o
53LDS_SCRIPT := ddr_cmd_32.lds
54endif
55
56################################################################################
57
58LINK_FILES = $(SSRC) ddr_training_custom.c
59
60.PHONY: $(DDR_CMD).bin
61all: $(DDR_CMD).bin
62	#remove soft link files
63	@rm -f $(LINK_FILES) *.o *.d *.elf *.map *.srec
64
65$(DDR_CMD).bin: $(DDR_CMD).elf
66	$(OBJCOPY) -O srec $(PWD)/$(DDR_CMD).elf $(DDR_CMD).srec
67	$(OBJCOPY) --gap-fill=0xff -O binary $(PWD)/$(DDR_CMD).elf $@
68
69$(DDR_CMD).elf: $(START) $(COBJS) $(LDS_SCRIPT)
70	#@echo CMD_TEXT_BASE=$(CMD_TEXT_BASE)
71	$(LD) -Bstatic -T $(LDS_SCRIPT) -Ttext $(CMD_TEXT_BASE) $(START) \
72		$(COBJS) $(AOBJS) -Map $(DDR_CMD).map -o $@
73
74$(SSRC):
75	rm -rf $@
76	rm -rf ddr_training_custom.c
77	ln -sf ../$@ $@
78	ln -sf $(TOPDIR)/drivers/ddr/hisilicon/$(SOC)/ddr_training_custom.c ddr_training_custom.c
79
80.PHONY: clean
81clean:
82	@rm -vf *.o *.d *.elf *.map *.srec $(LINK_FILES) $(DDR_CMD).bin
83
84%.o : %.S
85	$(CC) -D__ASSEMBLY__ $(CFLAGS) -o $@ -c $*.S
86
87%.o : %.c
88	$(CC) $(CFLAGS) -Wall -Wstrict-prototypes -fno-stack-protector \
89		-o $@ -c $*.c
90
91ifneq ("$(MAKECMDGOALS)","clean")
92sinclude $(DEPS)
93endif
94
95%.d : %.c
96	set -e; $(CC) $(CFLAGS) -MM $< | sed 's,$*.o:,$*.o $*.d:,g' > $@
97
98%.d : %.S
99	set -e; $(CC) $(CFLAGS) -MM $< | sed 's,$*.o:,$*.o $*.d:,g' > $@
100
101################################################################################
102