blob: 08246044b3ec758d09fada11035b2f84f3997ce6 [file] [log] [blame]
Alexandru Gagniuc00b579a2012-07-20 00:11:21 -05001################################################################################
Stefan Reinauer30584912010-08-14 20:38:17 +00002##
3## This file is part of the coreboot project.
4##
Alexandru Gagniuc00b579a2012-07-20 00:11:21 -05005## Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
Stefan Reinauer30584912010-08-14 20:38:17 +00006## Copyright (C) 2009-2010 coresystems GmbH
7## Copyright (C) 2009 Ronald G. Minnich
8##
9## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published by
11## the Free Software Foundation; version 2 of the License.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010020## Foundation, Inc.
Stefan Reinauer30584912010-08-14 20:38:17 +000021##
Furquan Shaikh88ca81a2014-04-22 16:33:22 -070022###############################################################################
Patrick Georgi0588d192009-08-12 15:00:51 +000023# Take care of subdirectories
Furquan Shaikh88ca81a2014-04-22 16:33:22 -070024###############################################################################
Patrick Georgi0588d192009-08-12 15:00:51 +000025subdirs-y += boot
Stefan Reinauere3778572010-01-30 09:47:18 +000026# subdirs-y += init
Patrick Georgi0588d192009-08-12 15:00:51 +000027subdirs-y += lib
28subdirs-y += smp
29
Patrick Georgi70a6b4f2015-03-27 14:14:58 +010030################################################################################
31# i386 specific tools
32NVRAMTOOL:=$(objutil)/nvramtool/nvramtool
33
Patrick Georgi8463dd92010-09-30 16:55:02 +000034OPTION_TABLE_H:=
35ifeq ($(CONFIG_HAVE_OPTION_TABLE),y)
Patrick Georgi70a6b4f2015-03-27 14:14:58 +010036
Patrick Georgi5c0bca22011-01-30 16:31:15 +000037cbfs-files-y += cmos_layout.bin
38cmos_layout.bin-file = $(obj)/cmos_layout.bin
39cmos_layout.bin-type = 0x01aa
Patrick Georgi24479372011-01-18 13:56:36 +000040
Patrick Georgi70a6b4f2015-03-27 14:14:58 +010041$(obj)/cmos_layout.bin: $(NVRAMTOOL) $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
42 @printf " OPTION $(subst $(obj)/,,$(@))\n"
43 $(NVRAMTOOL) -y $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout -L $@
44
Patrick Georgi8463dd92010-09-30 16:55:02 +000045OPTION_TABLE_H:=$(obj)/option_table.h
Patrick Georgi70a6b4f2015-03-27 14:14:58 +010046
47$(OPTION_TABLE_H): $(NVRAMTOOL) $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
48 @printf " OPTION $(subst $(obj)/,,$(@))\n"
49 $(NVRAMTOOL) -y $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout -H $@
50endif # CONFIG_HAVE_OPTION_TABLE
Patrick Georgi0588d192009-08-12 15:00:51 +000051
Patrick Georgiff9d78c2011-01-30 16:37:39 +000052stripped_vgabios_id = $(call strip_quotes,$(CONFIG_VGA_BIOS_ID))
53cbfs-files-$(CONFIG_VGA_BIOS) += pci$(stripped_vgabios_id).rom
54pci$(stripped_vgabios_id).rom-file := $(call strip_quotes,$(CONFIG_VGA_BIOS_FILE))
55pci$(stripped_vgabios_id).rom-type := optionrom
56
57cbfs-files-$(CONFIG_INTEL_MBI) += mbi.bin
58mbi.bin-file := $(call strip_quotes,$(CONFIG_MBI_FILE))
59mbi.bin-type := mbi
60
Stefan Reinauer181b7732015-03-15 19:23:50 +010061ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
Julius Wernerf780c402014-11-10 13:11:50 -080062CBFSTOOL_PRE1_OPTS = -m x86 -s $(CONFIG_ROM_SIZE) \
63 -o $$(( $(CONFIG_ROM_SIZE) - $(CONFIG_CBFS_SIZE) ))
Furquan Shaikhb4ce4d42014-10-30 11:47:20 -070064# Make sure that segment for .car.data is ignored while adding romstage.
65CBFSTOOL_PRE_OPTS = -b $(shell cat $(objcbfs)/base_xip.txt) -S ".car.data"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070066endif
Patrick Georgiff9d78c2011-01-30 16:37:39 +000067
Furquan Shaikh88ca81a2014-04-22 16:33:22 -070068###############################################################################
69# bootblock
70###############################################################################
Patrick Georgi641dd712011-11-01 18:55:59 +010071
Stefan Reinauer181b7732015-03-15 19:23:50 +010072ifeq ($(CONFIG_ARCH_BOOTBLOCK_X86_32)$(CONFIG_ARCH_BOOTBLOCK_X86_64),y)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070073
Patrick Georgi990e7c92015-04-03 10:47:15 +020074bootblock-srcs += $(src)/arch/x86/init/failover.ld
75bootblock-srcs += $(src)/cpu/x86/16bit/entry16.ld
76bootblock-srcs += $(src)/cpu/x86/16bit/reset16.ld
77bootblock-srcs += $(src)/arch/x86/lib/id.ld
Aaron Durbin6dccedd2012-12-03 16:17:40 -060078ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
Patrick Georgi990e7c92015-04-03 10:47:15 +020079bootblock-srcs += $(src)/cpu/intel/fit/fit.ld
Aaron Durbin6dccedd2012-12-03 16:17:40 -060080endif
Patrick Georgi641dd712011-11-01 18:55:59 +010081
Patrick Georgi990e7c92015-04-03 10:47:15 +020082# TODO: Why can't this use the real bootblock-y += xxx.S mechanism instead?
Patrick Georgi641dd712011-11-01 18:55:59 +010083bootblock_inc = $(src)/arch/x86/init/prologue.inc
84bootblock_inc += $(src)/cpu/x86/16bit/entry16.inc
85bootblock_inc += $(src)/cpu/x86/16bit/reset16.inc
86bootblock_inc += $(src)/cpu/x86/32bit/entry32.inc
87bootblock_inc += $(src)/arch/x86/lib/id.inc
Aaron Durbin6dccedd2012-12-03 16:17:40 -060088ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
89bootblock_inc += $(src)/cpu/intel/fit/fit.inc
90endif
Patrick Georgi641dd712011-11-01 18:55:59 +010091bootblock_inc += $(chipset_bootblock_inc)
92
93ifeq ($(CONFIG_SSE),y)
94bootblock_inc += $(src)/cpu/x86/sse_enable.inc
95endif
Kyösti Mälkkif775b8c2012-04-19 12:14:53 +030096bootblock_inc += $(objgenerated)/bootblock.inc
Patrick Georgi641dd712011-11-01 18:55:59 +010097bootblock_inc += $(src)/arch/x86/lib/walkcbfs.S
98
Patrick Georgi56b83092015-04-02 19:44:19 +020099bootblock_romccflags := -mcpu=i386 -O2 -D__PRE_RAM__ -D__BOOTBLOCK__
Patrick Georgi641dd712011-11-01 18:55:59 +0100100ifeq ($(CONFIG_SSE),y)
Patrick Georgi56b83092015-04-02 19:44:19 +0200101bootblock_romccflags := -mcpu=k7 -msse -O2 -D__PRE_RAM__ -D__BOOTBLOCK__
Patrick Georgi641dd712011-11-01 18:55:59 +0100102endif
103
Marc Jonesac630f72015-06-30 15:46:49 -0600104$(objgenerated)/bootblock.ld: $$(filter %.ld,$$(bootblock-objs))
Patrick Georgi641dd712011-11-01 18:55:59 +0100105 @printf " GEN $(subst $(obj)/,,$(@))\n"
Marc Jonesac630f72015-06-30 15:46:49 -0600106 cat $^ >> $@.tmp
107 mv $@.tmp $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100108
Marc Jones49fe74b2012-05-14 16:20:26 -0600109$(objgenerated)/bootblock_inc.S: $$(bootblock_inc)
Patrick Georgi641dd712011-11-01 18:55:59 +0100110 @printf " GEN $(subst $(obj)/,,$(@))\n"
Patrick Georgi950f20a2012-01-17 13:13:59 +0100111 printf '$(foreach crt0,$(bootblock_inc),#include "$(crt0)"\n)' > $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100112
Kyösti Mälkkif775b8c2012-04-19 12:14:53 +0300113$(objgenerated)/bootblock.o: $(objgenerated)/bootblock.s
Daniele Forsi96639fb2014-08-02 13:45:17 +0200114 @printf " CC $(subst $(obj)/,,$(@))\n"
Stefan Reinauer181b7732015-03-15 19:23:50 +0100115 $(CC_bootblock) $(CFLAGS_bootblock) -c -o $@ $< > $(basename $@).disasm
Patrick Georgi641dd712011-11-01 18:55:59 +0100116
Marc Jones49fe74b2012-05-14 16:20:26 -0600117$(objgenerated)/bootblock.s: $(objgenerated)/bootblock_inc.S $(obj)/config.h $(obj)/build.h
Patrick Georgi641dd712011-11-01 18:55:59 +0100118 @printf " CC $(subst $(obj)/,,$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700119 $(CC_bootblock) -MMD -x assembler-with-cpp -E -I$(src)/include -I$(src)/arch/x86/include -I$(obj) -include $(obj)/build.h -include $(obj)/config.h -I. -I$(src) $< -o $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100120
Kyösti Mälkkif775b8c2012-04-19 12:14:53 +0300121$(objgenerated)/bootblock.inc: $(src)/arch/x86/init/$(subst ",,$(CONFIG_BOOTBLOCK_SOURCE)) $(objutil)/romcc/romcc $(OPTION_TABLE_H)
Patrick Georgi641dd712011-11-01 18:55:59 +0100122 @printf " ROMCC $(subst $(obj)/,,$(@))\n"
Patrick Georgi59307742014-05-19 09:23:57 +0200123 $(CC_bootblock) $(CPPFLAGS_bootblock) -MM -MT$(objgenerated)/bootblock.inc \
Kyösti Mälkkif775b8c2012-04-19 12:14:53 +0300124 $< > $(objgenerated)/bootblock.inc.d
Patrick Georgi59307742014-05-19 09:23:57 +0200125 $(ROMCC) -c -S $(bootblock_romccflags) -I. $(CPPFLAGS_bootblock) $< -o $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100126
Kyösti Mälkkif775b8c2012-04-19 12:14:53 +0300127$(objcbfs)/bootblock.debug: $(objgenerated)/bootblock.o $(objgenerated)/bootblock.ld
Patrick Georgi641dd712011-11-01 18:55:59 +0100128 @printf " LINK $(subst $(obj)/,,$(@))\n"
Stefan Reinauer98749332015-06-23 12:57:06 -0700129ifeq ($(CONFIG_ARCH_BOOTBLOCK_X86_32),y)
130 $(LD_bootblock) -m elf_i386 --oformat elf32-i386 -static -o $@ -L$(obj) $< -T $(objgenerated)/bootblock.ld
131else
132 $(LD_bootblock) -m elf_x86_64 --oformat elf64-x86-64 -static -o $@ -L$(obj) $< -T $(objgenerated)/bootblock.ld
133endif
Patrick Georgi641dd712011-11-01 18:55:59 +0100134
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700135
Stefan Reinauer181b7732015-03-15 19:23:50 +0100136endif # CONFIG_ARCH_BOOTBLOCK_X86_32 / CONFIG_ARCH_BOOTBLOCK_X86_64
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700137
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700138###############################################################################
139# romstage
140###############################################################################
141
Stefan Reinauer181b7732015-03-15 19:23:50 +0100142ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700143
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700144crt0s = $(src)/arch/x86/init/prologue.inc
Patrick Georgi990e7c92015-04-03 10:47:15 +0200145romstage-srcs += $(src)/arch/x86/init/romstage.ld
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700146crt0s += $(src)/cpu/x86/32bit/entry32.inc
Patrick Georgi990e7c92015-04-03 10:47:15 +0200147romstage-srcs += $(src)/cpu/x86/32bit/entry32.ld
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700148
149crt0s += $(src)/cpu/x86/fpu_enable.inc
150ifeq ($(CONFIG_SSE),y)
151crt0s += $(src)/cpu/x86/sse_enable.inc
152endif
153
154crt0s += $(cpu_incs)
155crt0s += $(cpu_incs-y)
156
157crt0s += $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
158
159ifeq ($(CONFIG_ROMCC),y)
160crt0s += $(src)/arch/x86/init/crt0_romcc_epilogue.inc
161endif
162
163ifeq ($(CONFIG_ROMCC),y)
164ifeq ($(CONFIG_MMX),y)
165 ifeq ($(CONFIG_SSE),y)
166 ROMCCFLAGS := -mcpu=p4 -O2 # MMX, SSE
167 else
168 ROMCCFLAGS := -mcpu=p2 -O2 # MMX, !SSE
169 endif
170else
171 ROMCCFLAGS := -mcpu=i386 -O2 # !MMX, !SSE
172endif
173
Patrick Georgi24cca752014-11-29 11:51:25 +0100174$(objcbfs)/romstage%.bin: $(objcbfs)/romstage%.elf
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700175 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
176 $(OBJCOPY_romstage) -O binary $< $@
177
Patrick Georgi24cca752014-11-29 11:51:25 +0100178$(objcbfs)/romstage%.elf: $(objcbfs)/romstage%.debug
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700179 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
180 cp $< $@.tmp
181 $(OBJCOPY_romstage) --strip-debug $@.tmp
182 $(OBJCOPY_romstage) --add-gnu-debuglink=$< $@.tmp
183 mv $@.tmp $@
184
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700185$(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(objutil)/romcc/romcc $(OPTION_TABLE_H) $(obj)/build.h $(obj)/config.h
186 printf " ROMCC romstage.inc\n"
Patrick Georgi815f4bf2015-04-28 22:43:31 +0200187 $(ROMCC) -c -S $(ROMCCFLAGS) -D__ROMSTAGE__ -D__PRE_RAM__ -I. $(CPPFLAGS_romstage) $< -o $@
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700188else
189
190$(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(OPTION_TABLE_H) $(obj)/build.h $(obj)/config.h
191 @printf " CC romstage.inc\n"
Patrick Georgi815f4bf2015-04-28 22:43:31 +0200192 $(CC_romstage) $(CPPFLAGS_romstage) $(CFLAGS_romstage) -MMD -D__ROMSTAGE__ -D__PRE_RAM__ -I$(src) -I. -I$(obj) -c -S $< -o $@
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700193
194$(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc: $(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc
195 @printf " POST romstage.inc\n"
196 sed -e 's/\.rodata/.rom.data/g' -e 's/\^\.text/.section .rom.text/g' \
197 -e 's/\^\.section \.text/.section .rom.text/g' $^ > $@.tmp
198 mv $@.tmp $@
199endif
200
Patrick Georgidb273062015-03-27 17:03:28 +0100201romstage-srcs += $(objgenerated)/crt0.S
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300202
Alexandru Gagniuceb3c9912014-03-29 13:01:11 -0500203romstage-libs ?=
204
Stefan Reinauer98749332015-06-23 12:57:06 -0700205ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32),y)
206romstage-oformat=elf32-i386
207else
208romstage-oformat=elf64-x86-64
209endif
210
Alexandru Gagniuceb3c9912014-03-29 13:01:11 -0500211$(objcbfs)/romstage_null.debug: $$(romstage-objs) $(objgenerated)/romstage_null.ld $$(romstage-libs)
Patrick Georgi641dd712011-11-01 18:55:59 +0100212 @printf " LINK $(subst $(obj)/,,$(@))\n"
Stefan Reinauer98749332015-06-23 12:57:06 -0700213 $(LD_romstage) --gc-sections -nostdlib -nostartfiles -static -o $@ -L$(obj) $(COMPILER_RT_FLAGS_romstage) --whole-archive --start-group $(filter-out %.ld,$(romstage-objs)) $(romstage-libs) --no-whole-archive $(COMPILER_RT_romstage) --end-group -T $(objgenerated)/romstage_null.ld --oformat $(romstage-oformat)
Furquan Shaikh3cf6aea2014-10-30 11:53:38 -0700214 $(OBJCOPY_romstage) --only-section .illegal_globals $(@) $(objcbfs)/romstage_null.offenders && \
215 $(NM_romstage) $(objcbfs)/romstage_null.offenders | grep -q ""; if [ $$? -eq 0 ]; then \
Stefan Reinauerb6e12372012-07-31 14:52:04 -0700216 echo "Forbidden global variables in romstage:"; \
Furquan Shaikh3cf6aea2014-10-30 11:53:38 -0700217 $(NM_romstage) $(objcbfs)/romstage_null.offenders; false; \
Stefan Reinauerb6e12372012-07-31 14:52:04 -0700218 else true; fi
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300219
Patrick Georgi24cca752014-11-29 11:51:25 +0100220$(objcbfs)/romstage.debug: $$(romstage-objs) $(objgenerated)/romstage.ld $$(romstage-libs)
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300221 @printf " LINK $(subst $(obj)/,,$(@))\n"
Stefan Reinauer98749332015-06-23 12:57:06 -0700222 $(LD_romstage) --gc-sections -nostdlib -nostartfiles -static -o $@ -L$(obj) $(COMPILER_RT_FLAGS_romstage) --whole-archive --start-group $(filter-out %.ld,$(romstage-objs)) $(romstage-libs) --no-whole-archive $(COMPILER_RT_romstage) --end-group -T $(objgenerated)/romstage.ld --oformat $(romstage-oformat)
Patrick Georgi641dd712011-11-01 18:55:59 +0100223
Marc Jonesac630f72015-06-30 15:46:49 -0600224$(objgenerated)/romstage_null.ld: $$(filter %.ld,$$(romstage-objs))
Patrick Georgi641dd712011-11-01 18:55:59 +0100225 @printf " GEN $(subst $(obj)/,,$(@))\n"
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300226 rm -f $@
227 printf "ROMSTAGE_BASE = 0x0;\n" > $@.tmp
Marc Jonesac630f72015-06-30 15:46:49 -0600228 cat $^ >> $@.tmp
229 mv $@.tmp $@
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300230
Patrick Georgi24cca752014-11-29 11:51:25 +0100231$(objgenerated)/romstage.ld: $(objgenerated)/romstage_null.ld $(objcbfs)/base_xip.txt
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300232 @printf " GEN $(subst $(obj)/,,$(@))\n"
233 rm -f $@
Kyösti Mälkki1e9c1b32012-04-19 14:43:47 +0300234 sed -e 's/^/ROMSTAGE_BASE = /g' -e 's/$$/;/g' $(objcbfs)/base_xip.txt > $@.tmp
Patrick Georgi828e0e82015-04-04 15:50:20 +0200235 sed -e '/^ROMSTAGE_BASE/d' $(objgenerated)/romstage_null.ld >> $@.tmp
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300236 mv $@.tmp $@
237
Kyösti Mälkki1e9c1b32012-04-19 14:43:47 +0300238$(objcbfs)/base_xip.txt: $(obj)/coreboot.pre1 $(objcbfs)/romstage_null.bin
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300239 rm -f $@
Hung-Te Line9198372013-03-19 12:17:12 +0800240 $(CBFSTOOL) $(obj)/coreboot.pre1 locate -T -f $(objcbfs)/romstage_null.bin -n $(CONFIG_CBFS_PREFIX)/romstage -P $(CONFIG_XIP_ROM_SIZE) > $@.tmp \
Kyösti Mälkkia01ec142012-03-31 10:21:29 +0300241 || { echo "The romstage is larger than XIP size. Please expand the CONFIG_XIP_ROM_SIZE" ; exit 1; }
Hung-Te Lin657ea6a2013-01-28 23:00:47 +0800242 mv $@.tmp $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100243
Patrick Georgid69839b2015-04-03 10:32:17 +0200244$(objgenerated)/crt0.S: $$(crt0s)
Patrick Georgi641dd712011-11-01 18:55:59 +0100245 @printf " GEN $(subst $(obj)/,,$(@))\n"
Patrick Georgid69839b2015-04-03 10:32:17 +0200246 printf '$(foreach crt0,$(crt0s),#include "$(crt0)"\n)' > $@
Patrick Georgi641dd712011-11-01 18:55:59 +0100247
Patrick Georgid69839b2015-04-03 10:32:17 +0200248# Compiling crt0 with -g seems to trigger https://sourceware.org/bugzilla/show_bug.cgi?id=6428
249romstage-S-ccopts += -I. -g0
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700250
Stefan Reinauer181b7732015-03-15 19:23:50 +0100251endif # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
Stefan Reinauerf1939bb2010-12-30 17:39:50 +0000252
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700253###############################################################################
254# ramstage
255###############################################################################
256
Stefan Reinauer181b7732015-03-15 19:23:50 +0100257ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32)$(CONFIG_ARCH_RAMSTAGE_X86_64),y)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700258
Patrick Georgic32a52c2015-06-22 21:10:34 +0200259ifeq ($(CONFIG_COMPILE_IN_DSDT),y)
260ramstage-srcs += $(obj)/dsdt.aml
261
262ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y)
263target-objcopy=-O elf32-i386 -B i386
264endif
265ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_64),y)
266target-objcopy=-O elf64-x86_64 -B x86_64
267endif
268
269define ramstage-objs_aml_template
270$(call src-to-obj,ramstage,$(1).aml): $(1).aml
271 @printf " OBJCOPY $$(subst $$(obj)/,,$$(@))\n"
272 cd $$(dir $$@) && $$(OBJCOPY_ramstage) -I binary $$(target-objcopy) $$(notdir $$<) $$(notdir $$@)
273endef
274endif
275
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700276ramstage-srcs += $(wildcard src/mainboard/$(MAINBOARDDIR)/mainboard.c)
277ifeq ($(CONFIG_GENERATE_MP_TABLE),y)
278ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/mptable.c),)
279ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/mptable.c
280endif
281endif
282ifeq ($(CONFIG_GENERATE_PIRQ_TABLE),y)
283ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/irq_tables.c
284endif
285ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/reset.c),)
286ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/reset.c
287endif
Vladimir Serbinenko822bc652014-01-03 15:55:40 +0100288ifeq ($(CONFIG_HAVE_ACPI_TABLES),y)
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700289ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/acpi_tables.c
Vladimir Serbinenko36f8d272015-05-31 12:31:59 +0200290$(eval $(call asl_template,dsdt))
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700291ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/fadt.c),)
292ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/fadt.c
293endif
Patrick Georgi990e7c92015-04-03 10:47:15 +0200294endif # CONFIG_GENERATE_ACPI_TABLES
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700295ifeq ($(CONFIG_HAVE_SMI_HANDLER),y)
296ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/smihandler.c),)
297smm-srcs += src/mainboard/$(MAINBOARDDIR)/smihandler.c
298endif
299endif
300ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c),)
301ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c
302endif
303
304ramstage-libs ?=
305
306ifeq ($(CONFIG_RELOCATABLE_RAMSTAGE),y)
307
Stefan Reinauer181b7732015-03-15 19:23:50 +0100308ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y)
Furquan Shaikh133096b2014-07-31 09:28:55 -0700309$(eval $(call rmodule_link,$(objcbfs)/ramstage.debug, $(objgenerated)/ramstage.o, $(CONFIG_HEAP_SIZE),x86_32))
Stefan Reinauer181b7732015-03-15 19:23:50 +0100310else
311$(eval $(call rmodule_link,$(objcbfs)/ramstage.debug, $(objgenerated)/ramstage.o, $(CONFIG_HEAP_SIZE),x86_64))
312endif
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700313
314# The rmodule_link defintion creates an elf file with .rmod extension.
315$(objcbfs)/ramstage.elf: $(objcbfs)/ramstage.debug.rmod
316 cp $< $@
317
318else
319
Patrick Georgi828e0e82015-04-04 15:50:20 +0200320ramstage-srcs += $(src)/arch/x86/ramstage.ld
321
322$(objcbfs)/ramstage.debug: $(objgenerated)/ramstage.o $(obj)/arch/x86/ramstage.ramstage.ld
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700323 @printf " CC $(subst $(obj)/,,$(@))\n"
Julius Wernerec5e5e02014-08-20 15:29:56 -0700324 $(LD_ramstage) $(CPPFLAGS) --gc-sections -o $@ -L$(obj) $< -T $(obj)/arch/x86/ramstage.ramstage.ld
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700325
326endif
327
Patrick Georgi3ce96bd2014-11-22 17:42:58 +0100328$(objgenerated)/ramstage.o: $$(ramstage-objs) $(COMPILER_RT_ramstage) $$(ramstage-libs)
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700329 @printf " CC $(subst $(obj)/,,$(@))\n"
Stefan Reinauer181b7732015-03-15 19:23:50 +0100330ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32),y)
Patrick Georgieec8dfb2015-05-07 22:24:41 +0200331 $(LD_ramstage) -m elf_i386 -r -o $@ $(COMPILER_RT_FLAGS_ramstage) --whole-archive --start-group $(filter-out %.ld,$(ramstage-objs)) $(ramstage-libs) --no-whole-archive $(COMPILER_RT_ramstage) --end-group
Stefan Reinauer181b7732015-03-15 19:23:50 +0100332else
333 $(LD_ramstage) -m elf_x86_64 -r -o $@ $(COMPILER_RT_FLAGS_ramstage) --whole-archive --start-group $(filter-out %.ld,$(ramstage-objs)) $(ramstage-libs) --no-whole-archive $(COMPILER_RT_ramstage) --end-group
334endif
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700335
Stefan Reinauer181b7732015-03-15 19:23:50 +0100336endif # CONFIG_ARCH_RAMSTAGE_X86_32 / CONFIG_ARCH_RAMSTAGE_X86_64
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700337
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700338