Makefile.inc 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. ifneq ($(NOCOMPILE),1)
  3. GIT:=$(shell git -C "$(top)" rev-parse --git-dir 1>/dev/null 2>&1 \
  4. && command -v git)
  5. else
  6. GIT:=
  7. endif
  8. #######################################################################
  9. # normalize Kconfig variables in a central place
  10. CONFIG_CBFS_PREFIX:=$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
  11. CONFIG_FMDFILE:=$(call strip_quotes,$(CONFIG_FMDFILE))
  12. CONFIG_DEVICETREE:=$(call strip_quotes, $(CONFIG_DEVICETREE))
  13. CONFIG_OVERRIDE_DEVICETREE:=$(call strip_quotes, $(CONFIG_OVERRIDE_DEVICETREE))
  14. CONFIG_CHIPSET_DEVICETREE:=$(call strip_quotes, $(CONFIG_CHIPSET_DEVICETREE))
  15. CONFIG_MEMLAYOUT_LD_FILE:=$(call strip_quotes, $(CONFIG_MEMLAYOUT_LD_FILE))
  16. #######################################################################
  17. # misleadingly named, this is the coreboot version
  18. ifeq ($(KERNELVERSION),)
  19. ifeq ($(BUILD_TIMELESS),1)
  20. KERNELVERSION := -TIMELESS--LESSTIME-
  21. else
  22. KERNELVERSION := $(strip $(if $(GIT),\
  23. $(shell git describe --dirty --always || git describe),\
  24. $(if $(wildcard $(top)/.coreboot-version),\
  25. $(shell cat $(top)/.coreboot-version),\
  26. coreboot-unknown$(KERNELREVISION))))
  27. endif
  28. endif
  29. COREBOOT_EXPORTS += KERNELVERSION
  30. #######################################################################
  31. # Basic component discovery
  32. MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
  33. VARIANT_DIR:=$(call strip_quotes,$(CONFIG_VARIANT_DIR))
  34. CARRIER_DIR:=$(call strip_quotes,$(CONFIG_CARRIER_DIR))
  35. COREBOOT_EXPORTS += MAINBOARDDIR VARIANT_DIR CARRIER_DIR
  36. ## Final build results, which CBFSTOOL uses to create the final
  37. ## rom image file, are placed under $(objcbfs).
  38. ## These typically have suffixes .debug .elf .bin and .map
  39. objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
  40. additional-dirs += $(objcbfs)
  41. COREBOOT_EXPORTS += objcbfs
  42. ## Based on the active configuration, Makefile conditionally collects
  43. ## the required assembly includes and saves them in a file.
  44. ## Such files that do not have a clear one-to-one relation to a source
  45. ## file under src/ are placed and built under $(objgenerated)
  46. objgenerated := $(obj)/generated
  47. additional-dirs += $(objgenerated)
  48. COREBOOT_EXPORTS += objgenerated
  49. ## CCACHE_EXTRAFILES can be set by individual rules to help CCACHE
  50. ## discover dependencies it might not notice on its own (e.g. asm (".incbin")).
  51. COREBOOT_EXPORTS += CCACHE_EXTRAFILES
  52. #######################################################################
  53. # root rule to resolve if in build mode (ie. configuration exists)
  54. real-target: $(obj)/config.h coreboot files_added
  55. coreboot: $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool $(obj)/ifwitool $(obj)/cse_fpt $(obj)/cse_serger
  56. # This target can be used in site local to run scripts or additional
  57. # targets after the build completes by creating a Makefile.inc in the
  58. # site-local directory with a target named 'build_complete::'
  59. build_complete:: coreboot
  60. printf "\nBuilt %s (%s)\n" $(MAINBOARDDIR) \
  61. $(CONFIG_MAINBOARD_PART_NUMBER)
  62. # This target can be used to run rules after all files were added to CBFS,
  63. # for example to process FMAP regions or the entire image.
  64. files_added:: build_complete
  65. #######################################################################
  66. # our phony targets
  67. PHONY+= clean-abuild coreboot check-style build_complete
  68. #######################################################################
  69. # root source directories of coreboot
  70. subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi src/superio/common
  71. subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
  72. subdirs-y += $(wildcard src/soc/*) $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
  73. subdirs-y += $(wildcard src/superio/*) $(wildcard src/superio/*/*)
  74. subdirs-y += $(wildcard src/drivers/*) $(wildcard src/drivers/*/*) $(wildcard src/drivers/*/*/*)
  75. subdirs-y += src/cpu src/vendorcode
  76. subdirs-y += util/cbfstool util/sconfig util/nvramtool util/pgtblgen util/amdfwtool
  77. subdirs-y += util/futility util/marvell util/bincfg util/supermicro util/qemu
  78. subdirs-y += util/ifdtool
  79. subdirs-y += $(wildcard src/arch/*)
  80. subdirs-y += src/mainboard/$(MAINBOARDDIR)
  81. subdirs-y += src/security
  82. subdirs-y += payloads payloads/external
  83. subdirs-y += site-local
  84. subdirs-y += util/checklist util/testing
  85. #######################################################################
  86. # Add source classes and their build options
  87. classes-y := ramstage romstage bootblock decompressor postcar smm smmstub cpu_microcode verstage
  88. # Add a special 'all' class to add sources to all stages
  89. $(call add-special-class,all)
  90. all-handler = $(foreach class,bootblock verstage romstage postcar ramstage,$(eval $(class)-y += $(2)))
  91. $(call add-special-class,verstage_x86)
  92. ifeq ($(CONFIG_ARCH_VERSTAGE_X86_32)$(CONFIG_ARCH_VERSTAGE_X86_64),y)
  93. verstage_x86-handler = $(eval verstage-y += $(2))
  94. else
  95. verstage_x86-handler =
  96. endif
  97. # Add dynamic classes for rmodules
  98. $(foreach supported_arch,$(ARCH_SUPPORTED), \
  99. $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
  100. # Provide a macro to determine environment for free standing rmodules.
  101. $(foreach supported_arch,$(ARCH_SUPPORTED), \
  102. $(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
  103. #######################################################################
  104. # Helper functions for math, strings, and various file placement matters.
  105. # macros work on all formats understood by printf(1)
  106. # values are space separated if using more than one value
  107. #
  108. # int-add: adds an arbitrary length list of integers
  109. # int-subtract: subtracts the second of two integers from the first
  110. # int-multiply: multiplies an arbitrary length list of integers
  111. # int-divide: divides the first integer by the second
  112. # int-remainder: arithmetic remainder of the first number divided by the second
  113. # int-shift-left: Shift $1 left by $2 bits
  114. # int-lt: 1 if the first value is less than the second. 0 otherwise
  115. # int-gt: 1 if the first values is greater than the second. 0 otherwise
  116. # int-eq: 1 if the two values are equal. 0 otherwise
  117. # int-align: align $1 to $2 units
  118. # file-size: returns the filesize of the given file
  119. # tolower: returns the value in all lowercase
  120. # toupper: returns the value in all uppercase
  121. # ws_to_under: returns the value with any whitespace changed to underscores
  122. _toint=$(shell printf "%d" $1)
  123. _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
  124. 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)))
  125. int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
  126. _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
  127. 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)))
  128. int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
  129. int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
  130. int-shift-left=$(shell echo "$(call _toint,$(word 1, $1)) * (2 ^ $(call _toint,$(word 2, $1)))" | bc)
  131. int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
  132. int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
  133. int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
  134. int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
  135. int-align-down=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A - \( $$A % $$B \) )
  136. file-size=$(strip $(shell cat $1 | wc -c))
  137. tolower=$(shell echo '$1' | tr '[:upper:]' '[:lower:]')
  138. toupper=$(shell echo '$1' | tr '[:lower:]' '[:upper:]')
  139. ws_to_under=$(shell echo '$1' | tr ' \t' '_')
  140. #######################################################################
  141. # Helper functions for ramstage postprocess
  142. spc :=
  143. spc := $(spc) $(spc)
  144. comma := ,
  145. # Returns all files and dirs below `dir` (recursively).
  146. # files-below-dir,dir,files
  147. files-below-dir=$(filter $(1)%,$(2))
  148. # Returns all dirs below `dir` (recursively).
  149. # dirs-below-dir,dir,files
  150. dirs-below-dir=$(filter-out $(1),$(sort $(dir $(call files-below-dir,$(1),$(2)))))
  151. # Returns all files directly in `dir` (non-recursively).
  152. # files-in-dir,dir,files
  153. files-in-dir=$(filter-out $(addsuffix %,$(call dirs-below-dir,$(1),$(2))),$(call files-below-dir,$(1),$(2)))
  154. #######################################################################
  155. # reduce command line length by linking the objects of each
  156. # directory into an intermediate file
  157. ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
  158. $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
  159. $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
  160. $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
  161. decompressor-generic-ccopts += -D__DECOMPRESSOR__
  162. bootblock-generic-ccopts += -D__BOOTBLOCK__
  163. romstage-generic-ccopts += -D__ROMSTAGE__
  164. ramstage-generic-ccopts += -D__RAMSTAGE__
  165. ifeq ($(CONFIG_COVERAGE),y)
  166. ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
  167. endif
  168. ifneq ($(UPDATED_SUBMODULES),1)
  169. # try to fetch non-optional submodules if the source is under git
  170. forgetthis:=$(if $(GIT),$(shell git submodule update --init))
  171. # Checkout Cmocka repository
  172. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/cmocka))
  173. ifeq ($(CONFIG_USE_BLOBS),y)
  174. # These items are necessary because each has update=none in .gitmodules. They are ignored
  175. # until expressly requested and enabled with --checkout
  176. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
  177. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/intel-microcode))
  178. ifeq ($(CONFIG_FSP_USE_REPO),y)
  179. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/fsp))
  180. endif
  181. ifeq ($(CONFIG_USE_AMD_BLOBS),y)
  182. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/amd_blobs))
  183. endif
  184. ifeq ($(CONFIG_USE_QC_BLOBS),y)
  185. forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/qc_blobs))
  186. endif
  187. endif
  188. UPDATED_SUBMODULES:=1
  189. COREBOOT_EXPORTS += UPDATED_SUBMODULES
  190. endif
  191. postcar-c-deps:=$$(OPTION_TABLE_H)
  192. ramstage-c-deps:=$$(OPTION_TABLE_H)
  193. romstage-c-deps:=$$(OPTION_TABLE_H)
  194. verstage-c-deps:=$$(OPTION_TABLE_H)
  195. bootblock-c-deps:=$$(OPTION_TABLE_H)
  196. $(foreach type,ads adb, \
  197. $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
  198. $(eval $(stage)-$(type)-deps := \
  199. $(obj)/$(stage)/$(notdir $(KCONFIG_AUTOADS)) \
  200. $(obj)/libgnat-$(ARCH-$(stage)-y)/libgnat.a)))
  201. # Add handler to copy linker scripts
  202. define generic-objs_ld_template_gen
  203. de$(EMPTY)fine $(1)-objs_ld_template
  204. $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h $(obj)/fmap_config.h
  205. @printf " CP $$$$(subst $$$$(obj)/,,$$$$(@))\n"
  206. $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
  207. en$(EMPTY)def
  208. endef
  209. # Add handler to deal with archives
  210. define generic-objs_a_template_gen
  211. de$(EMPTY)fine $(1)-objs_a_template
  212. $$(call src-to-obj,$1,$$(1).a): $$(1).a
  213. @printf " AR $$$$(subst $$$$(obj)/,,$$$$(@))\n"
  214. $$$$(AR_$(1)) rcsT $$$$@.tmp $$$$<
  215. mv $$$$@.tmp $$$$@
  216. en$(EMPTY)def
  217. endef
  218. # Add handler to add no rules for manual files
  219. define generic-objs_manual_template_gen
  220. # do nothing
  221. endef
  222. #######################################################################
  223. # Add handler to compile ACPI's ASL
  224. # arg1: base file name
  225. # arg2: y or n for including in cbfs. defaults to y
  226. # Empty resource templates were marked as a warning in IASL with the comment
  227. # "This would appear to be worthless in real-world ASL code.", which is
  228. # possibly true in many cases. In other cases it seems that an empty
  229. # ResourceTemplate is the correct code.
  230. # As it's valid ASL, disable the warning.
  231. EMPTY_RESOURCE_TEMPLATE_WARNING = 3150
  232. # Redundant offset remarks are not useful in any way and are masking useful
  233. # ones that might indicate an issue so it is better to hide them.
  234. REDUNDANT_OFFSET_REMARK = 2158
  235. # Ignore _HID & _ADR coexisting in Intel Lynxpoint ASL code.
  236. # See cb:38802
  237. # "Multiple types (Device object requires either a _HID or _ADR, but not both)"
  238. MULTIPLE_TYPES_WARNING = 3073
  239. IASL_WARNINGS_LIST = $(EMPTY_RESOURCE_TEMPLATE_WARNING) $(REDUNDANT_OFFSET_REMARK)
  240. ifeq ($(CONFIG_SOUTHBRIDGE_INTEL_LYNXPOINT),y)
  241. IASL_WARNINGS_LIST += $(MULTIPLE_TYPES_WARNING)
  242. endif
  243. IGNORED_IASL_WARNINGS = $(addprefix -vw , $(IASL_WARNINGS_LIST))
  244. define asl_template
  245. $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
  246. $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
  247. $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
  248. cbfs-files-$(if $(2),$(2),y) += $(CONFIG_CBFS_PREFIX)/$(1).aml
  249. -include $(obj)/$(1).d
  250. $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
  251. @printf " IASL $$(subst $(top)/,,$$(@))\n"
  252. $(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 $(obj)/$(1).asl
  253. cd $$(dir $$@); $(IASL) $(IGNORED_IASL_WARNINGS) -we -p $$(notdir $$@) $(1).asl
  254. echo " IASL "$(IASL_WARNINGS_LIST)" warning types were ignored!"
  255. if ! $(IASL) -d $$@ 2>&1 | grep -Eq 'ACPI (Warning|Error)'; then \
  256. echo " IASL $$@ disassembled correctly."; \
  257. true; \
  258. else \
  259. echo "Error: Could not correctly disassemble $$@"; \
  260. $(IASL) -d $$@; \
  261. false; \
  262. fi
  263. endef
  264. #######################################################################
  265. # Parse plaintext CMOS defaults into binary format
  266. # arg1: source file
  267. # arg2: binary file name
  268. cbfs-files-processor-nvramtool= \
  269. $(eval $(2): $(1) $(top)/$(call strip_quotes,$(CONFIG_CMOS_LAYOUT_FILE)) | $(objutil)/nvramtool/nvramtool ; \
  270. printf " CREATE $(2) (from $(1))\n"; \
  271. $(objutil)/nvramtool/nvramtool -y $(top)/$(call strip_quotes,$(CONFIG_CMOS_LAYOUT_FILE)) -D $(2).tmp -p $(1) && \
  272. mv $(2).tmp $(2))
  273. #######################################################################
  274. # Reduce a .config file to its minimal representation
  275. # arg1: input
  276. # arg2: output
  277. define cbfs-files-processor-defconfig
  278. $(eval $(2): $(1) $(obj)/build.h $(objutil)/kconfig/conf; \
  279. +printf " CREATE $(2) (from $(1))\n"; \
  280. printf "# This image was built using coreboot " > $(2).tmp && \
  281. grep "\<COREBOOT_VERSION\>" $(obj)/build.h |cut -d\" -f2 >> $(2).tmp && \
  282. $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp2 savedefconfig && \
  283. cat $(2).tmp2 >> $(2).tmp && \
  284. rm -f $(2).tmp2 && \
  285. \mv -f $(2).tmp $(2))
  286. endef
  287. #######################################################################
  288. # Compile a C file with a bare struct definition into binary
  289. # arg1: C source file
  290. # arg2: binary file
  291. cbfs-files-processor-struct= \
  292. $(eval $(2): $(1) $(obj)/build.h $(KCONFIG_AUTOHEADER); \
  293. printf " CC+STRIP $(1)\n"; \
  294. $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) --param asan-globals=0 $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \
  295. $(OBJCOPY_ramstage) -O binary --set-section-flags .bss*=alloc,contents,load $(2).tmp $(2); \
  296. rm -f $(2).tmp) \
  297. $(eval DEPENDENCIES += $(2).d)
  298. #######################################################################
  299. # Add handler for arbitrary files in CBFS
  300. $(call add-special-class,cbfs-files)
  301. cbfs-files-handler= \
  302. $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
  303. $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
  304. $(eval tmp-cbfs-file:= ) \
  305. $(if $($(2)-file), \
  306. $(if $(wildcard $(1)$($(2)-file)), \
  307. $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
  308. $(eval tmp-cbfs-file:= $($(2)-file)))) \
  309. $(if $(strip $($(2)-required)), \
  310. $(if $(wildcard $(tmp-cbfs-file)),, \
  311. $(info This build configuration requires $($(2)-required)) \
  312. $(eval FAILBUILD:=1) \
  313. )) \
  314. $(if $(strip $($(2)-align)), \
  315. $(if $(strip $($(2)-position)), \
  316. $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
  317. $(eval FAILBUILD:=1) \
  318. )) \
  319. $(if $(tmp-cbfs-method), \
  320. $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
  321. $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
  322. $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
  323. $(if $(tmp-cbfs-file), \
  324. $(eval cbfs-files += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
  325. $(eval $(2)-name:=) \
  326. $(eval $(2)-type:=) \
  327. $(eval $(2)-compression:=) \
  328. $(eval $(2)-position:=) \
  329. $(eval $(2)-required:=) \
  330. $(eval $(2)-options:=) \
  331. $(eval $(2)-align:=)
  332. #######################################################################
  333. # a variety of flags for our build
  334. CBFS_COMPRESS_FLAG:=none
  335. ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
  336. CBFS_COMPRESS_FLAG:=LZMA
  337. endif
  338. CBFS_PAYLOAD_COMPRESS_FLAG:=none
  339. ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
  340. CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
  341. endif
  342. ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZ4),y)
  343. CBFS_PAYLOAD_COMPRESS_FLAG:=LZ4
  344. endif
  345. CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG:=none
  346. ifeq ($(CONFIG_COMPRESS_SECONDARY_PAYLOAD),y)
  347. CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG:=LZMA
  348. endif
  349. CBFS_PRERAM_COMPRESS_FLAG:=none
  350. ifeq ($(CONFIG_COMPRESS_PRERAM_STAGES),y)
  351. CBFS_PRERAM_COMPRESS_FLAG:=LZ4
  352. endif
  353. ifneq ($(CONFIG_LOCALVERSION),"")
  354. COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
  355. COREBOOT_EXPORTS += COREBOOT_EXTRA_VERSION
  356. endif
  357. CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -Isrc/commonlib/bsd/include -I$(obj)
  358. VBOOT_SOURCE ?= 3rdparty/vboot
  359. CPPFLAGS_common += -I$(VBOOT_SOURCE)/firmware/include
  360. CPPFLAGS_common += -include $(src)/include/kconfig.h
  361. CPPFLAGS_common += -include $(src)/include/rules.h
  362. CPPFLAGS_common += -include $(src)/commonlib/bsd/include/commonlib/bsd/compiler.h
  363. CPPFLAGS_common += -I3rdparty
  364. CPPFLAGS_common += -D__BUILD_DIR__=\"$(obj)\"
  365. ifeq ($(BUILD_TIMELESS),1)
  366. CPPFLAGS_common += -D__TIMELESS__
  367. endif
  368. ifeq ($(CONFIG_PCI_OPTION_ROM_RUN_YABEL)$(CONFIG_PCI_OPTION_ROM_RUN_REALMODE),y)
  369. CPPFLAGS_ramstage += -Isrc/device/oprom/include
  370. endif
  371. CFLAGS_common += -pipe -g -nostdinc -std=gnu11
  372. CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
  373. CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough
  374. CFLAGS_common += -Wshadow -Wdate-time -Wtype-limits -Wvla
  375. CFLAGS_common += -Wdangling-else
  376. CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
  377. CFLAGS_common += -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie
  378. ifeq ($(CONFIG_COMPILER_GCC),y)
  379. # Don't add these GCC specific flags when running scan-build
  380. ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
  381. CFLAGS_common += -Wno-packed-not-aligned
  382. CFLAGS_common += -fconserve-stack
  383. CFLAGS_common += -Wnull-dereference -Wreturn-type
  384. CFLAGS_common += -Wlogical-op -Wduplicated-cond
  385. # cf. commit f69a99db (coreboot: x86: enable gc-sections)
  386. CFLAGS_common += -Wno-unused-but-set-variable
  387. endif
  388. endif
  389. ADAFLAGS_common += -gnatp
  390. ADAFLAGS_common += -Wuninitialized -Wall -Werror
  391. ADAFLAGS_common += -pipe -g -nostdinc
  392. ADAFLAGS_common += -Wstrict-aliasing -Wshadow
  393. ADAFLAGS_common += -fno-common -fomit-frame-pointer
  394. ADAFLAGS_common += -ffunction-sections -fdata-sections
  395. # Ada warning options:
  396. #
  397. # a Activate most optional warnings.
  398. # .e Activate every optional warnings.
  399. # e Treat warnings and style checks as errors.
  400. #
  401. # D Suppress warnings on implicit dereferences:
  402. # As SPARK does not accept access types we have to map the
  403. # dynamically chosen register locations to a static SPARK
  404. # variable.
  405. #
  406. # .H Suppress warnings on holes/gaps in records:
  407. # We are modelling hardware here!
  408. #
  409. # H Suppress warnings on hiding:
  410. # It's too annoying, you run out of ideas for identifiers fast.
  411. #
  412. # T Suppress warnings for tracking of deleted conditional code:
  413. # We use static options to select code paths at compile time.
  414. #
  415. # U Suppress warnings on unused entities:
  416. # Would have lots of warnings for unused register definitions,
  417. # `withs` for debugging etc.
  418. #
  419. # .U Deactivate warnings on unordered enumeration types:
  420. # As SPARK doesn't support `pragma Ordered` by now, we don't
  421. # use that, yet.
  422. #
  423. # .W Suppress warnings on unnecessary Warnings Off pragmas:
  424. # Things get really messy when you use different compiler
  425. # versions, otherwise.
  426. # .Y Disable information messages for why package spec needs body:
  427. # Those messages are annoying. But don't forget to enable those,
  428. # if you need the information.
  429. ADAFLAGS_common += -gnatwa.eeD.HHTU.U.W.Y
  430. # Disable style checks for now
  431. ADAFLAGS_common += -gnatyN
  432. LDFLAGS_common := --gc-sections -nostdlib --nmagic -static
  433. # Workaround for RISC-V linker bug, merge back into above line when fixed.
  434. # https://sourceware.org/bugzilla/show_bug.cgi?id=27180
  435. ifneq ($(CONFIG_ARCH_RISCV),y)
  436. LDFLAGS_common += --emit-relocs
  437. endif
  438. ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
  439. CFLAGS_common += -Werror
  440. endif
  441. ifneq ($(GDB_DEBUG),)
  442. CFLAGS_common += -Og
  443. ADAFLAGS_common += -Og
  444. else
  445. CFLAGS_common += -Os
  446. ADAFLAGS_common += -Os
  447. endif
  448. ifeq ($(CONFIG_DEBUG_ADA_CODE),y)
  449. ADAFLAGS_common += -gnata
  450. endif
  451. additional-dirs += $(objutil)/cbfstool $(objutil)/ifdtool \
  452. $(objutil)/options $(objutil)/amdfwtool \
  453. $(objutil)/cbootimage
  454. export $(COREBOOT_EXPORTS)
  455. #######################################################################
  456. # generate build support files
  457. build_h := $(obj)/build.h
  458. # We have to manually export variables that `genbuild_h.sh` uses
  459. # when we call it through the `$(shell)` function. This is fragile
  460. # but as variables newly added to `genbuild_h.sh` would just not
  461. # work, we'd notice that instantly at least.
  462. build_h_exports := BUILD_TIMELESS KERNELVERSION COREBOOT_EXTRA_VERSION
  463. # Report new `build.ht` as dependency if `build.h` differs.
  464. build_h_check := \
  465. export $(foreach exp,$(build_h_exports),$(exp)="$($(exp))"); \
  466. util/genbuild_h/genbuild_h.sh $(xcompile) \
  467. >$(build_h)t 2>/dev/null; \
  468. cmp -s $(build_h)t $(build_h) >/dev/null 2>&1 || echo $(build_h)t
  469. $(build_h): $$(shell $$(build_h_check))
  470. @printf " GEN build.h\n"
  471. mv $< $@
  472. $(obj)/build_info:
  473. @echo 'COREBOOT_VERSION: $(call strip_quotes,$(KERNELVERSION))' > $@.tmp
  474. @echo 'MAINBOARD_VENDOR: $(call strip_quotes,$(CONFIG_MAINBOARD_VENDOR))' >> $@.tmp
  475. @echo 'MAINBOARD_PART_NUMBER: $(call strip_quotes,$(CONFIG_MAINBOARD_PART_NUMBER))' >> $@.tmp
  476. mv $@.tmp $@
  477. #######################################################################
  478. # Build the tools
  479. CBFSTOOL:=$(objutil)/cbfstool/cbfstool
  480. FMAPTOOL:=$(objutil)/cbfstool/fmaptool
  481. RMODTOOL:=$(objutil)/cbfstool/rmodtool
  482. IFWITOOL:=$(objutil)/cbfstool/ifwitool
  483. IFITTOOL:=$(objutil)/cbfstool/ifittool
  484. AMDCOMPRESS:=$(objutil)/cbfstool/amdcompress
  485. CSE_FPT:=$(objutil)/cbfstool/cse_fpt
  486. CSE_SERGER:=$(objutil)/cbfstool/cse_serger
  487. $(obj)/cbfstool: $(CBFSTOOL)
  488. cp $< $@
  489. $(obj)/fmaptool: $(FMAPTOOL)
  490. cp $< $@
  491. $(obj)/rmodtool: $(RMODTOOL)
  492. cp $< $@
  493. $(obj)/ifwitool: $(IFWITOOL)
  494. cp $< $@
  495. $(obj)/ifittool: $(IFITTOOL)
  496. cp $< $@
  497. $(obj)/amdcompress: $(AMDCOMPRESS)
  498. cp $< $@
  499. $(obj)/cse_fpt: $(CSE_FPT)
  500. cp $< $@
  501. $(obj)/cse_serger: $(CSE_SERGER)
  502. cp $< $@
  503. _WINCHECK=$(shell uname -o 2> /dev/null)
  504. STACK=
  505. ifeq ($(_WINCHECK),Msys)
  506. STACK=-Wl,--stack,16384000
  507. endif
  508. ifeq ($(_WINCHECK),Cygwin)
  509. STACK=-Wl,--stack,16384000
  510. endif
  511. BINCFG:=$(objutil)/bincfg/bincfg
  512. IFDTOOL:=$(objutil)/ifdtool/ifdtool
  513. AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
  514. APCB_EDIT_TOOL:=$(top)/util/apcb/apcb_edit.py
  515. CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
  516. FUTILITY?=$(objutil)/futility/futility
  517. subdirs-y += util/nvidia
  518. $(obj)/config.h: $(objutil)/kconfig/conf
  519. #######################################################################
  520. # needed objects that every mainboard uses
  521. # Creation of these is architecture and mainboard independent
  522. DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_DEVICETREE)
  523. SCONFIG_OPTIONS := --mainboard_devtree=$(DEVICETREE_FILE)
  524. ifneq ($(CONFIG_OVERRIDE_DEVICETREE),)
  525. OVERRIDE_DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_OVERRIDE_DEVICETREE)
  526. SCONFIG_OPTIONS += --override_devtree=$(OVERRIDE_DEVICETREE_FILE)
  527. endif
  528. ifneq ($(CONFIG_CHIPSET_DEVICETREE),)
  529. CHIPSET_DEVICETREE_FILE := $(src)/$(CONFIG_CHIPSET_DEVICETREE)
  530. SCONFIG_OPTIONS += --chipset_devtree=$(CHIPSET_DEVICETREE_FILE)
  531. endif
  532. DEVICETREE_STATIC_C := $(obj)/mainboard/$(MAINBOARDDIR)/static.c
  533. SCONFIG_OPTIONS += --output_c=$(DEVICETREE_STATIC_C)
  534. DEVICETREE_STATIC_H := $(obj)/static.h
  535. SCONFIG_OPTIONS += --output_h=$(DEVICETREE_STATIC_H)
  536. DEVICETREE_DEVICENAMES_H := $(obj)/static_devices.h
  537. SCONFIG_OPTIONS += --output_d=$(DEVICETREE_DEVICENAMES_H)
  538. DEVICETREE_FWCONFIG_H := $(obj)/static_fw_config.h
  539. SCONFIG_OPTIONS += --output_f=$(DEVICETREE_FWCONFIG_H)
  540. $(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(OVERRIDE_DEVICETREE_FILE) $(CHIPSET_DEVICETREE_FILE) $(objutil)/sconfig/sconfig
  541. @printf " SCONFIG $(subst $(src)/,,$(<))\n"
  542. mkdir -p $(dir $(DEVICETREE_STATIC_C))
  543. $(objutil)/sconfig/sconfig $(SCONFIG_OPTIONS)
  544. ramstage-y+=$(DEVICETREE_STATIC_C)
  545. romstage-y+=$(DEVICETREE_STATIC_C)
  546. verstage-y+=$(DEVICETREE_STATIC_C)
  547. bootblock-y+=$(DEVICETREE_STATIC_C)
  548. postcar-y+=$(DEVICETREE_STATIC_C)
  549. smm-y+=$(DEVICETREE_STATIC_C)
  550. # Ensure static.c and static.h are created before any objects are compiled
  551. ramstage-c-deps+=$(DEVICETREE_STATIC_C)
  552. romstage-c-deps+=$(DEVICETREE_STATIC_C)
  553. verstage-c-deps+=$(DEVICETREE_STATIC_C)
  554. bootblock-c-deps+=$(DEVICETREE_STATIC_C)
  555. postcar-c-deps+=$(DEVICETREE_STATIC_C)
  556. smm-c-deps+=$(DEVICETREE_STATIC_C)
  557. .PHONY: devicetree
  558. devicetree: $(DEVICETREE_STATIC_C)
  559. ramstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  560. romstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  561. bootblock-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  562. verstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  563. postcar-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  564. decompressor-y += $(CONFIG_MEMLAYOUT_LD_FILE)
  565. #######################################################################
  566. # Clean up rules
  567. clean-abuild:
  568. rm -rf coreboot-builds
  569. clean-for-update-target: clean-payloads
  570. rm -f $(obj)/ramstage?* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
  571. rm -rf $(obj)/bootblock?* $(obj)/romstage?* $(obj)/location.*
  572. rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
  573. rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
  574. rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
  575. rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
  576. rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/dsdt.*
  577. rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
  578. clean-target:
  579. rm -f $(obj)/coreboot*
  580. #######################################################################
  581. # Development utilities
  582. printcrt0s:
  583. @echo crt0s=$(crt0s)
  584. @echo ldscripts=$(ldscripts)
  585. update:
  586. dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
  587. check-style:
  588. grep "^# DESCR:" util/lint/check-style | sed "s,.*DESCR: *,,"
  589. echo "========"
  590. util/lint/check-style
  591. echo "========"
  592. gitconfig:
  593. util/gitconfig/gitconfig.sh "$(MAKE)"
  594. install-git-commit-clangfmt:
  595. cp util/scripts/prepare-commit-msg.clang-format .git/hooks/prepare-commit-msg
  596. include util/crossgcc/Makefile.inc
  597. .PHONY: tools
  598. tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(AMDFWTOOL) $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL) $(objutil)/supermicro/smcbiosinfo $(CSE_FPT) $(CSE_SERGER)
  599. ###########################################################################
  600. # Common recipes for all stages
  601. ###########################################################################
  602. # loadaddr can determine the load address of a stage, which may be needed for
  603. # platform-specific image headers (only works *after* the stage has been built)
  604. loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
  605. sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
  606. # find-substr is required for stages like romstage_null and romstage_xip to
  607. # eliminate the _* part of the string
  608. find-substr = $(word 1,$(subst _, ,$(1)))
  609. # find-class is used to identify the class from the name of the stage
  610. # The input to this macro can be something like romstage.x or romstage.x.y
  611. # find-class recursively strips off the suffixes to extract the exact class name
  612. # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
  613. # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
  614. # and remove .x the next time and finally return romstage
  615. find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
  616. # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
  617. # be cleared by the loader of the stage. For ARM SoCs that means one needs to
  618. # include the bss section in the binary so the BootROM clears the bss on
  619. # loading of the bootblock stage. Achieve this by marking the bss section
  620. # loadable,allocatable, and data. Do the same for the .data section in case
  621. # the linker marked it NOBITS automatically because there are only zeroes in it.
  622. preserve-bss-flags := --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data
  623. # For Intel TXT files in the CBFS needs to be marked as 'Initial Boot Block'.
  624. # As CBFS attributes aren't cheap, only mark them if TXT is enabled.
  625. ifeq ($(CONFIG_INTEL_TXT),y)
  626. TXTIBB := --ibb
  627. else
  628. TXTIBB :=
  629. endif
  630. ifeq ($(CONFIG_COMPRESS_BOOTBLOCK),y)
  631. $(objcbfs)/bootblock.lz4: $(objcbfs)/bootblock.elf $(objutil)/cbfstool/cbfs-compression-tool
  632. @printf " LZ4 $(subst $(obj)/,,$(@))\n"
  633. $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@.tmp
  634. $(OBJCOPY_bootblock) -O binary $@.tmp
  635. $(objutil)/cbfstool/cbfs-compression-tool rawcompress $@.tmp $@.tmp2 lz4
  636. rm -f $@.tmp
  637. mv $@.tmp2 $@
  638. # Put assembled decompressor+bootblock into bootblock.raw.elf so that SoC
  639. # Makefiles wrapping the bootblock in a header can always key off the same file.
  640. $(objcbfs)/bootblock.raw.elf: $(objcbfs)/decompressor.elf
  641. @printf " OBJCOPY $(notdir $(@))\n"
  642. $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@
  643. else # CONFIG_COMPRESS_BOOTBLOCK
  644. $(objcbfs)/bootblock.raw.elf: $(objcbfs)/bootblock.elf
  645. @printf " OBJCOPY $(notdir $(@))\n"
  646. $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@
  647. endif # CONFIG_COMPRESS_BOOTBLOCK
  648. $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.raw.elf
  649. @printf " OBJCOPY $(notdir $(@))\n"
  650. $(OBJCOPY_bootblock) -O binary $< $@
  651. ifneq ($(CONFIG_HAVE_BOOTBLOCK),y)
  652. $(objcbfs)/bootblock.bin:
  653. dd if=/dev/zero of=$@ bs=64 count=1
  654. endif
  655. $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
  656. cp $< $@
  657. $(objcbfs)/%.elf: $(objcbfs)/%.debug
  658. $(eval class := $(call find-class,$(@F)))
  659. @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
  660. cp $< $@.tmp
  661. $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
  662. $(OBJCOPY_$(class)) --strip-debug $@.tmp
  663. $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
  664. mv $@.tmp $@
  665. ###########################################################################
  666. # Build the final rom image
  667. ###########################################################################
  668. # extract_nth - Return a subsection of the $file string
  669. #
  670. # the input string looks like this:
  671. # ./build/cbfs/fallback/romstage.elf|fallback/romstage|stage|none||64|--xip*-S*.car.data*-P*0x10000
  672. #
  673. # Sections:
  674. # 1 - Path and name of file [FILENAME: Added to cbfs-files-y list variable]
  675. # 2 - Name of file in cbfs [$(FILENAME)-file]
  676. # 3 - File type: [$(FILENAME)-type]
  677. # bootblock, cbfs header, stage, payload, optionrom, bootsplash, raw, vsa,
  678. # mbi, microcode, fsp, mrc, cmos_default, cmos_layout, spd, mrc_cache,
  679. # mma, efi, deleted, null
  680. # 4 - Compression type [$(FILENAME)-compression]
  681. # none, LZMA
  682. # 5 - Base address [$(FILANAME)-position]
  683. # 6 - Alignment [$(FILENAME)-align]
  684. # 7 - cbfstool flags [$(FILENAME)-options]
  685. #
  686. # Input:
  687. # $(1) = Section to extract
  688. # $(2) = Input string
  689. #
  690. # Steps:
  691. # 1) replace all '|' characters with the sequence '- -' within the full string, prepended and appended with the character '-'
  692. # 2) extract the specified section from the string - this gets us the section surrounded by '-' characters
  693. # 3) remove the leading and trailing '-' characters
  694. # 4) replace all '*' characters with spaces
  695. extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
  696. # regions-for-file - Returns a cbfstool regions parameter
  697. # $(call regions-for-file,$(filename))
  698. # returns "REGION1,REGION2,..."
  699. #
  700. # This is the default implementation. When using a boot strategy employing
  701. # multiple CBFSes in fmap regions, override it.
  702. regions-for-file ?= COREBOOT
  703. ifeq ($(CONFIG_CBFS_AUTOGEN_ATTRIBUTES),y)
  704. cbfs-autogen-attributes=-g
  705. endif
  706. # cbfs-add-cmd-for-region
  707. # $(call cbfs-add-cmd-for-region,file in extract_nth format,region name)
  708. #
  709. # CBFSTOOL_ADD_CMD_OPTIONS can be used by arch/SoC/mainboard to supply
  710. # add commands with any additional arguments for cbfstool.
  711. # Example: --ext-win-base <base> --ext-win-size <size>
  712. define cbfs-add-cmd-for-region
  713. $(CBFSTOOL) $@.tmp \
  714. add$(if $(filter stage,$(call extract_nth,3,$(1))),-stage)$(if \
  715. $(filter payload,$(call extract_nth,3,$(1))),-payload)$(if \
  716. $(filter flat-binary,$(call extract_nth,3,$(1))),-flat-binary) \
  717. -f $(call extract_nth,1,$(1)) \
  718. -n $(call extract_nth,2,$(1)) \
  719. $(if $(filter-out flat-binary payload stage,$(call \
  720. extract_nth,3,$(1))),-t $(call extract_nth,3,$(1))) \
  721. $(if $(call extract_nth,4,$(1)),-c $(call extract_nth,4,$(1))) \
  722. $(cbfs-autogen-attributes) \
  723. -r $(2) \
  724. $(if $(call extract_nth,6,$(1)),-a $(call extract_nth,6,$(file)), \
  725. $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file)))) \
  726. $(call extract_nth,7,$(1)) \
  727. $(CBFSTOOL_ADD_CMD_OPTIONS)
  728. endef
  729. # Empty line before endef is necessary so cbfs-add-cmd-for-region ends in a
  730. # newline
  731. # cbfs-add-cmd
  732. # $(call cbfs-add-cmd,
  733. # file in extract_nth format,
  734. # region name,
  735. # non-empty if file removal requested)
  736. define cbfs-add-cmd
  737. printf " CBFS $(call extract_nth,2,$(1))\n"
  738. $(if $(3),-$(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null)
  739. $(call cbfs-add-cmd-for-region,$(1),$(2))
  740. endef
  741. # list of files to add (using their file system names, not CBFS names),
  742. # for dependencies etc.
  743. prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
  744. # $(all-regions)
  745. # returns full list of fmap regions that we add files to
  746. all-regions = $(sort $(subst $(comma),$(spc), \
  747. $(foreach file,$(cbfs-files), \
  748. $(call regions-for-file,$(call extract_nth,2,$(file))))))
  749. # $(call all-files-in-region,region name)
  750. # returns elements in $(cbfs-files) that end up in that region, in the order
  751. # they appear in $(cbfs-files)
  752. all-files-in-region = $(foreach file,$(cbfs-files), \
  753. $(if $(filter $(1), \
  754. $(subst $(comma),$(spc),$(call regions-for-file,$(call extract_nth,2,$(file))))), \
  755. $(file)))
  756. # $(call update-file-for-region,file string from $(cbfs-files),region name)
  757. # Update position and alignment according to overrides for region
  758. # Doesn't check for invalid configurations (eg. resetting neither or both
  759. # position and align)
  760. # Returns the updated file string
  761. update-file-for-region = \
  762. $(subst $(spc),*,$(call extract_nth,1,$(1))|$(call extract_nth,2,$(1))|$(call extract_nth,3,$(1))|$(call extract_nth,4,$(1))|$($(call extract_nth,2,$(1))-$(2)-position)|$($(call extract_nth,2,$(1))-$(2)-align)|$(call extract_nth,7,$(1)))
  763. # $(call placed-files-in-region,region name)
  764. # like all-files-in-region, but updates the files to contain region overrides
  765. # to position or alignment.
  766. placed-files-in-region = $(foreach file,$(call all-files-in-region,$(1)), \
  767. $(if $($(call extract_nth,2,$(file))-$(1)-position), \
  768. $(if $($(call extract_nth,2,$(file))-$(1)-align), \
  769. $(error It is not allowed to specify both alignment and position for $(call extract_nth,2,$(file))-$(1))) \
  770. $(call update-file-for-region,$(file),$(1)), \
  771. $(if $($(call extract_nth,2,$(file))-$(1)-align), \
  772. $(call update-file-for-region,$(file),$(1)), \
  773. $(file))))
  774. # $(call sort-files,subset of $(cbfs-files))
  775. # reorders the files in the given set to list files at fixed positions first,
  776. # followed by aligned files and finally those with no constraints.
  777. sort-files = \
  778. $(eval _tmp_fixed:=) \
  779. $(eval _tmp_aligned:=) \
  780. $(eval _tmp_regular:=) \
  781. $(foreach file,$(1), \
  782. $(if $(call extract_nth,5,$(file)),\
  783. $(eval _tmp_fixed += $(file)), \
  784. $(if $(call extract_nth,6,$(file)), \
  785. $(eval _tmp_aligned += $(file)), \
  786. $(eval _tmp_regular += $(file))))) \
  787. $(_tmp_fixed) $(_tmp_aligned) $(_tmp_regular)
  788. # command list to add files to CBFS
  789. prebuild-files = $(foreach region,$(all-regions), \
  790. $(foreach file, \
  791. $(call sort-files,$(call placed-files-in-region,$(region))), \
  792. $(call cbfs-add-cmd,$(file),$(region),$(CONFIG_UPDATE_IMAGE))))
  793. ifeq ($(CONFIG_FMDFILE),)
  794. # For a description of the flash layout described by these variables, check
  795. # the $(DEFAULT_FLASHMAP) .fmd files.
  796. ifeq ($(CONFIG_ARCH_X86),y)
  797. DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
  798. # entire flash
  799. FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
  800. FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
  801. # entire "BIOS" region (everything directly of concern to the host system)
  802. # relative to ROM_BASE
  803. FMAP_BIOS_BASE := $(call int-align, $(call int-subtract, $(CONFIG_ROM_SIZE) $(CONFIG_CBFS_SIZE)), 0x10000)
  804. FMAP_BIOS_SIZE := $(call int-align-down, $(shell echo $(CONFIG_CBFS_SIZE) | tr A-F a-f), 0x10000)
  805. # position and size of flashmap, relative to BIOS_BASE
  806. #
  807. # X86 CONSOLE FMAP region
  808. #
  809. # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
  810. FMAP_CURRENT_BASE := 0
  811. ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
  812. FMAP_CONSOLE_BASE := $(FMAP_CURRENT_BASE)
  813. FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
  814. FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
  815. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE))
  816. else
  817. FMAP_CONSOLE_ENTRY :=
  818. endif
  819. ifeq ($(CONFIG_CACHE_MRC_SETTINGS),y)
  820. FMAP_MRC_CACHE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
  821. FMAP_MRC_CACHE_SIZE := $(CONFIG_MRC_SETTINGS_CACHE_SIZE)
  822. FMAP_MRC_CACHE_ENTRY := RW_MRC_CACHE@$(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE)
  823. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE))
  824. else
  825. FMAP_MRC_CACHE_ENTRY :=
  826. endif
  827. ifeq ($(CONFIG_SMMSTORE),y)
  828. FMAP_SMMSTORE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
  829. FMAP_SMMSTORE_SIZE := $(CONFIG_SMMSTORE_SIZE)
  830. FMAP_SMMSTORE_ENTRY := SMMSTORE@$(FMAP_SMMSTORE_BASE) $(FMAP_SMMSTORE_SIZE)
  831. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_SMMSTORE_BASE) $(FMAP_SMMSTORE_SIZE))
  832. else
  833. FMAP_SMMSTORE_ENTRY :=
  834. endif
  835. ifeq ($(CONFIG_SPD_CACHE_IN_FMAP),y)
  836. FMAP_SPD_CACHE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x4000)
  837. FMAP_SPD_CACHE_SIZE := $(call int-multiply, $(CONFIG_DIMM_MAX) $(CONFIG_DIMM_SPD_SIZE))
  838. FMAP_SPD_CACHE_SIZE := $(call int-align, $(FMAP_SPD_CACHE_SIZE), 0x1000)
  839. FMAP_SPD_CACHE_ENTRY := $(CONFIG_SPD_CACHE_FMAP_NAME)@$(FMAP_SPD_CACHE_BASE) $(FMAP_SPD_CACHE_SIZE)
  840. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_SPD_CACHE_BASE) $(FMAP_SPD_CACHE_SIZE))
  841. else
  842. FMAP_SPD_CACHE_ENTRY :=
  843. endif
  844. ifeq ($(CONFIG_VPD),y)
  845. FMAP_VPD_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x4000)
  846. FMAP_VPD_SIZE := $(CONFIG_VPD_FMAP_SIZE)
  847. FMAP_VPD_ENTRY := $(CONFIG_VPD_FMAP_NAME)@$(FMAP_VPD_BASE) $(FMAP_VPD_SIZE)
  848. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_VPD_BASE) $(FMAP_VPD_SIZE))
  849. else
  850. FMAP_VPD_ENTRY :=
  851. endif
  852. #
  853. # X86 FMAP region
  854. #
  855. #
  856. # position, size
  857. FMAP_FMAP_BASE := $(FMAP_CURRENT_BASE)
  858. FMAP_FMAP_SIZE := 0x200
  859. #
  860. # X86 COREBOOT default cbfs FMAP region
  861. #
  862. # position and size of CBFS, relative to BIOS_BASE
  863. FMAP_CBFS_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
  864. FMAP_CBFS_SIZE := $(call int-subtract, $(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
  865. else # ifeq ($(CONFIG_ARCH_X86),y)
  866. DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default.fmd
  867. # entire flash
  868. FMAP_ROM_ADDR := 0
  869. FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
  870. # entire "BIOS" region (everything directly of concern to the host system)
  871. # relative to ROM_BASE
  872. FMAP_BIOS_BASE := 0
  873. FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
  874. # position and size of flashmap, relative to BIOS_BASE
  875. FMAP_FMAP_BASE := 0x20000
  876. FMAP_FMAP_SIZE := 0x200
  877. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
  878. #
  879. # NON-X86 CONSOLE FMAP region
  880. #
  881. # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
  882. ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
  883. FMAP_CONSOLE_BASE := $(FMAP_CURRENT_BASE)
  884. FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
  885. FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
  886. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE))
  887. else
  888. FMAP_CONSOLE_ENTRY :=
  889. endif
  890. #
  891. # NON-X86 RW_MRC_CACHE FMAP region
  892. #
  893. # position, size and entry line of MRC_CACHE relative to BIOS_BASE, if enabled
  894. ifeq ($(CONFIG_CACHE_MRC_SETTINGS),y)
  895. FMAP_MRC_CACHE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
  896. FMAP_MRC_CACHE_SIZE := $(CONFIG_MRC_SETTINGS_CACHE_SIZE)
  897. FMAP_MRC_CACHE_ENTRY := RW_MRC_CACHE@$(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE)
  898. FMAP_CURRENT_BASE := $(call int-add, $(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE))
  899. else
  900. FMAP_MRC_CACHE_ENTRY :=
  901. endif
  902. #
  903. # NON-X86 COREBOOT default cbfs FMAP region
  904. #
  905. # position and size of CBFS, relative to BIOS_BASE
  906. FMAP_CBFS_BASE := $(FMAP_CURRENT_BASE)
  907. FMAP_CBFS_SIZE := $(call int-subtract,$(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
  908. endif # ifeq ($(CONFIG_ARCH_X86),y)
  909. $(obj)/fmap.fmd: $(top)/Makefile.inc $(DEFAULT_FLASHMAP) $(obj)/config.h
  910. sed -e "s,##ROM_BASE##,$(FMAP_ROM_ADDR)," \
  911. -e "s,##ROM_SIZE##,$(FMAP_ROM_SIZE)," \
  912. -e "s,##BIOS_BASE##,$(FMAP_BIOS_BASE)," \
  913. -e "s,##BIOS_SIZE##,$(FMAP_BIOS_SIZE)," \
  914. -e "s,##FMAP_BASE##,$(FMAP_FMAP_BASE)," \
  915. -e "s,##FMAP_SIZE##,$(FMAP_FMAP_SIZE)," \
  916. -e "s,##CONSOLE_ENTRY##,$(FMAP_CONSOLE_ENTRY)," \
  917. -e "s,##MRC_CACHE_ENTRY##,$(FMAP_MRC_CACHE_ENTRY)," \
  918. -e "s,##SMMSTORE_ENTRY##,$(FMAP_SMMSTORE_ENTRY)," \
  919. -e "s,##SPD_CACHE_ENTRY##,$(FMAP_SPD_CACHE_ENTRY)," \
  920. -e "s,##VPD_ENTRY##,$(FMAP_VPD_ENTRY)," \
  921. -e "s,##CBFS_BASE##,$(FMAP_CBFS_BASE)," \
  922. -e "s,##CBFS_SIZE##,$(FMAP_CBFS_SIZE)," \
  923. $(DEFAULT_FLASHMAP) > $@.tmp
  924. mv $@.tmp $@
  925. else # ifeq ($(CONFIG_FMDFILE),)
  926. $(obj)/fmap.fmd: $(CONFIG_FMDFILE) $(obj)/config.h
  927. $(HOSTCC) $(PREPROCESS_ONLY) -include $(obj)/config.h $< -o $@.pre
  928. mv $@.pre $@
  929. endif # ifeq ($(CONFIG_FMDFILE),)
  930. # generated at the same time as fmap.fmap
  931. $(obj)/fmap_config.h: $(obj)/fmap.fmap
  932. true
  933. $(obj)/fmap.desc: $(obj)/fmap.fmap
  934. true
  935. $(obj)/fmap.fmap: $(obj)/fmap.fmd $(FMAPTOOL)
  936. echo " FMAP $(FMAPTOOL) -h $(obj)/fmap_config.h $< $@"
  937. $(FMAPTOOL) -h $(obj)/fmap_config.h -R $(obj)/fmap.desc $< $@
  938. ifeq ($(CONFIG_INTEL_ADD_TOP_SWAP_BOOTBLOCK),y)
  939. TS_OPTIONS := -j $(CONFIG_INTEL_TOP_SWAP_BOOTBLOCK_SIZE)
  940. endif
  941. ifneq ($(CONFIG_UPDATE_IMAGE),y)
  942. $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $(obj)/fmap.fmap $(obj)/fmap.desc
  943. $(CBFSTOOL) $@.tmp create -M $(obj)/fmap.fmap -r $(shell cat $(obj)/fmap.desc)
  944. ifeq ($(CONFIG_ARCH_X86),y)
  945. $(CBFSTOOL) $@.tmp add \
  946. -f $(objcbfs)/bootblock.bin \
  947. -n bootblock \
  948. -t bootblock \
  949. $(TXTIBB) \
  950. -b -$(call file-size,$(objcbfs)/bootblock.bin) $(cbfs-autogen-attributes) \
  951. $(TS_OPTIONS) \
  952. $(CBFSTOOL_ADD_CMD_OPTIONS)
  953. else # ifeq ($(CONFIG_ARCH_X86),y)
  954. $(CBFSTOOL) $@.tmp write -u \
  955. -r BOOTBLOCK \
  956. -f $(objcbfs)/bootblock.bin
  957. # make space for the CBFS master header pointer. "ptr_" is just
  958. # arbitrary 4 bytes that will be overwritten by add-master-header.
  959. printf "ptr_" > $@.tmp.2
  960. $(CBFSTOOL) $@.tmp add \
  961. -f $@.tmp.2 \
  962. -n "header pointer" \
  963. -t "cbfs header" \
  964. -b -4 \
  965. $(CBFSTOOL_ADD_CMD_OPTIONS)
  966. rm -f $@.tmp.2
  967. endif # ifeq ($(CONFIG_ARCH_X86),y)
  968. $(CBFSTOOL) $@.tmp add-master-header $(TS_OPTIONS) $(CBFSTOOL_ADD_CMD_OPTIONS)
  969. $(prebuild-files) true
  970. mv $@.tmp $@
  971. else # ifneq ($(CONFIG_UPDATE_IMAGE),y)
  972. .PHONY: $(obj)/coreboot.pre
  973. $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
  974. mv $(obj)/coreboot.rom $@.tmp || \
  975. (echo "Error: You have UPDATE_IMAGE set in Kconfig, but have no existing image to update." && \
  976. echo "Exiting." && \
  977. false)
  978. $(prebuild-files) true
  979. mv $@.tmp $@
  980. endif # ifneq ($(CONFIG_UPDATE_IMAGE),y)
  981. ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
  982. REFCODE_BLOB=$(obj)/refcode.rmod
  983. $(REFCODE_BLOB): $(RMODTOOL)
  984. $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
  985. endif
  986. ifeq ($(CONFIG_HAVE_RAMSTAGE),y)
  987. RAMSTAGE=$(objcbfs)/ramstage.elf
  988. else
  989. RAMSTAGE=
  990. endif
  991. add_intermediate = \
  992. $(1): $(obj)/coreboot.pre $(2) | $(INTERMEDIATE) \
  993. $(eval INTERMEDIATE+=$(1)) $(eval PHONY+=$(1))
  994. $(obj)/coreboot.rom: $(obj)/coreboot.pre $(CBFSTOOL) $(IFITTOOL) $$(INTERMEDIATE)
  995. @printf " CBFS $(subst $(obj)/,,$(@))\n"
  996. # The full ROM may be larger than the CBFS part, so create an empty
  997. # file (filled with \377 = 0xff) and copy the CBFS image over it.
  998. dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
  999. dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
  1000. ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
  1001. # Print final FIT table
  1002. $(IFITTOOL) -f $@.tmp -D -r COREBOOT
  1003. # Print final TS BOOTBLOCK FIT table
  1004. ifeq ($(CONFIG_INTEL_ADD_TOP_SWAP_BOOTBLOCK),y)
  1005. @printf " TOP SWAP FIT table\n"
  1006. $(IFITTOOL) -f $@.tmp -D $(TS_OPTIONS) -r COREBOOT
  1007. endif # CONFIG_INTEL_ADD_TOP_SWAP_BOOTBLOCK
  1008. endif # CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE
  1009. mv $@.tmp $@
  1010. @printf " CBFSLAYOUT $(subst $(obj)/,,$(@))\n\n"
  1011. $(CBFSTOOL) $@ layout
  1012. @printf " CBFSPRINT $(subst $(obj)/,,$(@))\n\n"
  1013. $(CBFSTOOL) $@ print -r $(subst $(spc),$(comma),$(all-regions))
  1014. cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
  1015. $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
  1016. $(CONFIG_CBFS_PREFIX)/romstage-type := stage
  1017. $(CONFIG_CBFS_PREFIX)/romstage-compression := $(CBFS_PRERAM_COMPRESS_FLAG)
  1018. ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
  1019. $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
  1020. endif
  1021. ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
  1022. # Use a 64 byte alignment to provide a minimum alignment
  1023. # requirement for the overall romstage. While the first object within
  1024. # romstage could have a 4 byte minimum alignment that doesn't mean the linker
  1025. # won't decide the entire section should be aligned to a larger value. In the
  1026. # future cbfstool should add XIP files proper and honor the alignment
  1027. # requirements of the program segment.
  1028. #
  1029. # Make sure that segment for .car.data is ignored while adding romstage.
  1030. $(CONFIG_CBFS_PREFIX)/romstage-align := 64
  1031. $(CONFIG_CBFS_PREFIX)/romstage-options := -S ".car.data"
  1032. # If CAR does not support execution of code, romstage on x86 is expected to be
  1033. # xip.
  1034. ifneq ($(CONFIG_NO_XIP_EARLY_STAGES),y)
  1035. $(CONFIG_CBFS_PREFIX)/romstage-options += --xip
  1036. # For efficient MTRR utilisation use natural alignment for romstage.
  1037. ifeq ($(CONFIG_SETUP_XIP_CACHE),y)
  1038. $(CONFIG_CBFS_PREFIX)/romstage-options += --pow2page
  1039. endif # CONFIG_SETUP_XIP_CACHE
  1040. endif # CONFIG_NO_XIP_EARLY_STAGES
  1041. endif # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
  1042. ifeq ($(CONFIG_VBOOT_STARTS_IN_ROMSTAGE),y)
  1043. $(CONFIG_CBFS_PREFIX)/romstage-options += $(TXTIBB)
  1044. endif
  1045. cbfs-files-$(CONFIG_HAVE_RAMSTAGE) += $(CONFIG_CBFS_PREFIX)/ramstage
  1046. $(CONFIG_CBFS_PREFIX)/ramstage-file := $(RAMSTAGE)
  1047. $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
  1048. $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
  1049. cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
  1050. $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
  1051. $(CONFIG_CBFS_PREFIX)/refcode-type := stage
  1052. $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
  1053. cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
  1054. vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
  1055. vgaroms/seavgabios.bin-type := raw
  1056. cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
  1057. config-file := $(DOTCONFIG):defconfig
  1058. config-type := raw
  1059. cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
  1060. revision-file := $(obj)/build.h
  1061. revision-type := raw
  1062. cbfs-files-y += build_info
  1063. build_info-file := $(obj)/build_info
  1064. build_info-type := raw
  1065. BOOTSPLASH_SUFFIX=$(suffix $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)))
  1066. cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash$(BOOTSPLASH_SUFFIX)
  1067. bootsplash$(BOOTSPLASH_SUFFIX)-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
  1068. bootsplash$(BOOTSPLASH_SUFFIX)-type := bootsplash
  1069. # Ensure that no payload segment overlaps with memory regions used by ramstage
  1070. # (not for x86 since it can relocate itself in that case)
  1071. ifneq ($(CONFIG_ARCH_X86),y)
  1072. check-ramstage-overlap-regions := ramstage
  1073. check-ramstage-overlap-files :=
  1074. ifneq ($(CONFIG_PAYLOAD_NONE),y)
  1075. check-ramstage-overlap-files += $(CONFIG_CBFS_PREFIX)/payload
  1076. endif
  1077. # will output one or more lines of "<load address in hex> <memlen in decimal>"
  1078. cbfs-get-segments-cmd = $(CBFSTOOL) $(obj)/coreboot.pre print -v | sed -n \
  1079. '\%$(1)%,\%^[^ ]\{4\}%s% .*load: \(0x[0-9a-fA-F]*\),.*length: [0-9]*/\([0-9]*\).*%\1 \2%p'
  1080. ramstage-symbol-addr-cmd = $(OBJDUMP_ramstage) -t $(objcbfs)/ramstage.elf | \
  1081. sed -n '/ $(1)$$/s/^\([0-9a-fA-F]*\) .*/0x\1/p' | \
  1082. uniq
  1083. $(call add_intermediate, check-ramstage-overlaps)
  1084. programs=$$($(foreach file,$(check-ramstage-overlap-files), \
  1085. $(call cbfs-get-segments-cmd,$(file)) ; )) ; \
  1086. regions=$$($(foreach region,$(check-ramstage-overlap-regions), \
  1087. echo $(region) ; \
  1088. $(call ramstage-symbol-addr-cmd,_$(region)) ; \
  1089. $(call ramstage-symbol-addr-cmd,_e$(region)) ; )) ; \
  1090. pstart= ; pend= ; \
  1091. for x in $$programs; do \
  1092. if [ -z $$pstart ]; then pstart=$$(($$x)) ; continue ; fi ; \
  1093. pend=$$(($$pstart + $$x)) ; \
  1094. rname= ; rstart= ; rend= ; \
  1095. for y in $$regions ; do \
  1096. if [ -z $$rname ]; then rname=$$y ; continue ; fi ; \
  1097. if [ -z $$rstart ]; then rstart=$$(($$y)) ; continue ; fi ; \
  1098. rend=$$(($$y)) ; \
  1099. if [ $$pstart -lt $$rend -a $$rstart -lt $$pend ]; then \
  1100. echo "ERROR: Ramstage region _$$rname overlapped by:" \
  1101. $(check-ramstage-overlap-files) ; \
  1102. exit 1 ; \
  1103. fi ; \
  1104. rname= ; rstart= ; rend= ; \
  1105. done ; \
  1106. pstart= ; pend= ; \
  1107. done
  1108. endif