From 2f066287f86ae7f350cf9e88e63c9ae9c85e7c2b Mon Sep 17 00:00:00 2001 From: kuqin12 <42554914+kuqin12@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:48:19 -0700 Subject: [PATCH] Adding base tool build for Linux ARM (#362) Please ensure you have read the [contribution docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior to submitting the pull request. In particular, [pull request guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices). This change added the build script to cross compile the base tool binaries for Linux ARM system. The needed libuuid system library is pulled from source file and rebuilt to support the corresponding library dependencies. Individual tools' makefiles are also updated to link the cross compiled library as well. This is the first step of https://github.com/microsoft/mu_basecore/issues/369. For each item, place an "x" in between `[` and `]` if true. Example: `[x]`. _(you can also check items in the GitHub UI)_ - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... This was tested functional on Linux ARM host system building QEMU virtual platforms (Q35 and SBSA). Update the basetool nuget version, once it is published. --- BaseTools/Source/C/DevicePath/GNUmakefile | 6 ++++++ BaseTools/Source/C/GenFv/GNUmakefile | 13 ++++++++++++- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 12 +++++++++++- BaseTools/Source/C/GenFw/GNUmakefile | 6 ++++++ BaseTools/Source/C/GenSec/GNUmakefile | 6 ++++++ BaseTools/Source/C/Makefiles/header.makefile | 12 +++++++----- 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile index f61b1b2f171..ee8e3a90582 100644 --- a/BaseTools/Source/C/DevicePath/GNUmakefile +++ b/BaseTools/Source/C/DevicePath/GNUmakefile @@ -30,6 +30,12 @@ ifeq ($(CYGWIN), CYGWIN) endif ifeq ($(LINUX), Linux) +# MU_CHANGE STARTs: Support cross compiling +ifndef CROSS_LIB_UUID LIBS += -luuid +else + LIBS += -L$(CROSS_LIB_UUID) +endif +# MU_CHANGE ENDs endif diff --git a/BaseTools/Source/C/GenFv/GNUmakefile b/BaseTools/Source/C/GenFv/GNUmakefile index 872b981f6a9..add64481b9e 100644 --- a/BaseTools/Source/C/GenFv/GNUmakefile +++ b/BaseTools/Source/C/GenFv/GNUmakefile @@ -14,6 +14,17 @@ include $(MAKEROOT)/Makefiles/app.makefile LIBS = -lCommon ifeq ($(CYGWIN), CYGWIN) - LIBS += -L/lib/e2fsprogs + LIBS += -L/lib/e2fsprogs -luuid +endif + +ifeq ($(LINUX), Linux) +# MU_CHANGE STARTs: Support cross compiling +ifndef CROSS_LIB_UUID + LIBS += -luuid +else + LIBS += -L$(CROSS_LIB_UUID) + BUILD_CFLAGS += -D__CROSS_LIB_UUID__ -I $(CROSS_LIB_UUID_INC) +endif +# MU_CHANGE ENDs endif diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index 29c3363a504..5d18f145d28 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -14,6 +14,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Include files // +#if defined(__FreeBSD__) +#include +#elif defined(__GNUC__) +// MU_CHANGE STARTs: Support cross compiling +#if !defined(__CROSS_LIB_UUID__) +#include +#else +#include +#endif +// MU_CHANGE ENDs +#endif #ifdef __GNUC__ #include #endif @@ -2286,7 +2297,6 @@ Routine Description: bSecCore |= 0x6F; //JAL opcode memcpy(FvImage->FileImage, &bSecCore, sizeof(bSecCore)); - return EFI_SUCCESS; } diff --git a/BaseTools/Source/C/GenFw/GNUmakefile b/BaseTools/Source/C/GenFw/GNUmakefile index 76cda7e7a3f..3a38d8872e4 100644 --- a/BaseTools/Source/C/GenFw/GNUmakefile +++ b/BaseTools/Source/C/GenFw/GNUmakefile @@ -18,6 +18,12 @@ ifeq ($(CYGWIN), CYGWIN) endif ifeq ($(LINUX), Linux) +# MU_CHANGE STARTs: Support cross compiling +ifndef CROSS_LIB_UUID LIBS += -luuid +else + LIBS += -L$(CROSS_LIB_UUID) +endif +# MU_CHANGE ENDs endif diff --git a/BaseTools/Source/C/GenSec/GNUmakefile b/BaseTools/Source/C/GenSec/GNUmakefile index 9f0844c1b8f..4f1949282d4 100644 --- a/BaseTools/Source/C/GenSec/GNUmakefile +++ b/BaseTools/Source/C/GenSec/GNUmakefile @@ -18,6 +18,12 @@ ifeq ($(CYGWIN), CYGWIN) endif ifeq ($(LINUX), Linux) +# MU_CHANGE STARTs: Support cross compiling +ifndef CROSS_LIB_UUID LIBS += -luuid +else + LIBS += -L$(CROSS_LIB_UUID) +endif +# MU_CHANGE ENDs endif diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile index d369908a094..dea5d6090d7 100644 --- a/BaseTools/Source/C/Makefiles/header.makefile +++ b/BaseTools/Source/C/Makefiles/header.makefile @@ -54,11 +54,13 @@ AS ?= $(CLANG_BIN)clang AR ?= $(CLANG_BIN)llvm-ar LD ?= $(CLANG_BIN)llvm-ld else ifeq ($(origin CC),default) -CC = gcc -CXX = g++ -AS = gcc -AR = ar -LD = ld +# MU_CHANGE STARTs: Support GCC prefix +CC ?= $(GCC_PREFIX)gcc +CXX ?= $(GCC_PREFIX)g++ +AS ?= $(GCC_PREFIX)gcc +AR ?= $(GCC_PREFIX)ar +LD ?= $(GCC_PREFIX)ld +# MU_CHANGE ENDs endif LINKER ?= $(CC) ifeq ($(HOST_ARCH), IA32)