# $Id: Makefile.kmk 48674 2013-09-25 08:26:15Z vboxsync $ ## @file # Toplevel sub-makefile for the EFI firmwares. # # Note! kBuild is only used for the build tools, the rest is handled by the # very custom EFI build system. # # # Copyright (C) 2013 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; # you can redistribute it and/or modify it under the terms of the GNU # General Public License (GPL) as published by the Free Software # Foundation, in version 2 as it comes in the "COPYING" file of the # VirtualBox OSE distribution. VirtualBox OSE is distributed in the # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. # # The contents of this file may alternatively be used under the terms # of the Common Development and Distribution License Version 1.0 # (CDDL) only, as it comes in the "COPYING.CDDL" file of the # VirtualBox OSE distribution, in which case the provisions of the # CDDL are applicable instead of those of the GPL. # # You may elect to license modified versions of this file under the # terms and conditions of either the GPL or the CDDL or both. # SUB_DEPTH = ../../../../.. include $(KBUILD_PATH)/subheader.kmk # # Make sure our Config.kmk is included. # ifndef VBOX_EFI_FIRMWARE_CONFIG_KMK_INCLUDED include $(PATH_SUB_CURRENT)/Config.kmk endif # # Include sub-makefiles. # VBOX_EFI_BLDPROGS := $(BLDPROGS) include $(PATH_SUB_CURRENT)/BaseTools/Makefile.kmk VBOX_EFI_BLDPROGS := $(filter-out $(VBOX_EFI_BLDPROGS),$(BLDPROGS)) VBoxEfiBldPythonWrappers # # Binary wrappers for python scripts. # VBOX_EFI_PYTHON_WRAPPERS = \ BPDG \ build \ Ecc \ GenFds \ GenPatchPcdTable \ PatchPcdValue \ Trim \ TargetTool \ UPT INSTALLS += VBoxEfiBldPythonWrappers VBoxEfiBldPythonWrappers_TEMPLATE = VBoxEfiBldProg if1of ($(KBUILD_HOST), win os2) VBoxEfiBldPythonWrappers_EXEC_SOURCES = \ $(foreach PyWrap,$(VBOX_EFI_PYTHON_WRAPPERS),$(VBoxEfiBldPythonWrappers_0_OUTDIR)/$(PyWrap).cmd) else VBoxEfiBldPythonWrappers_EXEC_SOURCES = \ $(addprefix $(VBoxEfiBldPythonWrappers_0_OUTDIR)/,$(VBOX_EFI_PYTHON_WRAPPERS)) endif VBoxEfiBldPythonWrappers_CLEAN = $(VBoxEfiBldPythonWrappers_SOURCES) if1of ($(KBUILD_HOST), win os2) define VBoxEfiBldPythonWrappersRuleTemplate $$$$(VBoxEfiBldPythonWrappers_0_OUTDIR)/$(PyWrap).cmd: | $$$$(dir $$$$@) $$(APPEND) -tn "$$@" \ '@SET PYTHONPATH=$$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python' \ '@"$$(VBOX_BLD_PYTHON)" "$$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python/$(PyWrap)/$(PyWrap).py" %*' endef else define VBoxEfiBldPythonWrappersRuleTemplate $$$$(VBoxEfiBldPythonWrappers_0_OUTDIR)/$(PyWrap): | $$$$(dir $$$$@) $$(APPEND) -tn "$$@" \ '#!$(ASH)' \ 'export PYTHONPATH="$$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python"' \ 'exec "$$(VBOX_BLD_PYTHON)" "$$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python/$(PyWrap)/$(PyWrap).py" "$$(DOLLAR)@"' $$(CHMOD) a+x "$$@" endef endif $(foreach PyWrap,$(VBOX_EFI_PYTHON_WRAPPERS),$(eval $(VBoxEfiBldPythonWrappersRuleTemplate))) # # Rules for building and installing the VBox EFI firmware images. # INSTALLS += VBoxEfiFirmware VBoxEfiFirmware_INST = $(INST_BIN) VBoxEfiFirmware_MODE = 0644 VBoxEfiFirmware_SOURCES = \ $(VBoxEfiFirmware_0_OUTDIR)/x86/$(VBOX_EFI_OUTPUT_SUBDIR)/FV/OVMF.fd=>VBoxEFI32.fd \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/$(VBOX_EFI_OUTPUT_SUBDIR)/FV/OVMF.fd=>VBoxEFI64.fd VBoxEfiFirmware_BLDDIRS = \ $(VBoxEfiFirmware_0_OUTDIR)/x86/ \ $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/ \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/ \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/ VBoxEfiFirmware_CLEAN = \ $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/target.txt \ $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/tools_def.txt \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/target.txt \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/tools_def.txt # Install the debug info. INSTALLS += VBoxEfiFirmwareDbg32 VBoxEfiFirmwareDbg32_INST = $(INST_VBOXDBG_SYMS)x86/ VBoxEfiFirmwareDbg32_MODE = 0644 if1of ($(KBUILD_HOST), win) VBoxEfiFirmwareDbg32_SOURCES = \ $(foreach mod,$(VBOX_EFI_MODULES),$(VBoxEfiFirmware_0_OUTDIR)/x86/$(VBOX_EFI_OUTPUT_SUBDIR)/IA32/$(mod).pdb) else VBoxEfiFirmwareDbg32_SOURCES = \ $(foreach mod,$(VBOX_EFI_MODULES_FLAT),$(VBoxEfiFirmware_0_OUTDIR)/x86/$(VBOX_EFI_OUTPUT_SUBDIR)/IA32/$(mod).debug) endif INSTALLS += VBoxEfiFirmwareDbg64 VBoxEfiFirmwareDbg64_INST = $(INST_VBOXDBG_SYMS)amd64/ VBoxEfiFirmwareDbg64_MODE = 0644 if1of ($(KBUILD_HOST), win) VBoxEfiFirmwareDbg64_SOURCES = \ $(foreach mod,$(VBOX_EFI_MODULES),$(VBoxEfiFirmware_0_OUTDIR)/amd64/$(VBOX_EFI_OUTPUT_SUBDIR)/X64/$(mod).pdb) else VBoxEfiFirmwareDbg64_SOURCES = \ $(foreach mod,$(VBOX_EFI_MODULES_FLAT),$(VBoxEfiFirmware_0_OUTDIR)/amd64/$(VBOX_EFI_OUTPUT_SUBDIR)/X64/$(mod).debug) endif # # Install a custom clean up rule for dealing with the EFI build system output. # PASS_CLEAN_trgs += VBoxEfiFirmwareCleanup VBoxEfiFirmwareCleanup: $(if $(VBoxEfiFirmware_0_OUTDIR),,exit 1) $(RM) -Rf -- "$(VBoxEfiFirmware_0_OUTDIR)/amd64/" "$(VBoxEfiFirmware_0_OUTDIR)/x86/" .PHONY: VBoxEfiFirmwareCleanup # # The reset vector code. # # Dummy Linker. TOOL_VBoxEfiResetVectorLd = Dummy linker for the EFI reset vectors. TOOL_VBoxEfiResetVectorLd_LINK_MISCBIN_OUTPUT = TOOL_VBoxEfiResetVectorLd_LINK_MISCBIN_DEPEND = TOOL_VBoxEfiResetVectorLd_LINK_MISCBIN_DEPORD = define TOOL_VBoxEfiResetVectorLd_LINK_MISCBIN_CMDS $(VBOX_BLD_PYTHON) $(VBOX_PATH_EFI_FIRMWARE)/UefiCpuPkg/ResetVector/Vtf0/Tools/FixupForRawSection.py \ "--only-padd-image" \ "$(objs)" \ "$(out)" endef # Makes a boot sector test image. TEMPLATE_VBoxEfiResetVectorRaw = kBuild tool config for building the EFI reset vectors. TEMPLATE_VBoxEfiResetVectorRaw_INSTTYPE = none TEMPLATE_VBoxEfiResetVectorRaw_BINSUFF = .raw TEMPLATE_VBoxEfiResetVectorRaw_MODE = 0644 TEMPLATE_VBoxEfiResetVectorRaw_ASTOOL = YASM TEMPLATE_VBoxEfiResetVectorRaw_ASFLAGS:= -f bin $(VBOX_YASM_Wno-segreg-in-64bit) --mapfile TEMPLATE_VBoxEfiResetVectorRaw_ASDEFS = ASM_FORMAT_BIN __YASM__ TEMPLATE_VBoxEfiResetVectorRaw_LDTOOL = VBoxEfiResetVectorLd MISCBINS += VBoxEfiResetVector-x86 VBoxEfiResetVector-x86_TEMPLATE = VBoxEfiResetVectorRaw VBoxEfiResetVector-x86_DEFS = ARCH_IA32 RT_ARCH_X86 DEBUG_NONE VBoxEfiResetVector-x86_SOURCES = UefiCpuPkg/ResetVector/Vtf0/ResetVectorCode.asm MISCBINS += VBoxEfiResetVector-amd64 VBoxEfiResetVector-amd64_TEMPLATE = VBoxEfiResetVectorRaw VBoxEfiResetVector-amd64_DEFS = ARCH_X64 RT_ARCH_AMD64 DEBUG_NONE VBoxEfiResetVector-amd64_SOURCES = UefiCpuPkg/ResetVector/Vtf0/ResetVectorCode.asm # # Include the footer early so that we can use VBoxEfiFirmware_0_OUTDIR below. # include $(FILE_KBUILD_SUB_FOOTER) # # The common build.py invocation part. # if1of ($(KBUILD_HOST), win) VBOX_EFI_REDIRECT_E_EQUAL:=$(EQUAL) VBOX_EFI_BUILD_CMD = $(REDIRECT) \ -E 'PATH=$(VBOX_PATH_STAGE_EFI_BLDPROGS)$(VBOX_SEP)$(PATH)' \ -E 'INCLUDE=$(PATH_ROOT)/include$(VBOX_SEP)$(PATH_OUT)$(VBOX_SEP)$(VBOX_SEP)$(PATH_TOOL_$(VBOX_VCC_TOOL)_INC)$(INCLUDE)' \ -E 'COMSPEC=$(windir)\system32\cmd.exe' else VBOX_EFI_REDIRECT_E_EQUAL:= VBOX_EFI_BUILD_CMD = $(REDIRECT) \ -E "PATH=$(VBOX_PATH_STAGE_EFI_BLDPROGS)$(VBOX_SEP)$(PATH)" \ -E "C_INCLUDE_PATH=$(PATH_ROOT)/include$(VBOX_SEP)$(PATH_OUT)$(VBOX_SEP)$(C_INCLUDE_PATH)" \ -E "CPLUS_INCLUDE_PATH=$(PATH_ROOT)/include$(VBOX_SEP)$(PATH_OUT)$(VBOX_SEP)$(C_INCLUDE_PATH)" endif VBOX_EFI_BUILD_CMD += \ -E 'PYTHONPATH=$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python' \ -E 'PYTHONDONTWRITEBYTECODE=1' \ -E 'IASL_BIN=$(VBOX_IASLCMD)' \ -E 'WORKSPACE=$(VBOX_PATH_EFI_FIRMWARE)' \ -E 'EDK_TOOLS_PATH=$(VBOX_PATH_EFI_FIRMWARE)/BaseTools' \ -E 'EFI_SOURCE$(VBOX_EFI_REDIRECT_E_EQUAL)' \ -E 'ECP_SOURCE$(VBOX_EFI_REDIRECT_E_EQUAL)' \ -E 'EDK_SOURCE$(VBOX_EFI_REDIRECT_E_EQUAL)' \ -E 'X64_PETOOLS_PREFIX$(VBOX_EFI_REDIRECT_E_EQUAL)' \ -E 'ARCH$(VBOX_EFI_REDIRECT_E_EQUAL)' \ -E 'IPF_PETOOLS_PREFIX=__no_ipf__' \ -E $(if-expr "$(EFI_QUIET)" != "" || "$(KBUILD_VERBOSE)" != "",'EFI_QUIET=','EFI_QUIET=@') \ -C '$(VBOX_PATH_EFI_FIRMWARE)' \ -- $(VBOX_BLD_PYTHON) "$(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Source/Python/build/build.py" \ -D VBOX_WITH_EDK2_REV=13361 \ -D VBOX=1 \ -D VBOX_WITH_OVMF=1 \ -D BUILD_NEW_SHELL=1 \ -D VBOX_REV=$(VBOX_SVN_REV) \ -D "VBOX_OUTPUT_BASE_DIR=$(VBoxEfiFirmware_0_OUTDIR)" \ -D "VBOX_PATH_ROOT=$(PATH_ROOT)" \ -D "VBOX_RESET_VECTOR_X86=$(VBoxEfiResetVector-x86_1_TARGET)" \ -D "VBOX_RESET_VECTOR_AMD64=$(VBoxEfiResetVector-amd64_1_TARGET)" \ $(if $(VBOX_OSE),-D "VBOX_OSE=1") \ --no-cache \ --buildtarget $(VBOX_EFI_BUILD_TARGET) \ --tagname $(VBOX_EFI_TOOL_CHAIN) # # VBoxEFI32 # $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/target.txt: $(MAKEFILE) | $$(dir $$@) $(VBOX_EFI_BLDPROGS) $(APPEND) -tn "$@" \ "# Automatically generated, do not edit" \ "" \ "# These variables cannot be overriden by the build.py command line." \ "TOOL_CHAIN_CONF = $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/tools_def.txt" \ "BUILD_RULE_CONF = BaseTools/Conf/build_rule.template" \ "" \ "# These variables are overridden and this is just for show." \ "ACTIVE_PLATFORM = OvmfPkg/OvmfPkgIa32.dsc" \ "TARGET = $(VBOX_EFI_BUILD_TARGET)" \ "TARGET_ARCH = IA32" \ "TOOL_CHAIN_TAG = $(VBOX_EFI_TOOL_CHAIN)" \ "MAX_CONCURRENT_THREAD_NUMBER = 1" $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/tools_def.txt: \ $(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Conf/tools_def.template \ $(MAKEFILE) | $$(dir $$@) $(RM) -f -- "$@" ifeq ($(VBOX_EFI_TOOL_CHAIN),UNIXGCC) $(SED) \ -e 's,^DEFINE UNIXGCC_IA32_PETOOLS_PREFIX.*$(DOLLAR),DEFINE UNIXGCC_IA32_PETOOLS_PREFIX = $(VBOX_PATH_PREFIX_MINGW32),' \ -e 's,^DEFINE UNIXGCC_X64_PETOOLS_PREFIX.*$(DOLLAR),DEFINE UNIXGCC_X64_PETOOLS_PREFIX = $(VBOX_PATH_PREFIX_MINGW64),' \ -e 's,^DEFINE UNIX_IASL_BIN.*$(DOLLAR),DEFINE UNIX_IASL_BIN = $(VBOX_IASLCMD),' \ -e 's,^\(DEFINE GCC_ALL_CC_FLAGS.*$(DOLLAR)\),\1 -Wno-address $(VBOX_MINGW32_Wno-unused-but-set-variable) $(VBOX_MINGW32_Wno-maybe-uninitialized),' \ $(if $(VBOX_MINGW32_Wno-array-bounds),,-e 's,-Wno-array-bounds,,g') \ -e 's,=[[:space:]]*make$(DOLLAR),= $(MAKE),' \ $(if-expr "$(VBOX_EFI_BUILD_TARGET)" == "DEBUG", -e 's/ -O2 / /g',) \ --output $@ $< else if ($(VBOX_EFI_TOOL_CHAIN),VS2010) $(SED) \ -e 's,^DEFINE VS2010_BIN[[:space:]]*=.*$(DOLLAR),DEFINE VS2010_BIN = $(PATH_TOOL_$(VBOX_VCC_TOOL))/bin,' \ -e 's,^DEFINE VS2010_DLL[[:space:]]*=.*$(DOLLAR),DEFINE VS2010_DLL = DEF(VS2010_BIN),' \ --output $@ $< else $(error Unexpected VBOX_EFI_TOOL_CHAIN value "$(VBOX_EFI_TOOL_CHAIN)") endif ## @todo 32-bit DEBUG is busted, image to big. $(VBoxEfiFirmware_0_OUTDIR)/x86/$(VBOX_EFI_OUTPUT_SUBDIR)/FV/OVMF.fd \ + $(VBoxEfiFirmwareDbg32_SOURCES): \ $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/target.txt \ $(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/tools_def.txt \ $$(VBoxEfiResetVector-x86_1_TARGET) + $(VBOX_EFI_BUILD_CMD) \ --vbox-target-conf "$(VBoxEfiFirmware_0_OUTDIR)/x86/Conf/target.txt" \ --arch IA32 \ --platform OvmfPkg/OvmfPkgIa32.dsc \ -n 1 # -v # # VBoxEFI64 # $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/target.txt: $(MAKEFILE) | $$(dir $$@) $(VBOX_EFI_BLDPROGS) $(APPEND) -tn "$@" \ "# Automatically generated, do not edit" \ "" \ "# These variables cannot be overriden by the build.py command line." \ "TOOL_CHAIN_CONF = $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/tools_def.txt" \ "BUILD_RULE_CONF = BaseTools/Conf/build_rule.template" \ "" \ "# These variables are overridden and this is just for show." \ "ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc" \ "TARGET = $(VBOX_EFI_BUILD_TARGET)" \ "TARGET_ARCH = X64" \ "TOOL_CHAIN_TAG = $(VBOX_EFI_TOOL_CHAIN)" \ "MAX_CONCURRENT_THREAD_NUMBER = 1" # Hack! Drop an underscore from the entrypoint, or SecMain won't work. $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/tools_def.txt: \ $(VBOX_PATH_EFI_FIRMWARE)/BaseTools/Conf/tools_def.template \ $(MAKEFILE) | $$(dir $$@) $(RM) -f -- "$@" ifeq ($(VBOX_EFI_TOOL_CHAIN),UNIXGCC) $(SED) \ -e 's,^DEFINE UNIXGCC_IA32_PETOOLS_PREFIX.*$(DOLLAR),DEFINE UNIXGCC_IA32_PETOOLS_PREFIX = $(VBOX_PATH_PREFIX_MINGW32),' \ -e 's,^DEFINE UNIXGCC_X64_PETOOLS_PREFIX.*$(DOLLAR),DEFINE UNIXGCC_X64_PETOOLS_PREFIX = $(VBOX_PATH_PREFIX_MINGW64),' \ -e 's,^DEFINE UNIX_IASL_BIN.*$(DOLLAR),DEFINE UNIX_IASL_BIN = $(VBOX_IASLCMD),' \ -e 's,^\(DEFINE GCC_ALL_CC_FLAGS.*$(DOLLAR)\),\1 -Wno-address $(VBOX_MINGW64_Wno-unused-but-set-variable) $(VBOX_MINGW64_Wno-maybe-uninitialized),' \ $(if $(VBOX_MINGW64_Wno-array-bounds),,-e 's,-Wno-array-bounds,,g') \ -e 's,=[[:space:]]*make$(DOLLAR),= $(MAKE),' \ -e 's,^\(DEFINE GCC_IA32_X64_DLINK_COMMON.*\)$(DOLLAR),\1 --fatal-warnings,' \ $(if $(VBOX_MINGW64_USER_LABEL_PREFIX),,-e 's,^\(DEFINE GCC_IA32_X64_DLINK_FLAGS.* --entry \)_,\1,') \ --output $@ $< else if ($(VBOX_EFI_TOOL_CHAIN),VS2010) $(SED) \ -e 's,^DEFINE VS2010_BIN[[:space:]]*=.*$(DOLLAR),DEFINE VS2010_BIN = $(PATH_TOOL_$(VBOX_VCC_TOOL))/bin,' \ -e 's,^DEFINE VS2010_DLL[[:space:]]*=.*$(DOLLAR),DEFINE VS2010_DLL = DEF(VS2010_BIN),' \ -e 's,^\([^=]*_VS2010[a-zA-Z_0-9]*_CC_FLAGS[[:space:]]*=.*\) /X \(.*\)$(DOLLAR),\1 \2,' \ --output $@ $< else $(error Unexpected VBOX_EFI_TOOL_CHAIN value "$(VBOX_EFI_TOOL_CHAIN)") endif $(VBoxEfiFirmware_0_OUTDIR)/amd64/$(VBOX_EFI_OUTPUT_SUBDIR)/FV/OVMF.fd \ + $(VBoxEfiFirmwareDbg64_SOURCES): \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/target.txt \ $(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/tools_def.txt \ $$(VBoxEfiResetVector-amd64_1_TARGET) + $(VBOX_EFI_BUILD_CMD) \ --vbox-target-conf "$(VBoxEfiFirmware_0_OUTDIR)/amd64/Conf/target.txt" \ --arch X64 \ --platform OvmfPkg/OvmfPkgX64.dsc \ -n 1 # -v # # Some aliases. # build-efi-x86: $$(filter %VBoxEFI32.fd,$$(VBoxEfiFirmware_2_STAGE_TARGETS)) build-efi-amd64: $$(filter %VBoxEFI64.fd,$$(VBoxEfiFirmware_2_STAGE_TARGETS))