[edk2-devel] [edk2-platforms Patch 10/14] Vlv2TbltDevicePkg: Switch to MdeModulePkg BdsDxe

Michael D Kinney michael.d.kinney at intel.com
Mon Jul 1 02:55:49 UTC 2019


Switch from Intel Framework BDS module and libraries to the
MdeModulePkg BdsDxe module and libraries.

Update FLASH map for full 8MB FLASH size

Cc: Zailiang Sun <zailiang.sun at intel.com>
Cc: Yi Qian <yi.qian at intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney at intel.com>
---
 .../Library/FmpDeviceLib/FmpDeviceLib.c       |   12 +-
 .../DxePlatformBootManagerLib/BdsPlatform.c   | 1409 ++++++
 .../DxePlatformBootManagerLib/BdsPlatform.h   |  253 +
 .../DxePlatformBootManagerLib.inf             |   95 +
 .../DxePlatformBootManagerLib/MemoryTest.c    |   83 +
 .../PlatformBootOption.c                      |  559 ++
 .../Library/PlatformBdsLib/BdsPlatform.c      | 3092 ------------
 .../Library/PlatformBdsLib/BdsPlatform.h      |  516 --
 .../Library/PlatformBdsLib/PlatformBdsLib.inf |  128 -
 .../PlatformBdsLib/PlatformBdsStrings.uni     |   30 -
 .../Library/PlatformBdsLib/PlatformData.c     |  306 --
 .../Library/GenericBdsLib/BdsBoot.c           | 4490 -----------------
 .../Library/GenericBdsLib/BdsConnect.c        |  429 --
 .../Library/GenericBdsLib/BdsConsole.c        | 1061 ----
 .../Library/GenericBdsLib/BdsMisc.c           | 1575 ------
 .../Library/GenericBdsLib/DevicePath.c        |   27 -
 .../Library/GenericBdsLib/GenericBdsLib.inf   |  143 -
 .../Library/GenericBdsLib/GenericBdsLib.uni   |   19 -
 .../GenericBdsLib/GenericBdsStrings.uni       |   30 -
 .../Library/GenericBdsLib/InternalBdsLib.h    |  173 -
 .../Library/GenericBdsLib/String.c            |   26 -
 .../Library/GenericBdsLib/String.h            |   42 -
 .../Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf   |   26 +-
 .../Vlv2TbltDevicePkg/PlatformPkgGcc.fdf      |   53 +-
 .../Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc   |   22 +-
 .../Vlv2TbltDevicePkg/PlatformPkgIA32.dsc     |   22 +-
 .../Vlv2TbltDevicePkg/PlatformPkgX64.dsc      |   22 +-
 .../Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c |   33 -
 .../Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf   |   32 -
 29 files changed, 2477 insertions(+), 12231 deletions(-)
 create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.c
 create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.h
 create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
 create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/MemoryTest.c
 create mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/PlatformBootOption.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLib.inf
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsStrings.uni
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformData.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.uni
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c
 delete mode 100644 Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf

diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib/FmpDeviceLib.c b/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib/FmpDeviceLib.c
index a863d69381..57185d8d09 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib/FmpDeviceLib.c
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Feature/Capsule/Library/FmpDeviceLib/FmpDeviceLib.c
@@ -32,11 +32,11 @@ typedef struct {
 } UPDATE_CONFIG_DATA;
 
 UPDATE_CONFIG_DATA mUpdateConfigData[] = {
-  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00000000, 0x00040000, 0x00000000 },
-  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x000C0000, 0x00050000, 0x000C0000 },
-  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00110000, 0x00210000, 0x00110000 },
-  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00320000, 0x00070000, 0x00320000 },
-  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00390000, 0x00070000, 0x00390000 }
+  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00400000, 0x00040000, 0x00400000 },
+  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x004C0000, 0x00050000, 0x004C0000 },
+  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00510000, 0x00210000, 0x00510000 },
+  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00720000, 0x00070000, 0x00720000 },
+  { PlatformFirmwareTypeSystemFirmware, FlashAddressTypeRelativeAddress, 0x00790000, 0x00070000, 0x00790000 }
 };
 
 /**
@@ -95,7 +95,7 @@ FmpDeviceGetSize (
   if (Size == NULL) {
     return EFI_INVALID_PARAMETER;
   }
-  *Size = PcdGet32 (PcdBiosRomBase);
+  *Size = PcdGet32 (PcdBiosRomSize);
   return EFI_SUCCESS;
 }
 
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.c
new file mode 100644
index 0000000000..4dd3827a6e
--- /dev/null
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.c
@@ -0,0 +1,1409 @@
+/** @file
+  This file include all platform action which can be customized by IBV/OEM.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BdsPlatform.h"
+#include <Guid/EventGroup.h>
+#include <Protocol/DxeSmmReadyToLock.h>
+#include <Protocol/FirmwareVolume2.h>
+#include <Protocol/PciRootBridgeIo.h>
+
+#include <Protocol/BlockIo.h>
+#include <Protocol/PciIo.h>
+#include <Library/IoLib.h>
+#include <Library/PciLib.h>
+#include <Guid/EventGroup.h>
+
+#include <Library/Tcg2PhysicalPresenceLib.h>
+
+#include <Library/HobLib.h>
+#include <Protocol/UsbIo.h>
+#include <Library/BootLogoLib.h>
+
+#include <Library/UefiBootManagerLib.h>
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODE                 gBootMode;
+
+BOOLEAN                      gPPRequireUIConfirm;
+
+extern UINTN                                      mBootMenuOptionNumber;
+
+GLOBAL_REMOVE_IF_UNREFERENCED USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath = {
+  {
+    {
+      MESSAGING_DEVICE_PATH,
+      MSG_USB_CLASS_DP,
+      {
+        (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)),
+        (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8)
+      }
+    },
+    0xffff,           // VendorId
+    0xffff,           // ProductId
+    CLASS_HID,        // DeviceClass
+    SUBCLASS_BOOT,    // DeviceSubClass
+    PROTOCOL_KEYBOARD // DeviceProtocol
+  },
+  gEndEntire
+};
+
+//
+// Platform specific ISA serial device path
+//
+GLOBAL_REMOVE_IF_UNREFERENCED PLATFORM_ISA_SERIAL_DEVICE_PATH gIsaSerialDevicePath = {
+  gPciRootBridge,
+  gPciIsaBridge,
+  gPnp16550ComPort,
+  gUart(115200, 8, 1, 1),
+  gPcAnsiTerminal,
+  gEndEntire
+};
+
+//
+// Internal shell mode
+//
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32         mShellModeColumn;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32         mShellModeRow;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32         mShellHorizontalResolution;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32         mShellVerticalResolution;
+//
+// BDS Platform Functions
+//
+
+BOOLEAN
+IsMorBitSet (
+  VOID
+  )
+{
+  UINTN                     MorControl;
+  EFI_STATUS                Status;
+  UINTN                     DataSize;
+
+  //
+  // Check if the MOR bit is set.
+  //
+  DataSize = sizeof (MorControl);
+  Status = gRT->GetVariable (
+                  MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
+                  &gEfiMemoryOverwriteControlDataGuid,
+                  NULL,
+                  &DataSize,
+                  &MorControl
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_INFO, " PlatformBootMangerLib: gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
+    MorControl = 0;
+  } else {
+    DEBUG ((DEBUG_INFO, " PlatformBootMangerLib: Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", MorControl));
+  }
+
+  return (BOOLEAN) (MorControl & 0x01);
+}
+
+VOID
+DumpDevicePath (
+  IN CHAR16           *Name,
+  IN EFI_DEVICE_PATH  *DevicePath
+  )
+{
+  CHAR16 *Str;
+
+  Str = ConvertDevicePathToText(DevicePath, TRUE, TRUE);
+  DEBUG ((DEBUG_INFO, "%s: %s\n", Name, Str));
+  if (Str != NULL) {
+    FreePool (Str);
+  }
+}
+
+/**
+  An empty function to pass error checking of CreateEventEx ().
+
+  This empty function ensures that EVT_NOTIFY_SIGNAL_ALL is error
+  checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.
+
+  @param  Event                 Event whose notification function is being invoked.
+  @param  Context               The pointer to the notification function's context,
+                                which is implementation-dependent.
+**/
+VOID
+EFIAPI
+InternalBdsEmptyCallbackFuntion (
+  IN EFI_EVENT                Event,
+  IN VOID                     *Context
+  )
+{
+  return;
+}
+
+VOID
+ExitPmAuth (
+  VOID
+  )
+{
+  EFI_HANDLE                 Handle;
+  EFI_STATUS                 Status;
+  EFI_EVENT                  EndOfDxeEvent;
+
+  DEBUG((DEBUG_INFO,"ExitPmAuth ()- Start\n"));
+  //
+  // Prepare S3 information, this MUST be done before ExitPmAuth/EndOfDxe
+  //
+  //
+  // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
+  //
+  Status = gBS->CreateEventEx (
+                  EVT_NOTIFY_SIGNAL,
+                  TPL_CALLBACK,
+                  InternalBdsEmptyCallbackFuntion,
+                  NULL,
+                  &gEfiEndOfDxeEventGroupGuid,
+                  &EndOfDxeEvent
+                  );
+  ASSERT_EFI_ERROR (Status);
+  gBS->SignalEvent (EndOfDxeEvent);
+  gBS->CloseEvent (EndOfDxeEvent);
+  DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n"));
+
+  //
+  // NOTE: We need install DxeSmmReadyToLock directly here because many boot script is added via ExitPmAuth/EndOfDxe callback.
+  // If we install them at same callback, these boot script will be rejected because BootScript Driver runs first to lock them done.
+  // So we seperate them to be 2 different events, ExitPmAuth is last chance to let platform add boot script. DxeSmmReadyToLock will
+  // make boot script save driver lock down the interface.
+  //
+  Handle = NULL;
+  Status = gBS->InstallProtocolInterface (
+                  &Handle,
+                  &gEfiDxeSmmReadyToLockProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL
+                  );
+  ASSERT_EFI_ERROR (Status);
+  DEBUG((DEBUG_INFO,"ExitPmAuth ()- End\n"));
+}
+
+VOID
+ConnectRootBridge (
+  BOOLEAN Recursive
+  )
+{
+  UINTN                            RootBridgeHandleCount;
+  EFI_HANDLE                       *RootBridgeHandleBuffer;
+  UINTN                            RootBridgeIndex;
+
+  RootBridgeHandleCount = 0;
+  gBS->LocateHandleBuffer (
+         ByProtocol,
+         &gEfiPciRootBridgeIoProtocolGuid,
+         NULL,
+         &RootBridgeHandleCount,
+         &RootBridgeHandleBuffer
+         );
+  for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) {
+    gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, Recursive);
+  }
+}
+
+
+/**
+  Return whether the device is trusted console.
+
+  @param Device  The device to be tested.
+
+  @retval TRUE   The device can be trusted.
+  @retval FALSE  The device cannot be trusted.
+**/
+BOOLEAN
+IsTrustedConsole (
+  IN CONSOLE_TYPE              ConsoleType,
+  IN EFI_DEVICE_PATH_PROTOCOL  *Device
+  )
+{
+  VOID                      *TrustedConsoleDevicepath;
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL  *Instance;
+  UINTN                     Size;
+  EFI_DEVICE_PATH_PROTOCOL  *ConsoleDevice;
+
+  if (Device == NULL) {
+    return FALSE;
+  }
+
+  ConsoleDevice = DuplicateDevicePath(Device);
+
+  TrustedConsoleDevicepath = NULL;
+
+  switch (ConsoleType) {
+  case ConIn:
+    TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
+    break;
+  case ConOut:
+    //
+    // Check GOP and remove last node
+    //
+    TempDevicePath = ConsoleDevice;
+    while (!IsDevicePathEndType (TempDevicePath)) {
+      if (DevicePathType (TempDevicePath) == ACPI_DEVICE_PATH &&
+          DevicePathSubType (TempDevicePath) == ACPI_ADR_DP) {
+        SetDevicePathEndNode (TempDevicePath);
+        break;
+      }
+      TempDevicePath = NextDevicePathNode (TempDevicePath);
+    }
+
+    TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
+    break;
+  default:
+    ASSERT(FALSE);
+    break;
+  }
+
+  TempDevicePath = TrustedConsoleDevicepath;
+  do {
+    Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
+    if (Instance == NULL) {
+      break;
+    }
+
+    if (CompareMem (ConsoleDevice, Instance, Size - END_DEVICE_PATH_LENGTH) == 0) {
+      FreePool (Instance);
+      FreePool (ConsoleDevice);
+      return TRUE;
+    }
+
+    FreePool (Instance);
+  } while (TempDevicePath != NULL);
+
+  FreePool (ConsoleDevice);
+
+  return FALSE;
+}
+
+BOOLEAN
+IsUsbShortForm (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath
+  )
+{
+  if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
+      ((DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP) || (DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)) ) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+  Connect the USB short form device path.
+
+  @param DevicePath   USB short form device path
+
+  @retval EFI_SUCCESS           Successfully connected the USB device
+  @retval EFI_NOT_FOUND         Cannot connect the USB device
+  @retval EFI_INVALID_PARAMETER The device path is invalid.
+**/
+EFI_STATUS
+ConnectUsbShortFormDevicePath (
+  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_HANDLE                            *Handles;
+  UINTN                                 HandleCount;
+  UINTN                                 Index;
+  EFI_PCI_IO_PROTOCOL                   *PciIo;
+  UINT8                                 Class[3];
+  BOOLEAN                               AtLeastOneConnected;
+
+  //
+  // Check the passed in parameters
+  //
+  if (DevicePath == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (!IsUsbShortForm (DevicePath)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Find the usb host controller firstly, then connect with the remaining device path
+  //
+  AtLeastOneConnected = FALSE;
+  Status = gBS->LocateHandleBuffer (
+                  ByProtocol,
+                  &gEfiPciIoProtocolGuid,
+                  NULL,
+                  &HandleCount,
+                  &Handles
+                  );
+  for (Index = 0; Index < HandleCount; Index++) {
+    Status = gBS->HandleProtocol (
+                    Handles[Index],
+                    &gEfiPciIoProtocolGuid,
+                    (VOID **) &PciIo
+                    );
+    if (!EFI_ERROR (Status)) {
+      //
+      // Check whether the Pci device is the wanted usb host controller
+      //
+      Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
+      if (!EFI_ERROR (Status) &&
+          ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1]))
+         ) {
+        Status = gBS->ConnectController (
+                        Handles[Index],
+                        NULL,
+                        DevicePath,
+                        FALSE
+                        );
+        if (!EFI_ERROR(Status)) {
+          AtLeastOneConnected = TRUE;
+        }
+      }
+    }
+  }
+
+  return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND;
+}
+
+/**
+  Update the ConIn/ConOut variable with ISA Serial device path,if its not already exists in ConIn/ConOut
+**/
+VOID
+EnumIsaSerial (
+  VOID
+  )
+{
+  DEBUG ((DEBUG_INFO, "[EnumIsaSerial]\n"));
+  EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *) &gIsaSerialDevicePath, NULL);
+  EfiBootManagerUpdateConsoleVariable (ConOut, (EFI_DEVICE_PATH_PROTOCOL *) &gIsaSerialDevicePath, NULL);
+
+  //
+  // Append ISA Serial DevicePath to "ConInDev" and "ConOutDev"
+  //
+  EfiBootManagerUpdateConsoleVariable (ConInDev, (EFI_DEVICE_PATH_PROTOCOL *) &gIsaSerialDevicePath, NULL);
+  EfiBootManagerUpdateConsoleVariable (ConOutDev, (EFI_DEVICE_PATH_PROTOCOL *) &gIsaSerialDevicePath, NULL);
+}
+
+/**
+  Update the ConIn variable with USB Keyboard device path,if its not already exists in ConIn
+**/
+VOID
+EnumUsbKeyboard (
+  VOID
+  )
+{
+  DEBUG ((DEBUG_INFO, "[EnumUsbKeyboard]\n"));
+  EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, NULL);
+
+  //
+  // Append Usb Keyboard short form DevicePath into "ConInDev"
+  //
+  EfiBootManagerUpdateConsoleVariable (ConInDev, (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, NULL);
+}
+
+BOOLEAN
+IsVgaHandle (
+  IN EFI_HANDLE Handle
+  )
+{
+  EFI_PCI_IO_PROTOCOL *PciIo;
+  PCI_TYPE00          Pci;
+  EFI_STATUS          Status;
+
+  Status = gBS->HandleProtocol (
+                  Handle,
+                  &gEfiPciIoProtocolGuid,
+                  (VOID **)&PciIo
+                  );
+  if (!EFI_ERROR (Status)) {
+    Status = PciIo->Pci.Read (
+                          PciIo,
+                          EfiPciIoWidthUint32,
+                          0,
+                          sizeof (Pci) / sizeof (UINT32),
+                          &Pci
+                          );
+    if (!EFI_ERROR (Status)) {
+      if (IS_PCI_VGA (&Pci) || IS_PCI_OLD_VGA (&Pci)) {
+        return TRUE;
+      }
+    }
+  }
+  return FALSE;
+}
+
+EFI_HANDLE
+IsVideoController (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath
+  )
+{
+  EFI_DEVICE_PATH_PROTOCOL  *DupDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;
+  EFI_STATUS                Status;
+  EFI_HANDLE                DeviceHandle;
+
+  DupDevicePath = DuplicateDevicePath (DevicePath);
+  ASSERT (DupDevicePath != NULL);
+  if (DupDevicePath == NULL) {
+    return NULL;
+  }
+
+  TempDevicePath = DupDevicePath;
+  Status = gBS->LocateDevicePath (
+                  &gEfiDevicePathProtocolGuid,
+                  &TempDevicePath,
+                  &DeviceHandle
+                  );
+  FreePool (DupDevicePath);
+  if (EFI_ERROR (Status)) {
+    return NULL;
+  }
+
+  if (IsVgaHandle (DeviceHandle)) {
+    return DeviceHandle;
+  } else {
+    return NULL;
+  }
+}
+
+BOOLEAN
+IsGopDevicePath (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath
+  )
+{
+  while (!IsDevicePathEndType (DevicePath)) {
+    if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH &&
+        DevicePathSubType (DevicePath) == ACPI_ADR_DP) {
+      return TRUE;
+    }
+    DevicePath = NextDevicePathNode (DevicePath);
+  }
+  return FALSE;
+}
+
+/**
+  Remove all GOP device path instance from DevicePath and add the Gop to the DevicePath.
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+UpdateGopDevicePath (
+  EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+  EFI_DEVICE_PATH_PROTOCOL *Gop
+  )
+{
+  UINTN                    Size;
+  UINTN                    GopSize;
+  EFI_DEVICE_PATH_PROTOCOL *Temp;
+  EFI_DEVICE_PATH_PROTOCOL *Return;
+  EFI_DEVICE_PATH_PROTOCOL *Instance;
+  BOOLEAN                  Exist;
+
+  Exist = FALSE;
+  Return = NULL;
+  GopSize = GetDevicePathSize (Gop);
+  do {
+    Instance = GetNextDevicePathInstance (&DevicePath, &Size);
+    if (Instance == NULL) {
+      break;
+    }
+    if (!IsGopDevicePath (Instance) ||
+        (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0)
+       ) {
+      if (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0) {
+        Exist = TRUE;
+      }
+      Temp = Return;
+      Return = AppendDevicePathInstance (Return, Instance);
+      if (Temp != NULL) {
+        FreePool (Temp);
+      }
+    }
+    FreePool (Instance);
+  } while (DevicePath != NULL);
+
+  if (!Exist) {
+    Temp = Return;
+    Return = AppendDevicePathInstance (Return, Gop);
+    if (Temp != NULL) {
+      FreePool (Temp);
+    }
+  }
+  return Return;
+}
+
+/**
+  Get Graphics Controller Handle.
+
+  @retval GraphicsController    Successfully located
+  @retval NULL                  Failed to locate
+**/
+EFI_HANDLE
+EFIAPI
+GetGraphicsController (
+  IN BOOLEAN    NeedTrustedConsole
+  )
+{
+  EFI_STATUS                Status;
+  UINTN                     Index;
+  EFI_HANDLE                *PciHandles;
+  UINTN                     PciHandlesSize;
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
+
+  Status = gBS->LocateHandleBuffer (
+                  ByProtocol,
+                  &gEfiPciIoProtocolGuid,
+                  NULL,
+                  &PciHandlesSize,
+                  &PciHandles
+                  );
+  if (EFI_ERROR (Status)) {
+    return NULL;
+  }
+
+  for (Index = 0; Index < PciHandlesSize; Index++) {
+    Status = gBS->HandleProtocol (
+                    PciHandles[Index],
+                    &gEfiDevicePathProtocolGuid,
+                    (VOID **) &DevicePath
+                    );
+    if (EFI_ERROR(Status)) {
+      continue;
+    }
+    if (!IsVgaHandle (PciHandles[Index])) {
+      continue;
+    }
+    if ((NeedTrustedConsole && IsTrustedConsole (ConOut, DevicePath)) ||
+        ((!NeedTrustedConsole) && (!IsTrustedConsole (ConOut, DevicePath)))) {
+      return PciHandles[Index];
+    }
+  }
+
+  return NULL;
+}
+
+VOID
+UpdateGraphicConOut (
+  IN BOOLEAN    NeedTrustedConsole
+  )
+{
+  EFI_HANDLE                          GraphicsControllerHandle;
+  EFI_DEVICE_PATH_PROTOCOL            *GopDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL            *ConOutDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL            *UpdatedConOutDevicePath;
+
+  //
+  // Update ConOut variable
+  //
+  GraphicsControllerHandle = GetGraphicsController (NeedTrustedConsole);
+  if (GraphicsControllerHandle != NULL) {
+    //
+    // Connect the GOP driver
+    //
+    gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE);
+
+    //
+    // Get the GOP device path
+    // NOTE: We may get a device path that contains Controller node in it.
+    //
+    GopDevicePath = EfiBootManagerGetGopDevicePath (GraphicsControllerHandle);
+    if (GopDevicePath != NULL) {
+      GetEfiGlobalVariable2 (L"ConOut", (VOID **)&ConOutDevicePath, NULL);
+      UpdatedConOutDevicePath = UpdateGopDevicePath (ConOutDevicePath, GopDevicePath);
+      if (ConOutDevicePath != NULL) {
+        FreePool (ConOutDevicePath);
+      }
+      FreePool (GopDevicePath);
+      gRT->SetVariable (
+                      L"ConOut",
+                      &gEfiGlobalVariableGuid,
+                      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+                      GetDevicePathSize (UpdatedConOutDevicePath),
+                      UpdatedConOutDevicePath
+                      );
+    }
+  }
+}
+
+VOID
+AddConsoleVariable (
+  IN CONSOLE_TYPE              ConsoleType,
+  IN EFI_DEVICE_PATH           *ConsoleDevicePath
+  )
+{
+  EFI_DEVICE_PATH           *TempDevicePath;
+  EFI_DEVICE_PATH           *Instance;
+  UINTN                     Size;
+  EFI_HANDLE                GraphicsControllerHandle;
+  EFI_DEVICE_PATH           *GopDevicePath;
+
+  TempDevicePath = ConsoleDevicePath;
+  do {
+    Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
+    if (Instance == NULL) {
+      break;
+    }
+
+    switch (ConsoleType) {
+    case ConIn:
+      if (IsUsbShortForm (Instance)) {
+        //
+        // Append Usb Keyboard short form DevicePath into "ConInDev"
+        //
+        EfiBootManagerUpdateConsoleVariable (ConInDev, Instance, NULL);
+      }
+      EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL);
+      break;
+    case ConOut:
+      GraphicsControllerHandle = IsVideoController (Instance);
+      if (GraphicsControllerHandle == NULL) {
+        EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL);
+      } else {
+        //
+        // Connect the GOP driver
+        //
+        gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE);
+        //
+        // Get the GOP device path
+        // NOTE: We may get a device path that contains Controller node in it.
+        //
+        GopDevicePath = EfiBootManagerGetGopDevicePath (GraphicsControllerHandle);
+        if (GopDevicePath != NULL) {
+          EfiBootManagerUpdateConsoleVariable (ConsoleType, GopDevicePath, NULL);
+        }
+      }
+      break;
+    default:
+      ASSERT(FALSE);
+      break;
+    }
+
+    FreePool (Instance);
+  } while (TempDevicePath != NULL);
+}
+
+/**
+  The function connects the trusted consoles.
+**/
+VOID
+ConnectTrustedConsole (
+  VOID
+  )
+{
+  EFI_DEVICE_PATH_PROTOCOL     *Consoles;
+  EFI_DEVICE_PATH_PROTOCOL     *TempDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL     *Instance;
+  EFI_DEVICE_PATH_PROTOCOL     *Next;
+  UINTN                        Size;
+  UINTN                        Index;
+  EFI_HANDLE                   Handle;
+  EFI_STATUS                   Status;
+  CHAR16                       *ConsoleVar[] = {L"ConIn", L"ConOut"};
+  VOID                         *TrustedConsoleDevicepath;
+
+  TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
+  DumpDevicePath (L"TrustedConsoleIn", TrustedConsoleDevicepath);
+  TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
+  DumpDevicePath (L"TrustedConsoleOut", TrustedConsoleDevicepath);
+
+  for (Index = 0; Index < sizeof (ConsoleVar) / sizeof (ConsoleVar[0]); Index++) {
+
+    GetEfiGlobalVariable2 (ConsoleVar[Index], (VOID **)&Consoles, NULL);
+
+    TempDevicePath = Consoles;
+    do {
+      Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
+      if (Instance == NULL) {
+        break;
+      }
+      if (IsTrustedConsole (Index, Instance)) {
+        if (IsUsbShortForm (Instance)) {
+          ConnectUsbShortFormDevicePath (Instance);
+        } else {
+          for (Next = Instance; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) {
+            if (DevicePathType (Next) == ACPI_DEVICE_PATH && DevicePathSubType (Next) == ACPI_ADR_DP) {
+              break;
+            } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH &&
+                       DevicePathSubType (Next) == HW_CONTROLLER_DP &&
+                       DevicePathType (NextDevicePathNode (Next)) == ACPI_DEVICE_PATH &&
+                       DevicePathSubType (NextDevicePathNode (Next)) == ACPI_ADR_DP
+                       ) {
+              break;
+            }
+          }
+          if (!IsDevicePathEnd (Next)) {
+            SetDevicePathEndNode (Next);
+            Status = EfiBootManagerConnectDevicePath (Instance, &Handle);
+            if (!EFI_ERROR (Status)) {
+              gBS->ConnectController (Handle, NULL, NULL, TRUE);
+            }
+          } else {
+            EfiBootManagerConnectDevicePath (Instance, NULL);
+          }
+        }
+      }
+      FreePool (Instance);
+    } while (TempDevicePath != NULL);
+
+    if (Consoles != NULL) {
+      FreePool (Consoles);
+    }
+  }
+}
+
+/**
+  The function connects the trusted Storages.
+**/
+VOID
+ConnectTrustedStorage (
+  VOID
+  )
+{
+  VOID                      *TrustedStorageDevicepath;
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL  *Instance;
+  UINTN                     Size;
+  EFI_DEVICE_PATH_PROTOCOL  *TempStorageDevicePath;
+  EFI_STATUS                Status;
+  EFI_HANDLE                DeviceHandle;
+
+  TrustedStorageDevicepath = PcdGetPtr (PcdTrustedStorageDevicePath);
+  DumpDevicePath (L"TrustedStorage", TrustedStorageDevicepath);
+
+  TempDevicePath = TrustedStorageDevicepath;
+  do {
+    Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
+    if (Instance == NULL) {
+      break;
+    }
+
+    EfiBootManagerConnectDevicePath (Instance, NULL);
+
+    TempStorageDevicePath = Instance;
+
+    Status = gBS->LocateDevicePath (
+                    &gEfiDevicePathProtocolGuid,
+                    &TempStorageDevicePath,
+                    &DeviceHandle
+                    );
+    if (!EFI_ERROR (Status)) {
+      gBS->ConnectController (DeviceHandle, NULL, NULL, FALSE);
+    }
+
+    FreePool (Instance);
+  } while (TempDevicePath != NULL);
+}
+
+/**
+  The function connects the trusted consoles and then call the PP processing library interface.
+**/
+VOID
+ProcessTcgPp (
+  VOID
+  )
+{
+  gPPRequireUIConfirm |= Tcg2PhysicalPresenceLibNeedUserConfirm();
+
+  if (gPPRequireUIConfirm) {
+    ConnectTrustedConsole ();
+  }
+
+  Tcg2PhysicalPresenceLibProcessRequest (NULL);
+}
+
+/**
+  The function connects the trusted storage to perform TPerReset.
+**/
+VOID
+ProcessTcgMor (
+  VOID
+  )
+{
+  if (IsMorBitSet ()) {
+    ConnectTrustedConsole();
+    ConnectTrustedStorage();
+  }
+}
+
+/**
+  Check if current BootCurrent variable is internal shell boot option.
+
+  @retval  TRUE         BootCurrent is internal shell.
+  @retval  FALSE        BootCurrent is not internal shell.
+**/
+BOOLEAN
+BootCurrentIsInternalShell (
+  VOID
+  )
+{
+  UINTN                         VarSize;
+  UINT16                        BootCurrent;
+  CHAR16                        BootOptionName[16];
+  UINT8                         *BootOption;
+  UINT8                         *Ptr;
+  BOOLEAN                       Result;
+  EFI_STATUS                    Status;
+  EFI_DEVICE_PATH_PROTOCOL      *TempDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL      *LastDeviceNode;
+  EFI_GUID                      *GuidPoint;
+
+  BootOption = NULL;
+  Result     = FALSE;
+
+  //
+  // Get BootCurrent variable
+  //
+  VarSize = sizeof (UINT16);
+  Status = gRT->GetVariable (
+                  L"BootCurrent",
+                  &gEfiGlobalVariableGuid,
+                  NULL,
+                  &VarSize,
+                  &BootCurrent
+                  );
+  if (EFI_ERROR (Status)) {
+    return FALSE;
+  }
+
+  //
+  // Create boot option Bootxxxx from BootCurrent
+  //
+  UnicodeSPrint (BootOptionName, sizeof(BootOptionName), L"Boot%04X", BootCurrent);
+
+  GetEfiGlobalVariable2 (BootOptionName, (VOID **) &BootOption, &VarSize);
+  if (BootOption == NULL || VarSize == 0) {
+    return FALSE;
+  }
+
+  Ptr = BootOption;
+  Ptr += sizeof (UINT32);
+  Ptr += sizeof (UINT16);
+  Ptr += StrSize ((CHAR16 *) Ptr);
+  TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
+  LastDeviceNode = TempDevicePath;
+  while (!IsDevicePathEnd (TempDevicePath)) {
+    LastDeviceNode = TempDevicePath;
+    TempDevicePath = NextDevicePathNode (TempDevicePath);
+  }
+  GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
+                (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
+                );
+  if ((GuidPoint != NULL) &&
+      ((CompareGuid (GuidPoint, &gUefiShellFileGuid)))
+    ) {
+    //
+    // if this option is internal shell, return TRUE
+    //
+    Result = TRUE;
+  }
+
+  if (BootOption != NULL) {
+    FreePool (BootOption);
+    BootOption = NULL;
+  }
+
+  return Result;
+}
+
+/**
+  This function will change video resolution and text mode
+  for internl shell when internal shell is launched.
+
+  @param   None.
+
+  @retval  EFI_SUCCESS  Mode is changed successfully.
+  @retval  Others       Mode failed to changed.
+**/
+EFI_STATUS
+EFIAPI
+ChangeModeForInternalShell (
+  VOID
+  )
+{
+  EFI_GRAPHICS_OUTPUT_PROTOCOL          *GraphicsOutput;
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL       *SimpleTextOut;
+  UINTN                                 SizeOfInfo;
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info;
+  UINT32                                MaxGopMode;
+  UINT32                                MaxTextMode;
+  UINT32                                ModeNumber;
+  UINTN                                 HandleCount;
+  EFI_HANDLE                            *HandleBuffer;
+  EFI_STATUS                            Status;
+  UINTN                                 Index;
+  UINTN                                 CurrentColumn;
+  UINTN                                 CurrentRow;
+
+  Status = gBS->HandleProtocol (
+                  gST->ConsoleOutHandle,
+                  &gEfiGraphicsOutputProtocolGuid,
+                  (VOID**)&GraphicsOutput
+                  );
+  if (EFI_ERROR (Status)) {
+    GraphicsOutput = NULL;
+  }
+
+  Status = gBS->HandleProtocol (
+                  gST->ConsoleOutHandle,
+                  &gEfiSimpleTextOutProtocolGuid,
+                  (VOID**)&SimpleTextOut
+                  );
+  if (EFI_ERROR (Status)) {
+    SimpleTextOut = NULL;
+  }
+
+  if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
+    return EFI_UNSUPPORTED;
+  }
+
+  MaxGopMode  = GraphicsOutput->Mode->MaxMode;
+  MaxTextMode = SimpleTextOut->Mode->MaxMode;
+
+  //
+  // 1. If current video resolution is same with new video resolution,
+  //    video resolution need not be changed.
+  //    1.1. If current text mode is same with new text mode, text mode need not be change.
+  //    1.2. If current text mode is different with new text mode, text mode need be change to new text mode.
+  // 2. If current video resolution is different with new video resolution, we need restart whole console drivers.
+  //
+  for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
+    Status = GraphicsOutput->QueryMode (
+                       GraphicsOutput,
+                       ModeNumber,
+                       &SizeOfInfo,
+                       &Info
+                       );
+    if (!EFI_ERROR (Status)) {
+      if ((Info->HorizontalResolution == mShellHorizontalResolution) &&
+          (Info->VerticalResolution == mShellVerticalResolution)) {
+        if ((GraphicsOutput->Mode->Info->HorizontalResolution == mShellHorizontalResolution) &&
+            (GraphicsOutput->Mode->Info->VerticalResolution == mShellVerticalResolution)) {
+          //
+          // If current video resolution is same with new resolution,
+          // then check if current text mode is same with new text mode.
+          //
+          Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
+          ASSERT_EFI_ERROR (Status);
+          if (CurrentColumn == mShellModeColumn && CurrentRow == mShellModeRow) {
+            //
+            // Current text mode is same with new text mode, text mode need not be change.
+            //
+            FreePool (Info);
+            return EFI_SUCCESS;
+          } else {
+            //
+            // Current text mode is different with new text mode, text mode need be change to new text mode.
+            //
+            for (Index = 0; Index < MaxTextMode; Index++) {
+              Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
+              if (!EFI_ERROR(Status)) {
+                if ((CurrentColumn == mShellModeColumn) && (CurrentRow == mShellModeRow)) {
+                  //
+                  // New text mode is supported, set it.
+                  //
+                  Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
+                  ASSERT_EFI_ERROR (Status);
+                  //
+                  // Update text mode PCD.
+                  //
+                  Status = PcdSet32S (PcdConOutColumn, mShellModeColumn);
+                  ASSERT_EFI_ERROR (Status);
+
+                  Status = PcdSet32S (PcdConOutRow, mShellModeRow);
+                  ASSERT_EFI_ERROR (Status);
+
+                  FreePool (Info);
+                  return EFI_SUCCESS;
+                }
+              }
+            }
+            if (Index == MaxTextMode) {
+              //
+              // If new text mode is not supported, return error.
+              //
+              FreePool (Info);
+              return EFI_UNSUPPORTED;
+            }
+          }
+        } else {
+          FreePool (Info);
+          //
+          // If current video resolution is not same with the new one, set new video resolution.
+          // In this case, the driver which produces simple text out need be restarted.
+          //
+          Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
+          if (!EFI_ERROR (Status)) {
+            //
+            // Set PCD to restart GraphicsConsole and Consplitter to change video resolution
+            // and produce new text mode based on new resolution.
+            //
+            Status = PcdSet32S (PcdVideoHorizontalResolution, mShellHorizontalResolution);
+            ASSERT_EFI_ERROR (Status);
+
+            Status = PcdSet32S (PcdVideoVerticalResolution, mShellVerticalResolution);
+            ASSERT_EFI_ERROR (Status);
+
+            Status = PcdSet32S (PcdConOutColumn, mShellModeColumn);
+            ASSERT_EFI_ERROR (Status);
+
+            Status = PcdSet32S (PcdConOutRow, mShellModeRow);
+            ASSERT_EFI_ERROR (Status);
+
+            Status = gBS->LocateHandleBuffer (
+                             ByProtocol,
+                             &gEfiSimpleTextOutProtocolGuid,
+                             NULL,
+                             &HandleCount,
+                             &HandleBuffer
+                             );
+            if (!EFI_ERROR (Status)) {
+              for (Index = 0; Index < HandleCount; Index++) {
+                gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
+              }
+              for (Index = 0; Index < HandleCount; Index++) {
+                gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
+              }
+              if (HandleBuffer != NULL) {
+                FreePool (HandleBuffer);
+              }
+              break;
+            }
+          }
+        }
+      }
+      FreePool (Info);
+    }
+  }
+
+  if (ModeNumber == MaxGopMode) {
+    //
+    // If the new resolution is not supported, return error.
+    //
+    return EFI_UNSUPPORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  ReadyToBoot callback to set video and text mode for internal shell boot.
+  That will not connect USB controller while CSM and FastBoot are disabled, we need to connect them
+  before booting to Shell for showing USB devices in Shell.
+
+  When FastBoot is enabled and Windows Console is the chosen Console behavior, input devices will not be connected
+  by default. Hence, when booting to EFI shell, connecting input consoles are required.
+
+  @param  Event   Pointer to this event
+  @param  Context Event hanlder private data
+
+  @retval None.
+**/
+VOID
+EFIAPI
+OnReadyToBootCallBack (
+  IN  EFI_EVENT                 Event,
+  IN  VOID                      *Context
+  )
+{
+  DEBUG ((DEBUG_INFO, "OnReadyToBootCallBack\n"));
+
+  if (BootCurrentIsInternalShell ()) {
+
+    ChangeModeForInternalShell ();
+    EfiBootManagerConnectAllDefaultConsoles();
+    gDS->Dispatch ();
+  }
+}
+
+/**
+  Platform Bds init. Incude the platform firmware vendor, revision
+  and so crc check.
+**/
+VOID
+EFIAPI
+PlatformBootManagerBeforeConsole (
+  VOID
+  )
+{
+  EFI_STATUS                          Status;
+  EFI_DEVICE_PATH_PROTOCOL            *VarConOut;
+  EFI_DEVICE_PATH_PROTOCOL            *VarConIn;
+  EFI_EVENT                           Event;
+
+  DEBUG ((DEBUG_INFO, "PlatformBootManagerBeforeConsole\n"));
+
+  Status = EFI_SUCCESS;
+
+  //
+  // Get user defined text mode for internal shell only once.
+  //
+  mShellHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
+  mShellVerticalResolution   = PcdGet32 (PcdSetupVideoVerticalResolution);
+  mShellModeColumn           = PcdGet32 (PcdSetupConOutColumn);
+  mShellModeRow              = PcdGet32 (PcdSetupConOutRow);
+
+  //
+  // Create event to set proper video resolution and text mode for internal shell.
+  //
+  Status = EfiCreateEventReadyToBootEx (
+             TPL_CALLBACK,
+             OnReadyToBootCallBack,
+             NULL,
+             &Event
+             );
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Connect Root Bridge to make PCI BAR resource allocated and all PciIo created
+  //
+  ConnectRootBridge (FALSE);
+
+  //
+  // Fill ConIn/ConOut in Full Configuration boot mode
+  //
+  gBootMode = GetBootModeHob();
+  DEBUG ((DEBUG_INFO, "PlatformBootManagerInit - %x\n", gBootMode));
+
+  if (gBootMode == BOOT_WITH_FULL_CONFIGURATION ||
+      gBootMode == BOOT_WITH_DEFAULT_SETTINGS ||
+      gBootMode == BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS ||
+      gBootMode == BOOT_IN_RECOVERY_MODE) {
+
+    GetEfiGlobalVariable2 (L"ConOut", (VOID **)&VarConOut, NULL);   if (VarConOut != NULL) { FreePool (VarConOut); }
+    GetEfiGlobalVariable2 (L"ConIn", (VOID **)&VarConIn, NULL);    if (VarConIn  != NULL) { FreePool (VarConIn);  }
+
+    //
+    // Only fill ConIn/ConOut when ConIn/ConOut is empty because we may drop to Full Configuration boot mode in non-first boot
+    //
+    if (VarConOut == NULL || VarConIn == NULL) {
+      if (PcdGetSize (PcdTrustedConsoleOutputDevicePath) >= sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
+        AddConsoleVariable (ConOut, PcdGetPtr (PcdTrustedConsoleOutputDevicePath));
+      }
+      if (PcdGetSize (PcdTrustedConsoleInputDevicePath) >= sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
+        AddConsoleVariable (ConIn, PcdGetPtr (PcdTrustedConsoleInputDevicePath));
+      }
+    }
+  }
+
+  EnumIsaSerial ();
+
+  EnumUsbKeyboard ();
+  //
+  // For trusted console it must be handled here.
+  //
+  UpdateGraphicConOut (TRUE);
+
+  if (gBootMode == BOOT_ON_FLASH_UPDATE) {
+    //
+    // Logo show
+    //
+    BootLogoEnableLogo ();
+
+    DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe......\n"));
+    ProcessCapsules ();
+    DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));
+  }
+
+  //
+  // Dynamically register hot key: F2/F7/Enter
+  //
+  RegisterDefaultBootOption ();
+  RegisterStaticHotkey ();
+
+  PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7010);
+  if (PcdGetBool (PcdTpm2Enable)) {
+    ProcessTcgPp ();
+    ProcessTcgMor ();
+  }
+  PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7011);
+
+  //
+  // We should make all UEFI memory and GCD information populated before ExitPmAuth.
+  // SMM may consume these information.
+  //
+  MemoryTest((EXTENDMEM_COVERAGE_LEVEL) PcdGet32 (PcdPlatformMemoryCheckLevel));
+
+  PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7020);
+  ExitPmAuth ();
+  PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7021);
+
+  //
+  // Dispatch the deferred 3rd party images.
+  //
+  EfiBootManagerDispatchDeferredImages ();
+
+  //
+  // For non-trusted console it must be handled here.
+  //
+  UpdateGraphicConOut (FALSE);
+
+  if (gBootMode == BOOT_ON_FLASH_UPDATE) {
+    //
+    // Logo show
+    //
+    BootLogoEnableLogo ();
+
+    DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll......\n"));
+    ProcessCapsules();
+    DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));
+  }
+}
+
+
+/**
+  Connect with predeined platform connect sequence,
+  the OEM/IBV can customize with their own connect sequence.
+
+  @param[in] BootMode          Boot mode of this boot.
+**/
+VOID
+ConnectSequence (
+  IN EFI_BOOT_MODE         BootMode
+  )
+{
+  EfiBootManagerConnectAll ();
+}
+
+/**
+  The function is to consider the boot order which is not in our expectation.
+  In the case that we need to re-sort the boot option.
+
+  @retval  TRUE         Need to sort Boot Option.
+  @retval  FALSE        Don't need to sort Boot Option.
+**/
+BOOLEAN
+IsNeedSortBootOption (
+  VOID
+  )
+{
+  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOptions;
+  UINTN                         BootOptionCount;
+
+  BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
+
+  //
+  // If setup is the first priority in boot option, we need to sort boot option.
+  //
+  if ((BootOptionCount > 1) &&
+      (((StrnCmp (BootOptions->Description, L"Enter Setup", StrLen (L"Enter Setup"))) == 0) ||
+       ((StrnCmp (BootOptions->Description, L"BootManagerMenuApp", StrLen (L"BootManagerMenuApp"))) == 0))) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+  The function will excute with as the platform policy, current policy
+  is driven by boot mode. IBV/OEM can customize this code for their specific
+  policy action.
+
+  @param DriverOptionList - The header of the driver option link list
+  @param BootOptionList   - The header of the boot option link list
+  @param ProcessCapsules  - A pointer to ProcessCapsules()
+  @param BaseMemoryTest   - A pointer to BaseMemoryTest()
+**/
+VOID
+EFIAPI
+PlatformBootManagerAfterConsole (
+  VOID
+  )
+{
+  EFI_BOOT_MODE                 LocalBootMode;
+
+  DEBUG ((DEBUG_INFO, "PlatformBootManagerAfterConsole\n"));
+
+  //
+  // Get current Boot Mode
+  //
+  LocalBootMode = gBootMode;
+  DEBUG ((DEBUG_INFO, "Current local bootmode - %x\n", LocalBootMode));
+
+  //
+  // Logo show
+  //
+  BootLogoEnableLogo ();
+
+  //
+  // Go the different platform policy with different boot mode
+  // Notes: this part code can be change with the table policy
+  //
+  switch (LocalBootMode) {
+
+
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
+  case BOOT_WITH_MINIMAL_CONFIGURATION:
+  case BOOT_ON_S4_RESUME:
+    //
+    // Perform some platform specific connect sequence
+    //
+    PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7050);
+    ConnectSequence (LocalBootMode);
+    PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7051);
+
+    break;
+
+  case BOOT_WITH_FULL_CONFIGURATION:
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
+  case BOOT_WITH_DEFAULT_SETTINGS:
+  default:
+    //
+    // Perform some platform specific connect sequence
+    //
+    ConnectSequence (LocalBootMode);
+
+    //
+    // Only in Full Configuration boot mode we do the enumeration of boot device
+    //
+    //
+    // Dispatch all but Storage Oprom explicitly, because we assume Int13Thunk driver is there.
+    //
+    EfiBootManagerRefreshAllBootOption ();
+
+    if (IsNeedSortBootOption()) {
+      EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
+    }
+    //
+    // PXE boot option may appear after boot option enumeration
+    //
+
+    break;
+  }
+
+  Print (L"Press F7 for BootMenu!\n");
+
+  EfiBootManagerRefreshAllBootOption ();
+  EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
+}
+
+/**
+  The function is called when no boot option could be launched,
+  including platform recovery options and options pointing to applications
+  built into firmware volumes.
+
+  If this function returns, BDS attempts to enter an infinite loop.
+**/
+VOID
+EFIAPI
+PlatformBootManagerUnableToBoot (
+  VOID
+  )
+{
+  EFI_STATUS                   Status;
+  EFI_BOOT_MANAGER_LOAD_OPTION BootDeviceList;
+  CHAR16                       OptionName[sizeof ("Boot####")];
+
+  if (mBootMenuOptionNumber == LoadOptionNumberUnassigned) {
+    return;
+  }
+  UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", mBootMenuOptionNumber);
+  Status = EfiBootManagerVariableToLoadOption (OptionName, &BootDeviceList);
+  if (EFI_ERROR (Status)) {
+    return;
+  }
+  for (;;) {
+    EfiBootManagerBoot (&BootDeviceList);
+  }
+}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.h b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.h
new file mode 100644
index 0000000000..0bdc11bdd8
--- /dev/null
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/BdsPlatform.h
@@ -0,0 +1,253 @@
+/** @file
+  Header file for BDS Platform specific code
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _BDS_PLATFORM_H
+#define _BDS_PLATFORM_H
+
+#include <PiDxe.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/SimpleNetwork.h>
+#include <Protocol/PciRootBridgeIo.h>
+#include <Protocol/LoadFile.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/CpuIo2.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/DiskInfo.h>
+#include <Protocol/GraphicsOutput.h>
+#include <Protocol/UgaDraw.h>
+#include <Protocol/GenericMemoryTest.h>
+#include <Protocol/DevicePathToText.h>
+#include <Protocol/FirmwareVolume2.h>
+#include <Protocol/SimpleFileSystem.h>
+
+#include <Guid/CapsuleVendor.h>
+#include <Guid/MemoryTypeInformation.h>
+#include <Guid/GlobalVariable.h>
+#include <Guid/MemoryOverwriteControl.h>
+#include <Guid/FileInfo.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PlatformBootManagerLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/UefiLib.h>
+#include <Library/HobLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/PrintLib.h>
+#include <Library/HiiLib.h>
+#include <Library/CapsuleLib.h>
+#include <Library/PerformanceLib.h>
+
+#include <IndustryStandard/Pci30.h>
+#include <IndustryStandard/PciCodeId.h>
+
+///
+/// ConnectType
+///
+#define CONSOLE_OUT 0x00000001
+#define STD_ERROR   0x00000002
+#define CONSOLE_IN  0x00000004
+#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR)
+
+extern EFI_GUID                  gUefiShellFileGuid;
+extern EFI_BOOT_MODE             gBootMode;
+
+#define PCI_DEVICE_PATH_NODE(Func, Dev) \
+  { \
+    HARDWARE_DEVICE_PATH, \
+    HW_PCI_DP, \
+    { \
+      (UINT8) (sizeof (PCI_DEVICE_PATH)), \
+      (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
+    }, \
+    (Func), \
+    (Dev) \
+  }
+
+#define PNPID_DEVICE_PATH_NODE(PnpId) \
+  { \
+    { \
+      ACPI_DEVICE_PATH, \
+      ACPI_DP, \
+      { \
+        (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
+        (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
+      } \
+    }, \
+    EISA_PNP_ID((PnpId)), \
+    0 \
+  }
+
+#define gPciRootBridge \
+  { \
+    { \
+      ACPI_DEVICE_PATH, \
+      ACPI_DP, \
+      { \
+        (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
+        (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
+      }, \
+    }, \
+    EISA_PNP_ID (0x0A03), \
+    0 \
+  }
+
+#define gPciIsaBridge \
+  PCI_DEVICE_PATH_NODE(0, 0x1f)
+
+#define gPnp16550ComPort \
+  PNPID_DEVICE_PATH_NODE(0x0501)
+
+#define gUart(BaudRate, DataBits, Parity, StopBits) \
+  { \
+    { \
+      MESSAGING_DEVICE_PATH, \
+      MSG_UART_DP, \
+      { \
+        (UINT8) (sizeof (UART_DEVICE_PATH)), \
+        (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \
+      } \
+    }, \
+    0, \
+    (BaudRate), \
+    (DataBits), \
+    (Parity), \
+    (StopBits) \
+  }
+
+#define gPcAnsiTerminal \
+  { \
+    { \
+      MESSAGING_DEVICE_PATH, \
+      MSG_VENDOR_DP, \
+      { \
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
+      } \
+    }, \
+    DEVICE_PATH_MESSAGING_PC_ANSI \
+  }
+
+#define gEndEntire \
+  { \
+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { END_DEVICE_PATH_LENGTH, 0 } \
+  }
+
+typedef struct {
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
+  UINTN                     ConnectType;
+} BDS_CONSOLE_CONNECT_ENTRY;
+
+//
+// Platform Root Bridge
+//
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_ROOT_BRIDGE_DEVICE_PATH;
+
+//
+// Below is the platform console device path
+//
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  PCI_DEVICE_PATH           IsaBridge;
+  ACPI_HID_DEVICE_PATH      Keyboard;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_KEYBOARD_DEVICE_PATH;
+
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  PCI_DEVICE_PATH           PciDevice;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_ONBOARD_CONTROLLER_DEVICE_PATH;
+
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  PCI_DEVICE_PATH           Pci0Device;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_PEG_ROOT_CONTROLLER_DEVICE_PATH;
+
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  PCI_DEVICE_PATH           PciBridge;
+  PCI_DEVICE_PATH           PciDevice;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_PCI_CONTROLLER_DEVICE_PATH;
+
+//
+// Below is the boot option device path
+//
+
+#define CLASS_HID           3
+#define SUBCLASS_BOOT       1
+#define PROTOCOL_KEYBOARD   1
+
+typedef struct {
+  USB_CLASS_DEVICE_PATH           UsbClass;
+  EFI_DEVICE_PATH_PROTOCOL        End;
+} USB_CLASS_FORMAT_DEVICE_PATH;
+
+typedef struct {
+  ACPI_HID_DEVICE_PATH      PciRootBridge;
+  PCI_DEVICE_PATH           IsaBridge;
+  ACPI_HID_DEVICE_PATH      IsaSerial;
+  UART_DEVICE_PATH          Uart;
+  VENDOR_DEVICE_PATH        TerminalType;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} PLATFORM_ISA_SERIAL_DEVICE_PATH;
+
+//
+// Platform BDS Functions
+//
+
+
+/**
+  Perform the memory test base on the memory test intensive level,
+  and update the memory resource.
+
+  @param  Level         The memory test intensive level.
+
+  @retval EFI_STATUS    Success test all the system memory and update
+                        the memory resource
+
+**/
+EFI_STATUS
+MemoryTest (
+  IN EXTENDMEM_COVERAGE_LEVEL Level
+  );
+
+VOID
+ConnectSequence (
+  IN EFI_BOOT_MODE                      BootMode
+  );
+
+
+INTN
+EFIAPI
+CompareBootOption (
+  CONST VOID  *Left,
+  CONST VOID  *Right
+  );
+
+
+VOID
+RegisterStaticHotkey (
+  VOID
+  );
+VOID
+RegisterDefaultBootOption (
+  VOID
+  );
+
+#endif
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
new file mode 100644
index 0000000000..b04169ad33
--- /dev/null
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
@@ -0,0 +1,95 @@
+### @file
+# Component name for module DxePlatformBootManagerLib
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+###
+
+[Defines]
+  INF_VERSION                    = 0x00010017
+  BASE_NAME                      = DxePlatformBootManagerLib
+  FILE_GUID                      = A6BC385D-59E5-4B77-87D7-200ABAA83C15
+  VERSION_STRING                 = 1.0
+  MODULE_TYPE                    = DXE_DRIVER
+  UEFI_SPECIFICATION_VERSION     = 2.10
+  LIBRARY_CLASS                  = PlatformBootManagerLib|DXE_DRIVER
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[LibraryClasses]
+  BaseLib
+  MemoryAllocationLib
+  UefiBootServicesTableLib
+  UefiRuntimeServicesTableLib
+  BaseMemoryLib
+  DebugLib
+  PcdLib
+  PrintLib
+  DevicePathLib
+  UefiLib
+  HobLib
+  DxeServicesLib
+  DxeServicesTableLib
+  HiiLib
+  UefiBootManagerLib
+  PerformanceLib
+  TimerLib
+  Tcg2PhysicalPresenceLib
+  CapsuleLib
+  BootLogoLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
+  MinPlatformPkg/MinPlatformPkg.dec
+
+[Pcd]
+  gMinPlatformPkgTokenSpaceGuid.PcdTpm2Enable                    ## CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut                   ## PRODUCES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution       ## PRODUCES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution         ## PRODUCES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow                       ## PRODUCES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn                    ## PRODUCES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutColumn               ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow                  ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution  ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution    ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand            ## PRODUCES
+  gMinPlatformPkgTokenSpaceGuid.PcdPlatformMemoryCheckLevel      ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdBootToShellOnly               ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleInputDevicePath  ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdTrustedConsoleOutputDevicePath ## CONSUMES
+  gMinPlatformPkgTokenSpaceGuid.PcdTrustedStorageDevicePath       ## CONSUMES
+
+[Sources]
+  BdsPlatform.c
+  BdsPlatform.h
+  PlatformBootOption.c
+  MemoryTest.c
+
+[Protocols]
+  gEfiPciRootBridgeIoProtocolGuid               ## CONSUMES
+  gEfiPciIoProtocolGuid                         ## CONSUMES
+  gEfiCpuIo2ProtocolGuid                        ## CONSUMES
+  gEfiDxeSmmReadyToLockProtocolGuid             ## PRODUCES
+  gEfiGenericMemTestProtocolGuid                ## CONSUMES
+  gEfiDiskInfoProtocolGuid                      ## CONSUMES
+  gEfiDevicePathToTextProtocolGuid              ## CONSUMES
+  gEfiSimpleTextInputExProtocolGuid             ## CONSUMES
+  gEfiFirmwareVolume2ProtocolGuid               ## CONSUMES
+  gEfiFormBrowser2ProtocolGuid                  ## CONSUMES
+  gEfiGenericMemTestProtocolGuid                ## CONSUMES
+
+[Guids]
+  gEfiGlobalVariableGuid                        ## PRODUCES
+  gEfiMemoryOverwriteControlDataGuid            ## PRODUCES
+  gEfiEndOfDxeEventGroupGuid                    ## CONSUMES
+
+[Depex.common.DXE_DRIVER]
+  gEfiVariableArchProtocolGuid
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/MemoryTest.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/MemoryTest.c
new file mode 100644
index 0000000000..654845349a
--- /dev/null
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/MemoryTest.c
@@ -0,0 +1,83 @@
+/** @file
+  Perform the platform memory test
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BdsPlatform.h"
+#include <Protocol/GenericMemoryTest.h>
+
+/**
+  Perform the memory test base on the memory test intensive level,
+  and update the memory resource.
+
+  @param  Level         The memory test intensive level.
+
+  @retval EFI_STATUS    Success test all the system memory and update
+                        the memory resource
+
+**/
+EFI_STATUS
+MemoryTest (
+  IN EXTENDMEM_COVERAGE_LEVEL Level
+  )
+{
+  EFI_STATUS                        Status;
+  BOOLEAN                           RequireSoftECCInit;
+  EFI_GENERIC_MEMORY_TEST_PROTOCOL  *GenMemoryTest;
+  UINT64                            TestedMemorySize;
+  UINT64                            TotalMemorySize;
+  BOOLEAN                           ErrorOut;
+  BOOLEAN                           TestAbort;
+
+  TestedMemorySize  = 0;
+  TotalMemorySize   = 0;
+  ErrorOut          = FALSE;
+  TestAbort         = FALSE;
+
+  RequireSoftECCInit = FALSE;
+
+  Status = gBS->LocateProtocol (
+                  &gEfiGenericMemTestProtocolGuid,
+                  NULL,
+                  (VOID **) &GenMemoryTest
+                  );
+  if (EFI_ERROR (Status)) {
+    return EFI_SUCCESS;
+  }
+
+  Status = GenMemoryTest->MemoryTestInit (
+                                GenMemoryTest,
+                                Level,
+                                &RequireSoftECCInit
+                                );
+  if (Status == EFI_NO_MEDIA) {
+    //
+    // The PEI codes also have the relevant memory test code to check the memory,
+    // it can select to test some range of the memory or all of them. If PEI code
+    // checks all the memory, this BDS memory test will has no not-test memory to
+    // do the test, and then the status of EFI_NO_MEDIA will be returned by
+    // "MemoryTestInit". So it does not need to test memory again, just return.
+    //
+    return EFI_SUCCESS;
+  }
+
+  do {
+    Status = GenMemoryTest->PerformMemoryTest (
+                              GenMemoryTest,
+                              &TestedMemorySize,
+                              &TotalMemorySize,
+                              &ErrorOut,
+                              TestAbort
+                              );
+    if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
+      ASSERT (0);
+    }
+  } while (Status != EFI_NOT_FOUND);
+
+  Status = GenMemoryTest->Finished (GenMemoryTest);
+
+  return EFI_SUCCESS;
+}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/PlatformBootOption.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/PlatformBootOption.c
new file mode 100644
index 0000000000..84aa097d58
--- /dev/null
+++ b/Platform/Intel/Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/PlatformBootOption.c
@@ -0,0 +1,559 @@
+/** @file
+  Driver for Platform Boot Options support.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BdsPlatform.h"
+
+#include <Library/PcdLib.h>
+
+BOOLEAN    mContinueBoot  = FALSE;
+BOOLEAN    mBootMenuBoot  = FALSE;
+BOOLEAN    mPxeBoot       = FALSE;
+BOOLEAN    mHotKeypressed = FALSE;
+EFI_EVENT  HotKeyEvent    = NULL;
+
+UINTN      mBootMenuOptionNumber;
+
+EFI_DEVICE_PATH_PROTOCOL *
+BdsCreateShellDevicePath (
+  VOID
+  )
+/*++
+
+Routine Description:
+
+  This function will create a SHELL BootOption to boot.
+
+Arguments:
+
+  None.
+
+Returns:
+
+  Shell Device path for booting.
+
+--*/
+{
+  UINTN                             FvHandleCount;
+  EFI_HANDLE                        *FvHandleBuffer;
+  UINTN                             Index;
+  EFI_STATUS                        Status;
+  EFI_FIRMWARE_VOLUME2_PROTOCOL     *Fv;
+  UINTN                             Size;
+  UINT32                            AuthenticationStatus;
+  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
+  VOID                              *Buffer;
+
+  DevicePath  = NULL;
+  Status      = EFI_SUCCESS;
+
+  DEBUG ((DEBUG_INFO, "BdsCreateShellDevicePath\n"));
+  gBS->LocateHandleBuffer (
+        ByProtocol,
+        &gEfiFirmwareVolume2ProtocolGuid,
+        NULL,
+        &FvHandleCount,
+        &FvHandleBuffer
+        );
+
+  for (Index = 0; Index < FvHandleCount; Index++) {
+    gBS->HandleProtocol (
+          FvHandleBuffer[Index],
+          &gEfiFirmwareVolume2ProtocolGuid,
+          (VOID **) &Fv
+          );
+
+    Buffer  = NULL;
+    Size    = 0;
+    Status  = Fv->ReadSection (
+                    Fv,
+                    &gUefiShellFileGuid,
+                    EFI_SECTION_PE32,
+                    0,
+                    &Buffer,
+                    &Size,
+                    &AuthenticationStatus
+                    );
+    if (EFI_ERROR (Status)) {
+      //
+      // Skip if no shell file in the FV
+      //
+      continue;
+    } else {
+      //
+      // Found the shell
+      //
+      break;
+    }
+  }
+
+  if (EFI_ERROR (Status)) {
+    //
+    // No shell present
+    //
+    if (FvHandleCount) {
+      FreePool (FvHandleBuffer);
+    }
+    return NULL;
+  }
+  //
+  // Build the shell boot option
+  //
+  DevicePath = DevicePathFromHandle (FvHandleBuffer[Index]);
+
+  if (FvHandleCount) {
+    FreePool (FvHandleBuffer);
+  }
+
+  return DevicePath;
+}
+
+
+EFI_STATUS
+CreateFvBootOption (
+  EFI_GUID                     *FileGuid,
+  CHAR16                       *Description,
+  EFI_BOOT_MANAGER_LOAD_OPTION *BootOption,
+  UINT32                       Attributes,
+  UINT8                        *OptionalData,    OPTIONAL
+  UINT32                       OptionalDataSize
+  )
+{
+  EFI_STATUS                         Status;
+  EFI_DEVICE_PATH_PROTOCOL           *DevicePath;
+  EFI_LOADED_IMAGE_PROTOCOL          *LoadedImage;
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;
+  EFI_FIRMWARE_VOLUME2_PROTOCOL      *Fv;
+  UINT32                             AuthenticationStatus;
+  VOID                               *Buffer;
+  UINTN                              Size;
+
+  if ((BootOption == NULL) || (FileGuid == NULL) || (Description == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
+
+  if (!CompareGuid (&gUefiShellFileGuid, FileGuid)) {
+    Status = gBS->HandleProtocol (
+                    gImageHandle,
+                    &gEfiLoadedImageProtocolGuid,
+                    (VOID **) &LoadedImage
+                    );
+    if (!EFI_ERROR (Status)) {
+      Status = gBS->HandleProtocol (
+                      LoadedImage->DeviceHandle,
+                      &gEfiFirmwareVolume2ProtocolGuid,
+                      (VOID **) &Fv
+                      );
+      if (!EFI_ERROR (Status)) {
+        Buffer  = NULL;
+        Size    = 0;
+        Status  = Fv->ReadSection (
+                        Fv,
+                        FileGuid,
+                        EFI_SECTION_PE32,
+                        0,
+                        &Buffer,
+                        &Size,
+                        &AuthenticationStatus
+                        );
+        if (Buffer != NULL) {
+          FreePool (Buffer);
+        }
+      }
+    }
+    if (EFI_ERROR (Status)) {
+      return EFI_NOT_FOUND;
+    }
+
+    DevicePath = AppendDevicePathNode (
+                   DevicePathFromHandle (LoadedImage->DeviceHandle),
+                   (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
+                   );
+  } else {
+    DevicePath = AppendDevicePathNode (
+                   BdsCreateShellDevicePath (),
+                   (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
+                   );
+  }
+
+  Status = EfiBootManagerInitializeLoadOption (
+             BootOption,
+             LoadOptionNumberUnassigned,
+             LoadOptionTypeBoot,
+             Attributes,
+             Description,
+             DevicePath,
+             OptionalData,
+             OptionalDataSize
+             );
+  FreePool (DevicePath);
+  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.
+
+  The function consider two load options are equal when the
+  OptionType, Attributes, Description, FilePath and OptionalData are equal.
+
+  @param Key    Pointer to the load option to be found.
+  @param Array  Pointer to the array of load options to be found.
+  @param Count  Number of entries in the Array.
+
+  @retval -1          Key wasn't found in the Array.
+  @retval 0 ~ Count-1 The index of the Key in the Array.
+**/
+INTN
+PlatformFindLoadOption (
+  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,
+  IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,
+  IN UINTN                              Count
+  )
+{
+  UINTN                             Index;
+
+  for (Index = 0; Index < Count; Index++) {
+    if ((Key->OptionType == Array[Index].OptionType) &&
+        (Key->Attributes == Array[Index].Attributes) &&
+        (StrCmp (Key->Description, Array[Index].Description) == 0) &&
+        (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&
+        (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&
+        (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {
+      return (INTN) Index;
+    }
+  }
+
+  return -1;
+}
+
+UINTN
+RegisterFvBootOption (
+  EFI_GUID                         *FileGuid,
+  CHAR16                           *Description,
+  UINTN                            Position,
+  UINT32                           Attributes,
+  UINT8                            *OptionalData,    OPTIONAL
+  UINT32                           OptionalDataSize
+  )
+{
+  EFI_STATUS                       Status;
+  UINTN                            OptionIndex;
+  EFI_BOOT_MANAGER_LOAD_OPTION     NewOption;
+  EFI_BOOT_MANAGER_LOAD_OPTION     *BootOptions;
+  UINTN                            BootOptionCount;
+
+  NewOption.OptionNumber = LoadOptionNumberUnassigned;
+  Status = CreateFvBootOption (FileGuid, Description, &NewOption, Attributes, OptionalData, OptionalDataSize);
+  if (!EFI_ERROR (Status)) {
+    BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
+
+    OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);
+
+    if (OptionIndex == -1) {
+      Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position);
+      ASSERT_EFI_ERROR (Status);
+    } else {
+      NewOption.OptionNumber = BootOptions[OptionIndex].OptionNumber;
+    }
+    EfiBootManagerFreeLoadOption (&NewOption);
+    EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
+  }
+
+  return NewOption.OptionNumber;
+}
+
+
+
+VOID
+EFIAPI
+PlatformBootManagerWaitCallback (
+  UINT16          TimeoutRemain
+  )
+{
+  EFI_STATUS                    Status;
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *TxtInEx;
+  EFI_KEY_DATA                  KeyData;
+  BOOLEAN                       PausePressed;
+
+  //
+  // Pause on PAUSE key
+  //
+  Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
+  ASSERT_EFI_ERROR (Status);
+
+  PausePressed = FALSE;
+
+  while (TRUE) {
+    Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);
+    if (EFI_ERROR (Status)) {
+      break;
+    }
+
+    if (KeyData.Key.ScanCode == SCAN_PAUSE) {
+      PausePressed = TRUE;
+      break;
+    }
+  }
+
+  //
+  // Loop until non-PAUSE key pressed
+  //
+  while (PausePressed) {
+    Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);
+    if (!EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_INFO, "[PauseCallback] %x/%x %x/%x\n",
+        KeyData.Key.ScanCode, KeyData.Key.UnicodeChar,
+        KeyData.KeyState.KeyShiftState, KeyData.KeyState.KeyToggleState
+        ));
+      PausePressed = (BOOLEAN) (KeyData.Key.ScanCode == SCAN_PAUSE);
+    }
+  }
+}
+
+
+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"
+
+VOID
+RegisterDefaultBootOption (
+  VOID
+  )
+{
+#if 0
+  EFI_DEVICE_PATH_PROTOCOL           *DevicePath;
+  EFI_LOADED_IMAGE_PROTOCOL          *LoadedImage;
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;
+#endif
+  UINT16                             *ShellData;
+  UINT32                             ShellDataSize;
+
+    ShellData = NULL;
+    ShellDataSize = 0;
+    RegisterFvBootOption (&gUefiShellFileGuid,      INTERNAL_UEFI_SHELL_NAME, (UINTN) -1, LOAD_OPTION_ACTIVE, (UINT8 *)ShellData, ShellDataSize);
+
+  //
+  // Boot Menu
+  //
+  mBootMenuOptionNumber = RegisterFvBootOption (&mBootMenuFile, L"Boot Device List",   (UINTN) -1, LOAD_OPTION_CATEGORY_APP | LOAD_OPTION_ACTIVE | LOAD_OPTION_HIDDEN, NULL, 0);
+
+  if (mBootMenuOptionNumber == LoadOptionNumberUnassigned) {
+    DEBUG ((DEBUG_INFO, "BootMenuOptionNumber (%d) should not be same to LoadOptionNumberUnassigned(%d).\n", mBootMenuOptionNumber, LoadOptionNumberUnassigned));
+  }
+#if 0
+  //
+  // Boot Manager Menu
+  //
+  EfiInitializeFwVolDevicepathNode (&FileNode, &mUiFile);
+
+  gBS->HandleProtocol (
+         gImageHandle,
+         &gEfiLoadedImageProtocolGuid,
+         (VOID **) &LoadedImage
+         );
+  DevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), (EFI_DEVICE_PATH_PROTOCOL *) &FileNode);
+#endif
+
+}
+
+VOID
+RegisterBootOptionHotkey (
+  UINT16                       OptionNumber,
+  EFI_INPUT_KEY                *Key,
+  BOOLEAN                      Add
+  )
+{
+  EFI_STATUS                   Status;
+
+  if (!Add) {
+    //
+    // No enter hotkey when force to setup or there is no boot option
+    //
+    Status = EfiBootManagerDeleteKeyOptionVariable (NULL, 0, Key, NULL);
+    ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);
+  } else {
+    //
+    // Register enter hotkey for the first boot option
+    //
+    Status = EfiBootManagerAddKeyOptionVariable (NULL, OptionNumber, 0, Key,NULL);
+    ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
+  }
+}
+
+EFI_STATUS
+EFIAPI
+DetectKeypressCallback (
+  IN EFI_KEY_DATA     *KeyData
+)
+{
+  mHotKeypressed = TRUE;
+
+  if (HotKeyEvent != NULL) {
+    gBS->SignalEvent(HotKeyEvent);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  This function is called after all the boot options are enumerated and ordered properly.
+**/
+VOID
+RegisterStaticHotkey (
+  VOID
+  )
+{
+
+  EFI_INPUT_KEY                 Enter;
+  EFI_KEY_DATA                  F2;
+  EFI_KEY_DATA                  F7;
+  BOOLEAN                       EnterSetup;
+  EFI_STATUS                    Status;
+  EFI_BOOT_MANAGER_LOAD_OPTION  BootOption;
+
+  EnterSetup = FALSE;
+
+  //
+  // [Enter]
+  //
+  mContinueBoot = !EnterSetup;
+  if (mContinueBoot) {
+    Enter.ScanCode    = SCAN_NULL;
+    Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
+    EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
+  }
+
+
+  //
+  // [F2]/[F7]
+  //
+  F2.Key.ScanCode    = SCAN_F2;
+  F2.Key.UnicodeChar = CHAR_NULL;
+  F2.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID;
+  F2.KeyState.KeyToggleState = 0;
+  Status = EfiBootManagerGetBootManagerMenu (&BootOption);
+  ASSERT_EFI_ERROR (Status);
+  RegisterBootOptionHotkey ((UINT16) BootOption.OptionNumber, &F2.Key, TRUE);
+  EfiBootManagerFreeLoadOption (&BootOption);
+
+  F7.Key.ScanCode    = SCAN_F7;
+  F7.Key.UnicodeChar = CHAR_NULL;
+  F7.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID;
+  F7.KeyState.KeyToggleState = 0;
+  mBootMenuBoot  = !EnterSetup;
+  RegisterBootOptionHotkey ((UINT16) mBootMenuOptionNumber, &F7.Key, mBootMenuBoot);
+
+}
+
+UINT8
+BootOptionType (
+  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath
+  )
+{
+  EFI_DEVICE_PATH_PROTOCOL      *Node;
+  EFI_DEVICE_PATH_PROTOCOL      *NextNode;
+
+  for (Node = DevicePath; !IsDevicePathEndType (Node); Node = NextDevicePathNode (Node)) {
+    if (DevicePathType (Node) == MESSAGING_DEVICE_PATH) {
+      //
+      // Make sure the device path points to the driver device.
+      //
+      NextNode = NextDevicePathNode (Node);
+      if (DevicePathSubType(NextNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {
+        //
+        // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),
+        // skip it
+        //
+        NextNode = NextDevicePathNode (NextNode);
+      }
+      if (IsDevicePathEndType (NextNode)) {
+        if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH)) {
+          return DevicePathSubType (Node);
+        } else {
+          return MSG_SATA_DP;
+        }
+      }
+    }
+  }
+
+  return (UINT8) -1;
+}
+
+/**
+  Returns the priority number.
+  OptionType                 EFI
+  ------------------------------------
+  PXE                         2
+  DVD                         4
+  USB                         6
+  NVME                        7
+  HDD                         8
+  EFI Shell                   9
+  Others                      100
+
+  @param BootOption
+**/
+UINTN
+BootOptionPriority (
+  CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
+  )
+{
+    //
+    // EFI boot options
+    //
+    switch (BootOptionType (BootOption->FilePath)) {
+    case MSG_MAC_ADDR_DP:
+    case MSG_VLAN_DP:
+    case MSG_IPv4_DP:
+    case MSG_IPv6_DP:
+      return 2;
+
+    case MSG_SATA_DP:
+    case MSG_ATAPI_DP:
+    case MSG_UFS_DP:
+    case MSG_NVME_NAMESPACE_DP:
+      return 4;
+
+    case MSG_USB_DP:
+      return 6;
+
+    }
+    if (StrCmp (BootOption->Description, INTERNAL_UEFI_SHELL_NAME) == 0) {
+      if (PcdGetBool (PcdBootToShellOnly)) {
+        return 0;
+      }
+      return 9;
+    }
+    if (StrCmp (BootOption->Description, UEFI_HARD_DRIVE_NAME) == 0) {
+      return 8;
+    }
+    return 100;
+}
+
+INTN
+EFIAPI
+CompareBootOption (
+  CONST VOID  *Left,
+  CONST VOID  *Right
+  )
+{
+  return BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Left) -
+         BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Right);
+}
+
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
deleted file mode 100644
index 4adca1b465..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
+++ /dev/null
@@ -1,3092 +0,0 @@
-/** @file
-
-  Copyright (c) 2004  - 2019, Intel Corporation. All rights reserved.<BR>
-                                                                                   
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-                                                                                   
-
-
-Module Name:
-
-  BdsPlatform.c
-
-Abstract:
-
-  This file include all platform action which can be customized
-  by IBV/OEM.
-
---*/
-
-#include "BdsPlatform.h"
-#include "SetupMode.h"
-#include <Guid/SetupVariable.h>
-#include <Library/TcgPhysicalPresenceLib.h>
-#include <Library/Tcg2PhysicalPresenceLib.h>
-#include <Protocol/I2cMasterMcg.h>
-#include <TianoApi.h>
-#include <PlatformBaseAddresses.h>
-#include <Protocol/GlobalNvsArea.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Protocol/BlockIo.h>
-#include <PchRegs/PchRegsPcu.h>
-#include <Library/S3BootScriptLib.h>
-#include "PchAccess.h"
-#include "PchRegs/PchRegsSata.h"
-#include <Library/SerialPortLib.h>
-#include <Library/DebugLib.h>
-
-#include <Library/GenericBdsLib/InternalBdsLib.h>
-#include <Library/GenericBdsLib/String.h>
-#include <Library/NetLib.h>
-
-#include <Library/CapsuleLib.h>
-#include <Protocol/EsrtManagement.h>
-
-EFI_GUID *ConnectDriverTable[] = {
-  &gEfiMmioDeviceProtocolGuid,
-  &gEfiI2cMasterProtocolGuid,
-  &gEfiI2cHostProtocolGuid
-};
-
-#define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \
-  { \
-    0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
-  }
-VOID               *mShellImageCallbackReg = NULL;
-
-
-
-EFI_USER_PROFILE_HANDLE                           mCurrentUser = NULL;
-EFI_EVENT                                         mHotKeyTimerEvent = NULL;
-EFI_EVENT                                         mHitHotkeyEvent = NULL;
-EFI_EVENT                                         mUsbKeyboardConnectEvent = NULL;
-BOOLEAN                                           mHotKeyPressed = FALSE;
-VOID                                              *mHitHotkeyRegistration;
-#define KEYBOARD_TIMER_INTERVAL                   20000 // 0.02s
-
-VOID
-ConnectUSBController (
-  VOID
-  );
-
-EFI_STATUS
-PlatformBdsConnectSimpleConsole (
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole
-);
-
-VOID 
-BootIntoFirmwareInterface(
-  VOID
-  );
-  
-VOID
-EFIAPI
-PlatformBdsInitHotKeyEvent (
-  VOID
-  );
-
-VOID
-EFIAPI
-DisableAhciCtlr (
-  IN EFI_EVENT                          Event,
-  IN VOID                               *Context
-  )
-{
-  UINT32                    PmcDisableAddress;
-  UINT8                     SataStorageAmount;
-  UINT32                    SataBase;
-  UINT16                    SataPortStatus;
-
-
-  DEBUG ((EFI_D_INFO, "Disable AHCI event is signalled\n"));
-  SataStorageAmount = 0;
-  SataBase = *(UINT32*) Context;
-
-  //
-  // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)
-  //
-  SataPortStatus = MmioRead16 (SataBase + R_PCH_SATA_PCS);
-
-  //
-  // Bit 8 EN: Port 0 Present
-  //
-  if ((SataPortStatus & 0x100) == 0x100) {
-    SataStorageAmount++;
-  }
-
-  //
-  // Bit 9 EN: Port 1 Present
-  //
-  if ((SataPortStatus & 0x200) == 0x200) {
-    SataStorageAmount++;
-  }
-
-  //
-  // Disable SATA controller when it sets to AHCI mode without carrying any devices
-  // in order to prevent AHCI yellow bang under Win device manager.
-  //
-  if (SataStorageAmount == 0) {
-    PmcDisableAddress = (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS + (UINT32) (31 << 15)) + R_PCH_LPC_PMC_BASE) & B_PCH_LPC_PMC_BASE_BAR) + R_PCH_PMC_FUNC_DIS;
-    MmioOr32 (PmcDisableAddress, B_PCH_PMC_FUNC_DIS_SATA);
-    S3BootScriptSaveMemWrite (
-      EfiBootScriptWidthUint32,
-      (UINTN) PmcDisableAddress,
-      1,
-      (VOID *) (UINTN) PmcDisableAddress
-      );
-  }
-}
-
-VOID
-InstallReadyToLock (
-  VOID
-  )
-{
-  EFI_STATUS                Status;
-  EFI_HANDLE                Handle;
-  EFI_SMM_ACCESS2_PROTOCOL  *SmmAccess;
-  EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
-
-  //
-  // Install DxeSmmReadyToLock protocol prior to the processing of boot options
-  //
-  Status = gBS->LocateProtocol (
-                  &gEfiSmmAccess2ProtocolGuid,
-                  NULL,
-                  (VOID **) &SmmAccess
-                  );
-  if (!EFI_ERROR (Status)) {
-
-    //
-    // Prepare S3 information, this MUST be done before DxeSmmReadyToLock
-    //
-    Status = gBS->LocateProtocol (
-                    &gEfiAcpiS3SaveProtocolGuid,
-                    NULL,
-                    (VOID **)&AcpiS3Save
-                    );
-    if (!EFI_ERROR (Status)) {
-      AcpiS3Save->S3Save (AcpiS3Save, NULL);
-    }
-
-    Handle = NULL;
-    Status = gBS->InstallProtocolInterface (
-                    &Handle,
-                    &gExitPmAuthProtocolGuid,
-                    EFI_NATIVE_INTERFACE,
-                    NULL
-                    );
-    ASSERT_EFI_ERROR (Status);
-
-    //
-    // Signal EndOfDxe PI Event
-    //
-    EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
-
-    Handle = NULL;
-    Status = gBS->InstallProtocolInterface (
-                    &Handle,
-                    &gEfiDxeSmmReadyToLockProtocolGuid,
-                    EFI_NATIVE_INTERFACE,
-                    NULL
-                    );
-    ASSERT_EFI_ERROR (Status);
-  }
-
-  return ;
-}
-
-VOID
-EFIAPI
-ShellImageCallback (
-  IN EFI_EVENT                          Event,
-  IN VOID                               *Context
-  )
-{
- BdsSetConsoleMode (TRUE);
- DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));
-}
-
-//
-// BDS Platform Functions
-//
-/**
-  Platform Bds init. Include the platform firmware vendor, revision
-  and so crc check.
-
-  @param VOID
-
-  @retval  None.
-
-**/
-VOID
-EFIAPI
-PlatformBdsInit (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-  EFI_EVENT   ShellImageEvent;
-  EFI_GUID    ShellEnvProtocol = SHELL_ENVIRONMENT_INTERFACE_PROTOCOL;
-
-  #ifdef __GNUC__
-  SerialPortWrite((UINT8 *)">>>>BdsEntry[GCC]\r\n", 19);
-  #else
-  SerialPortWrite((UINT8 *)">>>>BdsEntry\r\n", 14);
-  #endif
-  BdsLibSaveMemoryTypeInformation ();
-
-  //
-  // Before user authentication, the user identification devices need be connected
-  // from the platform customized device paths
-  //
-  PlatformBdsConnectAuthDevice ();
-
-  //
-  // As console is not ready, the auto logon user will be identified.
-  //
-  BdsLibUserIdentify (&mCurrentUser);
-
-  //
-  // Change Gop mode when boot into Shell
-  //
-  if (mShellImageCallbackReg == NULL) {
-    Status = gBS->CreateEvent (
-                    EFI_EVENT_NOTIFY_SIGNAL,
-                    EFI_TPL_CALLBACK,
-                    ShellImageCallback,
-                    NULL,
-                    &ShellImageEvent
-                    );
-    if (!EFI_ERROR (Status)) {
-      Status = gBS->RegisterProtocolNotify (
-                      &ShellEnvProtocol,
-                      ShellImageEvent,
-                      &mShellImageCallbackReg
-                      );
-
-      DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));
-    }
-  }
-}
-
-EFI_STATUS
-GetGopDevicePath (
-   IN  EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,
-   OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath
-   )
-{
-  UINTN                           Index;
-  EFI_STATUS                      Status;
-  EFI_HANDLE                      PciDeviceHandle;
-  EFI_DEVICE_PATH_PROTOCOL        *TempDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL        *TempPciDevicePath;
-  UINTN                           GopHandleCount;
-  EFI_HANDLE                      *GopHandleBuffer;
-
-  UINTN                                 VarSize;
-  SYSTEM_CONFIGURATION  mSystemConfiguration;
-
-  if (PciDevicePath == NULL || GopDevicePath == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Initialize the GopDevicePath to be PciDevicePath
-  //
-  *GopDevicePath    = PciDevicePath;
-  TempPciDevicePath = PciDevicePath;
-
-  Status = gBS->LocateDevicePath (
-                  &gEfiDevicePathProtocolGuid,
-                  &TempPciDevicePath,
-                  &PciDeviceHandle
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Try to connect this handle, so that GOP driver could start on this
-  // device and create child handles with GraphicsOutput Protocol installed
-  // on them, then we get device paths of these child handles and select
-  // them as possible console device.
-  //
-
-  //
-  // Select display devices
-  //
-  VarSize = sizeof(SYSTEM_CONFIGURATION);
-  Status = gRT->GetVariable(
-                  L"Setup",
-                  &gEfiNormalSetupGuid,
-                  NULL,
-                  &VarSize,
-                  &mSystemConfiguration
-                  );
-  if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
-    //The setup variable is corrupted
-    VarSize = sizeof(SYSTEM_CONFIGURATION);
-    Status = gRT->GetVariable(
-              L"SetupRecovery",
-              &gEfiNormalSetupGuid,
-              NULL,
-              &VarSize,
-              &mSystemConfiguration
-              );
-    ASSERT_EFI_ERROR (Status);
-  }    
-
-  if(mSystemConfiguration.BootDisplayDevice != 0x0)
-  {
-    ACPI_ADR_DEVICE_PATH         AcpiAdr;
-    EFI_DEVICE_PATH_PROTOCOL  *MyDevicePath = NULL;
-
-    AcpiAdr.Header.Type     = ACPI_DEVICE_PATH;
-    AcpiAdr.Header.SubType  = ACPI_ADR_DP;
-
-    switch (mSystemConfiguration.BootDisplayDevice) {
-    case 1:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0);    //CRT Device
-      break;
-    case 2:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_HDMI, 0);  //HDMI Device Port B
-      break;
-    case 3:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_DP, 0);    //DP PortB
-      break;
-    case 4:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_C_DP, 0);    //DP PortC
-      break;
-    case 5:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_C_DP, 0);    //eDP Port C
-      break;
-    case 6:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_A, 0);  //DSI Port A
-      break;
-    case 7:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_C, 0);  //DSI Port C
-      break;
-    default:
-      AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0);
-      break;
-    }
-
-    SetDevicePathNodeLength (&AcpiAdr.Header, sizeof (ACPI_ADR_DEVICE_PATH));
-
-    MyDevicePath = AppendDevicePathNode(MyDevicePath, (EFI_DEVICE_PATH_PROTOCOL*)&AcpiAdr);
-
-    gBS->ConnectController (
-           PciDeviceHandle,
-           NULL,
-           MyDevicePath,
-           FALSE
-           );
-
-    FreePool(MyDevicePath);
-  }
-  else
-  {
-    gBS->ConnectController (
-           PciDeviceHandle,
-           NULL,
-           NULL,
-           FALSE
-           );
-  }
-
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiGraphicsOutputProtocolGuid,
-                  NULL,
-                  &GopHandleCount,
-                  &GopHandleBuffer
-                  );
-  if (!EFI_ERROR (Status)) {
-    //
-    // Add all the child handles as possible Console Device
-    //
-    for (Index = 0; Index < GopHandleCount; Index++) {
-      Status = gBS->HandleProtocol (
-                      GopHandleBuffer[Index],
-                      &gEfiDevicePathProtocolGuid,
-                      (VOID**)&TempDevicePath
-                      );
-      if (EFI_ERROR (Status)) {
-        continue;
-      }
-      if (CompareMem (
-            PciDevicePath,
-            TempDevicePath,
-            GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH
-            ) == 0) {
-        //
-        // In current implementation, we only enable one of the child handles
-        // as console device, i.e. sotre one of the child handle's device
-        // path to variable "ConOut"
-        // In future, we could select all child handles to be console device
-        //
-        *GopDevicePath = TempDevicePath;
-      }
-    }
-    gBS->FreePool (GopHandleBuffer);
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-
-  Search out all the platform pci or agp video device. The function may will
-  find multiple video device, and return all enabled device path.
-
-  @param PlugInPciVgaDevicePath    Return the platform plug in pci video device
-                                   path if the system have plug in pci video device.
-  @param OnboardPciVgaDevicePath   Return the platform active agp video device path
-                                   if the system have plug in agp video device or on
-                                   chip agp device.
-
-  @retval EFI_SUCCSS               Get all platform active video device path.
-  @retval EFI_STATUS               Return the status of gBS->LocateDevicePath (),
-                                   gBS->ConnectController (),
-                                   and gBS->LocateHandleBuffer ().
-
-**/
-EFI_STATUS
-GetPlugInPciVgaDevicePath (
-  IN OUT EFI_DEVICE_PATH_PROTOCOL     **PlugInPciVgaDevicePath,
-  IN OUT EFI_DEVICE_PATH_PROTOCOL     **OnboardPciVgaDevicePath
-  )
-{
-  EFI_STATUS                Status;
-  EFI_HANDLE                RootHandle;
-  UINTN                     HandleCount;
-  EFI_HANDLE                *HandleBuffer;
-  UINTN                     Index;
-  UINTN                     Index1;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  BOOLEAN                   PlugInPciVga;
-  EFI_PCI_IO_PROTOCOL       *PciIo;
-  PCI_TYPE00                Pci;
-
-  DevicePath = NULL;
-  PlugInPciVga = TRUE;
-  HandleCount = 0;
-  HandleBuffer = NULL;
-
-  //
-  // Make all the PCI_IO protocols on PCI Seg 0 show up
-  //
-  BdsLibConnectDevicePath (gPlatformRootBridges[0]);
-
-  Status = gBS->LocateDevicePath (
-                  &gEfiDevicePathProtocolGuid,
-                  &gPlatformRootBridges[0],
-                  &RootHandle
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = gBS->ConnectController (
-                  RootHandle,
-                  NULL,
-                  NULL,
-                  FALSE
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Start to check all the pci io to find all possible VGA device
-  //
-  HandleCount = 0;
-  HandleBuffer = NULL;
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiPciIoProtocolGuid,
-                  NULL,
-                  &HandleCount,
-                  &HandleBuffer
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  for (Index = 0; Index < HandleCount; Index++) {
-    Status = gBS->HandleProtocol (
-                    HandleBuffer[Index],
-                    &gEfiPciIoProtocolGuid,
-                    (VOID**)&PciIo
-                    );
-    if (!EFI_ERROR (Status)) {
-
-      //
-      // Check for all VGA device
-      //
-      Status = PciIo->Pci.Read (
-                        PciIo,
-                        EfiPciIoWidthUint32,
-                        0,
-                        sizeof (Pci) / sizeof (UINT32),
-                        &Pci
-                        );
-      if (EFI_ERROR (Status)) {
-        continue;
-      }
-
-      //
-      // Here we decide which VGA device to enable in PCI bus
-      //
-      // The first plugin PCI VGA card device will be present as PCI VGA
-      // The onchip AGP or AGP card will be present as AGP VGA
-      //
-      if (!IS_PCI_VGA (&Pci)) {
-        continue;
-      }
-
-      //
-      // Set the device as the possible console out device,
-      //
-      // Below code will make every VGA device to be one
-      // of the possibe console out device
-      //
-      PlugInPciVga = TRUE;
-      gBS->HandleProtocol (
-             HandleBuffer[Index],
-             &gEfiDevicePathProtocolGuid,
-             (VOID**)&DevicePath
-             );
-
-      Index1 = 0;
-
-      while (gPlatformAllPossiblePciVgaConsole[Index1] != NULL) {
-        if (CompareMem (
-              DevicePath,
-              gPlatformAllPossiblePciVgaConsole[Index1],
-              GetDevicePathSize (gPlatformAllPossiblePciVgaConsole[Index1])
-              ) == 0) {
-
-          //
-          // This device is an AGP device
-          //
-          *OnboardPciVgaDevicePath = DevicePath;
-          PlugInPciVga = FALSE;
-          break;
-        }
-
-        Index1 ++;
-      }
-
-      if (PlugInPciVga) {
-        *PlugInPciVgaDevicePath = DevicePath;
-      }
-    }
-  }
-
-  FreePool (HandleBuffer);
-
-  return EFI_SUCCESS;
-}
-
-/**
-
-  Find the platform  active vga, and base on the policy to enable the vga as
-  the console out device. The policy is driven by one setup variable "VBIOS".
-
-  None.
-
-  @param EFI_UNSUPPORTED         There is no active vga device
-
-  @retval EFI_STATUS             Return the status of BdsLibGetVariableAndSize ()
-
-**/
-EFI_STATUS
-PlatformBdsForceActiveVga (
-  VOID
-  )
-{
-  EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *PlugInPciVgaDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *OnboardPciVgaDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePathFirst;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePathSecond;
-  EFI_DEVICE_PATH_PROTOCOL  *GopDevicePath;
-  UINTN                VarSize;
-  SYSTEM_CONFIGURATION  mSystemConfiguration;
-
-  Status = EFI_SUCCESS;
-  PlugInPciVgaDevicePath = NULL;
-  OnboardPciVgaDevicePath = NULL;
-
-  //
-  // Check the policy which is the first enabled VGA
-  //
-  GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath, &OnboardPciVgaDevicePath);
-
-  if (PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath == NULL) {
-    return EFI_UNSUPPORTED;
-  }
-
-  VarSize = sizeof(SYSTEM_CONFIGURATION);
-  Status = gRT->GetVariable(
-                  L"Setup",
-                  &gEfiNormalSetupGuid,
-                  NULL,
-                  &VarSize,
-                  &mSystemConfiguration
-                  );
-  if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
-    //The setup variable is corrupted
-    VarSize = sizeof(SYSTEM_CONFIGURATION);
-    Status = gRT->GetVariable(
-              L"SetupRecovery",
-              &gEfiNormalSetupGuid,
-              NULL,
-              &VarSize,
-              &mSystemConfiguration
-              );
-    ASSERT_EFI_ERROR (Status);
-  }    
-
-
-  if ((PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath != NULL) ) {
-    DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA ...\n"));
-    DevicePathFirst  = OnboardPciVgaDevicePath;
-    DevicePathSecond = PlugInPciVgaDevicePath;
-    goto UpdateConOut;
-  }
-  if(OnboardPciVgaDevicePath != NULL && mSystemConfiguration.PrimaryVideoAdaptor == 0) {
-    DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA When set primary!!!...\n"));
-    DevicePathFirst  = OnboardPciVgaDevicePath;
-    DevicePathSecond = PlugInPciVgaDevicePath;
-    goto UpdateConOut;
-  }
-
-  DEBUG ((EFI_D_ERROR,"Update plug in PCI VGA ...\n"));
-  DevicePathFirst  = PlugInPciVgaDevicePath;
-  DevicePathSecond = OnboardPciVgaDevicePath;
-
-UpdateConOut:
-  GetGopDevicePath (DevicePathFirst, &GopDevicePath);
-  DevicePathFirst = GopDevicePath;
-
-  Status = BdsLibUpdateConsoleVariable (
-             L"ConOut",
-             DevicePathFirst,
-             DevicePathSecond
-             );
-
-  return Status;
-}
-
-VOID
-UpdateConsoleResolution(
-  VOID
-  )
-{
-  UINT32                 HorizontalResolution;
-  UINT32                 VerticalResolution;
-  SYSTEM_CONFIGURATION   SystemConfiguration;
-  UINTN                  VarSize;
-  EFI_STATUS             Status;
-
-
-  HorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
-  VerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
-
-  VarSize = sizeof(SYSTEM_CONFIGURATION);
-  Status = gRT->GetVariable(
-                  L"Setup",
-                  &gEfiNormalSetupGuid,
-                  NULL,
-                  &VarSize,
-                  &SystemConfiguration
-                  );
-  if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
-    //The setup variable is corrupted
-    VarSize = sizeof(SYSTEM_CONFIGURATION);
-    Status = gRT->GetVariable(
-              L"SetupRecovery",
-              &gEfiNormalSetupGuid,
-              NULL,
-              &VarSize,
-              &SystemConfiguration
-              );
-    ASSERT_EFI_ERROR (Status);
-  }  
-
-  switch (SystemConfiguration.IgdFlatPanel) {
-
-  case 0:
-    //
-    // Use the detault PCD values.
-    //
-    break;
-
-  case 1:
-    HorizontalResolution = 640;
-    VerticalResolution = 480;
-    break;
-
-  case 2:
-    HorizontalResolution = 800;
-    VerticalResolution = 600;
-    break;
-
-  case 3:
-    HorizontalResolution = 1024;
-    VerticalResolution = 768;
-    break;
-
-  case 4:
-  HorizontalResolution = 1280;
-  VerticalResolution = 1024;
-  break;
-
-  case 5:
-  HorizontalResolution = 1366;
-  VerticalResolution = 768;
-  break;
-
-  case 6:
-  HorizontalResolution = 1680;
-  VerticalResolution = 1050;
-  break;
-
-  case 7:
-  HorizontalResolution = 1920;
-  VerticalResolution = 1200;
-  break;
-
-  case 8:
-  HorizontalResolution = 1280;
-  VerticalResolution = 800;
-  break;
-  }
-
-  PcdSet32 (PcdSetupVideoHorizontalResolution, HorizontalResolution);
-  PcdSet32 (PcdSetupVideoVerticalResolution, VerticalResolution);
-  DEBUG ((EFI_D_ERROR, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution, VerticalResolution));
-
-  return;
-}
-
-/**
-  Connect the predefined platform default console device. Always try to find
-  and enable the vga device if have.
-
-  @param PlatformConsole    Predefined platform default console device array.
-
-  @retval EFI_SUCCESS       Success connect at least one ConIn and ConOut
-                            device, there must have one ConOut device is
-                            active vga device.
-
-  @retval EFI_STATUS        Return the status of
-                            BdsLibConnectAllDefaultConsoles ()
-
-**/
-EFI_STATUS
-PlatformBdsConnectConsole (
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole
-)
-{
-  EFI_STATUS                         Status;
-  UINTN                              Index;
-  EFI_DEVICE_PATH_PROTOCOL           *VarConout;
-  EFI_DEVICE_PATH_PROTOCOL           *VarConin;
-  UINTN                              DevicePathSize;
-
-  UpdateConsoleResolution();
-
-  Index = 0;
-  Status = EFI_SUCCESS;
-  DevicePathSize = 0;
-  VarConout = BdsLibGetVariableAndSize (
-                L"ConOut",
-                &gEfiGlobalVariableGuid,
-                &DevicePathSize
-                );
-  VarConin = BdsLibGetVariableAndSize (
-               L"ConIn",
-               &gEfiGlobalVariableGuid,
-               &DevicePathSize
-               );
-  if (VarConout == NULL || VarConin == NULL) {
-    //
-    // Have chance to connect the platform default console,
-    // the platform default console is the minimum device group
-    // the platform should support
-    //
-    while (PlatformConsole[Index].DevicePath != NULL) {
-
-      //
-      // Update the console variable with the connect type
-      //
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
-        BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
-        BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
-        BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      Index ++;
-    }
-  }
-
-  //
-  // Make sure we have at least one active VGA, and have the right
-  // active VGA in console variable
-  //
-  Status = PlatformBdsForceActiveVga ();
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  DEBUG ((EFI_D_INFO, "DISPLAY INIT DONE\n"));
-
-  //
-  // Connect the all the default console with current console variable
-  //
-  Status = BdsLibConnectAllDefaultConsoles ();
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Connect with predefined platform connect sequence,
-  the OEM/IBV can customize with their own connect sequence.
-
-  @param None.
-
-  @retval None.
-
-**/
-VOID
-PlatformBdsConnectSequence (
-  VOID
-  )
-{
-  UINTN                     Index;
-
-  Index = 0;
-
-  //
-  // Here we can get the customized platform connect sequence
-  // Notes: we can connect with new variable which record the
-  // last time boots connect device path sequence
-  //
-  while (gPlatformConnectSequence[Index] != NULL) {
-
-    //
-    // Build the platform boot option
-    //
-    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
-    Index ++;
-  }
-
-  //
-  // Just use the simple policy to connect all devices
-  // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.
-  //
-  // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.
-  // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.
-  //
-  // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().
-  // We may also consider to connect SataController only later if needed.
-  //
-  BdsLibConnectAll ();
-}
-
-/**
-
-  Load the predefined driver option, OEM/IBV can customize this
-  to load their own drivers
-
-  @param BdsDriverLists  The header of the driver option link list.
-
-  @retval None.
-
-**/
-VOID
-PlatformBdsGetDriverOption (
-  IN OUT LIST_ENTRY                  *BdsDriverLists
-  )
-{
-  UINTN                              Index;
-
-  Index = 0;
-
-  //
-  // Here we can get the customized platform driver option
-  //
-  while (gPlatformDriverOption[Index] != NULL) {
-
-    //
-    // Build the platform boot option
-    //
-    BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
-    Index ++;
-  }
-
-}
-
-/**
-  This function is used for some critical time if the the system
-  have no any boot option, and there is no time out for user to add
-  the new boot option. This can also treat as the platform default
-  boot option.
-
-  @param BdsBootOptionList   The header of the boot option link list.
-
-  @retval None.
-
-**/
-VOID
-PlatformBdsPredictBootOption (
-  IN OUT LIST_ENTRY                  *BdsBootOptionList
-  )
-{
-  UINTN                              Index;
-
-  Index = 0;
-
-  //
-  // Here give chance to get platform boot option data
-  //
-  while (gPlatformBootOption[Index] != NULL) {
-
-    //
-    // Build the platform boot option
-    //
-    BdsLibRegisterNewOption (BdsBootOptionList, gPlatformBootOption[Index], NULL, L"BootOrder");
-    Index ++;
-  }
-}
-
-/**
-  Perform the platform diagnostic, such like test memory. OEM/IBV also
-  can customize this fuction to support specific platform diagnostic.
-
-  @param MemoryTestLevel   The memory test intensive level
-  @param QuietBoot         Indicate if need to enable the quiet boot
-  @param BaseMemoryTest    A pointer to BdsMemoryTest()
-
-  @retval  None.
-
-**/
-VOID
-PlatformBdsDiagnostics (
-  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,
-  IN BOOLEAN                     QuietBoot,
-  IN BASEM_MEMORY_TEST           BaseMemoryTest
-  )
-{
-  EFI_STATUS                     Status;
-
-  //
-  // Here we can decide if we need to show
-  // the diagnostics screen
-  // Notes: this quiet boot code should be remove
-  // from the graphic lib
-  //
-  if (QuietBoot) {
-    EnableQuietBoot (PcdGetPtr(PcdLogoFile));
-
-    //
-    // Perform system diagnostic
-    //
-    Status = BaseMemoryTest (MemoryTestLevel);
-    if (EFI_ERROR (Status)) {
-      DisableQuietBoot ();
-    }
-
-    return;
-  }
-
-  //
-  // Perform system diagnostic
-  //
-  Status = BaseMemoryTest (MemoryTestLevel);
-}
-
-
-/**
-  For EFI boot option, BDS separate them as six types:
-  1. Network - The boot option points to the SimpleNetworkProtocol device.
-               Bds will try to automatically create this type boot option when enumerate.
-  2. Shell   - The boot option points to internal flash shell.
-               Bds will try to automatically create this type boot option when enumerate.
-  3. Removable BlockIo      - The boot option only points to the removable media
-                              device, like USB flash disk, DVD, Floppy etc.
-                              These device should contain a *removable* blockIo
-                              protocol in their device handle.
-                              Bds will try to automatically create this type boot option
-                              when enumerate.
-  4. Fixed BlockIo          - The boot option only points to a Fixed blockIo device,
-                              like HardDisk.
-                              These device should contain a *fixed* blockIo
-                              protocol in their device handle.
-                              BDS will skip fixed blockIo devices, and NOT
-                              automatically create boot option for them. But BDS
-                              will help to delete those fixed blockIo boot option,
-                              whose description rule conflict with other auto-created
-                              boot options.
-  5. Non-BlockIo Simplefile - The boot option points to a device whose handle
-                              has SimpleFileSystem Protocol, but has no blockio
-                              protocol. These devices do not offer blockIo
-                              protocol, but BDS still can get the
-                              \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
-                              Protocol.
-  6. File    - The boot option points to a file. These boot options are usually
-               created by user manually or OS loader. BDS will not delete or modify
-               these boot options.
-
-  This function will enumerate all possible boot device in the system, and
-  automatically create boot options for Network, Shell, Removable BlockIo,
-  and Non-BlockIo Simplefile devices.
-  It will only execute once of every boot.
-
-  @param  BdsBootOptionList      The header of the link list which indexed all
-                                 current boot options
-
-  @retval EFI_SUCCESS            Finished all the boot device enumerate and create
-                                 the boot option base on that boot device
-
-  @retval EFI_OUT_OF_RESOURCES   Failed to enumerate the boot device and create the boot option list
-**/
-EFI_STATUS
-EFIAPI
-PlatformBdsLibEnumerateAllBootOption (
-  IN OUT LIST_ENTRY          *BdsBootOptionList
-  )
-{
-  EFI_STATUS                    Status;
-  UINT16                        FloppyNumber;
-  UINT16                        HarddriveNumber;
-  UINT16                        CdromNumber;
-  UINT16                        UsbNumber;
-  UINT16                        MiscNumber;
-  UINT16                        ScsiNumber;
-  UINT16                        NonBlockNumber;
-  UINTN                         NumberBlockIoHandles;
-  EFI_HANDLE                    *BlockIoHandles;
-  EFI_BLOCK_IO_PROTOCOL         *BlkIo;
-  BOOLEAN                       Removable[2];
-  UINTN                         RemovableIndex;
-  UINTN                         Index;
-  UINTN                         NumOfLoadFileHandles;
-  EFI_HANDLE                    *LoadFileHandles;
-  UINTN                         FvHandleCount;
-  EFI_HANDLE                    *FvHandleBuffer;
-  EFI_FV_FILETYPE               Type;
-  UINTN                         Size;
-  EFI_FV_FILE_ATTRIBUTES        Attributes;
-  UINT32                        AuthenticationStatus;
-  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
-  UINTN                         DevicePathType;
-  CHAR16                        Buffer[40];
-  EFI_HANDLE                    *FileSystemHandles;
-  UINTN                         NumberFileSystemHandles;
-  BOOLEAN                       NeedDelete;
-  EFI_IMAGE_DOS_HEADER          DosHeader;
-  CHAR8                         *PlatLang;
-  CHAR8                         *LastLang;
-  EFI_IMAGE_OPTIONAL_HEADER_UNION       HdrData;
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;
-  CHAR16                        *MacStr;
-  CHAR16                        *IPverStr;
-  EFI_HANDLE                    *NetworkHandles;
-  UINTN                         BufferSize;
-
-  FloppyNumber    = 0;
-  HarddriveNumber = 0;
-  CdromNumber     = 0;
-  UsbNumber       = 0;
-  MiscNumber      = 0;
-  ScsiNumber      = 0;
-  PlatLang        = NULL;
-  LastLang        = NULL;
-  ZeroMem (Buffer, sizeof (Buffer));
-
-  //
-  // If the boot device enumerate happened, just get the boot
-  // device from the boot order variable
-  //
-  if (mEnumBootDevice) {
-    GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);
-    GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);
-    ASSERT (PlatLang != NULL);
-    if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {
-      Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
-      FreePool (LastLang);
-      FreePool (PlatLang);
-      return Status;
-    } else {
-      Status = gRT->SetVariable (
-        LAST_ENUM_LANGUAGE_VARIABLE_NAME,
-        &gLastEnumLangGuid,
-        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-        AsciiStrSize (PlatLang),
-        PlatLang
-        );
-      //
-      // Failure to set the variable only impacts the performance next time enumerating the boot options.
-      //
-
-      if (LastLang != NULL) {
-        FreePool (LastLang);
-      }
-      FreePool (PlatLang);
-    }
-  }
-
-  //
-  // Notes: this dirty code is to get the legacy boot option from the
-  // BBS table and create to variable as the EFI boot option, it should
-  // be removed after the CSM can provide legacy boot option directly
-  //
-  REFRESH_LEGACY_BOOT_OPTIONS;
-
-  //
-  // Delete invalid boot option
-  //
-  BdsDeleteAllInvalidEfiBootOption ();
-
-  //
-  // Parse removable media followed by fixed media.
-  // The Removable[] array is used by the for-loop below to create removable media boot options 
-  // at first, and then to create fixed media boot options.
-  //
-  Removable[0]  = FALSE;
-  Removable[1]  = TRUE;
-
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiBlockIoProtocolGuid,
-        NULL,
-        &NumberBlockIoHandles,
-        &BlockIoHandles
-        );
-
-  for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {
-    for (Index = 0; Index < NumberBlockIoHandles; Index++) {
-      Status = gBS->HandleProtocol (
-                      BlockIoHandles[Index],
-                      &gEfiBlockIoProtocolGuid,
-                      (VOID **) &BlkIo
-                      );
-      //
-      // skip the logical partition
-      //
-      if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {
-        continue;
-      }
-
-      //
-      // firstly fixed block io then the removable block io
-      //
-      if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {
-        continue;
-      }
-      DevicePath  = DevicePathFromHandle (BlockIoHandles[Index]);
-      DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
-
-      switch (DevicePathType) {
-      case BDS_EFI_ACPI_FLOPPY_BOOT:
-        if (FloppyNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        FloppyNumber++;
-        break;
-
-      //
-      // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
-      //
-      case BDS_EFI_MESSAGE_ATAPI_BOOT:
-      case BDS_EFI_MESSAGE_SATA_BOOT:
-        if (BlkIo->Media->RemovableMedia) {
-          if (CdromNumber != 0) {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);
-          } else {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));
-          }
-          CdromNumber++;
-        } else {
-          if (HarddriveNumber != 0) {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);
-          } else {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));
-          }
-          HarddriveNumber++;
-        }
-        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        break;
-
-      case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
-        if (UsbNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        UsbNumber++;
-        break;
-
-      case BDS_EFI_MESSAGE_SCSI_BOOT:
-        if (ScsiNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        ScsiNumber++;
-        break;
-
-      case BDS_EFI_MESSAGE_MISC_BOOT:
-      default:
-        if (MiscNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        MiscNumber++;
-        break;
-      }
-    }
-  }
-
-  if (NumberBlockIoHandles != 0) {
-    FreePool (BlockIoHandles);
-  }
-
-  //
-  // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
-  //
-  NonBlockNumber = 0;
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiSimpleFileSystemProtocolGuid,
-        NULL,
-        &NumberFileSystemHandles,
-        &FileSystemHandles
-        );
-  for (Index = 0; Index < NumberFileSystemHandles; Index++) {
-    Status = gBS->HandleProtocol (
-                    FileSystemHandles[Index],
-                    &gEfiBlockIoProtocolGuid,
-                    (VOID **) &BlkIo
-                    );
-     if (!EFI_ERROR (Status)) {
-      //
-      //  Skip if the file system handle supports a BlkIo protocol,
-      //
-      continue;
-    }
-
-    //
-    // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
-    //  machinename is ia32, ia64, x64, ...
-    //
-    Hdr.Union  = &HdrData;
-    NeedDelete = TRUE;
-    Status     = BdsLibGetImageHeader (
-                   FileSystemHandles[Index],
-                   EFI_REMOVABLE_MEDIA_FILE_NAME,
-                   &DosHeader,
-                   Hdr
-                   );
-    if (!EFI_ERROR (Status) &&
-        EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
-        Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
-      NeedDelete = FALSE;
-    }
-
-    if (NeedDelete) {
-      //
-      // No such file or the file is not a EFI application, delete this boot option
-      //
-      BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
-    } else {
-      if (NonBlockNumber != 0) {
-        UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);
-      } else {
-        UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));
-      }
-      BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
-      NonBlockNumber++;
-    }
-  }
-
-  if (NumberFileSystemHandles != 0) {
-    FreePool (FileSystemHandles);
-  }
-
-  //
-  // Check if we have on flash shell
-  //
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiFirmwareVolume2ProtocolGuid,
-        NULL,
-        &FvHandleCount,
-        &FvHandleBuffer
-        );
-  for (Index = 0; Index < FvHandleCount; Index++) {
-    gBS->HandleProtocol (
-          FvHandleBuffer[Index],
-          &gEfiFirmwareVolume2ProtocolGuid,
-          (VOID **) &Fv
-          );
-
-    Status = Fv->ReadFile (
-                  Fv,
-                  &gUefiShellFileGuid,
-                  NULL,
-                  &Size,
-                  &Type,
-                  &Attributes,
-                  &AuthenticationStatus
-                  );
-    if (EFI_ERROR (Status)) {
-      //
-      // Skip if no shell file in the FV
-      //
-      continue;
-    }
-    //
-    // Build the shell boot option
-    //
-    BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
-  }
-
-  if (FvHandleCount != 0) {
-    FreePool (FvHandleBuffer);
-  }
-
-  //
-  // Parse Network Boot Device
-  //
-  NumOfLoadFileHandles = 0;
-  //
-  // Search Load File protocol for PXE boot option.
-  //
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiLoadFileProtocolGuid,
-        NULL,
-        &NumOfLoadFileHandles,
-        &LoadFileHandles
-        );
-
-  for (Index = 0; Index < NumOfLoadFileHandles; Index++) {
-
-//
-//Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
-//
-
- Status = gBS->HandleProtocol (
-                  LoadFileHandles[Index],
-                  &gEfiDevicePathProtocolGuid,
-                  (VOID **) &DevicePath
-                  );
-  
- ASSERT_EFI_ERROR (Status);
-
-  while (!IsDevicePathEnd (DevicePath)) {
-    if ((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
-        (DevicePath->SubType == MSG_IPv4_DP)) {
-
-  //
-  //Get handle infomation
-  //
-  BufferSize = 0;
-  NetworkHandles = NULL;
-  Status = gBS->LocateHandle (
-                  ByProtocol, 
-                  &gEfiSimpleNetworkProtocolGuid,
-                  NULL,
-                  &BufferSize,
-                  NetworkHandles
-                  );
-
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    NetworkHandles = AllocateZeroPool(BufferSize);
-    if (NetworkHandles == NULL) {
-      return (EFI_OUT_OF_RESOURCES);
-    }
-    Status = gBS->LocateHandle(
-                    ByProtocol,
-                    &gEfiSimpleNetworkProtocolGuid,
-                    NULL,
-                    &BufferSize,
-                    NetworkHandles
-                    );
- }
-               
-  //
-  //Get the MAC string
-  //
-  Status = NetLibGetMacString (
-             *NetworkHandles,
-             NULL,
-             &MacStr
-             );
-  if (EFI_ERROR (Status)) {	
-    return Status;
-  }
-  IPverStr = L" IPv4";
-  UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
-  break;
-  }
-    if((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
-        (DevicePath->SubType == MSG_IPv6_DP)) {
-
-  //
-  //Get handle infomation
-  //
-  BufferSize = 0;
-  NetworkHandles = NULL;
-  Status = gBS->LocateHandle (
-                  ByProtocol, 
-                  &gEfiSimpleNetworkProtocolGuid,
-                  NULL,
-                  &BufferSize,
-                  NetworkHandles
-                  );
-
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    NetworkHandles = AllocateZeroPool(BufferSize);
-    if (NetworkHandles == NULL) {
-       return (EFI_OUT_OF_RESOURCES);
-    }
-    Status = gBS->LocateHandle(
-                    ByProtocol,
-                    &gEfiSimpleNetworkProtocolGuid,
-                    NULL,
-                    &BufferSize,
-                    NetworkHandles
-                    );
- }
-                    
-  //
-  //Get the MAC string
-  //
-  Status = NetLibGetMacString (
-             *NetworkHandles,
-             NULL,
-             &MacStr
-             );
-  if (EFI_ERROR (Status)) {	
-    return Status;
-  }
-      IPverStr = L" IPv6";
-      UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
-      break;
-    }
-    DevicePath = NextDevicePathNode (DevicePath);
-  }
-  
-    BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);
-  }
-
-  if (NumOfLoadFileHandles != 0) {
-    FreePool (LoadFileHandles);
-  }
-
-  //
-  // Check if we have on flash shell
-  //
- /* gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiFirmwareVolume2ProtocolGuid,
-        NULL,
-        &FvHandleCount,
-        &FvHandleBuffer
-        );
-  for (Index = 0; Index < FvHandleCount; Index++) {
-    gBS->HandleProtocol (
-          FvHandleBuffer[Index],
-          &gEfiFirmwareVolume2ProtocolGuid,
-          (VOID **) &Fv
-          );
-
-    Status = Fv->ReadFile (
-                  Fv,
-                  &gUefiShellFileGuid,
-                  NULL,
-                  &Size,
-                  &Type,
-                  &Attributes,
-                  &AuthenticationStatus
-                  );
-    if (EFI_ERROR (Status)) {
-      //
-      // Skip if no shell file in the FV
-      //
-      continue;
-    }
-    //
-    // Build the shell boot option
-    //
-    BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
-  }
-
-  if (FvHandleCount != 0) {
-    FreePool (FvHandleBuffer);
-  } */
-  
-  //
-  // Make sure every boot only have one time
-  // boot device enumerate
-  //
-  Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
-  mEnumBootDevice = TRUE;
-
-  return Status;
-} 
-
-
-
-/**
-
-  The function will execute with as the platform policy, current policy
-  is driven by boot mode. IBV/OEM can customize this code for their specific
-  policy action.
-
-  @param DriverOptionList - The header of the driver option link list
-  @param  BootOptionList   - The header of the boot option link list
-  @param ProcessCapsules  - A pointer to ProcessCapsules()
-  @param BaseMemoryTest   - A pointer to BaseMemoryTest()
-
-  @retval None.
-
-**/
-VOID
-EFIAPI
-PlatformBdsPolicyBehavior (
-  IN OUT LIST_ENTRY                  *DriverOptionList,
-  IN OUT LIST_ENTRY                  *BootOptionList,
-  IN PROCESS_CAPSULES                BdsProcessCapsules,
-  IN BASEM_MEMORY_TEST               BaseMemoryTest
-  )
-{
-  EFI_STATUS                         Status;
-  UINT16                             Timeout;
-  EFI_BOOT_MODE                      BootMode;
-  BOOLEAN                            DeferredImageExist;
-  UINTN                              Index;
-  SYSTEM_CONFIGURATION               SystemConfiguration;
-  UINTN                              VarSize;
-  PLATFORM_PCI_DEVICE_PATH           *EmmcBootDevPath;
-  EFI_GLOBAL_NVS_AREA_PROTOCOL       *GlobalNvsArea;
-  EFI_HANDLE                         FvProtocolHandle;
-  UINTN                              HandleCount;
-  EFI_HANDLE                         *HandleBuffer;
-  UINTN                              Index1;
-  UINTN                              SataPciRegBase = 0;
-  UINT16                             SataModeSelect = 0;
-  VOID                               *RegistrationExitPmAuth = NULL;
-  EFI_EVENT                          Event;
-  BOOLEAN                            IsFirstBoot;
-  UINT16                             *BootOrder;
-  UINTN                              BootOrderSize;
-  ESRT_MANAGEMENT_PROTOCOL           *EsrtManagement;
-
-  Timeout = PcdGet16 (PcdPlatformBootTimeOut);
-  if (Timeout > 10 ) {
-    //we think the Timeout variable is corrupted
-    Timeout = 10;
-  }
-
-  VarSize = sizeof(SYSTEM_CONFIGURATION);
-  Status = gRT->GetVariable(
-                  NORMAL_SETUP_NAME,
-                  &gEfiNormalSetupGuid,
-                  NULL,
-                  &VarSize,
-                  &SystemConfiguration
-                  );
-
-  if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
-    //The setup variable is corrupted
-    VarSize = sizeof(SYSTEM_CONFIGURATION);
-    Status = gRT->GetVariable(
-              L"SetupRecovery",
-              &gEfiNormalSetupGuid,
-              NULL,
-              &VarSize,
-              &SystemConfiguration
-              );
-    ASSERT_EFI_ERROR (Status);
-  }
-
-  //
-  // Load the driver option as the driver option list
-  //
-  PlatformBdsGetDriverOption (DriverOptionList);
-
-  //
-  // Get current Boot Mode
-  //
-  BootMode = GetBootModeHob();
-
-  //
-  // No deferred images exist by default
-  //
-  DeferredImageExist = FALSE;
-  if ((BootMode != BOOT_WITH_MINIMAL_CONFIGURATION) && (PcdGet32(PcdFlashFvShellSize) > 0)){
-    gDS->ProcessFirmwareVolume (
-           (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),
-           PcdGet32(PcdFlashFvShellSize),
-           &FvProtocolHandle
-           );
-  }
-
-  if (SystemConfiguration.FastBoot == 1) {
-    BootOrder = BdsLibGetVariableAndSize (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  &BootOrderSize
-                  );
-    if ((BootOrder != NULL) && (BootMode != BOOT_ON_FLASH_UPDATE)) {
-      //
-      // BootOrder exist, it means system has boot before. We can do fast boot.
-      //
-      BootMode = BOOT_WITH_MINIMAL_CONFIGURATION;
-    }
-  }
-
-
-  //
-  // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,
-  // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.
-  //
-  SataPciRegBase  = MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, 0, 0);
-  SataModeSelect  = MmioRead16 (SataPciRegBase + R_PCH_SATA_MAP) & B_PCH_SATA_MAP_SMS_MASK;
-  Status          = EFI_SUCCESS;
-  if (SataModeSelect != V_PCH_SATA_MAP_SMS_IDE) {
-    Status = gBS->CreateEvent (
-                    EVT_NOTIFY_SIGNAL,
-                    TPL_CALLBACK,
-                    DisableAhciCtlr,
-                    &SataPciRegBase,
-                    &Event
-                     );
-    if (!EFI_ERROR (Status)) {
-      Status = gBS->RegisterProtocolNotify (
-                      &gExitPmAuthProtocolGuid,
-                      Event,
-                      &RegistrationExitPmAuth
-                      );
-    }
-  }
-
-  Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement);
-  if (EFI_ERROR(Status)) {
-    EsrtManagement = NULL;
-  }
-
-  DEBUG ((DEBUG_INFO, "BDS: BootMode=%02x\n", BootMode));
-
-  switch (BootMode) {
-
-  case BOOT_WITH_MINIMAL_CONFIGURATION:
-    PlatformBdsInitHotKeyEvent ();
-    PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole);
-
-
-    //
-    // Check to see if it's needed to dispatch more DXE drivers.
-    //
-    for (Index = 0; Index < sizeof(ConnectDriverTable)/sizeof(EFI_GUID *); Index++) {
-      Status = gBS->LocateHandleBuffer (
-                      ByProtocol,
-                      ConnectDriverTable[Index],
-                      NULL,
-                      &HandleCount,
-                      &HandleBuffer
-                      );
-      if (!EFI_ERROR (Status)) {
-        for (Index1 = 0; Index1 < HandleCount; Index1++) {
-          gBS->ConnectController (
-                 HandleBuffer[Index1],
-                 NULL,
-                 NULL,
-                 TRUE
-                 );
-        }
-      }
-
-      if (HandleBuffer != NULL) {
-        FreePool (HandleBuffer);
-      }
-
-      gDS->Dispatch ();
-    }
-
-    //
-    //  Locate the Global NVS Protocol.
-    //
-    Status = gBS->LocateProtocol (
-                    &gEfiGlobalNvsAreaProtocolGuid,
-                    NULL,
-                    (void **)&GlobalNvsArea
-                    );
-    if (GlobalNvsArea->Area->emmcVersion == 0){
-      EmmcBootDevPath = (PLATFORM_PCI_DEVICE_PATH *)gPlatformSimpleBootOption[0];
-      EmmcBootDevPath->PciDevice.Device = 0x10;
-    }
-
-    //
-    // Connect boot device here to give time to read keyboard.
-    //
-    BdsLibConnectDevicePath (gPlatformSimpleBootOption[0]);
-
-    //
-    // This is a workround for dectecting hotkey from USB keyboard.
-    //
-    gBS->Stall(KEYBOARD_TIMER_INTERVAL);
-
-    if (mHotKeyTimerEvent != NULL) {
-      gBS->SetTimer (
-             mHotKeyTimerEvent,
-             TimerCancel,
-             0
-             );
-      gBS->CloseEvent (mHotKeyTimerEvent);
-      mHotKeyTimerEvent = NULL;
-    }
-    if (mHotKeyPressed) {
-      //
-      // Skip show progress count down
-      //
-      Timeout = 0xFFFF;
-      goto FULL_CONFIGURATION;
-    }
-
-    EnableQuietBoot (PcdGetPtr(PcdLogoFile));
-    if (!SystemConfiguration.QuietBoot) {
-      PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);
-    }
-
-
-    #ifdef TPM_ENABLED
-    TcgPhysicalPresenceLibProcessRequest();
-    #endif
-
-    if (EsrtManagement != NULL) {
-      EsrtManagement->LockEsrtRepository();
-    }
-
-    //
-    // Close boot script and install ready to lock
-    //
-    InstallReadyToLock ();
-
-    //
-    // Give one chance to enter the setup if we
-    // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.
-    //
-    BootIntoFirmwareInterface();
-    break;
-
-  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
-
-    //
-    // In no-configuration boot mode, we can connect the
-    // console directly.
-    //
-    BdsLibConnectAllDefaultConsoles ();
-    PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);
-
-    //
-    // Perform some platform specific connect sequence
-    //
-    PlatformBdsConnectSequence ();
-
-    //
-    // As console is ready, perform user identification again.
-    //
-    if (mCurrentUser == NULL) {
-      PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
-      if (DeferredImageExist) {
-        //
-        // After user authentication, the deferred drivers was loaded again.
-        // Here, need to ensure the deferred images are connected.
-        //
-        BdsLibConnectAllDefaultConsoles ();
-        PlatformBdsConnectSequence ();
-      }
-    }
-
-    if (EsrtManagement != NULL) {
-      EsrtManagement->LockEsrtRepository();
-    }
-
-    //
-    // Close boot script and install ready to lock
-    //
-    InstallReadyToLock ();
-
-    //
-    // Notes: current time out = 0 can not enter the
-    // front page
-    //
-    PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
-
-    //
-    // Check the boot option with the boot option list
-    //
-    BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
-    break;
-
-  case BOOT_ON_FLASH_UPDATE:
-
-    //
-    // Boot with the specific configuration
-    //
-    PlatformBdsConnectConsole (gPlatformConsole);
-    PlatformBdsDiagnostics (EXTENSIVE, TRUE, BaseMemoryTest);
-
-    DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe......\n"));
-    ProcessCapsules ();
-    DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));
-
-    //
-    // Close boot script and install ready to lock
-    //
-    InstallReadyToLock ();
-
-    BdsLibConnectAll ();
-
-    //
-    // Perform user identification
-    //
-    if (mCurrentUser == NULL) {
-      PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
-      if (DeferredImageExist) {
-        //
-        // After user authentication, the deferred drivers was loaded again.
-        // Here, need to ensure the deferred images are connected.
-        //
-        BdsLibConnectAll ();
-      }
-    }
-
-    if (EsrtManagement != NULL) {
-      EsrtManagement->SyncEsrtFmp();
-    }
-
-    DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll......\n"));
-    ProcessCapsules();
-    DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));
-    break;
-
-  case BOOT_IN_RECOVERY_MODE:
-
-    //
-    // In recovery mode, just connect platform console
-    // and show up the front page
-    //
-    PlatformBdsConnectConsole (gPlatformConsole);
-    PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);
-    BdsLibConnectAll ();
-
-    //
-    // Perform user identification
-    //
-    if (mCurrentUser == NULL) {
-      PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
-      if (DeferredImageExist) {
-        //
-        // After user authentication, the deferred drivers was loaded again.
-        // Here, need to ensure the deferred drivers are connected.
-        //
-        BdsLibConnectAll ();
-      }
-    }
-
-    //
-    // Close boot script and install ready to lock
-    //
-    InstallReadyToLock ();
-
-    //
-    // In recovery boot mode, we still enter to the
-    // frong page now
-    //
-    PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
-    break;
-
-FULL_CONFIGURATION:
-  case BOOT_WITH_FULL_CONFIGURATION:
-  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
-  case BOOT_WITH_DEFAULT_SETTINGS:
-  default:
-
-    //
-    // Connect platform console
-    //
-    Status = PlatformBdsConnectConsole (gPlatformConsole);
-    if (EFI_ERROR (Status)) {
-
-      //
-      // Here OEM/IBV can customize with defined action
-      //
-      PlatformBdsNoConsoleAction ();
-    }
-
-    //
-    // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,
-    // Need to root cause this issue.
-    //
-    DEBUG ((DEBUG_ERROR, "Start to reconnect all driver.\n"));
-    BdsLibDisconnectAllEfi();
-    BdsLibConnectAll ();
-    DEBUG ((DEBUG_ERROR, "End to reconnect all driver.\n"));
-
-    //
-    // Perform some platform specific connect sequence
-    //
-    PlatformBdsConnectSequence ();
-    EnableQuietBoot (PcdGetPtr(PcdLogoFile));
-    if (!SystemConfiguration.QuietBoot) {
-      PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);
-    }
-
-    //
-    // Do a pre-delay so Hard Disk can spin up and see more logo.
-    //
-    gBS->Stall(SystemConfiguration.HddPredelay * 1000000);
-
-    //
-    // Perform user identification
-    //
-    if (mCurrentUser == NULL) {
-      PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);
-      if (DeferredImageExist) {
-        //
-        // After user authentication, the deferred drivers was loaded again.
-        // Here, need to ensure the deferred drivers are connected.
-        //
-        Status = PlatformBdsConnectConsole (gPlatformConsole);
-        if (EFI_ERROR (Status)) {
-          PlatformBdsNoConsoleAction ();
-        }
-        PlatformBdsConnectSequence ();
-      }
-    }
-   #ifdef TPM_ENABLED
-   TcgPhysicalPresenceLibProcessRequest();
-   #endif
-
-    if (EsrtManagement != NULL) {
-      EsrtManagement->SyncEsrtFmp();
-    }
-    //
-    // Close boot script and install ready to lock
-    //
-    InstallReadyToLock ();
-
-    //
-    // Here we have enough time to do the enumeration of boot device
-    //
-    PlatformBdsLibEnumerateAllBootOption (BootOptionList);
-
-    //
-    // Give one chance to enter the setup if we
-    // have the time out
-    //
-    PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);
-
-	//
-	// Give one chance to enter the setup if we
-	// select Gummiboot "Reboot Into Firmware Interface"
-	//
-	BootIntoFirmwareInterface();
-
-    //
-    // In default boot mode, always find all boot
-    // option and do enumerate all the default boot option
-    //
-    if (Timeout == 0) {
-      BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
-      if (IsListEmpty(BootOptionList)) {
-        PlatformBdsPredictBootOption (BootOptionList);
-      }
-
-      return;
-    }
-
-
-    break;
-  }
-
-
-  IsFirstBoot = PcdGetBool(PcdBootState);
-  if (IsFirstBoot) {
-    PcdSetBool(PcdBootState, FALSE);
-  }
-  return;
-
-}
-
-/**
-  Hook point after a boot attempt succeeds. We don't expect a boot option to
-  return, so the UEFI 2.0 specification defines that you will default to an
-  interactive mode and stop processing the BootOrder list in this case. This
-  is alos a platform implementation and can be customized by IBV/OEM.
-
-  @param Option  Pointer to Boot Option that succeeded to boot.
-
-  @retval None.
-
-**/
-VOID
-EFIAPI
-PlatformBdsBootSuccess (
-  IN  BDS_COMMON_OPTION *Option
-  )
-{
-  CHAR16  *TmpStr;
-
-  //
-  // If Boot returned with EFI_SUCCESS and there is not in the boot device
-  // select loop then we need to pop up a UI and wait for user input.
-  //
-  TmpStr =  Option->StatusString;
-  if (TmpStr != NULL) {
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
-    FreePool(TmpStr);
-  }
-}
-
-/**
-  Hook point after a boot attempt fails.
-
-  @param Option - Pointer to Boot Option that failed to boot.
-  @param Status - Status returned from failed boot.
-  @param ExitData - Exit data returned from failed boot.
-  @param ExitDataSize - Exit data size returned from failed boot.
-
-  @retval None.
-
-**/
-VOID
-EFIAPI
-PlatformBdsBootFail (
-  IN  BDS_COMMON_OPTION  *Option,
-  IN  EFI_STATUS         Status,
-  IN  CHAR16             *ExitData,
-  IN  UINTN              ExitDataSize
-  )
-{
-  CHAR16          *TmpStr;
-  EFI_HANDLE      FvProtocolHandle;
-
-  //
-  // If Boot returned with failed status then we need to pop up a UI and wait
-  // for user input.
-  //
-  TmpStr = Option->StatusString;
-  if (TmpStr != NULL) {
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
-    FreePool(TmpStr);
-  }
-  if (PcdGet32(PcdFlashFvShellSize) > 0){
-    gDS->ProcessFirmwareVolume (
-           (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),
-           PcdGet32(PcdFlashFvShellSize),
-           &FvProtocolHandle
-           );
-  }
-  PlatformBdsConnectSequence ();
-}
-
-/**
-  This function is remained for IBV/OEM to do some platform action,
-  if there no console device can be connected.
-
-  @param  None.
-
-  @retval EFI_SUCCESS       Direct return success now.
-
-**/
-EFI_STATUS
-PlatformBdsNoConsoleAction (
-  VOID
-  )
-{
-  return EFI_SUCCESS;
-}
-
-/**
-  This function locks the block
-
-  @param Base            The base address flash region to be locked.
-
-**/
-VOID
-BdsLockFv (
-  IN EFI_PHYSICAL_ADDRESS  Base
-  )
-{
-  EFI_FV_BLOCK_MAP_ENTRY      *BlockMap;
-  EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
-  EFI_PHYSICAL_ADDRESS        BaseAddress;
-  UINT32                      BlockLength;
-  UINTN                       Index;
-
-  BaseAddress = Base - 0x400000 + 2;
-  FvHeader    = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base));
-  BlockMap    = &(FvHeader->BlockMap[0]);
-
-  while ((BlockMap->NumBlocks != 0) && (BlockMap->Length != 0)) {
-    BlockLength = BlockMap->Length;
-    for (Index = 0; Index < BlockMap->NumBlocks; Index++) {
-      MmioOr8 ((UINTN) BaseAddress, 0x03);
-      BaseAddress += BlockLength;
-    }
-    BlockMap++;
-  }
-}
-
-VOID
-EFIAPI
-PlatformBdsLockNonUpdatableFlash (
-  VOID
-  )
-{
-  EFI_PHYSICAL_ADDRESS  Base;
-
-  Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvMainBase);
-  if (Base > 0) {
-    BdsLockFv (Base);
-  }
-
-  Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvRecoveryBase);
-  if (Base > 0) {
-    BdsLockFv (Base);
-  }
-}
-
-/**
-  Lock the ConsoleIn device in system table. All key
-  presses will be ignored until the Password is typed in. The only way to
-  disable the password is to type it in to a ConIn device.
-
-  @param  Password        Password used to lock ConIn device.
-
-  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.
-  @retval EFI_UNSUPPORTED Password not found
-
-**/
-EFI_STATUS
-EFIAPI
-LockKeyboards (
-  IN  CHAR16    *Password
-  )
-{
-    return EFI_UNSUPPORTED;
-}
-
-/**
-  Connect the predefined platform default authentication devices.
-
-  This function connects the predefined device path for authentication device,
-  and if the predefined device path has child device path, the child handle will
-  be connected too. But the child handle of the child will not be connected.
-
-**/
-VOID
-EFIAPI
-PlatformBdsConnectAuthDevice (
-  VOID
-  )
-{
-  EFI_STATUS                   Status;
-  UINTN                        Index;
-  UINTN                        HandleIndex;
-  UINTN                        HandleCount;
-  EFI_HANDLE                   *HandleBuffer;
-  EFI_DEVICE_PATH_PROTOCOL     *ChildDevicePath;
-  EFI_USER_MANAGER_PROTOCOL    *Manager;
-
-  Status = gBS->LocateProtocol (
-                  &gEfiUserManagerProtocolGuid,
-                  NULL,
-                  (VOID **) &Manager
-                  );
-  if (EFI_ERROR (Status)) {
-    //
-    // As user manager protocol is not installed, the authentication devices
-    // should not be connected.
-    //
-    return ;
-  }
-
-  Index = 0;
-  while (gUserAuthenticationDevice[Index] != NULL) {
-    //
-    // Connect the platform customized device paths
-    //
-    BdsLibConnectDevicePath (gUserAuthenticationDevice[Index]);
-    Index++;
-  }
-
-  //
-  // Find and connect the child device paths of the platform customized device paths
-  //
-  HandleBuffer = NULL;
-  for (Index = 0; gUserAuthenticationDevice[Index] != NULL; Index++) {
-    HandleCount = 0;
-    Status = gBS->LocateHandleBuffer (
-                    AllHandles,
-                    NULL,
-                    NULL,
-                    &HandleCount,
-                    &HandleBuffer
-                    );
-    ASSERT (!EFI_ERROR (Status));
-
-    //
-    // Find and connect the child device paths of gUserIdentificationDevice[Index]
-    //
-    for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
-      ChildDevicePath = NULL;
-      Status = gBS->HandleProtocol (
-                      HandleBuffer[HandleIndex],
-                      &gEfiDevicePathProtocolGuid,
-                      (VOID **) &ChildDevicePath
-                      );
-      if (EFI_ERROR (Status) || ChildDevicePath == NULL) {
-        continue;
-      }
-
-      if (CompareMem (
-            ChildDevicePath,
-            gUserAuthenticationDevice[Index],
-            (GetDevicePathSize (gUserAuthenticationDevice[Index]) - sizeof (EFI_DEVICE_PATH_PROTOCOL))
-            ) != 0) {
-        continue;
-      }
-      gBS->ConnectController (
-             HandleBuffer[HandleIndex],
-             NULL,
-             NULL,
-             TRUE
-             );
-    }
-  }
-
-  if (HandleBuffer != NULL) {
-    FreePool (HandleBuffer);
-  }
-}
-
-/**
-  This function is to identify a user, and return whether deferred images exist.
-
-  @param[out]  User               Point to user profile handle.
-  @param[out]  DeferredImageExist On return, points to TRUE if the deferred image
-                                  exist or FALSE if it did not exist.
-
-**/
-VOID
-EFIAPI
-PlatformBdsUserIdentify (
-  OUT EFI_USER_PROFILE_HANDLE        *User,
-  OUT BOOLEAN                        *DeferredImageExist
-  )
-{
-  EFI_STATUS                         Status;
-  EFI_DEFERRED_IMAGE_LOAD_PROTOCOL   *DeferredImage;
-  UINTN                              HandleCount;
-  EFI_HANDLE                         *HandleBuf;
-  UINTN                              Index;
-  UINTN                              DriverIndex;
-  EFI_DEVICE_PATH_PROTOCOL           *ImageDevicePath;
-  VOID                               *DriverImage;
-  UINTN                              ImageSize;
-  BOOLEAN                            BootOption;
-
-  //
-  // Perform user identification
-  //
-  do {
-    Status = BdsLibUserIdentify (User);
-  } while (EFI_ERROR (Status));
-
-  //
-  // After user authentication now, try to find whether deferred image exists
-  //
-  HandleCount = 0;
-  HandleBuf   = NULL;
-  *DeferredImageExist = FALSE;
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiDeferredImageLoadProtocolGuid,
-                  NULL,
-                  &HandleCount,
-                  &HandleBuf
-                  );
-  if (EFI_ERROR (Status)) {
-    return ;
-  }
-
-  for (Index = 0; Index < HandleCount; Index++) {
-    Status = gBS->HandleProtocol (
-                    HandleBuf[Index],
-                    &gEfiDeferredImageLoadProtocolGuid,
-                    (VOID **) &DeferredImage
-                    );
-    if (!EFI_ERROR (Status)) {
-      //
-      // Find whether deferred image exists in this instance.
-      //
-      DriverIndex = 0;
-      Status = DeferredImage->GetImageInfo(
-                                DeferredImage,
-                                DriverIndex,
-                                &ImageDevicePath,
-                                (VOID **) &DriverImage,
-                                &ImageSize,
-                                &BootOption
-                                );
-      if (!EFI_ERROR (Status)) {
-        //
-        // The deferred image is found.
-        //
-        FreePool (HandleBuf);
-        *DeferredImageExist = TRUE;
-        return ;
-      }
-    }
-  }
-
-  FreePool (HandleBuf);
-}
-
-UINTN gHotKey = 0;
-
-
-EFI_STATUS
-ShowProgressHotKey (
-  IN UINT16                       TimeoutDefault
-  )
-{
-  CHAR16                        *TmpStr;
-  UINT16                        TimeoutRemain;
-  EFI_STATUS                    Status;
-  EFI_INPUT_KEY                 Key;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
-  UINT32                        GpioValue;
-  CHAR16                        *TmpStr1;
-  CHAR16                        *TmpStr2;
-  CHAR16                        *TmpStr3;
-  UINTN                         TmpStrSize;
-  VOID                          *Buffer;
-  UINTN                         Size;
-
-  if (TimeoutDefault == 0) {
-    return EFI_TIMEOUT;
-  }
-
-  gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
-    
-  if (DebugAssertEnabled())
-  {
-    DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it, or press <F2> or <DEL> to enter setup page! ...Zzz....\n"));
-  }
-  else
-  {  
-    #ifdef __GNUC__
-    SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);
-    #else
-    SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);
-    #endif
-  } 
-  SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
-  SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
-  SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
-
-  TmpStr2 = NULL;
-  TmpStr3 = NULL;
-
-  //
-  // Check if the platform is using test key.
-  //
-  Status = GetSectionFromAnyFv(
-             PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid),
-             EFI_SECTION_RAW,
-             0,
-             &Buffer,
-             &Size
-             );
-  if (!EFI_ERROR(Status)) {
-    if ((Size == PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer)) &&
-        (CompareMem(Buffer, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer), Size) == 0)) {
-      TmpStr2 = L"WARNING: Recovery Test Key is used.\r\n";
-      if (DebugAssertEnabled()) {
-        DEBUG ((DEBUG_INFO, "\n\nWARNING: Recovery Test Key is used.\n"));
-      } else {
-        SerialPortWrite((UINT8 *)"\n\nWARNING: Recovery Test Key is used.", sizeof("\n\nWARNING: Recovery Test Key is used."));
-      }
-      PcdSetBoolS(PcdTestKeyUsed, TRUE);
-    }
-    FreePool(Buffer);
-  }
-  Status = GetSectionFromAnyFv(
-             PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid),
-             EFI_SECTION_RAW,
-             0,
-             &Buffer,
-             &Size
-             );
-  if (!EFI_ERROR(Status)) {
-    if ((Size == PcdGetSize(PcdPkcs7CertBuffer)) &&
-        (CompareMem(Buffer, PcdGetPtr(PcdPkcs7CertBuffer), Size) == 0)) {
-      TmpStr3 = L"WARNING: Capsule Test Key is used.\r\n";
-      if (DebugAssertEnabled()) {
-        DEBUG ((DEBUG_INFO, "\n\nWARNING: Capsule Test Key is used.\r\n"));
-      } else {
-        SerialPortWrite((UINT8 *)"\n\nWARNING: Capsule Test Key is used.", sizeof("\n\nWARNING: Capsule Test Key is used."));
-      }
-      PcdSetBoolS(PcdTestKeyUsed, TRUE);
-    }
-    FreePool(Buffer);
-  }
-
-  //
-  // Clear the progress status bar first
-  //
-  TmpStr1 = L"Start boot option, Press <F2> or <DEL> to enter setup page.\r\n";
-  TmpStrSize = StrSize(TmpStr1);
-  if (TmpStr2 != NULL) {
-    TmpStrSize += StrSize(TmpStr2);
-  }
-  if (TmpStr3 != NULL) {
-    TmpStrSize += StrSize(TmpStr3);
-  }
-  TmpStr = AllocatePool (TmpStrSize);
-  if (TmpStr == NULL) {
-    TmpStr = TmpStr1;
-  } else {
-    StrCpyS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr1);
-    if (TmpStr2 != NULL) {
-      StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr2);
-    }
-    if (TmpStr3 != NULL) {
-      StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr3);
-    }
-  }
-  PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);
-
-  TimeoutRemain = TimeoutDefault;
-  while (TimeoutRemain != 0) {
-    if (DebugAssertEnabled())
-    {
-    DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));
-    }
-    else
-    {	
-    SerialPortWrite ((UINT8 *)".", 1);
-    }
-    Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);
-    if (Status != EFI_TIMEOUT) {
-      break;
-    }
-    TimeoutRemain--;
-
-    //
-    // Show progress
-    //
-    if (TmpStr != NULL) {
-      PlatformBdsShowProgress (
-        Foreground,
-        Background,
-        TmpStr,
-        Color,
-        ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),
-        0
-        );
-    }
-  }
-
-  //
-  // Timeout expired
-  //
-  if (TimeoutRemain == 0) {
-    if (DebugAssertEnabled())
-	{
-	}
-    else
-    {	
-    SerialPortWrite ((UINT8 *)"\r\n", 2);
-    }
-    return EFI_TIMEOUT;
-  }
-
-  //
-  // User pressed some key
-  //
-  Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Check Volume Up Key to enter Setup
-  //
-  GpioValue = MmioRead32 (IO_BASE_ADDRESS + 0x0668);  // The value of GPIOC_5
-  if (((GpioValue & BIT0) == 0) && (Key.ScanCode == SCAN_UP)) {
-    gHotKey = 0;
-    return EFI_SUCCESS;
-  }
-
-  if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
-    //
-    // User pressed enter, equivalent to select "continue"
-    //
-    return EFI_TIMEOUT;
-  }
-
-  //
-  //F2 --  Front Page
-  //F5 --  Device Manager
-  //F7 --  Boot Manager
-  // do not use F8. generally people assume it is windows safe mode key.
-  //F9 --  Boot order
-  //
-  DEBUG ((EFI_D_INFO, "[Key Pressed]: ScanCode 0x%x\n", Key.ScanCode));
-  switch(Key.ScanCode) {
-      case SCAN_F2:
-          gHotKey = 0;
-          break;
-
-      case SCAN_DELETE:
-          gHotKey = 0;
-          break;
-
-      case SCAN_F5:
-          gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
-          break;
-
-      case SCAN_F7:
-          gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;
-          break;
-
-      case SCAN_F9:
-          gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;
-          break;
-
-      default:
-          //set gHotKey to continue so that flow will not go into CallFrontPage
-          gHotKey = FRONT_PAGE_KEY_CONTINUE;
-          return EFI_TIMEOUT;
-          break;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-
-/**
-  This function is the main entry of the platform setup entry.
-  The function will present the main menu of the system setup,
-  this is the platform reference part and can be customize.
-
-
-  @param TimeoutDefault     The fault time out value before the system
-                            continue to boot.
-  @param ConnectAllHappened The indicater to check if the connect all have
-                            already happened.
-
-**/
-VOID
-PlatformBdsEnterFrontPageWithHotKey (
-  IN UINT16                       TimeoutDefault,
-  IN BOOLEAN                      ConnectAllHappened
-  )
-{
-  EFI_STATUS                    Status;
-
-  EFI_STATUS                         LogoStatus;
-  EFI_BOOT_LOGO_PROTOCOL             *BootLogo;
-  EFI_GRAPHICS_OUTPUT_PROTOCOL       *GraphicsOutput;
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *SimpleTextOut;
-  UINTN                              BootTextColumn;
-  UINTN                              BootTextRow;
-
-  GraphicsOutput = NULL;
-  SimpleTextOut = NULL;
-
-  PERF_START (NULL, "BdsTimeOut", "BDS", 0);
-
-  //
-  // Indicate if we need connect all in the platform setup
-  //
-  if (ConnectAllHappened) {
-    gConnectAllHappened = TRUE;
-  }
-
-  if (!mModeInitialized) {
-    //
-    // After the console is ready, get current video resolution
-    // and text mode before launching setup at first time.
-    //
-    Status = gBS->HandleProtocol (
-                    gST->ConsoleOutHandle,
-                    &gEfiGraphicsOutputProtocolGuid,
-                    (VOID**)&GraphicsOutput
-                    );
-    if (EFI_ERROR (Status)) {
-      GraphicsOutput = NULL;
-    }
-
-    Status = gBS->HandleProtocol (
-                    gST->ConsoleOutHandle,
-                    &gEfiSimpleTextOutProtocolGuid,
-                    (VOID**)&SimpleTextOut
-                    );
-    if (EFI_ERROR (Status)) {
-      SimpleTextOut = NULL;
-    }
-
-    if (GraphicsOutput != NULL) {
-      //
-      // Get current video resolution and text mode.
-      //
-      mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
-      mBootVerticalResolution   = GraphicsOutput->Mode->Info->VerticalResolution;
-    }
-
-    if (SimpleTextOut != NULL) {
-      Status = SimpleTextOut->QueryMode (
-                                SimpleTextOut,
-                                SimpleTextOut->Mode->Mode,
-                                &BootTextColumn,
-                                &BootTextRow
-                                );
-      mBootTextModeColumn = (UINT32)BootTextColumn;
-      mBootTextModeRow    = (UINT32)BootTextRow;
-    }
-
-    //
-    // Get user defined text mode for setup.
-    //
-    mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
-    mSetupVerticalResolution   = PcdGet32 (PcdSetupVideoVerticalResolution);
-    mSetupTextModeColumn       = PcdGet32 (PcdSetupConOutColumn);
-    mSetupTextModeRow          = PcdGet32 (PcdSetupConOutRow);
-
-    mModeInitialized           = TRUE;
-  }
-
-  if (TimeoutDefault != 0xffff) {
-    Status = ShowProgressHotKey (TimeoutDefault);
-
-    //
-    // Ensure screen is clear when switch Console from Graphics mode to Text mode
-    //
-    gST->ConOut->EnableCursor (gST->ConOut, TRUE);
-    gST->ConOut->ClearScreen (gST->ConOut);
-
-    //
-    // Boot Logo is corrupted, report it using Boot Logo protocol.
-    //
-    LogoStatus = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
-    if (!EFI_ERROR (LogoStatus) && (BootLogo != NULL)) {
-      BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
-    }
-
-    if (EFI_ERROR (Status)) {
-      //
-      // Timeout or user press enter to continue
-      //
-      goto Exit;
-    }
-  }
-
-  //
-  // Install BM HiiPackages. 
-  // Keep BootMaint HiiPackage, so that it can be covered by global setting. 
-  //
-	InitBMPackage ();
-  do {
-
-    BdsSetConsoleMode (TRUE);
-
-    InitializeFrontPage (FALSE);
-
-    //
-    // Update Front Page strings
-    //
-    UpdateFrontPageStrings ();
-
-    Status = EFI_SUCCESS;
-    gCallbackKey = 0;
-    if (gHotKey == 0) {
-      Status = CallFrontPage ();
-    } else {
-      gCallbackKey = gHotKey;
-      gHotKey = 0;
-    }
-
-    //
-    // If gCallbackKey is greater than 1 and less or equal to 5,
-    // it will launch configuration utilities.
-    // 2 = set language
-    // 3 = boot manager
-    // 4 = device manager
-    // 5 = boot maintenance manager
-    //
-    if (gCallbackKey != 0) {
-      REPORT_STATUS_CODE (
-        EFI_PROGRESS_CODE,
-        (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
-        );
-    }
-
-    //
-    // Based on the key that was set, we can determine what to do
-    //
-    switch (gCallbackKey) {
-    //
-    // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
-    // describe to their customers in documentation how to find their setup information (namely
-    // under the device manager and specific buckets)
-    //
-    // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
-    //
-    case FRONT_PAGE_KEY_CONTINUE:
-
-      //
-      // User hit continue
-      //
-      break;
-
-    case FRONT_PAGE_KEY_LANGUAGE:
-
-      //
-      // User made a language setting change - display front page again
-      //
-      break;
-
-    case FRONT_PAGE_KEY_BOOT_MANAGER:
-      //
-	  // Remove the installed BootMaint HiiPackages when exit.
-      //
-      FreeBMPackage ();
-
-      //
-      // User chose to run the Boot Manager
-      //
-      CallBootManager ();
-	  
-	  //
-      // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
-      //
-      InitBMPackage ();
-      break;
-
-    case FRONT_PAGE_KEY_DEVICE_MANAGER:
-
-      //
-      // Display the Device Manager
-      //
-      do {
-        CallDeviceManager ();
-      } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);
-      break;
-
-    case FRONT_PAGE_KEY_BOOT_MAINTAIN:
-
-      //
-      // Display the Boot Maintenance Manager
-      //
-      BdsStartBootMaint ();
-      break;
-    }
-
-  } while (((UINTN)gCallbackKey) != FRONT_PAGE_KEY_CONTINUE);
-
-  //
-  //Will leave browser, check any reset required change is applied? if yes, reset system
-  //
-  SetupResetReminder ();
-  //
-  // Remove the installed BootMaint HiiPackages when exit.
-  //
-  FreeBMPackage ();
-
-Exit:
-  //
-  // Automatically load current entry
-  // Note: The following lines of code only execute when Auto boot
-  // takes affect
-  //
-  PERF_END (NULL, "BdsTimeOut", "BDS", 0);
-}
-
-
-VOID 
-BootIntoFirmwareInterface(
-VOID
-)
-{
-  EFI_STATUS        Status;
-  UINTN             DataSize;
-  UINT16            Timeout;    
-  UINT64            OsIndication;
-
-  
-  OsIndication = 0;
-  DataSize = sizeof(UINT64);
-  Status = gRT->GetVariable (
-                  L"OsIndications",
-                  &gEfiGlobalVariableGuid,
-                  NULL,
-                  &DataSize,
-                  &OsIndication
-                  );
-				  
-  DEBUG ((EFI_D_INFO, "OSIndication Variable Value %d\n", OsIndication));
-  //
-  //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.
-  //  
-  if (!EFI_ERROR(Status) && (OsIndication != 0)) {				  
-   Timeout = 0xffff;
-   PlatformBdsEnterFrontPage (Timeout, FALSE);
-   }
-}
-
-
-EFI_STATUS
-PlatformBdsConnectSimpleConsole (
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole
-)
-{
-  EFI_STATUS                         Status;
-  UINTN                              Index;
-  EFI_DEVICE_PATH_PROTOCOL           *VarConout;
-  EFI_DEVICE_PATH_PROTOCOL           *VarConin;
-  UINTN                              DevicePathSize;
-
-
-  Index = 0;
-  Status = EFI_SUCCESS;
-  DevicePathSize = 0;
-  VarConout = BdsLibGetVariableAndSize (
-                L"ConOut",
-                &gEfiGlobalVariableGuid,
-                &DevicePathSize
-                );
-  VarConin = BdsLibGetVariableAndSize (
-               L"ConIn",
-               &gEfiGlobalVariableGuid,
-               &DevicePathSize
-               );
-  if (VarConout == NULL || VarConin == NULL) {
-    //
-    // Have chance to connect the platform default console,
-    // the platform default console is the minimum device group
-    // the platform should support
-    //
-    while (PlatformConsole[Index].DevicePath != NULL) {
-
-      //
-      // Update the console variable with the connect type
-      //
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
-        BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
-        BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
-        BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
-      }
-
-      Index ++;
-    }
-  }
-
-  //
-  // Connect ConIn first to give keyboard time to parse hot key event.
-  //
-  Status = BdsLibConnectConsoleVariable (L"ConIn");
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Make sure we have at least one active VGA, and have the right
-  // active VGA in console variable
-  //
-  Status = PlatformBdsForceActiveVga ();
-
-  //
-  // It seems impossible not to have any ConOut device on platform,
-  // so we check the status here.
-  //
-  Status = BdsLibConnectConsoleVariable (L"ConOut");
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Timer handler to convert the key from USB.
-
-  @param  Event                    Indicates the event that invoke this function.
-  @param  Context                  Indicates the calling context.
-**/
-VOID
-EFIAPI
-HotKeyTimerHandler (
-  IN  EFI_EVENT                 Event,
-  IN  VOID                      *Context
-  )
-{
-  EFI_STATUS                    Status;
-  EFI_INPUT_KEY                 Key;
-
-  Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
-  if (EFI_ERROR (Status)) {
-    return;
-  }
-
-  switch(Key.ScanCode) {
-  case SCAN_F2:
-    gHotKey = 0;
-    mHotKeyPressed = TRUE;
-    break;
-
-  case SCAN_F5:
-    gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
-    mHotKeyPressed = TRUE;
-    break;
-
-  case SCAN_F7:
-    gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;
-    mHotKeyPressed = TRUE;
-    break;
-
-  case SCAN_F9:
-    gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;
-    mHotKeyPressed = TRUE;
-    break;
-  }
-
-  if (mHotKeyPressed) {
-    gBS->SetTimer (
-           mHotKeyTimerEvent,
-           TimerCancel,
-           0
-           );
-    gBS->CloseEvent (mHotKeyTimerEvent);
-    mHotKeyTimerEvent = NULL;
-  }
-
-  return;
-}
-
-
-/**
-  Callback function for SimpleTextInEx protocol install events
-
-  @param Event           the event that is signaled.
-  @param Context         not used here.
-
-**/
-VOID
-EFIAPI
-HitHotkeyEvent (
-  IN EFI_EVENT    Event,
-  IN VOID         *Context
-  )
-{
-  EFI_STATUS                         Status;
-
-  Status = gBS->CloseEvent(mHitHotkeyEvent);
-  if (EFI_ERROR (Status)) {
-    return;
-  }
-  Status = gBS->CreateEvent (
-                  EVT_TIMER | EVT_NOTIFY_SIGNAL,
-                  TPL_NOTIFY,
-                  HotKeyTimerHandler,
-                  NULL,
-                  &mHotKeyTimerEvent
-                  );
-  if (EFI_ERROR (Status)) {
-    return;
-  }
-  Status = gBS->SetTimer (
-                  mHotKeyTimerEvent,
-                  TimerPeriodic,
-                  KEYBOARD_TIMER_INTERVAL
-                  );
-  if (EFI_ERROR (Status)) {
-    return;
-  }
-
-  return;
-}
-
-
-VOID
-EFIAPI
-PlatformBdsInitHotKeyEvent (
-  VOID
-  )
-{
-  EFI_STATUS      Status;
-
-  //
-  // Register Protocol notify for Hotkey service
-  //
-  Status = gBS->CreateEvent (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_CALLBACK,
-                  HitHotkeyEvent,
-                  NULL,
-                  &mHitHotkeyEvent
-                  );
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // Register for protocol notifications on this event
-  //
-  Status = gBS->RegisterProtocolNotify (
-                  &gEfiSimpleTextInputExProtocolGuid,
-                  mHitHotkeyEvent,
-                  &mHitHotkeyRegistration
-                  );
-  ASSERT_EFI_ERROR (Status);
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h
deleted file mode 100644
index b5bb519747..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h
+++ /dev/null
@@ -1,516 +0,0 @@
-/*++
-
-  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>
-                                                                                   

-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-                                                                                   

-
-
-Module Name:
-
-  BdsPlatform.h
-
-Abstract:
-
-  Head file for BDS Platform specific code
-
---*/
-
-#ifndef _BDS_PLATFORM_H
-#define _BDS_PLATFORM_H
-
-#include <FrameworkDxe.h>
-
-#include <Protocol/FirmwareVolume2.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/SimpleNetwork.h>
-#include <Protocol/PciRootBridgeIo.h>
-#include <Protocol/LoadFile.h>
-#include <Protocol/LegacyBios.h>
-#include <Protocol/PciIo.h>
-#include <Protocol/SmmAccess2.h>
-#include <Protocol/DxeSmmReadyToLock.h>
-#include <Protocol/UserManager.h>
-#include <Protocol/DeferredImageLoad.h>
-#include <Protocol/AcpiS3Save.h>
-#include <Protocol/ExitPmAuth.h>
-#include <Protocol/MmioDevice.h>
-#include <Protocol/I2cBusMcg.h>
-#include <Protocol/I2cHostMcg.h>
-#include <Guid/CapsuleVendor.h>
-#include <Guid/MemoryTypeInformation.h>
-#include <Guid/GlobalVariable.h>
-#include <Guid/DebugAgentGuid.h>
-
-
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/BaseLib.h>
-#include <Library/PcdLib.h>
-#include <Library/IoLib.h>
-#include <Library/GenericBdsLib.h>
-#include <Library/PlatformBdsLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiLib.h>
-#include <Library/HobLib.h>
-#include <Library/PrintLib.h>
-#include <Library/PerformanceLib.h>
-#include <Library/ReportStatusCodeLib.h>
-
-#include <IndustryStandard/Pci.h>
-
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformRootBridges [];
-extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformAllPossiblePciVgaConsole [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformConnectSequence [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformDriverOption [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformBootOption [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gUserAuthenticationDevice[];
-extern BDS_CONSOLE_CONNECT_ENTRY gPlatformSimpleConsole [];
-extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformSimpleBootOption [];
-
-extern BOOLEAN mEnumBootDevice;
-
-
-//
-// the short form device path for Usb keyboard
-//
-#define CLASS_HID           3
-#define SUBCLASS_BOOT       1
-#define PROTOCOL_KEYBOARD   1
-
-#define PCI_DEVICE_PATH_NODE(Func, Dev) \
-  { \
-    HARDWARE_DEVICE_PATH, \
-    HW_PCI_DP, \
-    { \
-      (UINT8) (sizeof (PCI_DEVICE_PATH)), \
-      (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
-    }, \
-    (Func), \
-    (Dev) \
-  }
-
-#define PNPID_DEVICE_PATH_NODE(PnpId) \
-  { \
-    { \
-      ACPI_DEVICE_PATH, \
-      ACPI_DP, \
-      { \
-        (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
-        (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
-      } \
-    }, \
-    EISA_PNP_ID((PnpId)), \
-    0 \
-  }
-
-#define gUart(BaudRate, DataBits, Parity, StopBits) \
-  { \
-    { \
-      MESSAGING_DEVICE_PATH, \
-      MSG_UART_DP, \
-      { \
-        (UINT8) (sizeof (UART_DEVICE_PATH)), \
-        (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \
-      } \
-    }, \
-    0, \
-    (BaudRate), \
-    (DataBits), \
-    (Parity), \
-    (StopBits) \
-  }
-
-#define gPcAnsiTerminal \
-  { \
-    { \
-      MESSAGING_DEVICE_PATH, \
-      MSG_VENDOR_DP, \
-      { \
-        (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \
-        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
-      } \
-    }, \
-    DEVICE_PATH_MESSAGING_PC_ANSI \
-  }
-
-#define gUsbKeyboardMouse \
-  { \
-    { \
-      MESSAGING_DEVICE_PATH, \
-      MSG_USB_CLASS_DP, \
-      (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), \
-      (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) \
-    }, \
-    0xffff, \
-    0xffff, \
-    CLASS_HID, \
-    SUBCLASS_BOOT, \
-    PROTOCOL_KEYBOARD \
-  }
-
-#define gEndEntire \
-  { \
-    END_DEVICE_PATH_TYPE, \
-    END_ENTIRE_DEVICE_PATH_SUBTYPE, \
-    { \
-      END_DEVICE_PATH_LENGTH, \
-      0 \
-    } \
-  }
-
-#define gPciRootBridge \
-  PNPID_DEVICE_PATH_NODE(0x0A03)
-
-#define gPnpPs2Keyboard \
-  PNPID_DEVICE_PATH_NODE(0x0303)
-
-#define gPnp16550ComPort \
-  PNPID_DEVICE_PATH_NODE(0x0501)
-
-#define gPciePort0Bridge \
-  PCI_DEVICE_PATH_NODE(0, 0x1C)
-
-#define gPciePort1Bridge \
-  PCI_DEVICE_PATH_NODE(1, 0x1C)
-
-#define gPciePort2Bridge \
-  PCI_DEVICE_PATH_NODE(2, 0x1C)
-
-#define gPciePort3Bridge \
-  PCI_DEVICE_PATH_NODE(3, 0x1C)
-
-#define gPciIsaBridge \
-  PCI_DEVICE_PATH_NODE(0, 0x1f)
-
-//
-// Platform Root Bridge
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_ROOT_BRIDGE_DEVICE_PATH;
-
-//
-// Below is the platform console device path
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           IsaBridge;
-  ACPI_HID_DEVICE_PATH      Keyboard;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_ISA_KEYBOARD_DEVICE_PATH;
-
-typedef struct {
-  VENDOR_DEVICE_PATH             VendorDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL       End;
-} HII_VENDOR_DEVICE_PATH;
-
-typedef struct {
-  USB_CLASS_DEVICE_PATH           UsbClass;
-  EFI_DEVICE_PATH_PROTOCOL        End;
-} USB_CLASS_FORMAT_DEVICE_PATH;
-
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           OnboardVga;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_ONBOARD_VGA_DEVICE_PATH;
-
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           AgpBridge;
-  PCI_DEVICE_PATH           AgpDevice;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_OFFBOARD_VGA_DEVICE_PATH;
-
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           IsaBridge;
-  ACPI_HID_DEVICE_PATH      IsaSerial;
-  UART_DEVICE_PATH          Uart;
-  VENDOR_DEVICE_PATH        TerminalType;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_ISA_SERIAL_DEVICE_PATH;
-
-//
-// Below is the boot option device path
-//
-typedef struct {
-  BBS_BBS_DEVICE_PATH             LegacyHD;
-  EFI_DEVICE_PATH_PROTOCOL        End;
-} LEGACY_HD_DEVICE_PATH;
-
-//
-// Below is the platform IDE device path
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           IsaBridge;
-  ATAPI_DEVICE_PATH         Ide;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_IDE_DEVICE_PATH;
-
-//
-// Floppy device path definition
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           IsaBridge;
-  ACPI_HID_DEVICE_PATH      Floppy;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_FLOPPY_DEVICE_PATH;
-
-//
-// Below is the platform USB controller device path for
-// USB disk as user authentication device.
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           PciDevice;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_USB_DEVICE_PATH;
-
-//
-// Debug Agent UART Console device path definition
-//
-typedef struct {
-  VENDOR_DEVICE_PATH        VendorHardware;
-  UART_DEVICE_PATH          Uart;
-  VENDOR_DEVICE_PATH        TerminalType;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} VENDOR_UART_DEVICE_PATH;
-
-//
-// Below is the platform PCI device path
-//
-typedef struct {
-  ACPI_HID_DEVICE_PATH      PciRootBridge;
-  PCI_DEVICE_PATH           PciDevice;
-  EFI_DEVICE_PATH_PROTOCOL  End;
-} PLATFORM_PCI_DEVICE_PATH;
-
-typedef enum {
-  PMIC_Equal         = 0, // =		0
-  PMIC_Greater_Than,	  // >		1
-  PMIC_Smaller_Than,	  // <		2
-  PMIC_Greater_Equal,	  // >=		3
-  PMIC_Smaller_Equal,	  // <=		4
-  PMIC_Any				  // don't care 5
-} PMIC_Condition_list;
-
-typedef enum {
-  PMIC_White_List	= 0,  //White list
-  PMIC_Black_List	= 1   //Black list
-} PMIC_Compliance_mode;
-
-typedef struct {
-  UINT8		Cond_Choice;	// PMIC_Condition_list
-  UINT8		Cond_Number;		// the number
-}PMIC_Condition_Item;
-
-typedef struct {
-  PMIC_Condition_Item   					PMIC_BoardID;
-  PMIC_Condition_Item   					PMIC_FabID;
-  PMIC_Condition_Item   					Soc_Stepping;//define PMIC type, 1:Dialog , 2:Rohm
-  PMIC_Condition_Item   					PMIC_VendID;
-  PMIC_Condition_Item   					PMIC_RevID;
-  PMIC_Compliance_mode 				        mode;        //if 1, blacklist; if 0, white list.
-} PMIC_Compliance_Item;
-
-//
-// Platform BDS Functions
-//
-VOID
-PlatformBdsGetDriverOption (
-  IN LIST_ENTRY                   *BdsDriverLists
-  );
-
-VOID
-PlatformBdsPredictBootOption (
-  IN  LIST_ENTRY                     *BdsBootOptionList
-  );
-
-EFI_STATUS
-PlatformBdsShowProgress (
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,
-  CHAR16                        *Title,
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,
-  UINTN                         Progress,
-  UINTN                         PreviousValue
-  );
-
-VOID
-PlatformBdsConnectSequence (
-  VOID
-  );
-
-EFI_STATUS
-PlatformBdsConnectConsole (
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole
-  );
-
-EFI_STATUS
-PlatformBdsNoConsoleAction (
-  VOID
-  );
-
-VOID
-PlatformBdsEnterFrontPage (
-  IN UINT16                 TimeoutDefault,
-  IN BOOLEAN                ConnectAllHappened
-  );
-
-VOID
-EFIAPI
-PlatformBdsUserIdentify (
-  OUT EFI_USER_PROFILE_HANDLE        *User,
-  OUT BOOLEAN                        *DeferredImage
-  );
-
-VOID
-EFIAPI
-PlatformBdsConnectAuthDevice (
-  VOID
-  );
-
-VOID
-PlatformBdsEnterFrontPageWithHotKey (
-  IN UINT16                       TimeoutDefault,
-  IN BOOLEAN                      ConnectAllHappened
-  );
-
- EFI_STATUS
- ShowProgress (
-   IN UINT16					   TimeoutDefault
-   );
-
- EFI_STATUS
- InitializeFrontPage (
-   IN BOOLEAN						  InitializeHiiData
-   );
-
- VOID
- UpdateFrontPageStrings (
-   VOID
-   );
-   
-   
- EFI_STATUS
- InitBMPackage  (
-   VOID
-   );
-   
-      
- VOID
- FreeBMPackage  (
-   VOID
-   );
-   
-   
- EFI_STATUS
- CallFrontPage (
-   VOID
-   );
-
-
- VOID
- CallBootManager (
-   VOID
-   );
-
-VOID
-CallDeviceManager (
-  VOID
-  );
-
-VOID
-BdsStartBootMaint (
-  VOID
-  );
-
-CHAR16 *
-GetStringById (
-  IN  EFI_STRING_ID   Id
-  );
-
-EFI_STATUS
-WaitForSingleEvent (
-  IN EFI_EVENT                  Event,
-  IN UINT64                     Timeout OPTIONAL
-  );
-
-EFI_STATUS
-BdsLibDeleteOptionFromHandle (
-  IN  EFI_HANDLE                 Handle
-  );
-
-EFI_STATUS
-BdsDeleteAllInvalidEfiBootOption (
-  VOID
-  );
-
-
-#define ONE_SECOND  10000000
-#define FRONT_PAGE_KEY_CONTINUE        0x1000
-#define FRONT_PAGE_KEY_LANGUAGE        0x1234
-#define FRONT_PAGE_KEY_BOOT_MANAGER    0x1064
-#define FRONT_PAGE_KEY_DEVICE_MANAGER  0x8567
-#define FRONT_PAGE_KEY_BOOT_MAINTAIN   0x9876
-
-#define PORT_A_DVO                     0           // ; DVO A
-#define PORT_B_DVO                     1           // ; DVO B
-#define PORT_C_DVO                     2           // ; DVO C
-#define PORT_D_DVO                     3           // ; DVO D
-#define PORT_LVDS                      4           // ; Integrated LVDS port
-#define PORT_ANALOG_TV                 5           // ; Integrated TV port
-#define PORT_CRT                       6           // ; integrated Analog port
-#define PORT_B_DP                      7           // ; DisplayPort B
-#define PORT_C_DP                      8           // ; DisplayPort C
-#define PORT_D_DP                      9           // ; DisplayPort D
-#define PORT_A_DP                      10          // ; DisplayPort A (for eDP on ILK)
-#define PORT_B_HDMI                    11          // ; HDMI B
-#define PORT_C_HDMI                    12          // ; HDMI C
-#define PORT_D_HDMI                    13          // ; HDMI D
-#define PORT_B_DVI                     14          // ; DVI B
-#define PORT_C_DVI                     15          // ; DVI C
-#define PORT_D_DVI                     16          // ; DVI D
-#define PORT_MIPI_A                    21          // ; MIPI
-#define PORT_MIPI_B                    22
-#define PORT_MIPI_C                    23
-
-
-extern BOOLEAN gConnectAllHappened;
-extern UINTN gCallbackKey;
-
-VOID
-BdsBootDeviceSelect (
-  VOID
-);
-VOID FastBoot(VOID);
-
-extern BOOLEAN    mModeInitialized;
-
-//
-// Boot video resolution and text mode.
-//
-extern UINT32     mBootHorizontalResolution    ;
-extern UINT32     mBootVerticalResolution      ;
-extern UINT32     mBootTextModeColumn          ;
-extern UINT32     mBootTextModeRow             ;
-
-//
-// BIOS setup video resolution and text mode.
-//
-extern UINT32     mSetupTextModeColumn         ;
-extern UINT32     mSetupTextModeRow            ;
-extern UINT32     mSetupHorizontalResolution   ;
-extern UINT32     mSetupVerticalResolution     ;
-extern EFI_STATUS BdsSetConsoleMode (BOOLEAN);
-#endif // _BDS_PLATFORM_H
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLib.inf b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLib.inf
deleted file mode 100644
index 66d11c6cda..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsLib.inf
+++ /dev/null
@@ -1,128 +0,0 @@
-#/** @file
-# Component name for module PlatformBootManagerLib
-#
-# Copyright (c) 2008  - 2019, Intel Corporation. All rights reserved.<BR>
-#
-
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-
-#
-
-#
-#
-#
-#**/
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = PlatformBdsLib
-  FILE_GUID                      = A6BC385D-59E5-4b77-87D7-200ABAA83C15
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PlatformBootManagerLib|DXE_DRIVER
-  EDK_RELEASE_VERSION            = 0x00020000
-  EFI_SPECIFICATION_VERSION      = 0x0002000A
-
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64 EBC
-#
-
-[Sources]
-  BdsPlatform.c
-  BdsPlatform.h
-  PlatformData.c
-  PlatformBdsStrings.uni
-
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  IntelFrameworkPkg/IntelFrameworkPkg.dec
-  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
-  Vlv2TbltDevicePkg/PlatformPkg.dec
-  Vlv2DeviceRefCodePkg/Vlv2DeviceRefCodePkg.dec
-  ShellPkg/ShellPkg.dec
-  CryptoPkg/CryptoPkg.dec
-  SecurityPkg/SecurityPkg.dec
-  SignedCapsulePkg/SignedCapsulePkg.dec
-  SourceLevelDebugPkg/SourceLevelDebugPkg.dec
-  NetworkPkg/NetworkPkg.dec
-
-[LibraryClasses]
-  DxeServicesTableLib
-  BaseLib
-  MemoryAllocationLib
-  UefiBootServicesTableLib
-  UefiRuntimeServicesTableLib
-  BaseMemoryLib
-  DebugLib
-  PcdLib
-  GenericBdsLib
-  DevicePathLib
-  NetLib
-  UefiLib
-  HobLib
-  PciLib
-  PrintLib
-  BaseCryptLib
-#  TcgPhysicalPresenceLib
-  Tcg2PhysicalPresenceLib  
-  FileHandleLib
-  S3BootScriptLib
-  SerialPortLib
-  CapsuleLib
-
-[Protocols]
-  gEfiFirmwareVolume2ProtocolGuid
-  gEfiSimpleNetworkProtocolGuid
-  gEfiLoadFileProtocolGuid
-  gEfiPciIoProtocolGuid
-  gEfiSmmAccess2ProtocolGuid
-  gEfiDxeSmmReadyToLockProtocolGuid
-  gEfiUserManagerProtocolGuid
-  gEfiDeferredImageLoadProtocolGuid
-  gEfiAcpiS3SaveProtocolGuid
-  gEfiSpiProtocolGuid                           ## PROTOCOL CONSUMES
-  gExitPmAuthProtocolGuid
-  gEfiTdtOperationProtocolGuid
-  gEfiGlobalNvsAreaProtocolGuid
-  gEfiMmioDeviceProtocolGuid
-  gEfiI2cMasterProtocolGuid
-  gEfiI2cHostProtocolGuid
-  gEsrtManagementProtocolGuid
-
-[Guids]
-  gEfiMemoryTypeInformationGuid
-  gEfiCapsuleVendorGuid
-  gEfiGlobalVariableGuid
-  gEfiNormalSetupGuid
-  gEfiPartTypeSystemPartGuid
-  gEfiEndOfDxeEventGroupGuid
-  gUefiShellFileGuid
-
-[Pcd]
-  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid
-  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid
-  gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer
-  gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer
-  gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed
-  gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Base
-  gPlatformModuleTokenSpaceGuid.PcdFlashFvMainBase
-  gPlatformModuleTokenSpaceGuid.PcdFlashFvRecoveryBase
-  gPlatformModuleTokenSpaceGuid.PcdFlashFvShellBase
-  gPlatformModuleTokenSpaceGuid.PcdFlashFvShellSize
-  gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
-  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdLogoFile
-  gPlatformModuleTokenSpaceGuid.PcdIFWISigBaseAddress
-  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow
-  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn
-  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution
-  gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution
-  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
-  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutColumn
-  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow
-  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution
-  gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution
-  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootState
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsStrings.uni b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsStrings.uni
deleted file mode 100644
index 101106f9f4..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformBdsStrings.uni
+++ /dev/null
@@ -1,30 +0,0 @@
-///** @file
-//  
-//  String definitions for Boot Option description.
-//  
-//  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
-//  SPDX-License-Identifier: BSD-2-Clause-Patent
-//  
-//**/
-
-/=#
-
-#langdef   en-US "English"
-#langdef   fr-FR "Français"
-
-#string STR_DESCRIPTION_FLOPPY         #language en-US  "EFI Floppy"
-                                       #language fr-FR  "fr-FR: EFI Floppy"
-#string STR_DESCRIPTION_CD_DVD         #language en-US  "EFI DVD/CDROM"
-                                       #language fr-FR  "fr-FR: EFI DVD/CDROM"
-#string STR_DESCRIPTION_HARDDRIVE      #language en-US  "EFI Hard Drive"
-                                       #language fr-FR  "fr-FR: EFI Hard Drive"
-#string STR_DESCRIPTION_USB            #language en-US  "EFI USB Device"
-                                       #language fr-FR  "fr-FR: EFI USB Device"
-#string STR_DESCRIPTION_SCSI           #language en-US  "EFI SCSI Device"
-                                       #language fr-FR  "fr-FR: EFI SCSI Device"
-#string STR_DESCRIPTION_MISC           #language en-US  "EFI Misc Device"
-                                       #language fr-FR  "fr-FR: EFI Misc Device"
-#string STR_DESCRIPTION_NETWORK        #language en-US  "EFI Network"
-                                       #language fr-FR  "fr-FR: EFI Network"
-#string STR_DESCRIPTION_NON_BLOCK      #language en-US  "EFI Non-Block Boot Device"
-                                       #language fr-FR  "fr-FR: EFI Non-Block Boot Device"
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformData.c b/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformData.c
deleted file mode 100644
index 9dff93f52b..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Library/PlatformBdsLib/PlatformData.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/** @file
-
-  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>
-                                                                                   

-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-                                                                                   

-
-Module Name:
-
-  PlatformData.c
-
-Abstract:
-
-  Defined the platform specific device path which will be used by
-  platform Bbd to perform the platform policy connect.
-
---*/
-
-#include "BdsPlatform.h"
-
-//
-// Predefined platform default time out value
-//
-UINT16  gPlatformBootTimeOutDefault = 10;
-
-//
-// Predefined platform root bridge
-//
-PLATFORM_ROOT_BRIDGE_DEVICE_PATH gPlatformRootBridge0 = {
-  gPciRootBridge,
-  gEndEntire
-};
-
-EFI_DEVICE_PATH_PROTOCOL* gPlatformRootBridges [] = {
-  (EFI_DEVICE_PATH_PROTOCOL*)&gPlatformRootBridge0,
-  NULL
-};
-
-//
-// Platform specific ISA keyboard device path
-//
-PLATFORM_ISA_KEYBOARD_DEVICE_PATH gIsaKeyboardDevicePath = {
-  gPciRootBridge,
-  gPciIsaBridge,
-  gPnpPs2Keyboard,
-  gEndEntire
-};
-
-//
-// Platform specific on chip PCI VGA device path
-//
-PLATFORM_ONBOARD_VGA_DEVICE_PATH gOnChipPciVgaDevicePath = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(0, 0x2),
-  gEndEntire
-};
-
-//
-// Platform specific plug in PCI VGA device path
-//
-PLATFORM_OFFBOARD_VGA_DEVICE_PATH gPlugInPciVgaDevicePath = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(0, 0x1),
-  PCI_DEVICE_PATH_NODE(0, 0x0),
-  gEndEntire
-};
-
-//
-// Platform specific ISA serial device path
-//
-PLATFORM_ISA_SERIAL_DEVICE_PATH gIsaSerialDevicePath = {
-  gPciRootBridge,
-  gPciIsaBridge,
-  gPnp16550ComPort,
-  gUart(115200, 8, 1, 1),
-  gPcAnsiTerminal,
-  gEndEntire
-};
-
-
-//
-// Platform specific Button Array device path
-//
-HII_VENDOR_DEVICE_PATH  gHiiVendorDevicePath0 = {
-  {
-    {
-      HARDWARE_DEVICE_PATH,
-      HW_VENDOR_DP,
-      {
-        (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
-        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
-      }
-    },
-
-    //
-    // {C8752FDE-B5C8-4528-897D-6920FE771E38}
-    //
-    { 0xC8752FDE, 0xB5C8, 0x4528, { 0x89, 0x7D, 0x69, 0x20, 0xFE, 0x77, 0x1E, 0x38 } }
-  },
-  {
-    END_DEVICE_PATH_TYPE,
-    END_ENTIRE_DEVICE_PATH_SUBTYPE,
-    {
-      (UINT8) (END_DEVICE_PATH_LENGTH),
-      (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
-    }
-  }
-};
-
-USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath = {
-  gUsbKeyboardMouse,
-  gEndEntire
-};
-
-//
-// Debug Agent UART Console device path 
-//
-VENDOR_UART_DEVICE_PATH gDebugAgentUartDevicePath = {
-  {
-    {
-      HARDWARE_DEVICE_PATH,
-      HW_VENDOR_DP,
-      {
-        (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
-        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
-      }
-    },
-    EFI_DEBUG_AGENT_GUID,
-  },
-  {
-    {
-      MESSAGING_DEVICE_PATH,
-      MSG_UART_DP,
-      {
-        (UINT8) (sizeof (UART_DEVICE_PATH)),
-        (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8)
-      }
-    },
-    0,  // Reserved
-    0,  // BaudRate - Default
-    0,  // DataBits - Default
-    0,  // Parity   - Default
-    0,  // StopBits - Default
-  },
-  {
-    {
-      MESSAGING_DEVICE_PATH,
-      MSG_VENDOR_DP,
-      {
-        (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
-        (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
-      }
-    },
-    DEVICE_PATH_MESSAGING_PC_ANSI
-  },
-  gEndEntire
-};
-
-//
-// Predefined platform default console device path
-//
-BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole [] = {
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaSerialDevicePath, CONSOLE_ALL},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gHiiVendorDevicePath0, CONSOLE_IN},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaKeyboardDevicePath, CONSOLE_IN},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gDebugAgentUartDevicePath, CONSOLE_ALL},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gUsbClassKeyboardDevicePath, CONSOLE_IN},
-  {NULL, 0}
-};
-
-//
-// All the possible platform PCI VGA device path
-//
-EFI_DEVICE_PATH_PROTOCOL* gPlatformAllPossiblePciVgaConsole [] = {
-  (EFI_DEVICE_PATH_PROTOCOL*)&gOnChipPciVgaDevicePath,
-  (EFI_DEVICE_PATH_PROTOCOL*)&gPlugInPciVgaDevicePath,
-  NULL
-};
-
-//
-// Legacy hard disk boot option
-//
-LEGACY_HD_DEVICE_PATH gLegacyHd = {
-  {
-    BBS_DEVICE_PATH,
-    BBS_BBS_DP,
-    (UINT8)(sizeof(BBS_BBS_DEVICE_PATH)),
-    (UINT8)((sizeof(BBS_BBS_DEVICE_PATH)) >> 8),
-    BBS_TYPE_HARDDRIVE,
-    0,
-    0
-  },
-  gEndEntire
-};
-
-//
-// Legacy cdrom boot option
-//
-LEGACY_HD_DEVICE_PATH gLegacyCdrom = {
-  {
-    BBS_DEVICE_PATH,
-    BBS_BBS_DP,
-    (UINT8)(sizeof(BBS_BBS_DEVICE_PATH)),
-    (UINT8)((sizeof(BBS_BBS_DEVICE_PATH)) >> 8),
-    BBS_TYPE_CDROM,
-    0,
-    0
-  },
-  gEndEntire
-};
-
-//
-// Predefined platform specific perdict boot option
-//
-EFI_DEVICE_PATH_PROTOCOL* gPlatformBootOption [] = {
-  (EFI_DEVICE_PATH_PROTOCOL*)&gLegacyHd,
-  (EFI_DEVICE_PATH_PROTOCOL*)&gLegacyCdrom,
-  NULL
-};
-
-//
-// Predefined platform specific driver option
-//
-EFI_DEVICE_PATH_PROTOCOL* gPlatformDriverOption [] = {
-  NULL
-};
-
-//
-// Predefined platform connect sequence
-//
-EFI_DEVICE_PATH_PROTOCOL* gPlatformConnectSequence [] = {
-  (EFI_DEVICE_PATH_PROTOCOL *)&gPlatformRootBridge0,  // Force PCI enumer before Legacy OpROM shadow
-  NULL
-};
-
-//
-// Platform specific USB controller device path
-//
-PLATFORM_USB_DEVICE_PATH gUsbDevicePath0 = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(0, 0x1D),
-  gEndEntire
-};
-
-PLATFORM_USB_DEVICE_PATH gUsbDevicePath1 = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(1, 0x1D),
-  gEndEntire
-};
-
-PLATFORM_USB_DEVICE_PATH gUsbDevicePath2 = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(2, 0x1D),
-  gEndEntire
-};
-
-PLATFORM_USB_DEVICE_PATH gUsbDevicePath3 = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE(3, 0x1D),
-  gEndEntire
-};
-
-//
-// Predefined platform device path for user authtication
-//
-EFI_DEVICE_PATH_PROTOCOL* gUserAuthenticationDevice[] = {
-  //
-  // Predefined device path for secure card (USB disk).
-  //
-  (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath0,
-  (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath1,
-  (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath2,
-  (EFI_DEVICE_PATH_PROTOCOL*)&gUsbDevicePath3,
-  NULL
-};
-
-//
-// Predefined platform console device path
-//
-BDS_CONSOLE_CONNECT_ENTRY gPlatformSimpleConsole [] = {
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gOnChipPciVgaDevicePath, CONSOLE_OUT},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gIsaSerialDevicePath, CONSOLE_ALL},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gHiiVendorDevicePath0, CONSOLE_IN},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gDebugAgentUartDevicePath, CONSOLE_ALL},
-  {(EFI_DEVICE_PATH_PROTOCOL*)&gUsbClassKeyboardDevicePath, CONSOLE_IN},
-  {NULL, 0}
-};
-
-//
-// eMMC device at BDF(0x0, 0x17, 0x0)
-//
-PLATFORM_PCI_DEVICE_PATH gEmmcBootDevPath0 = {
-  gPciRootBridge,
-  PCI_DEVICE_PATH_NODE (0x00, 0x10),
-  gEndEntire
-};
-
-//
-// Predefined platform specific perdict boot option
-//
-EFI_DEVICE_PATH_PROTOCOL* gPlatformSimpleBootOption [] = {
-  (EFI_DEVICE_PATH_PROTOCOL*)&gEmmcBootDevPath0,
-  NULL
-};
-
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
deleted file mode 100644
index 3034853695..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ /dev/null
@@ -1,4490 +0,0 @@
-/** @file
-  BDS Lib functions which relate with create or process the boot option.
-
-Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "InternalBdsLib.h"
-#include "String.h"
-#include <Library/NetLib.h>
-#include "Library/DebugLib.h"
-
-BOOLEAN mEnumBootDevice = FALSE;
-EFI_HII_HANDLE gBdsLibStringPackHandle = NULL;
-
-/**
-
-  End Perf entry of BDS
-
-  @param  Event                 The triggered event.
-  @param  Context               Context for this event.
-
-**/
-VOID
-EFIAPI
-BmEndOfBdsPerfCode (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  //
-  // Record the performance data for End of BDS
-  //
-  PERF_END(NULL, "BDS", NULL, 0);
-
-  return ;
-}
-
-/**
-  The constructor function register UNI strings into imageHandle.
-  
-  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. 
-
-  @param  ImageHandle   The firmware allocated handle for the EFI image.
-  @param  SystemTable   A pointer to the EFI System Table.
-  
-  @retval EFI_SUCCESS   The constructor successfully added string package.
-  @retval Other value   The constructor can't add string package.
-
-**/
-EFI_STATUS
-EFIAPI
-GenericBdsLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-
-  gBdsLibStringPackHandle = HiiAddPackages (
-                              &gBdsLibStringPackageGuid,
-                              ImageHandle,
-                              GenericBdsLibStrings,
-                              NULL
-                              );
-
-  ASSERT (gBdsLibStringPackHandle != NULL);
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Deletete the Boot Option from EFI Variable. The Boot Order Arrray
-  is also updated.
-
-  @param OptionNumber    The number of Boot option want to be deleted.
-  @param BootOrder       The Boot Order array.
-  @param BootOrderSize   The size of the Boot Order Array.
-
-  @retval  EFI_SUCCESS           The Boot Option Variable was found and removed
-  @retval  EFI_UNSUPPORTED       The Boot Option Variable store was inaccessible
-  @retval  EFI_NOT_FOUND         The Boot Option Variable was not found
-**/
-EFI_STATUS
-EFIAPI
-BdsDeleteBootOption (
-  IN UINTN                       OptionNumber,
-  IN OUT UINT16                  *BootOrder,
-  IN OUT UINTN                   *BootOrderSize
-  )
-{
-  CHAR16      BootOption[9];
-  UINTN       Index;
-  EFI_STATUS  Status;
-
-  UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumber);
-  Status = gRT->SetVariable (
-                  BootOption,
-                  &gEfiGlobalVariableGuid,
-                  0,
-                  0,
-                  NULL
-                  );
-  //
-  // Deleting variable with existing variable implementation shouldn't fail.
-  //
-  ASSERT_EFI_ERROR (Status);
-
-  //
-  // adjust boot order array
-  //
-  for (Index = 0; Index < *BootOrderSize / sizeof (UINT16); Index++) {
-    if (BootOrder[Index] == OptionNumber) {
-      CopyMem (&BootOrder[Index], &BootOrder[Index+1], *BootOrderSize - (Index+1) * sizeof (UINT16));
-      *BootOrderSize -= sizeof (UINT16);
-      break;
-    }
-  }
-
-  return Status;
-}
-/**
-
-  Translate the first n characters of an Ascii string to
-  Unicode characters. The count n is indicated by parameter
-  Size. If Size is greater than the length of string, then
-  the entire string is translated.
-
-
-  @param AStr               Pointer to input Ascii string.
-  @param Size               The number of characters to translate.
-  @param UStr               Pointer to output Unicode string buffer.
-
-**/
-VOID
-AsciiToUnicodeSize (
-  IN UINT8              *AStr,
-  IN UINTN              Size,
-  OUT UINT16            *UStr
-  )
-{
-  UINTN Idx;
-
-  Idx = 0;
-  while (AStr[Idx] != 0) {
-    UStr[Idx] = (CHAR16) AStr[Idx];
-    if (Idx == Size) {
-      break;
-    }
-
-    Idx++;
-  }
-  UStr[Idx] = 0;
-}
-
-/**
-  Build Legacy Device Name String according.
-
-  @param CurBBSEntry     BBS Table.
-  @param Index           Index.
-  @param BufSize         The buffer size.
-  @param BootString      The output string.
-
-**/
-VOID
-BdsBuildLegacyDevNameString (
-  IN  BBS_TABLE                 *CurBBSEntry,
-  IN  UINTN                     Index,
-  IN  UINTN                     BufSize,
-  OUT CHAR16                    *BootString
-  )
-{
-  CHAR16  *Fmt;
-  CHAR16  *Type;
-  UINT8   *StringDesc;
-  CHAR16  Temp[80];
-
-  switch (Index) {
-  //
-  // Primary Master
-  //
-  case 1:
-    Fmt = L"Primary Master %s";
-    break;
-
- //
- // Primary Slave
- //
-  case 2:
-    Fmt = L"Primary Slave %s";
-    break;
-
-  //
-  // Secondary Master
-  //
-  case 3:
-    Fmt = L"Secondary Master %s";
-    break;
-
-  //
-  // Secondary Slave
-  //
-  case 4:
-    Fmt = L"Secondary Slave %s";
-    break;
-
-  default:
-    Fmt = L"%s";
-    break;
-  }
-
-  switch (CurBBSEntry->DeviceType) {
-  case BBS_FLOPPY:
-    Type = L"Floppy";
-    break;
-
-  case BBS_HARDDISK:
-    Type = L"Harddisk";
-    break;
-
-  case BBS_CDROM:
-    Type = L"CDROM";
-    break;
-
-  case BBS_PCMCIA:
-    Type = L"PCMCIAe";
-    break;
-
-  case BBS_USB:
-    Type = L"USB";
-    break;
-
-  case BBS_EMBED_NETWORK:
-    Type = L"Network";
-    break;
-
-  case BBS_BEV_DEVICE:
-    Type = L"BEVe";
-    break;
-
-  case BBS_UNKNOWN:
-  default:
-    Type = L"Unknown";
-    break;
-  }
-  //
-  // If current BBS entry has its description then use it.
-  //
-  StringDesc = (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
-  if (NULL != StringDesc) {
-    //
-    // Only get fisrt 32 characters, this is suggested by BBS spec
-    //
-    AsciiToUnicodeSize (StringDesc, 32, Temp);
-    Fmt   = L"%s";
-    Type  = Temp;
-  }
-
-  //
-  // BbsTable 16 entries are for onboard IDE.
-  // Set description string for SATA harddisks, Harddisk 0 ~ Harddisk 11
-  //
-  if (Index >= 5 && Index <= 16 && (CurBBSEntry->DeviceType == BBS_HARDDISK || CurBBSEntry->DeviceType == BBS_CDROM)) {
-    Fmt = L"%s %d";
-    UnicodeSPrint (BootString, BufSize, Fmt, Type, Index - 5);
-  } else {
-    UnicodeSPrint (BootString, BufSize, Fmt, Type);
-  }
-}
-
-/**
-
-  Create a legacy boot option for the specified entry of
-  BBS table, save it as variable, and append it to the boot
-  order list.
-
-
-  @param CurrentBbsEntry    Pointer to current BBS table.
-  @param CurrentBbsDevPath  Pointer to the Device Path Protocol instance of BBS
-  @param Index              Index of the specified entry in BBS table.
-  @param BootOrderList      On input, the original boot order list.
-                            On output, the new boot order list attached with the
-                            created node.
-  @param BootOrderListSize  On input, the original size of boot order list.
-                            On output, the size of new boot order list.
-
-  @retval  EFI_SUCCESS             Boot Option successfully created.
-  @retval  EFI_OUT_OF_RESOURCES    Fail to allocate necessary memory.
-  @retval  Other                   Error occurs while setting variable.
-
-**/
-EFI_STATUS
-BdsCreateLegacyBootOption (
-  IN BBS_TABLE                        *CurrentBbsEntry,
-  IN EFI_DEVICE_PATH_PROTOCOL         *CurrentBbsDevPath,
-  IN UINTN                            Index,
-  IN OUT UINT16                       **BootOrderList,
-  IN OUT UINTN                        *BootOrderListSize
-  )
-{
-  EFI_STATUS           Status;
-  UINT16               CurrentBootOptionNo;
-  UINT16               BootString[10];
-  CHAR16               BootDesc[100];
-  CHAR8                HelpString[100];
-  UINT16               *NewBootOrderList;
-  UINTN                BufferSize;
-  UINTN                StringLen;
-  VOID                 *Buffer;
-  UINT8                *Ptr;
-  UINT16               CurrentBbsDevPathSize;
-  UINTN                BootOrderIndex;
-  UINTN                BootOrderLastIndex;
-  UINTN                ArrayIndex;
-  BOOLEAN              IndexNotFound;
-  BBS_BBS_DEVICE_PATH  *NewBbsDevPathNode;
-
-  if ((*BootOrderList) == NULL) {
-    CurrentBootOptionNo = 0;
-  } else {
-    for (ArrayIndex = 0; ArrayIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); ArrayIndex++) {
-      IndexNotFound = TRUE;
-      for (BootOrderIndex = 0; BootOrderIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); BootOrderIndex++) {
-        if ((*BootOrderList)[BootOrderIndex] == ArrayIndex) {
-          IndexNotFound = FALSE;
-          break;
-        }
-      }
-
-      if (!IndexNotFound) {
-        continue;
-      } else {
-        break;
-      }
-    }
-
-    CurrentBootOptionNo = (UINT16) ArrayIndex;
-  }
-
-  UnicodeSPrint (
-    BootString,
-    sizeof (BootString),
-    L"Boot%04x",
-    CurrentBootOptionNo
-    );
-
-  BdsBuildLegacyDevNameString (CurrentBbsEntry, Index, sizeof (BootDesc), BootDesc);
-
-  //
-  // Create new BBS device path node with description string
-  //
-  UnicodeStrToAsciiStr (BootDesc, HelpString);
-
-  StringLen = AsciiStrLen (HelpString);
-  NewBbsDevPathNode = AllocateZeroPool (sizeof (BBS_BBS_DEVICE_PATH) + StringLen);
-  if (NewBbsDevPathNode == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-  CopyMem (NewBbsDevPathNode, CurrentBbsDevPath, sizeof (BBS_BBS_DEVICE_PATH));
-  CopyMem (NewBbsDevPathNode->String, HelpString, StringLen + 1);
-  SetDevicePathNodeLength (&(NewBbsDevPathNode->Header), sizeof (BBS_BBS_DEVICE_PATH) + StringLen);
-
-  //
-  // Create entire new CurrentBbsDevPath with end node
-  //
-  CurrentBbsDevPath = AppendDevicePathNode (
-                        NULL,
-                        (EFI_DEVICE_PATH_PROTOCOL *) NewBbsDevPathNode
-                        );
-   if (CurrentBbsDevPath == NULL) {
-    FreePool (NewBbsDevPathNode);
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  CurrentBbsDevPathSize = (UINT16) (GetDevicePathSize (CurrentBbsDevPath));
-
-  BufferSize = sizeof (UINT32) +
-    sizeof (UINT16) +
-    StrSize (BootDesc) +
-    CurrentBbsDevPathSize +
-    sizeof (BBS_TABLE) +
-    sizeof (UINT16);
-
-  Buffer = AllocateZeroPool (BufferSize);
-  if (Buffer == NULL) {
-    FreePool (NewBbsDevPathNode);
-    FreePool (CurrentBbsDevPath);
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Ptr               = (UINT8 *) Buffer;
-
-  *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE;
-  Ptr += sizeof (UINT32);
-
-  *((UINT16 *) Ptr) = CurrentBbsDevPathSize;
-  Ptr += sizeof (UINT16);
-
-  CopyMem (
-    Ptr,
-    BootDesc,
-    StrSize (BootDesc)
-    );
-  Ptr += StrSize (BootDesc);
-
-  CopyMem (
-    Ptr,
-    CurrentBbsDevPath,
-    CurrentBbsDevPathSize
-    );
-  Ptr += CurrentBbsDevPathSize;
-
-  CopyMem (
-    Ptr,
-    CurrentBbsEntry,
-    sizeof (BBS_TABLE)
-    );
-
-  Ptr += sizeof (BBS_TABLE);
-  *((UINT16 *) Ptr) = (UINT16) Index;
-
-  Status = gRT->SetVariable (
-                  BootString,
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  BufferSize,
-                  Buffer
-                  );
-
-  FreePool (Buffer);
-  
-  Buffer = NULL;
-
-  NewBootOrderList = AllocateZeroPool (*BootOrderListSize + sizeof (UINT16));
-  if (NULL == NewBootOrderList) {
-    FreePool (NewBbsDevPathNode);
-    FreePool (CurrentBbsDevPath);
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  if (*BootOrderList != NULL) {
-    CopyMem (NewBootOrderList, *BootOrderList, *BootOrderListSize);
-    FreePool (*BootOrderList);
-  }
-
-  BootOrderLastIndex                    = (UINTN) (*BootOrderListSize / sizeof (UINT16));
-  NewBootOrderList[BootOrderLastIndex]  = CurrentBootOptionNo;
-  *BootOrderListSize += sizeof (UINT16);
-  *BootOrderList = NewBootOrderList;
-
-  FreePool (NewBbsDevPathNode);
-  FreePool (CurrentBbsDevPath);
-  return Status;
-}
-
-/**
-  Check if the boot option is a legacy one.
-
-  @param BootOptionVar   The boot option data payload.
-  @param BbsEntry        The BBS Table.
-  @param BbsIndex        The table index.
-
-  @retval TRUE           It is a legacy boot option.
-  @retval FALSE          It is not a legacy boot option.
-
-**/
-BOOLEAN
-BdsIsLegacyBootOption (
-  IN UINT8                 *BootOptionVar,
-  OUT BBS_TABLE            **BbsEntry,
-  OUT UINT16               *BbsIndex
-  )
-{
-  UINT8                     *Ptr;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  BOOLEAN                   Ret;
-  UINT16                    DevPathLen;
-
-  Ptr = BootOptionVar;
-  Ptr += sizeof (UINT32);
-  DevPathLen = *(UINT16 *) Ptr;
-  Ptr += sizeof (UINT16);
-  Ptr += StrSize ((UINT16 *) Ptr);
-  DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
-  if ((BBS_DEVICE_PATH == DevicePath->Type) && (BBS_BBS_DP == DevicePath->SubType)) {
-    Ptr += DevPathLen;
-    *BbsEntry = (BBS_TABLE *) Ptr;
-    Ptr += sizeof (BBS_TABLE);
-    *BbsIndex = *(UINT16 *) Ptr;
-    Ret       = TRUE;
-  } else {
-    *BbsEntry = NULL;
-    Ret       = FALSE;
-  }
-
-  return Ret;
-}
-
-/**
-  Delete all the invalid legacy boot options.
-
-  @retval EFI_SUCCESS             All invalide legacy boot options are deleted.
-  @retval EFI_OUT_OF_RESOURCES    Fail to allocate necessary memory.
-  @retval EFI_NOT_FOUND           Fail to retrive variable of boot order.
-**/
-EFI_STATUS
-EFIAPI
-BdsDeleteAllInvalidLegacyBootOptions (
-  VOID
-  )
-{
-  UINT16                    *BootOrder;
-  UINT8                     *BootOptionVar;
-  UINTN                     BootOrderSize;
-  UINTN                     BootOptionSize;
-  EFI_STATUS                Status;
-  UINT16                    HddCount;
-  UINT16                    BbsCount;
-  HDD_INFO                  *LocalHddInfo;
-  BBS_TABLE                 *LocalBbsTable;
-  BBS_TABLE                 *BbsEntry;
-  UINT16                    BbsIndex;
-  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
-  UINTN                     Index;
-  UINT16                    BootOption[10];
-  UINT16                    BootDesc[100];
-  BOOLEAN                   DescStringMatch;
-
-  Status        = EFI_SUCCESS;
-  BootOrder     = NULL;
-  BootOrderSize = 0;
-  HddCount      = 0;
-  BbsCount      = 0;
-  LocalHddInfo  = NULL;
-  LocalBbsTable = NULL;
-  BbsEntry      = NULL;
-
-  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  BootOrder = BdsLibGetVariableAndSize (
-                L"BootOrder",
-                &gEfiGlobalVariableGuid,
-                &BootOrderSize
-                );
-  if (BootOrder == NULL) {
-    return EFI_NOT_FOUND;
-  }
-
-  LegacyBios->GetBbsInfo (
-                LegacyBios,
-                &HddCount,
-                &LocalHddInfo,
-                &BbsCount,
-                &LocalBbsTable
-                );
-
-  Index = 0;
-  while (Index < BootOrderSize / sizeof (UINT16)) {
-    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
-    BootOptionVar = BdsLibGetVariableAndSize (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      &BootOptionSize
-                      );
-    if (NULL == BootOptionVar) {
-      BootOptionSize = 0;
-      Status = gRT->GetVariable (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      NULL,
-                      &BootOptionSize,
-                      BootOptionVar
-                      );
-      if (Status == EFI_NOT_FOUND) {
-        //
-        // Update BootOrder
-        //
-        BdsDeleteBootOption (
-          BootOrder[Index],
-          BootOrder,
-          &BootOrderSize
-          );
-        continue;
-      } else {
-        FreePool (BootOrder);
-        return EFI_OUT_OF_RESOURCES;
-      }
-    }
-  
-    //
-    // Skip Non-Legacy boot option
-    // 
-    if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, &BbsIndex)) {
-      if (BootOptionVar!= NULL) {
-        FreePool (BootOptionVar);
-      }
-      Index++;
-      continue;
-    }
-
-    if (BbsIndex < BbsCount) {
-      //
-      // Check if BBS Description String is changed
-      //
-      DescStringMatch = FALSE;
-      BdsBuildLegacyDevNameString (
-        &LocalBbsTable[BbsIndex],
-        BbsIndex,
-        sizeof (BootDesc),
-        BootDesc
-        );
-
-      if (StrCmp (BootDesc, (UINT16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) == 0) {
-        DescStringMatch = TRUE;
-      }
-
-      if (!((LocalBbsTable[BbsIndex].BootPriority == BBS_IGNORE_ENTRY) ||
-            (LocalBbsTable[BbsIndex].BootPriority == BBS_DO_NOT_BOOT_FROM)) &&
-          (LocalBbsTable[BbsIndex].DeviceType == BbsEntry->DeviceType) &&
-          DescStringMatch) {
-        Index++;
-        continue;
-      }
-    }
-
-    if (BootOptionVar != NULL) {
-      FreePool (BootOptionVar);
-    }
-    //
-    // should delete
-    //
-    BdsDeleteBootOption (
-      BootOrder[Index],
-      BootOrder,
-      &BootOrderSize
-      );
-  }
-
-  //
-  // Adjust the number of boot options.
-  //
-  Status = gRT->SetVariable (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  BootOrderSize,
-                  BootOrder
-                  );
-  //
-  // Shrinking variable with existing variable implementation shouldn't fail.
-  //
-  ASSERT_EFI_ERROR (Status);
-  FreePool (BootOrder);
-
-  return Status;
-}
-
-/**
-  Find all legacy boot option by device type.
-
-  @param BootOrder       The boot order array.
-  @param BootOptionNum   The number of boot option.
-  @param DevType         Device type.
-  @param DevName         Device name.
-  @param Attribute       The boot option attribute.
-  @param BbsIndex        The BBS table index.
-  @param OptionNumber    The boot option index.
-
-  @retval TRUE           The Legacy boot option is found.
-  @retval FALSE          The legacy boot option is not found.
-
-**/
-BOOLEAN
-BdsFindLegacyBootOptionByDevTypeAndName (
-  IN UINT16                 *BootOrder,
-  IN UINTN                  BootOptionNum,
-  IN UINT16                 DevType,
-  IN CHAR16                 *DevName,
-  OUT UINT32                *Attribute,
-  OUT UINT16                *BbsIndex,
-  OUT UINT16                *OptionNumber
-  )
-{
-  UINTN     Index;
-  CHAR16    BootOption[9];
-  UINTN     BootOptionSize;
-  UINT8     *BootOptionVar;
-  BBS_TABLE *BbsEntry;
-  BOOLEAN   Found;
-
-  BbsEntry  = NULL;
-  Found     = FALSE;
-
-  if (NULL == BootOrder) {
-    return Found;
-  }
-
-  //
-  // Loop all boot option from variable
-  //
-  for (Index = 0; Index < BootOptionNum; Index++) {
-    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", (UINTN) BootOrder[Index]);
-    BootOptionVar = BdsLibGetVariableAndSize (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      &BootOptionSize
-                      );
-    if (NULL == BootOptionVar) {
-      continue;
-    }
-
-    //
-    // Skip Non-legacy boot option
-    //
-    if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, BbsIndex)) {
-      FreePool (BootOptionVar);
-      continue;
-    }
-
-    if (
-        (BbsEntry->DeviceType != DevType) ||
-        (StrCmp (DevName, (CHAR16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) != 0)
-       ) {
-      FreePool (BootOptionVar);
-      continue;
-    }
-
-    *Attribute    = *(UINT32 *) BootOptionVar;
-    *OptionNumber = BootOrder[Index];
-    Found         = TRUE;
-    FreePool (BootOptionVar);
-    break;
-  }
-
-  return Found;
-}
-
-/**
-  Create a legacy boot option.
-
-  @param BbsItem         The BBS Table entry.
-  @param Index           Index of the specified entry in BBS table.
-  @param BootOrderList   The boot order list.
-  @param BootOrderListSize The size of boot order list.
-
-  @retval EFI_OUT_OF_RESOURCE  No enough memory.
-  @retval EFI_SUCCESS          The function complete successfully.
-  @return Other value if the legacy boot option is not created.
-
-**/
-EFI_STATUS
-BdsCreateOneLegacyBootOption (
-  IN BBS_TABLE              *BbsItem,
-  IN UINTN                  Index,
-  IN OUT UINT16             **BootOrderList,
-  IN OUT UINTN              *BootOrderListSize
-  )
-{
-  BBS_BBS_DEVICE_PATH       BbsDevPathNode;
-  EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
-
-  DevPath                       = NULL;
-
-  //
-  // Create device path node.
-  //
-  BbsDevPathNode.Header.Type    = BBS_DEVICE_PATH;
-  BbsDevPathNode.Header.SubType = BBS_BBS_DP;
-  SetDevicePathNodeLength (&BbsDevPathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));
-  BbsDevPathNode.DeviceType = BbsItem->DeviceType;
-  CopyMem (&BbsDevPathNode.StatusFlag, &BbsItem->StatusFlags, sizeof (UINT16));
-
-  DevPath = AppendDevicePathNode (
-              NULL,
-              (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevPathNode
-              );
-  if (NULL == DevPath) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  Status = BdsCreateLegacyBootOption (
-            BbsItem,
-            DevPath,
-            Index,
-            BootOrderList,
-            BootOrderListSize
-            );
-  BbsItem->BootPriority = 0x00;
-
-  FreePool (DevPath);
-
-  return Status;
-}
-
-/**
-  Add the legacy boot options from BBS table if they do not exist.
-
-  @retval EFI_SUCCESS          The boot options are added successfully 
-                               or they are already in boot options.
-  @retval EFI_NOT_FOUND        No legacy boot options is found.
-  @retval EFI_OUT_OF_RESOURCE  No enough memory.
-  @return Other value          LegacyBoot options are not added.
-**/
-EFI_STATUS
-EFIAPI
-BdsAddNonExistingLegacyBootOptions (
-  VOID
-  )
-{
-  UINT16                    *BootOrder;
-  UINTN                     BootOrderSize;
-  EFI_STATUS                Status;
-  CHAR16                    Desc[100];
-  UINT16                    HddCount;
-  UINT16                    BbsCount;
-  HDD_INFO                  *LocalHddInfo;
-  BBS_TABLE                 *LocalBbsTable;
-  UINT16                    BbsIndex;
-  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
-  UINT16                    Index;
-  UINT32                    Attribute;
-  UINT16                    OptionNumber;
-  BOOLEAN                   Exist;
-
-  HddCount      = 0;
-  BbsCount      = 0;
-  LocalHddInfo  = NULL;
-  LocalBbsTable = NULL;
-
-  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  LegacyBios->GetBbsInfo (
-                LegacyBios,
-                &HddCount,
-                &LocalHddInfo,
-                &BbsCount,
-                &LocalBbsTable
-                );
-
-  BootOrder = BdsLibGetVariableAndSize (
-                L"BootOrder",
-                &gEfiGlobalVariableGuid,
-                &BootOrderSize
-                );
-  if (BootOrder == NULL) {
-    BootOrderSize = 0;
-  }
-
-  for (Index = 0; Index < BbsCount; Index++) {
-    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
-        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
-        ) {
-      continue;
-    }
-
-    BdsBuildLegacyDevNameString (&LocalBbsTable[Index], Index, sizeof (Desc), Desc);
-
-    Exist = BdsFindLegacyBootOptionByDevTypeAndName (
-              BootOrder,
-              BootOrderSize / sizeof (UINT16),
-              LocalBbsTable[Index].DeviceType,
-              Desc,
-              &Attribute,
-              &BbsIndex,
-              &OptionNumber
-              );
-    if (!Exist) {
-      //
-      // Not found such type of legacy device in boot options or we found but it's disabled
-      // so we have to create one and put it to the tail of boot order list
-      //
-      Status = BdsCreateOneLegacyBootOption (
-                &LocalBbsTable[Index],
-                Index,
-                &BootOrder,
-                &BootOrderSize
-                );
-      if (!EFI_ERROR (Status)) {
-        ASSERT (BootOrder != NULL);
-        BbsIndex     = Index;
-        OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
-      }
-    }
-
-    ASSERT (BbsIndex == Index);
-  }
-
-  Status = gRT->SetVariable (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  BootOrderSize,
-                  BootOrder
-                  );
-  if (BootOrder != NULL) {
-    FreePool (BootOrder);
-  }
-
-  return Status;
-}
-
-/**
-  Fill the device order buffer.
-
-  @param BbsTable        The BBS table.
-  @param BbsType         The BBS Type.
-  @param BbsCount        The BBS Count.
-  @param Buf             device order buffer.
-
-  @return The device order buffer.
-
-**/
-UINT16 *
-BdsFillDevOrderBuf (
-  IN BBS_TABLE                    *BbsTable,
-  IN BBS_TYPE                     BbsType,
-  IN UINTN                        BbsCount,
-  OUT UINT16                      *Buf
-  )
-{
-  UINTN Index;
-
-  for (Index = 0; Index < BbsCount; Index++) {
-    if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {
-      continue;
-    }
-
-    if (BbsTable[Index].DeviceType != BbsType) {
-      continue;
-    }
-
-    *Buf = (UINT16) (Index & 0xFF);
-    Buf++;
-  }
-
-  return Buf;
-}
-
-/**
-  Create the device order buffer.
-
-  @param BbsTable        The BBS table.
-  @param BbsCount        The BBS Count.
-
-  @retval EFI_SUCCES             The buffer is created and the EFI variable named 
-                                 VAR_LEGACY_DEV_ORDER and gEfiLegacyDevOrderVariableGuid is
-                                 set correctly.
-  @retval EFI_OUT_OF_RESOURCES   Memmory or storage is not enough.
-  @retval EFI_DEVICE_ERROR       Fail to add the device order into EFI variable fail
-                                 because of hardware error.
-**/
-EFI_STATUS
-BdsCreateDevOrder (
-  IN BBS_TABLE                  *BbsTable,
-  IN UINT16                     BbsCount
-  )
-{
-  UINTN                       Index;
-  UINTN                       FDCount;
-  UINTN                       HDCount;
-  UINTN                       CDCount;
-  UINTN                       NETCount;
-  UINTN                       BEVCount;
-  UINTN                       TotalSize;
-  UINTN                       HeaderSize;
-  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
-  LEGACY_DEV_ORDER_ENTRY      *DevOrderPtr;
-  EFI_STATUS                  Status;
-
-  FDCount     = 0;
-  HDCount     = 0;
-  CDCount     = 0;
-  NETCount    = 0;
-  BEVCount    = 0;
-  TotalSize   = 0;
-  HeaderSize  = sizeof (BBS_TYPE) + sizeof (UINT16);
-  DevOrder    = NULL;
-  Status      = EFI_SUCCESS;
-
-  //
-  // Count all boot devices
-  //
-  for (Index = 0; Index < BbsCount; Index++) {
-    if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {
-      continue;
-    }
-
-    switch (BbsTable[Index].DeviceType) {
-    case BBS_FLOPPY:
-      FDCount++;
-      break;
-
-    case BBS_HARDDISK:
-      HDCount++;
-      break;
-
-    case BBS_CDROM:
-      CDCount++;
-      break;
-
-    case BBS_EMBED_NETWORK:
-      NETCount++;
-      break;
-
-    case BBS_BEV_DEVICE:
-      BEVCount++;
-      break;
-
-    default:
-      break;
-    }
-  }
-
-  TotalSize += (HeaderSize + sizeof (UINT16) * FDCount);
-  TotalSize += (HeaderSize + sizeof (UINT16) * HDCount);
-  TotalSize += (HeaderSize + sizeof (UINT16) * CDCount);
-  TotalSize += (HeaderSize + sizeof (UINT16) * NETCount);
-  TotalSize += (HeaderSize + sizeof (UINT16) * BEVCount);
-
-  //
-  // Create buffer to hold all boot device order
-  //
-  DevOrder = AllocateZeroPool (TotalSize);
-  if (NULL == DevOrder) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-  DevOrderPtr          = DevOrder;
-
-  DevOrderPtr->BbsType = BBS_FLOPPY;
-  DevOrderPtr->Length  = (UINT16) (sizeof (DevOrderPtr->Length) + FDCount * sizeof (UINT16));
-  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_FLOPPY, BbsCount, DevOrderPtr->Data);
-
-  DevOrderPtr->BbsType = BBS_HARDDISK;
-  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));
-  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_HARDDISK, BbsCount, DevOrderPtr->Data);
-  
-  DevOrderPtr->BbsType = BBS_CDROM;
-  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));
-  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_CDROM, BbsCount, DevOrderPtr->Data);
-  
-  DevOrderPtr->BbsType = BBS_EMBED_NETWORK;
-  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));
-  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_EMBED_NETWORK, BbsCount, DevOrderPtr->Data);
-
-  DevOrderPtr->BbsType = BBS_BEV_DEVICE;
-  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));
-  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_BEV_DEVICE, BbsCount, DevOrderPtr->Data);
-
-  ASSERT (TotalSize == (UINTN) ((UINT8 *) DevOrderPtr - (UINT8 *) DevOrder));
-
-  //
-  // Save device order for legacy boot device to variable.
-  //
-  Status = gRT->SetVariable (
-                  VAR_LEGACY_DEV_ORDER,
-                  &gEfiLegacyDevOrderVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  TotalSize,
-                  DevOrder
-                  );
-  FreePool (DevOrder);
-
-  return Status;
-}
-
-/**
-  Add the legacy boot devices from BBS table into 
-  the legacy device boot order.
-
-  @retval EFI_SUCCESS           The boot devices are added successfully.
-  @retval EFI_NOT_FOUND         The legacy boot devices are not found.
-  @retval EFI_OUT_OF_RESOURCES  Memmory or storage is not enough.
-  @retval EFI_DEVICE_ERROR      Fail to add the legacy device boot order into EFI variable
-                                because of hardware error.
-**/
-EFI_STATUS
-EFIAPI
-BdsUpdateLegacyDevOrder (
-  VOID
-  )
-{
-  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
-  LEGACY_DEV_ORDER_ENTRY      *NewDevOrder;
-  LEGACY_DEV_ORDER_ENTRY      *Ptr;
-  LEGACY_DEV_ORDER_ENTRY      *NewPtr;
-  UINTN                       DevOrderSize;
-  EFI_LEGACY_BIOS_PROTOCOL    *LegacyBios;
-  EFI_STATUS                  Status;
-  UINT16                      HddCount;
-  UINT16                      BbsCount;
-  HDD_INFO                    *LocalHddInfo;
-  BBS_TABLE                   *LocalBbsTable;
-  UINTN                       Index;
-  UINTN                       Index2;
-  UINTN                       *Idx;
-  UINTN                       FDCount;
-  UINTN                       HDCount;
-  UINTN                       CDCount;
-  UINTN                       NETCount;
-  UINTN                       BEVCount;
-  UINTN                       TotalSize;
-  UINTN                       HeaderSize;
-  UINT16                      *NewFDPtr;
-  UINT16                      *NewHDPtr;
-  UINT16                      *NewCDPtr;
-  UINT16                      *NewNETPtr;
-  UINT16                      *NewBEVPtr;
-  UINT16                      *NewDevPtr;
-  UINTN                       FDIndex;
-  UINTN                       HDIndex;
-  UINTN                       CDIndex;
-  UINTN                       NETIndex;
-  UINTN                       BEVIndex;
-
-  Idx           = NULL;
-  FDCount       = 0;
-  HDCount       = 0;
-  CDCount       = 0;
-  NETCount      = 0;
-  BEVCount      = 0;
-  TotalSize     = 0;
-  HeaderSize    = sizeof (BBS_TYPE) + sizeof (UINT16);
-  FDIndex       = 0;
-  HDIndex       = 0;
-  CDIndex       = 0;
-  NETIndex      = 0;
-  BEVIndex      = 0;
-  NewDevPtr     = NULL;
-
-  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = LegacyBios->GetBbsInfo (
-                         LegacyBios,
-                         &HddCount,
-                         &LocalHddInfo,
-                         &BbsCount,
-                         &LocalBbsTable
-                         );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  DevOrder = BdsLibGetVariableAndSize (
-               VAR_LEGACY_DEV_ORDER,
-               &gEfiLegacyDevOrderVariableGuid,
-               &DevOrderSize
-               );
-  if (NULL == DevOrder) {
-    return BdsCreateDevOrder (LocalBbsTable, BbsCount);
-  }
-  //
-  // First we figure out how many boot devices with same device type respectively
-  //
-  for (Index = 0; Index < BbsCount; Index++) {
-    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
-        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
-        ) {
-      continue;
-    }
-
-    switch (LocalBbsTable[Index].DeviceType) {
-    case BBS_FLOPPY:
-      FDCount++;
-      break;
-
-    case BBS_HARDDISK:
-      HDCount++;
-      break;
-
-    case BBS_CDROM:
-      CDCount++;
-      break;
-
-    case BBS_EMBED_NETWORK:
-      NETCount++;
-      break;
-
-    case BBS_BEV_DEVICE:
-      BEVCount++;
-      break;
-
-    default:
-      break;
-    }
-  }
-
-  TotalSize += (HeaderSize + FDCount * sizeof (UINT16));
-  TotalSize += (HeaderSize + HDCount * sizeof (UINT16));
-  TotalSize += (HeaderSize + CDCount * sizeof (UINT16));
-  TotalSize += (HeaderSize + NETCount * sizeof (UINT16));
-  TotalSize += (HeaderSize + BEVCount * sizeof (UINT16));
-
-  NewDevOrder = AllocateZeroPool (TotalSize);
-  if (NULL == NewDevOrder) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-
-
-  //
-  // copy FD
-  //
-  Ptr             = DevOrder;
-  NewPtr          = NewDevOrder;
-  NewPtr->BbsType = Ptr->BbsType;
-  NewPtr->Length  = (UINT16) (sizeof (UINT16) + FDCount * sizeof (UINT16));
-  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
-    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_FLOPPY
-        ) {
-      continue;
-    }
-
-    NewPtr->Data[FDIndex] = Ptr->Data[Index];
-    FDIndex++;
-  }
-  NewFDPtr = NewPtr->Data;
-
-  //
-  // copy HD
-  //
-  Ptr             = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
-  NewPtr          = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
-  NewPtr->BbsType = Ptr->BbsType;
-  NewPtr->Length  = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));
-  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
-    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_HARDDISK
-        ) {
-      continue;
-    }
-
-    NewPtr->Data[HDIndex] = Ptr->Data[Index];
-    HDIndex++;
-  }
-  NewHDPtr = NewPtr->Data;
-
-  //
-  // copy CD
-  //
-  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
-  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
-  NewPtr->BbsType = Ptr->BbsType;
-  NewPtr->Length  = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));
-  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
-    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_CDROM
-        ) {
-      continue;
-    }
-
-    NewPtr->Data[CDIndex] = Ptr->Data[Index];
-    CDIndex++;
-  }
-  NewCDPtr = NewPtr->Data;
-
-  //
-  // copy NET
-  //
-  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
-  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
-  NewPtr->BbsType = Ptr->BbsType;
-  NewPtr->Length  = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));
-  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
-    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_EMBED_NETWORK
-        ) {
-      continue;
-    }
-
-    NewPtr->Data[NETIndex] = Ptr->Data[Index];
-    NETIndex++;
-  }
-  NewNETPtr = NewPtr->Data;
-  
-  //
-  // copy BEV
-  //
-  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
-  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
-  NewPtr->BbsType = Ptr->BbsType;
-  NewPtr->Length  = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));
-  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
-    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
-        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_BEV_DEVICE
-        ) {
-      continue;
-    }
-
-    NewPtr->Data[BEVIndex] = Ptr->Data[Index];
-    BEVIndex++;
-  }
-  NewBEVPtr = NewPtr->Data;
-
-  for (Index = 0; Index < BbsCount; Index++) {
-    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
-        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
-        ) {
-      continue;
-    }
-
-    switch (LocalBbsTable[Index].DeviceType) {
-    case BBS_FLOPPY:
-      Idx       = &FDIndex;
-      NewDevPtr = NewFDPtr;
-      break;
-
-    case BBS_HARDDISK:
-      Idx       = &HDIndex;
-      NewDevPtr = NewHDPtr;
-      break;
-
-    case BBS_CDROM:
-      Idx       = &CDIndex;
-      NewDevPtr = NewCDPtr;
-      break;
-
-    case BBS_EMBED_NETWORK:
-      Idx       = &NETIndex;
-      NewDevPtr = NewNETPtr;
-      break;
-
-    case BBS_BEV_DEVICE:
-      Idx       = &BEVIndex;
-      NewDevPtr = NewBEVPtr;
-      break;
-
-    default:
-      Idx = NULL;
-      break;
-    }
-    //
-    // at this point we have copied those valid indexes to new buffer
-    // and we should check if there is any new appeared boot device
-    //
-    if (Idx != NULL) {
-      for (Index2 = 0; Index2 < *Idx; Index2++) {
-        if ((NewDevPtr[Index2] & 0xFF) == (UINT16) Index) {
-          break;
-        }
-      }
-
-      if (Index2 == *Idx) {
-        //
-        // Index2 == *Idx means we didn't find Index
-        // so Index is a new appeared device's index in BBS table
-        // insert it before disabled indexes.
-        //
-        for (Index2 = 0; Index2 < *Idx; Index2++) {
-          if ((NewDevPtr[Index2] & 0xFF00) == 0xFF00) {
-            break;
-          }
-        }
-        CopyMem (&NewDevPtr[Index2 + 1], &NewDevPtr[Index2], (*Idx - Index2) * sizeof (UINT16));
-        NewDevPtr[Index2] = (UINT16) (Index & 0xFF);
-        (*Idx)++;
-      }
-    }
-  }
-
-  FreePool (DevOrder);
-
-  Status = gRT->SetVariable (
-                  VAR_LEGACY_DEV_ORDER,
-                  &gEfiLegacyDevOrderVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  TotalSize,
-                  NewDevOrder
-                  );
-  FreePool (NewDevOrder);
-
-  return Status;
-}
-
-/**
-  Set Boot Priority for specified device type.
-
-  @param DeviceType      The device type.
-  @param BbsIndex        The BBS index to set the highest priority. Ignore when -1.
-  @param LocalBbsTable   The BBS table.
-  @param Priority        The prority table.
-
-  @retval EFI_SUCCESS           The function completes successfully.
-  @retval EFI_NOT_FOUND         Failed to find device.
-  @retval EFI_OUT_OF_RESOURCES  Failed to get the efi variable of device order.
-
-**/
-EFI_STATUS
-BdsSetBootPriority4SameTypeDev (
-  IN UINT16                                              DeviceType,
-  IN UINTN                                               BbsIndex,
-  IN OUT BBS_TABLE                                       *LocalBbsTable,
-  IN OUT UINT16                                          *Priority
-  )
-{
-  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
-  LEGACY_DEV_ORDER_ENTRY      *DevOrderPtr;
-  UINTN                       DevOrderSize;
-  UINTN                       Index;
-
-  DevOrder = BdsLibGetVariableAndSize (
-               VAR_LEGACY_DEV_ORDER,
-               &gEfiLegacyDevOrderVariableGuid,
-               &DevOrderSize
-               );
-  if (NULL == DevOrder) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  DevOrderPtr = DevOrder;
-  while ((UINT8 *) DevOrderPtr < (UINT8 *) DevOrder + DevOrderSize) {
-    if (DevOrderPtr->BbsType == DeviceType) {
-      break;
-    }
-
-    DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) ((UINTN) DevOrderPtr + sizeof (BBS_TYPE) + DevOrderPtr->Length);
-  }
-
-  if ((UINT8 *) DevOrderPtr >= (UINT8 *) DevOrder + DevOrderSize) {
-    FreePool (DevOrder);
-    return EFI_NOT_FOUND;
-  }
-
-  if (BbsIndex != (UINTN) -1) {
-    LocalBbsTable[BbsIndex].BootPriority = *Priority;
-    (*Priority)++;
-  }
-  //
-  // If the high byte of the DevIndex is 0xFF, it indicates that this device has been disabled.
-  //
-  for (Index = 0; Index < DevOrderPtr->Length / sizeof (UINT16) - 1; Index++) {
-    if ((DevOrderPtr->Data[Index] & 0xFF00) == 0xFF00) {
-      //
-      // LocalBbsTable[DevIndex[Index] & 0xFF].BootPriority = BBS_DISABLED_ENTRY;
-      //
-    } else if (DevOrderPtr->Data[Index] != BbsIndex) {
-      LocalBbsTable[DevOrderPtr->Data[Index]].BootPriority = *Priority;
-      (*Priority)++;
-    }
-  }
-
-  FreePool (DevOrder);
-  return EFI_SUCCESS;
-}
-
-/**
-  Print the BBS Table.
-
-  @param LocalBbsTable   The BBS table.
-  @param BbsCount        The count of entry in BBS table.
-**/
-VOID
-PrintBbsTable (
-  IN BBS_TABLE  *LocalBbsTable,
-  IN UINT16     BbsCount
-  )
-{
-  UINT16  Idx;
-
-  DEBUG ((DEBUG_ERROR, "\n"));
-  DEBUG ((DEBUG_ERROR, " NO  Prio bb/dd/ff cl/sc Type Stat segm:offs\n"));
-  DEBUG ((DEBUG_ERROR, "=============================================\n"));
-  for (Idx = 0; Idx < BbsCount; Idx++) {
-    if ((LocalBbsTable[Idx].BootPriority == BBS_IGNORE_ENTRY) ||
-        (LocalBbsTable[Idx].BootPriority == BBS_DO_NOT_BOOT_FROM) ||
-        (LocalBbsTable[Idx].BootPriority == BBS_LOWEST_PRIORITY)
-        ) {
-      continue;
-    }
-
-    DEBUG (
-      (DEBUG_ERROR,
-      " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
-      (UINTN) Idx,
-      (UINTN) LocalBbsTable[Idx].BootPriority,
-      (UINTN) LocalBbsTable[Idx].Bus,
-      (UINTN) LocalBbsTable[Idx].Device,
-      (UINTN) LocalBbsTable[Idx].Function,
-      (UINTN) LocalBbsTable[Idx].Class,
-      (UINTN) LocalBbsTable[Idx].SubClass,
-      (UINTN) LocalBbsTable[Idx].DeviceType,
-      (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,
-      (UINTN) LocalBbsTable[Idx].BootHandlerSegment,
-      (UINTN) LocalBbsTable[Idx].BootHandlerOffset,
-      (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),
-      (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset))
-      );
-  }
-
-  DEBUG ((DEBUG_ERROR, "\n"));
-}
-
-/**
-  Set the boot priority for BBS entries based on boot option entry and boot order.
-
-  @param  Entry             The boot option is to be checked for refresh BBS table.
-  
-  @retval EFI_SUCCESS           The boot priority for BBS entries is refreshed successfully.
-  @retval EFI_NOT_FOUND         BBS entries can't be found.
-  @retval EFI_OUT_OF_RESOURCES  Failed to get the legacy device boot order.
-**/
-EFI_STATUS
-EFIAPI
-BdsRefreshBbsTableForBoot (
-  IN BDS_COMMON_OPTION        *Entry
-  )
-{
-  EFI_STATUS                Status;
-  UINT16                    BbsIndex;
-  UINT16                    HddCount;
-  UINT16                    BbsCount;
-  HDD_INFO                  *LocalHddInfo;
-  BBS_TABLE                 *LocalBbsTable;
-  UINT16                    DevType;
-  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
-  UINTN                     Index;
-  UINT16                    Priority;
-  UINT16                    *BootOrder;
-  UINTN                     BootOrderSize;
-  UINT8                     *BootOptionVar;
-  UINTN                     BootOptionSize;
-  CHAR16                    BootOption[9];
-  UINT8                     *Ptr;
-  UINT16                    DevPathLen;
-  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
-  UINT16                    *DeviceType;
-  UINTN                     DeviceTypeCount;
-  UINTN                     DeviceTypeIndex;
-
-  HddCount      = 0;
-  BbsCount      = 0;
-  LocalHddInfo  = NULL;
-  LocalBbsTable = NULL;
-  DevType       = BBS_UNKNOWN;
-
-  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  LegacyBios->GetBbsInfo (
-                LegacyBios,
-                &HddCount,
-                &LocalHddInfo,
-                &BbsCount,
-                &LocalBbsTable
-                );
-  //
-  // First, set all the present devices' boot priority to BBS_UNPRIORITIZED_ENTRY
-  // We will set them according to the settings setup by user
-  //
-  for (Index = 0; Index < BbsCount; Index++) {
-    if (!((BBS_IGNORE_ENTRY == LocalBbsTable[Index].BootPriority) ||
-        (BBS_DO_NOT_BOOT_FROM == LocalBbsTable[Index].BootPriority) ||
-         (BBS_LOWEST_PRIORITY == LocalBbsTable[Index].BootPriority))) {
-      LocalBbsTable[Index].BootPriority = BBS_UNPRIORITIZED_ENTRY;
-    }
-  }
-  //
-  // boot priority always starts at 0
-  //
-  Priority = 0;
-  if (Entry->LoadOptionsSize == sizeof (BBS_TABLE) + sizeof (UINT16)) {
-    //
-    // If Entry stands for a legacy boot option, we prioritize the devices with the same type first.
-    //
-    DevType  = ((BBS_TABLE *) Entry->LoadOptions)->DeviceType;
-    BbsIndex = *(UINT16 *) ((BBS_TABLE *) Entry->LoadOptions + 1);
-    Status = BdsSetBootPriority4SameTypeDev (
-              DevType,
-              BbsIndex,
-              LocalBbsTable,
-              &Priority
-              );
-    if (EFI_ERROR (Status)) {
-      return Status;
-    }
-  }
-  //
-  // we have to set the boot priority for other BBS entries with different device types
-  //
-  BootOrder = BdsLibGetVariableAndSize (
-                L"BootOrder",
-                &gEfiGlobalVariableGuid,
-                &BootOrderSize
-                );
-  DeviceType = AllocatePool (BootOrderSize + sizeof (UINT16));
-  ASSERT (DeviceType != NULL);
-
-  DeviceType[0]   = DevType;
-  DeviceTypeCount = 1;
-  for (Index = 0; ((BootOrder != NULL) && (Index < BootOrderSize / sizeof (UINT16))); Index++) {
-    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
-    BootOptionVar = BdsLibGetVariableAndSize (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      &BootOptionSize
-                      );
-    if (NULL == BootOptionVar) {
-      continue;
-    }
-
-    Ptr = BootOptionVar;
-
-    Ptr += sizeof (UINT32);
-    DevPathLen = *(UINT16 *) Ptr;
-    Ptr += sizeof (UINT16);
-    Ptr += StrSize ((UINT16 *) Ptr);
-    DevPath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
-    if (BBS_DEVICE_PATH != DevPath->Type || BBS_BBS_DP != DevPath->SubType) {
-      FreePool (BootOptionVar);
-      continue;
-    }
-
-    Ptr += DevPathLen;
-    DevType = ((BBS_TABLE *) Ptr)->DeviceType;
-    for (DeviceTypeIndex = 0; DeviceTypeIndex < DeviceTypeCount; DeviceTypeIndex++) {
-      if (DeviceType[DeviceTypeIndex] == DevType) {
-        break;
-      }
-    }
-    if (DeviceTypeIndex < DeviceTypeCount) {
-      //
-      // We don't want to process twice for a device type
-      //
-      FreePool (BootOptionVar);
-      continue;
-    }
-
-    DeviceType[DeviceTypeCount] = DevType;
-    DeviceTypeCount++;
-
-    Status = BdsSetBootPriority4SameTypeDev (
-              DevType,
-              (UINTN) -1,
-              LocalBbsTable,
-              &Priority
-              );
-    FreePool (BootOptionVar);
-    if (EFI_ERROR (Status)) {
-      break;
-    }
-  }
-
-  FreePool (DeviceType);
-
-  if (BootOrder != NULL) {
-    FreePool (BootOrder);
-  }
-
-  DEBUG_CODE_BEGIN();
-    PrintBbsTable (LocalBbsTable, BbsCount);
-  DEBUG_CODE_END();
-
-  return Status;
-}
-
-/**
-  Boot the legacy system with the boot option
-
-  @param  Option                 The legacy boot option which have BBS device path
-
-  @retval EFI_UNSUPPORTED        There is no legacybios protocol, do not support
-                                 legacy boot.
-  @retval EFI_STATUS             Return the status of LegacyBios->LegacyBoot ().
-
-**/
-EFI_STATUS
-BdsLibDoLegacyBoot (
-  IN  BDS_COMMON_OPTION           *Option
-  )
-{
-  EFI_STATUS                Status;
-  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
-  EFI_EVENT                 LegacyBootEvent;
-
-  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
-  if (EFI_ERROR (Status)) {
-    //
-    // If no LegacyBios protocol we do not support legacy boot
-    //
-    return EFI_UNSUPPORTED;
-  }
-  //
-  // Notes: if we separate the int 19, then we don't need to refresh BBS
-  //
-  BdsRefreshBbsTableForBoot (Option);
-
-  //
-  // Write boot to OS performance data for legacy boot.
-  //
-  PERF_CODE (
-    //
-    // Create an event to be signalled when Legacy Boot occurs to write performance data.
-    //
-    Status = EfiCreateEventLegacyBootEx(
-               TPL_NOTIFY,
-               BmEndOfBdsPerfCode,
-               NULL, 
-               &LegacyBootEvent
-               );
-    ASSERT_EFI_ERROR (Status);
-  );
-
-  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Description));
-  return LegacyBios->LegacyBoot (
-                      LegacyBios,
-                      (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
-                      Option->LoadOptionsSize,
-                      Option->LoadOptions
-                      );
-}
-
-/**
-  Internal function to check if the input boot option is a valid EFI NV Boot####.
-
-  @param OptionToCheck  Boot option to be checked.
-
-  @retval TRUE      This boot option matches a valid EFI NV Boot####.
-  @retval FALSE     If not.
-
-**/
-BOOLEAN
-IsBootOptionValidNVVarialbe (
-  IN  BDS_COMMON_OPTION             *OptionToCheck
-  )
-{
-  LIST_ENTRY        TempList;
-  BDS_COMMON_OPTION *BootOption;
-  BOOLEAN           Valid;
-  CHAR16            OptionName[20];
-
-  Valid = FALSE;
-
-  InitializeListHead (&TempList);
-  UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionToCheck->BootCurrent);
-
-  BootOption = BdsLibVariableToOption (&TempList, OptionName);
-  if (BootOption == NULL) {
-    return FALSE;
-  }
-
-  //
-  // If the Boot Option Number and Device Path matches, OptionToCheck matches a
-  // valid EFI NV Boot####.
-  //
-  if ((OptionToCheck->BootCurrent == BootOption->BootCurrent) &&
-      (CompareMem (OptionToCheck->DevicePath, BootOption->DevicePath, GetDevicePathSize (OptionToCheck->DevicePath)) == 0))
-      {
-    Valid = TRUE;
-  }
-
-  FreePool (BootOption);
-
-  return Valid;
-}
-
-/**
-  Check whether a USB device match the specified USB Class device path. This
-  function follows "Load Option Processing" behavior in UEFI specification.
-
-  @param UsbIo       USB I/O protocol associated with the USB device.
-  @param UsbClass    The USB Class device path to match.
-
-  @retval TRUE       The USB device match the USB Class device path.
-  @retval FALSE      The USB device does not match the USB Class device path.
-
-**/
-BOOLEAN
-BdsMatchUsbClass (
-  IN EFI_USB_IO_PROTOCOL        *UsbIo,
-  IN USB_CLASS_DEVICE_PATH      *UsbClass
-  )
-{
-  EFI_STATUS                    Status;
-  EFI_USB_DEVICE_DESCRIPTOR     DevDesc;
-  EFI_USB_INTERFACE_DESCRIPTOR  IfDesc;
-  UINT8                         DeviceClass;
-  UINT8                         DeviceSubClass;
-  UINT8                         DeviceProtocol;
-
-  if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
-      (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
-    return FALSE;
-  }
-
-  //
-  // Check Vendor Id and Product Id.
-  //
-  Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  }
-
-  if ((UsbClass->VendorId != 0xffff) &&
-      (UsbClass->VendorId != DevDesc.IdVendor)) {
-    return FALSE;
-  }
-
-  if ((UsbClass->ProductId != 0xffff) &&
-      (UsbClass->ProductId != DevDesc.IdProduct)) {
-    return FALSE;
-  }
-
-  DeviceClass    = DevDesc.DeviceClass;
-  DeviceSubClass = DevDesc.DeviceSubClass;
-  DeviceProtocol = DevDesc.DeviceProtocol;
-  if (DeviceClass == 0) {
-    //
-    // If Class in Device Descriptor is set to 0, use the Class, SubClass and
-    // Protocol in Interface Descriptor instead.
-    //
-    Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
-    if (EFI_ERROR (Status)) {
-      return FALSE;
-    }
-
-    DeviceClass    = IfDesc.InterfaceClass;
-    DeviceSubClass = IfDesc.InterfaceSubClass;
-    DeviceProtocol = IfDesc.InterfaceProtocol;
-  }
-
-  //
-  // Check Class, SubClass and Protocol.
-  //
-  if ((UsbClass->DeviceClass != 0xff) &&
-      (UsbClass->DeviceClass != DeviceClass)) {
-    return FALSE;
-  }
-
-  if ((UsbClass->DeviceSubClass != 0xff) &&
-      (UsbClass->DeviceSubClass != DeviceSubClass)) {
-    return FALSE;
-  }
-
-  if ((UsbClass->DeviceProtocol != 0xff) &&
-      (UsbClass->DeviceProtocol != DeviceProtocol)) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-/**
-  Check whether a USB device match the specified USB WWID device path. This
-  function follows "Load Option Processing" behavior in UEFI specification.
-
-  @param UsbIo       USB I/O protocol associated with the USB device.
-  @param UsbWwid     The USB WWID device path to match.
-
-  @retval TRUE       The USB device match the USB WWID device path.
-  @retval FALSE      The USB device does not match the USB WWID device path.
-
-**/
-BOOLEAN
-BdsMatchUsbWwid (
-  IN EFI_USB_IO_PROTOCOL        *UsbIo,
-  IN USB_WWID_DEVICE_PATH       *UsbWwid
-  )
-{
-  EFI_STATUS                   Status;
-  EFI_USB_DEVICE_DESCRIPTOR    DevDesc;
-  EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
-  UINT16                       *LangIdTable;
-  UINT16                       TableSize;
-  UINT16                       Index;
-  CHAR16                       *CompareStr;
-  UINTN                        CompareLen;
-  CHAR16                       *SerialNumberStr;
-  UINTN                        Length;
-
-  if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
-      (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP )){
-    return FALSE;
-  }
-
-  //
-  // Check Vendor Id and Product Id.
-  //
-  Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  }
-  if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
-      (DevDesc.IdProduct != UsbWwid->ProductId)) {
-    return FALSE;
-  }
-
-  //
-  // Check Interface Number.
-  //
-  Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
-  if (EFI_ERROR (Status)) {
-    return FALSE;
-  }
-  if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
-    return FALSE;
-  }
-
-  //
-  // Check Serial Number.
-  //
-  if (DevDesc.StrSerialNumber == 0) {
-    return FALSE;
-  }
-
-  //
-  // Get all supported languages.
-  //
-  TableSize = 0;
-  LangIdTable = NULL;
-  Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);
-  if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
-    return FALSE;
-  }
-
-  //
-  // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
-  //
-  CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);
-  CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
-  if (CompareStr[CompareLen - 1] == L'\0') {
-    CompareLen--;
-  }
-
-  //
-  // Compare serial number in each supported language.
-  //
-  for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
-    SerialNumberStr = NULL;
-    Status = UsbIo->UsbGetStringDescriptor (
-                      UsbIo,
-                      LangIdTable[Index],
-                      DevDesc.StrSerialNumber,
-                      &SerialNumberStr
-                      );
-    if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
-      continue;
-    }
-
-    Length = StrLen (SerialNumberStr);
-    if ((Length >= CompareLen) &&
-        (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
-      FreePool (SerialNumberStr);
-      return TRUE;
-    }
-
-    FreePool (SerialNumberStr);
-  }
-
-  return FALSE;
-}
-
-/**
-  Find a USB device path which match the specified short-form device path start
-  with USB Class or USB WWID device path and load the boot file then return the 
-  image handle. If ParentDevicePath is NULL, this function will search in all USB
-  devices of the platform. If ParentDevicePath is not NULL,this function will only
-  search in its child devices.
-
-  @param ParentDevicePath      The device path of the parent.
-  @param ShortFormDevicePath   The USB Class or USB WWID device path to match.
-
-  @return  The image Handle if find load file from specified short-form device path
-           or NULL if not found.
-
-**/
-EFI_HANDLE *
-BdsFindUsbDevice (
-  IN EFI_DEVICE_PATH_PROTOCOL   *ParentDevicePath,
-  IN EFI_DEVICE_PATH_PROTOCOL   *ShortFormDevicePath
-  )
-{
-  EFI_STATUS                Status;
-  UINTN                     UsbIoHandleCount;
-  EFI_HANDLE                *UsbIoHandleBuffer;
-  EFI_DEVICE_PATH_PROTOCOL  *UsbIoDevicePath;
-  EFI_USB_IO_PROTOCOL       *UsbIo;
-  UINTN                     Index;
-  UINTN                     ParentSize;
-  UINTN                     Size;
-  EFI_HANDLE                ImageHandle;
-  EFI_HANDLE                Handle;
-  EFI_DEVICE_PATH_PROTOCOL  *FullDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *NextDevicePath;
-
-  FullDevicePath = NULL;
-  ImageHandle    = NULL;
-
-  //
-  // Get all UsbIo Handles.
-  //
-  UsbIoHandleCount = 0;
-  UsbIoHandleBuffer = NULL;
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiUsbIoProtocolGuid,
-                  NULL,
-                  &UsbIoHandleCount,
-                  &UsbIoHandleBuffer
-                  );
-  if (EFI_ERROR (Status) || (UsbIoHandleCount == 0) || (UsbIoHandleBuffer == NULL)) {
-    return NULL;
-  }
-
-  ParentSize = (ParentDevicePath == NULL) ? 0 : GetDevicePathSize (ParentDevicePath);
-  for (Index = 0; Index < UsbIoHandleCount; Index++) {
-    //
-    // Get the Usb IO interface.
-    //
-    Status = gBS->HandleProtocol(
-                    UsbIoHandleBuffer[Index],
-                    &gEfiUsbIoProtocolGuid,
-                    (VOID **) &UsbIo
-                    );
-    if (EFI_ERROR (Status)) {
-      continue;
-    }
-
-    UsbIoDevicePath = DevicePathFromHandle (UsbIoHandleBuffer[Index]);
-    if (UsbIoDevicePath == NULL) {
-      continue;
-    }
-
-    if (ParentDevicePath != NULL) {
-      //
-      // Compare starting part of UsbIoHandle's device path with ParentDevicePath.
-      //
-      Size = GetDevicePathSize (UsbIoDevicePath);
-      if ((Size < ParentSize) ||
-          (CompareMem (UsbIoDevicePath, ParentDevicePath, ParentSize - END_DEVICE_PATH_LENGTH) != 0)) {
-        continue;
-      }
-    }
-
-    if (BdsMatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *) ShortFormDevicePath) ||
-        BdsMatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *) ShortFormDevicePath)) {
-      //
-      // Try to find if there is the boot file in this DevicePath
-      //
-      NextDevicePath = NextDevicePathNode (ShortFormDevicePath);
-      if (!IsDevicePathEnd (NextDevicePath)) {
-        FullDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePath);
-        //
-        // Connect the full device path, so that Simple File System protocol
-        // could be installed for this USB device.
-        //
-        BdsLibConnectDevicePath (FullDevicePath);
-        REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
-        Status = gBS->LoadImage (
-                       TRUE,
-                       gImageHandle,
-                       FullDevicePath,
-                       NULL,
-                       0,
-                       &ImageHandle
-                       );
-        FreePool (FullDevicePath);
-      } else {
-        FullDevicePath = UsbIoDevicePath;
-        Status = EFI_NOT_FOUND;
-      }
-
-      //
-      // If we didn't find an image directly, we need to try as if it is a removable device boot option
-      // and load the image according to the default boot behavior for removable device.
-      //
-      if (EFI_ERROR (Status)) {
-        //
-        // check if there is a bootable removable media could be found in this device path ,
-        // and get the bootable media handle
-        //
-        Handle = BdsLibGetBootableHandle(UsbIoDevicePath);
-        if (Handle == NULL) {
-          continue;
-        }
-        //
-        // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
-        //  machinename is ia32, ia64, x64, ...
-        //
-        FullDevicePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
-        if (FullDevicePath != NULL) {
-          REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
-          Status = gBS->LoadImage (
-                          TRUE,
-                          gImageHandle,
-                          FullDevicePath,
-                          NULL,
-                          0,
-                          &ImageHandle
-                          );
-          if (EFI_ERROR (Status)) {
-            //
-            // The DevicePath failed, and it's not a valid
-            // removable media device.
-            //
-            continue;
-          }
-        } else {
-          continue;
-        }
-      }
-      break;
-    }
-  }
-
-  FreePool (UsbIoHandleBuffer);
-  return ImageHandle;
-}
-
-/**
-  Expand USB Class or USB WWID device path node to be full device path of a USB
-  device in platform then load the boot file on this full device path and return the 
-  image handle.
-
-  This function support following 4 cases:
-  1) Boot Option device path starts with a USB Class or USB WWID device path,
-     and there is no Media FilePath device path in the end.
-     In this case, it will follow Removable Media Boot Behavior.
-  2) Boot Option device path starts with a USB Class or USB WWID device path,
-     and ended with Media FilePath device path.
-  3) Boot Option device path starts with a full device path to a USB Host Controller,
-     contains a USB Class or USB WWID device path node, while not ended with Media
-     FilePath device path. In this case, it will follow Removable Media Boot Behavior.
-  4) Boot Option device path starts with a full device path to a USB Host Controller,
-     contains a USB Class or USB WWID device path node, and ended with Media
-     FilePath device path.
-
-  @param  DevicePath    The Boot Option device path.
-
-  @return  The image handle of boot file, or NULL if there is no boot file found in
-           the specified USB Class or USB WWID device path.
-
-**/
-EFI_HANDLE *
-BdsExpandUsbShortFormDevicePath (
-  IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath
-  )
-{
-  EFI_HANDLE                *ImageHandle;
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *ShortFormDevicePath;
-
-  //
-  // Search for USB Class or USB WWID device path node.
-  //
-  ShortFormDevicePath = NULL;
-  ImageHandle         = NULL;
-  TempDevicePath      = DevicePath;
-  while (!IsDevicePathEnd (TempDevicePath)) {
-    if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&
-        ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||
-         (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {
-      ShortFormDevicePath = TempDevicePath;
-      break;
-    }
-    TempDevicePath = NextDevicePathNode (TempDevicePath);
-  }
-
-  if (ShortFormDevicePath == NULL) {
-    //
-    // No USB Class or USB WWID device path node found, do nothing.
-    //
-    return NULL;
-  }
-
-  if (ShortFormDevicePath == DevicePath) {
-    //
-    // Boot Option device path starts with USB Class or USB WWID device path.
-    //
-    ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);
-    if (ImageHandle == NULL) {
-      //
-      // Failed to find a match in existing devices, connect the short form USB
-      // device path and try again.
-      //
-      BdsLibConnectUsbDevByShortFormDP (0xff, ShortFormDevicePath);
-      ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);
-    }
-  } else {
-    //
-    // Boot Option device path contains USB Class or USB WWID device path node.
-    //
-
-    //
-    // Prepare the parent device path for search.
-    //
-    TempDevicePath = DuplicateDevicePath (DevicePath);
-    ASSERT (TempDevicePath != NULL);
-    SetDevicePathEndNode (((UINT8 *) TempDevicePath) + ((UINTN) ShortFormDevicePath - (UINTN) DevicePath));
-
-    //
-    // The USB Host Controller device path is already in Boot Option device path
-    // and USB Bus driver already support RemainingDevicePath starts with USB
-    // Class or USB WWID device path, so just search in existing USB devices and
-    // doesn't perform ConnectController here.
-    //
-    ImageHandle = BdsFindUsbDevice (TempDevicePath, ShortFormDevicePath);
-    FreePool (TempDevicePath);
-  }
-
-  return ImageHandle;
-}
-
-/**
-  Process the boot option follow the UEFI specification and
-  special treat the legacy boot option with BBS_DEVICE_PATH.
-
-  @param  Option                 The boot option need to be processed
-  @param  DevicePath             The device path which describe where to load the
-                                 boot image or the legacy BBS device path to boot
-                                 the legacy OS
-  @param  ExitDataSize           The size of exit data.
-  @param  ExitData               Data returned when Boot image failed.
-
-  @retval EFI_SUCCESS            Boot from the input boot option successfully.
-  @retval EFI_NOT_FOUND          If the Device Path is not found in the system
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibBootViaBootOption (
-  IN  BDS_COMMON_OPTION             *Option,
-  IN  EFI_DEVICE_PATH_PROTOCOL      *DevicePath,
-  OUT UINTN                         *ExitDataSize,
-  OUT CHAR16                        **ExitData OPTIONAL
-  )
-{
-  EFI_STATUS                Status;
-  EFI_STATUS                StatusLogo;
-  EFI_HANDLE                Handle;
-  EFI_HANDLE                ImageHandle;
-  EFI_DEVICE_PATH_PROTOCOL  *FilePath;
-  EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
-  EFI_DEVICE_PATH_PROTOCOL  *WorkingDevicePath;
-  EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
-  LIST_ENTRY                TempBootLists;
-  EFI_BOOT_LOGO_PROTOCOL    *BootLogo;
-
-  *ExitDataSize = 0;
-  *ExitData     = NULL;
-
-  //
-  // Notes: this code can be remove after the s3 script table
-  // hook on the event EVT_SIGNAL_READY_TO_BOOT or
-  // EVT_SIGNAL_LEGACY_BOOT
-  //
-  Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID **) &AcpiS3Save);
-  if (!EFI_ERROR (Status)) {
-    AcpiS3Save->S3Save (AcpiS3Save, NULL);
-  }
-  //
-  // If it's Device Path that starts with a hard drive path, append it with the front part to compose a
-  // full device path
-  //
-  WorkingDevicePath = NULL;
-  if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
-      (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {
-    WorkingDevicePath = BdsExpandPartitionPartialDevicePathToFull (
-                          (HARDDRIVE_DEVICE_PATH *)DevicePath
-                          );
-    if (WorkingDevicePath != NULL) {
-      DevicePath = WorkingDevicePath;
-    }
-  }
-
-  //
-  // Set Boot Current
-  //
-  if (IsBootOptionValidNVVarialbe (Option)) {
-    //
-    // For a temporary boot (i.e. a boot by selected a EFI Shell using "Boot From File"), Boot Current is actually not valid.
-    // In this case, "BootCurrent" is not created.
-    // Only create the BootCurrent variable when it points to a valid Boot#### variable.
-    //
-    SetVariableAndReportStatusCodeOnError (
-          L"BootCurrent",
-          &gEfiGlobalVariableGuid,
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-          sizeof (UINT16),
-          &Option->BootCurrent
-          );
-  }
-
-  //
-  // Report Status Code to indicate ReadyToBoot event will be signalled
-  //
-  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
-
-  //
-  // Signal the EVT_SIGNAL_READY_TO_BOOT event
-  //
-  EfiSignalEventReadyToBoot();
-
-  //
-  // Expand USB Class or USB WWID device path node to be full device path of a USB
-  // device in platform then load the boot file on this full device path and get the
-  // image handle.
-  //
-  ImageHandle = BdsExpandUsbShortFormDevicePath (DevicePath);
-
-  //
-  // Adjust the different type memory page number just before booting
-  // and save the updated info into the variable for next boot to use
-  //
-  BdsSetMemoryTypeInformationVariable ();
-
-  //
-  // By expanding the USB Class or WWID device path, the ImageHandle has returnned.
-  // Here get the ImageHandle for the non USB class or WWID device path.
-  //
-  if (ImageHandle == NULL) {
-    ASSERT (Option->DevicePath != NULL);
-    if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
-        (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)
-       ) {
-      //
-      // Check to see if we should legacy BOOT. If yes then do the legacy boot
-      //
-      return BdsLibDoLegacyBoot (Option);
-    }
-
-    //
-    // If the boot option point to Internal FV shell, make sure it is valid
-    //
-    Status = BdsLibUpdateFvFileDevicePath (&DevicePath, &gUefiShellFileGuid);
-    if (!EFI_ERROR(Status)) {
-      if (Option->DevicePath != NULL) {
-        FreePool(Option->DevicePath);
-      }
-      Option->DevicePath  = AllocateZeroPool (GetDevicePathSize (DevicePath));
-      ASSERT(Option->DevicePath != NULL);
-      CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
-      //
-      // Update the shell boot option
-      //
-      InitializeListHead (&TempBootLists);
-      BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");
-
-      //
-      // free the temporary device path created by BdsLibUpdateFvFileDevicePath()
-      //
-      FreePool (DevicePath);
-      DevicePath = Option->DevicePath;
-    }
-
-    DEBUG_CODE_BEGIN();
-
-    if (Option->Description == NULL) {
-      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting from unknown device path\n"));
-    } else {
-      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));
-    }
-        
-    DEBUG_CODE_END();
-  
-    //
-    // Report status code for OS Loader LoadImage.
-    //
-    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
-    Status = gBS->LoadImage (
-                    TRUE,
-                    gImageHandle,
-                    DevicePath,
-                    NULL,
-                    0,
-                    &ImageHandle
-                    );
-
-    //
-    // If we didn't find an image directly, we need to try as if it is a removable device boot option
-    // and load the image according to the default boot behavior for removable device.
-    //
-    if (EFI_ERROR (Status)) {
-      //
-      // check if there is a bootable removable media could be found in this device path ,
-      // and get the bootable media handle
-      //
-      Handle = BdsLibGetBootableHandle(DevicePath);
-      if (Handle != NULL) {
-        //
-        // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
-        //  machinename is ia32, ia64, x64, ...
-        //
-        FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
-        if (FilePath != NULL) {
-          REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
-          Status = gBS->LoadImage (
-                          TRUE,
-                          gImageHandle,
-                          FilePath,
-                          NULL,
-                          0,
-                          &ImageHandle
-                          );
-        }
-      }
-    }
-  }
-  //
-  // Provide the image with it's load options
-  //
-  if ((ImageHandle == NULL) || (EFI_ERROR(Status))) {
-    //
-    // Report Status Code to indicate that the failure to load boot option
-    //
-    REPORT_STATUS_CODE (
-      EFI_ERROR_CODE | EFI_ERROR_MINOR,
-      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR)
-      );    
-    goto Done;
-  }
-
-  Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
-  ASSERT_EFI_ERROR (Status);
-
-  if (Option->LoadOptionsSize != 0) {
-    ImageInfo->LoadOptionsSize  = Option->LoadOptionsSize;
-    ImageInfo->LoadOptions      = Option->LoadOptions;
-  }
-
-  //
-  // Clean to NULL because the image is loaded directly from the firmwares boot manager.
-  //
-  ImageInfo->ParentHandle = NULL;
-
-  //
-  // Before calling the image, enable the Watchdog Timer for
-  // the 5 Minute period
-  //
-  gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
-
-  //
-  // Write boot to OS performance data for UEFI boot
-  //
-  PERF_CODE (
-    BmEndOfBdsPerfCode (NULL, NULL);
-  );
-
-  //
-  // Report status code for OS Loader StartImage.
-  //
-  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderStart));
-
-  Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
-  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));
-  if (EFI_ERROR (Status)) {
-    //
-    // Report Status Code to indicate that boot failure
-    //
-    REPORT_STATUS_CODE (
-      EFI_ERROR_CODE | EFI_ERROR_MINOR,
-      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED)
-      );
-  }
-
-  //
-  // Clear the Watchdog Timer after the image returns
-  //
-  gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
-
-Done:
-  //
-  // Set Logo status invalid after trying one boot option
-  //
-  BootLogo = NULL;
-  StatusLogo = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
-  if (!EFI_ERROR (StatusLogo) && (BootLogo != NULL)) {
-    BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
-  }
-
-  //
-  // Clear Boot Current
-  // Deleting variable with current implementation shouldn't fail.
-  //
-  gRT->SetVariable (
-        L"BootCurrent",
-        &gEfiGlobalVariableGuid,
-        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-        0,
-        NULL
-        );
-
-  return Status;
-}
-
-
-/**
-  Expand a device path that starts with a hard drive media device path node to be a
-  full device path that includes the full hardware path to the device. We need
-  to do this so it can be booted. As an optimization the front match (the part point
-  to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved in a variable
-  so a connect all is not required on every boot. All successful history device path
-  which point to partition node (the front part) will be saved.
-
-  @param  HardDriveDevicePath    EFI Device Path to boot, if it starts with a hard
-                                 drive media device path.
-  @return A Pointer to the full device path or NULL if a valid Hard Drive devic path
-          cannot be found.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-BdsExpandPartitionPartialDevicePathToFull (
-  IN  HARDDRIVE_DEVICE_PATH      *HardDriveDevicePath
-  )
-{
-  EFI_STATUS                Status;
-  UINTN                     BlockIoHandleCount;
-  EFI_HANDLE                *BlockIoBuffer;
-  EFI_DEVICE_PATH_PROTOCOL  *FullDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *BlockIoDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  UINTN                     Index;
-  UINTN                     InstanceNum;
-  EFI_DEVICE_PATH_PROTOCOL  *CachedDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *TempNewDevicePath;
-  UINTN                     CachedDevicePathSize;
-  BOOLEAN                   DeviceExist;
-  BOOLEAN                   NeedAdjust;
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;
-  UINTN                     Size;
-
-  FullDevicePath = NULL;
-  //
-  // Check if there is prestore HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.
-  // If exist, search the front path which point to partition node in the variable instants.
-  // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system
-  //
-  GetVariable2 (
-    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
-    &gHdBootDevicePathVariablGuid,
-    (VOID **) &CachedDevicePath,
-    &CachedDevicePathSize
-    );
-
-  //
-  // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.
-  //
-  if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {
-    FreePool (CachedDevicePath);
-    CachedDevicePath = NULL;
-    Status = gRT->SetVariable (
-                    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
-                    &gHdBootDevicePathVariablGuid,
-                    0,
-                    0,
-                    NULL
-                    );
-    ASSERT_EFI_ERROR (Status);
-  }
-
-  if (CachedDevicePath != NULL) {
-    TempNewDevicePath = CachedDevicePath;
-    DeviceExist = FALSE;
-    NeedAdjust = FALSE;
-    do {
-      //
-      // Check every instance of the variable
-      // First, check whether the instance contain the partition node, which is needed for distinguishing  multi
-      // partial partition boot option. Second, check whether the instance could be connected.
-      //
-      Instance  = GetNextDevicePathInstance (&TempNewDevicePath, &Size);
-      if (MatchPartitionDevicePathNode (Instance, HardDriveDevicePath)) {
-        //
-        // Connect the device path instance, the device path point to hard drive media device path node
-        // e.g. ACPI() /PCI()/ATA()/Partition()
-        //
-        Status = BdsLibConnectDevicePath (Instance);
-        if (!EFI_ERROR (Status)) {
-          DeviceExist = TRUE;
-          break;
-        }
-      }
-      //
-      // Come here means the first instance is not matched
-      //
-      NeedAdjust = TRUE;
-      FreePool(Instance);
-    } while (TempNewDevicePath != NULL);
-
-    if (DeviceExist) {
-      //
-      // Find the matched device path.
-      // Append the file path information from the boot option and return the fully expanded device path.
-      //
-      DevicePath     = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
-      FullDevicePath = AppendDevicePath (Instance, DevicePath);
-
-      //
-      // Adjust the HD_BOOT_DEVICE_PATH_VARIABLE_NAME instances sequence if the matched one is not first one.
-      //
-      if (NeedAdjust) {
-        //
-        // First delete the matched instance.
-        //
-        TempNewDevicePath = CachedDevicePath;
-        CachedDevicePath  = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );
-        FreePool (TempNewDevicePath);
-
-        //
-        // Second, append the remaining path after the matched instance
-        //
-        TempNewDevicePath = CachedDevicePath;
-        CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );
-        FreePool (TempNewDevicePath);
-        //
-        // Save the matching Device Path so we don't need to do a connect all next time
-        // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
-        //
-        Status = gRT->SetVariable (
-                        HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
-                        &gHdBootDevicePathVariablGuid,
-                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                        GetDevicePathSize (CachedDevicePath),
-                        CachedDevicePath
-                        );
-      }
-
-      FreePool (Instance);
-      FreePool (CachedDevicePath);
-      return FullDevicePath;
-    }
-  }
-
-  //
-  // If we get here we fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, and now we need
-  // to search all devices in the system for a matched partition
-  //
-  BdsLibConnectAllDriversToAllControllers ();
-  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
-  if (EFI_ERROR (Status) || BlockIoHandleCount == 0 || BlockIoBuffer == NULL) {
-    //
-    // If there was an error or there are no device handles that support
-    // the BLOCK_IO Protocol, then return.
-    //
-    return NULL;
-  }
-  //
-  // Loop through all the device handles that support the BLOCK_IO Protocol
-  //
-  for (Index = 0; Index < BlockIoHandleCount; Index++) {
-
-    Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);
-    if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {
-      continue;
-    }
-
-    if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePath)) {
-      //
-      // Find the matched partition device path
-      //
-      DevicePath    = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
-      FullDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);
-
-      //
-      // Save the matched partition device path in HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable
-      //
-      if (CachedDevicePath != NULL) {
-        //
-        // Save the matched partition device path as first instance of HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable
-        //
-        if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {
-          TempNewDevicePath = CachedDevicePath;
-          CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);
-          FreePool(TempNewDevicePath);
-        }
-
-        if (CachedDevicePath != NULL) {
-          TempNewDevicePath = CachedDevicePath;
-          CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
-          FreePool(TempNewDevicePath);
-        } else {
-          CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);
-        }
-
-        //
-        // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller
-        // If the user try to boot many OS in different HDs or partitions, in theory, 
-        // the HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable maybe become larger and larger.
-        //
-        InstanceNum = 0;
-        ASSERT (CachedDevicePath != NULL);
-        TempNewDevicePath = CachedDevicePath;
-        while (!IsDevicePathEnd (TempNewDevicePath)) {
-          TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
-          //
-          // Parse one instance
-          //
-          while (!IsDevicePathEndType (TempNewDevicePath)) {
-            TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
-          }
-          InstanceNum++;
-          //
-          // If the CachedDevicePath variable contain too much instance, only remain 12 instances.
-          //
-          if (InstanceNum >= 12) {
-            SetDevicePathEndNode (TempNewDevicePath);
-            break;
-          }
-        }
-      } else {
-        CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);
-      }
-
-      //
-      // Save the matching Device Path so we don't need to do a connect all next time
-      // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
-      //
-      Status = gRT->SetVariable (
-                      HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
-                      &gHdBootDevicePathVariablGuid,
-                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                      GetDevicePathSize (CachedDevicePath),
-                      CachedDevicePath
-                      );
-
-      break;
-    }
-  }
-
-  if (CachedDevicePath != NULL) {
-    FreePool (CachedDevicePath);
-  }
-  if (BlockIoBuffer != NULL) {
-    FreePool (BlockIoBuffer);
-  }
-  return FullDevicePath;
-}
-
-/**
-  Check whether there is a instance in BlockIoDevicePath, which contain multi device path
-  instances, has the same partition node with HardDriveDevicePath device path
-
-  @param  BlockIoDevicePath      Multi device path instances which need to check
-  @param  HardDriveDevicePath    A device path which starts with a hard drive media
-                                 device path.
-
-  @retval TRUE                   There is a matched device path instance.
-  @retval FALSE                  There is no matched device path instance.
-
-**/
-BOOLEAN
-EFIAPI
-MatchPartitionDevicePathNode (
-  IN  EFI_DEVICE_PATH_PROTOCOL   *BlockIoDevicePath,
-  IN  HARDDRIVE_DEVICE_PATH      *HardDriveDevicePath
-  )
-{
-  HARDDRIVE_DEVICE_PATH     *TmpHdPath;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  BOOLEAN                   Match;
-  EFI_DEVICE_PATH_PROTOCOL  *BlockIoHdDevicePathNode;
-
-  if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {
-    return FALSE;
-  }
-
-  //
-  // Make PreviousDevicePath == the device path node before the end node
-  //
-  DevicePath              = BlockIoDevicePath;
-  BlockIoHdDevicePathNode = NULL;
-
-  //
-  // find the partition device path node
-  //
-  while (!IsDevicePathEnd (DevicePath)) {
-    if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
-        (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
-        ) {
-      BlockIoHdDevicePathNode = DevicePath;
-      break;
-    }
-
-    DevicePath = NextDevicePathNode (DevicePath);
-  }
-
-  if (BlockIoHdDevicePathNode == NULL) {
-    return FALSE;
-  }
-  //
-  // See if the harddrive device path in blockio matches the orig Hard Drive Node
-  //
-  TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;
-  Match = FALSE;
-
-  //
-  // Check for the match
-  //
-  if ((TmpHdPath->MBRType == HardDriveDevicePath->MBRType) &&
-      (TmpHdPath->SignatureType == HardDriveDevicePath->SignatureType)) {
-    switch (TmpHdPath->SignatureType) {
-    case SIGNATURE_TYPE_GUID:
-      Match = CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *)HardDriveDevicePath->Signature);
-      break;
-    case SIGNATURE_TYPE_MBR:
-      Match = (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) == ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0]))));
-      break;
-    default:
-      Match = FALSE;
-      break;
-    }
-  }
-
-  return Match;
-}
-
-/**
-  Delete the boot option associated with the handle passed in.
-
-  @param  Handle                 The handle which present the device path to create
-                                 boot option
-
-  @retval EFI_SUCCESS            Delete the boot option success
-  @retval EFI_NOT_FOUND          If the Device Path is not found in the system
-  @retval EFI_OUT_OF_RESOURCES   Lack of memory resource
-  @retval Other                  Error return value from SetVariable()
-
-**/
-EFI_STATUS
-BdsLibDeleteOptionFromHandle (
-  IN  EFI_HANDLE                 Handle
-  )
-{
-  UINT16                    *BootOrder;
-  UINT8                     *BootOptionVar;
-  UINTN                     BootOrderSize;
-  UINTN                     BootOptionSize;
-  EFI_STATUS                Status;
-  UINTN                     Index;
-  UINT16                    BootOption[BOOT_OPTION_MAX_CHAR];
-  UINTN                     DevicePathSize;
-  UINTN                     OptionDevicePathSize;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *OptionDevicePath;
-  UINT8                     *TempPtr;
-
-  Status        = EFI_SUCCESS;
-  BootOrder     = NULL;
-  BootOrderSize = 0;
-
-  //
-  // Check "BootOrder" variable, if no, means there is no any boot order.
-  //
-  BootOrder = BdsLibGetVariableAndSize (
-                L"BootOrder",
-                &gEfiGlobalVariableGuid,
-                &BootOrderSize
-                );
-  if (BootOrder == NULL) {
-    return EFI_NOT_FOUND;
-  }
-
-  //
-  // Convert device handle to device path protocol instance
-  //
-  DevicePath = DevicePathFromHandle (Handle);
-  if (DevicePath == NULL) {
-    return EFI_NOT_FOUND;
-  }
-  DevicePathSize = GetDevicePathSize (DevicePath);
-
-  //
-  // Loop all boot order variable and find the matching device path
-  //
-  Index = 0;
-  while (Index < BootOrderSize / sizeof (UINT16)) {
-    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
-    BootOptionVar = BdsLibGetVariableAndSize (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      &BootOptionSize
-                      );
-
-    if (BootOptionVar == NULL) {
-      FreePool (BootOrder);
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    if (!ValidateOption(BootOptionVar, BootOptionSize)) {
-      BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
-      FreePool (BootOptionVar);
-      Index++;
-      continue;
-    }
-
-    TempPtr = BootOptionVar;
-    TempPtr += sizeof (UINT32) + sizeof (UINT16);
-    TempPtr += StrSize ((CHAR16 *) TempPtr);
-    OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-    OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);
-
-    //
-    // Check whether the device path match
-    //
-    if ((OptionDevicePathSize == DevicePathSize) &&
-        (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {
-      BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
-      FreePool (BootOptionVar);
-      break;
-    }
-
-    FreePool (BootOptionVar);
-    Index++;
-  }
-
-  //
-  // Adjust number of boot option for "BootOrder" variable.
-  //
-  Status = gRT->SetVariable (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  BootOrderSize,
-                  BootOrder
-                  );
-  //
-  // Shrinking variable with existing variable implementation shouldn't fail.
-  //
-  ASSERT_EFI_ERROR (Status);
-
-  FreePool (BootOrder);
-
-  return Status;
-}
-
-
-/**
-  Delete all invalid EFI boot options.
-
-  @retval EFI_SUCCESS            Delete all invalid boot option success
-  @retval EFI_NOT_FOUND          Variable "BootOrder" is not found
-  @retval EFI_OUT_OF_RESOURCES   Lack of memory resource
-  @retval Other                  Error return value from SetVariable()
-
-**/
-EFI_STATUS
-BdsDeleteAllInvalidEfiBootOption (
-  VOID
-  )
-{
-  UINT16                    *BootOrder;
-  UINT8                     *BootOptionVar;
-  UINTN                     BootOrderSize;
-  UINTN                     BootOptionSize;
-  EFI_STATUS                Status;
-  UINTN                     Index;
-  UINTN                     Index2;
-  UINT16                    BootOption[BOOT_OPTION_MAX_CHAR];
-  EFI_DEVICE_PATH_PROTOCOL  *OptionDevicePath;
-  UINT8                     *TempPtr;
-  CHAR16                    *Description;
-  BOOLEAN                   Corrupted;
-
-  Status           = EFI_SUCCESS;
-  BootOrder        = NULL;
-  Description      = NULL;
-  OptionDevicePath = NULL;
-  BootOrderSize    = 0;
-  Corrupted        = FALSE;
-
-  //
-  // Check "BootOrder" variable firstly, this variable hold the number of boot options
-  //
-  BootOrder = BdsLibGetVariableAndSize (
-                L"BootOrder",
-                &gEfiGlobalVariableGuid,
-                &BootOrderSize
-                );
-  if (NULL == BootOrder) {
-    return EFI_NOT_FOUND;
-  }
-
-  Index = 0;
-  while (Index < BootOrderSize / sizeof (UINT16)) {
-    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
-    BootOptionVar = BdsLibGetVariableAndSize (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      &BootOptionSize
-                      );
-    if (NULL == BootOptionVar) {
-      FreePool (BootOrder);
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    if (!ValidateOption(BootOptionVar, BootOptionSize)) {
-      Corrupted = TRUE;
-    } else {
-      TempPtr = BootOptionVar;
-      TempPtr += sizeof (UINT32) + sizeof (UINT16);
-      Description = (CHAR16 *) TempPtr;
-      TempPtr += StrSize ((CHAR16 *) TempPtr);
-      OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-
-      //
-      // Skip legacy boot option (BBS boot device)
-      //
-      if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&
-          (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {
-        FreePool (BootOptionVar);
-        Index++;
-        continue;
-      }
-    }
-
-    if (Corrupted || !BdsLibIsValidEFIBootOptDevicePathExt (OptionDevicePath, FALSE, Description)) {
-      //
-      // Delete this invalid boot option "Boot####"
-      //
-      Status = gRT->SetVariable (
-                      BootOption,
-                      &gEfiGlobalVariableGuid,
-                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                      0,
-                      NULL
-                      );
-      //
-      // Deleting variable with current variable implementation shouldn't fail.
-      //
-      ASSERT_EFI_ERROR (Status);
-      //
-      // Mark this boot option in boot order as deleted
-      //
-      BootOrder[Index] = 0xffff;
-      Corrupted        = FALSE;
-    }
-
-    FreePool (BootOptionVar);
-    Index++;
-  }
-
-  //
-  // Adjust boot order array
-  //
-  Index2 = 0;
-  for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
-    if (BootOrder[Index] != 0xffff) {
-      BootOrder[Index2] = BootOrder[Index];
-      Index2 ++;
-    }
-  }
-  Status = gRT->SetVariable (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  Index2 * sizeof (UINT16),
-                  BootOrder
-                  );
-  //
-  // Shrinking variable with current variable implementation shouldn't fail.
-  //
-  ASSERT_EFI_ERROR (Status);
-
-  FreePool (BootOrder);
-
-  return Status;
-}
-
-
-/**
-  For EFI boot option, BDS separate them as six types:
-  1. Network - The boot option points to the SimpleNetworkProtocol device.
-               Bds will try to automatically create this type boot option when enumerate.
-  2. Shell   - The boot option points to internal flash shell.
-               Bds will try to automatically create this type boot option when enumerate.
-  3. Removable BlockIo      - The boot option only points to the removable media
-                              device, like USB flash disk, DVD, Floppy etc.
-                              These device should contain a *removable* blockIo
-                              protocol in their device handle.
-                              Bds will try to automatically create this type boot option
-                              when enumerate.
-  4. Fixed BlockIo          - The boot option only points to a Fixed blockIo device,
-                              like HardDisk.
-                              These device should contain a *fixed* blockIo
-                              protocol in their device handle.
-                              BDS will skip fixed blockIo devices, and NOT
-                              automatically create boot option for them. But BDS
-                              will help to delete those fixed blockIo boot option,
-                              whose description rule conflict with other auto-created
-                              boot options.
-  5. Non-BlockIo Simplefile - The boot option points to a device whose handle
-                              has SimpleFileSystem Protocol, but has no blockio
-                              protocol. These devices do not offer blockIo
-                              protocol, but BDS still can get the
-                              \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem
-                              Protocol.
-  6. File    - The boot option points to a file. These boot options are usually
-               created by user manually or OS loader. BDS will not delete or modify
-               these boot options.
-
-  This function will enumerate all possible boot device in the system, and
-  automatically create boot options for Network, Shell, Removable BlockIo,
-  and Non-BlockIo Simplefile devices.
-  It will only execute once of every boot.
-
-  @param  BdsBootOptionList      The header of the link list which indexed all
-                                 current boot options
-
-  @retval EFI_SUCCESS            Finished all the boot device enumerate and create
-                                 the boot option base on that boot device
-
-  @retval EFI_OUT_OF_RESOURCES   Failed to enumerate the boot device and create the boot option list
-**/
-EFI_STATUS
-EFIAPI
-BdsLibEnumerateAllBootOption (
-  IN OUT LIST_ENTRY          *BdsBootOptionList
-  )
-{
-  EFI_STATUS                    Status;
-  UINT16                        FloppyNumber;
-  UINT16                        HarddriveNumber;
-  UINT16                        CdromNumber;
-  UINT16                        UsbNumber;
-  UINT16                        MiscNumber;
-  UINT16                        ScsiNumber;
-  UINT16                        NonBlockNumber;
-  UINTN                         NumberBlockIoHandles;
-  EFI_HANDLE                    *BlockIoHandles;
-  EFI_BLOCK_IO_PROTOCOL         *BlkIo;
-  BOOLEAN                       Removable[2];
-  UINTN                         RemovableIndex;
-  UINTN                         Index;
-  UINTN                         NumOfLoadFileHandles;
-  EFI_HANDLE                    *LoadFileHandles;
-  UINTN                         FvHandleCount;
-  EFI_HANDLE                    *FvHandleBuffer;
-  EFI_FV_FILETYPE               Type;
-  UINTN                         Size;
-  EFI_FV_FILE_ATTRIBUTES        Attributes;
-  UINT32                        AuthenticationStatus;
-  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;
-  UINTN                         DevicePathType;
-  CHAR16                        Buffer[40];
-  EFI_HANDLE                    *FileSystemHandles;
-  UINTN                         NumberFileSystemHandles;
-  BOOLEAN                       NeedDelete;
-  EFI_IMAGE_DOS_HEADER          DosHeader;
-  CHAR8                         *PlatLang;
-  CHAR8                         *LastLang;
-  EFI_IMAGE_OPTIONAL_HEADER_UNION       HdrData;
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;
-  CHAR16                        *MacStr;
-  CHAR16                        *IPverStr;
-  EFI_HANDLE                    *NetworkHandles;
-  UINTN                         BufferSize;
-
-  FloppyNumber    = 0;
-  HarddriveNumber = 0;
-  CdromNumber     = 0;
-  UsbNumber       = 0;
-  MiscNumber      = 0;
-  ScsiNumber      = 0;
-  PlatLang        = NULL;
-  LastLang        = NULL;
-  ZeroMem (Buffer, sizeof (Buffer));
-
-  //
-  // If the boot device enumerate happened, just get the boot
-  // device from the boot order variable
-  //
-  if (mEnumBootDevice) {
-    GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);
-    GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);
-    ASSERT (PlatLang != NULL);
-    if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {
-      Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
-      FreePool (LastLang);
-      FreePool (PlatLang);
-      return Status;
-    } else {
-      Status = gRT->SetVariable (
-        LAST_ENUM_LANGUAGE_VARIABLE_NAME,
-        &gLastEnumLangGuid,
-        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-        AsciiStrSize (PlatLang),
-        PlatLang
-        );
-      //
-      // Failure to set the variable only impacts the performance next time enumerating the boot options.
-      //
-
-      if (LastLang != NULL) {
-        FreePool (LastLang);
-      }
-      FreePool (PlatLang);
-    }
-  }
-
-  //
-  // Notes: this dirty code is to get the legacy boot option from the
-  // BBS table and create to variable as the EFI boot option, it should
-  // be removed after the CSM can provide legacy boot option directly
-  //
-  REFRESH_LEGACY_BOOT_OPTIONS;
-
-  //
-  // Delete invalid boot option
-  //
-  BdsDeleteAllInvalidEfiBootOption ();
-
-  //
-  // Parse removable media followed by fixed media.
-  // The Removable[] array is used by the for-loop below to create removable media boot options 
-  // at first, and then to create fixed media boot options.
-  //
-  Removable[0]  = FALSE;
-  Removable[1]  = TRUE;
-
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiBlockIoProtocolGuid,
-        NULL,
-        &NumberBlockIoHandles,
-        &BlockIoHandles
-        );
-
-  for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {
-    for (Index = 0; Index < NumberBlockIoHandles; Index++) {
-      Status = gBS->HandleProtocol (
-                      BlockIoHandles[Index],
-                      &gEfiBlockIoProtocolGuid,
-                      (VOID **) &BlkIo
-                      );
-      //
-      // skip the logical partition
-      //
-      if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {
-        continue;
-      }
-
-      //
-      // firstly fixed block io then the removable block io
-      //
-      if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {
-        continue;
-      }
-      DevicePath  = DevicePathFromHandle (BlockIoHandles[Index]);
-      DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
-
-      switch (DevicePathType) {
-      case BDS_EFI_ACPI_FLOPPY_BOOT:
-        if (FloppyNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        FloppyNumber++;
-        break;
-
-      //
-      // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.
-      //
-      case BDS_EFI_MESSAGE_ATAPI_BOOT:
-      case BDS_EFI_MESSAGE_SATA_BOOT:
-        if (BlkIo->Media->RemovableMedia) {
-          if (CdromNumber != 0) {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);
-          } else {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));
-          }
-          CdromNumber++;
-        } else {
-          if (HarddriveNumber != 0) {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);
-          } else {
-            UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));
-          }
-          HarddriveNumber++;
-        }
-        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        break;
-
-      case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
-        if (UsbNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        UsbNumber++;
-        break;
-
-      case BDS_EFI_MESSAGE_SCSI_BOOT:
-        if (ScsiNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        ScsiNumber++;
-        break;
-
-      case BDS_EFI_MESSAGE_MISC_BOOT:
-      default:
-        if (MiscNumber != 0) {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
-        } else {
-          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));
-        }
-        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
-        MiscNumber++;
-        break;
-      }
-    }
-  }
-
-  if (NumberBlockIoHandles != 0) {
-    FreePool (BlockIoHandles);
-  }
-
-  //
-  // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
-  //
-  NonBlockNumber = 0;
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiSimpleFileSystemProtocolGuid,
-        NULL,
-        &NumberFileSystemHandles,
-        &FileSystemHandles
-        );
-  for (Index = 0; Index < NumberFileSystemHandles; Index++) {
-    Status = gBS->HandleProtocol (
-                    FileSystemHandles[Index],
-                    &gEfiBlockIoProtocolGuid,
-                    (VOID **) &BlkIo
-                    );
-     if (!EFI_ERROR (Status)) {
-      //
-      //  Skip if the file system handle supports a BlkIo protocol,
-      //
-      continue;
-    }
-
-    //
-    // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
-    //  machinename is ia32, ia64, x64, ...
-    //
-    Hdr.Union  = &HdrData;
-    NeedDelete = TRUE;
-    Status     = BdsLibGetImageHeader (
-                   FileSystemHandles[Index],
-                   EFI_REMOVABLE_MEDIA_FILE_NAME,
-                   &DosHeader,
-                   Hdr
-                   );
-    if (!EFI_ERROR (Status) &&
-        EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
-        Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
-      NeedDelete = FALSE;
-    }
-
-    if (NeedDelete) {
-      //
-      // No such file or the file is not a EFI application, delete this boot option
-      //
-      BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
-    } else {
-      if (NonBlockNumber != 0) {
-        UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);
-      } else {
-        UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));
-      }
-      BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
-      NonBlockNumber++;
-    }
-  }
-
-  if (NumberFileSystemHandles != 0) {
-    FreePool (FileSystemHandles);
-  }
-
-  //
-  // Parse Network Boot Device
-  //
-  NumOfLoadFileHandles = 0;
-  //
-  // Search Load File protocol for PXE boot option.
-  //
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiLoadFileProtocolGuid,
-        NULL,
-        &NumOfLoadFileHandles,
-        &LoadFileHandles
-        );
-
-  for (Index = 0; Index < NumOfLoadFileHandles; Index++) {
-
-//
-//Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.
-//
-
- Status = gBS->HandleProtocol (
-                  LoadFileHandles[Index],
-                  &gEfiDevicePathProtocolGuid,
-                  (VOID **) &DevicePath
-                  );
-  
- ASSERT_EFI_ERROR (Status);
-
-  while (!IsDevicePathEnd (DevicePath)) {
-    if ((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
-        (DevicePath->SubType == MSG_IPv4_DP)) {
-
-  //
-  //Get handle infomation
-  //
-  BufferSize = 0;
-  NetworkHandles = NULL;
-  Status = gBS->LocateHandle (
-                  ByProtocol, 
-                  &gEfiSimpleNetworkProtocolGuid,
-                  NULL,
-                  &BufferSize,
-                  NetworkHandles
-                  );
-
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    NetworkHandles = AllocateZeroPool(BufferSize);
-    if (NetworkHandles == NULL) {
-      return (EFI_OUT_OF_RESOURCES);
-    }
-    Status = gBS->LocateHandle(
-                    ByProtocol,
-                    &gEfiSimpleNetworkProtocolGuid,
-                    NULL,
-                    &BufferSize,
-                    NetworkHandles
-                    );
- }
-               
-  //
-  //Get the MAC string
-  //
-  Status = NetLibGetMacString (
-             *NetworkHandles,
-             NULL,
-             &MacStr
-             );
-  if (EFI_ERROR (Status)) {	
-    return Status;
-  }
-  IPverStr = L" IPv4";
-  UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
-  break;
-  }
-    if((DevicePath->Type == MESSAGING_DEVICE_PATH) &&
-        (DevicePath->SubType == MSG_IPv6_DP)) {
-
-  //
-  //Get handle infomation
-  //
-  BufferSize = 0;
-  NetworkHandles = NULL;
-  Status = gBS->LocateHandle (
-                  ByProtocol, 
-                  &gEfiSimpleNetworkProtocolGuid,
-                  NULL,
-                  &BufferSize,
-                  NetworkHandles
-                  );
-
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    NetworkHandles = AllocateZeroPool(BufferSize);
-    if (NetworkHandles == NULL) {
-       return (EFI_OUT_OF_RESOURCES);
-    }
-    Status = gBS->LocateHandle(
-                    ByProtocol,
-                    &gEfiSimpleNetworkProtocolGuid,
-                    NULL,
-                    &BufferSize,
-                    NetworkHandles
-                    );
- }
-                    
-  //
-  //Get the MAC string
-  //
-  Status = NetLibGetMacString (
-             *NetworkHandles,
-             NULL,
-             &MacStr
-             );
-  if (EFI_ERROR (Status)) {	
-    return Status;
-  }
-      IPverStr = L" IPv6";
-      UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);
-      break;
-    }
-    DevicePath = NextDevicePathNode (DevicePath);
-  }
-  
-    BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);
-  }
-
-  if (NumOfLoadFileHandles != 0) {
-    FreePool (LoadFileHandles);
-  }
-
-  //
-  // Check if we have on flash shell
-  //
-  gBS->LocateHandleBuffer (
-        ByProtocol,
-        &gEfiFirmwareVolume2ProtocolGuid,
-        NULL,
-        &FvHandleCount,
-        &FvHandleBuffer
-        );
-  for (Index = 0; Index < FvHandleCount; Index++) {
-    gBS->HandleProtocol (
-          FvHandleBuffer[Index],
-          &gEfiFirmwareVolume2ProtocolGuid,
-          (VOID **) &Fv
-          );
-
-    Status = Fv->ReadFile (
-                  Fv,
-                  &gUefiShellFileGuid,
-                  NULL,
-                  &Size,
-                  &Type,
-                  &Attributes,
-                  &AuthenticationStatus
-                  );
-    if (EFI_ERROR (Status)) {
-      //
-      // Skip if no shell file in the FV
-      //
-      continue;
-    }
-    //
-    // Build the shell boot option
-    //
-    BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
-  }
-
-  if (FvHandleCount != 0) {
-    FreePool (FvHandleBuffer);
-  }
-  //
-  // Make sure every boot only have one time
-  // boot device enumerate
-  //
-  Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
-  mEnumBootDevice = TRUE;
-
-  return Status;
-}
-
-/**
-  Build the boot option with the handle parsed in
-
-  @param  Handle                 The handle which present the device path to create
-                                 boot option
-  @param  BdsBootOptionList      The header of the link list which indexed all
-                                 current boot options
-  @param  String                 The description of the boot option.
-
-**/
-VOID
-EFIAPI
-BdsLibBuildOptionFromHandle (
-  IN  EFI_HANDLE                 Handle,
-  IN  LIST_ENTRY                 *BdsBootOptionList,
-  IN  CHAR16                     *String
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-
-  DevicePath = DevicePathFromHandle (Handle);
-
-  //
-  // Create and register new boot option
-  //
-  BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOrder");
-}
-
-
-/**
-  Build the on flash shell boot option with the handle parsed in.
-
-  @param  Handle                 The handle which present the device path to create
-                                 on flash shell boot option
-  @param  BdsBootOptionList      The header of the link list which indexed all
-                                 current boot options
-
-**/
-VOID
-EFIAPI
-BdsLibBuildOptionFromShell (
-  IN EFI_HANDLE                  Handle,
-  IN OUT LIST_ENTRY              *BdsBootOptionList
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
-  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;
-
-  DevicePath = DevicePathFromHandle (Handle);
-
-  //
-  // Build the shell device path
-  //
-  EfiInitializeFwVolDevicepathNode (&ShellNode, &gUefiShellFileGuid);
-
-  DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);
-
-  //
-  // Create and register the shell boot option
-  //
-  BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal Shell", L"BootOrder");
-
-}
-
-/**
-  Boot from the UEFI spec defined "BootNext" variable.
-
-**/
-VOID
-EFIAPI
-BdsLibBootNext (
-  VOID
-  )
-{
-  EFI_STATUS        Status;
-  UINT16            *BootNext;
-  UINTN             BootNextSize;
-  CHAR16            Buffer[20];
-  BDS_COMMON_OPTION *BootOption;
-  LIST_ENTRY        TempList;
-  UINTN             ExitDataSize;
-  CHAR16            *ExitData;
-
-  //
-  // Init the boot option name buffer and temp link list
-  //
-  InitializeListHead (&TempList);
-  ZeroMem (Buffer, sizeof (Buffer));
-
-  BootNext = BdsLibGetVariableAndSize (
-              L"BootNext",
-              &gEfiGlobalVariableGuid,
-              &BootNextSize
-              );
-
-  //
-  // Clear the boot next variable first
-  //
-  if (BootNext != NULL) {
-    Status = gRT->SetVariable (
-                    L"BootNext",
-                    &gEfiGlobalVariableGuid,
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                    0,
-                    NULL
-                    );
-    //
-    // Deleting variable with current variable implementation shouldn't fail.
-    //
-    ASSERT_EFI_ERROR (Status);
-
-    //
-    // Start to build the boot option and try to boot
-    //
-    UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);
-    BootOption = BdsLibVariableToOption (&TempList, Buffer);
-    ASSERT (BootOption != NULL);
-    BdsLibConnectDevicePath (BootOption->DevicePath);
-    BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
-    FreePool(BootOption);
-    FreePool(BootNext);
-  }
-
-}
-
-/**
-  Return the bootable media handle.
-  First, check the device is connected
-  Second, check whether the device path point to a device which support SimpleFileSystemProtocol,
-  Third, detect the the default boot file in the Media, and return the removable Media handle.
-
-  @param  DevicePath  Device Path to a  bootable device
-
-  @return  The bootable media handle. If the media on the DevicePath is not bootable, NULL will return.
-
-**/
-EFI_HANDLE
-EFIAPI
-BdsLibGetBootableHandle (
-  IN  EFI_DEVICE_PATH_PROTOCOL      *DevicePath
-  )
-{
-  EFI_STATUS                      Status;
-  EFI_TPL                         OldTpl;
-  EFI_DEVICE_PATH_PROTOCOL        *UpdatedDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL        *DupDevicePath;
-  EFI_HANDLE                      Handle;
-  EFI_BLOCK_IO_PROTOCOL           *BlockIo;
-  VOID                            *Buffer;
-  EFI_DEVICE_PATH_PROTOCOL        *TempDevicePath;
-  UINTN                           Size;
-  UINTN                           TempSize;
-  EFI_HANDLE                      ReturnHandle;
-  EFI_HANDLE                      *SimpleFileSystemHandles;
-
-  UINTN                           NumberSimpleFileSystemHandles;
-  UINTN                           Index;
-  EFI_IMAGE_DOS_HEADER            DosHeader;
-  EFI_IMAGE_OPTIONAL_HEADER_UNION       HdrData;
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;
-
-  UpdatedDevicePath = DevicePath;
-
-  //
-  // Enter to critical section to protect the acquired BlockIo instance 
-  // from getting released due to the USB mass storage hotplug event
-  //
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
-
-  //
-  // Check whether the device is connected
-  //
-  Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevicePath, &Handle);
-  if (EFI_ERROR (Status)) {
-    //
-    // Skip the case that the boot option point to a simple file protocol which does not consume block Io protocol,
-    //
-    Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &UpdatedDevicePath, &Handle);
-    if (EFI_ERROR (Status)) {
-      //
-      // Fail to find the proper BlockIo and simple file protocol, maybe because device not present,  we need to connect it firstly
-      //
-      UpdatedDevicePath = DevicePath;
-      Status            = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
-      gBS->ConnectController (Handle, NULL, NULL, TRUE);
-    }
-  } else {
-    //
-    // For removable device boot option, its contained device path only point to the removable device handle, 
-    // should make sure all its children handles (its child partion or media handles) are created and connected. 
-    //
-    gBS->ConnectController (Handle, NULL, NULL, TRUE); 
-    //
-    // Get BlockIo protocol and check removable attribute
-    //
-    Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
-    ASSERT_EFI_ERROR (Status);
-
-    //
-    // Issue a dummy read to the device to check for media change.
-    // When the removable media is changed, any Block IO read/write will
-    // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is
-    // returned. After the Block IO protocol is reinstalled, subsequent
-    // Block IO read/write will success.
-    //
-    Buffer = AllocatePool (BlockIo->Media->BlockSize);
-    if (Buffer != NULL) {
-      BlockIo->ReadBlocks (
-               BlockIo,
-               BlockIo->Media->MediaId,
-               0,
-               BlockIo->Media->BlockSize,
-               Buffer
-               );
-      FreePool(Buffer);
-    }
-  }
-
-  //
-  // Detect the the default boot file from removable Media
-  //
-
-  //
-  // If fail to get bootable handle specified by a USB boot option, the BDS should try to find other bootable device in the same USB bus
-  // Try to locate the USB node device path first, if fail then use its previous PCI node to search
-  //
-  DupDevicePath = DuplicateDevicePath (DevicePath);
-  ASSERT (DupDevicePath != NULL);
-
-  UpdatedDevicePath = DupDevicePath;
-  Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
-  //
-  // if the resulting device path point to a usb node, and the usb node is a dummy node, should only let device path only point to the previous Pci node
-  // Acpi()/Pci()/Usb() --> Acpi()/Pci()
-  //
-  if ((DevicePathType (UpdatedDevicePath) == MESSAGING_DEVICE_PATH) &&
-      (DevicePathSubType (UpdatedDevicePath) == MSG_USB_DP)) {
-    //
-    // Remove the usb node, let the device path only point to PCI node
-    //
-    SetDevicePathEndNode (UpdatedDevicePath);
-    UpdatedDevicePath = DupDevicePath;
-  } else {
-    UpdatedDevicePath = DevicePath;
-  }
-
-  //
-  // Get the device path size of boot option
-  //
-  Size = GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
-  ReturnHandle = NULL;
-  gBS->LocateHandleBuffer (
-      ByProtocol,
-      &gEfiSimpleFileSystemProtocolGuid,
-      NULL,
-      &NumberSimpleFileSystemHandles,
-      &SimpleFileSystemHandles
-      );
-  for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
-    //
-    // Get the device path size of SimpleFileSystem handle
-    //
-    TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
-    TempSize = GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
-    //
-    // Check whether the device path of boot option is part of the  SimpleFileSystem handle's device path
-    //
-    if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) {
-      //
-      // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
-      //  machinename is ia32, ia64, x64, ...
-      //
-      Hdr.Union = &HdrData;
-      Status = BdsLibGetImageHeader (
-                 SimpleFileSystemHandles[Index],
-                 EFI_REMOVABLE_MEDIA_FILE_NAME,
-                 &DosHeader,
-                 Hdr
-                 );
-      if (!EFI_ERROR (Status) &&
-        EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
-        Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
-        ReturnHandle = SimpleFileSystemHandles[Index];
-        break;
-      }
-    }
-  }
-
-  FreePool(DupDevicePath);
-
-  if (SimpleFileSystemHandles != NULL) {
-    FreePool(SimpleFileSystemHandles);
-  }
-
-  gBS->RestoreTPL (OldTpl);
-
-  return ReturnHandle;
-}
-
-/**
-  Check to see if the network cable is plugged in. If the DevicePath is not
-  connected it will be connected.
-
-  @param  DevicePath             Device Path to check
-
-  @retval TRUE                   DevicePath points to an Network that is connected
-  @retval FALSE                  DevicePath does not point to a bootable network
-
-**/
-BOOLEAN
-BdsLibNetworkBootWithMediaPresent (
-  IN  EFI_DEVICE_PATH_PROTOCOL      *DevicePath
-  )
-{
-  EFI_STATUS                      Status;
-  EFI_DEVICE_PATH_PROTOCOL        *UpdatedDevicePath;
-  EFI_HANDLE                      Handle;
-  EFI_SIMPLE_NETWORK_PROTOCOL     *Snp;
-  BOOLEAN                         MediaPresent;
-  UINT32                          InterruptStatus;
-
-  MediaPresent = FALSE;
-
-  UpdatedDevicePath = DevicePath;
-  //
-  // Locate Load File Protocol for PXE boot option first
-  //
-  Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);
-  if (EFI_ERROR (Status)) {
-    //
-    // Device not present so see if we need to connect it
-    //
-    Status = BdsLibConnectDevicePath (DevicePath);
-    if (!EFI_ERROR (Status)) {
-      //
-      // This one should work after we did the connect
-      //
-      Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);
-    }
-  }
-
-  if (!EFI_ERROR (Status)) {
-    Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);
-    if (EFI_ERROR (Status)) {
-      //
-      // Failed to open SNP from this handle, try to get SNP from parent handle
-      //
-      UpdatedDevicePath = DevicePathFromHandle (Handle);
-      if (UpdatedDevicePath != NULL) {
-        Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);
-        if (!EFI_ERROR (Status)) {
-          //
-          // SNP handle found, get SNP from it
-          //
-          Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp);
-        }
-      }
-    }
-
-    if (!EFI_ERROR (Status)) {
-      if (Snp->Mode->MediaPresentSupported) {
-        if (Snp->Mode->State == EfiSimpleNetworkInitialized) {
-          //
-          // Invoke Snp->GetStatus() to refresh the media status
-          //
-          Snp->GetStatus (Snp, &InterruptStatus, NULL);
-
-          //
-          // In case some one else is using the SNP check to see if it's connected
-          //
-          MediaPresent = Snp->Mode->MediaPresent;
-        } else {
-          //
-          // No one is using SNP so we need to Start and Initialize so
-          // MediaPresent will be valid.
-          //
-          Status = Snp->Start (Snp);
-          if (!EFI_ERROR (Status)) {
-            Status = Snp->Initialize (Snp, 0, 0);
-            if (!EFI_ERROR (Status)) {
-              MediaPresent = Snp->Mode->MediaPresent;
-              Snp->Shutdown (Snp);
-            }
-            Snp->Stop (Snp);
-          }
-        }
-      } else {
-        MediaPresent = TRUE;
-      }
-    }
-  }
-
-  return MediaPresent;
-}
-
-/**
-  For a bootable Device path, return its boot type.
-
-  @param  DevicePath                      The bootable device Path to check
-
-  @retval BDS_EFI_MEDIA_HD_BOOT           If given device path contains MEDIA_DEVICE_PATH type device path node
-                                          which subtype is MEDIA_HARDDRIVE_DP
-  @retval BDS_EFI_MEDIA_CDROM_BOOT        If given device path contains MEDIA_DEVICE_PATH type device path node
-                                          which subtype is MEDIA_CDROM_DP
-  @retval BDS_EFI_ACPI_FLOPPY_BOOT        If given device path contains ACPI_DEVICE_PATH type device path node
-                                          which HID is floppy device.
-  @retval BDS_EFI_MESSAGE_ATAPI_BOOT      If given device path contains MESSAGING_DEVICE_PATH type device path node
-                                          and its last device path node's subtype is MSG_ATAPI_DP.
-  @retval BDS_EFI_MESSAGE_SCSI_BOOT       If given device path contains MESSAGING_DEVICE_PATH type device path node
-                                          and its last device path node's subtype is MSG_SCSI_DP.
-  @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node
-                                          and its last device path node's subtype is MSG_USB_DP.
-  @retval BDS_EFI_MESSAGE_MISC_BOOT       If the device path not contains any media device path node,  and
-                                          its last device path node point to a message device path node.
-  @retval BDS_LEGACY_BBS_BOOT             If given device path contains BBS_DEVICE_PATH type device path node.
-  @retval BDS_EFI_UNSUPPORT               An EFI Removable BlockIO device path not point to a media and message device,
-
-**/
-UINT32
-EFIAPI
-BdsGetBootTypeFromDevicePath (
-  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath
-  )
-{
-  ACPI_HID_DEVICE_PATH          *Acpi;
-  EFI_DEVICE_PATH_PROTOCOL      *TempDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL      *LastDeviceNode;
-  UINT32                        BootType;
-
-  if (NULL == DevicePath) {
-    return BDS_EFI_UNSUPPORT;
-  }
-
-  TempDevicePath = DevicePath;
-
-  while (!IsDevicePathEndType (TempDevicePath)) {
-    switch (DevicePathType (TempDevicePath)) {
-      case BBS_DEVICE_PATH:
-         return BDS_LEGACY_BBS_BOOT;
-      case MEDIA_DEVICE_PATH:
-        if (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP) {
-          return BDS_EFI_MEDIA_HD_BOOT;
-        } else if (DevicePathSubType (TempDevicePath) == MEDIA_CDROM_DP) {
-          return BDS_EFI_MEDIA_CDROM_BOOT;
-        }
-        break;
-      case ACPI_DEVICE_PATH:
-        Acpi = (ACPI_HID_DEVICE_PATH *) TempDevicePath;
-        if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
-          return BDS_EFI_ACPI_FLOPPY_BOOT;
-        }
-        break;
-      case MESSAGING_DEVICE_PATH:
-        //
-        // Get the last device path node
-        //
-        LastDeviceNode = NextDevicePathNode (TempDevicePath);
-        if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {
-          //
-          // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),
-          // skip it
-          //
-          LastDeviceNode = NextDevicePathNode (LastDeviceNode);
-        }
-        //
-        // if the device path not only point to driver device, it is not a messaging device path,
-        //
-        if (!IsDevicePathEndType (LastDeviceNode)) {
-          break;
-        }
-
-        switch (DevicePathSubType (TempDevicePath)) {
-        case MSG_ATAPI_DP:
-          BootType = BDS_EFI_MESSAGE_ATAPI_BOOT;
-          break;
-
-        case MSG_USB_DP:
-          BootType = BDS_EFI_MESSAGE_USB_DEVICE_BOOT;
-          break;
-
-        case MSG_SCSI_DP:
-          BootType = BDS_EFI_MESSAGE_SCSI_BOOT;
-          break;
-
-        case MSG_SATA_DP:
-          BootType = BDS_EFI_MESSAGE_SATA_BOOT;
-          break;
-
-        case MSG_MAC_ADDR_DP:
-        case MSG_VLAN_DP:
-        case MSG_IPv4_DP:
-        case MSG_IPv6_DP:
-          BootType = BDS_EFI_MESSAGE_MAC_BOOT;
-          break;
-
-        default:
-          BootType = BDS_EFI_MESSAGE_MISC_BOOT;
-          break;
-        }
-        return BootType;
-
-      default:
-        break;
-    }
-    TempDevicePath = NextDevicePathNode (TempDevicePath);
-  }
-
-  return BDS_EFI_UNSUPPORT;
-}
-
-/**
-  Check whether the Device path in a boot option point to a valid bootable device,
-  And if CheckMedia is true, check the device is ready to boot now.
-
-  @param  DevPath     the Device path in a boot option
-  @param  CheckMedia  if true, check the device is ready to boot now.
-
-  @retval TRUE        the Device path  is valid
-  @retval FALSE       the Device path  is invalid .
-
-**/
-BOOLEAN
-EFIAPI
-BdsLibIsValidEFIBootOptDevicePath (
-  IN EFI_DEVICE_PATH_PROTOCOL     *DevPath,
-  IN BOOLEAN                      CheckMedia
-  )
-{
-  return BdsLibIsValidEFIBootOptDevicePathExt (DevPath, CheckMedia, NULL);
-}
-
-/**
-  Check whether the Device path in a boot option point to a valid bootable device,
-  And if CheckMedia is true, check the device is ready to boot now.
-  If Description is not NULL and the device path point to a fixed BlockIo
-  device, check the description whether conflict with other auto-created
-  boot options.
-
-  @param  DevPath     the Device path in a boot option
-  @param  CheckMedia  if true, check the device is ready to boot now.
-  @param  Description the description in a boot option
-
-  @retval TRUE        the Device path  is valid
-  @retval FALSE       the Device path  is invalid .
-
-**/
-BOOLEAN
-EFIAPI
-BdsLibIsValidEFIBootOptDevicePathExt (
-  IN EFI_DEVICE_PATH_PROTOCOL     *DevPath,
-  IN BOOLEAN                      CheckMedia,
-  IN CHAR16                       *Description
-  )
-{
-  EFI_STATUS                Status;
-  EFI_HANDLE                Handle;
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *LastDeviceNode;
-  EFI_BLOCK_IO_PROTOCOL     *BlockIo;
-
-  TempDevicePath = DevPath;
-  LastDeviceNode = DevPath;
-
-  //
-  // Check if it's a valid boot option for network boot device.
-  // Check if there is EfiLoadFileProtocol installed. 
-  // If yes, that means there is a boot option for network.
-  //
-  Status = gBS->LocateDevicePath (
-                  &gEfiLoadFileProtocolGuid,
-                  &TempDevicePath,
-                  &Handle
-                  );
-  if (EFI_ERROR (Status)) {
-    //
-    // Device not present so see if we need to connect it
-    //
-    TempDevicePath = DevPath;
-    BdsLibConnectDevicePath (TempDevicePath);
-    Status = gBS->LocateDevicePath (
-                    &gEfiLoadFileProtocolGuid,
-                    &TempDevicePath,
-                    &Handle
-                    );
-  }
-
-  if (!EFI_ERROR (Status)) {
-    if (!IsDevicePathEnd (TempDevicePath)) {
-      //
-      // LoadFile protocol is not installed on handle with exactly the same DevPath
-      //
-      return FALSE;
-    }
-
-    if (CheckMedia) {
-      //
-      // Test if it is ready to boot now
-      //
-      if (BdsLibNetworkBootWithMediaPresent(DevPath)) {
-        return TRUE;
-      }
-    } else {
-      return TRUE;
-    }    
-  }
-
-  //
-  // If the boot option point to a file, it is a valid EFI boot option,
-  // and assume it is ready to boot now
-  //
-  while (!IsDevicePathEnd (TempDevicePath)) {
-    //
-    // If there is USB Class or USB WWID device path node, treat it as valid EFI
-    // Boot Option. BdsExpandUsbShortFormDevicePath () will be used to expand it
-    // to full device path.
-    //
-    if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&
-        ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||
-         (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {
-      return TRUE;
-    }
-
-    LastDeviceNode = TempDevicePath;
-    TempDevicePath = NextDevicePathNode (TempDevicePath);
-  }
-  if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&
-    (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) {
-    return TRUE;
-  }
-
-  //
-  // Check if it's a valid boot option for internal FV application
-  //
-  if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL) {
-    //
-    // If the boot option point to internal FV application, make sure it is valid
-    //
-    TempDevicePath = DevPath;
-    Status = BdsLibUpdateFvFileDevicePath (
-               &TempDevicePath,
-               EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode)
-               );
-    if (Status == EFI_ALREADY_STARTED) {
-      return TRUE;
-    } else {
-      if (Status == EFI_SUCCESS) {
-        FreePool (TempDevicePath);
-      }
-      return FALSE;
-    }
-  }
-
-  //
-  // If the boot option point to a blockIO device:
-  //    if it is a removable blockIo device, it is valid.
-  //    if it is a fixed blockIo device, check its description confliction.
-  //
-  TempDevicePath = DevPath;
-  Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
-  if (EFI_ERROR (Status)) {
-    //
-    // Device not present so see if we need to connect it
-    //
-    Status = BdsLibConnectDevicePath (DevPath);
-    if (!EFI_ERROR (Status)) {
-      //
-      // Try again to get the Block Io protocol after we did the connect
-      //
-      TempDevicePath = DevPath;
-      Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
-    }
-  }
-
-  if (!EFI_ERROR (Status)) {
-    Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
-    if (!EFI_ERROR (Status)) {
-      if (CheckMedia) {
-        //
-        // Test if it is ready to boot now
-        //
-        if (BdsLibGetBootableHandle (DevPath) != NULL) {
-          return TRUE;
-        }
-      } else {
-        return TRUE;
-      }
-    }
-  } else {
-    //
-    // if the boot option point to a simple file protocol which does not consume block Io protocol, it is also a valid EFI boot option,
-    //
-    Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);
-    if (!EFI_ERROR (Status)) {
-      if (CheckMedia) {
-        //
-        // Test if it is ready to boot now
-        //
-        if (BdsLibGetBootableHandle (DevPath) != NULL) {
-          return TRUE;
-        }
-      } else {
-        return TRUE;
-      }
-    }
-  }
-
-  return FALSE;
-}
-
-
-/**
-  According to a file guild, check a Fv file device path is valid. If it is invalid,
-  try to return the valid device path.
-  FV address maybe changes for memory layout adjust from time to time, use this function
-  could promise the Fv file device path is right.
-
-  @param  DevicePath             on input, the Fv file device path need to check on
-                                 output, the updated valid Fv file device path
-  @param  FileGuid               the Fv file guild
-
-  @retval EFI_INVALID_PARAMETER  the input DevicePath or FileGuid is invalid
-                                 parameter
-  @retval EFI_UNSUPPORTED        the input DevicePath does not contain Fv file
-                                 guild at all
-  @retval EFI_ALREADY_STARTED    the input DevicePath has pointed to Fv file, it is
-                                 valid
-  @retval EFI_SUCCESS            has successfully updated the invalid DevicePath,
-                                 and return the updated device path in DevicePath
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibUpdateFvFileDevicePath (
-  IN  OUT EFI_DEVICE_PATH_PROTOCOL      ** DevicePath,
-  IN  EFI_GUID                          *FileGuid
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL      *TempDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL      *LastDeviceNode;
-  EFI_STATUS                    Status;
-  EFI_GUID                      *GuidPoint;
-  UINTN                         Index;
-  UINTN                         FvHandleCount;
-  EFI_HANDLE                    *FvHandleBuffer;
-  EFI_FV_FILETYPE               Type;
-  UINTN                         Size;
-  EFI_FV_FILE_ATTRIBUTES        Attributes;
-  UINT32                        AuthenticationStatus;
-  BOOLEAN                       FindFvFile;
-  EFI_LOADED_IMAGE_PROTOCOL     *LoadedImage;
-  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
-  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;
-  EFI_HANDLE                    FoundFvHandle;
-  EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;
-
-  if ((DevicePath == NULL) || (*DevicePath == NULL)) {
-    return EFI_INVALID_PARAMETER;
-  }
-  if (FileGuid == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Check whether the device path point to the default the input Fv file
-  //
-  TempDevicePath = *DevicePath;
-  LastDeviceNode = TempDevicePath;
-  while (!IsDevicePathEnd (TempDevicePath)) {
-     LastDeviceNode = TempDevicePath;
-     TempDevicePath = NextDevicePathNode (TempDevicePath);
-  }
-  GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
-                (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
-                );
-  if (GuidPoint == NULL) {
-    //
-    // if this option does not points to a Fv file, just return EFI_UNSUPPORTED
-    //
-    return EFI_UNSUPPORTED;
-  }
-  if (!CompareGuid (GuidPoint, FileGuid)) {
-    //
-    // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED
-    //
-    return EFI_UNSUPPORTED;
-  }
-
-  //
-  // Check whether the input Fv file device path is valid
-  //
-  TempDevicePath = *DevicePath;
-  FoundFvHandle = NULL;
-  Status = gBS->LocateDevicePath (
-                  &gEfiFirmwareVolume2ProtocolGuid,
-                  &TempDevicePath,
-                  &FoundFvHandle
-                  );
-  if (!EFI_ERROR (Status)) {
-    Status = gBS->HandleProtocol (
-                    FoundFvHandle,
-                    &gEfiFirmwareVolume2ProtocolGuid,
-                    (VOID **) &Fv
-                    );
-    if (!EFI_ERROR (Status)) {
-      //
-      // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there
-      //
-      Status = Fv->ReadFile (
-                    Fv,
-                    FileGuid,
-                    NULL,
-                    &Size,
-                    &Type,
-                    &Attributes,
-                    &AuthenticationStatus
-                    );
-      if (!EFI_ERROR (Status)) {
-        return EFI_ALREADY_STARTED;
-      }
-    }
-  }
-
-  //
-  // Look for the input wanted FV file in current FV
-  // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV
-  //
-  FindFvFile = FALSE;
-  FoundFvHandle = NULL;
-  Status = gBS->HandleProtocol (
-             gImageHandle,
-             &gEfiLoadedImageProtocolGuid,
-             (VOID **) &LoadedImage
-             );
-  if (!EFI_ERROR (Status)) {
-    Status = gBS->HandleProtocol (
-                    LoadedImage->DeviceHandle,
-                    &gEfiFirmwareVolume2ProtocolGuid,
-                    (VOID **) &Fv
-                    );
-    if (!EFI_ERROR (Status)) {
-      Status = Fv->ReadFile (
-                    Fv,
-                    FileGuid,
-                    NULL,
-                    &Size,
-                    &Type,
-                    &Attributes,
-                    &AuthenticationStatus
-                    );
-      if (!EFI_ERROR (Status)) {
-        FindFvFile = TRUE;
-        FoundFvHandle = LoadedImage->DeviceHandle;
-      }
-    }
-  }
-  //
-  // Second, if fail to find, try to enumerate all FV
-  //
-  if (!FindFvFile) {
-    FvHandleBuffer = NULL;
-    gBS->LocateHandleBuffer (
-          ByProtocol,
-          &gEfiFirmwareVolume2ProtocolGuid,
-          NULL,
-          &FvHandleCount,
-          &FvHandleBuffer
-          );
-    for (Index = 0; Index < FvHandleCount; Index++) {
-      gBS->HandleProtocol (
-            FvHandleBuffer[Index],
-            &gEfiFirmwareVolume2ProtocolGuid,
-            (VOID **) &Fv
-            );
-
-      Status = Fv->ReadFile (
-                    Fv,
-                    FileGuid,
-                    NULL,
-                    &Size,
-                    &Type,
-                    &Attributes,
-                    &AuthenticationStatus
-                    );
-      if (EFI_ERROR (Status)) {
-        //
-        // Skip if input Fv file not in the FV
-        //
-        continue;
-      }
-      FindFvFile = TRUE;
-      FoundFvHandle = FvHandleBuffer[Index];
-      break;
-    }
-
-    if (FvHandleBuffer != NULL) {
-      FreePool (FvHandleBuffer);
-    }
-  }
-
-  if (FindFvFile) {
-    //
-    // Build the shell device path
-    //
-    NewDevicePath = DevicePathFromHandle (FoundFvHandle);
-    EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
-    NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
-    ASSERT (NewDevicePath != NULL);
-    *DevicePath = NewDevicePath;
-    return EFI_SUCCESS;
-  }
-  return EFI_NOT_FOUND;
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c
deleted file mode 100644
index dfeefc01b8..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/** @file
-  BDS Lib functions which relate with connect the device
-
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "InternalBdsLib.h"
-
-
-/**
-  This function will connect all the system driver to controller
-  first, and then special connect the default console, this make
-  sure all the system controller available and the platform default
-  console connected.
-
-**/
-VOID
-EFIAPI
-BdsLibConnectAll (
-  VOID
-  )
-{
-  //
-  // Connect the platform console first
-  //
-  BdsLibConnectAllDefaultConsoles ();
-
-  //
-  // Generic way to connect all the drivers
-  //
-  BdsLibConnectAllDriversToAllControllers ();
-
-  //
-  // Here we have the assumption that we have already had
-  // platform default console
-  //
-  BdsLibConnectAllDefaultConsoles ();
-}
-
-
-/**
-  This function will connect all the system drivers to all controllers
-  first, and then connect all the console devices the system current
-  have. After this we should get all the device work and console available
-  if the system have console device.
-
-**/
-VOID
-BdsLibGenericConnectAll (
-  VOID
-  )
-{
-  //
-  // Most generic way to connect all the drivers
-  //
-  BdsLibConnectAllDriversToAllControllers ();
-  BdsLibConnectAllConsoles ();
-}
-
-/**
-  This function will create all handles associate with every device
-  path node. If the handle associate with one device path node can not
-  be created successfully, then still give chance to do the dispatch,
-  which load the missing drivers if possible.
-
-  @param  DevicePathToConnect   The device path which will be connected, it can be
-                                a multi-instance device path
-
-  @retval EFI_SUCCESS           All handles associate with every device path  node
-                                have been created
-  @retval EFI_OUT_OF_RESOURCES  There is no resource to create new handles
-  @retval EFI_NOT_FOUND         Create the handle associate with one device  path
-                                node failed
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectDevicePath (
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePathToConnect
-  )
-{
-  EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;
-  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *Next;
-  EFI_HANDLE                Handle;
-  EFI_HANDLE                PreviousHandle;
-  UINTN                     Size;
-  EFI_TPL                   CurrentTpl;
-
-  if (DevicePathToConnect == NULL) {
-    return EFI_SUCCESS;
-  }
-
-  CurrentTpl  = EfiGetCurrentTpl ();
-
-  DevicePath        = DuplicateDevicePath (DevicePathToConnect);
-  if (DevicePath == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-  CopyOfDevicePath  = DevicePath;
-  
-  do {
-    //
-    // The outer loop handles multi instance device paths.
-    // Only console variables contain multiple instance device paths.
-    //
-    // After this call DevicePath points to the next Instance
-    //
-    Instance  = GetNextDevicePathInstance (&DevicePath, &Size);
-    if (Instance == NULL) {
-      FreePool (CopyOfDevicePath);
-      return EFI_OUT_OF_RESOURCES;
-    }
-    
-    Next      = Instance;
-    while (!IsDevicePathEndType (Next)) {
-      Next = NextDevicePathNode (Next);
-    }
-
-    SetDevicePathEndNode (Next);
-
-    //
-    // Start the real work of connect with RemainingDevicePath
-    //
-    PreviousHandle = NULL;
-    do {
-      //
-      // Find the handle that best matches the Device Path. If it is only a
-      // partial match the remaining part of the device path is returned in
-      // RemainingDevicePath.
-      //
-      RemainingDevicePath = Instance;
-      Status              = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
-
-      if (!EFI_ERROR (Status)) {
-        if (Handle == PreviousHandle) {
-          //
-          // If no forward progress is made try invoking the Dispatcher.
-          // A new FV may have been added to the system an new drivers
-          // may now be found.
-          // Status == EFI_SUCCESS means a driver was dispatched
-          // Status == EFI_NOT_FOUND means no new drivers were dispatched
-          //
-          if (CurrentTpl == TPL_APPLICATION) {
-            //
-            // Dispatch calls LoadImage/StartImage which cannot run at TPL > TPL_APPLICATION
-            //
-            Status = gDS->Dispatch ();
-          } else {
-            //
-            // Always return EFI_NOT_FOUND here
-            // to prevent dead loop when control handle is found but connection failded case
-            //
-            Status = EFI_NOT_FOUND;
-          }
-        }
-
-        if (!EFI_ERROR (Status)) {
-          PreviousHandle = Handle;
-          //
-          // Connect all drivers that apply to Handle and RemainingDevicePath,
-          // the Recursive flag is FALSE so only one level will be expanded.
-          //
-          // Do not check the connect status here, if the connect controller fail,
-          // then still give the chance to do dispatch, because partial
-          // RemainingDevicepath may be in the new FV
-          //
-          // 1. If the connect fail, RemainingDevicepath and handle will not
-          //    change, so next time will do the dispatch, then dispatch's status
-          //    will take effect
-          // 2. If the connect success, the RemainingDevicepath and handle will
-          //    change, then avoid the dispatch, we have chance to continue the
-          //    next connection
-          //
-          gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
-        }
-      }
-      //
-      // Loop until RemainingDevicePath is an empty device path
-      //
-    } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));
-
-  } while (DevicePath != NULL);
-
-  if (CopyOfDevicePath != NULL) {
-    FreePool (CopyOfDevicePath);
-  }
-  //
-  // All handle with DevicePath exists in the handle database
-  //
-  return Status;
-}
-
-/**
-  This function will connect all current system handles recursively. 
-  
-  gBS->ConnectController() service is invoked for each handle exist in system handler buffer.
-  If the handle is bus type handler, all childrens also will be connected recursively
-  by gBS->ConnectController().
-
-  @retval EFI_SUCCESS           All handles and it's child handle have been connected
-  @retval EFI_STATUS            Error status returned by of gBS->LocateHandleBuffer().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectAllEfi (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-  UINTN       HandleCount;
-  EFI_HANDLE  *HandleBuffer;
-  UINTN       Index;
-
-  Status = gBS->LocateHandleBuffer (
-                  AllHandles,
-                  NULL,
-                  NULL,
-                  &HandleCount,
-                  &HandleBuffer
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  for (Index = 0; Index < HandleCount; Index++) {
-    Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
-  }
-
-  if (HandleBuffer != NULL) {
-    FreePool (HandleBuffer);
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  This function will disconnect all current system handles. 
-  
-  gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
-  If handle is a bus type handle, all childrens also are disconnected recursively by
-  gBS->DisconnectController().
-
-  @retval EFI_SUCCESS           All handles have been disconnected
-  @retval EFI_STATUS            Error status returned by of gBS->LocateHandleBuffer().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibDisconnectAllEfi (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-  UINTN       HandleCount;
-  EFI_HANDLE  *HandleBuffer;
-  UINTN       Index;
-
-  //
-  // Disconnect all
-  //
-  Status = gBS->LocateHandleBuffer (
-                  AllHandles,
-                  NULL,
-                  NULL,
-                  &HandleCount,
-                  &HandleBuffer
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  for (Index = 0; Index < HandleCount; Index++) {
-    Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
-  }
-
-  if (HandleBuffer != NULL) {
-    FreePool (HandleBuffer);
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-/**
-  Connects all drivers to all controllers.
-  This function make sure all the current system driver will manage
-  the correspoinding controllers if have. And at the same time, make
-  sure all the system controllers have driver to manage it if have.
-
-**/
-VOID
-EFIAPI
-BdsLibConnectAllDriversToAllControllers (
-  VOID
-  )
-{
-  EFI_STATUS  Status;
-
-  do {
-    //
-    // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
-    //
-    BdsLibConnectAllEfi ();
-
-    //
-    // Check to see if it's possible to dispatch an more DXE drivers.
-    // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
-    // If anything is Dispatched Status == EFI_SUCCESS and we will try
-    // the connect again.
-    //
-    Status = gDS->Dispatch ();
-
-  } while (!EFI_ERROR (Status));
-
-}
-
-
-/**
-  Connect the specific Usb device which match the short form device path,
-  and whose bus is determined by Host Controller (Uhci or Ehci).
-
-  @param  HostControllerPI      Uhci (0x00) or Ehci (0x20) or Both uhci and ehci
-                                (0xFF)
-  @param  RemainingDevicePath   a short-form device path that starts with the first
-                                element  being a USB WWID or a USB Class device
-                                path
-
-  @return EFI_INVALID_PARAMETER  RemainingDevicePath is NULL pointer.
-                                 RemainingDevicePath is not a USB device path.
-                                 Invalid HostControllerPI type.
-  @return EFI_SUCCESS            Success to connect USB device
-  @return EFI_NOT_FOUND          Fail to find handle for USB controller to connect.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectUsbDevByShortFormDP(
-  IN UINT8                      HostControllerPI,
-  IN EFI_DEVICE_PATH_PROTOCOL   *RemainingDevicePath
-  )
-{
-  EFI_STATUS                            Status;
-  EFI_HANDLE                            *HandleArray;
-  UINTN                                 HandleArrayCount;
-  UINTN                                 Index;
-  EFI_PCI_IO_PROTOCOL                   *PciIo;
-  UINT8                                 Class[3];
-  BOOLEAN                               AtLeastOneConnected;
-
-  //
-  // Check the passed in parameters
-  //
-  if (RemainingDevicePath == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if ((DevicePathType (RemainingDevicePath) != MESSAGING_DEVICE_PATH) ||
-      ((DevicePathSubType (RemainingDevicePath) != MSG_USB_CLASS_DP)
-      && (DevicePathSubType (RemainingDevicePath) != MSG_USB_WWID_DP)
-      )) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (HostControllerPI != 0xFF &&
-      HostControllerPI != 0x00 &&
-      HostControllerPI != 0x20) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Find the usb host controller firstly, then connect with the remaining device path
-  //
-  AtLeastOneConnected = FALSE;
-  Status = gBS->LocateHandleBuffer (
-                  ByProtocol,
-                  &gEfiPciIoProtocolGuid,
-                  NULL,
-                  &HandleArrayCount,
-                  &HandleArray
-                  );
-  if (!EFI_ERROR (Status)) {
-    for (Index = 0; Index < HandleArrayCount; Index++) {
-      Status = gBS->HandleProtocol (
-                      HandleArray[Index],
-                      &gEfiPciIoProtocolGuid,
-                      (VOID **)&PciIo
-                      );
-      if (!EFI_ERROR (Status)) {
-        //
-        // Check whether the Pci device is the wanted usb host controller
-        //
-        Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
-        if (!EFI_ERROR (Status)) {
-          if ((PCI_CLASS_SERIAL == Class[2]) &&
-              (PCI_CLASS_SERIAL_USB == Class[1])) {
-            if (HostControllerPI == Class[0] || HostControllerPI == 0xFF) {
-              Status = gBS->ConnectController (
-                              HandleArray[Index],
-                              NULL,
-                              RemainingDevicePath,
-                              FALSE
-                              );
-              if (!EFI_ERROR(Status)) {
-                AtLeastOneConnected = TRUE;
-              }
-            }
-          }
-        }
-      }
-    }
-
-    if (HandleArray != NULL) {
-      FreePool (HandleArray);
-    }
-
-    if (AtLeastOneConnected) {
-      return EFI_SUCCESS;
-    }
-  }
-
-  return EFI_NOT_FOUND;
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
deleted file mode 100644
index 2fffd9e4bc..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
+++ /dev/null
@@ -1,1061 +0,0 @@
-/** @file
-  BDS Lib functions which contain all the code to connect console device
-
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "InternalBdsLib.h"
-
-
-/**
-  Check if we need to save the EFI variable with "ConVarName" as name
-  as NV type
-  If ConVarName is NULL, then ASSERT().
-  
-  @param ConVarName The name of the EFI variable.
-
-  @retval TRUE    Set the EFI variable as NV type.
-  @retval FALSE   EFI variable as NV type can be set NonNV.
-**/
-BOOLEAN
-IsNvNeed (
-  IN CHAR16 *ConVarName
-  )
-{
-  CHAR16 *Ptr;
-
-  ASSERT (ConVarName != NULL);
-  
-  Ptr = ConVarName;
-
-  //
-  // If the variable includes "Dev" at last, we consider
-  // it does not support NV attribute.
-  //
-  while (*Ptr != L'\0') {
-    Ptr++;
-  }
-
-  if (((INTN)((UINTN)Ptr - (UINTN)ConVarName) / sizeof (CHAR16)) <= 3) {
-    return TRUE;
-  }
-  
-  if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
-    return FALSE;
-  } else {
-    return TRUE;
-  }
-}
-
-/**
-  Fill console handle in System Table if there are no valid console handle in.
-
-  Firstly, check the validation of console handle in System Table. If it is invalid,
-  update it by the first console device handle from EFI console variable. 
-
-  @param  VarName            The name of the EFI console variable.
-  @param  ConsoleGuid        Specified Console protocol GUID.
-  @param  ConsoleHandle      On IN,  console handle in System Table to be checked. 
-                             On OUT, new console handle in system table.
-  @param  ProtocolInterface  On IN,  console protocol on console handle in System Table to be checked. 
-                             On OUT, new console protocol on new console handle in system table.
-
-  @retval TRUE               System Table has been updated.
-  @retval FALSE              System Table hasn't been updated.
-
-**/
-BOOLEAN 
-UpdateSystemTableConsole (
-  IN     CHAR16                          *VarName,
-  IN     EFI_GUID                        *ConsoleGuid,
-  IN OUT EFI_HANDLE                      *ConsoleHandle,
-  IN OUT VOID                            **ProtocolInterface
-  )
-{
-  EFI_STATUS                Status;
-  UINTN                     DevicePathSize;
-  EFI_DEVICE_PATH_PROTOCOL  *FullDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *VarConsole;
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;
-  VOID                      *Interface;
-  EFI_HANDLE                NewHandle;
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
-
-  ASSERT (VarName != NULL);
-  ASSERT (ConsoleHandle != NULL);
-  ASSERT (ConsoleGuid != NULL);
-  ASSERT (ProtocolInterface != NULL);
-
-  if (*ConsoleHandle != NULL) {
-    Status = gBS->HandleProtocol (
-                   *ConsoleHandle,
-                   ConsoleGuid,
-                   &Interface
-                   );
-    if (Status == EFI_SUCCESS && Interface == *ProtocolInterface) {
-      //
-      // If ConsoleHandle is valid and console protocol on this handle also
-      // also matched, just return.
-      //
-      return FALSE;
-    }
-  }
-  
-  //
-  // Get all possible consoles device path from EFI variable
-  //
-  VarConsole = BdsLibGetVariableAndSize (
-                VarName,
-                &gEfiGlobalVariableGuid,
-                &DevicePathSize
-                );
-  if (VarConsole == NULL) {
-    //
-    // If there is no any console device, just return.
-    //
-    return FALSE;
-  }
-
-  FullDevicePath = VarConsole;
-
-  do {
-    //
-    // Check every instance of the console variable
-    //
-    Instance  = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);
-    if (Instance == NULL) {
-      FreePool (FullDevicePath);
-      ASSERT (FALSE);
-    }
-    
-    //
-    // Find console device handle by device path instance
-    //
-    Status = gBS->LocateDevicePath (
-                   ConsoleGuid,
-                   &Instance,
-                   &NewHandle
-                   );
-    if (!EFI_ERROR (Status)) {
-      //
-      // Get the console protocol on this console device handle
-      //
-      Status = gBS->HandleProtocol (
-                     NewHandle,
-                     ConsoleGuid,
-                     &Interface
-                     );
-      if (!EFI_ERROR (Status)) {
-        //
-        // Update new console handle in System Table.
-        //
-        *ConsoleHandle     = NewHandle;
-        *ProtocolInterface = Interface;
-        if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {
-          //
-          // If it is console out device, set console mode 80x25 if current mode is invalid.
-          //
-          TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;
-          if (TextOut->Mode->Mode == -1) {
-            TextOut->SetMode (TextOut, 0);
-          }
-        }
-        return TRUE;
-      }
-    }
-
-  } while (Instance != NULL);
-
-  //
-  // No any available console devcie found.
-  //
-  return FALSE;
-}
-
-/**
-  This function update console variable based on ConVarName, it can
-  add or remove one specific console device path from the variable
-
-  @param  ConVarName               Console related variable name, ConIn, ConOut,
-                                   ErrOut.
-  @param  CustomizedConDevicePath  The console device path which will be added to
-                                   the console variable ConVarName, this parameter
-                                   can not be multi-instance.
-  @param  ExclusiveDevicePath      The console device path which will be removed
-                                   from the console variable ConVarName, this
-                                   parameter can not be multi-instance.
-
-  @retval EFI_UNSUPPORTED          The added device path is same to the removed one.
-  @retval EFI_SUCCESS              Success add or remove the device path from  the
-                                   console variable.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibUpdateConsoleVariable (
-  IN  CHAR16                    *ConVarName,
-  IN  EFI_DEVICE_PATH_PROTOCOL  *CustomizedConDevicePath,
-  IN  EFI_DEVICE_PATH_PROTOCOL  *ExclusiveDevicePath
-  )
-{
-  EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *VarConsole;
-  UINTN                     DevicePathSize;
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *TempNewDevicePath;
-  UINT32                    Attributes;
-
-  VarConsole      = NULL;
-  DevicePathSize  = 0;
-
-  //
-  // Notes: check the device path point, here should check
-  // with compare memory
-  //
-  if (CustomizedConDevicePath == ExclusiveDevicePath) {
-    return EFI_UNSUPPORTED;
-  }
-  //
-  // Delete the ExclusiveDevicePath from current default console
-  //
-  VarConsole = BdsLibGetVariableAndSize (
-                ConVarName,
-                &gEfiGlobalVariableGuid,
-                &DevicePathSize
-                );
-
-  //
-  // Initialize NewDevicePath
-  //
-  NewDevicePath  = VarConsole;
-
-  //
-  // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
-  // In the end, NewDevicePath is the final device path.
-  //
-  if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
-      NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);
-  }
-  //
-  // Try to append customized device path to NewDevicePath.
-  //
-  if (CustomizedConDevicePath != NULL) {
-    if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {
-      //
-      // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
-      //
-      NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);
-      //
-      // In the first check, the default console variable will be _ModuleEntryPoint,
-      // just append current customized device path
-      //
-      TempNewDevicePath = NewDevicePath;
-      NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
-      if (TempNewDevicePath != NULL) {
-        FreePool(TempNewDevicePath);
-      }
-    }
-  }
-
-  //
-  // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
-  //
-  if (IsNvNeed(ConVarName)) {
-    //
-    // ConVarName has NV attribute.
-    //
-    Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
-  } else {
-    //
-    // ConVarName does not have NV attribute.
-    //
-    Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
-  }
-
-  //
-  // Finally, Update the variable of the default console by NewDevicePath
-  //
-  DevicePathSize = GetDevicePathSize (NewDevicePath);
-  Status = SetVariableAndReportStatusCodeOnError (
-             ConVarName,
-             &gEfiGlobalVariableGuid,
-             Attributes,
-             DevicePathSize,
-             NewDevicePath
-             );
-  if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
-    Status = EFI_SUCCESS;
-  }
-
-  if (VarConsole == NewDevicePath) {
-    if (VarConsole != NULL) {
-      FreePool(VarConsole);
-    }
-  } else {
-    if (VarConsole != NULL) {
-      FreePool(VarConsole);
-    }
-    if (NewDevicePath != NULL) {
-      FreePool(NewDevicePath);
-    }
-  }
-
-  return Status;
-
-}
-
-
-/**
-  Connect the console device base on the variable ConVarName, if
-  device path of the ConVarName is multi-instance device path and
-  anyone of the instances is connected success, then this function
-  will return success.
-  If the handle associate with one device path node can not
-  be created successfully, then still give chance to do the dispatch,
-  which load the missing drivers if possible..
-
-  @param  ConVarName               Console related variable name, ConIn, ConOut,
-                                   ErrOut.
-
-  @retval EFI_NOT_FOUND            There is not any console devices connected
-                                   success
-  @retval EFI_SUCCESS              Success connect any one instance of the console
-                                   device path base on the variable ConVarName.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectConsoleVariable (
-  IN  CHAR16                 *ConVarName
-  )
-{
-  EFI_STATUS                Status;
-  EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath;
-  UINTN                     VariableSize;
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;
-  EFI_DEVICE_PATH_PROTOCOL  *Next;
-  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;
-  UINTN                     Size;
-  BOOLEAN                   DeviceExist;
-
-  Status      = EFI_SUCCESS;
-  DeviceExist = FALSE;
-
-  //
-  // Check if the console variable exist
-  //
-  StartDevicePath = BdsLibGetVariableAndSize (
-                      ConVarName,
-                      &gEfiGlobalVariableGuid,
-                      &VariableSize
-                      );
-  if (StartDevicePath == NULL) {
-    return EFI_UNSUPPORTED;
-  }
-
-  CopyOfDevicePath = StartDevicePath;
-  do {
-    //
-    // Check every instance of the console variable
-    //
-    Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);
-    if (Instance == NULL) {
-      FreePool (StartDevicePath);
-      return EFI_UNSUPPORTED;
-    }
-    
-    Next      = Instance;
-    while (!IsDevicePathEndType (Next)) {
-      Next = NextDevicePathNode (Next);
-    }
-
-    SetDevicePathEndNode (Next);
-    //
-    // Connect the USB console
-    // USB console device path is a short-form device path that 
-    //  starts with the first element being a USB WWID
-    //  or a USB Class device path
-    //
-    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
-       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
-       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
-       )) {
-      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);
-      if (!EFI_ERROR (Status)) {
-        DeviceExist = TRUE;
-      }
-    } else {
-      //
-      // Connect the instance device path
-      //
-      Status = BdsLibConnectDevicePath (Instance);
-
-      if (EFI_ERROR (Status)) {
-        //
-        // Delete the instance from the console varialbe
-        //
-        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
-      } else {
-        DeviceExist = TRUE;
-      }
-    }
-    FreePool(Instance);
-  } while (CopyOfDevicePath != NULL);
-
-  FreePool (StartDevicePath);
-
-  if (!DeviceExist) {
-    return EFI_NOT_FOUND;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  This function will search every simpletext device in current system,
-  and make every simpletext device as pertantial console device.
-
-**/
-VOID
-EFIAPI
-BdsLibConnectAllConsoles (
-  VOID
-  )
-{
-  UINTN                     Index;
-  EFI_DEVICE_PATH_PROTOCOL  *ConDevicePath;
-  UINTN                     HandleCount;
-  EFI_HANDLE                *HandleBuffer;
-
-  Index         = 0;
-  HandleCount   = 0;
-  HandleBuffer  = NULL;
-  ConDevicePath = NULL;
-
-  //
-  // Update all the console variables
-  //
-  gBS->LocateHandleBuffer (
-          ByProtocol,
-          &gEfiSimpleTextInProtocolGuid,
-          NULL,
-          &HandleCount,
-          &HandleBuffer
-          );
-
-  for (Index = 0; Index < HandleCount; Index++) {
-    gBS->HandleProtocol (
-            HandleBuffer[Index],
-            &gEfiDevicePathProtocolGuid,
-            (VOID **) &ConDevicePath
-            );
-    BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
-  }
-
-  if (HandleBuffer != NULL) {
-    FreePool(HandleBuffer);
-    HandleBuffer = NULL;
-  }
-
-  gBS->LocateHandleBuffer (
-          ByProtocol,
-          &gEfiSimpleTextOutProtocolGuid,
-          NULL,
-          &HandleCount,
-          &HandleBuffer
-          );
-  for (Index = 0; Index < HandleCount; Index++) {
-    gBS->HandleProtocol (
-            HandleBuffer[Index],
-            &gEfiDevicePathProtocolGuid,
-            (VOID **) &ConDevicePath
-            );
-    BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
-    BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
-  }
-
-  if (HandleBuffer != NULL) {
-    FreePool(HandleBuffer);
-  }
-
-  //
-  // Connect all console variables
-  //
-  BdsLibConnectAllDefaultConsoles ();
-
-}
-
-/**
-  This function will connect console device base on the console
-  device variable ConIn, ConOut and ErrOut.
-
-  @retval EFI_SUCCESS              At least one of the ConIn and ConOut device have
-                                   been connected success.
-  @retval EFI_STATUS               Return the status of BdsLibConnectConsoleVariable ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectAllDefaultConsoles (
-  VOID
-  )
-{
-  EFI_STATUS                Status;
-  BOOLEAN                   SystemTableUpdated;
-
-  //
-  // Connect all default console variables
-  //
-
-  //
-  // It seems impossible not to have any ConOut device on platform,
-  // so we check the status here.
-  //
-  Status = BdsLibConnectConsoleVariable (L"ConOut");
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Insert the performance probe for Console Out
-  //
-  PERF_START (NULL, "ConOut", "BDS", 1);
-  PERF_END (NULL, "ConOut", "BDS", 0);
-
-  //
-  // Because possibly the platform is legacy free, in such case,
-  // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
-  // so we need not check the status.
-  //
-  BdsLibConnectConsoleVariable (L"ConIn");
-
-  //
-  // The _ModuleEntryPoint err out var is legal.
-  //
-  BdsLibConnectConsoleVariable (L"ErrOut");
-
-  SystemTableUpdated = FALSE;
-  //
-  // Fill console handles in System Table if no console device assignd.
-  //
-  if (UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) {
-    SystemTableUpdated = TRUE;
-  }
-  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
-    SystemTableUpdated = TRUE;
-  }
-  if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
-    SystemTableUpdated = TRUE;
-  }
-
-  if (SystemTableUpdated) {
-    //
-    // Update the CRC32 in the EFI System Table header
-    //
-    gST->Hdr.CRC32 = 0;
-    gBS->CalculateCrc32 (
-          (UINT8 *) &gST->Hdr,
-          gST->Hdr.HeaderSize,
-          &gST->Hdr.CRC32
-          );
-  }
-
-  //
-  // If any component set PcdTestKeyUsed to TRUE because use of a test key
-  // was detected, then display a warning message on the debug log and the console
-  //
-  if (PcdGetBool (PcdTestKeyUsed) == TRUE) {
-    DEBUG ((DEBUG_ERROR, "**********************************\n"));
-    DEBUG ((DEBUG_ERROR, "**  WARNING: Test Key is used.  **\n"));
-    DEBUG ((DEBUG_ERROR, "**********************************\n"));
-    Print (L"**  WARNING: Test Key is used.  **\n");
-  }
-
-  return EFI_SUCCESS;
-
-}
-
-/**
-  This function will connect console device except ConIn base on the console
-  device variable  ConOut and ErrOut.
-
-  @retval EFI_SUCCESS              At least one of the ConOut device have
-                                   been connected success.
-  @retval EFI_STATUS               Return the status of BdsLibConnectConsoleVariable ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibConnectAllDefaultConsolesWithOutConIn (
-  VOID
-  )
-{
-  EFI_STATUS                Status;
-  BOOLEAN                   SystemTableUpdated;
-
-  //
-  // Connect all default console variables except ConIn
-  //
-
-  //
-  // It seems impossible not to have any ConOut device on platform,
-  // so we check the status here.
-  //
-  Status = BdsLibConnectConsoleVariable (L"ConOut");
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Insert the performance probe for Console Out
-  //
-  PERF_START (NULL, "ConOut", "BDS", 1);
-  PERF_END (NULL, "ConOut", "BDS", 0);
-
-  //
-  // The _ModuleEntryPoint err out var is legal.
-  //
-  BdsLibConnectConsoleVariable (L"ErrOut");
-
-  SystemTableUpdated = FALSE;
-  //
-  // Fill console handles in System Table if no console device assignd.
-  //
-  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
-    SystemTableUpdated = TRUE;
-  }
-  if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
-    SystemTableUpdated = TRUE;
-  }
-
-  if (SystemTableUpdated) {
-    //
-    // Update the CRC32 in the EFI System Table header
-    //
-    gST->Hdr.CRC32 = 0;
-    gBS->CalculateCrc32 (
-          (UINT8 *) &gST->Hdr,
-          gST->Hdr.HeaderSize,
-          &gST->Hdr.CRC32
-          );
-  }
-
-  return EFI_SUCCESS;
-
-}
-
-/**
-  Use SystemTable Conout to stop video based Simple Text Out consoles from going
-  to the video device. Put up LogoFile on every video device that is a console.
-
-  @param[in]  LogoFile   File name of logo to display on the center of the screen.
-
-  @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo displayed.
-  @retval EFI_UNSUPPORTED Logo not found
-
-**/
-EFI_STATUS
-EFIAPI
-EnableQuietBoot (
-  IN  EFI_GUID  *LogoFile
-  )
-{
-  EFI_STATUS                    Status;
-  EFI_OEM_BADGING_PROTOCOL      *Badging;
-  UINT32                        SizeOfX;
-  UINT32                        SizeOfY;
-  INTN                          DestX;
-  INTN                          DestY;
-  UINT8                         *ImageData;
-  UINTN                         ImageSize;
-  UINTN                         BltSize;
-  UINT32                        Instance;
-  EFI_BADGING_FORMAT            Format;
-  EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
-  UINTN                         CoordinateX;
-  UINTN                         CoordinateY;
-  UINTN                         Height;
-  UINTN                         Width;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
-  EFI_UGA_DRAW_PROTOCOL         *UgaDraw;
-  UINT32                        ColorDepth;
-  UINT32                        RefreshRate;
-  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;
-  EFI_BOOT_LOGO_PROTOCOL        *BootLogo;
-  UINTN                         NumberOfLogos;
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt;
-  UINTN                         LogoDestX;
-  UINTN                         LogoDestY;
-  UINTN                         LogoHeight;
-  UINTN                         LogoWidth;
-  UINTN                         NewDestX;
-  UINTN                         NewDestY;
-  UINTN                         NewHeight;
-  UINTN                         NewWidth;
-  UINT64                        BufferSize;
-
-  UgaDraw = NULL;
-  //
-  // Try to open GOP first
-  //
-  Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
-  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
-    GraphicsOutput = NULL;
-    //
-    // Open GOP failed, try to open UGA
-    //
-    Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
-  }
-  if (EFI_ERROR (Status)) {
-    return EFI_UNSUPPORTED;
-  }
-
-  //
-  // Try to open Boot Logo Protocol.
-  //
-  BootLogo = NULL;
-  gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
-
-  //
-  // Erase Cursor from screen
-  //
-  gST->ConOut->EnableCursor (gST->ConOut, FALSE);
-
-  Badging = NULL;
-  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
-
-  if (GraphicsOutput != NULL) {
-    SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
-    SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
-
-  } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
-    Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
-    if (EFI_ERROR (Status)) {
-      return EFI_UNSUPPORTED;
-    }
-  } else {
-    return EFI_UNSUPPORTED;
-  }
-
-  Blt = NULL;
-  NumberOfLogos = 0;
-  LogoDestX = 0;
-  LogoDestY = 0;
-  LogoHeight = 0;
-  LogoWidth = 0;
-  NewDestX = 0;
-  NewDestY = 0;
-  NewHeight = 0;
-  NewWidth = 0;
-  Instance = 0;
-  while (1) {
-    ImageData = NULL;
-    ImageSize = 0;
-
-    if (Badging != NULL) {
-      //
-      // Get image from OEMBadging protocol.
-      //
-      Status = Badging->GetImage (
-                          Badging,
-                          &Instance,
-                          &Format,
-                          &ImageData,
-                          &ImageSize,
-                          &Attribute,
-                          &CoordinateX,
-                          &CoordinateY
-                          );
-      if (EFI_ERROR (Status)) {
-        goto Done;
-      }
-
-      //
-      // Currently only support BMP format.
-      //
-      if (Format != EfiBadgingFormatBMP) {
-        if (ImageData != NULL) {
-          FreePool (ImageData);
-        }
-        continue;
-      }
-    } else {
-      //
-      // Get the specified image from FV.
-      //
-      Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
-      if (EFI_ERROR (Status)) {
-        return EFI_UNSUPPORTED;
-      }
-
-      CoordinateX = 0;
-      CoordinateY = 0;
-      if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {
-        Attribute   = EfiBadgingDisplayAttributeCenter;
-      } else {
-        Attribute   = EfiBadgingDisplayAttributeCustomized;
-      } 
-    }
-
-    if (Blt != NULL) {
-      FreePool (Blt);
-    }
-    Blt = NULL;
-    Status = TranslateBmpToGopBlt (
-              ImageData,
-              ImageSize,
-              &Blt,
-              &BltSize,
-              &Height,
-              &Width
-              );
-    if (EFI_ERROR (Status)) {
-      FreePool (ImageData);
-
-      if (Badging == NULL) {
-        return Status;
-      } else {
-        continue;
-      }
-    }
-
-    //
-    // Calculate the display position according to Attribute.
-    //
-    switch (Attribute) {
-    case EfiBadgingDisplayAttributeLeftTop:
-      DestX = CoordinateX;
-      DestY = CoordinateY;
-      break;
-
-    case EfiBadgingDisplayAttributeCenterTop:
-      DestX = (SizeOfX - Width) / 2;
-      DestY = CoordinateY;
-      break;
-
-    case EfiBadgingDisplayAttributeRightTop:
-      DestX = (SizeOfX - Width - CoordinateX);
-      DestY = CoordinateY;;
-      break;
-
-    case EfiBadgingDisplayAttributeCenterRight:
-      DestX = (SizeOfX - Width - CoordinateX);
-      DestY = (SizeOfY - Height) / 2;
-      break;
-
-    case EfiBadgingDisplayAttributeRightBottom:
-      DestX = (SizeOfX - Width - CoordinateX);
-      DestY = (SizeOfY - Height - CoordinateY);
-      break;
-
-    case EfiBadgingDisplayAttributeCenterBottom:
-      DestX = (SizeOfX - Width) / 2;
-      DestY = (SizeOfY - Height - CoordinateY);
-      break;
-
-    case EfiBadgingDisplayAttributeLeftBottom:
-      DestX = CoordinateX;
-      DestY = (SizeOfY - Height - CoordinateY);
-      break;
-
-    case EfiBadgingDisplayAttributeCenterLeft:
-      DestX = CoordinateX;
-      DestY = (SizeOfY - Height) / 2;
-      break;
-
-    case EfiBadgingDisplayAttributeCenter:
-      DestX = (SizeOfX - Width) / 2;
-      DestY = (SizeOfY - Height) / 2;
-      break;
-
-    case EfiBadgingDisplayAttributeCustomized:
-      DestX = (SizeOfX - Width) / 2;
-      DestY = ((SizeOfY * 382) / 1000) - Height / 2;
-      break;
-
-    default:
-      DestX = CoordinateX;
-      DestY = CoordinateY;
-      break;
-    }
-
-    if ((DestX >= 0) && (DestY >= 0)) {
-      if (GraphicsOutput != NULL) {
-        Status = GraphicsOutput->Blt (
-                            GraphicsOutput,
-                            Blt,
-                            EfiBltBufferToVideo,
-                            0,
-                            0,
-                            (UINTN) DestX,
-                            (UINTN) DestY,
-                            Width,
-                            Height,
-                            Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
-                            );
-      } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
-        Status = UgaDraw->Blt (
-                            UgaDraw,
-                            (EFI_UGA_PIXEL *) Blt,
-                            EfiUgaBltBufferToVideo,
-                            0,
-                            0,
-                            (UINTN) DestX,
-                            (UINTN) DestY,
-                            Width,
-                            Height,
-                            Width * sizeof (EFI_UGA_PIXEL)
-                            );
-      } else {
-        Status = EFI_UNSUPPORTED;
-      }
-
-      //
-      // Report displayed Logo information.
-      //
-      if (!EFI_ERROR (Status)) {
-        NumberOfLogos++;
-
-        if (LogoWidth == 0) {
-          //
-          // The first Logo.
-          //
-          LogoDestX = (UINTN) DestX;
-          LogoDestY = (UINTN) DestY;
-          LogoWidth = Width;
-          LogoHeight = Height;
-        } else {
-          //
-          // Merge new logo with old one.
-          //
-          NewDestX = MIN ((UINTN) DestX, LogoDestX);
-          NewDestY = MIN ((UINTN) DestY, LogoDestY);
-          NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX;
-          NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY;
-
-          LogoDestX = NewDestX;
-          LogoDestY = NewDestY;
-          LogoWidth = NewWidth;
-          LogoHeight = NewHeight;
-        }
-      }
-    }
-
-    FreePool (ImageData);
-
-    if (Badging == NULL) {
-      break;
-    }
-  }
-
-Done:
-  if (BootLogo == NULL || NumberOfLogos == 0) {
-    //
-    // No logo displayed.
-    //
-    if (Blt != NULL) {
-      FreePool (Blt);
-    }
-
-    return Status;
-  }
-
-  //
-  // Advertise displayed Logo information.
-  //
-  if (NumberOfLogos == 1) {
-    //
-    // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.
-    //
-    LogoBlt = Blt;
-    Status = EFI_SUCCESS;
-  } else {
-    //
-    // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. 
-    //
-    if (Blt != NULL) {
-      FreePool (Blt);
-    }
-
-    //
-    // Ensure the LogoHeight * LogoWidth doesn't overflow
-    //
-    if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) {
-      return EFI_UNSUPPORTED;
-    }
-    BufferSize = MultU64x64 (LogoWidth, LogoHeight);
-
-    //
-    // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
-    //
-    if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
-      return EFI_UNSUPPORTED;
-    }
-
-    LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-    if (LogoBlt == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
-
-    if (GraphicsOutput != NULL) {
-      Status = GraphicsOutput->Blt (
-                          GraphicsOutput,
-                          LogoBlt,
-                          EfiBltVideoToBltBuffer,
-                          LogoDestX,
-                          LogoDestY,
-                          0,
-                          0,
-                          LogoWidth,
-                          LogoHeight,
-                          LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
-                          );
-    } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
-      Status = UgaDraw->Blt (
-                          UgaDraw,
-                          (EFI_UGA_PIXEL *) LogoBlt,
-                          EfiUgaVideoToBltBuffer,
-                          LogoDestX,
-                          LogoDestY,
-                          0,
-                          0,
-                          LogoWidth,
-                          LogoHeight,
-                          LogoWidth * sizeof (EFI_UGA_PIXEL)
-                          );
-    } else {
-      Status = EFI_UNSUPPORTED;
-    }
-  }
-
-  if (!EFI_ERROR (Status)) {
-    BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);
-  }
-  FreePool (LogoBlt);
-
-  return Status;
-}
-
-/**
-  Use SystemTable Conout to turn on video based Simple Text Out consoles. The 
-  Simple Text Out screens will now be synced up with all non video output devices
-
-  @retval EFI_SUCCESS     UGA devices are back in text mode and synced up.
-
-**/
-EFI_STATUS
-EFIAPI
-DisableQuietBoot (
-  VOID
-  )
-{
-
-  //
-  // Enable Cursor on Screen
-  //
-  gST->ConOut->EnableCursor (gST->ConOut, TRUE);
-  return EFI_SUCCESS;
-}
-
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
deleted file mode 100644
index 313a1ea9f6..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ /dev/null
@@ -1,1575 +0,0 @@
-/** @file
-  Misc BDS library function
-
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "InternalBdsLib.h"
-
-
-#define MAX_STRING_LEN        200
-
-BOOLEAN   mFeaturerSwitch = TRUE;
-BOOLEAN   mResetRequired  = FALSE;
-
-extern UINT16 gPlatformBootTimeOutDefault;
-
-/**
-  The function will go through the driver option link list, load and start
-  every driver the driver option device path point to.
-
-  @param  BdsDriverLists        The header of the current driver option link list
-
-**/
-VOID
-EFIAPI
-BdsLibLoadDrivers (
-  IN LIST_ENTRY                   *BdsDriverLists
-  )
-{
-  EFI_STATUS                Status;
-  LIST_ENTRY                *Link;
-  BDS_COMMON_OPTION         *Option;
-  EFI_HANDLE                ImageHandle;
-  EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
-  UINTN                     ExitDataSize;
-  CHAR16                    *ExitData;
-  BOOLEAN                   ReconnectAll;
-
-  ReconnectAll = FALSE;
-
-  //
-  // Process the driver option
-  //
-  for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {
-    Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
-    
-    //
-    // If a load option is not marked as LOAD_OPTION_ACTIVE,
-    // the boot manager will not automatically load the option.
-    //
-    if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {
-      continue;
-    }
-    
-    //
-    // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
-    // then all of the EFI drivers in the system will be disconnected and
-    // reconnected after the last driver load option is processed.
-    //
-    if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {
-      ReconnectAll = TRUE;
-    }
-    
-    //
-    // Make sure the driver path is connected.
-    //
-    BdsLibConnectDevicePath (Option->DevicePath);
-
-    //
-    // Load and start the image that Driver#### describes
-    //
-    Status = gBS->LoadImage (
-                    FALSE,
-                    gImageHandle,
-                    Option->DevicePath,
-                    NULL,
-                    0,
-                    &ImageHandle
-                    );
-
-    if (!EFI_ERROR (Status)) {
-      gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
-
-      //
-      // Verify whether this image is a driver, if not,
-      // exit it and continue to parse next load option
-      //
-      if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
-        gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);
-        continue;
-      }
-
-      if (Option->LoadOptionsSize != 0) {
-        ImageInfo->LoadOptionsSize  = Option->LoadOptionsSize;
-        ImageInfo->LoadOptions      = Option->LoadOptions;
-      }
-      //
-      // Before calling the image, enable the Watchdog Timer for
-      // the 5 Minute period
-      //
-      gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
-
-      Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);
-      DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status = %r\n", Status));
-
-      //
-      // Clear the Watchdog Timer after the image returns
-      //
-      gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
-    }
-  }
-  
-  //
-  // Process the LOAD_OPTION_FORCE_RECONNECT driver option
-  //
-  if (ReconnectAll) {
-    BdsLibDisconnectAllEfi ();
-    BdsLibConnectAll ();
-  }
-
-}
-
-/**
-  Get the Option Number that does not used.
-  Try to locate the specific option variable one by one utile find a free number.
-
-  @param  VariableName          Indicate if the boot#### or driver#### option
-
-  @return The Minimal Free Option Number
-
-**/
-UINT16
-BdsLibGetFreeOptionNumber (
-  IN  CHAR16    *VariableName
-  )
-{
-  UINTN         Index;
-  CHAR16        StrTemp[10];
-  UINT16        *OptionBuffer;
-  UINTN         OptionSize;
-
-  //
-  // Try to find the minimum free number from 0, 1, 2, 3....
-  //
-  Index = 0;
-  do {
-    if (*VariableName == 'B') {
-      UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index);
-    } else {
-      UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index);
-    }
-    //
-    // try if the option number is used
-    //
-    OptionBuffer = BdsLibGetVariableAndSize (
-                     StrTemp,
-                     &gEfiGlobalVariableGuid,
-                     &OptionSize
-                     );
-    if (OptionBuffer == NULL) {
-      break;
-    }
-    FreePool(OptionBuffer);
-    Index++;
-  } while (TRUE);
-
-  return ((UINT16) Index);
-}
-
-
-/**
-  This function will register the new boot#### or driver#### option base on
-  the VariableName. The new registered boot#### or driver#### will be linked
-  to BdsOptionList and also update to the VariableName. After the boot#### or
-  driver#### updated, the BootOrder or DriverOrder will also be updated.
-
-  @param  BdsOptionList         The header of the boot#### or driver#### link list
-  @param  DevicePath            The device path which the boot#### or driver####
-                                option present
-  @param  String                The description of the boot#### or driver####
-  @param  VariableName          Indicate if the boot#### or driver#### option
-
-  @retval EFI_SUCCESS           The boot#### or driver#### have been success
-                                registered
-  @retval EFI_STATUS            Return the status of gRT->SetVariable ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibRegisterNewOption (
-  IN  LIST_ENTRY                     *BdsOptionList,
-  IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath,
-  IN  CHAR16                         *String,
-  IN  CHAR16                         *VariableName
-  )
-{
-  EFI_STATUS                Status;
-  UINTN                     Index;
-  UINT16                    RegisterOptionNumber;
-  UINT16                    *TempOptionPtr;
-  UINTN                     TempOptionSize;
-  UINT16                    *OptionOrderPtr;
-  VOID                      *OptionPtr;
-  UINTN                     OptionSize;
-  UINT8                     *TempPtr;
-  EFI_DEVICE_PATH_PROTOCOL  *OptionDevicePath;
-  CHAR16                    *Description;
-  CHAR16                    OptionName[10];
-  BOOLEAN                   UpdateDescription;
-  UINT16                    BootOrderEntry;
-  UINTN                     OrderItemNum;
-
-  if (DevicePath == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  OptionPtr             = NULL;
-  OptionSize            = 0;
-  TempPtr               = NULL;
-  OptionDevicePath      = NULL;
-  Description           = NULL;
-  OptionOrderPtr        = NULL;
-  UpdateDescription     = FALSE;
-  Status                = EFI_SUCCESS;
-  ZeroMem (OptionName, sizeof (OptionName));
-
-  TempOptionSize = 0;
-  TempOptionPtr = BdsLibGetVariableAndSize (
-                    VariableName,
-                    &gEfiGlobalVariableGuid,
-                    &TempOptionSize
-                    );
-  //
-  // Compare with current option variable if the previous option is set in global variable.
-  //
-  for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
-    //
-    // TempOptionPtr must not be NULL if we have non-zero TempOptionSize.
-    //
-    ASSERT (TempOptionPtr != NULL);
-
-    if (*VariableName == 'B') {
-      UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
-    } else {
-      UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
-    }
-
-    OptionPtr = BdsLibGetVariableAndSize (
-                  OptionName,
-                  &gEfiGlobalVariableGuid,
-                  &OptionSize
-                  );
-    if (OptionPtr == NULL) {
-      continue;
-    }
-
-    //
-    // Validate the variable.
-    //
-    if (!ValidateOption(OptionPtr, OptionSize)) {
-      FreePool(OptionPtr);
-      continue;
-    }
-
-    TempPtr         =   OptionPtr;
-    TempPtr         +=  sizeof (UINT32) + sizeof (UINT16);
-    Description     =   (CHAR16 *) TempPtr;
-    TempPtr         +=  StrSize ((CHAR16 *) TempPtr);
-    OptionDevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-
-    //
-    // Notes: the description may will change base on the GetStringToken
-    //
-    if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {
-      if (CompareMem (Description, String, StrSize (Description)) == 0) { 
-        //
-        // Got the option, so just return
-        //
-        FreePool (OptionPtr);
-        FreePool (TempOptionPtr);
-        return EFI_SUCCESS;
-      } else {
-        //
-        // Option description changed, need update.
-        //
-        UpdateDescription = TRUE;
-        FreePool (OptionPtr);
-        break;
-      }
-    }
-
-    FreePool (OptionPtr);
-  }
-
-  OptionSize          = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);
-  OptionSize          += GetDevicePathSize (DevicePath);
-  OptionPtr           = AllocateZeroPool (OptionSize);
-  ASSERT (OptionPtr != NULL);
-  
-  TempPtr             = OptionPtr;
-  *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
-  TempPtr             += sizeof (UINT32);
-  *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);
-  TempPtr             += sizeof (UINT16);
-  CopyMem (TempPtr, String, StrSize (String));
-  TempPtr             += StrSize (String);
-  CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));
-
-  if (UpdateDescription) {
-    //
-    // The number in option#### to be updated. 
-    // In this case, we must have non-NULL TempOptionPtr.
-    //
-    ASSERT (TempOptionPtr != NULL);
-    RegisterOptionNumber = TempOptionPtr[Index];
-  } else {
-    //
-    // The new option#### number
-    //
-    RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);
-  }
-
-  if (*VariableName == 'B') {
-    UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
-  } else {
-    UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
-  }
-
-  Status = gRT->SetVariable (
-                  OptionName,
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  OptionSize,
-                  OptionPtr
-                  );
-  //
-  // Return if only need to update a changed description or fail to set option.
-  //
-  if (EFI_ERROR (Status) || UpdateDescription) {
-    FreePool (OptionPtr);
-    if (TempOptionPtr != NULL) {
-      FreePool (TempOptionPtr);
-    }
-    return Status;
-  }
-
-  FreePool (OptionPtr);
-
-  //
-  // Update the option order variable
-  //
-
-  //
-  // If no option order
-  //
-  if (TempOptionSize == 0) {
-    BootOrderEntry = 0;
-    Status = gRT->SetVariable (
-                    VariableName,
-                    &gEfiGlobalVariableGuid,
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                    sizeof (UINT16),
-                    &BootOrderEntry
-                    );
-    if (TempOptionPtr != NULL) {
-      FreePool (TempOptionPtr);
-    }
-    return Status;
-  }
-  
-  //
-  // TempOptionPtr must not be NULL if TempOptionSize is not zero.
-  //
-  ASSERT (TempOptionPtr != NULL);
-  //
-  // Append the new option number to the original option order
-  //
-  OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;
-  OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));
-  ASSERT (OptionOrderPtr!= NULL);
-  CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));
-
-  OptionOrderPtr[Index] = RegisterOptionNumber;
-
-  Status = gRT->SetVariable (
-                  VariableName,
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  OrderItemNum * sizeof (UINT16),
-                  OptionOrderPtr
-                  );
-  FreePool (TempOptionPtr);
-  FreePool (OptionOrderPtr);
-
-  return Status;
-}
-
-/**
-  Returns the size of a device path in bytes.
-
-  This function returns the size, in bytes, of the device path data structure 
-  specified by DevicePath including the end of device path node. If DevicePath 
-  is NULL, then 0 is returned. If the length of the device path is bigger than
-  MaxSize, also return 0 to indicate this is an invalidate device path.
-
-  @param  DevicePath         A pointer to a device path data structure.
-  @param  MaxSize            Max valid device path size. If big than this size, 
-                             return error.
-  
-  @retval 0                  An invalid device path.
-  @retval Others             The size of a device path in bytes.
-
-**/
-UINTN
-GetDevicePathSizeEx (
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath,
-  IN UINTN                           MaxSize
-  )
-{
-  UINTN  Size;
-  UINTN  NodeSize;
-
-  if (DevicePath == NULL) {
-    return 0;
-  }
-
-  //
-  // Search for the end of the device path structure
-  //
-  Size = 0;
-  while (!IsDevicePathEnd (DevicePath)) {
-    NodeSize = DevicePathNodeLength (DevicePath);
-    if (NodeSize < END_DEVICE_PATH_LENGTH) {
-      return 0;
-    }
-    Size += NodeSize;
-    if (Size > MaxSize) {
-      return 0;
-    }
-    DevicePath = NextDevicePathNode (DevicePath);
-  }
-  Size += DevicePathNodeLength (DevicePath);
-  if (Size > MaxSize) {
-    return 0;
-  }
-
-  return Size;
-}
-
-/**
-  Returns the length of a Null-terminated Unicode string. If the length is 
-  bigger than MaxStringLen, return length 0 to indicate that this is an 
-  invalidate string.
-
-  This function returns the byte length of Unicode characters in the Null-terminated
-  Unicode string specified by String. 
-
-  If String is NULL, then ASSERT().
-  If String is not aligned on a 16-bit boundary, then ASSERT().
-
-  @param  String           A pointer to a Null-terminated Unicode string.
-  @param  MaxStringLen     Max string len in this string.
-
-  @retval 0                An invalid string.
-  @retval Others           The length of String.
-
-**/
-UINTN
-StrSizeEx (
-  IN      CONST CHAR16              *String,
-  IN      UINTN                     MaxStringLen
-  )
-{
-  UINTN                             Length;
-
-  ASSERT (String != NULL && MaxStringLen != 0);
-  ASSERT (((UINTN) String & BIT0) == 0);
-
-  for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length+=2);
-
-  if (*String != L'\0' && MaxStringLen == Length) {
-    return 0;
-  }
-
-  return Length + 2;
-}
-
-/**
-  Validate the EFI Boot#### variable (VendorGuid/Name)
-
-  @param  Variable              Boot#### variable data.
-  @param  VariableSize          Returns the size of the EFI variable that was read
-
-  @retval TRUE                  The variable data is correct.
-  @retval FALSE                 The variable data is corrupted.
-
-**/
-BOOLEAN 
-ValidateOption (
-  UINT8                     *Variable,
-  UINTN                     VariableSize
-  )
-{
-  UINT16                    FilePathSize;
-  UINT8                     *TempPtr;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  UINTN                     TempSize;
-
-  if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {
-    return FALSE;
-  }
-
-  //
-  // Skip the option attribute
-  //
-  TempPtr    = Variable;
-  TempPtr   += sizeof (UINT32);
-
-  //
-  // Get the option's device path size
-  //
-  FilePathSize  = *(UINT16 *) TempPtr;
-  TempPtr      += sizeof (UINT16);
-
-  //
-  // Get the option's description string size
-  //
-  TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT16) - sizeof (UINT32));
-  TempPtr += TempSize;
-
-  //
-  // Get the option's device path
-  //
-  DevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-  TempPtr   += FilePathSize;
-
-  //
-  // Validation boot option variable.
-  //
-  if ((FilePathSize == 0) || (TempSize == 0)) {
-    return FALSE;
-  }
-
-  if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > VariableSize) {
-    return FALSE;
-  }
-
-  return (BOOLEAN) (GetDevicePathSizeEx (DevicePath, FilePathSize) != 0);
-}
-
-/**
-  Convert a single character to number.
-  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
-  
-  @param Char    The input char which need to change to a hex number.
-  
-**/
-UINTN
-CharToUint (
-  IN CHAR16                           Char
-  )
-{
-  if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
-  }
-
-  if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
-  }
-
-  ASSERT (FALSE);
-  return 0;
-}
-
-/**
-  Build the boot#### or driver#### option from the VariableName, the
-  build boot#### or driver#### will also be linked to BdsCommonOptionList.
-
-  @param  BdsCommonOptionList   The header of the boot#### or driver#### option
-                                link list
-  @param  VariableName          EFI Variable name indicate if it is boot#### or
-                                driver####
-
-  @retval BDS_COMMON_OPTION     Get the option just been created
-  @retval NULL                  Failed to get the new option
-
-**/
-BDS_COMMON_OPTION *
-EFIAPI
-BdsLibVariableToOption (
-  IN OUT LIST_ENTRY                   *BdsCommonOptionList,
-  IN  CHAR16                          *VariableName
-  )
-{
-  UINT32                    Attribute;
-  UINT16                    FilePathSize;
-  UINT8                     *Variable;
-  UINT8                     *TempPtr;
-  UINTN                     VariableSize;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  BDS_COMMON_OPTION         *Option;
-  VOID                      *LoadOptions;
-  UINT32                    LoadOptionsSize;
-  CHAR16                    *Description;
-  UINT8                     NumOff;
-
-  //
-  // Read the variable. We will never free this data.
-  //
-  Variable = BdsLibGetVariableAndSize (
-              VariableName,
-              &gEfiGlobalVariableGuid,
-              &VariableSize
-              );
-  if (Variable == NULL) {
-    return NULL;
-  }
-
-  //
-  // Validate Boot#### variable data.
-  //
-  if (!ValidateOption(Variable, VariableSize)) {
-    FreePool (Variable);
-    return NULL;
-  }
-
-  //
-  // Notes: careful defined the variable of Boot#### or
-  // Driver####, consider use some macro to abstract the code
-  //
-  //
-  // Get the option attribute
-  //
-  TempPtr   =  Variable;
-  Attribute =  *(UINT32 *) Variable;
-  TempPtr   += sizeof (UINT32);
-
-  //
-  // Get the option's device path size
-  //
-  FilePathSize =  *(UINT16 *) TempPtr;
-  TempPtr      += sizeof (UINT16);
-
-  //
-  // Get the option's description string
-  //
-  Description = (CHAR16 *) TempPtr;
-
-  //
-  // Get the option's description string size
-  //
-  TempPtr += StrSize((CHAR16 *) TempPtr);
-
-  //
-  // Get the option's device path
-  //
-  DevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
-  TempPtr    += FilePathSize;
-
-  //
-  // Get load opion data.
-  //
-  LoadOptions     = TempPtr;
-  LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
-
-  //
-  // The Console variables may have multiple device paths, so make
-  // an Entry for each one.
-  //
-  Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
-  if (Option == NULL) {
-    FreePool (Variable);
-    return NULL;
-  }
-
-  Option->Signature   = BDS_LOAD_OPTION_SIGNATURE;
-  Option->DevicePath  = AllocateZeroPool (GetDevicePathSize (DevicePath));
-  ASSERT(Option->DevicePath != NULL);
-  CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
-
-  Option->Attribute   = Attribute;
-  Option->Description = AllocateZeroPool (StrSize (Description));
-  ASSERT(Option->Description != NULL);
-  CopyMem (Option->Description, Description, StrSize (Description));
-
-  Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);
-  ASSERT(Option->LoadOptions != NULL);
-  CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);
-  Option->LoadOptionsSize = LoadOptionsSize;
-
-  //
-  // Get the value from VariableName Unicode string
-  // since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this
-  // Unicode stream to ASCII without any loss in meaning.
-  //
-  if (*VariableName == 'B') {
-    NumOff = (UINT8) (sizeof (L"Boot") / sizeof (CHAR16) - 1);
-    Option->BootCurrent = (UINT16) (CharToUint (VariableName[NumOff+0]) * 0x1000) 
-               + (UINT16) (CharToUint (VariableName[NumOff+1]) * 0x100)
-               + (UINT16) (CharToUint (VariableName[NumOff+2]) * 0x10)
-               + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1);
-  }
-  InsertTailList (BdsCommonOptionList, &Option->Link);
-  FreePool (Variable);
-  return Option;
-}
-
-/**
-  Process BootOrder, or DriverOrder variables, by calling
-  BdsLibVariableToOption () for each UINT16 in the variables.
-
-  @param  BdsCommonOptionList   The header of the option list base on variable
-                                VariableName
-  @param  VariableName          EFI Variable name indicate the BootOrder or
-                                DriverOrder
-
-  @retval EFI_SUCCESS           Success create the boot option or driver option
-                                list
-  @retval EFI_OUT_OF_RESOURCES  Failed to get the boot option or driver option list
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibBuildOptionFromVar (
-  IN  LIST_ENTRY                      *BdsCommonOptionList,
-  IN  CHAR16                          *VariableName
-  )
-{
-  UINT16            *OptionOrder;
-  UINTN             OptionOrderSize;
-  UINTN             Index;
-  BDS_COMMON_OPTION *Option;
-  CHAR16            OptionName[20];
-
-  //
-  // Zero Buffer in order to get all BOOT#### variables
-  //
-  ZeroMem (OptionName, sizeof (OptionName));
-
-  //
-  // Read the BootOrder, or DriverOrder variable.
-  //
-  OptionOrder = BdsLibGetVariableAndSize (
-                  VariableName,
-                  &gEfiGlobalVariableGuid,
-                  &OptionOrderSize
-                  );
-  if (OptionOrder == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
-    if (*VariableName == 'B') {
-      UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);
-    } else {
-      UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);
-    }
-
-    Option              = BdsLibVariableToOption (BdsCommonOptionList, OptionName);
-    if (Option != NULL) {
-      Option->BootCurrent = OptionOrder[Index];
-    }
-  }
-
-  FreePool (OptionOrder);
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Get boot mode by looking up configuration table and parsing HOB list
-
-  @param  BootMode              Boot mode from PEI handoff HOB.
-
-  @retval EFI_SUCCESS           Successfully get boot mode
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibGetBootMode (
-  OUT EFI_BOOT_MODE       *BootMode
-  )
-{
-  *BootMode = GetBootModeHob ();
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
-  buffer, and the size of the buffer. If failure return NULL.
-
-  @param  Name                  String part of EFI variable name
-  @param  VendorGuid            GUID part of EFI variable name
-  @param  VariableSize          Returns the size of the EFI variable that was read
-
-  @return                       Dynamically allocated memory that contains a copy of the EFI variable
-                                Caller is responsible freeing the buffer.
-  @retval NULL                  Variable was not read
-
-**/
-VOID *
-EFIAPI
-BdsLibGetVariableAndSize (
-  IN  CHAR16              *Name,
-  IN  EFI_GUID            *VendorGuid,
-  OUT UINTN               *VariableSize
-  )
-{
-  EFI_STATUS  Status;
-  UINTN       BufferSize;
-  VOID        *Buffer;
-
-  Buffer = NULL;
-
-  //
-  // Pass in a zero size buffer to find the required buffer size.
-  //
-  BufferSize  = 0;
-  Status      = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
-  if (Status == EFI_BUFFER_TOO_SMALL) {
-    //
-    // Allocate the buffer to return
-    //
-    Buffer = AllocateZeroPool (BufferSize);
-    if (Buffer == NULL) {
-      *VariableSize = 0;
-      return NULL;
-    }
-    //
-    // Read variable into the allocated buffer.
-    //
-    Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
-    if (EFI_ERROR (Status)) {
-      FreePool (Buffer);
-      BufferSize = 0;
-      Buffer     = NULL;
-    }
-  }
-
-  ASSERT (((Buffer == NULL) && (BufferSize == 0)) ||
-          ((Buffer != NULL) && (BufferSize != 0))
-          );
-  *VariableSize = BufferSize;
-  return Buffer;
-}
-
-/**
-  Delete the instance in Multi which matches partly with Single instance
-
-  @param  Multi                 A pointer to a multi-instance device path data
-                                structure.
-  @param  Single                A pointer to a single-instance device path data
-                                structure.
-
-  @return This function will remove the device path instances in Multi which partly
-          match with the Single, and return the result device path. If there is no
-          remaining device path as a result, this function will return NULL.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-BdsLibDelPartMatchInstance (
-  IN     EFI_DEVICE_PATH_PROTOCOL  *Multi,
-  IN     EFI_DEVICE_PATH_PROTOCOL  *Single
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *TempNewDevicePath;
-  UINTN                     InstanceSize;
-  UINTN                     SingleDpSize;
-  UINTN                     Size;
-
-  NewDevicePath     = NULL;
-  TempNewDevicePath = NULL;
-
-  if (Multi == NULL || Single == NULL) {
-    return Multi;
-  }
-
-  Instance        =  GetNextDevicePathInstance (&Multi, &InstanceSize);
-  SingleDpSize    =  GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
-  InstanceSize    -= END_DEVICE_PATH_LENGTH;
-
-  while (Instance != NULL) {
-
-    Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
-
-    if ((CompareMem (Instance, Single, Size) != 0)) {
-      //
-      // Append the device path instance which does not match with Single
-      //
-      TempNewDevicePath = NewDevicePath;
-      NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
-      if (TempNewDevicePath != NULL) {
-        FreePool(TempNewDevicePath);
-      }
-    }
-    FreePool(Instance);
-    Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
-    InstanceSize  -= END_DEVICE_PATH_LENGTH;
-  }
-
-  return NewDevicePath;
-}
-
-/**
-  Function compares a device path data structure to that of all the nodes of a
-  second device path instance.
-
-  @param  Multi                 A pointer to a multi-instance device path data
-                                structure.
-  @param  Single                A pointer to a single-instance device path data
-                                structure.
-
-  @retval TRUE                  If the Single device path is contained within Multi device path.
-  @retval FALSE                 The Single device path is not match within Multi device path.
-
-**/
-BOOLEAN
-EFIAPI
-BdsLibMatchDevicePaths (
-  IN  EFI_DEVICE_PATH_PROTOCOL  *Multi,
-  IN  EFI_DEVICE_PATH_PROTOCOL  *Single
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;
-  UINTN                     Size;
-
-  if (Multi == NULL || Single  == NULL) {
-    return FALSE;
-  }
-
-  DevicePath      = Multi;
-  DevicePathInst  = GetNextDevicePathInstance (&DevicePath, &Size);
-
-  //
-  // Search for the match of 'Single' in 'Multi'
-  //
-  while (DevicePathInst != NULL) {
-    //
-    // If the single device path is found in multiple device paths,
-    // return success
-    //
-    if (CompareMem (Single, DevicePathInst, Size) == 0) {
-      FreePool (DevicePathInst);
-      return TRUE;
-    }
-
-    FreePool (DevicePathInst);
-    DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
-  }
-
-  return FALSE;
-}
-
-/**
-  This function prints a series of strings.
-
-  @param  ConOut                Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
-  @param  ...                   A variable argument list containing series of
-                                strings, the last string must be NULL.
-
-  @retval EFI_SUCCESS           Success print out the string using ConOut.
-  @retval EFI_STATUS            Return the status of the ConOut->OutputString ().
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibOutputStrings (
-  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *ConOut,
-  ...
-  )
-{
-  VA_LIST     Args;
-  EFI_STATUS  Status;
-  CHAR16      *String;
-
-  Status = EFI_SUCCESS;
-  VA_START (Args, ConOut);
-
-  while (!EFI_ERROR (Status)) {
-    //
-    // If String is NULL, then it's the end of the list
-    //
-    String = VA_ARG (Args, CHAR16 *);
-    if (String == NULL) {
-      break;
-    }
-
-    Status = ConOut->OutputString (ConOut, String);
-
-    if (EFI_ERROR (Status)) {
-      break;
-    }
-  }
-  
-  VA_END(Args);
-  return Status;
-}
-
-//
-//  Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
-//  Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser  if
-//  user change any option setting which needs a reset to be effective, and  the reset will be applied according to  the user selection.
-//
-
-
-/**
-  Enable the setup browser reset reminder feature.
-  This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
-
-**/
-VOID
-EFIAPI
-EnableResetReminderFeature (
-  VOID
-  )
-{
-  mFeaturerSwitch = TRUE;
-}
-
-
-/**
-  Disable the setup browser reset reminder feature.
-  This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
-
-**/
-VOID
-EFIAPI
-DisableResetReminderFeature (
-  VOID
-  )
-{
-  mFeaturerSwitch = FALSE;
-}
-
-
-/**
-  Record the info that  a reset is required.
-  A  module boolean variable is used to record whether a reset is required.
-
-**/
-VOID
-EFIAPI
-EnableResetRequired (
-  VOID
-  )
-{
-  mResetRequired = TRUE;
-}
-
-
-/**
-  Record the info that  no reset is required.
-  A  module boolean variable is used to record whether a reset is required.
-
-**/
-VOID
-EFIAPI
-DisableResetRequired (
-  VOID
-  )
-{
-  mResetRequired = FALSE;
-}
-
-
-/**
-  Check whether platform policy enable the reset reminder feature. The default is enabled.
-
-**/
-BOOLEAN
-EFIAPI
-IsResetReminderFeatureEnable (
-  VOID
-  )
-{
-  return mFeaturerSwitch;
-}
-
-
-/**
-  Check if  user changed any option setting which needs a system reset to be effective.
-
-**/
-BOOLEAN
-EFIAPI
-IsResetRequired (
-  VOID
-  )
-{
-  return mResetRequired;
-}
-
-
-/**
-  Check whether a reset is needed, and finish the reset reminder feature.
-  If a reset is needed, Popup a menu to notice user, and finish the feature
-  according to the user selection.
-
-**/
-VOID
-EFIAPI
-SetupResetReminder (
-  VOID
-  )
-{
-  EFI_INPUT_KEY                 Key;
-  CHAR16                        *StringBuffer1;
-  CHAR16                        *StringBuffer2;
-
-
-  //
-  //check any reset required change is applied? if yes, reset system
-  //
-  if (IsResetReminderFeatureEnable ()) {
-    if (IsResetRequired ()) {
-
-      StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
-      ASSERT (StringBuffer1 != NULL);
-      StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
-      ASSERT (StringBuffer2 != NULL);
-      StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now.");
-      StrCpy (StringBuffer2, L"Press ENTER to reset");
-      //
-      // Popup a menu to notice user
-      //
-      do {
-        CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
-      } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
-      FreePool (StringBuffer1);
-      FreePool (StringBuffer2);
-
-      gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
-    }
-  }
-}
-
-/**
-  Get the headers (dos, image, optional header) from an image
-
-  @param  Device                SimpleFileSystem device handle
-  @param  FileName              File name for the image
-  @param  DosHeader             Pointer to dos header
-  @param  Hdr                   The buffer in which to return the PE32, PE32+, or TE header.
-
-  @retval EFI_SUCCESS           Successfully get the machine type.
-  @retval EFI_NOT_FOUND         The file is not found.
-  @retval EFI_LOAD_ERROR        File is not a valid image file.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibGetImageHeader (
-  IN  EFI_HANDLE                  Device,
-  IN  CHAR16                      *FileName,
-  OUT EFI_IMAGE_DOS_HEADER        *DosHeader,
-  OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr
-  )
-{
-  EFI_STATUS                       Status;
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *Volume;
-  EFI_FILE_HANDLE                  Root;
-  EFI_FILE_HANDLE                  ThisFile;
-  UINTN                            BufferSize;
-  UINT64                           FileSize;
-  EFI_FILE_INFO                    *Info;
-
-  Root     = NULL;
-  ThisFile = NULL;
-  //
-  // Handle the file system interface to the device
-  //
-  Status = gBS->HandleProtocol (
-                  Device,
-                  &gEfiSimpleFileSystemProtocolGuid,
-                  (VOID *) &Volume
-                  );
-  if (EFI_ERROR (Status)) {
-    goto Done;
-  }
-
-  Status = Volume->OpenVolume (
-                     Volume,
-                     &Root
-                     );
-  if (EFI_ERROR (Status)) {
-    Root = NULL;
-    goto Done;
-  }
-  ASSERT (Root != NULL);
-  Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
-  if (EFI_ERROR (Status)) {
-    goto Done;
-  }
-  ASSERT (ThisFile != NULL);
-
-  //
-  // Get file size
-  //
-  BufferSize  = SIZE_OF_EFI_FILE_INFO + 200;
-  do {
-    Info   = NULL;
-    Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);
-    if (EFI_ERROR (Status)) {
-      goto Done;
-    }
-    Status = ThisFile->GetInfo (
-                         ThisFile,
-                         &gEfiFileInfoGuid,
-                         &BufferSize,
-                         Info
-                         );
-    if (!EFI_ERROR (Status)) {
-      break;
-    }
-    if (Status != EFI_BUFFER_TOO_SMALL) {
-      FreePool (Info);
-      goto Done;
-    }
-    FreePool (Info);
-  } while (TRUE);
-
-  FileSize = Info->FileSize;
-  FreePool (Info);
-
-  //
-  // Read dos header
-  //
-  BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
-  Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);
-  if (EFI_ERROR (Status) ||
-      BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||
-      FileSize <= DosHeader->e_lfanew ||
-      DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
-    Status = EFI_LOAD_ERROR;
-    goto Done;
-  }
-
-  //
-  // Move to PE signature
-  //
-  Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);
-  if (EFI_ERROR (Status)) {
-    Status = EFI_LOAD_ERROR;
-    goto Done;
-  }
-
-  //
-  // Read and check PE signature
-  //
-  BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
-  Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);
-  if (EFI_ERROR (Status) ||
-      BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||
-      Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
-    Status = EFI_LOAD_ERROR;
-    goto Done;
-  }
-
-  //
-  // Check PE32 or PE32+ magic
-  //
-  if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
-      Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
-    Status = EFI_LOAD_ERROR;
-    goto Done;
-  }
-
- Done:
-  if (ThisFile != NULL) {
-    ThisFile->Close (ThisFile);
-  }
-  if (Root != NULL) {
-    Root->Close (Root);
-  }
-  return Status;
-}
-
-/**
-  This routine adjust the memory information for different memory type and 
-  save them into the variables for next boot.
-**/
-VOID
-BdsSetMemoryTypeInformationVariable (
-  VOID
-  )
-{
-  EFI_STATUS                   Status;
-  EFI_MEMORY_TYPE_INFORMATION  *PreviousMemoryTypeInformation;
-  EFI_MEMORY_TYPE_INFORMATION  *CurrentMemoryTypeInformation;
-  UINTN                        VariableSize;
-  UINTN                        Index;
-  UINTN                        Index1;
-  UINT32                       Previous;
-  UINT32                       Current;
-  UINT32                       Next;
-  EFI_HOB_GUID_TYPE            *GuidHob;
-  BOOLEAN                      MemoryTypeInformationModified;
-  BOOLEAN                      MemoryTypeInformationVariableExists;
-  EFI_BOOT_MODE                BootMode;
-
-  MemoryTypeInformationModified       = FALSE;
-  MemoryTypeInformationVariableExists = FALSE;
-
-
-  BootMode = GetBootModeHob ();
-  //
-  // In BOOT_IN_RECOVERY_MODE, Variable region is not reliable.
-  //
-  if (BootMode == BOOT_IN_RECOVERY_MODE) {
-    return;
-  }
-
-  //
-  // Only check the the Memory Type Information variable in the boot mode 
-  // other than BOOT_WITH_DEFAULT_SETTINGS because the Memory Type
-  // Information is not valid in this boot mode.
-  //
-  if (BootMode != BOOT_WITH_DEFAULT_SETTINGS) {
-    VariableSize = 0;
-    Status = gRT->GetVariable (
-                    EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
-                    &gEfiMemoryTypeInformationGuid,
-                    NULL, 
-                    &VariableSize, 
-                    NULL
-                    );
-    if (Status == EFI_BUFFER_TOO_SMALL) {
-      MemoryTypeInformationVariableExists = TRUE;
-    }
-  }
-
-  //
-  // Retrieve the current memory usage statistics.  If they are not found, then
-  // no adjustments can be made to the Memory Type Information variable.
-  //
-  Status = EfiGetSystemConfigurationTable (
-             &gEfiMemoryTypeInformationGuid,
-             (VOID **) &CurrentMemoryTypeInformation
-             );
-  if (EFI_ERROR (Status) || CurrentMemoryTypeInformation == NULL) {
-    return;
-  }
-
-  //
-  // Get the Memory Type Information settings from Hob if they exist,
-  // PEI is responsible for getting them from variable and build a Hob to save them.
-  // If the previous Memory Type Information is not available, then set defaults
-  //
-  GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);
-  if (GuidHob == NULL) {
-    //
-    // If Platform has not built Memory Type Info into the Hob, just return.
-    //
-    return;
-  }
-  PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);
-  VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
-
-  //
-  // Use a heuristic to adjust the Memory Type Information for the next boot
-  //
-  DEBUG ((EFI_D_INFO, "Memory  Previous  Current    Next   \n"));
-  DEBUG ((EFI_D_INFO, " Type    Pages     Pages     Pages  \n"));
-  DEBUG ((EFI_D_INFO, "======  ========  ========  ========\n"));
-
-  for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
-
-    for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {
-      if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
-        break;
-      }
-    }
-    if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {
-      continue;
-    }
-
-    //
-    // Previous is the number of pages pre-allocated
-    // Current is the number of pages actually needed
-    //
-    Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;
-    Current  = CurrentMemoryTypeInformation[Index1].NumberOfPages;
-    Next     = Previous;
-
-    //
-    // Inconsistent Memory Reserved across bootings may lead to S4 fail
-    // Write next varible to 125% * current when the pre-allocated memory is:
-    //  1. More than 150% of needed memory and boot mode is BOOT_WITH_DEFAULT_SETTING
-    //  2. Less than the needed memory
-    //
-    if ((Current + (Current >> 1)) < Previous) {
-      if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
-        Next = Current + (Current >> 2);
-      }
-    } else if (Current > Previous) {
-      Next = Current + (Current >> 2);
-    }
-    if (Next > 0 && Next < 4) {
-      Next = 4;
-    }
-
-    if (Next != Previous) {
-      PreviousMemoryTypeInformation[Index].NumberOfPages = Next;
-      MemoryTypeInformationModified = TRUE;
-    }
-
-    DEBUG ((EFI_D_INFO, "  %02x    %08x  %08x  %08x\n", PreviousMemoryTypeInformation[Index].Type, Previous, Current, Next));
-  }
-
-  //
-  // If any changes were made to the Memory Type Information settings, then set the new variable value;
-  // Or create the variable in first boot.
-  //
-  if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
-    Status = SetVariableAndReportStatusCodeOnError (
-               EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
-               &gEfiMemoryTypeInformationGuid,
-               EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,
-               VariableSize,
-               PreviousMemoryTypeInformation
-               );
-
-    if (!EFI_ERROR (Status)) {
-      //
-      // If the Memory Type Information settings have been modified, then reset the platform
-      // so the new Memory Type Information setting will be used to guarantee that an S4
-      // entry/resume cycle will not fail.
-      //
-      if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
-        DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));
-        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
-      }
-    } else {
-      DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. OS S4 may fail!\n"));
-    }
-  }
-}
-
-/**
-  This routine is kept for backward compatibility.
-**/
-VOID
-EFIAPI
-BdsLibSaveMemoryTypeInformation (
-  VOID
-  )
-{
-}
-
-
-/**
-  Identify a user and, if authenticated, returns the current user profile handle.
-
-  @param[out]  User           Point to user profile handle.
-  
-  @retval EFI_SUCCESS         User is successfully identified, or user identification
-                              is not supported.
-  @retval EFI_ACCESS_DENIED   User is not successfully identified
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibUserIdentify (
-  OUT EFI_USER_PROFILE_HANDLE         *User
-  )
-{
-  EFI_STATUS                          Status;
-  EFI_USER_MANAGER_PROTOCOL           *Manager;
-  
-  Status = gBS->LocateProtocol (
-                  &gEfiUserManagerProtocolGuid,
-                  NULL,
-                  (VOID **) &Manager
-                  );
-  if (EFI_ERROR (Status)) {
-    return EFI_SUCCESS;
-  }
-
-  return Manager->Identify (Manager, User);
-}
-
-/**
-  Set the variable and report the error through status code upon failure.
-
-  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.
-                                 Each VariableName is unique for each VendorGuid. VariableName must
-                                 contain 1 or more characters. If VariableName is an empty string,
-                                 then EFI_INVALID_PARAMETER is returned.
-  @param  VendorGuid             A unique identifier for the vendor.
-  @param  Attributes             Attributes bitmask to set for the variable.
-  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, 
-                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
-                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero 
-                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is 
-                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to 
-                                 the variable value (the timestamp associated with the variable may be updated however 
-                                 even if no new data value is provided,see the description of the 
-                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not 
-                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
-  @param  Data                   The contents for the variable.
-
-  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as
-                                 defined by the Attributes.
-  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the
-                                 DataSize exceeds the maximum allowed.
-  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
-  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.
-  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.
-  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
-  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
-  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
-                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
-                                 does NOT pass the validation check carried out by the firmware.
-
-  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.
-**/
-EFI_STATUS
-SetVariableAndReportStatusCodeOnError (
-  IN CHAR16     *VariableName,
-  IN EFI_GUID   *VendorGuid,
-  IN UINT32     Attributes,
-  IN UINTN      DataSize,
-  IN VOID       *Data
-  )
-{
-  EFI_STATUS                 Status;
-  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;
-  UINTN                      NameSize;
-
-  Status = gRT->SetVariable (
-                  VariableName,
-                  VendorGuid,
-                  Attributes,
-                  DataSize,
-                  Data
-                  );
-  if (EFI_ERROR (Status)) {
-    NameSize = StrSize (VariableName);
-    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);
-    if (SetVariableStatus != NULL) {
-      CopyGuid (&SetVariableStatus->Guid, VendorGuid);
-      SetVariableStatus->NameSize   = NameSize;
-      SetVariableStatus->DataSize   = DataSize;
-      SetVariableStatus->SetStatus  = Status;
-      SetVariableStatus->Attributes = Attributes;
-      CopyMem (SetVariableStatus + 1,                          VariableName, NameSize);
-      if ((Data != NULL) && (DataSize != 0)) {
-        CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         DataSize);
-      }
-
-      REPORT_STATUS_CODE_EX (
-        EFI_ERROR_CODE,
-        PcdGet32 (PcdErrorCodeSetVariable),
-        0,
-        NULL,
-        &gEdkiiStatusCodeDataTypeVariableGuid,
-        SetVariableStatus,
-        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
-        );
-
-      FreePool (SetVariableStatus);
-    }
-  }
-
-  return Status;
-}
-
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
deleted file mode 100644
index a0b9da880d..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/** @file
-  BDS internal function define the default device path string, it can be
-  replaced by platform device path.
-
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "InternalBdsLib.h"
-
-/**
-  This function converts an input device structure to a Unicode string.
-
-  @param DevPath                  A pointer to the device path structure.
-
-  @return A new allocated Unicode string that represents the device path.
-
-**/
-CHAR16 *
-EFIAPI
-DevicePathToStr (
-  IN EFI_DEVICE_PATH_PROTOCOL     *DevPath
-  )
-{
-  return ConvertDevicePathToText (DevPath, TRUE, TRUE);
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
deleted file mode 100644
index 795a9de4b8..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+++ /dev/null
@@ -1,143 +0,0 @@
-## @file
-#  General BDS library.
-#  
-#  General BDS defines and produce general interfaces for platform BDS driver including:
-#  1) BDS boot policy interface;
-#  2) BDS boot device connect interface;
-#  3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
-#  
-#  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
-#  SPDX-License-Identifier: BSD-2-Clause-Patent
-#  
-##
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = GenericBdsLib
-  MODULE_UNI_FILE                = GenericBdsLib.uni
-  FILE_GUID                      = e405ec31-ccaa-4dd4-83e8-0aec01703f7e
-  MODULE_TYPE                    = DXE_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = GenericBdsLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION 
-  CONSTRUCTOR                    = GenericBdsLibConstructor
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64 EBC
-#
-
-[Sources]
-  DevicePath.c
-  BdsConnect.c
-  BdsMisc.c
-  BdsConsole.c
-  BdsBoot.c
-  InternalBdsLib.h
-  String.h
-  String.c
-  GenericBdsStrings.uni
-  
-[Packages]
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  IntelFrameworkPkg/IntelFrameworkPkg.dec
-  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
-  ShellPkg/ShellPkg.dec
-  NetworkPkg/NetworkPkg.dec
-
-[LibraryClasses]
-  DevicePathLib
-  PeCoffGetEntryPointLib
-  BaseLib
-  HobLib
-  UefiRuntimeServicesTableLib
-  DxeServicesTableLib
-  MemoryAllocationLib
-  UefiLib
-  UefiBootServicesTableLib
-  BaseMemoryLib
-  DebugLib
-  PrintLib
-  PcdLib
-  PerformanceLib
-  TimerLib
-  DxeServicesLib
-  HiiLib
-  ReportStatusCodeLib
-  NetLib
-  BmpSupportLib
-
-[Guids]
-  ## SOMETIMES_CONSUMES ## HOB         # The hob holding memory type information
-  ## SOMETIMES_CONSUMES ## SystemTable # The identifier of memory type information type in system table
-  ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"
-  ## SOMETIMES_PRODUCES ## Variable:L"MemoryTypeInformation"
-  gEfiMemoryTypeInformationGuid                 
-  ## SOMETIMES_CONSUMES ## Variable:L"BootXXXX"    # Boot option variable
-  ## SOMETIMES_PRODUCES ## Variable:L"BootXXXX"    # Boot option variable
-  ## SOMETIMES_CONSUMES ## Variable:L"DriverXXXX"  # Driver load option.
-  ## SOMETIMES_PRODUCES ## Variable:L"DriverXXXX"  # Driver load option.
-  ## SOMETIMES_CONSUMES ## Variable:L"BootNext"    # Next Boot Option
-  ## SOMETIMES_PRODUCES ## Variable:L"BootNext"    # Next Boot Option
-  ## SOMETIMES_CONSUMES ## Variable:L"BootOrder"   # The boot option array
-  ## SOMETIMES_PRODUCES ## Variable:L"BootOrder"   # The boot option array
-  ## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" # The driver order list
-  ## SOMETIMES_CONSUMES ## Variable:L"ConIn"       # The device path of console in device
-  ## SOMETIMES_PRODUCES ## Variable:L"ConIn"       # The device path of console in device
-  ## SOMETIMES_CONSUMES ## Variable:L"ConOut"      # The device path of console out device
-  ## SOMETIMES_PRODUCES ## Variable:L"ConOut"      # The device path of console out device
-  ## SOMETIMES_CONSUMES ## Variable:L"ErrOut"      # The device path of error out device
-  ## SOMETIMES_PRODUCES ## Variable:L"ErrOut"      # The device path of error out device
-  ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" # The boot option of current boot
-  ## SOMETIMES_PRODUCES ## Variable:L"BootNext"    # The number of next boot option
-  gEfiGlobalVariableGuid
-  gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## GUID
-  gLastEnumLangGuid                             ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" # Platform language at last time enumeration.
-  gHdBootDevicePathVariablGuid                  ## SOMETIMES_PRODUCES ## Variable:L"HDDP" # The device path of Boot file on Hard device.
-  gBdsLibStringPackageGuid                      ## CONSUMES ## HII # HII String PackageList Guid
-  ## SOMETIMES_PRODUCES ## Variable:L"LegacyDevOrder"
-  ## SOMETIMES_CONSUMES ## Variable:L"LegacyDevOrder"
-  gEfiLegacyDevOrderVariableGuid
-  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES ## GUID
-  gUefiShellFileGuid
-
-[Protocols]
-  gEfiSimpleFileSystemProtocolGuid              ## SOMETIMES_CONSUMES
-  gEfiLoadFileProtocolGuid                      ## SOMETIMES_CONSUMES
-  gEfiSimpleTextOutProtocolGuid                 ## CONSUMES
-  gEfiPciIoProtocolGuid                         ## SOMETIMES_CONSUMES
-  gEfiLoadedImageProtocolGuid                   ## SOMETIMES_CONSUMES
-  gEfiSimpleNetworkProtocolGuid                 ## SOMETIMES_CONSUMES
-  gEfiDebugPortProtocolGuid                     ## SOMETIMES_CONSUMES
-  gEfiSimpleTextInProtocolGuid                  ## CONSUMES
-  gEfiBlockIoProtocolGuid                       ## SOMETIMES_CONSUMES
-  gEfiFirmwareVolume2ProtocolGuid               ## SOMETIMES_CONSUMES
-  gEfiLegacyBiosProtocolGuid                    ## SOMETIMES_CONSUMES
-  gEfiCpuArchProtocolGuid                       ## CONSUMES
-  gEfiDevicePathProtocolGuid                    ## CONSUMES
-  gEfiAcpiS3SaveProtocolGuid                    ## SOMETIMES_CONSUMES
-  gEfiGraphicsOutputProtocolGuid                ## SOMETIMES_CONSUMES
-  gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## SOMETIMES_CONSUMES
-  gEfiOEMBadgingProtocolGuid                    ## SOMETIMES_CONSUMES
-  gEfiHiiFontProtocolGuid                       ## CONSUMES
-  gEfiUserManagerProtocolGuid                   ## SOMETIMES_CONSUMES
-  gEfiUsbIoProtocolGuid                         ## SOMETIMES_CONSUMES
-  gEfiBootLogoProtocolGuid                      ## SOMETIMES_CONSUMES
-
-[FeaturePcd]
-  gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport                   ## CONSUMES
-  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable ## CONSUMES
-
-[Pcd]
-  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange ## SOMETIMES_CONSUMES
-  gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad  ## SOMETIMES_CONSUMES
-  gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart ## SOMETIMES_CONSUMES
-  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable      ## CONSUMES
-  gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ## CONSUMES
-
-#
-# [BootMode] 
-#   RECOVERY_FULL    ## SOMETIMES_CONSUMES # Memory Type Information variable
-#
-
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.uni b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.uni
deleted file mode 100644
index c853d3409e..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.uni
+++ /dev/null
@@ -1,19 +0,0 @@
-// /** @file
-// General BDS library.
-//
-// General BDS defines and produce general interfaces for platform BDS driver including:
-// 1) BDS boot policy interface;
-// 2) BDS boot device connect interface;
-// 3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
-//
-// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT             #language en-US "General BDS library"
-
-#string STR_MODULE_DESCRIPTION          #language en-US "General BDS defines and produces general interfaces for a platform BDS driver including: 1) BDS boot policy interface; 2) BDS boot device connect interface; 3) BDS Misc interfaces for maintaining boot variable, output string, etc."
-
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni
deleted file mode 100644
index 59a75e548b..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsStrings.uni
+++ /dev/null
@@ -1,30 +0,0 @@
-///** @file
-//  
-//  String definitions for Boot Option description.
-//  
-//  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
-//  SPDX-License-Identifier: BSD-2-Clause-Patent
-//  
-//**/
-
-/=#
-
-#langdef   en-US "English"
-#langdef   fr-FR "Français"
-
-#string STR_DESCRIPTION_FLOPPY         #language en-US  "EFI Floppy"
-                                       #language fr-FR  "fr-FR: EFI Floppy"
-#string STR_DESCRIPTION_CD_DVD         #language en-US  "EFI DVD/CDROM"
-                                       #language fr-FR  "fr-FR: EFI DVD/CDROM"
-#string STR_DESCRIPTION_HARDDRIVE      #language en-US  "EFI Hard Drive"
-                                       #language fr-FR  "fr-FR: EFI Hard Drive"
-#string STR_DESCRIPTION_USB            #language en-US  "EFI USB Device"
-                                       #language fr-FR  "fr-FR: EFI USB Device"
-#string STR_DESCRIPTION_SCSI           #language en-US  "EFI SCSI Device"
-                                       #language fr-FR  "fr-FR: EFI SCSI Device"
-#string STR_DESCRIPTION_MISC           #language en-US  "EFI Misc Device"
-                                       #language fr-FR  "fr-FR: EFI Misc Device"
-#string STR_DESCRIPTION_NETWORK        #language en-US  "EFI Network "
-                                       #language fr-FR  "fr-FR: EFI Network "
-#string STR_DESCRIPTION_NON_BLOCK      #language en-US  "EFI Non-Block Boot Device"
-                                       #language fr-FR  "fr-FR: EFI Non-Block Boot Device"
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
deleted file mode 100644
index 025f06572b..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/** @file
-  BDS library definition, include the file and data structure
-
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _INTERNAL_BDS_LIB_H_
-#define _INTERNAL_BDS_LIB_H_
-
-#include <FrameworkDxe.h>
-
-#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/PeImage.h>
-
-#include <Protocol/BlockIo.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/Cpu.h>
-#include <Protocol/SimpleFileSystem.h>
-#include <Protocol/LoadFile.h>
-#include <Protocol/DebugPort.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/SimpleTextIn.h>
-#include <Protocol/LegacyBios.h>
-#include <Protocol/SimpleTextOut.h>
-#include <Protocol/SimpleNetwork.h>
-#include <Protocol/FirmwareVolume2.h>
-#include <Protocol/PciIo.h>
-#include <Protocol/AcpiS3Save.h>
-#include <Protocol/OEMBadging.h>
-#include <Protocol/GraphicsOutput.h>
-#include <Protocol/UgaDraw.h>
-#include <Protocol/HiiFont.h>
-#include <Protocol/HiiImage.h>
-#include <Protocol/UsbIo.h>
-#include <Protocol/BootLogo.h>
-
-#include <Guid/MemoryTypeInformation.h>
-#include <Guid/FileInfo.h>
-#include <Guid/GlobalVariable.h>
-#include <Guid/PcAnsi.h>
-#include <Guid/BdsLibHii.h>
-#include <Guid/HdBootVariable.h>
-#include <Guid/LastEnumLang.h>
-#include <Guid/LegacyDevOrder.h>
-#include <Guid/StatusCodeDataTypeVariable.h>
-
-#include <Library/PrintLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/HobLib.h>
-#include <Library/BaseLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PerformanceLib.h>
-#include <Library/PcdLib.h>
-#include <Library/PeCoffGetEntryPointLib.h>
-#include <Library/GenericBdsLib.h>
-#include <Library/TimerLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DxeServicesLib.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/BmpSupportLib.h>
-
-#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
-    #if defined (MDE_CPU_EBC)
-        //
-        // Uefi specification only defines the default boot file name for IA32, X64
-        // and IPF processor, so need define boot file name for EBC architecture here.
-        //
-        #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
-    #else
-        #error "Can not determine the default boot file name for unknown processor type!"
-    #endif
-#endif
-
-/**
-  Get the headers (dos, image, optional header) from an image
-
-  @param  Device                SimpleFileSystem device handle
-  @param  FileName              File name for the image
-  @param  DosHeader             Pointer to dos header
-  @param  Hdr                   The buffer in which to return the PE32, PE32+, or TE header.
-
-  @retval EFI_SUCCESS           Successfully get the machine type.
-  @retval EFI_NOT_FOUND         The file is not found.
-  @retval EFI_LOAD_ERROR        File is not a valid image file.
-
-**/
-EFI_STATUS
-EFIAPI
-BdsLibGetImageHeader (
-  IN  EFI_HANDLE                  Device,
-  IN  CHAR16                      *FileName,
-  OUT EFI_IMAGE_DOS_HEADER        *DosHeader,
-  OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr
-  );
-
-/**
-  This routine adjust the memory information for different memory type and 
-  save them into the variables for next boot.
-**/
-VOID
-BdsSetMemoryTypeInformationVariable (
-  VOID
-  );
-
-/**
-  Validate the EFI Boot#### or Driver#### variable (VendorGuid/Name)
-
-  @param  Variable              Boot#### variable data.
-  @param  VariableSize          Returns the size of the EFI variable that was read
-
-  @retval TRUE                  The variable data is correct.
-  @retval FALSE                 The variable data is corrupted.
-
-**/
-BOOLEAN 
-ValidateOption (
-  UINT8                     *Variable,
-  UINTN                     VariableSize
-  );
-
-/**
-  Set the variable and report the error through status code upon failure.
-
-  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.
-                                 Each VariableName is unique for each VendorGuid. VariableName must
-                                 contain 1 or more characters. If VariableName is an empty string,
-                                 then EFI_INVALID_PARAMETER is returned.
-  @param  VendorGuid             A unique identifier for the vendor.
-  @param  Attributes             Attributes bitmask to set for the variable.
-  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, 
-                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
-                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero 
-                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is 
-                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to 
-                                 the variable value (the timestamp associated with the variable may be updated however 
-                                 even if no new data value is provided,see the description of the 
-                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not 
-                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
-  @param  Data                   The contents for the variable.
-
-  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as
-                                 defined by the Attributes.
-  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the
-                                 DataSize exceeds the maximum allowed.
-  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
-  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.
-  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.
-  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
-  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
-  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
-                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
-                                 does NOT pass the validation check carried out by the firmware.
-
-  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.
-**/
-EFI_STATUS
-SetVariableAndReportStatusCodeOnError (
-  IN CHAR16     *VariableName,
-  IN EFI_GUID   *VendorGuid,
-  IN UINT32     Attributes,
-  IN UINTN      DataSize,
-  IN VOID       *Data
-  );
-
-#endif // _BDS_LIB_H_
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c
deleted file mode 100644
index f36860d5a1..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/** @file
-  String support
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-#include "String.h"
-
-/**
-  Get string by string id from HII Interface
-
-
-  @param Id              String ID.
-
-  @retval  CHAR16 *  String from ID.
-  @retval  NULL      If error occurs.
-
-**/
-CHAR16 *
-BdsLibGetStringById (
-  IN  EFI_STRING_ID   Id
-  )
-{
-  return HiiGetString (gBdsLibStringPackHandle, Id, NULL);
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h b/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h
deleted file mode 100644
index 53cabe64a9..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/String.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/** @file
-  String support
-
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _STRING_H_
-#define _STRING_H_
-
-#include <Library/HiiLib.h>
-#include <Library/DebugLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/UefiLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-
-extern EFI_HII_HANDLE gBdsLibStringPackHandle;
-
-//
-// This is the VFR compiler generated header file which defines the
-// string identifiers.
-//
-
-extern UINT8  GenericBdsLibStrings[];
-
-/**
-  Get string by string id from HII Interface
-
-
-  @param Id              String ID.
-
-  @retval  CHAR16 *  String from ID.
-  @retval  NULL      If error occurs.
-
-**/
-CHAR16 *
-BdsLibGetStringById (
-  IN  EFI_STRING_ID   Id
-  );
-
-#endif // _STRING_H_
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf
index 15a4251cf8..b0fbbdb9cb 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkg.fdf
@@ -9,12 +9,10 @@
 #**/
 
 [Defines]
-DEFINE FLASH_BASE       = 0xFF800000     #The base address of the 4Mb FLASH Device.
-DEFINE FLASH_SIZE       = 0x00800000     #The flash size in bytes of the 4Mb FLASH Device.
-DEFINE FLASH_BLOCK_SIZE = 0x1000        #The block size in bytes of the 4Mb FLASH Device.
-DEFINE FLASH_NUM_BLOCKS = 0x800           #The number of blocks in 4Mb FLASH Device.
-DEFINE FLASH_AREA_BASE_ADDRESS                                = 0xFF800000
-DEFINE FLASH_AREA_SIZE                                        = 0x00800000
+DEFINE FLASH_BASE       = 0xFF800000     #The base address of the 8Mb FLASH Device.
+DEFINE FLASH_SIZE       = 0x00800000     #The flash size in bytes of the 8Mb FLASH Device.
+DEFINE FLASH_BLOCK_SIZE = 0x1000         #The block size in bytes of the 8Mb FLASH Device.
+DEFINE FLASH_NUM_BLOCKS = 0x800          #The number of blocks in 8Mb FLASH Device.
 
 DEFINE FLASH_REGION_VLVMICROCODE_OFFSET                       = 0x00400000
 DEFINE FLASH_REGION_VLVMICROCODE_SIZE                         = 0x00040000
@@ -62,8 +60,11 @@ [FD.Vlv]
 #
 #Flash location override based on actual flash map
 #
-SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress            = $(FLASH_AREA_BASE_ADDRESS)
-SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize                   = $(FLASH_AREA_SIZE)
+SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress            = $(FLASH_BASE)
+SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize                   = $(FLASH_SIZE)
+
+SET gPlatformModuleTokenSpaceGuid.PcdBiosRomBase                     = $(FLASH_BASE)
+SET gPlatformModuleTokenSpaceGuid.PcdBiosRomSize                     = $(FLASH_SIZE)
 
 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress = $(FLASH_REGION_VLVMICROCODE_BASE) + 0x60
 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize = $(FLASH_REGION_VLVMICROCODE_SIZE) - 0x60
@@ -401,12 +402,9 @@ [FV.FVMAIN]
 INF UefiCpuPkg/CpuDxe/CpuDxe.inf
 INF UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
 INF MdeModulePkg/Universal/Metronome/Metronome.inf
-INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
-!if $(ARCH) == IA32
-INF USE=IA32 MdeModulePkg/Logo/Logo.inf
-!else
-INF USE=X64 MdeModulePkg/Logo/Logo.inf
-!endif
+INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+INF MdeModulePkg/Logo/LogoDxe.inf
+INF MdeModulePkg/Application/UiApp/UiApp.inf
 INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
 INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
 INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf
index b8ac61d710..107c160b76 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf
@@ -9,34 +9,32 @@
 #**/
 
 [Defines]
-DEFINE FLASH_BASE       = 0xFFC00000     #The base address of the 4Mb FLASH Device.
-DEFINE FLASH_SIZE       = 0x00400000     #The flash size in bytes of the 4Mb FLASH Device.
-DEFINE FLASH_BLOCK_SIZE = 0x1000        #The block size in bytes of the 4Mb FLASH Device.
-DEFINE FLASH_NUM_BLOCKS = 0x400           #The number of blocks in 4Mb FLASH Device.
-DEFINE FLASH_AREA_BASE_ADDRESS                                = 0xFF800000
-DEFINE FLASH_AREA_SIZE                                        = 0x00800000
+DEFINE FLASH_BASE       = 0xFF800000     #The base address of the 8Mb FLASH Device.
+DEFINE FLASH_SIZE       = 0x00800000     #The flash size in bytes of the 8Mb FLASH Device.
+DEFINE FLASH_BLOCK_SIZE = 0x1000         #The block size in bytes of the 8Mb FLASH Device.
+DEFINE FLASH_NUM_BLOCKS = 0x800          #The number of blocks in 8Mb FLASH Device.
 
-DEFINE FLASH_REGION_VLVMICROCODE_OFFSET                       = 0x00000000
+DEFINE FLASH_REGION_VLVMICROCODE_OFFSET                       = 0x00400000
 DEFINE FLASH_REGION_VLVMICROCODE_SIZE                         = 0x00040000
 DEFINE FLASH_REGION_VLVMICROCODE_BASE                         = 0xFFC00000
 
-DEFINE FLASH_REGION_VPD_OFFSET                                = 0x00040000
+DEFINE FLASH_REGION_VPD_OFFSET                                = 0x00440000
 DEFINE FLASH_REGION_VPD_SIZE                                  = 0x0003E000
 
-DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_OFFSET = 0x0007E000
+DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_OFFSET = 0x0047E000
 DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_WORKING_SIZE   = 0x00002000
 
 
-DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_OFFSET   = 0x00080000
+DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_OFFSET   = 0x00480000
 DEFINE FLASH_REGION_NVSTORAGE_SUBREGION_NV_FTW_SPARE_SIZE     = 0x00040000
 
-DEFINE FLASH_REGION_FVMAIN_OFFSET                             = 0x00110000
-DEFINE FLASH_REGION_FVMAIN_SIZE                               = 0x00215000
+DEFINE FLASH_REGION_FVMAIN_OFFSET                             = 0x00510000
+DEFINE FLASH_REGION_FVMAIN_SIZE                               = 0x00210000
 
-DEFINE FLASH_REGION_FV_RECOVERY2_OFFSET                       = 0x00325000
-DEFINE FLASH_REGION_FV_RECOVERY2_SIZE                         = 0x0006B000
+DEFINE FLASH_REGION_FV_RECOVERY2_OFFSET                       = 0x00720000
+DEFINE FLASH_REGION_FV_RECOVERY2_SIZE                         = 0x00070000
 
-DEFINE FLASH_REGION_FV_RECOVERY_OFFSET                        = 0x00390000
+DEFINE FLASH_REGION_FV_RECOVERY_OFFSET                        = 0x00790000
 DEFINE FLASH_REGION_FV_RECOVERY_SIZE                          = 0x00070000
 
 ################################################################################
@@ -62,8 +60,11 @@ [FD.Vlv]
 #
 #Flash location override based on actual flash map
 #
-SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress            = $(FLASH_AREA_BASE_ADDRESS)
-SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize                   = $(FLASH_AREA_SIZE)
+SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress            = $(FLASH_BASE)
+SET gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize                   = $(FLASH_SIZE)
+
+SET gPlatformModuleTokenSpaceGuid.PcdBiosRomBase                     = $(FLASH_BASE)
+SET gPlatformModuleTokenSpaceGuid.PcdBiosRomSize                     = $(FLASH_SIZE)
 
 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress = $(FLASH_REGION_VLVMICROCODE_BASE) + 0x60
 SET gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize = $(FLASH_REGION_VLVMICROCODE_SIZE) - 0x60
@@ -84,9 +85,12 @@ [FD.Vlv]
 # Fv Size can be adjusted; FVMAIN_COMPACT can be reduced to 0x120000, and FV_RECOVERY can be enlarged to 0x80000
 #
 ################################################################################
-# Since the Fce tool don't have gcc version, we can't handle default variable in Linux,
-# so we hardcode the default value of variable here.
-# Please note that we MUST update the binary once the default value is changed.
+
+  #
+  # IFWI Header
+  #
+0x0000|0x1000
+FILE=Vlv2TbltDevicePkg/Stitch/IFWIHeader/IFWI_HEADER.bin
 
 #
   # CPU Microcodes
@@ -347,12 +351,9 @@ [FV.FVMAIN]
 INF UefiCpuPkg/CpuDxe/CpuDxe.inf
 INF UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
 INF MdeModulePkg/Universal/Metronome/Metronome.inf
-INF IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
-!if $(ARCH) == IA32
-INF USE=IA32 MdeModulePkg/Logo/Logo.inf
-!else
-INF USE=X64 MdeModulePkg/Logo/Logo.inf
-!endif
+INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+INF MdeModulePkg/Logo/LogoDxe.inf
+INF MdeModulePkg/Application/UiApp/UiApp.inf
 INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
 INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
 INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc
index 3910281c49..e4c6750c70 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc
@@ -118,7 +118,6 @@ [LibraryClasses.common]
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
   UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
-  GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
   BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
   FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.inf
@@ -523,6 +522,8 @@ [PcdsFixedAtBuild.common]
   #
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000
 
+  gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
+
   #
   # Clear unused single certificate PCD
   #
@@ -933,19 +934,18 @@ [Components.X64]
   }
   MdeModulePkg/Universal/Metronome/Metronome.inf
 
-  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{
+  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf {
     <LibraryClasses>
-      OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
-      IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
-      BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-      PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBdsLib.inf
-      DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
-      PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-      SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+      PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
       Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
   }
-
-  $(PLATFORM_PACKAGE)/UiApp/UiApp.inf
+  MdeModulePkg/Logo/LogoDxe.inf
+  MdeModulePkg/Application/UiApp/UiApp.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
+  }
 
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
   MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
index 2ae594e5be..f5795e5ab0 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
@@ -116,7 +116,6 @@ [LibraryClasses.common]
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
   UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
-  GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
   BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
   FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.inf
@@ -520,6 +519,8 @@ [PcdsFixedAtBuild.common]
   #
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000
 
+  gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
+
   #
   # Clear unused single certificate PCD
   #
@@ -917,19 +918,18 @@ [Components.IA32]
   }
   MdeModulePkg/Universal/Metronome/Metronome.inf
 
-  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{
+  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf {
     <LibraryClasses>
-      OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
-      IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
-      BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-      PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBdsLib.inf
-      DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
-      PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-      SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+      PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
       Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
   }
-
-  $(PLATFORM_PACKAGE)/UiApp/UiApp.inf
+  MdeModulePkg/Logo/LogoDxe.inf
+  MdeModulePkg/Application/UiApp/UiApp.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
+  }
 
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
   MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
index 5cdc9bebc8..a930a85a35 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
@@ -118,7 +118,6 @@ [LibraryClasses.common]
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
   UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
-  GenericBdsLib|$(PLATFORM_PACKAGE)/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
   BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
   FlashDeviceLib|Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.inf
@@ -522,6 +521,8 @@ [PcdsFixedAtBuild.common]
   #
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackSize|0x4000
 
+  gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
+
   #
   # Clear unused single certificate PCD
   #
@@ -932,19 +933,18 @@ [Components.X64]
   }
   MdeModulePkg/Universal/Metronome/Metronome.inf
 
-  IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf{
+  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf {
     <LibraryClasses>
-      OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
-      IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
-      BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-      PlatformBdsLib|$(PLATFORM_PACKAGE)/Library/PlatformBdsLib/PlatformBdsLib.inf
-      DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
-      PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-      SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+      PlatformBootManagerLib|Vlv2TbltDevicePkg/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
       Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
   }
-
-  $(PLATFORM_PACKAGE)/UiApp/UiApp.inf
+  MdeModulePkg/Logo/LogoDxe.inf
+  MdeModulePkg/Application/UiApp/UiApp.inf {
+    <LibraryClasses>
+      NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
+      NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
+  }
 
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
   MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c b/Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c
deleted file mode 100644
index 3e58a6d22a..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/FrontPage.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/** @file
-
-  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
-                                                                                   

-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-                                                                                   

-
-
-
-**/
-
-/**
-  The user Entry Point for Application. The user code starts with this function
-  as the real entry point for the image goes into a library that calls this
-  function.
-
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
-  @param[in] SystemTable    A pointer to the EFI System Table.
-
-  @retval EFI_SUCCESS       The entry point is executed successfully.
-  @retval other             Some error occurs when executing this entry point.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeUserInterface (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-  return EFI_SUCCESS;
-}
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf b/Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf
deleted file mode 100644
index f7a0a83b80..0000000000
--- a/Platform/Intel/Vlv2TbltDevicePkg/UiApp/UiApp.inf
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-#
-# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
-#                                                                                  

-# SPDX-License-Identifier: BSD-2-Clause-Patent
-
-#                                                                                  

-#
-##
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = UiApp
-  FILE_GUID                      = 462CAA21-7614-4503-836E-8AB6F4662331
-  MODULE_TYPE                    = UEFI_APPLICATION
-  VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = InitializeUserInterface
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64 EBC
-#
-
-[Sources]
-  FrontPage.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-
-[LibraryClasses]
-  UefiApplicationEntryPoint
-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43069): https://edk2.groups.io/g/devel/message/43069
Mute This Topic: https://groups.io/mt/32267625/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