From d97f3a1d80fc4880da9726d9a5d7504d3c31da70 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Mon, 22 Jan 2024 14:41:15 -0800 Subject: [PATCH 1/6] .pytool/Plugin: UncrustifyCheck: use stat instead of os.stat The UncrustifyCheck plugin passes os.stat.S_IWRITE to os.chmod, when attempting to change file permissions. os.stat.S_IWRITE does not exist as os.stat is a function. The correct value is stat.S_IWRITE. Signed-off-by: Joey Vagedes Cc: Liming Gao Cc: Michael D Kinney Cc: Sean Brogan Reviewed-by: Michael D Kinney --- .pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py index 9aeef5a5a3..73dc03c0dc 100644 --- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py +++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py @@ -12,6 +12,7 @@ import os import pathlib import shutil +import stat import timeit from edk2toolext.environment import version_aggregator from edk2toolext.environment.plugin_manager import PluginManager @@ -628,7 +629,7 @@ def _remove_readonly(func, path, _): """ Private function to attempt to change permissions on file/folder being deleted. """ - os.chmod(path, os.stat.S_IWRITE) + os.chmod(path, stat.S_IWRITE) func(path) for _ in range(3): # retry up to 3 times From 2ddae5df31789853040f4c5261bb85e2f010c4a7 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Mon, 22 Jan 2024 09:31:41 +0700 Subject: [PATCH 2/6] StandaloneMmPkg/Core: Remove optimization for depex evaluation The current dependency evaluator violates the memory access permission when patching depex grammar directly in the read-only depex memory area. Laszlo pointed out the optimization issue in the thread (1) "Memory Attribute for depex section" and provided suggested patch to remove the perf optimization. In my testing, removing the optimization does not make significant perf reduction. That makes sense that StandaloneMM dispatcher only searches in MM protocol database and does not depend on UEFI/DXE protocol database. Also, we don't have many protocols in StandaloneMM like UEFI/DXE. From Laszlo, "The patch removes the EFI_DEP_REPLACE_TRUE handling altogether, plus it CONST-ifies the Iterator pointer (which points into the DEPEX section), so that the compiler catch any possible accesses at *build time* that would write to the write-protected DEPEX memory area." (1) https://edk2.groups.io/g/devel/message/113531 Signed-off-by: Nhi Pham Tested-by: levi.yun Reviewed-by: levi.yun Reviewed-by: Ray Ni --- StandaloneMmPkg/Core/Dependency.c | 37 ++++++------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/StandaloneMmPkg/Core/Dependency.c b/StandaloneMmPkg/Core/Dependency.c index 440fe3e452..2bcb07d346 100644 --- a/StandaloneMmPkg/Core/Dependency.c +++ b/StandaloneMmPkg/Core/Dependency.c @@ -13,16 +13,6 @@ #include "StandaloneMmCore.h" -/// -/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expression -/// to save time. A EFI_DEP_PUSH is evaluated one an -/// replaced with EFI_DEP_REPLACE_TRUE. If PI spec's Vol 2 -/// Driver Execution Environment Core Interface use 0xff -/// as new DEPEX opcode. EFI_DEP_REPLACE_TRUE should be -/// defined to a new value that is not conflicting with PI spec. -/// -#define EFI_DEP_REPLACE_TRUE 0xff - /// /// Define the initial size of the dependency expression evaluation stack /// @@ -170,12 +160,12 @@ MmIsSchedulable ( IN EFI_MM_DRIVER_ENTRY *DriverEntry ) { - EFI_STATUS Status; - UINT8 *Iterator; - BOOLEAN Operator; - BOOLEAN Operator2; - EFI_GUID DriverGuid; - VOID *Interface; + EFI_STATUS Status; + CONST UINT8 *Iterator; + BOOLEAN Operator; + BOOLEAN Operator2; + EFI_GUID DriverGuid; + VOID *Interface; Operator = FALSE; Operator2 = FALSE; @@ -253,8 +243,7 @@ MmIsSchedulable ( Status = PushBool (FALSE); } else { DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid)); - *Iterator = EFI_DEP_REPLACE_TRUE; - Status = PushBool (TRUE); + Status = PushBool (TRUE); } if (EFI_ERROR (Status)) { @@ -356,18 +345,6 @@ MmIsSchedulable ( DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE")); return Operator; - case EFI_DEP_REPLACE_TRUE: - CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); - DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid)); - Status = PushBool (TRUE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Iterator += sizeof (EFI_GUID); - break; - default: DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n")); goto Done; From 417ebe6d1d6052b6cf023332da07558363d7fd08 Mon Sep 17 00:00:00 2001 From: Suqiang Ren Date: Mon, 22 Jan 2024 23:02:36 -0800 Subject: [PATCH 3/6] MdePkg/Include/Guid: Update the definition of FileName in EFI_FILE_INFO Add the description of EFI_FILE_INFO FileName[1] field to align with UEFI spec 2.10 Section 13.5.16. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Suqiang Ren Reviewed-by: Michael D Kinney --- MdePkg/Include/Guid/FileInfo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/MdePkg/Include/Guid/FileInfo.h b/MdePkg/Include/Guid/FileInfo.h index 2b7edf36aa..71bb289e12 100644 --- a/MdePkg/Include/Guid/FileInfo.h +++ b/MdePkg/Include/Guid/FileInfo.h @@ -47,6 +47,7 @@ typedef struct { UINT64 Attribute; /// /// The Null-terminated name of the file. + /// For a root directory, the name is an empty string. /// CHAR16 FileName[1]; } EFI_FILE_INFO; From 7f72c2829fa29d2b4451c9a60e904df4c6a5df6c Mon Sep 17 00:00:00 2001 From: "devel@edk2.groups.io" Date: Tue, 23 Jan 2024 03:36:49 -0800 Subject: [PATCH 4/6] MdePkg/Library/BaseCpuLibNull: Add StandardSignatureIsAuthenticAMD() CpuLib.h exposes StandardSignatureIsAuthenticAMD() API and we require stub function in its BaseCpuLibNull library instance to avoid potential link issue. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Qing Huang Reviewed-by: Michael D Kinney --- MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.c b/MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.c index 3ba7a35096..3542cf6921 100644 --- a/MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.c +++ b/MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.c @@ -35,3 +35,18 @@ CpuFlushTlb ( ) { } + +/** + Determine if the standard CPU signature is "AuthenticAMD". + + @retval TRUE The CPU signature matches. + @retval FALSE The CPU signature does not match. +**/ +BOOLEAN +EFIAPI +StandardSignatureIsAuthenticAMD ( + VOID + ) +{ + return FALSE; +} From 1063665fa5466ece0814a3e764ee3382656956a1 Mon Sep 17 00:00:00 2001 From: Ashish Singhal Date: Wed, 6 Dec 2023 16:52:47 -0700 Subject: [PATCH 5/6] MdeModulePkg/ResetSystemRuntimeDxe: Print Reset Data ResetSystem runtime call allows for sending reset data that starts with a NULL terminated string. Add support to print that string on console. Signed-off-by: Ashish Singhal Reviewed-by: Zhichao Gao --- .../Universal/ResetSystemRuntimeDxe/ResetSystem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c b/MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c index 42f1b1d015..72bb1d2be6 100644 --- a/MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c +++ b/MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c @@ -252,6 +252,14 @@ RuntimeServiceResetSystem ( mResetNotifyDepth )); + if ((ResetData != NULL) && (DataSize != 0)) { + DEBUG (( + DEBUG_INFO, + "DXE ResetSystem2: ResetData: %s\n", + ResetData + )); + } + if (mResetNotifyDepth <= MAX_RESET_NOTIFY_DEPTH) { if (!EfiAtRuntime ()) { // From b81f9d4b17b162682f4df11c08dad9c83eb2c78f Mon Sep 17 00:00:00 2001 From: Jeff Brasen Date: Mon, 20 Nov 2023 23:40:42 +0000 Subject: [PATCH 6/6] MdePkg: Add FdtLib gmock support Add Google Mock Library for FdtLib Jira TEGRAUEFI-3105 Signed-off-by: Jeff Brasen Change-Id: I96b74688b50ff555ca77b58f239ecc0f493cb118 --- MdePkg/Test/MdePkgHostTest.dsc | 1 + .../Include/GoogleTest/Library/MockFdtLib.h | 164 ++++++++++++++++++ .../GoogleTest/MockFdtLib/MockFdtLib.cpp | 34 ++++ .../GoogleTest/MockFdtLib/MockFdtLib.inf | 28 +++ 4 files changed, 227 insertions(+) create mode 100644 MdePkg/Test/Mock/Include/GoogleTest/Library/MockFdtLib.h create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.cpp create mode 100644 MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc index 583f8fc0dd..e666636b7c 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -45,3 +45,4 @@ MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf + MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockFdtLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockFdtLib.h new file mode 100644 index 0000000000..5b21b232b7 --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockFdtLib.h @@ -0,0 +1,164 @@ +/** @file + Google Test mocks for FdtLib + + Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MOCK_FDT_LIB_H_ +#define MOCK_FDT_LIB_H_ + +#include +#include +extern "C" { + #include + #include +} + +struct MockFdtLib { + MOCK_INTERFACE_DECLARATION (MockFdtLib); + + MOCK_FUNCTION_DECLARATION ( + UINT16, + Fdt16ToCpu, + (IN UINT16 Value) + ); + MOCK_FUNCTION_DECLARATION ( + UINT16, + CpuToFdt16, + (IN UINT16 Value) + ); + MOCK_FUNCTION_DECLARATION ( + UINT32, + Fdt32ToCpu, + (IN UINT32 Value) + ); + MOCK_FUNCTION_DECLARATION ( + UINT32, + CpuToFdt32, + (IN UINT32 Value) + ); + MOCK_FUNCTION_DECLARATION ( + UINT64, + Fdt64ToCpu, + (IN UINT64 Value) + ); + MOCK_FUNCTION_DECLARATION ( + UINT64, + CpuToFdt64, + (IN UINT64 Value) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtCheckHeader, + (IN CONST VOID *Fdt) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtCreateEmptyTree, + (IN VOID *Buffer, + IN UINT32 BufferSize) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtNextNode, + (IN CONST VOID *Fdt, + IN INT32 Offset, + IN INT32 *Depth) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtFirstSubnode, + (IN CONST VOID *Fdt, + IN INT32 Offset) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtNextSubnode, + (IN CONST VOID *Fdt, + IN INT32 Offset) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtSubnodeOffsetNameLen, + (IN CONST VOID *Fdt, + IN INT32 ParentOffset, + IN CONST CHAR8 *Name, + IN INT32 NameLength) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtNodeOffsetByPropValue, + (IN CONST VOID *Fdt, + IN INT32 StartOffset, + IN CONST CHAR8 *PropertyName, + IN CONST VOID *PropertyValue, + IN INT32 PropertyLength) + ); + MOCK_FUNCTION_DECLARATION ( + CONST FDT_PROPERTY *, + FdtGetProperty, + (IN CONST VOID *Fdt, + IN INT32 NodeOffset, + IN CONST CHAR8 *Name, + IN INT32 *Length) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtFirstPropertyOffset, + (IN CONST VOID *Fdt, + IN INT32 NodeOffset) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtNextPropertyOffset, + (IN CONST VOID *Fdt, + IN INT32 NodeOffset) + ); + MOCK_FUNCTION_DECLARATION ( + CONST FDT_PROPERTY *, + FdtGetPropertyByOffset, + (IN CONST VOID *Fdt, + IN INT32 Offset, + IN INT32 *Length) + ); + MOCK_FUNCTION_DECLARATION ( + CONST CHAR8 *, + FdtGetString, + (IN CONST VOID *Fdt, + IN INT32 StrOffset, + IN INT32 *Length OPTIONAL) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtAddSubnode, + (IN VOID *Fdt, + IN INT32 ParentOffset, + IN CONST CHAR8 *Name) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtSetProp, + (IN VOID *Fdt, + IN INT32 NodeOffset, + IN CONST CHAR8 *Name, + IN CONST VOID *Value, + IN UINT32 Length) + ); + MOCK_FUNCTION_DECLARATION ( + CONST CHAR8 *, + FdtGetName, + (IN VOID *Fdt, + IN INT32 NodeOffset, + IN INT32 *Length) + ); + MOCK_FUNCTION_DECLARATION ( + INT32, + FdtNodeDepth, + (IN CONST VOID *Fdt, + IN INT32 NodeOffset) + ); +}; + +#endif diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.cpp new file mode 100644 index 0000000000..a955780d23 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.cpp @@ -0,0 +1,34 @@ +/** @file + Google Test mocks for FdtLib + + Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +MOCK_INTERFACE_DEFINITION (MockFdtLib); + +MOCK_FUNCTION_DEFINITION (MockFdtLib, Fdt16ToCpu, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, CpuToFdt16, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, Fdt32ToCpu, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, CpuToFdt32, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, Fdt64ToCpu, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, CpuToFdt64, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtCheckHeader, 1, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtCreateEmptyTree, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtNextNode, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtFirstSubnode, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtNextSubnode, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtSubnodeOffsetNameLen, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtNodeOffsetByPropValue, 5, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtGetProperty, 4, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtFirstPropertyOffset, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtNextPropertyOffset, 2, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtGetPropertyByOffset, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtGetString, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtAddSubnode, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtSetProp, 5, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtGetName, 3, EFIAPI); +MOCK_FUNCTION_DEFINITION (MockFdtLib, FdtNodeDepth, 2, EFIAPI); diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf b/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf new file mode 100644 index 0000000000..b227bcbae9 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf @@ -0,0 +1,28 @@ +## @file +# Google Test mocks for FdtLib +# +# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2023, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = MockFdtLib + FILE_GUID = 0f5471bc-fc2c-4cf4-b9f7-c1396d32831c + MODULE_TYPE = HOST_APPLICATION + VERSION_STRING = 1.0 + LIBRARY_CLASS = FdtLib + +[Sources] + MockFdtLib.cpp + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + +[BuildOptions] + MSFT:*_*_*_CC_FLAGS = /EHsc /bigobj