cbfs: add struct cbfsf
[coreboot.git] / Makefile.inc
blob017addc60ee38b5ee627a88c08ff3dfbc19b3d38
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2011 secunet Security Networks AG
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; version 2 of the License.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc.
20 GIT:=$(shell [ -d "$(top)/.git" ] && command -v git)
22 #######################################################################
23 # misleadingly named, this is the coreboot version
24 export KERNELVERSION := $(strip $(if $(GIT),\
25         $(shell git describe --dirty --always || git describe),\
26         $(if $(wildcard $(top)/.coreboot-version),\
27                 $(shell cat $(top)/.coreboot-version),\
28                 coreboot-unknown$(KERNELREVISION))))
30 #######################################################################
31 # Basic component discovery
32 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
33 export MAINBOARDDIR
35 ## Final build results, which CBFSTOOL uses to create the final
36 ## rom image file, are placed under $(objcbfs).
37 ## These typically have suffixes .debug .elf .bin and .map
38 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
40 ## Based on the active configuration, Makefile conditionally collects
41 ## the required assembly includes and saves them in a file.
42 ## Such files that do not have a clear one-to-one relation to a source
43 ## file under src/ are placed and built under $(objgenerated)
44 export objgenerated := $(obj)/generated
46 #######################################################################
47 # root rule to resolve if in build mode (ie. configuration exists)
48 real-target: $(obj)/config.h coreboot
49 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool
51 #######################################################################
52 # our phony targets
53 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
55 #######################################################################
56 # root source directories of coreboot
57 subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi
58 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
59 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
60 subdirs-y += src/superio $(wildcard src/drivers/*) src/cpu src/vendorcode
61 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/broadcom
62 subdirs-y += $(wildcard src/arch/*)
63 subdirs-y += src/mainboard/$(MAINBOARDDIR)
64 subdirs-y += payloads/external
66 subdirs-y += site-local
68 #######################################################################
69 # Add source classes and their build options
70 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode libverstage verstage secmon
72 # Add dynamic classes for rmodules
73 $(foreach supported_arch,$(ARCH_SUPPORTED), \
74             $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
75 # Provide a macro to determine environment for free standing rmodules.
76 $(foreach supported_arch,$(ARCH_SUPPORTED), \
77         $(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
79 #######################################################################
80 # Helper functions for math and various file placement matters.
81 # macros work on all formats understood by printf(1)
82 # values are space separated if using more than one value
84 # int-add:       adds an arbitrary length list of integers
85 # int-subtract:  subtracts the the second of two integers from the first
86 # int-multiply:  multiplies an arbitrary length list of integers
87 # int-divide:    divides the first integer by the second
88 # int-remainder: arithmetic remainder of the first number divided by the second
89 # int-lt:        1 if the first value is less than the second.  0 otherwise
90 # int-gt:        1 if the first values is greater than the second.  0 otherwise
91 # int-eq:        1 if the two values are equal.  0 otherwise
92 # int-align:     align $1 to $2 units
93 # file-size:     returns the filesize of the given file
94 _toint=$(shell printf "%d" $1)
95 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
96 int-add=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-add,$(call _int-add2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1)))
97 int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
98 _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
99 int-multiply=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-multiply,$(call _int-multiply2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1)))
100 int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
101 int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
102 int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
103 int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
104 int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
105 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
106 file-size=$(shell cat $1 | wc -c)
108 #######################################################################
109 # Helper functions for ramstage postprocess
110 spc :=
111 spc +=
112 $(spc) :=
113 $(spc) +=
115 # files-in-dir-recursive,dir,files
116 files-in-dir-recursive=$(filter $(1)%,$(2))
118 # parent-dir,dir/
119 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
121 # filters out exactly the directory specified
122 # filter-out-dir,dir_to_keep,dirs
123 filter-out-dir=$(filter-out $(1),$(2))
125 # filters out dir_to_keep and all its parents
126 # filter-out-dirs,dir_to_keep,dirs
127 filter-out-dirs=$(if $(filter-out ./ /,$(1)),$(call filter-out-dirs,$(call parent-dir,$(1)),$(call filter-out-dir,$(1),$(2))),$(call filter-out-dir,$(1),$(2)))
129 # dir-wildcards,dirs
130 dir-wildcards=$(addsuffix %,$(1))
132 # files-in-dir,dir,files
133 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
135 #######################################################################
136 # reduce command line length by linking the objects of each
137 # directory into an intermediate file
138 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
139         $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
140         $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
141         $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
143 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
144 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
145 ramstage-generic-ccopts += -D__RAMSTAGE__
146 ifeq ($(CONFIG_TRACE),y)
147 ramstage-c-ccopts += -finstrument-functions
148 endif
149 ifeq ($(CONFIG_COVERAGE),y)
150 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
151 endif
153 # try to fetch non-optional submodules if the source is under git
154 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
155 ifeq ($(CONFIG_USE_BLOBS),y)
156 # this is necessary because 3rdparty/blobs is update=none, and so is ignored
157 # unless explicitly requested and enabled through --checkout
158 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
159 endif
161 ramstage-c-deps:=$$(OPTION_TABLE_H)
162 romstage-c-deps:=$$(OPTION_TABLE_H)
163 libverstage-c-deps:=$$(OPTION_TABLE_H)
164 verstage-c-deps:=$$(OPTION_TABLE_H)
165 bootblock-c-deps:=$$(OPTION_TABLE_H)
167 # Add handler to copy linker scripts
168 define generic-objs_ld_template_gen
169 de$(EMPTY)fine $(1)-objs_ld_template
170 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
171         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
172         $$(CC_$(1)) $$(CPPFLAGS_$(1)) $($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h $$$$< > $$$$@.tmp
173         mv $$$$@.tmp $$$$@
174 en$(EMPTY)def
175 endef
177 # Add handler to deal with archives
178 define generic-objs_a_template_gen
179 de$(EMPTY)fine $(1)-objs_a_template
180 $$(call src-to-obj,$1,$$(1).a): $$(1).a
181         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
182         cp $$$$< $$$$@.tmp
183         mv $$$$@.tmp $$$$@
184 en$(EMPTY)def
185 endef
187 # Add handler to add no rules for manual files
188 define generic-objs_manual_template_gen
189 # do nothing
190 endef
192 #######################################################################
193 # Add handler to compile ACPI's ASL
194 # arg1: base file name
195 # arg2: y or n for including in cbfs. defaults to y
196 define asl_template
197 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-file = $(obj)/$(1).aml
198 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-type = raw
199 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-compression = none
200 cbfs-files-$(if $(2),$(2),y) += $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml
201 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
202         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
203         $(CC_ramstage) -x assembler-with-cpp -E -MMD -MT $$(@) $$(CPPFLAGS_ramstage) -D__ACPI__ -P -include $(src)/include/kconfig.h -I$(obj) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-$(ARCH-ramstage-y))/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$@
204         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) $$(notdir $$@)
205 endef
207 #######################################################################
208 # Parse plaintext cmos defaults into binary format
209 # arg1: source file
210 # arg2: binary file name
211 cbfs-files-processor-nvramtool= \
212         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
213                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
215 #######################################################################
216 # Link VSA binary to ELF-ish stage
217 # arg1: source file
218 # arg2: binary file name
219 cbfs-files-processor-vsa= \
220         $(eval $(2): $(1) ; \
221                 printf "    CREATE     $(2) (from $(1))\n";  $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
223 #######################################################################
224 # Add handler for arbitrary files in CBFS
225 $(call add-special-class,cbfs-files)
226 cbfs-files-handler= \
227                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
228                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
229                 $(if $(wildcard $(1)$($(2)-file)), \
230                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
231                         $(eval tmp-cbfs-file:= $($(2)-file))) \
232                 $(if $(strip $($(2)-required)), \
233                         $(if $(wildcard $(tmp-cbfs-file)),, \
234                                 $(info This build configuration requires $($(2)-required)) \
235                                 $(eval FAILBUILD:=1) \
236                         )) \
237                 $(if $(strip $($(2)-align)), \
238                         $(if $(strip $($(2)-position)), \
239                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
240                                 $(eval FAILBUILD:=1) \
241                         )) \
242                 $(if $(tmp-cbfs-method), \
243                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
244                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
245                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
246                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align))\
247                 $(eval $(2)-name:=) \
248                 $(eval $(2)-type:=) \
249                 $(eval $(2)-compression:=) \
250                 $(eval $(2)-position:=) \
251                 $(eval $(2)-required:=) \
252                 $(eval $(2)-align:=)
254 #######################################################################
255 # a variety of flags for our build
256 CBFS_COMPRESS_FLAG:=none
257 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
258 CBFS_COMPRESS_FLAG:=LZMA
259 endif
261 CBFS_PAYLOAD_COMPRESS_FLAG:=none
262 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
263 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
264 endif
266 ifneq ($(CONFIG_LOCALVERSION),"")
267 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
268 endif
270 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
271 CPPFLAGS_common += -Isrc/device/oprom/include
272 CPPFLAGS_common += -include $(src)/include/kconfig.h
274 CFLAGS_common += -pipe -g -nostdinc
275 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
276 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
277 CFLAGS_common += -Wstrict-aliasing -Wshadow
278 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
279 CFLAGS_common += -ffunction-sections -fdata-sections
281 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
283 ifeq ($(CONFIG_COMPILER_GCC),y)
284 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
285 CFLAGS_common += -Wno-unused-but-set-variable
286 endif
288 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
289 CFLAGS_common += -Werror
290 endif
291 ifneq ($(GDB_DEBUG),)
292 CFLAGS_common += -Og
293 else
294 CFLAGS_common += -Os
295 endif
297 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
298                    $(objutil)/ifdfake $(objutil)/options $(objutil)/fletcher \
299                    $(objutil)/cbootimage $(objutil)/bimgtool
301 #######################################################################
302 # generate build support files
303 $(obj)/build.h: .xcompile
304         @printf "    GEN        build.h\n"
305         rm -f $(obj)/build.h
306         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
307         mv $(obj)/build.ht $(obj)/build.h
309 build-dirs:
310         mkdir -p $(objcbfs) $(objgenerated)
312 #######################################################################
313 # Build the tools
314 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
315 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
316 RMODTOOL:=$(objutil)/cbfstool/rmodtool
318 $(obj)/cbfstool: $(CBFSTOOL)
319         cp $< $@
321 $(obj)/fmaptool: $(FMAPTOOL)
322         cp $< $@
324 $(obj)/rmodtool: $(RMODTOOL)
325         cp $< $@
327 _WINCHECK=$(shell uname -o 2> /dev/null)
328 STACK=
329 ifeq ($(_WINCHECK),Msys)
330         STACK=-Wl,--stack,16384000
331 endif
332 ifeq ($(_WINCHECK),Cygwin)
333         STACK=-Wl,--stack,16384000
334 endif
336 # this allows ccache to prepend itself
337 # (ccache handling happens first)
338 ROMCC_BIN= $(objutil)/romcc/romcc
339 ROMCC?=$(ROMCC_BIN)
340 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
341         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
342         @# Note: Adding -O2 here might cause problems. For details see:
343         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
344         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
346 IFDTOOL:=$(objutil)/ifdtool/ifdtool
347 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
348         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
349         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
351 IFDFAKE:=$(objutil)/ifdfake/ifdfake
352 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
353         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
354         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
356 FLETCHER:=$(objutil)/fletcher/fletcher
357 $(FLETCHER): $(top)/util/fletcher/fletcher.c
358         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
359         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
361 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
363 subdirs-y += util/nvidia
365 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
366 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
367         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
368         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
370 #######################################################################
371 # needed objects that every mainboard uses
372 # Creation of these is architecture and mainboard independent
373 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
374         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
375         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
376         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
378 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
379 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
381 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
382         @printf "    CC         $(subst $(obj)/,,$(@))\n"
383         $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
385 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
386         @printf "    CC         $(subst $(obj)/,,$(@))\n"
387         $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
389 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
390         @printf "    CC         $(subst $(obj)/,,$(@))\n"
391         $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
393 $(objgenerated)/libverstage.a: $$(libverstage-objs)
394         rm -f $@
395         $(AR_libverstage) rcsT $@ $^
397 #######################################################################
398 # Clean up rules
399 clean-abuild:
400         rm -rf coreboot-builds
402 clean-for-update-target:
403         rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
404         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
405         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
406         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
407         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
408         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
409         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
410         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
411         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
413 clean-target:
414         rm -f $(obj)/coreboot*
416 #######################################################################
417 # Development utilities
418 printcrt0s:
419         @echo crt0s=$(crt0s)
420         @echo ldscripts=$(ldscripts)
422 update:
423         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
425 lint lint-stable:
426         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
427         for script in util/lint/$@-*; do \
428                 echo; echo `basename $$script`; \
429                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
430                 echo ========; \
431                 $$script > $$LINTLOG; \
432                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
433                         printf "success\n\n"; \
434                 else \
435                         echo test failed: ; \
436                         cat $$LINTLOG; \
437                         rm -f $$LINTLOG; \
438                         FAILED=$$(( $$FAILED + 1 )); \
439                 fi; \
440                 echo ========; \
441         done; \
442         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed."; rm -f $$LINTLOG && exit 1; }; \
443         rm -f $$LINTLOG
445 gitconfig:
446         [ -d .git ]
447         mkdir -p .git/hooks
448         for hook in commit-msg pre-commit ; do                       \
449                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
450                 ! -x .git/hooks/$$hook ]; then                       \
451                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook;  \
452                         chmod +x .git/hooks/$$hook;                  \
453                 fi;                                                  \
454         done
455         # Now set up thehooks for 3rdparty/blobs
456         if [ -d .git/modules/3rdparty -a \
457         \( util/gitconfig/commit-msg -nt .git/modules/3rdparty/hooks/commit-msg -o \
458         ! -x .git/modules/3rdparty/hooks/commit-msg \) ]; then \
459                 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > .git/modules/3rdparty/hooks/commit-msg; \
460                 chmod +x .git/modules/3rdparty/hooks/commit-msg; \
461         fi
462         [ -d 3rdparty/blobs ] && cd 3rdparty/blobs && git config remote.origin.push HEAD:refs/for/master
463         git config remote.origin.push HEAD:refs/for/master
464         (git config --global user.name >/dev/null && git config --global user.email >/dev/null) || (printf 'Please configure your name and email in git:\n\n git config --global user.name "Your Name Comes Here"\n git config --global user.email your.email@example.com\n'; exit 1)
466 crossgcc: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
468 .PHONY: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
469 crossgcc-i386: clean-for-update
470         $(MAKE) -C util/crossgcc build-i386-without-gdb
472 crossgcc-x64: clean-for-update
473         $(MAKE) -C util/crossgcc build-x64-without-gdb
475 crossgcc-arm: clean-for-update
476         $(MAKE) -C util/crossgcc build-armv7a-without-gdb
478 crossgcc-aarch64: clean-for-update
479         $(MAKE) -C util/crossgcc build-aarch64-without-gdb
481 crossgcc-mips: clean-for-update
482         $(MAKE) -C util/crossgcc build-mips-without-gdb
484 crossgcc-riscv: clean-for-update
485         $(MAKE) -C util/crossgcc build-riscv-without-gdb
487 crosstools: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
489 .PHONY: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
490 crosstools-i386: clean-for-update
491         $(MAKE) -C util/crossgcc build-i386
493 crosstools-x64: clean-for-update
494         $(MAKE) -C util/crossgcc build-x64
496 crosstools-arm: clean-for-update
497         $(MAKE) -C util/crossgcc build-armv7a
499 crosstools-aarch64: clean-for-update
500         $(MAKE) -C util/crossgcc build-aarch64
502 crosstools-mips: clean-for-update
503         $(MAKE) -C util/crossgcc build-mips
505 crosstools-riscv: clean-for-update
506         $(MAKE) -C util/crossgcc build-riscv
508 crossgcc-clean: clean-for-update
509         $(MAKE) -C util/crossgcc clean
511 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(FMAPTOOL) $(RMODTOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE)
513 ###########################################################################
514 # Common recipes for all stages
515 ###########################################################################
517 # loadaddr can determine the load address of a stage, which may be needed for
518 # platform-specific image headers (only works *after* the stage has been built)
519 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
520              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
522 # find-substr is required for stages like romstage_null and romstage_xip to
523 # eliminate the _* part of the string
524 find-substr = $(word 1,$(subst _, ,$(1)))
526 # find-class is used to identify the class from the name of the stage
527 # The input to this macro can be something like romstage.x or romstage.x.y
528 # find-class recursively strips off the suffixes to extract the exact class name
529 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
530 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
531 # and remove .x the next time and finally return romstage
532 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
534 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
535 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
536 # include the bss section in the binary so the BootROM clears the bss on
537 # loading of the bootblock stage. Achieve this by marking the bss section
538 # loadable,allocatable, and data. Do the same for the .data section in case
539 # it's marked as NOBITS.
540 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
541         @printf "    OBJCOPY    $(notdir $(@))\n"
542         $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
543         $(OBJCOPY_bootblock) -O binary $<.tmp $@
545 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
546         cp $< $@
548 $(objcbfs)/%.elf: $(objcbfs)/%.debug
549         $(eval class := $(call find-class,$(@F)))
550         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
551         cp $< $@.tmp
552         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
553         $(OBJCOPY_$(class)) --strip-debug $@.tmp
554         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
555         mv $@.tmp $@
557 ###########################################################################
558 # Build the final rom image
559 ###########################################################################
561 COREBOOT_ROM_DEPENDENCIES:=
563 extract_nth=$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-)))
565 cbfs-add-cmd = \
566                $(CBFSTOOL) $@.tmp \
567                add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
568                -f $(call extract_nth,1,$(file)) \
569                -n $(call extract_nth,2,$(file)) \
570                $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
571                $(if $(call extract_nth,4,$(file)),-c $(call extract_nth,4,$(file)))
573 ifneq ($(CONFIG_UPDATE_IMAGE),y)
574 prebuild-files = \
575                $(foreach file,$(cbfs-files), \
576                $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&, \
577                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
578 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
580 $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(FMAPTOOL) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
581         $(CBFSTOOL) $@.tmp create \
582         -B $(objcbfs)/bootblock.bin \
583         $(CBFSTOOL_PRE1_OPTS)
584         $(prebuild-files) true
585         mv $@.tmp $@
586 else
587 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
588 # Add all cbfs files to image of the form: CONFIG_CBFS_PREFIX/<filename>
589 prebuild-files = \
590         $(foreach file,$(cbfs-files), \
591                $(if $(filter $(call strip_quotes, $(CONFIG_CBFS_PREFIX))/%,\
592                    $(call extract_nth,2,$(file))), \
593                $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&,\
594                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&)))
596 .PHONY: $(obj)/coreboot.pre1
597 $(obj)/coreboot.pre1: $$(prebuilt-files) $(CBFSTOOL)
598         mv $(obj)/coreboot.rom $@.tmp
599         $(prebuild-files) true
600         mv $@.tmp $@
601 endif
603 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
604 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
605       ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
606 endif
607 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
608       ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
609 endif
610 endif
612 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
613 REFCODE_BLOB=$(obj)/refcode.rmod
614 $(REFCODE_BLOB): $(RMODTOOL)
615         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
616 endif
618 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(call strip_quotes,$$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $$(VBOOT_STUB) $(REFCODE_BLOB)
619         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
620 # The full ROM may be larger than the CBFS part, so create an empty
621 # file (filled with \377 = 0xff) and copy the CBFS image over it.
622         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
623         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
624         $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/ramstage.elf -n $(CONFIG_CBFS_PREFIX)/ramstage -c $(CBFS_COMPRESS_FLAG)
625 ifeq ($(CONFIG_PAYLOAD_NONE),y)
626         @printf "    PAYLOAD    none (as specified by user)\n"
627 endif
628 ifneq ($(CONFIG_PAYLOAD_FILE),)
629         @printf "    PAYLOAD    $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
630         $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG) $(ADDITIONAL_PAYLOAD_CONFIG)
631 endif
632 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
633 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
634         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
635         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
636 endif
637 endif
638 ifeq ($(CONFIG_SEABIOS_VGA_COREBOOT),y)
639         @printf "    SeaBIOS    Adding generated legacy VGA option rom.\n"
640         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PAYLOAD_VGABIOS_FILE) -n vgaroms/seavgabios.bin -t raw
641 endif
642 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
643         @printf "    CONFIG     $(DOTCONFIG)\n"
644         if [ -f $(DOTCONFIG) ]; then \
645         echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp && \
646         $(MAKE) DOTCONFIG=$(DOTCONFIG) DEFCONFIG=$(obj)/config.tmp savedefconfig && \
647         $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
648         @printf "    REVISION   build.h\n"
649         if [ -f $(obj)/build.h ]; then $(CBFSTOOL) $@.tmp add -f $(obj)/build.h -n revision -t raw; fi
650 endif
651 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
652         $(CBFSTOOL) $@.tmp add-stage -f $(REFCODE_BLOB) -n $(CONFIG_CBFS_PREFIX)/refcode -c $(CBFS_COMPRESS_FLAG)
653 endif
654 ifeq ($(CONFIG_PXE_ROM),y)
655         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PXE_ROM_FILE) -n pci$(CONFIG_PXE_ROM_ID).rom -t raw
656 endif
657 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
658 ifeq ($(CONFIG_CPU_MICROCODE_ADDED_DURING_BUILD),y)
659         @printf "    UPDATE-FIT \n"
660         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
661 endif
662 endif
663 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
664         @printf "    CONFIG     $(PAYLOAD_CONFIG)\n"
665         if [ -f "$(PAYLOAD_CONFIG)" ]; then \
666                 $(CBFSTOOL) $@.tmp add -f  "$(PAYLOAD_CONFIG)" -n payload_config -t raw; \
667         fi
668         @printf "    REVISION   $(PAYLOAD_VERSION)\n"
669         if [ -f "$(PAYLOAD_VERSION)" ]; then \
670                 $(CBFSTOOL) $@.tmp add -f "$(PAYLOAD_VERSION)" -n payload_revision -t raw; \
671         fi
672 endif
673         mv $@.tmp $@
674         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
675         $(CBFSTOOL) $@ print
677 cbfs-files-$(CONFIG_BOOTSPLASH) += bootsplash.jpg
678 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
679 bootsplash.jpg-type := bootsplash
681 $(obj)/coreboot.pre: $(objcbfs)/romstage.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
682         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
683         cp $(obj)/coreboot.pre1 $@.tmp
684         $(CBFSTOOL) $@.tmp add-stage \
685                 -f $(objcbfs)/romstage.elf \
686                 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
687                 $(CBFSTOOL_PRE_OPTS)
688         mv $@.tmp $@
690 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
691 board_id-file := $(obj)/board_id
692 board_id-type := raw
694 $(obj)/board_id:
695         printf $(CONFIG_BOARD_ID_STRING) > $@
697 JENKINS_PAYLOAD?=none
698 CPUS?=4
699 what-jenkins-does:
700         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD) -x
701         -mv abuild.xml abuild-chromeos.xml
702         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD)
703         (cd payloads/libpayload; unset COREBOOT_BUILD_DIR; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_LP_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
704         $(MAKE) V=$(V) Q=$(Q) -C util/cbmem junit.xml