From nobody Sun May 5 12:32:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+39964+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39964+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1556925561; cv=none; d=zoho.com; s=zohoarc; b=CNLG9EW+/fl5VyhCCMuRoyAEa0WVbT8uCB/vHY+sEgwegnceGO6Wge5pPzb1gPDBtKj9UwShp4kPJhwOumm5eW8rbaM9I5naLTeBe5YRIuSmEFeZnQ04N7yk8c81OUoVuT/j9RkfDJSz55L35z0srE9l7PkR4V9vdedg2/Oe+FM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556925561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=W7oKA2tvkQpHOJhQeZlyc+k7gBCpzaeRyAyOjC/nrwc=; b=iNWFsutFKrwp+eF/L3q9LR5bQtSwc6It/gMJtIq2PL2mk/lbogfSE84aV11H/OOm5qhGRzVrGjd1vp8UfJetht4mPfS+6OEiYdaYmeDbtX29M0OveMUKZ5197g7LrtPNQ2FAbv6nydcW7J6jDOUokURbabi3GgWNrC2p5kX0N10= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39964+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1556925561584413.91470091998394; Fri, 3 May 2019 16:19:21 -0700 (PDT) Return-Path: X-Received: from mga06.intel.com (mga06.intel.com []) by groups.io with SMTP; Fri, 03 May 2019 16:19:20 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2019 16:19:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,427,1549958400"; d="scan'208";a="148017019" X-Received: from paagyema-desk2.amr.corp.intel.com ([10.7.159.148]) by orsmga003.jf.intel.com with ESMTP; 03 May 2019 16:19:19 -0700 From: "Agyeman, Prince" To: devel@edk2.groups.io Cc: Michael Kubacki , Nate DeSimone , Ankit Sinha , Michael D Kinney , Isaac W Oram , Liming Gao , Bowen Zhou , Shifei A Lu Subject: [edk2-devel] [edk2-platforms/devel-MinPlatform] [PATCH v3 1/2] Platform/Intel: Added python build script. Date: Fri, 3 May 2019 16:19:18 -0700 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,prince.agyeman@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1556925561; bh=Gs6EShieCgYf0OXHKAeEjg4HBqB2Z2ZULh/QduGDo7c=; h=Cc:Date:From:Reply-To:Subject:To; b=ojB8s5L120jbI9JQyclHFVXJhen8b+PmUtCAF1A4s/Dz5T0fKuEZNkIHlvizpZ0hxDT WhkQKTD1EOJzlxhoWu6GMGi8/DBrutC2TVqKAlc4W0n+lafvbVfzdVhCKCBotXUmmJt2u 1PDH+pq2X2Ns50Gf2sSzumS0PJ7DZEMizvQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This change allows building all the platforms in Platform/Intel with a single python script. This script works with python 2.7 and python 3.7 Files Added: * build_bios.py: the main build script build.cfg: contains general/default build settings * ClevoOpenBoardPkg/N1xxWU/build_config.cfg: contains N1xxWU specific build settings * KabylakeOpenBoardPkg/KabylakeRvp3/build_board.py : contains sample custom build script * KabylakeOpenBoardPkg/KabylakeRvp3/build_config.cfg: contains KabylakeRvp3 build settings * PurleyOpenBoardPkg/BoardMtOlympus/build_board.py: contains BoardMtOlympus custom build script * PurleyOpenBoardPkg/BoardMtOlympus/build_config.cfg: contains BoardMtOlympus custom build settings Cc: Michael Kubacki Cc: Nate DeSimone Cc: Ankit Sinha Cc: Michael D Kinney Cc: Isaac W Oram Cc: Liming Gao Cc: Bowen Zhou Cc: Shifei A Lu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Agyeman Reviewed-by: Michael Kubacki Reviewed-by: Nate DeSimone --- .../ClevoOpenBoardPkg/N1xxWU/build_config.cfg | 33 + .../KabylakeRvp3/build_board.py | 68 ++ .../KabylakeRvp3/build_config.cfg | 34 + .../BoardMtOlympus/build_board.py | 177 ++++ .../BoardMtOlympus/build_config.cfg | 32 + Platform/Intel/build.cfg | 56 + Platform/Intel/build_bios.py | 976 ++++++++++++++++++ 7 files changed, 1376 insertions(+) create mode 100644 Platform/Intel/ClevoOpenBoardPkg/N1xxWU/build_config.cfg create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_= board.py create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_= config.cfg create mode 100644 Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_= board.py create mode 100644 Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_= config.cfg create mode 100644 Platform/Intel/build.cfg create mode 100644 Platform/Intel/build_bios.py diff --git a/Platform/Intel/ClevoOpenBoardPkg/N1xxWU/build_config.cfg b/Pla= tform/Intel/ClevoOpenBoardPkg/N1xxWU/build_config.cfg new file mode 100644 index 0000000000..ee1261e700 --- /dev/null +++ b/Platform/Intel/ClevoOpenBoardPkg/N1xxWU/build_config.cfg @@ -0,0 +1,33 @@ +# @ build_config.cfg +# This is the N1xxWU board specific build settings +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + + +[CONFIG] +WORKSPACE_PLATFORM_BIN =3D WORKSPACE_PLATFORM_BIN +EDK_SETUP_OPTION =3D +openssl_path =3D +PLATFORM_BOARD_PACKAGE =3D ClevoOpenBoardPkg +PROJECT =3D ClevoOpenBoardPkg/N1xxWU +BOARD =3D N1xxWU +FLASH_MAP_FDF =3D ClevoOpenBoardPkg/N1xxWU/Include/Fdf/FlashMapInclude.fdf +PROJECT_DSC =3D ClevoOpenBoardPkg/N1xxWU/OpenBoardPkg.dsc +BOARD_PKG_PCD_DSC =3D ClevoOpenBoardPkg/N1xxWU/OpenBoardPkgPcd.dsc +PrepRELEASE =3D DEBUG +SILENT_MODE =3D FALSE +EXT_CONFIG_CLEAR =3D +CapsuleBuild =3D FALSE +EXT_BUILD_FLAGS =3D +CAPSULE_BUILD =3D 0 +TARGET =3D DEBUG +TARGET_SHORT =3D D +PERFORMANCE_BUILD =3D FALSE +FSP_WRAPPER_BUILD =3D TRUE +FSP_BIN_PKG =3D KabylakeFspBinPkg +FSP_PKG_NAME =3D KabylakeFspPkg +FSP_BINARY_BUILD =3D FALSE +FSP_TEST_RELEASE =3D FALSE +SECURE_BOOT_ENABLE =3D FALSE diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_board.p= y b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_board.py new file mode 100644 index 0000000000..726ad85874 --- /dev/null +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_board.py @@ -0,0 +1,68 @@ +# @ build_board.py +# This is a sample code provides Optional dynamic imports +# of build functions to the BuildBios.py script +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +""" +This module serves as a sample implementation of the build extension +scripts +""" + + +def pre_build_ex(config, functions): + """Additional Pre BIOS build function + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: nothing + """ + print("pre_build_ex") + return None + + +def build_ex(config, functions): + """Additional BIOS build function + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("build_ex") + return None + + +def post_build_ex(config, functions): + """Additional Post BIOS build function + + :param config: The environment variables to be used in the post + build process + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("post_build_ex") + return None + + +def clean_ex(config, functions): + """Additional clean function + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("clean_ex") + return None diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_config.= cfg b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_config.cfg new file mode 100644 index 0000000000..5ea61dceb8 --- /dev/null +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/build_config.cfg @@ -0,0 +1,34 @@ +# @ build_config.cfg +# This is the KabylakeRvp3 board specific build settings +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + + +[CONFIG] +WORKSPACE_PLATFORM_BIN =3D WORKSPACE_PLATFORM_BIN +EDK_SETUP_OPTION =3D +openssl_path =3D +PLATFORM_BOARD_PACKAGE =3D KabylakeOpenBoardPkg +PROJECT =3D KabylakeOpenBoardPkg/KabylakeRvp3 +BOARD =3D KabylakeRvp3 +FLASH_MAP_FDF =3D KabylakeOpenBoardPkg/Include/Fdf/FlashMapInclude.fdf +PROJECT_DSC =3D KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc +BOARD_PKG_PCD_DSC =3D KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkgPcd.dsc +ADDITIONAL_SCRIPTS =3D KabylakeOpenBoardPkg/KabylakeRvp3/build_board.py +PrepRELEASE =3D DEBUG +SILENT_MODE =3D FALSE +EXT_CONFIG_CLEAR =3D +CapsuleBuild =3D FALSE +EXT_BUILD_FLAGS =3D +CAPSULE_BUILD =3D 0 +TARGET =3D DEBUG +TARGET_SHORT =3D D +PERFORMANCE_BUILD =3D FALSE +FSP_WRAPPER_BUILD =3D TRUE +FSP_BIN_PKG =3D KabylakeFspBinPkg +FSP_PKG_NAME =3D KabylakeFspPkg +FSP_BINARY_BUILD =3D FALSE +FSP_TEST_RELEASE =3D FALSE +SECURE_BOOT_ENABLE =3D FALSE diff --git a/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_board.p= y b/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_board.py new file mode 100644 index 0000000000..0dda929a00 --- /dev/null +++ b/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_board.py @@ -0,0 +1,177 @@ +# @ build_board.py +# This adds additional functions to the build_bios.py +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +""" +This module serves as an additional build steps for the Mt Olympus board +""" + +import os +import sys + + +def pre_build_ex(config, functions): + """Additional Pre BIOS build function + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: nothing + """ + print("Info: re-generating PlatformOffset header files") + + execute_script =3D functions.get("execute_script") + + command =3D ["build", "-D", "MAX_SOCKET=3D" + config.get("MAX_SOCKET",= "1"), + "-m", + os.path.join(config["PLATFORM_BOARD_PACKAGE"], + "Acpi", "BoardAcpiDxe", "Dsdt.inf"), + "-y", + config.get("PRE_BUILD_REPORT", + os.path.join(config["WORKSPACE"], + "preBuildReport.txt")), + "--log=3D" + config.get("PRE_BUILD_LOG", + os.path.join(config["WORKSPACE"], + "prebuild.log"))] + + _, _, _, code =3D execute_script(command, config) + if code !=3D 0: + print(" ".join(command)) + print("Error re-generating PlatformOffset header files") + sys.exit(1) + + config["AML_FILTER"] =3D "\"PSYS\" .MCTL\" .FIX[0-9,A-Z]\"" + print("AML_FILTER=3D ", config.get("AML_FILTER")) + + # build the command with arguments + command =3D ["python", + os.path.join(config["MIN_PACKAGE_TOOLS"], + "AmlGenOffset", + "AmlGenOffset.py"), + "-d", "--aml_filter", config["AML_FILTER"], + "-o", os.path.join(config["WORKSPACE_PLATFORM"], + config["PLATFORM_BOARD_PACKAGE"], + "Acpi", "BoardAcpiDxe", + "AmlOffsetTable.c"), + os.path.join(config["BUILD_X64"], + "PurleyOpenBoardPkg", + "Acpi", + "BoardAcpiDxe", + "DSDT", + "OUTPUT", + "Dsdt", "WFPPlatform.offset.h")] + + # execute the command + _, _, _, code =3D execute_script(command, config) + if code !=3D 0: + print(" ".join(command)) + print("Error re-generating PlatformOffset header files") + sys.exit(1) + + print("GenOffset done") + return config + + +def build_ex(config, functions): + """Additional BIOS build function + + :param config: The environment variables to be used in + the build process + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("build_ex") + return None + + +def post_build_ex(config, functions): + """Additional Post BIOS build function + + :param config: The environment variables to be used in the post + build process + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("post_build_ex") + + execute_script =3D functions.get("execute_script") + + if not execute_script: + print("post_build_ex Error") + sys.exit(1) + + common_patch_command =3D [os.path.join(config["PYTHON_HOME"], "python"= ), + os.path.join(config["MIN_PACKAGE_TOOLS"], + "PatchFv", "PatchBinFv.py"), + config["TARGET"], + os.path.join(config["WORKSPACE_SILICON_BIN"], + "PurleySiliconBinPkg"), + os.path.join(config["WORKSPACE"], + "BuildReport.log")] + + fvs_to_patch =3D ["FvTempMemorySilicon", + "FvPreMemorySilicon", + "FvPostMemorySilicon", + "FvLateSilicon"] + for fv in fvs_to_patch: + patch_command =3D common_patch_command + [fv] + _, _, _, code =3D execute_script(patch_command, config) + if code !=3D 0: + print(" ".join(patch_command)) + print("Patch Error!") + sys.exit(1) + + common_rebase_command =3D [os.path.join(config["PYTHON_HOME"], "python= "), + os.path.join(config["MIN_PACKAGE_TOOLS"], + "PatchFv", "RebaseBinFv.py"), + config["TARGET"], + os.path.join(config["WORKSPACE_SILICON_BIN"], + "PurleySiliconBinPkg"), + os.path.join(config["WORKSPACE"], + "BuildReport.log")] + + rebase_command =3D common_rebase_command +\ + ["FvPreMemorySilicon", + "gMinPlatformPkgTokenSpaceGuid.PcdFlashFvFspMBase"] + + _, _, _, code =3D execute_script(rebase_command, config) + if code !=3D 0: + print(" ".join(rebase_command)) + print("Patch Error!") + sys.exit(1) + + rebase_command =3D common_rebase_command +\ + ["FvPostMemorySilicon", + "gMinPlatformPkgTokenSpaceGuid.PcdFlashFvFspSBase"] + + _, _, _, code =3D execute_script(rebase_command, config) + if code !=3D 0: + print(" ".join(rebase_command)) + print("Patch Error!") + sys.exit(1) + + return None + + +def clean_ex(config, functions): + """Additional clean function + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :param functions: A dictionary of function pointers + :type functions: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + print("clean_ex") + return None diff --git a/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_config.= cfg b/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_config.cfg new file mode 100644 index 0000000000..dcf19d658d --- /dev/null +++ b/Platform/Intel/PurleyOpenBoardPkg/BoardMtOlympus/build_config.cfg @@ -0,0 +1,32 @@ +# @ build_config.cfg +# This is the main/default build configuration file +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + + +[CONFIG] +WORKSPACE_PLATFORM_BIN =3D WORKSPACE_PLATFORM_BIN +EDK_SETUP_OPTION =3D +openssl_path =3D +PLATFORM_BOARD_PACKAGE =3D PurleyOpenBoardPkg +PROJECT =3D PurleyOpenBoardPkg/BoardMtOlympus +BOARD =3D BoardMtOlympus +FLASH_MAP_FDF =3D PurleyOpenBoardPkg/Include/Fdf/FlashMapInclude.fdf +PROJECT_DSC =3D PurleyOpenBoardPkg/BoardMtOlympus/PlatformPkg.dsc +BOARD_PKG_PCD_DSC =3D PurleyOpenBoardPkg/BoardMtOlympus/PlatformPkgPcd.dsc +ADDITIONAL_SCRIPTS =3D PurleyOpenBoardPkg/BoardMtOlympus/build_board.py +PRE_BUILD_LOG =3D prebuild.log +PRE_BUILD_REPORT =3D prebuildReport.log +PrepRELEASE =3D DEBUG +SILENT_MODE =3D FALSE +EXT_CONFIG_CLEAR =3D +CapsuleBuild =3D FALSE +EXT_BUILD_FLAGS =3D +CAPSULE_BUILD =3D 0 +TARGET =3D DEBUG +TARGET_SHORT =3D D +PERFORMANCE_BUILD =3D FALSE +FSP_WRAPPER_BUILD =3D FALSE +MAX_SOCKET =3D 2 diff --git a/Platform/Intel/build.cfg b/Platform/Intel/build.cfg new file mode 100644 index 0000000000..b6c0cca4f7 --- /dev/null +++ b/Platform/Intel/build.cfg @@ -0,0 +1,56 @@ +# @ build.cfg +# This is the main/default build configuration file +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + + +[DEFAULT_CONFIG] +WORKSPACE =3D +WORKSPACE_FSP_BIN =3D FSP +EDK_TOOLS_BIN =3D edk2-BaseTools-win32 +EDK_BASETOOLS =3D BaseTools +WORKSPACE_PLATFORM =3D edk2-platforms/Platform/Intel +WORKSPACE_SILICON =3D edk2-platforms/Silicon/Intel +WORKSPACE_PLATFORM_BIN =3D +WORKSPACE_SILICON_BIN =3D edk2-non-osi/Silicon/Intel +MIN_PACKAGE_TOOLS =3D edk2-platforms/Platform/Intel/MinPlatformPkg/Tools +PACKAGES_PATH =3D +EDK_SETUP_OPTION =3D +BASE_TOOLS_PATH =3D edk2/BaseTools +EDK_TOOLS_PATH =3D edk2/BaseTools +openssl_path =3D +PLATFORM_BOARD_PACKAGE =3D +BIOS_SIZE_OPTION =3D -DBIOS_SIZE_OPTION=3DSIZE_70 +WORKSPACE_CORE =3D edk2 +EFI_SOURCE =3D edk2 +PATHEXT =3D .COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC +PROMPT =3D $P$G +PLATFORM_PACKAGE =3D MinPlatformPkg +BOARD =3D +PrepRELEASE =3D DEBUG +SILENT_MODE =3D FALSE +EXT_CONFIG_CLEAR =3D +CapsuleBuild =3D FALSE +EXT_BUILD_FLAGS =3D +CAPSULE_BUILD =3D 0 +TARGET =3D DEBUG +TARGET_SHORT =3D D +PERFORMANCE_BUILD =3D FALSE +FSP_WRAPPER_BUILD =3D FALSE +FSP_BIN_PKG =3D +FSP_PKG_NAME =3D +FSP_BINARY_BUILD =3D FALSE +FSP_TEST_RELEASE =3D FALSE +SECURE_BOOT_ENABLE =3D FALSE +REBUILD_MODE =3D +BUILD_ROM_ONLY =3D +NUMBER_OF_PROCESSORS =3D 1 + + +[PLATFORMS] +# board_name =3D path_to_board_build_config.cfg +KabylakeRvp3 =3D KabylakeOpenBoardPkg/KabylakeRvp3/build_config.cfg +N1xxWU =3D ClevoOpenBoardPkg/N1xxWU/build_config.cfg +BoardMtOlympus =3D PurleyOpenBoardPkg/BoardMtOlympus/build_config.cfg diff --git a/Platform/Intel/build_bios.py b/Platform/Intel/build_bios.py new file mode 100644 index 0000000000..2edf340e0c --- /dev/null +++ b/Platform/Intel/build_bios.py @@ -0,0 +1,976 @@ + +# @ build_bios.py +# Builds BIOS using configuration files and dynamically +# imported functions from board directory +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +""" +This module builds BIOS using configuration files and dynamically +imported functions from board directory +""" + + +import os +import re +import sys +import signal +import shutil +import argparse +import traceback +import subprocess +from importlib import import_module + +try: + # python 2.7 + import ConfigParser as configparser +except ImportError: + # python 3 + import configparser + + +def pre_build(build_config, build_type=3D"DEBUG", silent=3DFalse, toolchai= n=3DNone): + """Sets the environment variables that shall be used for the build + + :param build_config: The build configuration as defined in the JOSN + configuration files + :type build_config: Dictionary + :param build_type: The build target, DEBUG, RELEASE, RELEASE_PDB, + TEST_RELEASE + :type build_type: String + :param silent: Enables build in silent mode + :type silent: Boolean + :param toolchain: Specifies the tool chain tag to use for the build + :type toolchain: String + :returns: The updated environment variables + :rtype: Dictionary + """ + + # get current environment variables + config =3D os.environ.copy() + + # patch the build config + build_config =3D patch_config(build_config) + + # update the current config with the build config + config.update(build_config) + + # make the config and build python 2.7 compartible + config =3D py_27_fix(config) + + # Set WORKSPACE environment. + config["WORKSPACE"] =3D os.path.abspath(os.path.join("..", "..", "..",= "")) + print("Set WORKSPACE as: {}".format(config["WORKSPACE"])) + + # Check whether Git has been installed and been added to system path. + try: + subprocess.Popen(["git", "--help"], stdout=3Dsubprocess.PIPE) + except OSError: + print("The 'git' command is not recognized.") + print("Please make sure that Git is installed\ + and has been added to system path.") + sys.exit(1) + + # Create the Conf directory under WORKSPACE + if not os.path.isdir(os.path.join(config["WORKSPACE"], "Conf")): + try: + # create directory + os.makedirs(os.path.join(config["WORKSPACE"], "Conf")) + # copy files to it + config_template_path =3D os.path.join(config["WORKSPACE"], + config["BASE_TOOLS_PATH"], + "Conf") + config_path =3D os.path.join(config["WORKSPACE"], "Conf") + shutil.copyfile(config_template_path + + os.sep + "target.template", + config_path + os.sep + "target.txt") + shutil.copyfile(config_template_path + + os.sep + "tools_def.template", + config_path + os.sep + "tools_def.txt") + shutil.copyfile(config_template_path + + os.sep + "build_rule.template", + config_path + os.sep + "build_rule.txt") + except OSError: + print("Error while creating Conf") + sys.exit(1) + + # Set other environments. + # Basic Rule: + # Platform override Silicon override Core + # Source override Binary + config["WORKSPACE_PLATFORM"] =3D os.path.join(config["WORKSPACE"], + config["WORKSPACE_PLATFORM= "]) + config["WORKSPACE_SILICON"] =3D os.path.join(config["WORKSPACE"], + config["WORKSPACE_SILICON"]) + config["WORKSPACE_PLATFORM_BIN"] =3D \ + os.path.join(config["WORKSPACE"], config["WORKSPACE_PLATFORM_BIN"]) + config["WORKSPACE_SILICON_BIN"] =3D \ + os.path.join(config["WORKSPACE"], config["WORKSPACE_SILICON_BIN"]) + config["WORKSPACE_FSP_BIN"] =3D os.path.join(config["WORKSPACE"], + config["WORKSPACE_FSP_BIN"]) + + # add to package path + config["PACKAGES_PATH"] =3D config["WORKSPACE_PLATFORM"] + config["PACKAGES_PATH"] +=3D os.pathsep + config["WORKSPACE_SILICON"] + config["PACKAGES_PATH"] +=3D os.pathsep + config["WORKSPACE_SILICON_BI= N"] + config["PACKAGES_PATH"] +=3D os.pathsep + \ + os.path.join(config["WORKSPACE"], "FSP") + config["PACKAGES_PATH"] +=3D os.pathsep + \ + os.path.join(config["WORKSPACE"], "edk2") + config["PACKAGES_PATH"] +=3D os.pathsep + os.path.join(config["WORKSPA= CE"]) + config["EDK_TOOLS_PATH"] =3D os.path.join(config["WORKSPACE"], + config["EDK_TOOLS_PATH"]) + config["BASE_TOOLS_PATH"] =3D config["EDK_TOOLS_PATH"] + config["EDK_TOOLS_BIN"] =3D os.path.join(config["WORKSPACE"], + config["EDK_TOOLS_BIN"]) + config["PLATFORM_FSP_BIN_PACKAGE"] =3D \ + os.path.join(config['WORKSPACE_FSP_BIN'], config['FSP_BIN_PKG']) + config['PROJECT_DSC'] =3D os.path.join(config["WORKSPACE_PLATFORM"], + config['PROJECT_DSC']) + config['BOARD_PKG_PCD_DSC'] =3D os.path.join(config["WORKSPACE_PLATFOR= M"], + config['BOARD_PKG_PCD_DSC']) + config["CONF_PATH"] =3D os.path.join(config["WORKSPACE"], "Conf") + + # get the python path + if os.environ.get("PYTHON_HOME") is None: + config["PYTHON_HOME"] =3D None + if os.environ.get("PYTHONPATH") is not None: + config["PYTHON_HOME"] =3D os.environ.get("PYTHONPATH") + else: + print("PYTHONPATH environment variable is not found") + sys.exit(1) + + # if python is installed, disable the binary base tools. + # python is installed if this code is running :) + if config.get("PYTHON_HOME") is not None: + if config.get("EDK_TOOLS_BIN") is not None: + del config["EDK_TOOLS_BIN"] + + # Run edk setup and update config + if os.name =3D=3D 'nt': + edk2_setup_cmd =3D [os.path.join(config["EFI_SOURCE"], "edksetup"), + "Rebuild"] + + if config.get("EDK_SETUP_OPTION") and \ + config["EDK_SETUP_OPTION"] !=3D " ": + edk2_setup_cmd.append(config["EDK_SETUP_OPTION"]) + + _, _, result, return_code =3D execute_script(edk2_setup_cmd, + config, + collect_env=3DTrue, + shell=3DTrue) + if return_code =3D=3D 0 and result is not None and isinstance(resu= lt, + dict): + config.update(result) + + # nmake BaseTools source + # and enable BaseTools source build + shell =3D True + command =3D ["nmake", "-f", os.path.join(config["BASE_TOOLS_PATH"], + "Makefile")] + if os.name =3D=3D "posix": # linux + shell =3D False + command =3D ["make", "-C", os.path.join(config["BASE_TOOLS_PATH"])] + + _, _, result, return_code =3D execute_script(command, config, shell=3D= shell) + if return_code !=3D 0: + build_failed(config) + + config["SILENT_MODE"] =3D 'TRUE' if silent else 'FALSE' + + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= ") + + if os.path.isfile(os.path.join(config['WORKSPACE'], "Prep.log")): + os.remove(os.path.join(config['WORKSPACE'], "Prep.log")) + + config["PROJECT"] =3D os.path.join(config["PLATFORM_BOARD_PACKAGE"], + config["BOARD"]) + + # Setup Build + # @todo: Need better TOOL_CHAIN_TAG detection + if toolchain is not None: + config["TOOL_CHAIN_TAG"] =3D toolchain + elif config.get("TOOL_CHAIN_TAG") is None: + if os.name =3D=3D 'nt': + config["TOOL_CHAIN_TAG"] =3D "VS2015" + else: + config["TOOL_CHAIN_TAG"] =3D "GCC5" + + # echo Show CL revision + config["PrepRELEASE"] =3D build_type + + if build_type =3D=3D "DEBUG": + config["TARGET"] =3D 'DEBUG' + config["TARGET_SHORT"] =3D 'D' + else: + config["TARGET"] =3D 'RELEASE' + config["TARGET_SHORT"] =3D 'R' + + # set BUILD_DIR_PATH path + config["BUILD_DIR_PATH"] =3D os.path.join(config["WORKSPACE"], + 'Build', + config["PROJECT"], + "{}_{}".format( + config["TARGET"], + config["TOOL_CHAIN_TAG"])) + # set BUILD_DIR path + config["BUILD_DIR"] =3D os.path.join('Build', + config["PROJECT"], + "{}_{}".format( + config["TARGET"], + config["TOOL_CHAIN_TAG"])) + + config["BUILD_X64"] =3D os.path.join(config["BUILD_DIR_PATH"], 'X64') + config["BUILD_IA32"] =3D os.path.join(config["BUILD_DIR_PATH"], 'IA32') + + if not os.path.isdir(config["BUILD_DIR_PATH"]): + try: + os.makedirs(config["BUILD_DIR_PATH"]) + except OSError: + print("Error while creating Build folder") + sys.exit(1) + + # Set FSP_WRAPPER_BUILD + if config['FSP_WRAPPER_BUILD'] =3D=3D "TRUE": + # Create dummy Fsp_Rebased_S_padded.fd to build the BiosInfo.inf + # if it is wrapper build, due to the SECTION inclusion + open(os.path.join(config["WORKSPACE_FSP_BIN"], + config["FSP_BIN_PKG"], + "Fsp_Rebased_S_padded.fd"), 'w').close() + + if not os.path.isdir(config["BUILD_X64"]): + try: + os.mkdir(config["BUILD_X64"]) + except OSError: + print("Error while creating {}".format(config["BUILD_X64"])) + sys.exit(1) + + # update config file with changes + update_target_file(config) + + # Additional pre build scripts for this platform + result =3D pre_build_ex(config) + if result is not None and isinstance(result, dict): + config.update(result) + + # print user settings + print("BIOS_SIZE_OPTION =3D {}".format(config["BIOS_SIZE_OPTION"])) + print("EFI_SOURCE =3D {}".format(config["EFI_SOURCE"])) + print("TARGET =3D {}".format(config["TARGET"])) + print("TARGET_ARCH =3D {}".format("IA32 X64")) + print("TOOL_CHAIN_TAG =3D {}".format(config["TOOL_CHAIN_TAG"])) + print("WORKSPACE =3D {}".format(config["WORKSPACE"])) + print("WORKSPACE_CORE =3D {}".format(config["WORKSPACE_CORE"])) + print("EXT_BUILD_FLAGS =3D {}".format(config["EXT_BUILD_FLAGS"])) + + return config + + +def build(config): + """Builds the BIOS image + + :param config: The environment variables to be used + in the build process + :type config: Dictionary + :returns: nothing + """ + + if config["FSP_WRAPPER_BUILD"] =3D=3D "TRUE": + pattern =3D "Fsp_Rebased.*\\.fd$" + file_dir =3D os.path.join(config['WORKSPACE_FSP_BIN'], + config['FSP_BIN_PKG']) + for item in os.listdir(file_dir): + if re.search(pattern, item): + os.remove(os.path.join(file_dir, item)) + + command =3D [os.path.join(config['PYTHON_HOME'], "python"), + os.path.join(config['WORKSPACE_PLATFORM'], + config['PLATFORM_PACKAGE'], + 'Tools', 'Fsp', + 'RebaseAndPatchFspBinBaseAddress.py'), + os.path.join(config['WORKSPACE_PLATFORM'], + config['FLASH_MAP_FDF']), + os.path.join(config['WORKSPACE_FSP_BIN'], + config['FSP_BIN_PKG']), + "Fsp.fd", + os.path.join(config['WORKSPACE_PLATFORM'], + config['PROJECT'], + config['BOARD_PKG_PCD_DSC']), + "0x0"] + + _, _, _, return_code =3D execute_script(command, config, shell=3DF= alse) + + if return_code !=3D 0: + print("ERROR:RebaseAndPatchFspBinBaseAddress failed") + sys.exit(return_code) + + # create Fsp_Rebased.fd which is Fsp_Rebased_S.fd + + # Fsp_Rebased_M + Fsp_Rebased_T + with open(os.path.join(file_dir, "Fsp_Rebased_S.fd"), 'rb') as fsp= _s, \ + open(os.path.join(file_dir, + "Fsp_Rebased_M.fd"), 'rb') as fsp_m, \ + open(os.path.join(file_dir, + "Fsp_Rebased_T.fd"), 'rb') as fsp_t: + + fsp_rebased =3D fsp_s.read() + fsp_m.read() + fsp_t.read() + with open(os.path.join(file_dir, + "Fsp_Rebased.fd"), 'wb') as new_fsp: + new_fsp.write(fsp_rebased) + + if not os.path.isfile(os.path.join(file_dir, "Fsp_Rebased.fd")): + print("!!! ERROR:failed to create fsp!!!") + sys.exit(1) + + # Output the build variables the user has selected. + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D") + print(" User Selected build options:") + print(" SILENT_MODE =3D ", config.get("SILENT_MODE")) + print(" REBUILD_MODE =3D ", config.get("REBUILD_MODE")) + print(" BUILD_ROM_ONLY =3D ", config.get("BUILD_ROM_ONLY")) + print("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D") + + command =3D ["build", "-n", config["NUMBER_OF_PROCESSORS"]] + + if config["REBUILD_MODE"] and config["REBUILD_MODE"] !=3D "": + command.append(config["REBUILD_MODE"]) + + if config["EXT_BUILD_FLAGS"] and config["EXT_BUILD_FLAGS"] !=3D "": + command.append(config["EXT_BUILD_FLAGS"]) + + if config.get("SILENT_MODE", "FALSE") =3D=3D "TRUE": + command.append("--silent") + command.append("--quiet") + + else: + command.append("--log=3D" + config.get("BUILD_LOG", "Build.log")) + command.append("--report-file=3D" + + config.get("BUILD_REPORT", "BuildReport.log")) + + if config.get("VERBOSE", "FALSE") =3D=3D "TRUE": + command.append("--verbose") + + if config.get("MAX_SOCKET") is not None: + command.append("-D") + command.append("MAX_SOCKET=3D" + config["MAX_SOCKET"]) + + _, _, _, exit_code =3D execute_script(command, config) + if exit_code !=3D 0: + build_failed(config) + + # Additional build scripts for this platform + result =3D build_ex(config) + if result is not None and isinstance(result, dict): + config.update(result) + + return config + + +def post_build(config): + """Post build process of BIOS image + + :param config: The environment variables to be used in the build proce= ss + :type config: Dictionary + :returns: nothing + """ + print("Running post_build to complete the build process.") + + # Additional build scripts for this platform + result =3D post_build_ex(config) + if result is not None and isinstance(result, dict): + config.update(result) + + # cleanup + pattern =3D "Fsp_Rebased.*\\.fd$" + file_dir =3D os.path.join(config['WORKSPACE_FSP_BIN'], + config['FSP_BIN_PKG']) + for item in os.listdir(file_dir): + if re.search(pattern, item): + os.remove(os.path.join(file_dir, item)) + + if config.get("DYNAMIC_BUILD_INIT_FILES") is not None: + for item in config["DYNAMIC_BUILD_INIT_FILES"].split(","): + try: + os.remove(item) # remove __init__.py + os.remove(item + "c") # remove __init__.pyc as well + except OSError: + pass + + +def build_failed(config): + """Displays results when build fails + + :param config: The environment variables used in the build process + :type config: Dictionary + :returns: nothing + """ + print(" The EDKII BIOS Build has failed!") + # clean up + if config.get("DYNAMIC_BUILD_INIT_FILES") is not None: + for item in config["DYNAMIC_BUILD_INIT_FILES"].split(","): + if os.path.isfile(item): + try: + os.remove(item) # remove __init__.py + os.remove(item + "c") # remove __init__.pyc as well + except OSError: + pass + sys.exit(1) + + +def import_platform_lib(path, function): + """Imports custom functions for the platforms being built + + :param path: the location of the custom build script to be executed + :type path: String + :param path: the function to be executed + :type path: String + :returns: nothing + """ + if path.endswith(".py"): + path =3D path[:-3] + path =3D path.replace(os.sep, ".") + module =3D import_module(path) + lib =3D getattr(module, function) + return lib + + +def pre_build_ex(config): + """ An extension of the pre_build process as defined platform + specific pre_build setup script + + :param config: The environment variables used in the pre build pro= cess + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + if config.get("ADDITIONAL_SCRIPTS"): + try: + platform_function =3D\ + import_platform_lib(config["ADDITIONAL_SCRIPTS"], + "pre_build_ex") + functions =3D {"execute_script": execute_script} + return platform_function(config, functions) + except ImportError as error: + print(config["ADDITIONAL_SCRIPTS"], str(error)) + build_failed(config) + return None + + +def build_ex(config): + """ An extension of the build process as defined platform + specific build setup script + + :param config: The environment variables used in the build process + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + if config.get("ADDITIONAL_SCRIPTS"): + try: + platform_function =3D\ + import_platform_lib(config["ADDITIONAL_SCRIPTS"], + "build_ex") + functions =3D {"execute_script": execute_script} + return platform_function(config, functions) + except ImportError as error: + print("error", config["ADDITIONAL_SCRIPTS"], str(error)) + build_failed(config) + return None + + +def post_build_ex(config): + """ An extension of the post build process as defined platform + specific build setup script + + :param config: The environment variables used in the post build + process + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + if config.get("ADDITIONAL_SCRIPTS"): + try: + platform_function =3D\ + import_platform_lib(config["ADDITIONAL_SCRIPTS"], + "post_build_ex") + functions =3D {"execute_script": execute_script} + return platform_function(config, functions) + except ImportError as error: + print(config["ADDITIONAL_SCRIPTS"], str(error)) + build_failed(config) + return None + + +def clean_ex(config): + """ An extension of the platform cleanning + + :param config: The environment variables used in the clean process + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + if config.get("ADDITIONAL_SCRIPTS"): + try: + platform_function =3D\ + import_platform_lib(config["ADDITIONAL_SCRIPTS"], + "clean_ex") + functions =3D {"execute_script": execute_script} + return platform_function(config, functions) + except ImportError as error: + print(config["ADDITIONAL_SCRIPTS"], str(error)) + build_failed(config) + return None + + +def get_environment_variables(std_out_str, marker): + """Gets the environment variables from a process + + :param std_out_str: The std_out pipe + :type std_out_str: String + :param marker: A begining and end mark of environment + variables printed to std_out + :type marker: String + :returns: The environment variables read from the process' std_out= pipe + :rtype: Tuple + """ + start_env_update =3D False + environment_vars =3D {} + out_put =3D "" + for line in std_out_str.split("\n"): + if start_env_update and len(line.split("=3D")) =3D=3D 2: + key, value =3D line.split("=3D") + environment_vars[key] =3D value + else: + out_put +=3D "\n" + line.replace(marker, "") + + if marker in line: + if start_env_update: + start_env_update =3D False + else: + start_env_update =3D True + return (out_put, environment_vars) + + +def execute_script(command, env_variables, collect_env=3DFalse, + enable_std_pipe=3DFalse, shell=3DTrue): + """launches a process that executes a script/shell command passed to it + + :param command: The command/script with its commandline + arguments to be executed + :type command: List:String + :param env_variables: Environment variables passed to the process + :type env_variables: String + :param collect_env: Enables the collection of evironment variables + when process execution is done + :type collect_env: Boolean + :param enable_std_pipe: Enables process out to be piped to + :type enable_std_pipe: String + :returns: a tuple of std_out, stderr , environment variables, + return code + :rtype: Tuple: (std_out, stderr , enVar, return_code) + """ + + print("Calling " + " ".join(command)) + + env_marker =3D '-----env-----' + env =3D {} + kwarg =3D {"env": env_variables, + "universal_newlines": True, + "shell": shell, + "cwd": env_variables["WORKSPACE"]} + + if enable_std_pipe or collect_env: + kwarg["stdout"] =3D subprocess.PIPE + kwarg["stderr"] =3D subprocess.PIPE + + # collect environment variables + if collect_env: + # get the binary that prints environment variables based on os + if os.name =3D=3D 'nt': + get_var_command =3D "set" + else: + get_var_command =3D "env" + # modify the command to print the environment variables + if isinstance(command, list): + command +=3D ["&&", "echo", env_marker, "&&", + get_var_command, "&&", "echo", env_marker] + else: + command +=3D " " + " ".join(["&&", "echo", env_marker, + "&&", get_var_command, + "&&", "echo", env_marker]) + + # execute the command + execute =3D subprocess.Popen(command, **kwarg) + std_out, stderr =3D execute.communicate() + code =3D execute.returncode + + # wait for process to be done + execute.wait() + + # if collect enviroment variables + if collect_env: + # get the new environment variables + std_out, env =3D get_environment_variables(std_out, env_marker) + return (std_out, stderr, env, code) + + +def patch_config(config): + """ An extension of the platform cleanning + + :param config: The environment variables used in the build process + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + new_config =3D {} + for key in config: + new_config[str(key)] =3D str(config[key].replace("/", os.sep)) + return new_config + + +def py_27_fix(config): + """ Prepares build for python 2.7 =3D> build + :param config: The environment variables used in the build process + :type config: Dictionary + :returns: config dictionary + :rtype: Dictionary + """ + if not sys.version_info > (3, 0): + path_list =3D [] + # create __init__.py in directories in this path + if config.get("ADDITIONAL_SCRIPTS"): + # get the directory + path_to_directory =3D\ + os.path.dirname(config.get("ADDITIONAL_SCRIPTS")) + path =3D "" + for directories in path_to_directory.split(os.sep): + path +=3D directories + os.sep + init_file =3D path + os.sep + "__init__.py" + if not os.path.isfile(init_file): + open(init_file, 'w').close() + path_list.append(init_file) + config["DYNAMIC_BUILD_INIT_FILES"] =3D ",".join(path_list) + + return config + + +def clean(build_config, board=3DFalse): + """Cleans the build workspace + + :param config: The environment variables used in the build process + :type config: Dictionary + :param board: This flag specifies specific board clean + :type board: Bool + :returns: nothing + """ + + # patch the config + build_config =3D patch_config(build_config) + + # get current environment variables + config =3D os.environ.copy() + + # update it with the build variables + config.update(build_config) + + if config.get('WORKSPACE') is None or not config.get('WORKSPACE'): + config["WORKSPACE"] =3D\ + os.path.abspath(os.path.join("..", "..", "..", "")) + + # build cleanall + print("Cleaning directories...") + + if board: + platform_pkg =3D config.get("PLATFORM_BOARD_PACKAGE", None) + if platform_pkg is None or\ + not os.path.isdir(os.path.join(config['WORKSPACE'], + "Build", platform_pkg)): + print("Platform package not found") + sys.exit(1) + else: + print("Removing " + os.path.join(config['WORKSPACE'], + "Build", platform_pkg)) + shutil.rmtree(os.path.join(config['WORKSPACE'], + "Build", platform_pkg)) + + else: + if os.path.isdir(os.path.join(config['WORKSPACE'], "Build")): + print("Removing " + os.path.join(config['WORKSPACE'], "Build")) + shutil.rmtree(os.path.join(config['WORKSPACE'], "Build")) + + if os.path.isdir(os.path.join(config['WORKSPACE'], "Conf")): + print("Removing " + os.path.join(config['WORKSPACE'], "Conf")) + shutil.rmtree(os.path.join(config['WORKSPACE'], "Conf")) + + print("Cleaning files...") + + if os.path.isfile(os.path.join(config['WORKSPACE'], + config.get("BUILD_REPORT", + "BuildReport.log"))): + print("Removing ", os.path.join(config['WORKSPACE'], + config.get("BUILD_REPORT", + "BuildReport.log"))) + os.remove(os.path.join(config['WORKSPACE'], + config.get("BUILD_REPORT", "BuildReport.log= "))) + + print(" All done...") + + sys.exit(0) + + +def update_target_file(config): + """Updates Conf's target file that will be used in the build + + :param config: The environment variables used in the build process + :type config: Dictionary + :returns: True if update was successful and False if update fails + :rtype: Boolean + """ + contents =3D None + result =3D False + with open(os.path.join(config["CONF_PATH"], "target.txt"), 'r') as tar= get: + contents =3D target.readlines() + options_list =3D ['ACTIVE_PLATFORM', 'TARGET', + 'TARGET_ARCH', 'TOOL_CHAIN_TAG', 'BUILD_RULE_CONF'] + modified =3D [] + + # remove these options from the config file + for line in contents: + if line.replace(" ", "")[0] !=3D '#' and\ + any(opt in line for opt in options_list): + continue + modified.append(line) + + # replace with config options provided + string =3D "{} =3D {}\n".format("ACTIVE_PLATFORM", + os.path.join( + config['WORKSPACE_PLATFORM'], + config['PLATFORM_BOARD_PACKAGE'], + config['BOARD'], + config['PROJECT_DSC'])) + modified.append(string) + + string =3D "{} =3D {}\n".format("TARGET", config['TARGET']) + modified.append(string) + + string =3D "TARGET_ARCH =3D IA32 X64\n" + modified.append(string) + + string =3D "{} =3D {}\n".format("TOOL_CHAIN_TAG", config['TOOL_CHA= IN_TAG']) + modified.append(string) + + string =3D "{} =3D {}\n".format("BUILD_RULE_CONF", + os.path.join("Conf", "build_rule.txt")) + modified.append(string) + + if modified is not None: + with open(os.path.join(config["WORKSPACE"], + "Conf", "target.txt"), 'w') as target: + for line in modified: + target.write(line) + result =3D True + + return result + + +def get_config(): + """Reads the default projects config file + + :returns: The config defined in the the Build.cfg file + :rtype: Dictionary + """ + config_file =3D configparser.RawConfigParser() + config_file.optionxform =3D str + config_file.read('build.cfg') + config_dictionary =3D {} + for section in config_file.sections(): + dictionary =3D dict(config_file.items(section)) + config_dictionary[section] =3D dictionary + return config_dictionary + + +def get_platform_config(platform_name, config_data): + """ Reads the platform specifig config file + + param platform_name: The name of the platform to be built + :type platform_name: String + param configData: The environment variables to be + used in the build process + :type configData: Dictionary + :returns: The config defined in the the Build.cfg file + :rtype: Dictionary + """ + config =3D {} + + platform_data =3D config_data.get("PLATFORMS") + path =3D platform_data.get(platform_name) + config_file =3D configparser.RawConfigParser() + config_file.optionxform =3D str + config_file.read(path) + for section in config_file.sections(): + config[section] =3D dict(config_file.items(section)) + + return config + + +def get_cmd_config_arguments(arguments): + """Get commandline config arguments + + param arguments: The environment variables to be used in the build pro= cess + :type arguments: argparse + :returns: The config dictionary built from the commandline arguments + :rtype: Dictionary + """ + result =3D {} + if arguments.capsule is True: + result["CAPSULE_BUILD"] =3D "1" + + if arguments.performance is True: + result["PERFORMANCE_BUILD"] =3D "TRUE" + + if arguments.fsp is True: + result["FSP_WRAPPER_BUILD"] =3D "TRUE" + + return result + + +def get_cmd_arguments(build_config): + """ Get commandline inputs from user + + param config_data: The environment variables to be + used in the build process + :type config_data: Dictionary + :returns: The commandline arguments input by the user + :rtype: argparse object + """ + + class PrintPlatforms(argparse.Action): + """ this is an argparse action that lists the available platforms + """ + def __call__(self, parser, namespace, values, option_string=3DNone= ): + print("Platforms:") + for key in build_config.get("PLATFORMS"): + print(" " + key) + setattr(namespace, self.dest, values) + sys.exit(0) + + # get the build commands + parser =3D argparse.ArgumentParser(description=3D"Build Help") + parser.add_argument('--platform', '-p', dest=3D"platform", + help=3D'the platform to build', + choices=3Dbuild_config.get("PLATFORMS"), + required=3D('-l' not in sys.argv and + '--cleanall' not in sys.argv)) + + parser.add_argument('--toolchain', '-t', dest=3D"toolchain", + help=3D"using the Tool Chain Tagname to build \ + the platform,overriding \ + target.txt's TOOL_CHAIN_TAG definition") + + parser.add_argument("--DEBUG", '-d', help=3D"debug flag", + action=3D'store_const', dest=3D"target", + const=3D"DEBUG", default=3D"DEBUG") + + parser.add_argument("--RELEASE", '-r', help=3D"release flag", + action=3D'store_const', + dest=3D"target", const=3D"RELEASE") + + parser.add_argument("--TEST_RELEASE", '-tr', help=3D"test Release flag= ", + action=3D'store_const', + dest=3D"target", const=3D"TEST_RELEASE") + + parser.add_argument("--RELEASE_PDB", '-rp', help=3D"release flag", + action=3D'store_const', dest=3D"target", + const=3D"RELEASE_PDB") + + parser.add_argument('--list', '-l', action=3DPrintPlatforms, + help=3D'lists available platforms', nargs=3D0) + + parser.add_argument('--cleanall', dest=3D'clean_all', + help=3D'cleans all', action=3D'store_true') + + parser.add_argument('--clean', dest=3D'clean', + help=3D'cleans specific platform', action=3D'store= _true') + + parser.add_argument("--capsule", help=3D"capsule build enabled", + action=3D'store_true', dest=3D"capsule") + + parser.add_argument("--silent", help=3D"silent build enabled", + action=3D'store_true', dest=3D"silent") + + parser.add_argument("--performance", help=3D"performance build enabled= ", + action=3D'store_true', dest=3D"performance") + + parser.add_argument("--fsp", help=3D"fsp build enabled", + action=3D'store_true', dest=3D"fsp") + + return parser.parse_args() + + +def keyboard_interruption(int_signal, int_frame): + """ Catches a keyboard interruption handler + + param int_signal: The signal this handler is called with + :type int_signal: Signal + param int_frame: The signal this handler is called with + :type int_frame: frame + :rtype: nothing + """ + print("Signal #: {} Frame: {}".format(int_signal, int_frame)) + print("Quiting...") + sys.exit(0) + + +def main(): + """ The main function of this module + :rtype: nothing + """ + # to quit the build + signal.signal(signal.SIGINT, keyboard_interruption) + + # get general build configurations + build_config =3D get_config() + + # get commandline parameters + arguments =3D get_cmd_arguments(build_config) + + if arguments.clean_all: + clean(build_config.get("DEFAULT_CONFIG")) + + # get platform specific config + platform_config =3D get_platform_config(arguments.platform, build_conf= ig) + + # update general build config with platform specific config + config =3D build_config.get("DEFAULT_CONFIG") + config.update(platform_config.get("CONFIG")) + + # if user selected clean + if arguments.clean: + clean(config, board=3DTrue) + + # Override config with cmd arguments + cmd_config_args =3D get_cmd_config_arguments(arguments) + config.update(cmd_config_args) + + # get pre_build configurations + config =3D pre_build(config, + build_type=3Darguments.target, + toolchain=3Darguments.toolchain, + silent=3Darguments.silent) + + # build selected platform + config =3D build(config) + + # post build + post_build(config) + + +if __name__ =3D=3D "__main__": + try: + EXIT_CODE =3D 0 + main() + except Exception as error: + EXIT_CODE =3D 1 + traceback.print_exc() + sys.exit(EXIT_CODE) --=20 2.19.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#39964): https://edk2.groups.io/g/devel/message/39964 Mute This Topic: https://groups.io/mt/31489355/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 12:32:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+39963+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39963+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1556925561; cv=none; d=zoho.com; s=zohoarc; b=MNzFMvZkiyepAaxCqWay8xk4YGnl8paG0zLo8q+LUjyywCWO7cYHOnDDs502a2Vp7lnxTPEQQraXU4SPP5/YZ1ZOYktb1CkLY+vXvUI08gjMVJ0SOSQ5QJ7ijNzogSZ6R+H0cvbk6YCUOkGGosEdedIFUU74G9H+7MwPNFicCyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556925561; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=RIhvMPgWpuIqUAbLVXvrfs1JobqM6MN5Avb7xTyoaRs=; b=Z+aScOl4aulNdEuTMUp2vuucQRN7/jVL5IWA3E/Lmx6Bv8SWXXLZsbvmxzw8bhACs8F24NT8TZ1RmIu5RAGr96gKezfEj1AE6HUY+NY3EJ1iwKsIgTWwRtb3KAMY7487g7euTz/THaUbRu+HL7NTQ4Ykvf8eXQjvo8sDgg5a5xQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39963+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1556925561116430.5871640735487; Fri, 3 May 2019 16:19:21 -0700 (PDT) Return-Path: X-Received: from mga06.intel.com (mga06.intel.com []) by groups.io with SMTP; Fri, 03 May 2019 16:19:20 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2019 16:19:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,427,1549958400"; d="scan'208";a="148017021" X-Received: from paagyema-desk2.amr.corp.intel.com ([10.7.159.148]) by orsmga003.jf.intel.com with ESMTP; 03 May 2019 16:19:19 -0700 From: "Agyeman, Prince" To: devel@edk2.groups.io Cc: Michael Kubacki , Michael D Kinney , Nate DeSimone , Liming Gao , Ankit Sinha Subject: [edk2-devel] [edk2-platforms/devel-MinPlatform] [PATCH v3 2/2] Updated the build instructions to include the python script build instructions Date: Fri, 3 May 2019 16:19:19 -0700 Message-Id: <642ca97b3e34312a292099401814a83f8c8a07fa.1556831443.git.prince.agyeman@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,prince.agyeman@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1556925560; bh=gbhxpmueomlXXU2SlkwWG8QioSwgEQ4Kt6pj3OvFpbk=; h=Cc:Date:From:Reply-To:Subject:To; b=MwPmmAs8Lx0q5/XyPDWs89lhKGEHK/in2CSfrJoqgX/FOeAmK1gN9WUtTE29pgMKWhz tJX3cb800ZUvUGLYLi22RRMyi0YE9xvCC+QbT4u5e8nTazHqvMgwUuKmtf16sR4njbpUl 6VqlJvhm4ValbpNCPmFTWOudhrUaz5lvGw4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Cc: Michael Kubacki Cc: Michael D Kinney Cc: Nate DeSimone Cc: Liming Gao Cc: Ankit Sinha Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Agyeman Reviewed-by: Michael Kubacki Reviewed-by: Nate DeSimone --- ReadMe.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index 72e332a476..fbf735173f 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -105,6 +105,82 @@ return back to the minimum platform caller. =20 ### Build =20 +**Building with the python script** + +1. Open command window, go to the workspace directory, e.g. c:\Kabylake. +2. Type "cd edk2-platforms\Platform\Intel +3. Type "python build_bios.py -p REPLACE_WITH_BOARD_NAME" + +* build_bios.py arguments: + + | Argument | Function | + | ----------------------|-------------------------------------| + | -h, --help | show this help message and exit | + | --platform, -p | the platform to build | + | --toolchain, -t | tool Chain to use in build process | + | --DEBUG, -d | debug flag | + | --RELEASE, -r | release flag | + | --TEST_RELEASE, -tr | test Release flag | + | --RELEASE_PDB, -rp | release flag | + | --list, -l | lists available platforms | + | --cleanall | cleans all | + | --clean | cleans specified platform | + | --capsule | capsule build enabled | + | --silent | silent build enabled | + | --performance | performance build enabled | + | --fsp | fsp build enabled | + | | + +* For more information on build options + * ``Type "python build_bios.py -h"`` + +* Note + * ``Python 2.7.16 and Python 3.7.3 compatible`` + * ``These python build scripts have been tested on Windows due to`` [cro= ss-platform limitations](#Known-limitations) + +* Configuration Files + * ``The edk2-platforms\Platform\Intel\build.cfg file contains the defaul= t settings used by build_bios.py`` + * ``The default settings are under the DEFAULT_CONFIG section`` + * ``Each board can have a settings file that will override the edk2-plat= forms\Platform\Intel\build.cfg settings`` + * ``An example of a board specific settings:`` + * ``edk2-platforms\Platform\Intel\KabylakeOpenBoardPkg\KabylakeRvp3\bu= ild_config.cfg`` + +* Workspace view of the build scripts + *
+    WORKSPACE
+          |------edk2
+          |------edk2-non-osi
+          |------edk2-platforms
+          |       |---Platform
+          |       |    |--Intel
+          |       |        |------build.cfg: Default build settings. These=
 are overridden by
+          |       |        |                 platform specific settings (b=
uild_config.cfg) and
+          |       |        |                 then command-line settings.
+          |       |        |
+          |       |        |------build_bios.py: Main build script. Generi=
c pre-build, build,
+          |       |        |                     post-build, and clean fun=
ctions.
+          |       |        |
+          |       |        |------ClevoOpenBoardPkg
+          |       |        |        |------N1xxWU
+          |       |        |                |---build_config.cfg: N1xxWU s=
pecific build
+          |       |        |                                      settings=
 environment variables.
+          |       |        |
+          |       |        |------KabylakeOpenBoardPkg
+          |       |        |        |------KabylakeRvp3
+          |       |        |                  |---build_config.cfg: Kabyla=
keRvp3 specific
+          |       |        |                  |                     build =
settings, environment variables.
+          |       |        |                  |---build_board.py: Optional=
 board-specific pre-build, build
+          |       |        |                                      and clea=
n post-build functions.
+          |       |        |------PurleyOpenBoardPkg
+          |       |        |       |------BoardMtOlympus
+          |       |        |                |---build_config.cfg: BoardMtO=
lympus specific
+          |       |        |                |                     build se=
ttings, environment variables.
+          |       |        |                |---build_board.py: Optional b=
oard-specific pre-build,
+          |       |        |                |                   build, pos=
t-build and clean functions.
+          |------FSP
+  
+ +**Building with the batch scripts** For KabylakeOpenBoardPkg 1. Open command window, go to the workspace directory, e.g. c:\Kabylake. 2. Type "cd edk2-platforms\Platform\Intel\KabylakeOpenBoardPkg\KabylakeRvp= 3". --=20 2.19.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#39963): https://edk2.groups.io/g/devel/message/39963 Mute This Topic: https://groups.io/mt/31489354/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-