Skip to content

Commit

Permalink
adding the web dep
Browse files Browse the repository at this point in the history
  • Loading branch information
kuqin12 committed Apr 25, 2023
1 parent 34db2c9 commit ad2ba98
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
24 changes: 24 additions & 0 deletions BaseTools/Bin/util_linux_ext_dep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## @file
# Download util-linux source code from Linux Kernel release site
# Set shell variable CROSS_LIB_UUID to this folder
#
# This is only downloaded when a build activates scope cross_lib_uuid for cross
# compilation process.
#
# Current version is using the version that comes with Ubuntu 20.04
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
{
"scope": "cross_lib_uuid",
"type": "web",
"name": "util-linux",
"source": "https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.34/util-linux-2.34.tar.gz",
"version": "2.34",
"compression_type": "tar",
"sha256": "b62c92e5e1629642113cd41cec1ee86d1ee7e36b8ffe8ec3ac89c11797e9ac25",
"internal_path": "/gcc-riscv-9.2.0-2020.04-x86_64_riscv64-unknown-gnu",
"flags": ["set_shell_var", ],
"var_name": "CROSS_LIB_UUID"
}
53 changes: 25 additions & 28 deletions BaseTools/Edk2ToolsBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def ParseCommandLineOptions(self):
# MU_CHANGE
self.skip_path_env = args.skip_env

def TranslateTargetArch(self, uefi_target_arch)
if uefi_target_arch == "IA32":
TargetInfoArch = "x86"
elif uefi_target_arch == "X64":
TargetInfoArch = "x86"
elif uefi_target_arch == "ARM":
TargetInfoArch = "ARM"
elif uefi_target_arch == "AARCH64":
TargetInfoArch = "ARM"
else:
raise NotImplementedError(f"Unknown architecture")

return TargetInfoArch

def GetWorkspaceRoot(self):
''' Return the workspace root for initializing the SDE '''

Expand All @@ -58,6 +72,12 @@ def GetActiveScopes(self):
scopes += ("gcc_aarch64_linux",)
if "ARM" in self.target_arch:
scopes += ("gcc_arm_linux",)

# Added logic to support cross compilation scenarios
HostInfo = GetHostInfo()
TargetInfoArch = self.TranslateTargetArch(self.target_arch)
if TargetInfoArch != HostInfo.arch:
scopes += ("cross_lib_uuid",)
return scopes
# MU_CHANGE ENDs

Expand Down Expand Up @@ -197,6 +217,7 @@ def Go(self):
TargetInfoArch = None
if self.target_arch is not None:
shell_env.set_shell_var('HOST_ARCH', self.target_arch)
TargetInfoArch = self.TranslateTargetArch(self.target_arch)

if "AARCH64" in self.target_arch:
# now check for install dir. If set then set the Prefix
Expand All @@ -205,7 +226,6 @@ def Go(self):
# make GCC5_AARCH64_PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "aarch64-none-linux-gnu-")
shell_environment.GetEnvironment().set_shell_var("GCC_PREFIX", prefix)
TargetInfoArch = "ARM"

elif "ARM" in self.target_arch:
# now check for install dir. If set then set the Prefix
Expand All @@ -214,38 +234,16 @@ def Go(self):
# make GCC5_ARM_PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "arm-none-linux-gnueabihf-")
shell_environment.GetEnvironment().set_shell_var("GCC_PREFIX", prefix)
TargetInfoArch = "ARM"

else:
TargetInfoArch = "x86"

# Otherwise, the built binary arch will be consistent with the host system

# Added logic to support cross compilation scenarios
HostInfo = GetHostInfo()
if TargetInfoArch != HostInfo.arch:
# this is defaulting to the version that comes with Ubuntu 20.04
ver = shell_environment.GetBuildVars().GetValue("LIBUUID_VERSION", "2.34")
work_dir = os.path.join(shell_env.get_shell_var("EDK_TOOLS_PATH"), self.GetLoggingFolderRelativeToRoot())
pack_name = f"util-linux-{ver}"
unzip_dir = os.path.join(work_dir, pack_name)

if os.path.isfile(os.path.join(work_dir, f"{pack_name}.tar.gz")):
os.remove(os.path.join(work_dir, f"{pack_name}.tar.gz"))
if os.path.isdir(unzip_dir):
shutil.rmtree(unzip_dir)

# cross compiling, need to rebuild libuuid for the target
ret = RunCmd("wget", f"https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v{ver}/{pack_name}.tar.gz", workingdir=work_dir)
if ret != 0:
raise Exception(f"Failed to download libuuid version {ver} - {ret}")

ret = RunCmd("tar", f"xvzf {pack_name}.tar.gz", workingdir=work_dir)
if ret != 0:
raise Exception(f"Failed to untar the downloaded file {ret}")

if TargetInfoArch is not None and TargetInfoArch != HostInfo.arch:
# configure the source to use the cross compiler
pack_name = f"util-linux-{ver}"
# TODO: Change to use the ext dep
unzip_dir = shell_environment.GetEnvironment().get_shell_var("CROSS_LIB_UUID")

if "AARCH64" in self.target_arch:
ret = RunCmd("sh", f"./configure --host=aarch64-linux -disable-all-programs --enable-libuuid CC={prefix}gcc", workingdir=unzip_dir)
elif "ARM" in self.target_arch:
Expand All @@ -257,7 +255,6 @@ def Go(self):
if ret != 0:
raise Exception(f"Failed to build the libuuid with our gcc {ret}")

shell_environment.GetEnvironment().set_shell_var("CROSS_LIB_UUID", unzip_dir)
shell_environment.GetEnvironment().set_shell_var("CROSS_LIB_UUID_INC", os.path.join(unzip_dir, "libuuid", "src"))

ret = RunCmd("make", "clean", workingdir=shell_env.get_shell_var("EDK_TOOLS_PATH"))
Expand Down

0 comments on commit ad2ba98

Please sign in to comment.