Makefile.mk 54 KB

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