[edk2-devel] [edk2-platforms] [PATCH V2 4/5] MinPlatformPkg: Add PcdDefaultTerminalType support to SerialPortTerminalLib

Nate DeSimone nathaniel.l.desimone at intel.com
Wed Sep 7 06:27:34 UTC 2022


 - Sets the terminal type GUID for ConIn, ConOut, and ConErr to the terminal
   type indicated by PcdDefaultTerminalType.
 - Some improvements to the comments in SerialPortTerminalLib

Cc: Chasel Chiu <chasel.chiu at intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty at intel.com>
Cc: Isaac Oram <isaac.w.oram at intel.com>
Cc: Eric Dong <eric.dong at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Cc: Benjamin Doron <benjamin.doron00 at gmail.com>
Cc: Michael Kubacki <michael.kubacki at microsoft.com>
Cc: Jeremy Soller <jeremy at system76.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone at intel.com>
---
 .../SerialPortTerminalLib.c                   | 66 ++++++++++++++-----
 .../SerialPortTerminalLib.h                   | 11 +++-
 .../SerialPortTerminalLib.inf                 | 17 ++++-
 3 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.c b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.c
index 66e8ee018b..ca5e966cb5 100644
--- a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.c
+++ b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.c
@@ -1,13 +1,26 @@
 /** @file
-  Main file for NULL named library for Serial Port Terminal Redirection library.
+  Main file for NULL named library for the Serial Port Terminal Redirection library.
 
-  Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+  This library adds a Terminal Device connected to SerialDxe to the UEFI Console
+  Variables. This allows BIOS Setup, UEFI Shell, etc. to be used on a headless
+  system via a null modem and terminal
+  emulator.
+
+  Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
 #include "SerialPortTerminalLib.h"
 
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  *mTerminalType[] = {
+  &gEfiPcAnsiGuid,
+  &gEfiVT100Guid,
+  &gEfiVT100PlusGuid,
+  &gEfiVTUTF8Guid,
+  &gEfiTtyTermGuid
+};
+
 GLOBAL_REMOVE_IF_UNREFERENCED SERIAL_DEVICE_PATH mSerialDevicePath = {
   {
     {
@@ -59,10 +72,36 @@ AddSerialTerminal (
   VOID
   )
 {
-  DEBUG ((DEBUG_INFO, "[AddSerialPortTerminal]\n"));
+  UINT8   DefaultTerminalType;
+
+  //
+  // Update the Terminal Device Configuration Parameters
+  //
+  mSerialDevicePath.Uart.BaudRate = PcdGet64 (PcdUartDefaultBaudRate);
+  mSerialDevicePath.Uart.DataBits = PcdGet8 (PcdUartDefaultDataBits);
+  mSerialDevicePath.Uart.Parity   = PcdGet8 (PcdUartDefaultParity);
+  mSerialDevicePath.Uart.StopBits = PcdGet8 (PcdUartDefaultStopBits);
+  DefaultTerminalType             = PcdGet8 (PcdDefaultTerminalType);
+  DEBUG ((DEBUG_INFO, "[AddSerialPortTerminal] [%d, %d, %d, %d, %d]\n",
+      (int) mSerialDevicePath.Uart.BaudRate,
+      (int) mSerialDevicePath.Uart.DataBits,
+      (int) mSerialDevicePath.Uart.Parity,
+      (int) mSerialDevicePath.Uart.StopBits,
+      (int) DefaultTerminalType));
+
+  if (DefaultTerminalType >= 0 &&
+      DefaultTerminalType < (sizeof (mTerminalType) / sizeof (mTerminalType[0]))) {
+    CopyMem (
+      (VOID *) &(mSerialDevicePath.TerminalType.Guid),
+      (VOID *) mTerminalType[DefaultTerminalType],
+      sizeof (EFI_GUID)
+      );
+  } else {
+    DEBUG ((DEBUG_WARN, "PcdDefaultTerminalType has invalid value: %d\n", (int) DefaultTerminalType));
+  }
 
   //
-  // Append Serial Terminal into "ConIn"
+  // Append Serial Terminal into "ConIn", "ConOut", and "ErrOut"
   //
   EfiBootManagerUpdateConsoleVariable (ConOut, (EFI_DEVICE_PATH_PROTOCOL *) &mSerialDevicePath, NULL);
   EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *) &mSerialDevicePath, NULL);
@@ -71,13 +110,12 @@ AddSerialTerminal (
 
 
 /**
-  Constructor for the Serial Port Device controller library.
+  Constructor for the Serial Port Terminal Device library.
 
-  @param ImageHandle    the image handle of the process
-  @param SystemTable    the EFI System Table pointer
+  @param ImageHandle    The Image Handle of the process
+  @param SystemTable    The EFI System Table pointer
 
-  @retval EFI_SUCCESS        the shell command handlers were installed sucessfully
-  @retval EFI_UNSUPPORTED    the shell level required was not found.
+  @retval EFI_SUCCESS   The Serial Port Terminal Device was installed successfully
 **/
 EFI_STATUS
 EFIAPI
@@ -86,15 +124,7 @@ SerialPortTerminalLibConstructor (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  mSerialDevicePath.Uart.BaudRate = PcdGet64(PcdUartDefaultBaudRate);
-  mSerialDevicePath.Uart.DataBits = PcdGet8(PcdUartDefaultDataBits);
-  mSerialDevicePath.Uart.Parity   = PcdGet8(PcdUartDefaultParity);
-  mSerialDevicePath.Uart.StopBits = PcdGet8(PcdUartDefaultStopBits);
-  DEBUG ((DEBUG_INFO, "[SerialPortTerminalLibConstructor] [%d, %d, %d, %d]\n",
-      mSerialDevicePath.Uart.BaudRate,
-      mSerialDevicePath.Uart.DataBits,
-      mSerialDevicePath.Uart.Parity,
-      mSerialDevicePath.Uart.StopBits));
+  DEBUG ((DEBUG_INFO, "[SerialPortTerminalLibConstructor]\n"));
 
   AddSerialTerminal();
 
diff --git a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.h b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.h
index bfa73cca7d..33415721cd 100644
--- a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.h
+++ b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.h
@@ -1,7 +1,12 @@
 /** @file
-  Header file for NULL named library for for Serial Port Terminal Redirection library.
+  Header file for NULL named library for the Serial Port Terminal Redirection library.
 
-  Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+  This library adds a Terminal Device connected to SerialDxe to the UEFI Console
+  Variables. This allows BIOS Setup, UEFI Shell, etc. to be used on a headless
+  system via a null modem and terminal
+  emulator.
+
+  Copyright (c) 2020 -2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -12,8 +17,10 @@
 #include <Uefi.h>
 #include <Guid/SerialPortLibVendor.h>
 #include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/DevicePathLib.h>
 #include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
 #include <Library/UefiBootManagerLib.h>
 
 //
diff --git a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.inf b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.inf
index dc5bb91a8e..ac1a06b2a5 100644
--- a/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.inf
+++ b/Platform/Intel/MinPlatformPkg/Library/SerialPortTerminalLib/SerialPortTerminalLib.inf
@@ -1,5 +1,9 @@
 ## @file
-# Component information file for Serial Port Terminal Redirection Library
+# Component information file for the Serial Port Terminal Redirection library.
+#
+#  This library adds a Terminal Device connected to SerialDxe to the UEFI Console
+#  Variables. This allows BIOS Setup, UEFI Shell, etc. to be used on a headless
+#  system via a null modem and terminal
 #
 # Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
 #
@@ -18,22 +22,29 @@
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
-  BoardModulePkg/BoardModulePkg.dec
-  MinPlatformPkg/MinPlatformPkg.dec
 
 [Sources]
   SerialPortTerminalLib.c
   SerialPortTerminalLib.h
 
 [LibraryClasses]
+  BaseMemoryLib
   DevicePathLib
   DebugLib
   UefiDriverEntryPoint
   UefiBootManagerLib
   UefiLib
 
+[Guids]
+  gEfiPcAnsiGuid
+  gEfiVT100Guid
+  gEfiVT100PlusGuid
+  gEfiVTUTF8Guid
+  gEfiTtyTermGuid
+
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
   gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
+  gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType
-- 
2.27.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#93354): https://edk2.groups.io/g/devel/message/93354
Mute This Topic: https://groups.io/mt/93519774/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list