edk2-firmware-tegra: fixes and reproducibility improvements

* Apply the inclusion of the NVIDIA-specific tools definitions when
  the Conf directory is populated, rather than trying to pass LZMA_FLAGS
  on the build command line (which doesn't work)

* Update the compiler and linker flags to allow us to pass the DEBUG_PREFIX_MAP
  flags in via an environment variable. This doesn't completely solve the build-paths
  embedding problem, but gets us closer.

* Pass the SOURCE_DATE_EPOCH in as a compilation flag, rather than having the
  generated makefiles for NVIDIA's RTC drivers call on the 'date' command during
  the build to get a suitable build epoch.

Signed-off-by: Matt Madison <matt@madison.systems>
This commit is contained in:
Matt Madison
2024-05-20 11:32:09 -07:00
parent a4f7ed44eb
commit ed154b3183
5 changed files with 133 additions and 11 deletions

View File

@@ -31,8 +31,11 @@ SRC_URI += "\
SRCREV_FORMAT = "edk2_edk2-platforms_edk2-non-osi_edk2-nvidia_edk2-nvidia-non-osi" SRCREV_FORMAT = "edk2_edk2-platforms_edk2-non-osi_edk2-nvidia_edk2-nvidia-non-osi"
# edk2-nvidia SRC_URI += "\
SRC_URI += "file://0003-L4TLauncher-allow-for-empty-missing-APPEND-line-in-e.patch;patchdir=../edk2-nvidia" file://0001-Update-tools_def.template-for-toolchain-differences.patch \
file://0002-L4TLauncher-allow-for-empty-missing-APPEND-line-in-e.patch;patchdir=../edk2-nvidia \
file://0003-Remove-BUILD_EPOCH-definitions-from-RTC-inf-files.patch;patchdir=../edk2-nvidia \
"
S = "${WORKDIR}/edk2-tegra/edk2" S = "${WORKDIR}/edk2-tegra/edk2"
@@ -40,6 +43,26 @@ COMPATIBLE_MACHINE = "(tegra)"
S_EDK2_NVIDIA = "${@os.path.normpath(os.path.join(d.getVar('S'), '../edk2-nvidia'))}" S_EDK2_NVIDIA = "${@os.path.normpath(os.path.join(d.getVar('S'), '../edk2-nvidia'))}"
# A bit of a hack here... S is the 'edk2' subtree, and all of the other
# subtrees are prefixed 'edk2', and this happens to work out nicely for
# the debug prefix mapping if we just put 'edk2' as last component of
# TARGET_DBGSRC_DIR.
TARGET_DBGSRC_DIR = "/usr/src/debug/${PN}/${PV}/edk2"
export DEBUG_PREFIX_MAP
# We've patched the tools_def template to pick ths flag up from the
# environment, so we don't end up with `date` commands inserted into
# makefiles for setting the RTC epoch.
export SOURCE_DATE_EPOCH_FLAG = "-DBUILD_EPOCH=${SOURCE_DATE_EPOCH}"
# NVIDIA has some additional tools_def definitions, which get added
# like this as part of the stuart build setup.
apply_tools_def_updates() {
if [ -e ${S_EDK2_NVIDIA}/Silicon/NVIDIA/tools_def.inc ]; then
echo "!include Silicon/NVIDIA/tools_def.inc" >> ${S}/Conf/tools_def.txt
fi
}
# derived from edk2-nvidia/Silicon/NVIDIA/edk2nv/stuart/settings.py # derived from edk2-nvidia/Silicon/NVIDIA/edk2nv/stuart/settings.py
def nvidia_edk2_packages_path(d): def nvidia_edk2_packages_path(d):
paths = ':'.join([os.path.normpath(os.path.join(d.getVar('S'), '../{}'.format(m))) for m in ['edk2/BaseTools', 'edk2', 'edk2-platforms', 'edk2-nvidia', paths = ':'.join([os.path.normpath(os.path.join(d.getVar('S'), '../{}'.format(m))) for m in ['edk2/BaseTools', 'edk2', 'edk2-platforms', 'edk2-nvidia',
@@ -55,9 +78,8 @@ PACKAGES_PATH = "${@nvidia_edk2_packages_path(d)}"
# BUILD_* taken from Silicon/NVIDIA/edk2nv/stuart/settings.py and # BUILD_* taken from Silicon/NVIDIA/edk2nv/stuart/settings.py and
# builder.py, plus Platform/NVIDIA/Jetson/PlatformBuild.py # builder.py, plus Platform/NVIDIA/Jetson/PlatformBuild.py
# LZMA_FLAGS taken from Silicon/NVIDIA/tools_def.inc EDK2_EXTRA_BUILD = '-D "BUILDID_STRING=v${PV}" -D "BUILD_DATE_TIME=${@format_build_date(d)}" -D "BUILD_PROJECT_TYPE=EDK2" \
EDK2_EXTRA_BUILD = '-D "BUILDID_STRING=v${PV}" -D "BUILD_DATE_TIME=${@format_build_date(d)}" -D "BUILD_PROJECT_TYPE=EDK2" -D "GENFW_FLAGS=--zero" \ -D BUILD_GUID=49a79a15-8f69-4be7-a30c-a172f44abce7 -DBUILD_NAME=Jetson'
-D BUILD_GUID=b175f7b7-0cb0-446e-b338-0e0d0f688de8 -D "LZMA_FLAGS=d 27" -DBUILD_NAME=Jetson'
def format_build_date(d): def format_build_date(d):
import datetime import datetime

View File

@@ -92,6 +92,10 @@ do_configure:prepend() {
sed -i -e "s#-target ${HOST_ARCH}-linux-gnu.*#-target ${HOST_SYS}#" ${S}/BaseTools/Conf/tools_def.template sed -i -e "s#-target ${HOST_ARCH}-linux-gnu.*#-target ${HOST_SYS}#" ${S}/BaseTools/Conf/tools_def.template
} }
apply_tools_def_updates() {
:
}
do_compile() { do_compile() {
sed -i -e 's:-I \.\.:-I \.\. ${BUILD_CFLAGS} :' ${EDK_TOOLS_PATH}/Source/C/Makefiles/header.makefile sed -i -e 's:-I \.\.:-I \.\. ${BUILD_CFLAGS} :' ${EDK_TOOLS_PATH}/Source/C/Makefiles/header.makefile
sed -i -e 's: -luuid: -luuid ${BUILD_LDFLAGS}:g' ${EDK_TOOLS_PATH}/Source/C/*/GNUmakefile sed -i -e 's: -luuid: -luuid ${BUILD_LDFLAGS}:g' ${EDK_TOOLS_PATH}/Source/C/*/GNUmakefile
@@ -100,6 +104,7 @@ do_compile() {
cp ${EDK_TOOLS_PATH}/Conf/build_rule.template ${S}/Conf/build_rule.txt cp ${EDK_TOOLS_PATH}/Conf/build_rule.template ${S}/Conf/build_rule.txt
cp ${EDK_TOOLS_PATH}/Conf/tools_def.template ${S}/Conf/tools_def.txt cp ${EDK_TOOLS_PATH}/Conf/tools_def.template ${S}/Conf/tools_def.txt
cp ${EDK_TOOLS_PATH}/Conf/target.template ${S}/Conf/target.txt cp ${EDK_TOOLS_PATH}/Conf/target.template ${S}/Conf/target.txt
apply_tools_def_updates
# Build basetools # Build basetools
oe_runmake -C ${S}/BaseTools oe_runmake -C ${S}/BaseTools

View File

@@ -0,0 +1,49 @@
From 3c436fd0ec658b315edac10a170093f32b73754b Mon Sep 17 00:00:00 2001
From: Matt Madison <matt@madison.systems>
Date: Mon, 20 May 2024 10:59:27 -0700
Subject: [PATCH] Update tools_def.template for toolchain differences
* Add support for passing SOURCE_DATE_EPOCH and DEBUG_PREFIX_MAP from environment
* Add linker flags that are built into the toolchain NVIDIA uses for ther builds
Upstream-Status: Pending
Signed-off-by: Matt Madison <matt@madison.systems>
---
BaseTools/Conf/tools_def.template | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 1395ce9ad0..a41189ba1b 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -739,7 +739,7 @@ NOOPT_*_*_OBJCOPY_ADDDEBUGFLAG = --add-gnu-debuglink="$(DEBUG_DIR)/$(MODULE_
*_*_*_DTCPP_PATH = DEF(DTCPP_BIN)
*_*_*_DTC_PATH = DEF(DTC_BIN)
-DEFINE GCC_ALL_CC_FLAGS = -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common
+DEFINE GCC_ALL_CC_FLAGS = -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common ENV(DEBUG_PREFIX_MAP) ENV(SOURCE_DATE_EPOCH_FLAG)
DEFINE GCC_ARM_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -fno-pic -fno-pie
DEFINE GCC_LOONGARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mabi=lp64d -fno-asynchronous-unwind-tables -fno-plt -Wno-address -fno-short-enums -fsigned-char -ffunction-sections -fdata-sections
DEFINE GCC_ARM_CC_XIPFLAGS = -mno-unaligned-access
@@ -749,7 +749,7 @@ DEFINE GCC_RISCV64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
DEFINE GCC_DLINK_FLAGS_COMMON = -nostdlib --pie
DEFINE GCC_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE GCC_IA32_X64_DLINK_COMMON = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
-DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
+DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map -Wl,-z,relro,-z,now,--as-needed,--hash-style=gnu ENV(DEBUG_PREFIX_MAP)
DEFINE GCC_LOONGARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20 -Wl,--pic-veneer
DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
@@ -789,7 +789,7 @@ DEFINE GCC48_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_FLAGS) -Wl,-melf
DEFINE GCC48_X64_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 DEF(GCC_DLINK2_FLAGS_COMMON)
DEFINE GCC48_ASM_FLAGS = DEF(GCC_ASM_FLAGS)
DEFINE GCC48_ARM_ASM_FLAGS = $(PLATFORM_FLAGS) DEF(GCC_ASM_FLAGS) -mlittle-endian
-DEFINE GCC48_AARCH64_ASM_FLAGS = $(PLATFORM_FLAGS) DEF(GCC_ASM_FLAGS) -mlittle-endian
+DEFINE GCC48_AARCH64_ASM_FLAGS = $(PLATFORM_FLAGS) DEF(GCC_ASM_FLAGS) -mlittle-endian ENV(DEBUG_PREFIX_MAP)
DEFINE GCC48_ARM_CC_FLAGS = $(PLATFORM_FLAGS) DEF(GCC_ARM_CC_FLAGS) -fstack-protector -mword-relocations
DEFINE GCC48_ARM_CC_XIPFLAGS = DEF(GCC_ARM_CC_XIPFLAGS)
DEFINE GCC48_AARCH64_CC_FLAGS = $(PLATFORM_FLAGS) -mcmodel=large DEF(GCC_AARCH64_CC_FLAGS)
--
2.34.1

View File

@@ -1,7 +1,7 @@
From 9e77fe4f3a34eda6d131e33f9a5f11fbaa34d423 Mon Sep 17 00:00:00 2001 From 12f67e4724a2e44659a08a64e01b9eafcd992241 Mon Sep 17 00:00:00 2001
From: Matt Madison <matt@madison.systems> From: Matt Madison <matt@madison.systems>
Date: Sat, 4 Feb 2023 06:31:24 -0800 Date: Sat, 4 Feb 2023 06:31:24 -0800
Subject: [PATCH 3/4] L4TLauncher: allow for empty/missing APPEND line in Subject: [PATCH 2/3] L4TLauncher: allow for empty/missing APPEND line in
extlinux.conf extlinux.conf
Signed-off-by: Matt Madison <matt@madison.systems> Signed-off-by: Matt Madison <matt@madison.systems>
@@ -10,10 +10,10 @@ Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io>
.../Application/L4TLauncher/L4TLauncher.c | 30 ++++++++++--------- .../Application/L4TLauncher/L4TLauncher.c | 30 ++++++++++---------
1 file changed, 16 insertions(+), 14 deletions(-) 1 file changed, 16 insertions(+), 14 deletions(-)
Index: edk2-nvidia/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c diff --git a/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c b/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c
=================================================================== index ab86f3e0..3be26f82 100644
--- edk2-nvidia.orig/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c --- a/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c
+++ edk2-nvidia/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c +++ b/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c
@@ -1422,21 +1422,23 @@ ExtLinuxBoot ( @@ -1422,21 +1422,23 @@ ExtLinuxBoot (
CHAR8 SWModule[] = "kernel"; CHAR8 SWModule[] = "kernel";
INTN FdtStatus; INTN FdtStatus;
@@ -52,3 +52,6 @@ Index: edk2-nvidia/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c
} }
} }
} }
--
2.34.1

View File

@@ -0,0 +1,43 @@
From fe0b1d149762eab19bdd3a8018afdf190364ddf3 Mon Sep 17 00:00:00 2001
From: Matt Madison <matt@madison.systems>
Date: Mon, 20 May 2024 11:09:38 -0700
Subject: [PATCH 3/3] Remove BUILD_EPOCH definitions from RTC inf files
as we will pass that flag to all compilations via an environment variable.
Upstream-Status: Inappropriate [OE specific]
Signed-off-by: Matt Madison <matt@madison.systems>
---
.../Library/MaximRealTimeClockLib/MaximRealTimeClockLib.inf | 4 ----
.../NuvotonRealTimeClockLib/NuvotonRealTimeClockLib.inf | 5 -----
2 files changed, 9 deletions(-)
diff --git a/Silicon/NVIDIA/Library/MaximRealTimeClockLib/MaximRealTimeClockLib.inf b/Silicon/NVIDIA/Library/MaximRealTimeClockLib/MaximRealTimeClockLib.inf
index 4a69ad62..64e76bee 100644
--- a/Silicon/NVIDIA/Library/MaximRealTimeClockLib/MaximRealTimeClockLib.inf
+++ b/Silicon/NVIDIA/Library/MaximRealTimeClockLib/MaximRealTimeClockLib.inf
@@ -52,7 +52,3 @@
gEfiVariableArchProtocolGuid
AND
gEfiVariableWriteArchProtocolGuid
-
-# Current usage of this library expects GCC in a UNIX-like shell environment with the date command
-[BuildOptions]
- GCC:*_*_*_CC_FLAGS = -DBUILD_EPOCH=`date +%s`
diff --git a/Silicon/NVIDIA/Library/NuvotonRealTimeClockLib/NuvotonRealTimeClockLib.inf b/Silicon/NVIDIA/Library/NuvotonRealTimeClockLib/NuvotonRealTimeClockLib.inf
index db01f928..f444c2b8 100644
--- a/Silicon/NVIDIA/Library/NuvotonRealTimeClockLib/NuvotonRealTimeClockLib.inf
+++ b/Silicon/NVIDIA/Library/NuvotonRealTimeClockLib/NuvotonRealTimeClockLib.inf
@@ -52,8 +52,3 @@
gEfiVariableArchProtocolGuid
AND
gEfiVariableWriteArchProtocolGuid
-
-# Current usage of this library expects GCC in a UNIX-like shell environment with the date command
-# BUILD_EPOCH will be used as the reference date/time needed for Virtual RTC feature.
-[BuildOptions]
- GCC:*_*_*_CC_FLAGS = -DBUILD_EPOCH=`date +%s`
--
2.34.1