blob: 1d12eca3b76ede30dffe5e60aa51cc46a28c19a1 [file] [log] [blame]
Stefan Reinauer52db0b92012-12-07 17:15:04 -08001################################################################################
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.
13##
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.
18##
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
22##
23################################################################################
24
25# Take care of subdirectories
26subdirs-y += boot/
27subdirs-y += lib/
28# subdirs-y += smp/
29
30################################################################################
31# Build the final rom image
32COREBOOT_ROM_DEPENDENCIES:=
33ifeq ($(CONFIG_PAYLOAD_ELF),y)
34COREBOOT_ROM_DEPENDENCIES+=$(CONFIG_PAYLOAD_FILE)
35endif
Stefan Reinauer52db0b92012-12-07 17:15:04 -080036
37extract_nth=$(word $(1), $(subst |, ,$(2)))
38
39ifneq ($(CONFIG_UPDATE_IMAGE),y)
40prebuild-files = \
41 $(foreach file,$(cbfs-files), \
42 $(CBFSTOOL) $@.tmp \
43 add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
Stefan Reinauer935a9422012-12-11 15:23:45 -080044 -f $(call extract_nth,1,$(file)) \
45 -n $(call extract_nth,2,$(file)) $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
46 $(if $(call extract_nth,4,$(file)),-b $(call extract_nth,4,$(file))) &&)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080047prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
48
49$(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL)
50 $(CBFSTOOL) $@.tmp create -m armv7 -s $(CONFIG_COREBOOT_ROMSIZE_KB)K \
David Hendricks0b23d472013-01-14 20:58:50 -080051 -B $(objcbfs)/bootblock.bin -a 64
Stefan Reinauer52db0b92012-12-07 17:15:04 -080052 $(prebuild-files) true
53 mv $@.tmp $@
54else
55.PHONY: $(obj)/coreboot.pre1
56$(obj)/coreboot.pre1: $(CBFSTOOL)
57 mv $(obj)/coreboot.rom $@
58endif
59
60$(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/coreboot_ram.elf $(CBFSTOOL) $(call strip_quotes,$(COREBOOT_ROM_DEPENDENCIES))
61 @printf " CBFS $(subst $(obj)/,,$(@))\n"
62 cp $(obj)/coreboot.pre $@.tmp
63 if [ -f $(objcbfs)/coreboot_ap.elf ]; \
64 then \
65 $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/coreboot_ap.elf -n $(CONFIG_CBFS_PREFIX)/coreboot_ap -c $(CBFS_COMPRESS_FLAG) ; \
66 fi
67 $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/coreboot_ram.elf -n $(CONFIG_CBFS_PREFIX)/coreboot_ram -c $(CBFS_COMPRESS_FLAG)
68ifeq ($(CONFIG_PAYLOAD_NONE),y)
Patrick Georgi7a334422012-12-19 10:58:08 +010069 @printf " PAYLOAD none (as specified by user)\n"
Stefan Reinauer52db0b92012-12-07 17:15:04 -080070endif
71ifeq ($(CONFIG_PAYLOAD_ELF),y)
72 @printf " PAYLOAD $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_NAME))\n"
Stefan Reinauer935a9422012-12-11 15:23:45 -080073 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080074endif
75ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
76 @printf " CONFIG $(DOTCONFIG)\n"
77 if [ -f $(DOTCONFIG) ]; then \
78 echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp ; \
79 sed -e '/^#/d' -e '/^ *$$/d' $(DOTCONFIG) >> $(obj)/config.tmp ; \
80 $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
81endif
82 mv $@.tmp $@
83 @printf " CBFSPRINT $(subst $(obj)/,,$(@))\n\n"
84 $(CBFSTOOL) $@ print
85
86bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
87bootsplash.jpg-type := bootsplash
88
89################################################################################
90# armv7 specific tools
91
92################################################################################
93# Common recipes for all stages
94
95$(objcbfs)/%.bin: $(objcbfs)/%.elf
96 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
97 $(OBJCOPY) -O binary $< $@
98
99$(objcbfs)/%.elf: $(objcbfs)/%.debug
100 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
101 cp $< $@.tmp
102 $(NM) -n $@.tmp | sort > $(basename $@).map
103 $(OBJCOPY) --strip-debug $@.tmp
104 $(OBJCOPY) --add-gnu-debuglink=$< $@.tmp
105 mv $@.tmp $@
106
107################################################################################
108# Build the coreboot_ram (stage 2)
109
110$(objcbfs)/coreboot_ram.debug: $(objgenerated)/coreboot_ram.o $(src)/arch/armv7/coreboot_ram.ld
111 @printf " CC $(subst $(obj)/,,$(@))\n"
112ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
113 $(LD) -m armelf_linux_eabi -o $@ -L$(obj) $< -T $(src)/arch/armv7/coreboot_ram.ld
114else
115 $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/armv7/coreboot_ram.ld $<
116endif
117
118$(objgenerated)/coreboot_ram.o: $$(ramstage-objs) $(LIBGCC_FILE_NAME)
119 @printf " CC $(subst $(obj)/,,$(@))\n"
120ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
121 $(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
122else
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800123 $(CC) $(CFLAGS) -nostdlib -r -o $@ -Wl,--start-group $(ramstage-objs) $(LIBGCC_FILE_NAME) -Wl,--end-group
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800124endif
125
126################################################################################
127# Ramstage for AP CPU (AMD K8, obsolete?)
128
129#$(objcbfs)/coreboot_ap.debug: $(objgenerated)/coreboot_ap.o $(src)/arch/armv7/init/ldscript_apc.lb
130# @printf " CC $(subst $(obj)/,,$(@))\n"
131# $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/armv7/init/ldscript_apc.lb $<
132
133#$(objgenerated)/coreboot_ap.o: $(src)/mainboard/$(MAINBOARDDIR)/ap_romstage.c $(OPTION_TABLE_H)
134# @printf " CC $(subst $(obj)/,,$(@))\n"
135# $(CC) -MMD $(CFLAGS) -I$(src) -D__PRE_RAM__ -I. -I$(obj) -c $< -o $@
136
137################################################################################
138# done
139
David Hendricks10c90d32012-12-27 13:30:55 -0800140CFLAGS += \
David Hendricks10c90d32012-12-27 13:30:55 -0800141 -ffixed-r8\
David Hendricks10c90d32012-12-27 13:30:55 -0800142 -march=armv7-a\
143 -marm\
144 -mno-unaligned-access\
145 -mthumb\
146 -mthumb-interwork
147
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800148# For various headers imported from Linux
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800149CFLAGS += -D__LINUX_ARM_ARCH__=7
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800150
David Hendrickse2851f22013-01-16 15:00:07 -0800151#crt0s = $(src)/arch/armv7/bootblock.inc
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800152ldscripts =
153ldscripts += $(src)/arch/armv7/romstage.ld
154
155#crt0s += $(src)/cpu/arm/fpu_enable.inc
156# FIXME: CONFIG_NEON or something similar for ARM?
157#ifeq ($(CONFIG_SSE),y)
158#crt0s += $(src)/cpu/arm/sse_enable.inc
159#endif
160
161crt0s += $(cpu_incs)
162crt0s += $(cpu_incs-y)
163
164ifeq ($(CONFIG_LLSHELL),y)
165crt0s += $(src)/arch/armv7/llshell/llshell.inc
166endif
167
David Hendrickse2851f22013-01-16 15:00:07 -0800168# FIXME: do we need romstage.inc? Maybe just get rid of this entirely.
169#crt0s += $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800170
171$(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(OPTION_TABLE_H) $(obj)/build.h $(obj)/config.h
172 @printf " CC romstage.inc\n"
173 $(CC) -MMD $(CFLAGS) -D__PRE_RAM__ -I$(src) -I. -I$(obj) -c -S $< -o $@
174
David Hendrickse2851f22013-01-16 15:00:07 -0800175#$(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc: $(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc
176# @printf " POST romstage.inc\n"
177# sed -e 's/\.rodata/.rom.data/g' -e 's/\^\.text/.section .rom.text/g' \
178# -e 's/\^\.section \.text/.section .rom.text/g' $^ > $@.tmp
179# mv $@.tmp $@
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800180
181# Things that appear in every board
182romstage-srcs += $(objgenerated)/crt0.s
183ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/mainboard.c
184ifeq ($(CONFIG_GENERATE_PIRQ_TABLE),y)
185ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/irq_tables.c
186endif
187ifeq ($(CONFIG_BOARD_HAS_HARD_RESET),y)
188ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/reset.c
189endif
190ifeq ($(CONFIG_GENERATE_ACPI_TABLES),y)
191ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/acpi_tables.c
192ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/dsdt.asl
193# make doesn't have arithmetic operators or greater-than comparisons
194ifeq ($(subst 5,4,$(CONFIG_ACPI_SSDTX_NUM)),4)
195ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt2.asl
196ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt3.asl
197ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt4.asl
198endif
199ifeq ($(CONFIG_ACPI_SSDTX_NUM),5)
200ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/ssdt5.asl
201endif
202ifeq ($(CONFIG_BOARD_HAS_FADT),y)
203ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/fadt.c
204endif
205endif
206
207ifeq ($(CONFIG_HAVE_BUS_CONFIG),y)
208ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c
209endif
210
211################################################################################
212# Build the final rom image
213
214$(obj)/coreboot.pre: $(objcbfs)/romstage_xip.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
215 @printf " CBFS $(subst $(obj)/,,$(@))\n"
216 cp $(obj)/coreboot.pre1 $@.tmp
217 $(CBFSTOOL) $@.tmp add-stage \
218 -f $(objcbfs)/romstage_xip.elf \
219 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
220 -b $(shell cat $(objcbfs)/base_xip.txt)
221 mv $@.tmp $@
222
223################################################################################
224# Build the bootblock
225
David Hendricks3d7344a2013-01-08 21:05:06 -0800226bootblock_lds = $(src)/arch/armv7/bootblock.lds
227bootblock_lds += $(src)/arch/armv7/lib/id.lds
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800228bootblock_lds += $(chipset_bootblock_lds)
229
David Hendricks3d7344a2013-01-08 21:05:06 -0800230bootblock_inc += $(src)/arch/armv7/bootblock.inc
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800231bootblock_inc += $(src)/arch/armv7/lib/id.inc
232bootblock_inc += $(chipset_bootblock_inc)
David Hendricks3d7344a2013-01-08 21:05:06 -0800233bootblock_inc += $(objgenerated)/bootblock.inc
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800234
235$(objgenerated)/bootblock.ld: $$(bootblock_lds) $(obj)/ldoptions
236 @printf " GEN $(subst $(obj)/,,$(@))\n"
237 printf '$(foreach ldscript,ldoptions $(bootblock_lds),INCLUDE "$(ldscript)"\n)' > $@
238
239$(objgenerated)/bootblock_inc.S: $$(bootblock_inc)
240 @printf " GEN $(subst $(obj)/,,$(@))\n"
241 printf '$(foreach crt0,$(bootblock_inc),#include "$(crt0)"\n)' > $@
242
243$(objgenerated)/bootblock.o: $(objgenerated)/bootblock.s
244 @printf " CC $(subst $(obj)/,,$(@))\n"
245 $(CC) -Wa,-acdlns -c -o $@ $< > $(basename $@).disasm
246
247$(objgenerated)/bootblock.s: $(objgenerated)/bootblock_inc.S $(obj)/config.h $(obj)/build.h
248 @printf " CC $(subst $(obj)/,,$(@))\n"
249 $(CC) -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 $@
250
David Hendricks3d7344a2013-01-08 21:05:06 -0800251$(objgenerated)/bootblock.inc: $(src)/arch/armv7/$(subst ",,$(CONFIG_BOOTBLOCK_SOURCE)) $(OPTION_TABLE_H)
252 @printf " CC $(subst $(obj)/,,$(@))\n"
253 $(CC) $(INCLUDES) -MM -MT$(objgenerated)/bootblock.inc \
254 $< > $(objgenerated)/bootblock.inc.d
255 $(CC) -c -S $(CFLAGS) -I. $(INCLUDES) $< -o $@
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800256
257$(objcbfs)/bootblock.debug: $(objgenerated)/bootblock.o $(objgenerated)/bootblock.ld
258 @printf " LINK $(subst $(obj)/,,$(@))\n"
259ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
260 $(LD) -m armelf_linux_eabi -static -o $@.tmp -L$(obj) $< -T $(objgenerated)/bootblock.ld
261else
David Hendricksfba42a72013-01-17 15:07:35 -0800262 $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/bootblock.ld -Wl,--start-group $< $(LIBGCC_FILE_NAME) -Wl,--end-group
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800263endif
264
265################################################################################
266# Build the romstage
267
Gabe Black929f9f12013-01-17 22:26:36 -0800268romstage_main_c = $(src)/arch/armv7/romstage_main.c
269romstage_main_o = $(obj)/arch/armv7/romstage_main.o
270
271$(romstage_main_o): $(romstage_main_c)
272 @printf " CC $(subst $(obj)/,,$(@))\n"
273 $(CC) -nostdlib -nostartfiles -static -c -o $@ $< -marm
274
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800275# FIXME(dhendrix): added debug printfs
Gabe Black929f9f12013-01-17 22:26:36 -0800276$(objcbfs)/romstage_null.debug: $$(romstage-objs) $(romstage_main_o) $(objgenerated)/romstage_null.ld
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800277 @printf " LINK $(subst $(obj)/,,$(@))\n"
278ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
279 $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) -T $(objgenerated)/romstage_null.ld
280else
Gabe Black929f9f12013-01-17 22:26:36 -0800281 $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_null.ld -Wl,--start-group $(romstage-objs) $(romstage_main_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800282endif
283
284$(objcbfs)/romstage_xip.debug: $$(romstage-objs) $(objgenerated)/romstage_xip.ld
285 @printf " LINK $(subst $(obj)/,,$(@))\n"
286ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Gabe Black929f9f12013-01-17 22:26:36 -0800287 $(LD) -nostdlib -nostartfiles -static -o $@ -L$(obj) $(romstage-objs) $(romstage_main_o) -T $(objgenerated)/romstage_xip.ld
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800288else
Gabe Black929f9f12013-01-17 22:26:36 -0800289 $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(objgenerated)/romstage_xip.ld -Wl,--start-group $(romstage-objs) $(romstage_main_o) $(LIBGCC_FILE_NAME) -Wl,--end-group
Stefan Reinauer52db0b92012-12-07 17:15:04 -0800290endif
291
292$(objgenerated)/romstage_null.ld: $$(ldscripts) $(obj)/ldoptions
293 @printf " GEN $(subst $(obj)/,,$(@))\n"
294 rm -f $@
295 printf "ROMSTAGE_BASE = 0x0;\n" > $@.tmp
296 printf '$(foreach ldscript,ldoptions $(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' >> $@.tmp
297 mv $@.tmp $@
298
299$(objgenerated)/romstage_xip.ld: $(objgenerated)/romstage_null.ld $(objcbfs)/base_xip.txt
300 @printf " GEN $(subst $(obj)/,,$(@))\n"
301 rm -f $@
302 sed -e 's/^/ROMSTAGE_BASE = /g' -e 's/$$/;/g' $(objcbfs)/base_xip.txt > $@.tmp
303 sed -e '/ROMSTAGE_BASE/d' $(objgenerated)/romstage_null.ld >> $@.tmp
304 mv $@.tmp $@
305
306$(objcbfs)/base_xip.txt: $(obj)/coreboot.pre1 $(objcbfs)/romstage_null.bin
307 @printf " generating base_xip.txt\n"
308 rm -f $@
309 $(CBFSTOOL) $(obj)/coreboot.pre1 locate -f $(objcbfs)/romstage_null.bin -n $(CONFIG_CBFS_PREFIX)/romstage -a $(CONFIG_XIP_ROM_SIZE) > $@.tmp \
310 || { echo "The romstage is larger than XIP size. Please expand the CONFIG_XIP_ROM_SIZE" ; exit 1; }
311 sed -e 's/^/0x/g' $@.tmp > $@.tmp2
312 rm $@.tmp
313 mv $@.tmp2 $@
314
315$(objgenerated)/crt0.romstage.S: $$(crt0s)
316 @printf " GEN $(subst $(obj)/,,$(@))\n"
317 printf '$(foreach crt0,$(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@
318
319$(objgenerated)/crt0.romstage.o: $(objgenerated)/crt0.s
320 @printf " CC $(subst $(obj)/,,$(@))\n"
321 $(CC) -Wa,-acdlns -c -o $@ $< > $(basename $@).disasm
322
323$(objgenerated)/crt0.s: $(objgenerated)/crt0.romstage.S $(obj)/config.h $(obj)/build.h
324 @printf " CC $(subst $(obj)/,,$(@))\n"
325 $(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 $@
326