Revert "ARMv7: drop special handling for stages.c"
[coreboot.git] / src / arch / armv7 / Makefile.inc
blob6d4a3644ff268f8fe9096f4043e25eef3e9d890d
1 ################################################################################
2 ##
3 ## This file is part of the coreboot project.
4 ##
5 ## Copyright (C) 2012 The ChromiumOS Authors
6 ## Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7 ## Copyright (C) 2009-2010 coresystems GmbH
8 ## Copyright (C) 2009 Ronald G. Minnich
9 ##
10 ## This program is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; version 2 of the License.
14 ## This program is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with this program; if not, write to the Free Software
21 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23 ################################################################################
25 # Take care of subdirectories
26 subdirs-y += boot/
27 subdirs-y += lib/
29 ################################################################################
30 # Build the final rom image
31 COREBOOT_ROM_DEPENDENCIES:=
32 ifeq ($(CONFIG_PAYLOAD_ELF),y)
33 COREBOOT_ROM_DEPENDENCIES+=$(CONFIG_PAYLOAD_FILE)
34 endif
36 extract_nth=$(word $(1), $(subst |, ,$(2)))
38 ifneq ($(CONFIG_UPDATE_IMAGE),y)
39 prebuild-files = \
40         $(foreach file,$(cbfs-files), \
41         $(CBFSTOOL) $@.tmp \
42         add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
43         -f $(call extract_nth,1,$(file)) \
44         -n $(call extract_nth,2,$(file)) $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
45         $(if $(call extract_nth,4,$(file)),-b $(call extract_nth,4,$(file))) &&)
46 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
48 # TODO Change -b to Kconfig variable.
49 $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL)
50         $(CBFSTOOL) $@.tmp create -m armv7 -s $(CONFIG_COREBOOT_ROMSIZE_KB)K \
51                 -B $(objcbfs)/bootblock.bin -a 64 -b 0x0000 \
52                 -H $(CONFIG_CBFS_HEADER_ROM_OFFSET) \
53                 -o $(CONFIG_CBFS_ROM_OFFSET)
54         $(prebuild-files) true
55         mv $@.tmp $@
56 else
57 .PHONY: $(obj)/coreboot.pre1
58 $(obj)/coreboot.pre1: $(CBFSTOOL)
59         mv $(obj)/coreboot.rom $@
60 endif
62 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/coreboot_ram.elf $(CBFSTOOL) $(call strip_quotes,$(COREBOOT_ROM_DEPENDENCIES))
63         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
64         cp $(obj)/coreboot.pre $@.tmp
65         $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/coreboot_ram.elf -n $(CONFIG_CBFS_PREFIX)/coreboot_ram -c $(CBFS_COMPRESS_FLAG)
66 ifeq ($(CONFIG_PAYLOAD_NONE),y)
67         @printf "    PAYLOAD    none (as specified by user)\n"
68 endif
69 ifeq ($(CONFIG_PAYLOAD_ELF),y)
70         @printf "    PAYLOAD    $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_NAME))\n"
71         $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
72 endif
73 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
74         @printf "    CONFIG     $(DOTCONFIG)\n"
75         if [ -f $(DOTCONFIG) ]; then \
76         echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp ; \
77         sed -e '/^#/d' -e '/^ *$$/d' $(DOTCONFIG) >> $(obj)/config.tmp ; \
78         $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
79 endif
80         mv $@.tmp $@
81         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
82         $(CBFSTOOL) $@ print
84 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
85 bootsplash.jpg-type := bootsplash
87 ################################################################################
88 # armv7 specific tools
90 ################################################################################
91 # Common recipes for all stages
93 $(objcbfs)/%.bin: $(objcbfs)/%.elf
94         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
95         $(OBJCOPY) -O binary $< $@
97 $(objcbfs)/%.elf: $(objcbfs)/%.debug
98         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
99         cp $< $@.tmp
100         $(NM) -n $@.tmp | sort > $(basename $@).map
101         $(OBJCOPY) --strip-debug $@.tmp
102         $(OBJCOPY) --add-gnu-debuglink=$< $@.tmp
103         mv $@.tmp $@
105 stages_c = $(src)/arch/armv7/stages.c
106 stages_o = $(obj)/arch/armv7/stages.o
108 $(stages_o): $(stages_c)
109         @printf "    CC         $(subst $(obj)/,,$(@))\n"
110         $(CC) -Wa,-acdlns -I. $(INCLUDES) -c -o $@ $< -marm
113 ################################################################################
114 # Build the coreboot_ram (stage 2)
116 $(objcbfs)/coreboot_ram.debug: $(objgenerated)/coreboot_ram.o $(src)/arch/armv7/coreboot_ram.ld
117         @printf "    CC         $(subst $(obj)/,,$(@))\n"
118 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
119         $(LD) -m armelf_linux_eabi -o $@ -L$(obj) $< -T $(src)/arch/armv7/coreboot_ram.ld
120 else
121         $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/armv7/coreboot_ram.ld $<
122 endif
124 $(objgenerated)/coreboot_ram.o: $(stages_o) $$(ramstage-objs) $(LIBGCC_FILE_NAME)
125         @printf "    CC         $(subst $(obj)/,,$(@))\n"
126 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
127         $(LD) -m -m armelf_linux_eabi -r -o $@ --wrap __divdi3 --wrap __udivdi3 --wrap __moddi3 --wrap __umoddi3 --wrap __uidiv --wrap __do_div64 --start-group $(ramstage-objs) $(LIBGCC_FILE_NAME) --end-group
128 else
129         $(CC) $(CFLAGS) -nostdlib -r -o $@ -Wl,--start-group $(stages_o) $(ramstage-objs) $(LIBGCC_FILE_NAME) -Wl,--end-group
130 endif
132 CFLAGS += \
133         -ffixed-r8\
134         -march=armv7-a\
135         -marm\
136         -mno-unaligned-access\
137         -mthumb\
138         -mthumb-interwork
140 ldscripts =
141 ldscripts += $(src)/arch/armv7/romstage.ld
143 #crt0s += $(src)/cpu/arm/fpu_enable.inc
144 # FIXME: CONFIG_NEON or something similar for ARM?
145 #ifeq ($(CONFIG_SSE),y)
146 #crt0s += $(src)/cpu/arm/sse_enable.inc
147 #endif
149 crt0s += $(cpu_incs)
150 crt0s += $(cpu_incs-y)
152 ifeq ($(CONFIG_LLSHELL),y)
153 crt0s += $(src)/arch/armv7/llshell/llshell.inc
154 endif
156 $(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(OPTION_TABLE_H) $(obj)/build.h $(obj)/config.h
157         @printf "    CC         romstage.inc\n"
158         $(CC) -MMD $(CFLAGS) -D__PRE_RAM__ -I$(src) -I. -I$(obj) -c -S $< -o $@
160 # Things that appear in every board
161 romstage-srcs += $(objgenerated)/crt0.s
162 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/mainboard.c
163 ifeq ($(CONFIG_GENERATE_PIRQ_TABLE),y)
164 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/irq_tables.c
165 endif
166 ifeq ($(CONFIG_BOARD_HAS_HARD_RESET),y)
167 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/reset.c
168 endif
169 ifeq ($(CONFIG_GENERATE_ACPI_TABLES),y)
170 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/acpi_tables.c
171 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/dsdt.asl
172 # make doesn't have arithmetic operators or greater-than comparisons
173 ifeq ($(subst 5,4,$(CONFIG_ACPI_SSDTX_NUM)),4)
174 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt2.asl
175 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt3.asl
176 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt4.asl
177 endif
178 ifeq ($(CONFIG_ACPI_SSDTX_NUM),5)
179 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt5.asl
180 endif
181 ifeq ($(CONFIG_BOARD_HAS_FADT),y)
182 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/fadt.c
183 endif
184 endif
186 ifeq ($(CONFIG_HAVE_BUS_CONFIG),y)
187 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c
188 endif
190 ################################################################################
191 # Build the final rom image
193 $(obj)/coreboot.pre: $(objcbfs)/romstage_xip.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
194         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
195         cp $(obj)/coreboot.pre1 $@.tmp
196         $(CBFSTOOL) $@.tmp add-stage \
197                 -f $(objcbfs)/romstage_null.debug \
198                 -n $(CONFIG_CBFS_PREFIX)/romstage -c none
199         mv $@.tmp $@
201 ################################################################################
202 # Build the bootblock
204 bootblock_lds = $(src)/arch/armv7/bootblock.lds
205 bootblock_lds += $(chipset_bootblock_lds)
207 bootblock_inc += $(src)/arch/armv7/bootblock.inc
208 bootblock_inc += $(src)/arch/armv7/lib/id.inc
209 bootblock_inc += $(chipset_bootblock_inc)
210 bootblock_inc += $(objgenerated)/bootblock.inc
212 bootblock_custom = $(src)/$(call strip_quotes,$(CONFIG_BOOTBLOCK_CPU_INIT))
213 bootblock_custom += $(src)/$(call strip_quotes,$(CONFIG_BOOTBLOCK_MAINBOARD_INIT))
215 $(objgenerated)/bootblock.ld: $$(bootblock_lds) $(obj)/ldoptions
216         @printf "    GEN        $(subst $(obj)/,,$(@))\n"
217         printf '$(foreach ldscript,ldoptions $(bootblock_lds),INCLUDE "$(ldscript)"\n)' > $@
219 $(objgenerated)/bootblock_inc.S: $$(bootblock_inc)
220         @printf "    GEN        $(subst $(obj)/,,$(@))\n"
221         printf '$(foreach crt0,$(bootblock_inc),#include "$(crt0)"\n)' > $@
223 $(objgenerated)/bootblock.o: $(objgenerated)/bootblock.s
224         @printf "    CC         $(subst $(obj)/,,$(@))\n"
225         $(CC) $(bootblock-S-ccopts) -Wa,-acdlns -c -o $@ $<  > $(basename $@).disasm
227 $(objgenerated)/bootblock.s: $(objgenerated)/bootblock_inc.S $(obj)/config.h $(obj)/build.h
228         @printf "    CC         $(subst $(obj)/,,$(@))\n"
229         $(CC) $(bootblock-S-ccopts) -MMD -x assembler-with-cpp -E -I$(src)/include -I$(src)/arch/armv7/include -I$(obj) -include $(obj)/build.h -include $(obj)/config.h -I. -I$(src) $< -o $@
231 $(objgenerated)/bootblock.inc: $(src)/arch/armv7/$(subst ",,$(CONFIG_BOOTBLOCK_SOURCE)) $(bootblock_custom) $(OPTION_TABLE_H)
232         @printf "    CC      $(subst $(obj)/,,$(@))\n"
233         $(CC) $(bootblock-c-ccopts) $(INCLUDES) -MM \
234                 -MT$(objgenerated)/bootblock.inc \
235                 $< > $(objgenerated)/bootblock.inc.d
236         $(CC) $(bootblock-c-ccopts) -c -S $(CFLAGS) -I. $(INCLUDES) $< -o $@
238 $(objcbfs)/bootblock.debug:  $(objgenerated)/bootblock.o $(objgenerated)/bootblock.ld $$(bootblock-objs) $(stages)
239         @printf "    LINK       $(subst $(obj)/,,$(@))\n"
240 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
241         $(LD) -m armelf_linux_eabi -include $(obj)/config.h -static -o $@.tmp -L$(obj) $< -T $(objgenerated)/bootblock.ld
242 else
243         $(CC) -nostdlib -nostartfiles -include $(obj)/config.h -static -o $@ -L$(obj) -T $(objgenerated)/bootblock.ld -Wl,--start-group $(objgenerated)/bootblock.o $(bootblock-objs) $(stages) $(LIBGCC_FILE_NAME) -Wl,--end-group
244 endif
246 ################################################################################
247 # Build the romstage
249 $(objcbfs)/romstage_null.debug: $$(romstage-objs) $(stages_o) $(objgenerated)/romstage_null.ld
250         @printf "    LINK       $(subst $(obj)/,,$(@))\n"
251 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
252         $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) -T $(objgenerated)/romstage_null.ld
253 else
254         $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_null.ld -Wl,--start-group $(romstage-objs) $(stages_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
255 endif
257 $(objcbfs)/romstage_xip.debug: $$(romstage-objs) $(objgenerated)/romstage_xip.ld
258         @printf "    LINK       $(subst $(obj)/,,$(@))\n"
259 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
260         $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) $(stages_o) -T $(objgenerated)/romstage_xip.ld
261 else
262         $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_xip.ld -Wl,--start-group $(romstage-objs) $(stages_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
263 endif
265 $(objgenerated)/romstage_null.ld: $$(ldscripts) $(obj)/ldoptions
266         @printf "    GEN        $(subst $(obj)/,,$(@))\n"
267         rm -f $@
268         printf "ROMSTAGE_BASE = 0x0;\n" > $@.tmp
269         printf '$(foreach ldscript,ldoptions $(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' >> $@.tmp
270         mv $@.tmp $@
272 $(objgenerated)/romstage_xip.ld: $(objgenerated)/romstage_null.ld $(objcbfs)/base_xip.txt
273         @printf "    GEN        $(subst $(obj)/,,$(@))\n"
274         rm -f $@
275         sed -e 's/^/ROMSTAGE_BASE = /g' -e 's/$$/;/g' $(objcbfs)/base_xip.txt > $@.tmp
276         sed -e '/ROMSTAGE_BASE/d' $(objgenerated)/romstage_null.ld >> $@.tmp
277         mv $@.tmp $@
279 $(objcbfs)/base_xip.txt: $(obj)/coreboot.pre1 $(objcbfs)/romstage_null.bin
280         @printf "    generating base_xip.txt\n"
281         rm -f $@
282         $(CBFSTOOL) $(obj)/coreboot.pre1 locate -f $(objcbfs)/romstage_null.bin -n $(CONFIG_CBFS_PREFIX)/romstage -a $(CONFIG_XIP_ROM_SIZE) > $@.tmp \
283          || { echo "The romstage is larger than XIP size. Please expand the CONFIG_XIP_ROM_SIZE" ; exit 1; }
284         mv $@.tmp $@
286 $(objgenerated)/crt0.romstage.S: $$(crt0s)
287         @printf "    GEN        $(subst $(obj)/,,$(@))\n"
288         printf '$(foreach crt0,$(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@
290 $(objgenerated)/crt0.romstage.o: $(objgenerated)/crt0.s
291         @printf "    CC         $(subst $(obj)/,,$(@))\n"
292         $(CC) -Wa,-acdlns -c -o $@ $<  > $(basename $@).disasm
294 $(objgenerated)/crt0.s: $(objgenerated)/crt0.romstage.S $(obj)/config.h $(obj)/build.h
295         @printf "    CC         $(subst $(obj)/,,$(@))\n"
296         $(CC) -MMD -x assembler-with-cpp -E -I$(src)/include -I$(src)/arch/armv7/include -I$(obj) -include $(obj)/config.h -include $(obj)/build.h -I. -I$(src) $< -o $@