public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 1/2] BoardModulePkg: Copy device path before processing
       [not found] <cover.1674047008.git.abdattar@amd.com>
@ 2023-01-18 13:04 ` Abdul Lateef Attar
  2023-01-18 13:04 ` [PATCH v3 2/2] BoardModulePkg: Adds PCD to load UEFI Shell image Abdul Lateef Attar
  1 sibling, 0 replies; 2+ messages in thread
From: Abdul Lateef Attar @ 2023-01-18 13:04 UTC (permalink / raw)
  To: devel; +Cc: Abdul Lateef Attar, Oram Isaac W, Eric Dong, Liming Gao

GCC compiler puts the DevicePath PCDs to the read-only
section. During boot if try to process the device path
after PtrGetPtr it throws a page fault exception.

Hence making a local copy using DuplicateDevicePath()
to avoid the page fault exception.

Cc: Oram Isaac W <isaac.w.oram@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Abdul Lateef Attar <abdattar@amd.com>
---
 .../Library/BoardBdsHookLib/BoardBdsHookLib.c | 24 +++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
index 0bcee7c9a4ba..e866f70bc336 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
@@ -3,6 +3,7 @@
   implementation instance of the BDS hook library
 
   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -131,7 +132,7 @@ IsTrustedConsole (
 
   switch (ConsoleType) {
     case ConIn:
-      TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
+      TrustedConsoleDevicepath = DuplicateDevicePath (PcdGetPtr (PcdTrustedConsoleInputDevicePath));
       break;
     case ConOut:
       //
@@ -147,7 +148,7 @@ IsTrustedConsole (
         TempDevicePath = NextDevicePathNode (TempDevicePath);
       }
 
-      TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
+      TrustedConsoleDevicepath = DuplicateDevicePath (PcdGetPtr (PcdTrustedConsoleOutputDevicePath));
       break;
     default:
       ASSERT (FALSE);
@@ -164,6 +165,9 @@ IsTrustedConsole (
     if (CompareMem (ConsoleDevice, Instance, Size - END_DEVICE_PATH_LENGTH) == 0) {
       FreePool (Instance);
       FreePool (ConsoleDevice);
+      if (TempDevicePath != NULL) {
+        FreePool (TempDevicePath);
+      }
       return TRUE;
     }
 
@@ -171,7 +175,9 @@ IsTrustedConsole (
   } while (TempDevicePath != NULL);
 
   FreePool (ConsoleDevice);
-
+  if (TempDevicePath != NULL) {
+    FreePool (TempDevicePath);
+  }
   return FALSE;
 }
 
@@ -624,7 +630,7 @@ ConnectTrustedStorage (
   EFI_STATUS                Status;
   EFI_HANDLE                DeviceHandle;
 
-  TrustedStorageDevicepath = PcdGetPtr (PcdTrustedStorageDevicePath);
+  TrustedStorageDevicepath = DuplicateDevicePath (PcdGetPtr (PcdTrustedStorageDevicePath));
   DumpDevicePath (L"TrustedStorage", TrustedStorageDevicepath);
 
   TempDevicePath = TrustedStorageDevicepath;
@@ -649,6 +655,10 @@ ConnectTrustedStorage (
 
     FreePool (Instance);
   } while (TempDevicePath != NULL);
+
+  if (TempDevicePath != NULL) {
+    FreePool (TempDevicePath);
+  }
 }
 
 
@@ -1031,7 +1041,7 @@ AddConsoleVariable (
   EFI_HANDLE                GraphicsControllerHandle;
   EFI_DEVICE_PATH           *GopDevicePath;
 
-  TempDevicePath = ConsoleDevicePath;
+  TempDevicePath = DuplicateDevicePath (ConsoleDevicePath);
   do {
     Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
     if (Instance == NULL) {
@@ -1074,6 +1084,10 @@ AddConsoleVariable (
 
     FreePool (Instance);
   } while (TempDevicePath != NULL);
+
+  if (TempDevicePath != NULL) {
+    FreePool (TempDevicePath);
+  }
 }
 
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v3 2/2] BoardModulePkg: Adds PCD to load UEFI Shell image
       [not found] <cover.1674047008.git.abdattar@amd.com>
  2023-01-18 13:04 ` [PATCH v3 1/2] BoardModulePkg: Copy device path before processing Abdul Lateef Attar
@ 2023-01-18 13:04 ` Abdul Lateef Attar
  1 sibling, 0 replies; 2+ messages in thread
From: Abdul Lateef Attar @ 2023-01-18 13:04 UTC (permalink / raw)
  To: devel; +Cc: Abdul Lateef Attar, Oram Isaac W, Eric Dong, Liming Gao

From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>

defines two PCDs, PcdShellFile and PcdShellFileDesc,
which holds the GUID and description of the UEFI shell file to be loaded.

A PCDs based solution gives flexibility to the user to load different
images, by just overriding the DSC file.

The user can load a diagnostic image or test image during
PCDBootToShellOnly or later stages.

Cc: Oram Isaac W <isaac.w.oram@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
 .../Intel/MinPlatformPkg/MinPlatformPkg.dec   |  5 ++++
 .../BoardBdsHookLib/BoardBdsHookLib.inf       |  3 ++
 .../Library/BoardBdsHookLib/BoardBootOption.c | 29 +++++++++----------
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec
index 2953e9527224..e6f714b1816f 100644
--- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec
+++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec
@@ -7,6 +7,7 @@
 # for the build infrastructure.
 #
 # Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -266,6 +267,10 @@ [PcdsFixedAtBuild, PcdsPatchableInModule]
   gMinPlatformPkgTokenSpaceGuid.PcdFlashFvFspUSize|0x00000000|UINT32|0x2000002B
   gMinPlatformPkgTokenSpaceGuid.PcdFlashFvFspUOffset|0x00000000|UINT32|0x2000002C
 
+  # GUID of Shell file to be loaded, default value is gUefiShellFileGuid define in ShellPkg.dec
+  gMinPlatformPkgTokenSpaceGuid.PcdShellFile|{GUID({0x7c04a583, 0x9e3e, 0x4f1c, {0xad, 0x65, 0xe0, 0x52, 0x68, 0xd0, 0xb4, 0xd1}})}|VOID*|0x20000230
+  gMinPlatformPkgTokenSpaceGuid.PcdShellFileDesc|L"Internal UEFI Shell 2.0"|VOID*|0x20000231
+
 [PcdsDynamic, PcdsDynamicEx]
   gMinPlatformPkgTokenSpaceGuid.PcdPcIoApicEnable|0x0|UINT32|0x90000019
   gMinPlatformPkgTokenSpaceGuid.PcdAcpiSleepControlRegisterAddressSpaceId|0x00|UINT8|0x0001004B
diff --git a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.inf b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.inf
index 69f3fcb55222..7a1dbe62eafd 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.inf
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.inf
@@ -2,6 +2,7 @@
 # Module Information file for the Bds Hook Library.
 #
 # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -59,6 +60,8 @@ [Pcd]
   gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleInputDevicePath    ## CONSUMES
   gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleOutputDevicePath   ## CONSUMES
   gMinPlatformPkgTokenSpaceGuid.PcdTrustedStorageDevicePath         ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdShellFile                        ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdShellFileDesc                    ## CONSUMES
 
 [Sources]
   BoardBdsHook.h
diff --git a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBootOption.c b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBootOption.c
index dec3ce93ef71..05b9fa7ac682 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBootOption.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBootOption.c
@@ -2,12 +2,23 @@
   Driver for Platform Boot Options support.
 
 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
 #include "BoardBdsHook.h"
 
+EFI_GUID gUefiShellFileGuid = {0};
+#define UEFI_HARD_DRIVE_NAME          L"UEFI Hard Drive"
+EFI_GUID mUiFile = {
+  0x462CAA21, 0x7614, 0x4503, { 0x83, 0x6E, 0x8A, 0xB6, 0xF4, 0x66, 0x23, 0x31 }
+};
+EFI_GUID mBootMenuFile = {
+  0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
+};
+
 BOOLEAN    mContinueBoot  = FALSE;
 BOOLEAN    mBootMenuBoot  = FALSE;
 BOOLEAN    mPxeBoot       = FALSE;
@@ -186,14 +197,6 @@ CreateFvBootOption (
   return Status;
 }
 
-EFI_GUID mUiFile = {
-  0x462CAA21, 0x7614, 0x4503, { 0x83, 0x6E, 0x8A, 0xB6, 0xF4, 0x66, 0x23, 0x31 }
-};
-EFI_GUID mBootMenuFile = {
-  0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }
-};
-
-
 /**
   Return the index of the load option in the load option array.
 
@@ -333,11 +336,6 @@ PlatformBootManagerWaitCallback (
 }
 
 
-EFI_GUID gUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, { 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } };
-
-#define INTERNAL_UEFI_SHELL_NAME      L"Internal UEFI Shell 2.0"
-#define UEFI_HARD_DRIVE_NAME          L"UEFI Hard Drive"
-
 /**
    Registers default boot option
 **/
@@ -352,7 +350,8 @@ RegisterDefaultBootOption (
 
     ShellData = NULL;
     ShellDataSize = 0;
-    RegisterFvBootOption (&gUefiShellFileGuid,      INTERNAL_UEFI_SHELL_NAME, (UINTN) -1, LOAD_OPTION_ACTIVE, (UINT8 *)ShellData, ShellDataSize);
+    CopyMem (&gUefiShellFileGuid, PcdGetPtr (PcdShellFile), sizeof (GUID));
+    RegisterFvBootOption (&gUefiShellFileGuid, (CHAR16 *) PcdGetPtr (PcdShellFileDesc), (UINTN) -1, LOAD_OPTION_ACTIVE, (UINT8 *)ShellData, ShellDataSize);
 
   //
   // Boot Menu
@@ -557,7 +556,7 @@ BootOptionPriority (
       return 6;
 
     }
-    if (StrCmp (BootOption->Description, INTERNAL_UEFI_SHELL_NAME) == 0) {
+    if (StrCmp (BootOption->Description, (CHAR16 *) PcdGetPtr (PcdShellFileDesc)) == 0) {
       if (PcdGetBool (PcdBootToShellOnly)) {
         return 0;
       }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-18 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1674047008.git.abdattar@amd.com>
2023-01-18 13:04 ` [PATCH v3 1/2] BoardModulePkg: Copy device path before processing Abdul Lateef Attar
2023-01-18 13:04 ` [PATCH v3 2/2] BoardModulePkg: Adds PCD to load UEFI Shell image Abdul Lateef Attar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox