Arthur Heymans | 791ce58 | 2023-07-13 16:58:55 +0200 | [diff] [blame] | 1 | ## SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
| 3 | ifeq ($(CONFIG_SOC_AMD_OPENSIL),y) |
| 4 | |
| 5 | ifneq ($(CONFIG_ARCH_RAMSTAGE_X86_32)$(CONFIG_ARCH_RAMSTAGE_X86_64),y) |
| 6 | $(error OpenSIL can only be built for either x86 or x86_64) |
| 7 | endif |
| 8 | |
| 9 | opensil_dir := $(call strip_quotes,$(CONFIG_AMD_OPENSIL_PATH)) |
| 10 | |
Felix Held | 9314bb6 | 2023-12-15 11:15:26 +0100 | [diff] [blame] | 11 | subdirs-$(CONFIG_SOC_AMD_OPENSIL_GENOA_POC) += genoa_poc |
Arthur Heymans | 0832e67 | 2023-07-13 17:16:37 +0200 | [diff] [blame] | 12 | |
Arthur Heymans | 791ce58 | 2023-07-13 16:58:55 +0200 | [diff] [blame] | 13 | ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32),y) |
| 14 | cpu_family_string="x86" |
| 15 | cpu_string="i686" |
| 16 | opensil_target_name=AMDopensil32 |
| 17 | is_32bit="true" |
| 18 | ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) |
| 19 | clang_args=\'-m32\'\, \'-fno-pic\'\, |
| 20 | endif |
| 21 | endif |
| 22 | |
| 23 | ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_64),y) |
| 24 | cpu_family_string="x86_64" |
| 25 | cpu_string="x86_64" |
| 26 | opensil_target_name=AMDopensil64 |
| 27 | is_32bit="false" |
| 28 | ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y) |
| 29 | clang_args=\'-fno-pic\'\, |
| 30 | endif |
| 31 | endif |
| 32 | |
| 33 | ifeq ($(CONFIG_OPENSIL_DEBUG_OUTPUT),y) |
| 34 | sil_debug_enable="true" |
| 35 | else |
| 36 | sil_debug_enable="false" |
| 37 | endif |
| 38 | |
| 39 | # check if $(obj) is an absolute or a relative path |
| 40 | ifeq ($(shell printf %.1s "$(obj)"),/) |
| 41 | OBJPATH = $(obj) |
| 42 | else |
| 43 | OBJPATH = $(top)/$(obj) |
| 44 | endif |
| 45 | |
| 46 | PYTHON?=python |
| 47 | |
| 48 | OPENSIL_CONFIG=opensil_config |
| 49 | |
| 50 | bios_base=$(shell printf "%x" $(call int-subtract, $(CONFIG_ROMSTAGE_ADDR) $(CONFIG_C_ENV_BOOTBLOCK_SIZE))) |
| 51 | bios_size=$(CONFIG_C_ENV_BOOTBLOCK_SIZE) |
| 52 | |
| 53 | $(OBJPATH)/$(OPENSIL_CONFIG): $(opensil_dir)/../opensil_config.template |
| 54 | sed -e "s,##APOB_BASE##,$(CONFIG_PSP_APOB_DRAM_ADDRESS)," \ |
| 55 | -e "s,##BIOS_ENTRY_BASE##,$(bios_base)," \ |
| 56 | -e "s,##BIOS_ENTRY_SIZE##,$(bios_size) ," \ |
| 57 | $< > $@ |
| 58 | |
| 59 | $(OBJPATH)/$(OPENSIL_CONFIG).h: $(OBJPATH)/$(OPENSIL_CONFIG) $(obj)/config.h $(objutil)/kconfig/conf |
| 60 | cd $(opensil_dir); KCONFIG_CONFIG=$(OBJPATH)/$(OPENSIL_CONFIG) KCONFIG_AUTOHEADER=$@ $(PYTHON) util/kconfig/lib/genconfig.py Kconfig |
| 61 | |
| 62 | # meson handles ccache on its own |
| 63 | OPENSIL_COMPILER=$(filter-out $(CCACHE), $(CC_ramstage)) |
| 64 | |
| 65 | $(OBJPATH)/meson_crosscompile: $(opensil_dir)/../meson_cross.template $(obj)/config.h $(OBJPATH)/$(OPENSIL_CONFIG).h |
| 66 | sed -e "s,##COMPILER##,$(OPENSIL_COMPILER)," \ |
| 67 | -e "s,##AR##,$(AR_ramstage)," \ |
| 68 | -e "s,##NASM##,$(NASM)," \ |
| 69 | -e "s,##COREBOOT_DIR##,$(top)," \ |
| 70 | -e "s,##OPENSIL_DIR##,$(opensil_dir)," \ |
| 71 | -e "s,##OBJPATH##,$(OBJPATH)," \ |
| 72 | -e "s,##CPU_FAMILY##,$(cpu_family_string)," \ |
| 73 | -e "s,##CPU##,$(cpu_string)," \ |
| 74 | -e "s,##IS32BIT##,$(is_32bit)," \ |
| 75 | -e "s,##SIL_DEBUG_ENABLE##,$(sil_debug_enable)," \ |
| 76 | -e "s,##CLANG_ARGS##,$(clang_args)," \ |
| 77 | $< > $@ |
| 78 | |
| 79 | # Don't set a meson buildtype as opensil is broken when compiler optimizations are enabled |
| 80 | $(OBJPATH)/opensil: $(OBJPATH)/meson_crosscompile $(obj)/config.h |
| 81 | cd $(opensil_dir); meson setup --cross-file $< $(OBJPATH)/opensil -Db_staticpic=false \ |
| 82 | -DPlatKcfgDir=$(OBJPATH) -DPlatKcfg=$(OPENSIL_CONFIG) |
| 83 | |
| 84 | $(OBJPATH)/opensil/lib$(opensil_target_name).a: $(OBJPATH)/opensil |
| 85 | meson compile -C $(OBJPATH)/opensil $(opensil_target_name) |
| 86 | |
| 87 | $(OBJPATH)/opensil.a: $(OBJPATH)/opensil/lib$(opensil_target_name).a |
| 88 | cp $(OBJPATH)/opensil/lib$(opensil_target_name).a $@ |
| 89 | |
| 90 | romstage-libs += $(OBJPATH)/opensil.a |
| 91 | ramstage-libs += $(OBJPATH)/opensil.a |
| 92 | |
| 93 | endif |