VirtualBox

Ignore:
Timestamp:
Oct 28, 2015 8:17:18 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103761
Message:

EFI/Firmware: 'svn merge /vendor/edk2/UDK2010.SR1 /vendor/edk2/current .', reverting and removing files+dirs listed in ReadMe.vbox, resolving conflicts with help from ../UDK2014.SP1/. This is a raw untested merge.

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware

  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c

    r48674 r58459  
    33  It will do Tiano or UEFI decompress with different verison parameter.
    44 
    5 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
     5Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    66This program and the accompanying materials                         
    77are licensed and made available under the terms and conditions of the BSD License         
     
    324324  UINT32  Mask;
    325325
     326  ASSERT (nn <= NPT);
    326327  //
    327328  // Read Extra Set Code Length Array size
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf

    r48674 r58459  
    33#  Tiano custom decompression algorithm shares most of code with Uefi Decompress algorithm.
    44#
    5 #  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     5#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    66#
    77#  This program and the accompanying materials
     
    1717  INF_VERSION                    = 0x00010005
    1818  BASE_NAME                      = BaseUefiTianoDecompressLib
     19  MODULE_UNI_FILE                = BaseUefiTianoDecompressLib.uni
    1920  FILE_GUID                      = d774c4d9-c121-4da3-a5e2-0f317e3c630c
    2021  MODULE_TYPE                    = BASE
     
    4445
    4546[Guids]
    46   gTianoCustomDecompressGuid      ## PRODUCED  ## GUID specifies tiano custom decompress algorithm.
     47  gTianoCustomDecompressGuid      ## PRODUCES  ## UNDEFINED # specifies tiano custom decompress algorithm.
     48
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c

    r48674 r58459  
    11/** @file
    2   Capsule Library instance to update capsule image to flash.
    3 
    4   Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
     2  Capsule Library instance to process capsule images.
     3
     4  Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    1414**/
    1515#include <PiDxe.h>
     16
    1617#include <Guid/Capsule.h>
     18#include <Guid/FmpCapsule.h>
     19
    1720#include <Library/DebugLib.h>
    1821#include <Library/BaseMemoryLib.h>
     
    2023#include <Library/MemoryAllocationLib.h>
    2124#include <Library/CapsuleLib.h>
     25#include <Library/GenericBdsLib.h>
     26#include <Library/UefiBootServicesTableLib.h>
     27#include <Library/BaseLib.h>
     28#include <Library/DevicePathLib.h>
     29
     30#include <Protocol/FirmwareManagement.h>
     31#include <Protocol/DevicePath.h>
     32
     33
     34/**
     35  Function indicate the current completion progress of the firmware
     36  update. Platform may override with own specific progress function.
     37
     38  @param  Completion    A value between 1 and 100 indicating the current completion progress of the firmware update
     39
     40  @retval EFI_SUCESS    Input capsule is a correct FMP capsule.
     41**/
     42EFI_STATUS
     43EFIAPI
     44Update_Image_Progress (
     45   IN UINTN Completion
     46)
     47{
     48  return EFI_SUCCESS;
     49}
     50
     51
     52/**
     53  Validate Fmp capsules layout.
     54
     55  @param  CapsuleHeader    Points to a capsule header.
     56
     57  @retval EFI_SUCESS                     Input capsule is a correct FMP capsule.
     58  @retval EFI_INVALID_PARAMETER  Input capsule is not a correct FMP capsule.
     59**/
     60EFI_STATUS
     61ValidateFmpCapsule (
     62  IN EFI_CAPSULE_HEADER *CapsuleHeader
     63  )
     64{
     65  EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER       *FmpCapsuleHeader;
     66  UINT8                                        *EndOfCapsule;
     67  EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *ImageHeader;
     68  UINT8                                        *EndOfPayload;
     69  UINT64                                       *ItemOffsetList;
     70  UINT32                                       ItemNum;
     71  UINTN                                        Index;
     72
     73  FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize);
     74  EndOfCapsule     = (UINT8 *) CapsuleHeader + CapsuleHeader->CapsuleImageSize;
     75
     76  if (FmpCapsuleHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION) {
     77    return EFI_INVALID_PARAMETER;
     78  }
     79  ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
     80
     81  ItemNum = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount;
     82
     83  if (ItemNum == FmpCapsuleHeader->EmbeddedDriverCount) {
     84    //
     85    // No payload element
     86    //
     87    if (((UINT8 *)FmpCapsuleHeader + ItemOffsetList[ItemNum - 1]) < EndOfCapsule) {
     88      return EFI_SUCCESS;
     89    } else {
     90      return EFI_INVALID_PARAMETER;
     91    }
     92  }
     93
     94  if (FmpCapsuleHeader->PayloadItemCount != 0) {
     95    //
     96    // Check if the last payload is within capsule image range
     97    //
     98    ImageHeader  = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[ItemNum - 1]);
     99    EndOfPayload = (UINT8 *)(ImageHeader + 1) + ImageHeader->UpdateImageSize + ImageHeader->UpdateVendorCodeSize;
     100  } else {
     101    //
     102    // No driver & payload element in FMP
     103    //
     104    EndOfPayload = (UINT8 *)(FmpCapsuleHeader + 1);
     105  }
     106
     107  if (EndOfPayload != EndOfCapsule) {
     108    return EFI_INVALID_PARAMETER;
     109  }
     110
     111  //
     112  // All the address in ItemOffsetList must be stored in ascending order
     113  //
     114  if (ItemNum >= 2) {
     115    for (Index = 0; Index < ItemNum - 1; Index++) {
     116      if (ItemOffsetList[Index] >= ItemOffsetList[Index + 1]) {
     117        return EFI_INVALID_PARAMETER;
     118      }
     119    }
     120  }
     121
     122  return EFI_SUCCESS;
     123}
     124
     125/**
     126  Process Firmware management protocol data capsule. 
     127
     128  @param  CapsuleHeader         Points to a capsule header.
     129
     130  @retval EFI_SUCESS            Process Capsule Image successfully.
     131  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.
     132  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.
     133  @retval EFI_OUT_OF_RESOURCES  Not enough memory.
     134**/
     135EFI_STATUS
     136ProcessFmpCapsuleImage (
     137  IN EFI_CAPSULE_HEADER *CapsuleHeader
     138  )
     139{
     140  EFI_STATUS                                    Status;
     141  EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER        *FmpCapsuleHeader;
     142  UINT8                                         *EndOfCapsule;
     143  EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER  *ImageHeader;
     144  EFI_HANDLE                                    ImageHandle;
     145  UINT64                                        *ItemOffsetList;
     146  UINT32                                        ItemNum;
     147  UINTN                                         Index;
     148  UINTN                                         ExitDataSize;
     149  EFI_HANDLE                                    *HandleBuffer;
     150  EFI_FIRMWARE_MANAGEMENT_PROTOCOL              *Fmp;
     151  UINTN                                         NumberOfHandles;
     152  UINTN                                         DescriptorSize;
     153  UINT8                                         FmpImageInfoCount;
     154  UINT32                                        FmpImageInfoDescriptorVer;
     155  UINTN                                         ImageInfoSize;
     156  UINT32                                        PackageVersion;
     157  CHAR16                                        *PackageVersionName;
     158  CHAR16                                        *AbortReason;
     159  EFI_FIRMWARE_IMAGE_DESCRIPTOR                 *FmpImageInfoBuf;
     160  EFI_FIRMWARE_IMAGE_DESCRIPTOR                 *TempFmpImageInfo;
     161  UINTN                                         DriverLen;
     162  UINTN                                         Index1;
     163  UINTN                                         Index2;
     164  MEMMAP_DEVICE_PATH                            MemMapNode;
     165  EFI_DEVICE_PATH_PROTOCOL                      *DriverDevicePath;
     166
     167  Status           = EFI_SUCCESS;
     168  HandleBuffer     = NULL;
     169  ExitDataSize     = 0;
     170  DriverDevicePath = NULL;
     171
     172  FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize);
     173  EndOfCapsule     = (UINT8 *) CapsuleHeader + CapsuleHeader->CapsuleImageSize;
     174
     175  if (FmpCapsuleHeader->Version > EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION) {
     176    return EFI_INVALID_PARAMETER;
     177  }
     178  ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
     179
     180  ItemNum = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount;
     181
     182  //
     183  // capsule in which driver count and payload count are both zero is not processed.
     184  //
     185  if (ItemNum == 0) {
     186    return EFI_SUCCESS;
     187  }
     188
     189  //
     190  // 1. ConnectAll to ensure
     191  //    All the communication protocol required by driver in capsule installed
     192  //    All FMP protocols are installed
     193  //
     194  BdsLibConnectAll();
     195
     196
     197  //
     198  // 2. Try to load & start all the drivers within capsule
     199  //
     200  SetDevicePathNodeLength (&MemMapNode.Header, sizeof (MemMapNode));
     201  MemMapNode.Header.Type     = HARDWARE_DEVICE_PATH;
     202  MemMapNode.Header.SubType  = HW_MEMMAP_DP;
     203  MemMapNode.MemoryType      = EfiBootServicesCode;
     204  MemMapNode.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CapsuleHeader;
     205  MemMapNode.EndingAddress   = (EFI_PHYSICAL_ADDRESS)(UINTN)((UINT8 *)CapsuleHeader + CapsuleHeader->CapsuleImageSize - 1);
     206
     207  DriverDevicePath = AppendDevicePathNode (NULL, &MemMapNode.Header);
     208  if (DriverDevicePath == NULL) {
     209    return EFI_OUT_OF_RESOURCES;
     210  }
     211
     212  for (Index = 0; Index < FmpCapsuleHeader->EmbeddedDriverCount; Index++) {
     213    if (FmpCapsuleHeader->PayloadItemCount == 0 && Index == (UINTN)FmpCapsuleHeader->EmbeddedDriverCount - 1) {
     214      //
     215      // When driver is last element in the ItemOffsetList array, the driver size is calculated by reference CapsuleImageSize in EFI_CAPSULE_HEADER
     216      //
     217      DriverLen = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize - (UINTN)ItemOffsetList[Index];
     218    } else {
     219      DriverLen = (UINTN)ItemOffsetList[Index + 1] - (UINTN)ItemOffsetList[Index];
     220    }
     221
     222    Status = gBS->LoadImage(
     223                    FALSE,
     224                    gImageHandle,
     225                    DriverDevicePath,
     226                    (UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index],
     227                    DriverLen,
     228                    &ImageHandle
     229                    );
     230    if (EFI_ERROR(Status)) {
     231      goto EXIT;
     232    }
     233
     234    Status = gBS->StartImage(
     235                    ImageHandle,
     236                    &ExitDataSize,
     237                    NULL
     238                    );
     239    if (EFI_ERROR(Status)) {
     240      DEBUG ((DEBUG_ERROR, "Driver Return Status = %r\n", Status));
     241      goto EXIT;
     242    }
     243  }
     244
     245  //
     246  // Connnect all again to connect drivers within capsule
     247  //
     248  if (FmpCapsuleHeader->EmbeddedDriverCount > 0) {
     249    BdsLibConnectAll();
     250  }
     251
     252  //
     253  // 3. Route payload to right FMP instance
     254  //
     255  Status = gBS->LocateHandleBuffer (
     256                  ByProtocol,
     257                  &gEfiFirmwareManagementProtocolGuid,
     258                  NULL,
     259                  &NumberOfHandles,
     260                  &HandleBuffer
     261                  );
     262
     263  if (!EFI_ERROR(Status)) {
     264    for(Index1 = 0; Index1 < NumberOfHandles; Index1++) {
     265      Status = gBS->HandleProtocol(
     266                      HandleBuffer[Index1],
     267                      &gEfiFirmwareManagementProtocolGuid,
     268                      (VOID **)&Fmp
     269                      );
     270      if (EFI_ERROR(Status)) {
     271        continue;
     272      }
     273
     274      ImageInfoSize = 0;
     275      Status = Fmp->GetImageInfo (
     276                      Fmp,
     277                      &ImageInfoSize,
     278                      NULL,
     279                      NULL,
     280                      NULL,
     281                      NULL,
     282                      NULL,
     283                      NULL
     284                      );
     285      if (Status != EFI_BUFFER_TOO_SMALL) {
     286        continue;
     287      }
     288
     289      FmpImageInfoBuf = NULL;
     290      FmpImageInfoBuf = AllocateZeroPool (ImageInfoSize);
     291      if (FmpImageInfoBuf == NULL) {
     292        Status = EFI_OUT_OF_RESOURCES;
     293        goto EXIT;
     294      }
     295
     296      PackageVersionName = NULL;
     297      Status = Fmp->GetImageInfo (
     298                      Fmp,
     299                      &ImageInfoSize,               // ImageInfoSize
     300                      FmpImageInfoBuf,              // ImageInfo
     301                      &FmpImageInfoDescriptorVer,   // DescriptorVersion
     302                      &FmpImageInfoCount,           // DescriptorCount
     303                      &DescriptorSize,              // DescriptorSize
     304                      &PackageVersion,              // PackageVersion
     305                      &PackageVersionName           // PackageVersionName
     306                      );
     307
     308      //
     309      // If FMP GetInformation interface failed, skip this resource
     310      //
     311      if (EFI_ERROR(Status)) {
     312        FreePool(FmpImageInfoBuf);
     313        continue;
     314      }
     315
     316      if (PackageVersionName != NULL) {
     317        FreePool(PackageVersionName);
     318      }
     319
     320      TempFmpImageInfo = FmpImageInfoBuf;
     321      for (Index2 = 0; Index2 < FmpImageInfoCount; Index2++) {
     322        //
     323        // Check all the payload entry in capsule payload list
     324        //
     325        for (Index = FmpCapsuleHeader->EmbeddedDriverCount; Index < ItemNum; Index++) {
     326          ImageHeader  = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
     327          if (CompareGuid(&ImageHeader->UpdateImageTypeId, &TempFmpImageInfo->ImageTypeId) &&
     328              ImageHeader->UpdateImageIndex == TempFmpImageInfo->ImageIndex) {
     329            AbortReason = NULL;
     330            if (ImageHeader->UpdateVendorCodeSize == 0) {
     331              Status = Fmp->SetImage(
     332                              Fmp,
     333                              TempFmpImageInfo->ImageIndex,           // ImageIndex
     334                              (UINT8 *)(ImageHeader + 1),             // Image
     335                              ImageHeader->UpdateImageSize,           // ImageSize
     336                              NULL,                                   // VendorCode
     337                              Update_Image_Progress,                  // Progress
     338                              &AbortReason                            // AbortReason
     339                              );
     340            } else {
     341              Status = Fmp->SetImage(
     342                              Fmp,
     343                              TempFmpImageInfo->ImageIndex,                                          // ImageIndex
     344                              (UINT8 *)(ImageHeader + 1),                                            // Image
     345                              ImageHeader->UpdateImageSize,                                          // ImageSize
     346                              (UINT8 *)((UINT8 *) (ImageHeader + 1) + ImageHeader->UpdateImageSize), // VendorCode
     347                              Update_Image_Progress,                                                 // Progress
     348                              &AbortReason                                                           // AbortReason
     349                              );
     350            }
     351            if (AbortReason != NULL) {
     352              DEBUG ((EFI_D_ERROR, "%s\n", AbortReason));
     353              FreePool(AbortReason);
     354            }
     355          }
     356        }
     357        //
     358        // Use DescriptorSize to move ImageInfo Pointer to stay compatible with different ImageInfo version
     359        //
     360        TempFmpImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)TempFmpImageInfo + DescriptorSize);
     361      }
     362      FreePool(FmpImageInfoBuf);
     363    }
     364  }
     365
     366EXIT:
     367
     368  if (HandleBuffer != NULL) {
     369    FreePool(HandleBuffer);
     370  }
     371
     372  if (DriverDevicePath != NULL) {
     373    FreePool(DriverDevicePath);
     374  }
     375
     376  return Status;
     377}
    22378
    23379/**
     
    28384  @retval EFI_SUCESS       Input capsule is supported by firmware.
    29385  @retval EFI_UNSUPPORTED  Input capsule is not supported by the firmware.
     386  @retval EFI_INVALID_PARAMETER Input capsule layout is not correct
    30387**/
    31388EFI_STATUS
     
    37394  if (CompareGuid (&gEfiCapsuleGuid, &CapsuleHeader->CapsuleGuid)) {
    38395    return EFI_SUCCESS;
     396  }
     397
     398  if (CompareGuid (&gEfiFmpCapsuleGuid, &CapsuleHeader->CapsuleGuid)) {
     399    //
     400    // Check layout of FMP capsule
     401    //
     402    return ValidateFmpCapsule(CapsuleHeader);
    39403  }
    40404
     
    74438
    75439  //
     440  // Check FMP capsule layout
     441  //
     442  if (CompareGuid (&gEfiFmpCapsuleGuid, &CapsuleHeader->CapsuleGuid)){
     443    Status = ValidateFmpCapsule(CapsuleHeader);
     444    if (EFI_ERROR(Status)) {
     445      return Status;
     446    }
     447
     448    //
     449    // Press EFI FMP Capsule
     450    //
     451    return ProcessFmpCapsuleImage(CapsuleHeader);
     452  }
     453
     454  //
    76455  // Skip the capsule header, move to the Firware Volume
    77456  //
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.inf

    r48674 r58459  
    11## @file
    2 # Capsule library instance for DXE_DRIVER, DXE_RUNTIME_DRIVER
     2# Capsule library instance for DXE_DRIVER, DXE_RUNTIME_DRIVER.
    33#
    4 # Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
     4# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
    55#
    66# This program and the accompanying materials
     
    1717  INF_VERSION                    = 0x00010005
    1818  BASE_NAME                      = DxeCapsuleLib
     19  MODULE_UNI_FILE                = DxeCapsuleLib.uni
    1920  FILE_GUID                      = 654950df-1ede-4b04-b144-6b77845736ad
    2021  MODULE_TYPE                    = DXE_DRIVER
     
    3435[Packages]
    3536  MdePkg/MdePkg.dec
     37  MdeModulePkg/MdeModulePkg.dec
    3638  IntelFrameworkPkg/IntelFrameworkPkg.dec
    37   MdeModulePkg/MdeModulePkg.dec
     39  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
    3840
    3941[LibraryClasses]
     
    4244  MemoryAllocationLib
    4345  DxeServicesTableLib
     46  GenericBdsLib
     47  UefiBootServicesTableLib
     48  DevicePathLib
     49
     50[Protocols]
     51  gEfiFirmwareManagementProtocolGuid      ## SOMETIMES_CONSUMES
    4452
    4553[Guids]
    46   gEfiCapsuleGuid                         # SOMETIMES_CONSUMED
    47  
     54  gEfiCapsuleGuid                         ## SOMETIMES_CONSUMES ## GUID # Capsule Image Header Guid
     55  gEfiFmpCapsuleGuid                      ## SOMETIMES_CONSUMES ## GUID
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

    r48674 r58459  
    11## @file
    2 DXE report status code library
     2Framework DXE report status code library to support EFI1.1 and UEFI2.0 system.
    33#
    4 #  Retrieve status code and report status code in DXE phase
    5 #  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     4#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    65#
    76#  This program and the accompanying materials
     
    1817  INF_VERSION                    = 0x00010005
    1918  BASE_NAME                      = DxeReportStatusCodeLib
     19  MODULE_UNI_FILE                = DxeReportStatusCodeLib.uni
    2020  FILE_GUID                      = 3ddc3b12-99ea-4364-b315-6310a2050be5
    2121  MODULE_TYPE                    = DXE_DRIVER
     
    4848
    4949[Guids]
    50   gEfiStatusCodeSpecificDataGuid                ## CONSUMES
    51   gEfiStatusCodeDataTypeDebugGuid               ## CONSUMES
     50  gEfiStatusCodeSpecificDataGuid                ## SOMETIMES_CONSUMES ## UNDEFINED
     51  gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES ## UNDEFINED
    5252
    5353[Protocols]
    54   gEfiStatusCodeRuntimeProtocolGuid             ## SOMETIMES_CONSUMES (Used if revision of the EFI Specification is not less than 0x20000)
     54  gEfiStatusCodeRuntimeProtocolGuid             ## SOMETIMES_CONSUMES # Used if revision of the EFI Specification is not less than 0x20000
    5555
    5656[Pcd]
    57   gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask
     57  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ## CONSUMES
    5858
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c

    r48762 r58459  
    22  BDS Lib functions which relate with create or process the boot option.
    33
    4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    4949  gBdsLibStringPackHandle = HiiAddPackages (
    5050                              &gBdsLibStringPackageGuid,
    51                               &ImageHandle,
     51                              ImageHandle,
    5252                              GenericBdsLibStrings,
    5353                              NULL
     
    5959}
    6060
    61 
     61/**
     62  Deletete the Boot Option from EFI Variable. The Boot Order Arrray
     63  is also updated.
     64
     65  @param OptionNumber    The number of Boot option want to be deleted.
     66  @param BootOrder       The Boot Order array.
     67  @param BootOrderSize   The size of the Boot Order Array.
     68
     69  @retval  EFI_SUCCESS           The Boot Option Variable was found and removed
     70  @retval  EFI_UNSUPPORTED       The Boot Option Variable store was inaccessible
     71  @retval  EFI_NOT_FOUND         The Boot Option Variable was not found
     72**/
     73EFI_STATUS
     74EFIAPI
     75BdsDeleteBootOption (
     76  IN UINTN                       OptionNumber,
     77  IN OUT UINT16                  *BootOrder,
     78  IN OUT UINTN                   *BootOrderSize
     79  )
     80{
     81  CHAR16      BootOption[9];
     82  UINTN       Index;
     83  EFI_STATUS  Status;
     84
     85  UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumber);
     86  Status = gRT->SetVariable (
     87                  BootOption,
     88                  &gEfiGlobalVariableGuid,
     89                  0,
     90                  0,
     91                  NULL
     92                  );
     93  //
     94  // Deleting variable with existing variable implementation shouldn't fail.
     95  //
     96  ASSERT_EFI_ERROR (Status);
     97
     98  //
     99  // adjust boot order array
     100  //
     101  for (Index = 0; Index < *BootOrderSize / sizeof (UINT16); Index++) {
     102    if (BootOrder[Index] == OptionNumber) {
     103      CopyMem (&BootOrder[Index], &BootOrder[Index+1], *BootOrderSize - (Index+1) * sizeof (UINT16));
     104      *BootOrderSize -= sizeof (UINT16);
     105      break;
     106    }
     107  }
     108
     109  return Status;
     110}
     111/**
     112
     113  Translate the first n characters of an Ascii string to
     114  Unicode characters. The count n is indicated by parameter
     115  Size. If Size is greater than the length of string, then
     116  the entire string is translated.
     117
     118
     119  @param AStr               Pointer to input Ascii string.
     120  @param Size               The number of characters to translate.
     121  @param UStr               Pointer to output Unicode string buffer.
     122
     123**/
     124VOID
     125AsciiToUnicodeSize (
     126  IN UINT8              *AStr,
     127  IN UINTN              Size,
     128  OUT UINT16            *UStr
     129  )
     130{
     131  UINTN Idx;
     132
     133  Idx = 0;
     134  while (AStr[Idx] != 0) {
     135    UStr[Idx] = (CHAR16) AStr[Idx];
     136    if (Idx == Size) {
     137      break;
     138    }
     139
     140    Idx++;
     141  }
     142  UStr[Idx] = 0;
     143}
     144
     145/**
     146  Build Legacy Device Name String according.
     147
     148  @param CurBBSEntry     BBS Table.
     149  @param Index           Index.
     150  @param BufSize         The buffer size.
     151  @param BootString      The output string.
     152
     153**/
     154VOID
     155BdsBuildLegacyDevNameString (
     156  IN  BBS_TABLE                 *CurBBSEntry,
     157  IN  UINTN                     Index,
     158  IN  UINTN                     BufSize,
     159  OUT CHAR16                    *BootString
     160  )
     161{
     162  CHAR16  *Fmt;
     163  CHAR16  *Type;
     164  UINT8   *StringDesc;
     165  CHAR16  Temp[80];
     166
     167  switch (Index) {
     168  //
     169  // Primary Master
     170  //
     171  case 1:
     172    Fmt = L"Primary Master %s";
     173    break;
     174
     175 //
     176 // Primary Slave
     177 //
     178  case 2:
     179    Fmt = L"Primary Slave %s";
     180    break;
     181
     182  //
     183  // Secondary Master
     184  //
     185  case 3:
     186    Fmt = L"Secondary Master %s";
     187    break;
     188
     189  //
     190  // Secondary Slave
     191  //
     192  case 4:
     193    Fmt = L"Secondary Slave %s";
     194    break;
     195
     196  default:
     197    Fmt = L"%s";
     198    break;
     199  }
     200
     201  switch (CurBBSEntry->DeviceType) {
     202  case BBS_FLOPPY:
     203    Type = L"Floppy";
     204    break;
     205
     206  case BBS_HARDDISK:
     207    Type = L"Harddisk";
     208    break;
     209
     210  case BBS_CDROM:
     211    Type = L"CDROM";
     212    break;
     213
     214  case BBS_PCMCIA:
     215    Type = L"PCMCIAe";
     216    break;
     217
     218  case BBS_USB:
     219    Type = L"USB";
     220    break;
     221
     222  case BBS_EMBED_NETWORK:
     223    Type = L"Network";
     224    break;
     225
     226  case BBS_BEV_DEVICE:
     227    Type = L"BEVe";
     228    break;
     229
     230  case BBS_UNKNOWN:
     231  default:
     232    Type = L"Unknown";
     233    break;
     234  }
     235  //
     236  // If current BBS entry has its description then use it.
     237  //
     238  StringDesc = (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
     239  if (NULL != StringDesc) {
     240    //
     241    // Only get fisrt 32 characters, this is suggested by BBS spec
     242    //
     243    AsciiToUnicodeSize (StringDesc, 32, Temp);
     244    Fmt   = L"%s";
     245    Type  = Temp;
     246  }
     247
     248  //
     249  // BbsTable 16 entries are for onboard IDE.
     250  // Set description string for SATA harddisks, Harddisk 0 ~ Harddisk 11
     251  //
     252  if (Index >= 5 && Index <= 16 && (CurBBSEntry->DeviceType == BBS_HARDDISK || CurBBSEntry->DeviceType == BBS_CDROM)) {
     253    Fmt = L"%s %d";
     254    UnicodeSPrint (BootString, BufSize, Fmt, Type, Index - 5);
     255  } else {
     256    UnicodeSPrint (BootString, BufSize, Fmt, Type);
     257  }
     258}
     259
     260/**
     261
     262  Create a legacy boot option for the specified entry of
     263  BBS table, save it as variable, and append it to the boot
     264  order list.
     265
     266
     267  @param CurrentBbsEntry    Pointer to current BBS table.
     268  @param CurrentBbsDevPath  Pointer to the Device Path Protocol instance of BBS
     269  @param Index              Index of the specified entry in BBS table.
     270  @param BootOrderList      On input, the original boot order list.
     271                            On output, the new boot order list attached with the
     272                            created node.
     273  @param BootOrderListSize  On input, the original size of boot order list.
     274                            On output, the size of new boot order list.
     275
     276  @retval  EFI_SUCCESS             Boot Option successfully created.
     277  @retval  EFI_OUT_OF_RESOURCES    Fail to allocate necessary memory.
     278  @retval  Other                   Error occurs while setting variable.
     279
     280**/
     281EFI_STATUS
     282BdsCreateLegacyBootOption (
     283  IN BBS_TABLE                        *CurrentBbsEntry,
     284  IN EFI_DEVICE_PATH_PROTOCOL         *CurrentBbsDevPath,
     285  IN UINTN                            Index,
     286  IN OUT UINT16                       **BootOrderList,
     287  IN OUT UINTN                        *BootOrderListSize
     288  )
     289{
     290  EFI_STATUS           Status;
     291  UINT16               CurrentBootOptionNo;
     292  UINT16               BootString[10];
     293  CHAR16               BootDesc[100];
     294  CHAR8                HelpString[100];
     295  UINT16               *NewBootOrderList;
     296  UINTN                BufferSize;
     297  UINTN                StringLen;
     298  VOID                 *Buffer;
     299  UINT8                *Ptr;
     300  UINT16               CurrentBbsDevPathSize;
     301  UINTN                BootOrderIndex;
     302  UINTN                BootOrderLastIndex;
     303  UINTN                ArrayIndex;
     304  BOOLEAN              IndexNotFound;
     305  BBS_BBS_DEVICE_PATH  *NewBbsDevPathNode;
     306
     307  if ((*BootOrderList) == NULL) {
     308    CurrentBootOptionNo = 0;
     309  } else {
     310    for (ArrayIndex = 0; ArrayIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); ArrayIndex++) {
     311      IndexNotFound = TRUE;
     312      for (BootOrderIndex = 0; BootOrderIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); BootOrderIndex++) {
     313        if ((*BootOrderList)[BootOrderIndex] == ArrayIndex) {
     314          IndexNotFound = FALSE;
     315          break;
     316        }
     317      }
     318
     319      if (!IndexNotFound) {
     320        continue;
     321      } else {
     322        break;
     323      }
     324    }
     325
     326    CurrentBootOptionNo = (UINT16) ArrayIndex;
     327  }
     328
     329  UnicodeSPrint (
     330    BootString,
     331    sizeof (BootString),
     332    L"Boot%04x",
     333    CurrentBootOptionNo
     334    );
     335
     336  BdsBuildLegacyDevNameString (CurrentBbsEntry, Index, sizeof (BootDesc), BootDesc);
     337
     338  //
     339  // Create new BBS device path node with description string
     340  //
     341  UnicodeStrToAsciiStr (BootDesc, HelpString);
     342
     343  StringLen = AsciiStrLen (HelpString);
     344  NewBbsDevPathNode = AllocateZeroPool (sizeof (BBS_BBS_DEVICE_PATH) + StringLen);
     345  if (NewBbsDevPathNode == NULL) {
     346    return EFI_OUT_OF_RESOURCES;
     347  }
     348  CopyMem (NewBbsDevPathNode, CurrentBbsDevPath, sizeof (BBS_BBS_DEVICE_PATH));
     349  CopyMem (NewBbsDevPathNode->String, HelpString, StringLen + 1);
     350  SetDevicePathNodeLength (&(NewBbsDevPathNode->Header), sizeof (BBS_BBS_DEVICE_PATH) + StringLen);
     351
     352  //
     353  // Create entire new CurrentBbsDevPath with end node
     354  //
     355  CurrentBbsDevPath = AppendDevicePathNode (
     356                        NULL,
     357                        (EFI_DEVICE_PATH_PROTOCOL *) NewBbsDevPathNode
     358                        );
     359   if (CurrentBbsDevPath == NULL) {
     360    FreePool (NewBbsDevPathNode);
     361    return EFI_OUT_OF_RESOURCES;
     362  }
     363
     364  CurrentBbsDevPathSize = (UINT16) (GetDevicePathSize (CurrentBbsDevPath));
     365
     366  BufferSize = sizeof (UINT32) +
     367    sizeof (UINT16) +
     368    StrSize (BootDesc) +
     369    CurrentBbsDevPathSize +
     370    sizeof (BBS_TABLE) +
     371    sizeof (UINT16);
     372
     373  Buffer = AllocateZeroPool (BufferSize);
     374  if (Buffer == NULL) {
     375    FreePool (NewBbsDevPathNode);
     376    FreePool (CurrentBbsDevPath);
     377    return EFI_OUT_OF_RESOURCES;
     378  }
     379
     380  Ptr               = (UINT8 *) Buffer;
     381
     382  *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE;
     383  Ptr += sizeof (UINT32);
     384
     385  *((UINT16 *) Ptr) = CurrentBbsDevPathSize;
     386  Ptr += sizeof (UINT16);
     387
     388  CopyMem (
     389    Ptr,
     390    BootDesc,
     391    StrSize (BootDesc)
     392    );
     393  Ptr += StrSize (BootDesc);
     394
     395  CopyMem (
     396    Ptr,
     397    CurrentBbsDevPath,
     398    CurrentBbsDevPathSize
     399    );
     400  Ptr += CurrentBbsDevPathSize;
     401
     402  CopyMem (
     403    Ptr,
     404    CurrentBbsEntry,
     405    sizeof (BBS_TABLE)
     406    );
     407
     408  Ptr += sizeof (BBS_TABLE);
     409  *((UINT16 *) Ptr) = (UINT16) Index;
     410
     411  Status = gRT->SetVariable (
     412                  BootString,
     413                  &gEfiGlobalVariableGuid,
     414                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     415                  BufferSize,
     416                  Buffer
     417                  );
     418
     419  FreePool (Buffer);
     420 
     421  Buffer = NULL;
     422
     423  NewBootOrderList = AllocateZeroPool (*BootOrderListSize + sizeof (UINT16));
     424  if (NULL == NewBootOrderList) {
     425    FreePool (NewBbsDevPathNode);
     426    FreePool (CurrentBbsDevPath);
     427    return EFI_OUT_OF_RESOURCES;
     428  }
     429
     430  if (*BootOrderList != NULL) {
     431    CopyMem (NewBootOrderList, *BootOrderList, *BootOrderListSize);
     432    FreePool (*BootOrderList);
     433  }
     434
     435  BootOrderLastIndex                    = (UINTN) (*BootOrderListSize / sizeof (UINT16));
     436  NewBootOrderList[BootOrderLastIndex]  = CurrentBootOptionNo;
     437  *BootOrderListSize += sizeof (UINT16);
     438  *BootOrderList = NewBootOrderList;
     439
     440  FreePool (NewBbsDevPathNode);
     441  FreePool (CurrentBbsDevPath);
     442  return Status;
     443}
     444
     445/**
     446  Check if the boot option is a legacy one.
     447
     448  @param BootOptionVar   The boot option data payload.
     449  @param BbsEntry        The BBS Table.
     450  @param BbsIndex        The table index.
     451
     452  @retval TRUE           It is a legacy boot option.
     453  @retval FALSE          It is not a legacy boot option.
     454
     455**/
     456BOOLEAN
     457BdsIsLegacyBootOption (
     458  IN UINT8                 *BootOptionVar,
     459  OUT BBS_TABLE            **BbsEntry,
     460  OUT UINT16               *BbsIndex
     461  )
     462{
     463  UINT8                     *Ptr;
     464  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
     465  BOOLEAN                   Ret;
     466  UINT16                    DevPathLen;
     467
     468  Ptr = BootOptionVar;
     469  Ptr += sizeof (UINT32);
     470  DevPathLen = *(UINT16 *) Ptr;
     471  Ptr += sizeof (UINT16);
     472  Ptr += StrSize ((UINT16 *) Ptr);
     473  DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
     474  if ((BBS_DEVICE_PATH == DevicePath->Type) && (BBS_BBS_DP == DevicePath->SubType)) {
     475    Ptr += DevPathLen;
     476    *BbsEntry = (BBS_TABLE *) Ptr;
     477    Ptr += sizeof (BBS_TABLE);
     478    *BbsIndex = *(UINT16 *) Ptr;
     479    Ret       = TRUE;
     480  } else {
     481    *BbsEntry = NULL;
     482    Ret       = FALSE;
     483  }
     484
     485  return Ret;
     486}
     487
     488/**
     489  Delete all the invalid legacy boot options.
     490
     491  @retval EFI_SUCCESS             All invalide legacy boot options are deleted.
     492  @retval EFI_OUT_OF_RESOURCES    Fail to allocate necessary memory.
     493  @retval EFI_NOT_FOUND           Fail to retrive variable of boot order.
     494**/
     495EFI_STATUS
     496EFIAPI
     497BdsDeleteAllInvalidLegacyBootOptions (
     498  VOID
     499  )
     500{
     501  UINT16                    *BootOrder;
     502  UINT8                     *BootOptionVar;
     503  UINTN                     BootOrderSize;
     504  UINTN                     BootOptionSize;
     505  EFI_STATUS                Status;
     506  UINT16                    HddCount;
     507  UINT16                    BbsCount;
     508  HDD_INFO                  *LocalHddInfo;
     509  BBS_TABLE                 *LocalBbsTable;
     510  BBS_TABLE                 *BbsEntry;
     511  UINT16                    BbsIndex;
     512  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
     513  UINTN                     Index;
     514  UINT16                    BootOption[10];
     515  UINT16                    BootDesc[100];
     516  BOOLEAN                   DescStringMatch;
     517
     518  Status        = EFI_SUCCESS;
     519  BootOrder     = NULL;
     520  BootOrderSize = 0;
     521  HddCount      = 0;
     522  BbsCount      = 0;
     523  LocalHddInfo  = NULL;
     524  LocalBbsTable = NULL;
     525  BbsEntry      = NULL;
     526
     527  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
     528  if (EFI_ERROR (Status)) {
     529    return Status;
     530  }
     531
     532  BootOrder = BdsLibGetVariableAndSize (
     533                L"BootOrder",
     534                &gEfiGlobalVariableGuid,
     535                &BootOrderSize
     536                );
     537  if (BootOrder == NULL) {
     538    return EFI_NOT_FOUND;
     539  }
     540
     541  LegacyBios->GetBbsInfo (
     542                LegacyBios,
     543                &HddCount,
     544                &LocalHddInfo,
     545                &BbsCount,
     546                &LocalBbsTable
     547                );
     548
     549  Index = 0;
     550  while (Index < BootOrderSize / sizeof (UINT16)) {
     551    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
     552    BootOptionVar = BdsLibGetVariableAndSize (
     553                      BootOption,
     554                      &gEfiGlobalVariableGuid,
     555                      &BootOptionSize
     556                      );
     557    if (NULL == BootOptionVar) {
     558      BootOptionSize = 0;
     559      Status = gRT->GetVariable (
     560                      BootOption,
     561                      &gEfiGlobalVariableGuid,
     562                      NULL,
     563                      &BootOptionSize,
     564                      BootOptionVar
     565                      );
     566      if (Status == EFI_NOT_FOUND) {
     567        //
     568        // Update BootOrder
     569        //
     570        BdsDeleteBootOption (
     571          BootOrder[Index],
     572          BootOrder,
     573          &BootOrderSize
     574          );
     575        continue;
     576      } else {
     577        FreePool (BootOrder);
     578        return EFI_OUT_OF_RESOURCES;
     579      }
     580    }
     581 
     582    //
     583    // Skip Non-Legacy boot option
     584    //
     585    if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, &BbsIndex)) {
     586      if (BootOptionVar!= NULL) {
     587        FreePool (BootOptionVar);
     588      }
     589      Index++;
     590      continue;
     591    }
     592
     593    if (BbsIndex < BbsCount) {
     594      //
     595      // Check if BBS Description String is changed
     596      //
     597      DescStringMatch = FALSE;
     598      BdsBuildLegacyDevNameString (
     599        &LocalBbsTable[BbsIndex],
     600        BbsIndex,
     601        sizeof (BootDesc),
     602        BootDesc
     603        );
     604
     605      if (StrCmp (BootDesc, (UINT16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) == 0) {
     606        DescStringMatch = TRUE;
     607      }
     608
     609      if (!((LocalBbsTable[BbsIndex].BootPriority == BBS_IGNORE_ENTRY) ||
     610            (LocalBbsTable[BbsIndex].BootPriority == BBS_DO_NOT_BOOT_FROM)) &&
     611          (LocalBbsTable[BbsIndex].DeviceType == BbsEntry->DeviceType) &&
     612          DescStringMatch) {
     613        Index++;
     614        continue;
     615      }
     616    }
     617
     618    if (BootOptionVar != NULL) {
     619      FreePool (BootOptionVar);
     620    }
     621    //
     622    // should delete
     623    //
     624    BdsDeleteBootOption (
     625      BootOrder[Index],
     626      BootOrder,
     627      &BootOrderSize
     628      );
     629  }
     630
     631  //
     632  // Adjust the number of boot options.
     633  //
     634  Status = gRT->SetVariable (
     635                  L"BootOrder",
     636                  &gEfiGlobalVariableGuid,
     637                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     638                  BootOrderSize,
     639                  BootOrder
     640                  );
     641  //
     642  // Shrinking variable with existing variable implementation shouldn't fail.
     643  //
     644  ASSERT_EFI_ERROR (Status);
     645  FreePool (BootOrder);
     646
     647  return Status;
     648}
     649
     650/**
     651  Find all legacy boot option by device type.
     652
     653  @param BootOrder       The boot order array.
     654  @param BootOptionNum   The number of boot option.
     655  @param DevType         Device type.
     656  @param DevName         Device name.
     657  @param Attribute       The boot option attribute.
     658  @param BbsIndex        The BBS table index.
     659  @param OptionNumber    The boot option index.
     660
     661  @retval TRUE           The Legacy boot option is found.
     662  @retval FALSE          The legacy boot option is not found.
     663
     664**/
     665BOOLEAN
     666BdsFindLegacyBootOptionByDevTypeAndName (
     667  IN UINT16                 *BootOrder,
     668  IN UINTN                  BootOptionNum,
     669  IN UINT16                 DevType,
     670  IN CHAR16                 *DevName,
     671  OUT UINT32                *Attribute,
     672  OUT UINT16                *BbsIndex,
     673  OUT UINT16                *OptionNumber
     674  )
     675{
     676  UINTN     Index;
     677  CHAR16    BootOption[9];
     678  UINTN     BootOptionSize;
     679  UINT8     *BootOptionVar;
     680  BBS_TABLE *BbsEntry;
     681  BOOLEAN   Found;
     682
     683  BbsEntry  = NULL;
     684  Found     = FALSE;
     685
     686  if (NULL == BootOrder) {
     687    return Found;
     688  }
     689
     690  //
     691  // Loop all boot option from variable
     692  //
     693  for (Index = 0; Index < BootOptionNum; Index++) {
     694    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", (UINTN) BootOrder[Index]);
     695    BootOptionVar = BdsLibGetVariableAndSize (
     696                      BootOption,
     697                      &gEfiGlobalVariableGuid,
     698                      &BootOptionSize
     699                      );
     700    if (NULL == BootOptionVar) {
     701      continue;
     702    }
     703
     704    //
     705    // Skip Non-legacy boot option
     706    //
     707    if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, BbsIndex)) {
     708      FreePool (BootOptionVar);
     709      continue;
     710    }
     711
     712    if (
     713        (BbsEntry->DeviceType != DevType) ||
     714        (StrCmp (DevName, (CHAR16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) != 0)
     715       ) {
     716      FreePool (BootOptionVar);
     717      continue;
     718    }
     719
     720    *Attribute    = *(UINT32 *) BootOptionVar;
     721    *OptionNumber = BootOrder[Index];
     722    Found         = TRUE;
     723    FreePool (BootOptionVar);
     724    break;
     725  }
     726
     727  return Found;
     728}
     729
     730/**
     731  Create a legacy boot option.
     732
     733  @param BbsItem         The BBS Table entry.
     734  @param Index           Index of the specified entry in BBS table.
     735  @param BootOrderList   The boot order list.
     736  @param BootOrderListSize The size of boot order list.
     737
     738  @retval EFI_OUT_OF_RESOURCE  No enough memory.
     739  @retval EFI_SUCCESS          The function complete successfully.
     740  @return Other value if the legacy boot option is not created.
     741
     742**/
     743EFI_STATUS
     744BdsCreateOneLegacyBootOption (
     745  IN BBS_TABLE              *BbsItem,
     746  IN UINTN                  Index,
     747  IN OUT UINT16             **BootOrderList,
     748  IN OUT UINTN              *BootOrderListSize
     749  )
     750{
     751  BBS_BBS_DEVICE_PATH       BbsDevPathNode;
     752  EFI_STATUS                Status;
     753  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
     754
     755  DevPath                       = NULL;
     756
     757  //
     758  // Create device path node.
     759  //
     760  BbsDevPathNode.Header.Type    = BBS_DEVICE_PATH;
     761  BbsDevPathNode.Header.SubType = BBS_BBS_DP;
     762  SetDevicePathNodeLength (&BbsDevPathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));
     763  BbsDevPathNode.DeviceType = BbsItem->DeviceType;
     764  CopyMem (&BbsDevPathNode.StatusFlag, &BbsItem->StatusFlags, sizeof (UINT16));
     765
     766  DevPath = AppendDevicePathNode (
     767              NULL,
     768              (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevPathNode
     769              );
     770  if (NULL == DevPath) {
     771    return EFI_OUT_OF_RESOURCES;
     772  }
     773
     774  Status = BdsCreateLegacyBootOption (
     775            BbsItem,
     776            DevPath,
     777            Index,
     778            BootOrderList,
     779            BootOrderListSize
     780            );
     781  BbsItem->BootPriority = 0x00;
     782
     783  FreePool (DevPath);
     784
     785  return Status;
     786}
     787
     788/**
     789  Add the legacy boot options from BBS table if they do not exist.
     790
     791  @retval EFI_SUCCESS          The boot options are added successfully
     792                               or they are already in boot options.
     793  @retval EFI_NOT_FOUND        No legacy boot options is found.
     794  @retval EFI_OUT_OF_RESOURCE  No enough memory.
     795  @return Other value          LegacyBoot options are not added.
     796**/
     797EFI_STATUS
     798EFIAPI
     799BdsAddNonExistingLegacyBootOptions (
     800  VOID
     801  )
     802{
     803  UINT16                    *BootOrder;
     804  UINTN                     BootOrderSize;
     805  EFI_STATUS                Status;
     806  CHAR16                    Desc[100];
     807  UINT16                    HddCount;
     808  UINT16                    BbsCount;
     809  HDD_INFO                  *LocalHddInfo;
     810  BBS_TABLE                 *LocalBbsTable;
     811  UINT16                    BbsIndex;
     812  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
     813  UINT16                    Index;
     814  UINT32                    Attribute;
     815  UINT16                    OptionNumber;
     816  BOOLEAN                   Exist;
     817
     818  HddCount      = 0;
     819  BbsCount      = 0;
     820  LocalHddInfo  = NULL;
     821  LocalBbsTable = NULL;
     822
     823  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
     824  if (EFI_ERROR (Status)) {
     825    return Status;
     826  }
     827
     828  LegacyBios->GetBbsInfo (
     829                LegacyBios,
     830                &HddCount,
     831                &LocalHddInfo,
     832                &BbsCount,
     833                &LocalBbsTable
     834                );
     835
     836  BootOrder = BdsLibGetVariableAndSize (
     837                L"BootOrder",
     838                &gEfiGlobalVariableGuid,
     839                &BootOrderSize
     840                );
     841  if (BootOrder == NULL) {
     842    BootOrderSize = 0;
     843  }
     844
     845  for (Index = 0; Index < BbsCount; Index++) {
     846    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
     847        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
     848        ) {
     849      continue;
     850    }
     851
     852    BdsBuildLegacyDevNameString (&LocalBbsTable[Index], Index, sizeof (Desc), Desc);
     853
     854    Exist = BdsFindLegacyBootOptionByDevTypeAndName (
     855              BootOrder,
     856              BootOrderSize / sizeof (UINT16),
     857              LocalBbsTable[Index].DeviceType,
     858              Desc,
     859              &Attribute,
     860              &BbsIndex,
     861              &OptionNumber
     862              );
     863    if (!Exist) {
     864      //
     865      // Not found such type of legacy device in boot options or we found but it's disabled
     866      // so we have to create one and put it to the tail of boot order list
     867      //
     868      Status = BdsCreateOneLegacyBootOption (
     869                &LocalBbsTable[Index],
     870                Index,
     871                &BootOrder,
     872                &BootOrderSize
     873                );
     874      if (!EFI_ERROR (Status)) {
     875        ASSERT (BootOrder != NULL);
     876        BbsIndex     = Index;
     877        OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
     878      }
     879    }
     880
     881    ASSERT (BbsIndex == Index);
     882  }
     883
     884  Status = gRT->SetVariable (
     885                  L"BootOrder",
     886                  &gEfiGlobalVariableGuid,
     887                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     888                  BootOrderSize,
     889                  BootOrder
     890                  );
     891  if (BootOrder != NULL) {
     892    FreePool (BootOrder);
     893  }
     894
     895  return Status;
     896}
     897
     898/**
     899  Fill the device order buffer.
     900
     901  @param BbsTable        The BBS table.
     902  @param BbsType         The BBS Type.
     903  @param BbsCount        The BBS Count.
     904  @param Buf             device order buffer.
     905
     906  @return The device order buffer.
     907
     908**/
     909UINT16 *
     910BdsFillDevOrderBuf (
     911  IN BBS_TABLE                    *BbsTable,
     912  IN BBS_TYPE                     BbsType,
     913  IN UINTN                        BbsCount,
     914  OUT UINT16                      *Buf
     915  )
     916{
     917  UINTN Index;
     918
     919  for (Index = 0; Index < BbsCount; Index++) {
     920    if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {
     921      continue;
     922    }
     923
     924    if (BbsTable[Index].DeviceType != BbsType) {
     925      continue;
     926    }
     927
     928    *Buf = (UINT16) (Index & 0xFF);
     929    Buf++;
     930  }
     931
     932  return Buf;
     933}
     934
     935/**
     936  Create the device order buffer.
     937
     938  @param BbsTable        The BBS table.
     939  @param BbsCount        The BBS Count.
     940
     941  @retval EFI_SUCCES             The buffer is created and the EFI variable named
     942                                 VAR_LEGACY_DEV_ORDER and gEfiLegacyDevOrderVariableGuid is
     943                                 set correctly.
     944  @retval EFI_OUT_OF_RESOURCES   Memmory or storage is not enough.
     945  @retval EFI_DEVICE_ERROR       Fail to add the device order into EFI variable fail
     946                                 because of hardware error.
     947**/
     948EFI_STATUS
     949BdsCreateDevOrder (
     950  IN BBS_TABLE                  *BbsTable,
     951  IN UINT16                     BbsCount
     952  )
     953{
     954  UINTN                       Index;
     955  UINTN                       FDCount;
     956  UINTN                       HDCount;
     957  UINTN                       CDCount;
     958  UINTN                       NETCount;
     959  UINTN                       BEVCount;
     960  UINTN                       TotalSize;
     961  UINTN                       HeaderSize;
     962  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
     963  LEGACY_DEV_ORDER_ENTRY      *DevOrderPtr;
     964  EFI_STATUS                  Status;
     965
     966  FDCount     = 0;
     967  HDCount     = 0;
     968  CDCount     = 0;
     969  NETCount    = 0;
     970  BEVCount    = 0;
     971  TotalSize   = 0;
     972  HeaderSize  = sizeof (BBS_TYPE) + sizeof (UINT16);
     973  DevOrder    = NULL;
     974  Status      = EFI_SUCCESS;
     975
     976  //
     977  // Count all boot devices
     978  //
     979  for (Index = 0; Index < BbsCount; Index++) {
     980    if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {
     981      continue;
     982    }
     983
     984    switch (BbsTable[Index].DeviceType) {
     985    case BBS_FLOPPY:
     986      FDCount++;
     987      break;
     988
     989    case BBS_HARDDISK:
     990      HDCount++;
     991      break;
     992
     993    case BBS_CDROM:
     994      CDCount++;
     995      break;
     996
     997    case BBS_EMBED_NETWORK:
     998      NETCount++;
     999      break;
     1000
     1001    case BBS_BEV_DEVICE:
     1002      BEVCount++;
     1003      break;
     1004
     1005    default:
     1006      break;
     1007    }
     1008  }
     1009
     1010  TotalSize += (HeaderSize + sizeof (UINT16) * FDCount);
     1011  TotalSize += (HeaderSize + sizeof (UINT16) * HDCount);
     1012  TotalSize += (HeaderSize + sizeof (UINT16) * CDCount);
     1013  TotalSize += (HeaderSize + sizeof (UINT16) * NETCount);
     1014  TotalSize += (HeaderSize + sizeof (UINT16) * BEVCount);
     1015
     1016  //
     1017  // Create buffer to hold all boot device order
     1018  //
     1019  DevOrder = AllocateZeroPool (TotalSize);
     1020  if (NULL == DevOrder) {
     1021    return EFI_OUT_OF_RESOURCES;
     1022  }
     1023  DevOrderPtr          = DevOrder;
     1024
     1025  DevOrderPtr->BbsType = BBS_FLOPPY;
     1026  DevOrderPtr->Length  = (UINT16) (sizeof (DevOrderPtr->Length) + FDCount * sizeof (UINT16));
     1027  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_FLOPPY, BbsCount, DevOrderPtr->Data);
     1028
     1029  DevOrderPtr->BbsType = BBS_HARDDISK;
     1030  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));
     1031  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_HARDDISK, BbsCount, DevOrderPtr->Data);
     1032 
     1033  DevOrderPtr->BbsType = BBS_CDROM;
     1034  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));
     1035  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_CDROM, BbsCount, DevOrderPtr->Data);
     1036 
     1037  DevOrderPtr->BbsType = BBS_EMBED_NETWORK;
     1038  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));
     1039  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_EMBED_NETWORK, BbsCount, DevOrderPtr->Data);
     1040
     1041  DevOrderPtr->BbsType = BBS_BEV_DEVICE;
     1042  DevOrderPtr->Length  = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));
     1043  DevOrderPtr          = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_BEV_DEVICE, BbsCount, DevOrderPtr->Data);
     1044
     1045  ASSERT (TotalSize == (UINTN) ((UINT8 *) DevOrderPtr - (UINT8 *) DevOrder));
     1046
     1047  //
     1048  // Save device order for legacy boot device to variable.
     1049  //
     1050  Status = gRT->SetVariable (
     1051                  VAR_LEGACY_DEV_ORDER,
     1052                  &gEfiLegacyDevOrderVariableGuid,
     1053                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     1054                  TotalSize,
     1055                  DevOrder
     1056                  );
     1057  FreePool (DevOrder);
     1058
     1059  return Status;
     1060}
     1061
     1062/**
     1063  Add the legacy boot devices from BBS table into
     1064  the legacy device boot order.
     1065
     1066  @retval EFI_SUCCESS           The boot devices are added successfully.
     1067  @retval EFI_NOT_FOUND         The legacy boot devices are not found.
     1068  @retval EFI_OUT_OF_RESOURCES  Memmory or storage is not enough.
     1069  @retval EFI_DEVICE_ERROR      Fail to add the legacy device boot order into EFI variable
     1070                                because of hardware error.
     1071**/
     1072EFI_STATUS
     1073EFIAPI
     1074BdsUpdateLegacyDevOrder (
     1075  VOID
     1076  )
     1077{
     1078  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
     1079  LEGACY_DEV_ORDER_ENTRY      *NewDevOrder;
     1080  LEGACY_DEV_ORDER_ENTRY      *Ptr;
     1081  LEGACY_DEV_ORDER_ENTRY      *NewPtr;
     1082  UINTN                       DevOrderSize;
     1083  EFI_LEGACY_BIOS_PROTOCOL    *LegacyBios;
     1084  EFI_STATUS                  Status;
     1085  UINT16                      HddCount;
     1086  UINT16                      BbsCount;
     1087  HDD_INFO                    *LocalHddInfo;
     1088  BBS_TABLE                   *LocalBbsTable;
     1089  UINTN                       Index;
     1090  UINTN                       Index2;
     1091  UINTN                       *Idx;
     1092  UINTN                       FDCount;
     1093  UINTN                       HDCount;
     1094  UINTN                       CDCount;
     1095  UINTN                       NETCount;
     1096  UINTN                       BEVCount;
     1097  UINTN                       TotalSize;
     1098  UINTN                       HeaderSize;
     1099  UINT16                      *NewFDPtr;
     1100  UINT16                      *NewHDPtr;
     1101  UINT16                      *NewCDPtr;
     1102  UINT16                      *NewNETPtr;
     1103  UINT16                      *NewBEVPtr;
     1104  UINT16                      *NewDevPtr;
     1105  UINTN                       FDIndex;
     1106  UINTN                       HDIndex;
     1107  UINTN                       CDIndex;
     1108  UINTN                       NETIndex;
     1109  UINTN                       BEVIndex;
     1110
     1111  Idx           = NULL;
     1112  FDCount       = 0;
     1113  HDCount       = 0;
     1114  CDCount       = 0;
     1115  NETCount      = 0;
     1116  BEVCount      = 0;
     1117  TotalSize     = 0;
     1118  HeaderSize    = sizeof (BBS_TYPE) + sizeof (UINT16);
     1119  FDIndex       = 0;
     1120  HDIndex       = 0;
     1121  CDIndex       = 0;
     1122  NETIndex      = 0;
     1123  BEVIndex      = 0;
     1124  NewDevPtr     = NULL;
     1125
     1126  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
     1127  if (EFI_ERROR (Status)) {
     1128    return Status;
     1129  }
     1130
     1131  Status = LegacyBios->GetBbsInfo (
     1132                         LegacyBios,
     1133                         &HddCount,
     1134                         &LocalHddInfo,
     1135                         &BbsCount,
     1136                         &LocalBbsTable
     1137                         );
     1138  if (EFI_ERROR (Status)) {
     1139    return Status;
     1140  }
     1141
     1142  DevOrder = BdsLibGetVariableAndSize (
     1143               VAR_LEGACY_DEV_ORDER,
     1144               &gEfiLegacyDevOrderVariableGuid,
     1145               &DevOrderSize
     1146               );
     1147  if (NULL == DevOrder) {
     1148    return BdsCreateDevOrder (LocalBbsTable, BbsCount);
     1149  }
     1150  //
     1151  // First we figure out how many boot devices with same device type respectively
     1152  //
     1153  for (Index = 0; Index < BbsCount; Index++) {
     1154    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
     1155        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
     1156        ) {
     1157      continue;
     1158    }
     1159
     1160    switch (LocalBbsTable[Index].DeviceType) {
     1161    case BBS_FLOPPY:
     1162      FDCount++;
     1163      break;
     1164
     1165    case BBS_HARDDISK:
     1166      HDCount++;
     1167      break;
     1168
     1169    case BBS_CDROM:
     1170      CDCount++;
     1171      break;
     1172
     1173    case BBS_EMBED_NETWORK:
     1174      NETCount++;
     1175      break;
     1176
     1177    case BBS_BEV_DEVICE:
     1178      BEVCount++;
     1179      break;
     1180
     1181    default:
     1182      break;
     1183    }
     1184  }
     1185
     1186  TotalSize += (HeaderSize + FDCount * sizeof (UINT16));
     1187  TotalSize += (HeaderSize + HDCount * sizeof (UINT16));
     1188  TotalSize += (HeaderSize + CDCount * sizeof (UINT16));
     1189  TotalSize += (HeaderSize + NETCount * sizeof (UINT16));
     1190  TotalSize += (HeaderSize + BEVCount * sizeof (UINT16));
     1191
     1192  NewDevOrder = AllocateZeroPool (TotalSize);
     1193  if (NULL == NewDevOrder) {
     1194    return EFI_OUT_OF_RESOURCES;
     1195  }
     1196
     1197
     1198
     1199  //
     1200  // copy FD
     1201  //
     1202  Ptr             = DevOrder;
     1203  NewPtr          = NewDevOrder;
     1204  NewPtr->BbsType = Ptr->BbsType;
     1205  NewPtr->Length  = (UINT16) (sizeof (UINT16) + FDCount * sizeof (UINT16));
     1206  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
     1207    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
     1208        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
     1209        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_FLOPPY
     1210        ) {
     1211      continue;
     1212    }
     1213
     1214    NewPtr->Data[FDIndex] = Ptr->Data[Index];
     1215    FDIndex++;
     1216  }
     1217  NewFDPtr = NewPtr->Data;
     1218
     1219  //
     1220  // copy HD
     1221  //
     1222  Ptr             = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
     1223  NewPtr          = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
     1224  NewPtr->BbsType = Ptr->BbsType;
     1225  NewPtr->Length  = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));
     1226  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
     1227    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
     1228        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
     1229        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
     1230        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_HARDDISK
     1231        ) {
     1232      continue;
     1233    }
     1234
     1235    NewPtr->Data[HDIndex] = Ptr->Data[Index];
     1236    HDIndex++;
     1237  }
     1238  NewHDPtr = NewPtr->Data;
     1239
     1240  //
     1241  // copy CD
     1242  //
     1243  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
     1244  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
     1245  NewPtr->BbsType = Ptr->BbsType;
     1246  NewPtr->Length  = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));
     1247  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
     1248    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
     1249        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
     1250        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
     1251        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_CDROM
     1252        ) {
     1253      continue;
     1254    }
     1255
     1256    NewPtr->Data[CDIndex] = Ptr->Data[Index];
     1257    CDIndex++;
     1258  }
     1259  NewCDPtr = NewPtr->Data;
     1260
     1261  //
     1262  // copy NET
     1263  //
     1264  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
     1265  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
     1266  NewPtr->BbsType = Ptr->BbsType;
     1267  NewPtr->Length  = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));
     1268  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
     1269    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
     1270        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
     1271        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
     1272        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_EMBED_NETWORK
     1273        ) {
     1274      continue;
     1275    }
     1276
     1277    NewPtr->Data[NETIndex] = Ptr->Data[Index];
     1278    NETIndex++;
     1279  }
     1280  NewNETPtr = NewPtr->Data;
     1281 
     1282  //
     1283  // copy BEV
     1284  //
     1285  Ptr    = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);
     1286  NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);
     1287  NewPtr->BbsType = Ptr->BbsType;
     1288  NewPtr->Length  = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));
     1289  for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {
     1290    if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||
     1291        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||
     1292        LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||
     1293        LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_BEV_DEVICE
     1294        ) {
     1295      continue;
     1296    }
     1297
     1298    NewPtr->Data[BEVIndex] = Ptr->Data[Index];
     1299    BEVIndex++;
     1300  }
     1301  NewBEVPtr = NewPtr->Data;
     1302
     1303  for (Index = 0; Index < BbsCount; Index++) {
     1304    if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||
     1305        (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)
     1306        ) {
     1307      continue;
     1308    }
     1309
     1310    switch (LocalBbsTable[Index].DeviceType) {
     1311    case BBS_FLOPPY:
     1312      Idx       = &FDIndex;
     1313      NewDevPtr = NewFDPtr;
     1314      break;
     1315
     1316    case BBS_HARDDISK:
     1317      Idx       = &HDIndex;
     1318      NewDevPtr = NewHDPtr;
     1319      break;
     1320
     1321    case BBS_CDROM:
     1322      Idx       = &CDIndex;
     1323      NewDevPtr = NewCDPtr;
     1324      break;
     1325
     1326    case BBS_EMBED_NETWORK:
     1327      Idx       = &NETIndex;
     1328      NewDevPtr = NewNETPtr;
     1329      break;
     1330
     1331    case BBS_BEV_DEVICE:
     1332      Idx       = &BEVIndex;
     1333      NewDevPtr = NewBEVPtr;
     1334      break;
     1335
     1336    default:
     1337      Idx = NULL;
     1338      break;
     1339    }
     1340    //
     1341    // at this point we have copied those valid indexes to new buffer
     1342    // and we should check if there is any new appeared boot device
     1343    //
     1344    if (Idx != NULL) {
     1345      for (Index2 = 0; Index2 < *Idx; Index2++) {
     1346        if ((NewDevPtr[Index2] & 0xFF) == (UINT16) Index) {
     1347          break;
     1348        }
     1349      }
     1350
     1351      if (Index2 == *Idx) {
     1352        //
     1353        // Index2 == *Idx means we didn't find Index
     1354        // so Index is a new appeared device's index in BBS table
     1355        // insert it before disabled indexes.
     1356        //
     1357        for (Index2 = 0; Index2 < *Idx; Index2++) {
     1358          if ((NewDevPtr[Index2] & 0xFF00) == 0xFF00) {
     1359            break;
     1360          }
     1361        }
     1362        CopyMem (&NewDevPtr[Index2 + 1], &NewDevPtr[Index2], (*Idx - Index2) * sizeof (UINT16));
     1363        NewDevPtr[Index2] = (UINT16) (Index & 0xFF);
     1364        (*Idx)++;
     1365      }
     1366    }
     1367  }
     1368
     1369  FreePool (DevOrder);
     1370
     1371  Status = gRT->SetVariable (
     1372                  VAR_LEGACY_DEV_ORDER,
     1373                  &gEfiLegacyDevOrderVariableGuid,
     1374                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     1375                  TotalSize,
     1376                  NewDevOrder
     1377                  );
     1378  FreePool (NewDevOrder);
     1379
     1380  return Status;
     1381}
     1382
     1383/**
     1384  Set Boot Priority for specified device type.
     1385
     1386  @param DeviceType      The device type.
     1387  @param BbsIndex        The BBS index to set the highest priority. Ignore when -1.
     1388  @param LocalBbsTable   The BBS table.
     1389  @param Priority        The prority table.
     1390
     1391  @retval EFI_SUCCESS           The function completes successfully.
     1392  @retval EFI_NOT_FOUND         Failed to find device.
     1393  @retval EFI_OUT_OF_RESOURCES  Failed to get the efi variable of device order.
     1394
     1395**/
     1396EFI_STATUS
     1397BdsSetBootPriority4SameTypeDev (
     1398  IN UINT16                                              DeviceType,
     1399  IN UINTN                                               BbsIndex,
     1400  IN OUT BBS_TABLE                                       *LocalBbsTable,
     1401  IN OUT UINT16                                          *Priority
     1402  )
     1403{
     1404  LEGACY_DEV_ORDER_ENTRY      *DevOrder;
     1405  LEGACY_DEV_ORDER_ENTRY      *DevOrderPtr;
     1406  UINTN                       DevOrderSize;
     1407  UINTN                       Index;
     1408
     1409  DevOrder = BdsLibGetVariableAndSize (
     1410               VAR_LEGACY_DEV_ORDER,
     1411               &gEfiLegacyDevOrderVariableGuid,
     1412               &DevOrderSize
     1413               );
     1414  if (NULL == DevOrder) {
     1415    return EFI_OUT_OF_RESOURCES;
     1416  }
     1417
     1418  DevOrderPtr = DevOrder;
     1419  while ((UINT8 *) DevOrderPtr < (UINT8 *) DevOrder + DevOrderSize) {
     1420    if (DevOrderPtr->BbsType == DeviceType) {
     1421      break;
     1422    }
     1423
     1424    DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) ((UINTN) DevOrderPtr + sizeof (BBS_TYPE) + DevOrderPtr->Length);
     1425  }
     1426
     1427  if ((UINT8 *) DevOrderPtr >= (UINT8 *) DevOrder + DevOrderSize) {
     1428    FreePool (DevOrder);
     1429    return EFI_NOT_FOUND;
     1430  }
     1431
     1432  if (BbsIndex != (UINTN) -1) {
     1433    LocalBbsTable[BbsIndex].BootPriority = *Priority;
     1434    (*Priority)++;
     1435  }
     1436  //
     1437  // If the high byte of the DevIndex is 0xFF, it indicates that this device has been disabled.
     1438  //
     1439  for (Index = 0; Index < DevOrderPtr->Length / sizeof (UINT16) - 1; Index++) {
     1440    if ((DevOrderPtr->Data[Index] & 0xFF00) == 0xFF00) {
     1441      //
     1442      // LocalBbsTable[DevIndex[Index] & 0xFF].BootPriority = BBS_DISABLED_ENTRY;
     1443      //
     1444    } else if (DevOrderPtr->Data[Index] != BbsIndex) {
     1445      LocalBbsTable[DevOrderPtr->Data[Index]].BootPriority = *Priority;
     1446      (*Priority)++;
     1447    }
     1448  }
     1449
     1450  FreePool (DevOrder);
     1451  return EFI_SUCCESS;
     1452}
     1453
     1454/**
     1455  Print the BBS Table.
     1456
     1457  @param LocalBbsTable   The BBS table.
     1458  @param BbsCount        The count of entry in BBS table.
     1459**/
     1460VOID
     1461PrintBbsTable (
     1462  IN BBS_TABLE  *LocalBbsTable,
     1463  IN UINT16     BbsCount
     1464  )
     1465{
     1466  UINT16  Idx;
     1467
     1468  DEBUG ((DEBUG_ERROR, "\n"));
     1469  DEBUG ((DEBUG_ERROR, " NO  Prio bb/dd/ff cl/sc Type Stat segm:offs\n"));
     1470  DEBUG ((DEBUG_ERROR, "=============================================\n"));
     1471  for (Idx = 0; Idx < BbsCount; Idx++) {
     1472    if ((LocalBbsTable[Idx].BootPriority == BBS_IGNORE_ENTRY) ||
     1473        (LocalBbsTable[Idx].BootPriority == BBS_DO_NOT_BOOT_FROM) ||
     1474        (LocalBbsTable[Idx].BootPriority == BBS_LOWEST_PRIORITY)
     1475        ) {
     1476      continue;
     1477    }
     1478
     1479    DEBUG (
     1480      (DEBUG_ERROR,
     1481      " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
     1482      (UINTN) Idx,
     1483      (UINTN) LocalBbsTable[Idx].BootPriority,
     1484      (UINTN) LocalBbsTable[Idx].Bus,
     1485      (UINTN) LocalBbsTable[Idx].Device,
     1486      (UINTN) LocalBbsTable[Idx].Function,
     1487      (UINTN) LocalBbsTable[Idx].Class,
     1488      (UINTN) LocalBbsTable[Idx].SubClass,
     1489      (UINTN) LocalBbsTable[Idx].DeviceType,
     1490      (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,
     1491      (UINTN) LocalBbsTable[Idx].BootHandlerSegment,
     1492      (UINTN) LocalBbsTable[Idx].BootHandlerOffset,
     1493      (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),
     1494      (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset))
     1495      );
     1496  }
     1497
     1498  DEBUG ((DEBUG_ERROR, "\n"));
     1499}
     1500
     1501/**
     1502  Set the boot priority for BBS entries based on boot option entry and boot order.
     1503
     1504  @param  Entry             The boot option is to be checked for refresh BBS table.
     1505 
     1506  @retval EFI_SUCCESS           The boot priority for BBS entries is refreshed successfully.
     1507  @retval EFI_NOT_FOUND         BBS entries can't be found.
     1508  @retval EFI_OUT_OF_RESOURCES  Failed to get the legacy device boot order.
     1509**/
     1510EFI_STATUS
     1511EFIAPI
     1512BdsRefreshBbsTableForBoot (
     1513  IN BDS_COMMON_OPTION        *Entry
     1514  )
     1515{
     1516  EFI_STATUS                Status;
     1517  UINT16                    BbsIndex;
     1518  UINT16                    HddCount;
     1519  UINT16                    BbsCount;
     1520  HDD_INFO                  *LocalHddInfo;
     1521  BBS_TABLE                 *LocalBbsTable;
     1522  UINT16                    DevType;
     1523  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
     1524  UINTN                     Index;
     1525  UINT16                    Priority;
     1526  UINT16                    *BootOrder;
     1527  UINTN                     BootOrderSize;
     1528  UINT8                     *BootOptionVar;
     1529  UINTN                     BootOptionSize;
     1530  CHAR16                    BootOption[9];
     1531  UINT8                     *Ptr;
     1532  UINT16                    DevPathLen;
     1533  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
     1534  UINT16                    *DeviceType;
     1535  UINTN                     DeviceTypeCount;
     1536  UINTN                     DeviceTypeIndex;
     1537
     1538  HddCount      = 0;
     1539  BbsCount      = 0;
     1540  LocalHddInfo  = NULL;
     1541  LocalBbsTable = NULL;
     1542  DevType       = BBS_UNKNOWN;
     1543
     1544  Status        = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
     1545  if (EFI_ERROR (Status)) {
     1546    return Status;
     1547  }
     1548
     1549  LegacyBios->GetBbsInfo (
     1550                LegacyBios,
     1551                &HddCount,
     1552                &LocalHddInfo,
     1553                &BbsCount,
     1554                &LocalBbsTable
     1555                );
     1556  //
     1557  // First, set all the present devices' boot priority to BBS_UNPRIORITIZED_ENTRY
     1558  // We will set them according to the settings setup by user
     1559  //
     1560  for (Index = 0; Index < BbsCount; Index++) {
     1561    if (!((BBS_IGNORE_ENTRY == LocalBbsTable[Index].BootPriority) ||
     1562        (BBS_DO_NOT_BOOT_FROM == LocalBbsTable[Index].BootPriority) ||
     1563         (BBS_LOWEST_PRIORITY == LocalBbsTable[Index].BootPriority))) {
     1564      LocalBbsTable[Index].BootPriority = BBS_UNPRIORITIZED_ENTRY;
     1565    }
     1566  }
     1567  //
     1568  // boot priority always starts at 0
     1569  //
     1570  Priority = 0;
     1571  if (Entry->LoadOptionsSize == sizeof (BBS_TABLE) + sizeof (UINT16)) {
     1572    //
     1573    // If Entry stands for a legacy boot option, we prioritize the devices with the same type first.
     1574    //
     1575    DevType  = ((BBS_TABLE *) Entry->LoadOptions)->DeviceType;
     1576    BbsIndex = *(UINT16 *) ((BBS_TABLE *) Entry->LoadOptions + 1);
     1577    Status = BdsSetBootPriority4SameTypeDev (
     1578              DevType,
     1579              BbsIndex,
     1580              LocalBbsTable,
     1581              &Priority
     1582              );
     1583    if (EFI_ERROR (Status)) {
     1584      return Status;
     1585    }
     1586  }
     1587  //
     1588  // we have to set the boot priority for other BBS entries with different device types
     1589  //
     1590  BootOrder = BdsLibGetVariableAndSize (
     1591                L"BootOrder",
     1592                &gEfiGlobalVariableGuid,
     1593                &BootOrderSize
     1594                );
     1595  DeviceType = AllocatePool (BootOrderSize + sizeof (UINT16));
     1596  ASSERT (DeviceType != NULL);
     1597
     1598  DeviceType[0]   = DevType;
     1599  DeviceTypeCount = 1;
     1600  for (Index = 0; ((BootOrder != NULL) && (Index < BootOrderSize / sizeof (UINT16))); Index++) {
     1601    UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
     1602    BootOptionVar = BdsLibGetVariableAndSize (
     1603                      BootOption,
     1604                      &gEfiGlobalVariableGuid,
     1605                      &BootOptionSize
     1606                      );
     1607    if (NULL == BootOptionVar) {
     1608      continue;
     1609    }
     1610
     1611    Ptr = BootOptionVar;
     1612
     1613    Ptr += sizeof (UINT32);
     1614    DevPathLen = *(UINT16 *) Ptr;
     1615    Ptr += sizeof (UINT16);
     1616    Ptr += StrSize ((UINT16 *) Ptr);
     1617    DevPath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
     1618    if (BBS_DEVICE_PATH != DevPath->Type || BBS_BBS_DP != DevPath->SubType) {
     1619      FreePool (BootOptionVar);
     1620      continue;
     1621    }
     1622
     1623    Ptr += DevPathLen;
     1624    DevType = ((BBS_TABLE *) Ptr)->DeviceType;
     1625    for (DeviceTypeIndex = 0; DeviceTypeIndex < DeviceTypeCount; DeviceTypeIndex++) {
     1626      if (DeviceType[DeviceTypeIndex] == DevType) {
     1627        break;
     1628      }
     1629    }
     1630    if (DeviceTypeIndex < DeviceTypeCount) {
     1631      //
     1632      // We don't want to process twice for a device type
     1633      //
     1634      FreePool (BootOptionVar);
     1635      continue;
     1636    }
     1637
     1638    DeviceType[DeviceTypeCount] = DevType;
     1639    DeviceTypeCount++;
     1640
     1641    Status = BdsSetBootPriority4SameTypeDev (
     1642              DevType,
     1643              (UINTN) -1,
     1644              LocalBbsTable,
     1645              &Priority
     1646              );
     1647    FreePool (BootOptionVar);
     1648    if (EFI_ERROR (Status)) {
     1649      break;
     1650    }
     1651  }
     1652
     1653  FreePool (DeviceType);
     1654
     1655  if (BootOrder != NULL) {
     1656    FreePool (BootOrder);
     1657  }
     1658
     1659  DEBUG_CODE_BEGIN();
     1660    PrintBbsTable (LocalBbsTable, BbsCount);
     1661  DEBUG_CODE_END();
     1662
     1663  return Status;
     1664}
    621665
    631666/**
     
    781681  EFI_STATUS                Status;
    791682  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
     1683  EFI_EVENT                 LegacyBootEvent;
    801684
    811685  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
     
    951699  //
    961700  PERF_CODE (
    97     WriteBootToOsPerformanceData ();
     1701    //
     1702    // Create an event to be signalled when Legacy Boot occurs to write performance data.
     1703    //
     1704    Status = EfiCreateEventLegacyBootEx(
     1705               TPL_NOTIFY,
     1706               WriteBootToOsPerformanceData,
     1707               NULL,
     1708               &LegacyBootEvent
     1709               );
     1710    ASSERT_EFI_ERROR (Status);
    981711  );
    991712
     
    6582271  EFI_BOOT_LOGO_PROTOCOL    *BootLogo;
    6592272
    660   //
    661   // Record the performance data for End of BDS
    662   //
    663   PERF_END(NULL, "BDS", NULL, 0);
    664 
     2273#ifdef VBOX
    6652274  VBoxLog(("BdsLibBootViaBootOption: BootCurrent=0x%x OptionName=%s Description=%s StatusString=%s Attribute=0x%x LoadOptionsSize=0x%x\n",
    6662275           Option->BootCurrent, Option->OptionName, Option->Description, Option->StatusString, Option->Attribute, Option->LoadOptionsSize));
     2276#endif
    6672277
    6682278  *ExitDataSize = 0;
     
    7022312    // Only create the BootCurrent variable when it points to a valid Boot#### variable.
    7032313    //
    704     gRT->SetVariable (
     2314    SetVariableAndReportStatusCodeOnError (
    7052315          L"BootCurrent",
    7062316          &gEfiGlobalVariableGuid,
     
    7102320          );
    7112321  }
     2322
     2323  //
     2324  // Report Status Code to indicate ReadyToBoot event will be signalled
     2325  //
     2326  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
    7122327
    7132328  //
     
    8032418      Handle = BdsLibGetBootableHandle(DevicePath);
    8042419      VBoxLogFlowFuncMarkVar(Handle, "%p");
    805       if (Handle == NULL) {
    806         goto Done;
    807       }
     2420      if (Handle != NULL) {
    8082421#ifdef VBOX /* We have more options to try out because of apple. */
    8092422      //
     
    8132426      if (Option->LoadOptionsSize) {
    8142427        /*
    815          * First, see the there is a config=folder in the load options.  We
    816          * interpret it as a path to the folder containing boot.efi and go
    817          * about constructing the path in a bit of a round about way...
    818          *
    819          * This is what we got when Lion rebooted after the first installation stage:
    820          *   Variable - fAttr=0x07 - '8be4df61-93ca-11d2-aa0d-00e098032b8c:Boot0080' - cb=0xbe
    821          *   0000: 01 00 00 00 48 00 4d 00-61 00 63 00 20 00 4f 00 ....H.M.a.c. .O.
    822          *   0010: 53 00 20 00 58 00 00 00-02 01 0c 00 d0 41 03 0a S. .X........A..
    823          *   0020: 00 00 00 00 01 01 06 00-02 1f 03 01 08 00 00 01 ................
    824          *   0030: 00 00 04 01 2a 00 02 00-00 00 28 40 06 00 00 00 ....*.....(@....
    825          *   0040: 00 00 b0 bf 75 02 00 00-00 00 e5 b2 19 a7 cb 59 ....u..........Y
    826          *   0050: 69 4c b9 92 51 3c fd 4b-d7 c4 02 02 7f ff 04 00 iL..Q<.K........
    827          *   0060: 63 00 6f 00 6e 00 66 00-69 00 67 00 3d 00 22 00 c.o.n.f.i.g.=.".
    828          *   0070: 5c 00 4d 00 61 00 63 00-20 00 4f 00 53 00 20 00 \.M.a.c. .O.S. .
    829          *   0080: 58 00 20 00 49 00 6e 00-73 00 74 00 61 00 6c 00 X. .I.n.s.t.a.l.
    830          *   0090: 6c 00 20 00 44 00 61 00-74 00 61 00 5c 00 63 00 l. .D.a.t.a.\.c.
    831          *   00a0: 6f 00 6d 00 2e 00 61 00-70 00 70 00 6c 00 65 00 o.m...a.p.p.l.e.
    832          *   00b0: 2e 00 42 00 6f 00 6f 00-74 00 22 00 00 00       ..B.o.o.t."...
    833          *
    834          * This is waht we got when Moutain Kitten reboot after the first installation stage:
    835          * Variable - fAttr=0x07 - '8be4df61-93ca-11d2-aa0d-00e098032b8c:Boot0080' - cb=0xb6
    836          *   0000: 01 00 00 00 48 00 4d 00-61 00 63 00 20 00 4f 00 ....H.M.a.c. .O.
    837          *   0010: 53 00 20 00 58 00 00 00-02 01 0c 00 d0 41 03 0a S. .X........A..
    838          *   0020: 00 00 00 00 01 01 06 00-02 1f 03 01 08 00 00 01 ................
    839          *   0030: 00 00 04 01 2a 00 02 00-00 00 28 40 06 00 00 00 ....*.....(@....
    840          *   0040: 00 00 98 b5 53 02 00 00-00 00 a5 9a 97 b7 33 60 ....S.........3`
    841          *   0050: 2d 47 bf 1a fa 14 fe c5-f2 b8 02 02 7f ff 04 00 -G..............
    842          *   0060: 63 00 6f 00 6e 00 66 00-69 00 67 00 3d 00 22 00 c.o.n.f.i.g.=.".
    843          *   0070: 5c 00 4f 00 53 00 20 00-58 00 20 00 49 00 6e 00 \.O.S. .X. .I.n.
    844          *   0080: 73 00 74 00 61 00 6c 00-6c 00 20 00 44 00 61 00 s.t.a.l.l. .D.a.
    845          *   0090: 74 00 61 00 5c 00 63 00-6f 00 6d 00 2e 00 61 00 t.a.\.c.o.m...a.
    846          *   00a0: 70 00 70 00 6c 00 65 00-2e 00 42 00 6f 00 6f 00 p.p.l.e...B.o.o.
    847          *   00b0: 74 00 22 00 00 00                               t."...
    848          */
    849         VBoxLogFlowFuncMarkVar(Option->LoadOptions, "%s");
     2428           * First, see the there is a config=folder in the load options.  We
     2429           * interpret it as a path to the folder containing boot.efi and go
     2430           * about constructing the path in a bit of a round about way...
     2431           *
     2432           * This is what we got when Lion rebooted after the first installation stage:
     2433           *   Variable - fAttr=0x07 - '8be4df61-93ca-11d2-aa0d-00e098032b8c:Boot0080' - cb=0xbe
     2434           *   0000: 01 00 00 00 48 00 4d 00-61 00 63 00 20 00 4f 00 ....H.M.a.c. .O.
     2435           *   0010: 53 00 20 00 58 00 00 00-02 01 0c 00 d0 41 03 0a S. .X........A..
     2436           *   0020: 00 00 00 00 01 01 06 00-02 1f 03 01 08 00 00 01 ................
     2437           *   0030: 00 00 04 01 2a 00 02 00-00 00 28 40 06 00 00 00 ....*.....(@....
     2438           *   0040: 00 00 b0 bf 75 02 00 00-00 00 e5 b2 19 a7 cb 59 ....u..........Y
     2439           *   0050: 69 4c b9 92 51 3c fd 4b-d7 c4 02 02 7f ff 04 00 iL..Q<.K........
     2440           *   0060: 63 00 6f 00 6e 00 66 00-69 00 67 00 3d 00 22 00 c.o.n.f.i.g.=.".
     2441           *   0070: 5c 00 4d 00 61 00 63 00-20 00 4f 00 53 00 20 00 \.M.a.c. .O.S. .
     2442           *   0080: 58 00 20 00 49 00 6e 00-73 00 74 00 61 00 6c 00 X. .I.n.s.t.a.l.
     2443           *   0090: 6c 00 20 00 44 00 61 00-74 00 61 00 5c 00 63 00 l. .D.a.t.a.\.c.
     2444           *   00a0: 6f 00 6d 00 2e 00 61 00-70 00 70 00 6c 00 65 00 o.m...a.p.p.l.e.
     2445           *   00b0: 2e 00 42 00 6f 00 6f 00-74 00 22 00 00 00       ..B.o.o.t."...
     2446           *
     2447           * This is waht we got when Moutain Kitten reboot after the first installation stage:
     2448           * Variable - fAttr=0x07 - '8be4df61-93ca-11d2-aa0d-00e098032b8c:Boot0080' - cb=0xb6
     2449           *   0000: 01 00 00 00 48 00 4d 00-61 00 63 00 20 00 4f 00 ....H.M.a.c. .O.
     2450           *   0010: 53 00 20 00 58 00 00 00-02 01 0c 00 d0 41 03 0a S. .X........A..
     2451           *   0020: 00 00 00 00 01 01 06 00-02 1f 03 01 08 00 00 01 ................
     2452           *   0030: 00 00 04 01 2a 00 02 00-00 00 28 40 06 00 00 00 ....*.....(@....
     2453           *   0040: 00 00 98 b5 53 02 00 00-00 00 a5 9a 97 b7 33 60 ....S.........3`
     2454           *   0050: 2d 47 bf 1a fa 14 fe c5-f2 b8 02 02 7f ff 04 00 -G..............
     2455           *   0060: 63 00 6f 00 6e 00 66 00-69 00 67 00 3d 00 22 00 c.o.n.f.i.g.=.".
     2456           *   0070: 5c 00 4f 00 53 00 20 00-58 00 20 00 49 00 6e 00 \.O.S. .X. .I.n.
     2457           *   0080: 73 00 74 00 61 00 6c 00-6c 00 20 00 44 00 61 00 s.t.a.l.l. .D.a.
     2458           *   0090: 74 00 61 00 5c 00 63 00-6f 00 6d 00 2e 00 61 00 t.a.\.c.o.m...a.
     2459           *   00a0: 70 00 70 00 6c 00 65 00-2e 00 42 00 6f 00 6f 00 p.p.l.e...B.o.o.
     2460           *   00b0: 74 00 22 00 00 00                               t."...
     2461           */
     2462          VBoxLogFlowFuncMarkVar(Option->LoadOptions, "%s");
    8502463        if (StrnCmp(L"config=", (CHAR16 *)Option->LoadOptions, 7) == 0) {
    8512464          EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *Volume;
     
    9112524      }
    9122525#else  /* !VBOX */
    913       //
    914       // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
    915       //  machinename is ia32, ia64, x64, ...
    916       //
    917       FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
    918       if (FilePath != NULL) {
    919         REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
    920         Status = gBS->LoadImage (
    921                         TRUE,
    922                         gImageHandle,
    923                         FilePath,
    924                         NULL,
    925                         0,
    926                         &ImageHandle
    927                         );
    928        if (EFI_ERROR (Status)) {
    929           //
    930           // The DevicePath failed, and it's not a valid
    931           // removable media device.
    932           //
    933           goto Done;
     2526        //
     2527        // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
     2528        //  machinename is ia32, ia64, x64, ...
     2529        //
     2530        FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
     2531        if (FilePath != NULL) {
     2532          REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
     2533          Status = gBS->LoadImage (
     2534                          TRUE,
     2535                          gImageHandle,
     2536                          FilePath,
     2537                          NULL,
     2538                          0,
     2539                          &ImageHandle
     2540                          );
    9342541        }
    935       }
    9362542#endif /* !VBOX */
    9372543    }
    938 
    939     if (EFI_ERROR (Status)) {
    940       //
    941       // It there is any error from the Boot attempt exit now.
    942       //
    943       goto Done;
    944     }
     2544  }
    9452545  }
    9462546  //
    9472547  // Provide the image with it's load options
    9482548  //
    949   if (ImageHandle == NULL) {
     2549  if ((ImageHandle == NULL) || (EFI_ERROR(Status))) {
     2550    //
     2551    // Report Status Code to indicate that the failure to load boot option
     2552    //
     2553    REPORT_STATUS_CODE (
     2554      EFI_ERROR_CODE | EFI_ERROR_MINOR,
     2555      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR)
     2556      );   
    9502557    goto Done;
    9512558  }
     2559
    9522560  Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
    9532561  ASSERT_EFI_ERROR (Status);
     
    9572565    ImageInfo->LoadOptions      = Option->LoadOptions;
    9582566  }
     2567
     2568  //
     2569  // Clean to NULL because the image is loaded directly from the firmwares boot manager.
     2570  //
     2571  ImageInfo->ParentHandle = NULL;
     2572
    9592573  //
    9602574  // Before calling the image, enable the Watchdog Timer for
     
    9672581  //
    9682582  PERF_CODE (
    969     WriteBootToOsPerformanceData ();
     2583    WriteBootToOsPerformanceData (NULL, NULL);
    9702584  );
    9712585
     
    9772591  Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
    9782592  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));
     2593  if (EFI_ERROR (Status)) {
     2594    //
     2595    // Report Status Code to indicate that boot failure
     2596    //
     2597    REPORT_STATUS_CODE (
     2598      EFI_ERROR_CODE | EFI_ERROR_MINOR,
     2599      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED)
     2600      );
     2601  }
    9792602
    9802603  //
     
    9952618  //
    9962619  // Clear Boot Current
     2620  // Deleting variable with current implementation shouldn't fail.
    9972621  //
    9982622  gRT->SetVariable (
     
    10012625        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
    10022626        0,
    1003         &Option->BootCurrent
     2627        NULL
    10042628        );
    10052629
     
    10502674  // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system
    10512675  //
    1052   CachedDevicePath = BdsLibGetVariableAndSize (
    1053                       HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
    1054                       &gHdBootDevicePathVariablGuid,
    1055                       &CachedDevicePathSize
    1056                       );
     2676  GetVariable2 (
     2677    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
     2678    &gHdBootDevicePathVariablGuid,
     2679    (VOID **) &CachedDevicePath,
     2680    &CachedDevicePathSize
     2681    );
     2682
     2683  //
     2684  // Delete the invalid HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.
     2685  //
     2686  if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {
     2687    FreePool (CachedDevicePath);
     2688    CachedDevicePath = NULL;
     2689    Status = gRT->SetVariable (
     2690                    HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
     2691                    &gHdBootDevicePathVariablGuid,
     2692                    0,
     2693                    0,
     2694                    NULL
     2695                    );
     2696    ASSERT_EFI_ERROR (Status);
     2697  }
    10572698
    10582699  if (CachedDevicePath != NULL) {
     
    11122753        //
    11132754        // Save the matching Device Path so we don't need to do a connect all next time
     2755        // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
    11142756        //
    11152757        Status = gRT->SetVariable (
    11162758                        HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
    11172759                        &gHdBootDevicePathVariablGuid,
    1118                         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     2760                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
    11192761                        GetDevicePathSize (CachedDevicePath),
    11202762                        CachedDevicePath
     
    11692811          CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);
    11702812          FreePool(TempNewDevicePath);
    1171 
    1172           TempNewDevicePath = CachedDevicePath;
    1173           CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
    1174           if (TempNewDevicePath != NULL) {
    1175             FreePool(TempNewDevicePath);
    1176           }
    1177         } else {
     2813        }
     2814
     2815        if (CachedDevicePath != NULL) {
    11782816          TempNewDevicePath = CachedDevicePath;
    11792817          CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
    11802818          FreePool(TempNewDevicePath);
     2819        } else {
     2820          CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);
    11812821        }
     2822
    11822823        //
    11832824        // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller
     
    12112852      //
    12122853      // Save the matching Device Path so we don't need to do a connect all next time
     2854      // Failure to set the variable only impacts the performance when next time expanding the short-form device path.
    12132855      //
    12142856      Status = gRT->SetVariable (
    12152857                      HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
    12162858                      &gHdBootDevicePathVariablGuid,
    1217                       EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     2859                      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
    12182860                      GetDevicePathSize (CachedDevicePath),
    12192861                      CachedDevicePath
     
    14203062                  BootOrder
    14213063                  );
     3064  //
     3065  // Shrinking variable with existing variable implementation shouldn't fail.
     3066  //
     3067  ASSERT_EFI_ERROR (Status);
    14223068
    14233069  FreePool (BootOrder);
     
    15243170                      );
    15253171      //
     3172      // Deleting variable with current variable implementation shouldn't fail.
     3173      //
     3174      ASSERT_EFI_ERROR (Status);
     3175      //
    15263176      // Mark this boot option in boot order as deleted
    15273177      //
     
    15543204                  );
    15553205  VBoxLogFlowFuncMarkRC(Status);
     3206  //
     3207  // Shrinking variable with current variable implementation shouldn't fail.
     3208  //
     3209  ASSERT_EFI_ERROR (Status);
     3210
    15563211  FreePool (BootOrder);
    15573212
     
    16623317  //
    16633318  if (mEnumBootDevice) {
    1664     LastLang = GetVariable (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid);
    1665     PlatLang = GetEfiGlobalVariable (L"PlatformLang");
     3319    GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);
     3320    GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);
    16663321    ASSERT (PlatLang != NULL);
    16673322    if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {
     
    16793334        PlatLang
    16803335        );
    1681       ASSERT_EFI_ERROR (Status);
     3336      //
     3337      // Failure to set the variable only impacts the performance next time enumerating the boot options.
     3338      //
    16823339
    16833340      if (LastLang != NULL) {
     
    17243381                      );
    17253382      //
    1726       // skip the fixed block io then the removable block io
    1727       //
    1728       if (EFI_ERROR (Status) || (BlkIo->Media->RemovableMedia == Removable[RemovableIndex])) {
     3383      // skip the logical partition
     3384      //
     3385      if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {
     3386        continue;
     3387      }
     3388
     3389      //
     3390      // firstly fixed block io then the removable block io
     3391      //
     3392      if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {
    17293393        continue;
    17303394      }
     
    17883452
    17893453      case BDS_EFI_MESSAGE_MISC_BOOT:
     3454      default:
    17903455        if (MiscNumber != 0) {
    17913456          UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);
     
    17953460        BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
    17963461        MiscNumber++;
    1797         break;
    1798 
    1799       default:
    18003462        break;
    18013463      }
     
    20403702  )
    20413703{
     3704  EFI_STATUS        Status;
    20423705  UINT16            *BootNext;
    20433706  UINTN             BootNextSize;
     
    20643727  //
    20653728  if (BootNext != NULL) {
    2066     gRT->SetVariable (
    2067           L"BootNext",
    2068           &gEfiGlobalVariableGuid,
    2069           EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
    2070           0,
    2071           BootNext
    2072           );
     3729    Status = gRT->SetVariable (
     3730                    L"BootNext",
     3731                    &gEfiGlobalVariableGuid,
     3732                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
     3733                    0,
     3734                    NULL
     3735                    );
     3736    //
     3737    // Deleting variable with current variable implementation shouldn't fail.
     3738    //
     3739    ASSERT_EFI_ERROR (Status);
    20733740
    20743741    //
     
    20803747    BdsLibConnectDevicePath (BootOption->DevicePath);
    20813748    BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
     3749    FreePool(BootOption);
     3750    FreePool(BootNext);
    20823751  }
    20833752
     
    29764645    EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
    29774646    NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
     4647    ASSERT (NewDevicePath != NULL);
    29784648    *DevicePath = NewDevicePath;
    29794649    return EFI_SUCCESS;
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConnect.c

    r48674 r58459  
    22  BDS Lib functions which relate with connect the device
    33
    4 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    6666}
    6767
    68 
    6968/**
    7069  This function will create all handles associate with every device
    7170  path node. If the handle associate with one device path node can not
    72   be created success, then still give one chance to do the dispatch,
     71  be created successfully, then still give chance to do the dispatch,
    7372  which load the missing drivers if possible.
    7473
     
    9897  EFI_HANDLE                PreviousHandle;
    9998  UINTN                     Size;
     99  EFI_TPL                   CurrentTpl;
    100100
    101101  if (DevicePathToConnect == NULL) {
    102102    return EFI_SUCCESS;
    103103  }
     104
     105  CurrentTpl  = EfiGetCurrentTpl ();
    104106
    105107  DevicePath        = DuplicateDevicePath (DevicePathToConnect);
     
    151153          // Status == EFI_NOT_FOUND means no new drivers were dispatched
    152154          //
    153           Status = gDS->Dispatch ();
     155          if (CurrentTpl == TPL_APPLICATION) {
     156            //
     157            // Dispatch calls LoadImage/StartImage which cannot run at TPL > TPL_APPLICATION
     158            //
     159            Status = gDS->Dispatch ();
     160          } else {
     161            //
     162            // Always return EFI_NOT_FOUND here
     163            // to prevent dead loop when control handle is found but connection failded case
     164            //
     165            Status = EFI_NOT_FOUND;
     166          }
    154167        }
    155168
     
    189202  return Status;
    190203}
    191 
    192204
    193205/**
     
    411423    }
    412424
     425    if (HandleArray != NULL) {
     426      FreePool (HandleArray);
     427    }
     428
    413429    if (AtLeastOneConnected) {
    414430      return EFI_SUCCESS;
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c

    r48730 r58459  
    22  BDS Lib functions which contain all the code to connect console device
    33
    4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    6666  @param  ConsoleGuid        Specified Console protocol GUID.
    6767  @param  ConsoleHandle      On IN,  console handle in System Table to be checked.
    68                              On OUT, new console hanlde in system table.
     68                             On OUT, new console handle in system table.
    6969  @param  ProtocolInterface  On IN,  console protocol on console handle in System Table to be checked.
    70                              On OUT, new console protocol on new console hanlde in system table.
     70                             On OUT, new console protocol on new console handle in system table.
    7171
    7272  @retval TRUE               System Table has been updated.
     
    8989  VOID                      *Interface;
    9090  EFI_HANDLE                NewHandle;
     91  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
    9192
    9293  ASSERT (VarName != NULL);
     
    160161        *ConsoleHandle     = NewHandle;
    161162        *ProtocolInterface = Interface;
     163        if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {
     164          //
     165          // If it is console out device, set console mode 80x25 if current mode is invalid.
     166          //
     167          TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;
     168          if (TextOut->Mode->Mode == -1) {
     169            TextOut->SetMode (TextOut, 0);
     170          }
     171        }
    162172        return TRUE;
    163173      }
     
    294304  DevicePathSize = GetDevicePathSize (NewDevicePath);
    295305  VBoxLogFlowFuncMark();
    296   Status = gRT->SetVariable (
    297                   ConVarName,
    298                   &gEfiGlobalVariableGuid,
    299                   Attributes,
    300                   DevicePathSize,
    301                   NewDevicePath
    302                   );
     306  Status = SetVariableAndReportStatusCodeOnError (
     307             ConVarName,
     308             &gEfiGlobalVariableGuid,
     309             Attributes,
     310             DevicePathSize,
     311             NewDevicePath
     312             );
    303313  VBoxLogFlowFuncMarkRC(Status);
    304314  if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
    305315    Status = EFI_SUCCESS;
    306316  }
    307   ASSERT_EFI_ERROR (Status);
    308317
    309318  if (VarConsole == NewDevicePath) {
     
    328337/**
    329338  Connect the console device base on the variable ConVarName, if
    330   device path of the ConVarName is multi-instance device path, if
     339  device path of the ConVarName is multi-instance device path and
    331340  anyone of the instances is connected success, then this function
    332341  will return success.
     342  If the handle associate with one device path node can not
     343  be created successfully, then still give chance to do the dispatch,
     344  which load the missing drivers if possible..
    333345
    334346  @param  ConVarName               Console related variable name, ConIn, ConOut,
     
    407419      //
    408420      Status = BdsLibConnectDevicePath (Instance);
     421
    409422      if (EFI_ERROR (Status)) {
    410423        //
     
    427440  return EFI_SUCCESS;
    428441}
    429 
    430442
    431443/**
     
    559571    SystemTableUpdated = TRUE;
    560572  }
     573  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
     574    SystemTableUpdated = TRUE;
     575  }
     576  if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
     577    SystemTableUpdated = TRUE;
     578  }
     579
     580  if (SystemTableUpdated) {
     581    //
     582    // Update the CRC32 in the EFI System Table header
     583    //
     584    gST->Hdr.CRC32 = 0;
     585    gBS->CalculateCrc32 (
     586          (UINT8 *) &gST->Hdr,
     587          gST->Hdr.HeaderSize,
     588          &gST->Hdr.CRC32
     589          );
     590  }
     591
     592  return EFI_SUCCESS;
     593
     594}
     595
     596/**
     597  This function will connect console device except ConIn base on the console
     598  device variable  ConOut and ErrOut.
     599
     600  @retval EFI_SUCCESS              At least one of the ConOut device have
     601                                   been connected success.
     602  @retval EFI_STATUS               Return the status of BdsLibConnectConsoleVariable ().
     603
     604**/
     605EFI_STATUS
     606EFIAPI
     607BdsLibConnectAllDefaultConsolesWithOutConIn (
     608  VOID
     609  )
     610{
     611  EFI_STATUS                Status;
     612  BOOLEAN                   SystemTableUpdated;
     613
     614  //
     615  // Connect all default console variables except ConIn
     616  //
     617
     618  //
     619  // It seems impossible not to have any ConOut device on platform,
     620  // so we check the status here.
     621  //
     622  Status = BdsLibConnectConsoleVariable (L"ConOut");
     623  if (EFI_ERROR (Status)) {
     624    return Status;
     625  }
     626
     627  //
     628  // Insert the performance probe for Console Out
     629  //
     630  PERF_START (NULL, "ConOut", "BDS", 1);
     631  PERF_END (NULL, "ConOut", "BDS", 0);
     632
     633  //
     634  // The _ModuleEntryPoint err out var is legal.
     635  //
     636  BdsLibConnectConsoleVariable (L"ErrOut");
     637
     638  SystemTableUpdated = FALSE;
     639  //
     640  // Fill console handles in System Table if no console device assignd.
     641  //
    561642  if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
    562643    SystemTableUpdated = TRUE;
     
    690771        break;
    691772      }
    692     if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) != sizeof (BMP_COLOR_MAP) * ColorMapNum) {
     773    //
     774    // BMP file may has padding data between the bmp header section and the bmp data section.
     775    //
     776    if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) {
    693777      return EFI_INVALID_PARAMETER;
    694778    }
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c

    r48738 r58459  
    22  Misc BDS library function
    33
    4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    169169      break;
    170170    }
     171    FreePool(OptionBuffer);
    171172    Index++;
    172173  } while (TRUE);
     
    218219  UINTN                     OrderItemNum;
    219220
     221  if (DevicePath == NULL) {
     222    return EFI_INVALID_PARAMETER;
     223  }
    220224
    221225  OptionPtr             = NULL;
     
    268272    //
    269273    if (!ValidateOption(OptionPtr, OptionSize)) {
     274      FreePool(OptionPtr);
    270275      continue;
    271276    }
     
    465470  invalidate string.
    466471
    467   This function returns the number of Unicode characters in the Null-terminated
     472  This function returns the byte length of Unicode characters in the Null-terminated
    468473  Unicode string specified by String.
    469474
     
    489494  ASSERT (((UINTN) String & BIT0) == 0);
    490495
    491   for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length++);
     496  for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length+=2);
    492497
    493498  if (*String != L'\0' && MaxStringLen == Length) {
     
    495500  }
    496501
    497   return (Length + 1) * sizeof (*String);
     502  return Length + 2;
    498503}
    499504
     
    517522  UINT8                     *TempPtr;
    518523  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    519   EFI_DEVICE_PATH_PROTOCOL  *TempPath;
    520524  UINTN                     TempSize;
    521525
     
    523527  VBoxLogFlowFuncMarkVar(Variable, "%s");
    524528  VBoxLogFlowFuncMarkVar(VariableSize, "%d");
     529
     530  if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {
     531    return FALSE;
     532  }
     533
    525534  //
    526535  // Skip the option attribute
     
    538547  // Get the option's description string size
    539548  //
    540   TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);
     549  TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT16) - sizeof (UINT32));
    541550  TempPtr += TempSize;
    542551
     
    545554  //
    546555  DevicePath =  (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
    547   TempPtr    += FilePathSize;
     556  TempPtr   += FilePathSize;
    548557
    549558  //
     
    555564  }
    556565
    557   if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT16) > VariableSize) {
    558     VBoxLogFlowFuncLeave();
    559     return FALSE;
    560   }
    561 
    562   TempPath = DevicePath;
    563   while (FilePathSize > 0) {
    564     TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);
    565     if (TempSize == 0) {
     566  if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > VariableSize) {
    566567      VBoxLogFlowFuncLeave();
    567568      return FALSE;
    568     }
    569     FilePathSize = (UINT16) (FilePathSize - TempSize);
    570     TempPath    += TempSize;
    571   }
    572 
    573   VBoxLogFlowFuncLeave();
    574   return TRUE;
     569  }
     570
     571  return (BOOLEAN) (GetDevicePathSizeEx (DevicePath, FilePathSize) != 0);
    575572}
    576573
     
    625622  UINTN                     VariableSize;
    626623  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    627   EFI_DEVICE_PATH_PROTOCOL  *TempPath;
    628624  BDS_COMMON_OPTION         *Option;
    629625  VOID                      *LoadOptions;
     
    631627  CHAR16                    *Description;
    632628  UINT8                     NumOff;
     629#ifdef VBOX
    633630  UINTN                     TempSize;
     631#endif
     632
    634633  //
    635634  // Read the variable. We will never free this data.
     
    654653    VBoxLogFlowFuncMarkVar(Variable, "%p");
    655654    VBoxLogFlowFuncLeave();
     655    FreePool (Variable);
    656656    return NULL;
    657657  }
     
    682682  // Get the option's description string size
    683683  //
    684   TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize);
    685   if (TempSize == 0) {
    686     return NULL;
    687   }
    688   TempPtr += TempSize;
     684  TempPtr += StrSize((CHAR16 *) TempPtr);
    689685
    690686  //
     
    695691
    696692  //
    697   // Validation device path.
    698   //
    699   TempPath       = DevicePath;
    700   while (FilePathSize > 0) {
    701     TempSize = GetDevicePathSizeEx (TempPath, FilePathSize);
    702     if (TempSize == 0) {
    703       return NULL;
    704     }
    705     FilePathSize = (UINT16) (FilePathSize - TempSize);
    706     TempPath    += TempSize;
    707   }
    708 
    709   //
    710693  // Get load opion data.
    711694  //
    712695  LoadOptions     = TempPtr;
    713   if (VariableSize < (UINTN)(TempPtr - Variable)) {
    714     VBoxLogFlowFuncMarkVar(Variable, "%p");
    715     VBoxLogFlowFuncLeave();
    716     return NULL;
    717   }
    718696  LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
    719697
     
    726704    VBoxLogFlowFuncMarkVar(Variable, "%p");
    727705    VBoxLogFlowFuncLeave();
     706    FreePool (Variable);
    728707    return NULL;
    729708  }
     
    763742               + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1);
    764743  }
    765   //
    766   // Insert active entry to BdsDeviceList
    767   //
    768   if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {
    769     InsertTailList (BdsCommonOptionList, &Option->Link);
    770     FreePool (Variable);
    771     VBoxLogFlowFuncMarkVar(Option, "%p");
    772     VBoxLogFlowFuncLeave();
    773     return Option;
    774   }
    775 
     744  InsertTailList (BdsCommonOptionList, &Option->Link);
    776745  FreePool (Variable);
    777   FreePool (Option->Description);
    778   FreePool (Option->DevicePath);
    779   FreePool (Option->LoadOptions);
    780 #ifdef VBOX
    781   FreePool (Option->OptionName);
    782 #endif
    783   FreePool (Option);
    784746  VBoxLogFlowFuncLeave();
    785   return NULL;
     747  return Option;
    786748}
    787749
     
    908870    Buffer = AllocateZeroPool (BufferSize);
    909871    if (Buffer == NULL) {
     872      *VariableSize = 0;
    910873      return NULL;
    911874    }
     
    916879    VBoxLogFlowFuncMarkRC(Status);
    917880    if (EFI_ERROR (Status)) {
     881      FreePool (Buffer);
    918882      BufferSize = 0;
    919     }
    920   }
    921 
     883      Buffer     = NULL;
     884    }
     885  }
     886
     887  ASSERT (((Buffer == NULL) && (BufferSize == 0)) ||
     888          ((Buffer != NULL) && (BufferSize != 0))
     889          );
    922890  *VariableSize = BufferSize;
    923891  VBoxLogFlowFuncLeave();
     
    12031171      StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
    12041172      ASSERT (StringBuffer2 != NULL);
    1205       StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
    1206       StrCpy (StringBuffer2, L"Enter (YES)  /   Esc (NO)");
     1173      StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now.");
     1174      StrCpy (StringBuffer2, L"Press ENTER to reset");
    12071175      //
    12081176      // Popup a menu to notice user
     
    12101178      do {
    12111179        CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
    1212       } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
     1180      } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
    12131181
    12141182      FreePool (StringBuffer1);
    12151183      FreePool (StringBuffer2);
    1216       //
    1217       // If the user hits the YES Response key, reset
    1218       //
    1219       if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
    1220         gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
    1221       }
    1222       gST->ConOut->ClearScreen (gST->ConOut);
     1184
     1185      gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
    12231186    }
    12241187  }
     
    13961359
    13971360/**
    1398   This routine adjusts the memory information for different memory type and
    1399   saves them into the variables for next boot. It conditionally resets the
    1400   system when the memory information changes. Platform can reserve memory
    1401   large enough (125% of actual requirement) to avoid the reset in the first boot.
     1361  This routine adjust the memory information for different memory type and
     1362  save them into the variables for next boot.
    14021363**/
    14031364VOID
     
    15051466
    15061467    //
    1507     // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail
    1508     //
    1509     if (Current < Previous) {
     1468    // Inconsistent Memory Reserved across bootings may lead to S4 fail
     1469    // Write next varible to 125% * current when the pre-allocated memory is:
     1470    //  1. More than 150% of needed memory and boot mode is BOOT_WITH_DEFAULT_SETTING
     1471    //  2. Less than the needed memory
     1472    //
     1473    if ((Current + (Current >> 1)) < Previous) {
    15101474      if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
    15111475        Next = Current + (Current >> 2);
    1512       } else if (!MemoryTypeInformationVariableExists) {
    1513         Next = MAX (Current + (Current >> 2), Previous);
    15141476      }
    15151477    } else if (Current > Previous) {
     
    15331495  //
    15341496  if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
    1535     Status = gRT->SetVariable (
    1536                     EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
    1537                     &gEfiMemoryTypeInformationGuid,
    1538                     EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
    1539                     VariableSize,
    1540                     PreviousMemoryTypeInformation
    1541                     );
    1542 
    1543     //
    1544     // If the Memory Type Information settings have been modified, then reset the platform
    1545     // so the new Memory Type Information setting will be used to guarantee that an S4
    1546     // entry/resume cycle will not fail.
    1547     //
    1548     if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
    1549       DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));
    1550       gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
     1497    Status = SetVariableAndReportStatusCodeOnError (
     1498               EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
     1499               &gEfiMemoryTypeInformationGuid,
     1500               EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,
     1501               VariableSize,
     1502               PreviousMemoryTypeInformation
     1503               );
     1504
     1505    if (!EFI_ERROR (Status)) {
     1506      //
     1507      // If the Memory Type Information settings have been modified, then reset the platform
     1508      // so the new Memory Type Information setting will be used to guarantee that an S4
     1509      // entry/resume cycle will not fail.
     1510      //
     1511      if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
     1512        DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));
     1513        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
     1514      }
     1515    } else {
     1516      DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. OS S4 may fail!\n"));
    15511517    }
    15521518  }
     
    15961562}
    15971563
     1564/**
     1565  Set the variable and report the error through status code upon failure.
     1566
     1567  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.
     1568                                 Each VariableName is unique for each VendorGuid. VariableName must
     1569                                 contain 1 or more characters. If VariableName is an empty string,
     1570                                 then EFI_INVALID_PARAMETER is returned.
     1571  @param  VendorGuid             A unique identifier for the vendor.
     1572  @param  Attributes             Attributes bitmask to set for the variable.
     1573  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
     1574                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
     1575                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
     1576                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
     1577                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to
     1578                                 the variable value (the timestamp associated with the variable may be updated however
     1579                                 even if no new data value is provided,see the description of the
     1580                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
     1581                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
     1582  @param  Data                   The contents for the variable.
     1583
     1584  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as
     1585                                 defined by the Attributes.
     1586  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the
     1587                                 DataSize exceeds the maximum allowed.
     1588  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
     1589  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.
     1590  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.
     1591  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
     1592  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
     1593  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
     1594                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
     1595                                 does NOT pass the validation check carried out by the firmware.
     1596
     1597  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.
     1598**/
     1599EFI_STATUS
     1600SetVariableAndReportStatusCodeOnError (
     1601  IN CHAR16     *VariableName,
     1602  IN EFI_GUID   *VendorGuid,
     1603  IN UINT32     Attributes,
     1604  IN UINTN      DataSize,
     1605  IN VOID       *Data
     1606  )
     1607{
     1608  EFI_STATUS                 Status;
     1609  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;
     1610  UINTN                      NameSize;
     1611
     1612  Status = gRT->SetVariable (
     1613                  VariableName,
     1614                  VendorGuid,
     1615                  Attributes,
     1616                  DataSize,
     1617                  Data
     1618                  );
     1619  if (EFI_ERROR (Status)) {
     1620    NameSize = StrSize (VariableName);
     1621    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);
     1622    if (SetVariableStatus != NULL) {
     1623      CopyGuid (&SetVariableStatus->Guid, VendorGuid);
     1624      SetVariableStatus->NameSize   = NameSize;
     1625      SetVariableStatus->DataSize   = DataSize;
     1626      SetVariableStatus->SetStatus  = Status;
     1627      SetVariableStatus->Attributes = Attributes;
     1628      CopyMem (SetVariableStatus + 1,                          VariableName, NameSize);
     1629      if ((Data != NULL) && (DataSize != 0)) {
     1630        CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         DataSize);
     1631      }
     1632
     1633      REPORT_STATUS_CODE_EX (
     1634        EFI_ERROR_CODE,
     1635        PcdGet32 (PcdErrorCodeSetVariable),
     1636        0,
     1637        NULL,
     1638        &gEdkiiStatusCodeDataTypeVariableGuid,
     1639        SetVariableStatus,
     1640        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
     1641        );
     1642
     1643      FreePool (SetVariableStatus);
     1644    }
     1645  }
     1646
     1647  return Status;
     1648}
     1649
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c

    r48674 r58459  
    33  replaced by platform device path.
    44
    5 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
     5Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
    66This program and the accompanying materials
    77are licensed and made available under the terms and conditions of the BSD License
     
    1515
    1616#include "InternalBdsLib.h"
    17 
    18 /**
    19   Concatenates a formatted unicode string to allocated pool.
    20   The caller must free the resulting buffer.
    21 
    22   @param  Str      Tracks the allocated pool, size in use, and amount of pool allocated.
    23   @param  Fmt      The format string
    24   @param  ...      The data will be printed.
    25 
    26   @return Allocated buffer with the formatted string printed in it.
    27           The caller must free the allocated buffer.
    28           The buffer allocation is not packed.
    29 
    30 **/
    31 CHAR16 *
    32 EFIAPI
    33 CatPrint (
    34   IN OUT POOL_PRINT   *Str,
    35   IN CHAR16           *Fmt,
    36   ...
    37   )
    38 {
    39   UINT16  *AppendStr;
    40   VA_LIST Args;
    41   UINTN   StringSize;
    42 
    43   AppendStr = AllocateZeroPool (0x1000);
    44   if (AppendStr == NULL) {
    45     return Str->Str;
    46   }
    47 
    48   VA_START (Args, Fmt);
    49   UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
    50   VA_END (Args);
    51   if (NULL == Str->Str) {
    52     StringSize   = StrSize (AppendStr);
    53     Str->Str  = AllocateZeroPool (StringSize);
    54     ASSERT (Str->Str != NULL);
    55   } else {
    56     StringSize = StrSize (AppendStr);
    57     StringSize += (StrSize (Str->Str) - sizeof (UINT16));
    58 
    59     Str->Str = ReallocatePool (
    60                 StrSize (Str->Str),
    61                 StringSize,
    62                 Str->Str
    63                 );
    64     ASSERT (Str->Str != NULL);
    65   }
    66 
    67   Str->Maxlen = MAX_CHAR * sizeof (UINT16);
    68   if (StringSize < Str->Maxlen) {
    69     StrCat (Str->Str, AppendStr);
    70     Str->Len = StringSize - sizeof (UINT16);
    71   }
    72 
    73   FreePool (AppendStr);
    74   return Str->Str;
    75 }
    76 
    77 /**
    78   Convert Device Path to a Unicode string for printing.
    79 
    80   @param Str             The buffer holding the output string.
    81                          This buffer contains the length of the
    82                          string and the maixmum length reserved
    83                          for the string buffer.
    84   @param DevPath         The device path.
    85 
    86 **/
    87 VOID
    88 DevPathPci (
    89   IN OUT POOL_PRINT       *Str,
    90   IN VOID                 *DevPath
    91   )
    92 {
    93   PCI_DEVICE_PATH *Pci;
    94 
    95   Pci = DevPath;
    96   CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);
    97 }
    98 
    99 /**
    100   Convert Device Path to a Unicode string for printing.
    101 
    102   @param Str             The buffer holding the output string.
    103                          This buffer contains the length of the
    104                          string and the maixmum length reserved
    105                          for the string buffer.
    106   @param DevPath         The device path.
    107 
    108 **/
    109 VOID
    110 DevPathPccard (
    111   IN OUT POOL_PRINT       *Str,
    112   IN VOID                 *DevPath
    113   )
    114 {
    115   PCCARD_DEVICE_PATH  *Pccard;
    116 
    117   Pccard = DevPath;
    118   CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);
    119 }
    120 
    121 /**
    122   Convert Device Path to a Unicode string for printing.
    123 
    124   @param Str             The buffer holding the output string.
    125                          This buffer contains the length of the
    126                          string and the maixmum length reserved
    127                          for the string buffer.
    128   @param DevPath         The device path.
    129 
    130 **/
    131 VOID
    132 DevPathMemMap (
    133   IN OUT POOL_PRINT       *Str,
    134   IN VOID                 *DevPath
    135   )
    136 {
    137   MEMMAP_DEVICE_PATH  *MemMap;
    138 
    139   MemMap = DevPath;
    140   CatPrint (
    141     Str,
    142     L"MemMap(%d:%lx-%lx)",
    143     (UINTN) MemMap->MemoryType,
    144     MemMap->StartingAddress,
    145     MemMap->EndingAddress
    146     );
    147 }
    148 
    149 /**
    150   Convert Device Path to a Unicode string for printing.
    151 
    152   @param Str             The buffer holding the output string.
    153                          This buffer contains the length of the
    154                          string and the maixmum length reserved
    155                          for the string buffer.
    156   @param DevPath         The device path.
    157 
    158 **/
    159 VOID
    160 DevPathController (
    161   IN OUT POOL_PRINT       *Str,
    162   IN VOID                 *DevPath
    163   )
    164 {
    165   CONTROLLER_DEVICE_PATH  *Controller;
    166 
    167   Controller = DevPath;
    168   CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);
    169 }
    170 
    171 
    172 /**
    173   Convert Vendor device path to device name.
    174 
    175   @param  Str      The buffer store device name
    176   @param  DevPath  Pointer to vendor device path
    177 
    178 **/
    179 VOID
    180 DevPathVendor (
    181   IN OUT POOL_PRINT       *Str,
    182   IN VOID                 *DevPath
    183   )
    184 {
    185   VENDOR_DEVICE_PATH  *Vendor;
    186   CHAR16              *Type;
    187   UINTN               DataLength;
    188   UINTN               Index;
    189   UINT32              FlowControlMap;
    190 
    191   UINT16              Info;
    192 
    193   Vendor  = DevPath;
    194 
    195   switch (DevicePathType (&Vendor->Header)) {
    196   case HARDWARE_DEVICE_PATH:
    197     Type = L"Hw";
    198     break;
    199 
    200   case MESSAGING_DEVICE_PATH:
    201     Type = L"Msg";
    202     if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
    203       CatPrint (Str, L"VenPcAnsi()");
    204       return ;
    205     } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
    206       CatPrint (Str, L"VenVt100()");
    207       return ;
    208     } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
    209       CatPrint (Str, L"VenVt100Plus()");
    210       return ;
    211     } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
    212       CatPrint (Str, L"VenUft8()");
    213       return ;
    214     } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid     )) {
    215       FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
    216       switch (FlowControlMap & 0x00000003) {
    217       case 0:
    218         CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
    219         break;
    220 
    221       case 1:
    222         CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
    223         break;
    224 
    225       case 2:
    226         CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
    227         break;
    228 
    229       default:
    230         break;
    231       }
    232 
    233       return ;
    234 
    235     } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
    236       CatPrint (
    237         Str,
    238         L"SAS(%lx,%lx,%x,",
    239         ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
    240         ((SAS_DEVICE_PATH *) Vendor)->Lun,
    241         (UINTN) ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
    242         );
    243       Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
    244       if ((Info & 0x0f) == 0) {
    245         CatPrint (Str, L"NoTopology,0,0,0,");
    246       } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
    247         CatPrint (
    248           Str,
    249           L"%s,%s,%s,",
    250           ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
    251           ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
    252           ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
    253           );
    254         if ((Info & 0x0f) == 1) {
    255           CatPrint (Str, L"0,");
    256         } else {
    257           CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));
    258         }
    259       } else {
    260         CatPrint (Str, L"0,0,0,0,");
    261       }
    262 
    263       CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);
    264       return ;
    265 
    266     } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
    267       CatPrint (Str, L"DebugPort()");
    268       return ;
    269     }
    270     break;
    271 
    272   case MEDIA_DEVICE_PATH:
    273     Type = L"Media";
    274     break;
    275 
    276   default:
    277     Type = L"?";
    278     break;
    279   }
    280 
    281   CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
    282   DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
    283   if (DataLength > 0) {
    284     CatPrint (Str, L",");
    285     for (Index = 0; Index < DataLength; Index++) {
    286       CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
    287     }
    288   }
    289   CatPrint (Str, L")");
    290 }
    291 
    292 /**
    293   Convert Device Path to a Unicode string for printing.
    294 
    295   @param Str             The buffer holding the output string.
    296                          This buffer contains the length of the
    297                          string and the maixmum length reserved
    298                          for the string buffer.
    299   @param DevPath         The device path.
    300 
    301 **/
    302 VOID
    303 DevPathAcpi (
    304   IN OUT POOL_PRINT       *Str,
    305   IN VOID                 *DevPath
    306   )
    307 {
    308   ACPI_HID_DEVICE_PATH  *Acpi;
    309 
    310   Acpi = DevPath;
    311   if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
    312     CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN)  EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);
    313   } else {
    314     CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);
    315   }
    316 }
    317 
    318 /**
    319   Convert Device Path to a Unicode string for printing.
    320 
    321   @param Str             The buffer holding the output string.
    322                          This buffer contains the length of the
    323                          string and the maixmum length reserved
    324                          for the string buffer.
    325   @param DevPath         The device path.
    326 
    327 **/
    328 VOID
    329 DevPathExtendedAcpi (
    330   IN OUT POOL_PRINT       *Str,
    331   IN VOID                 *DevPath
    332   )
    333 {
    334   ACPI_EXTENDED_HID_DEVICE_PATH   *ExtendedAcpi;
    335  
    336   //
    337   // Index for HID, UID and CID strings, 0 for non-exist
    338   //
    339   UINT16                          HIDSTRIdx;
    340   UINT16                          UIDSTRIdx;
    341   UINT16                          CIDSTRIdx;
    342   UINT16                          Index;
    343   UINT16                          Length;
    344   UINT16                          Anchor;
    345   CHAR8                           *AsChar8Array;
    346 
    347   HIDSTRIdx    = 0;
    348   UIDSTRIdx    = 0;
    349   CIDSTRIdx    = 0;
    350   ExtendedAcpi = DevPath;
    351   Length       = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
    352 
    353   AsChar8Array = (CHAR8 *) ExtendedAcpi;
    354 
    355   //
    356   // find HIDSTR
    357   //
    358   Anchor = 16;
    359   for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
    360     ;
    361   }
    362   if (Index > Anchor) {
    363     HIDSTRIdx = Anchor;
    364   }
    365   //
    366   // find UIDSTR
    367   //
    368   Anchor = (UINT16) (Index + 1);
    369   for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
    370     ;
    371   }
    372   if (Index > Anchor) {
    373     UIDSTRIdx = Anchor;
    374   }
    375   //
    376   // find CIDSTR
    377   //
    378   Anchor = (UINT16) (Index + 1);
    379   for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
    380     ;
    381   }
    382   if (Index > Anchor) {
    383     CIDSTRIdx = Anchor;
    384   }
    385 
    386   if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
    387     CatPrint (Str, L"AcpiExp(");
    388     if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
    389       CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
    390     } else {
    391       CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
    392     }
    393     if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
    394       CatPrint (Str, L"PNP%04x,", (UINTN)  EISA_ID_TO_NUM (ExtendedAcpi->CID));
    395     } else {
    396       CatPrint (Str, L"%08x,", (UINTN)  ExtendedAcpi->CID);
    397     }
    398     if (UIDSTRIdx != 0) {
    399       CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
    400     } else {
    401       CatPrint (Str, L"\"\")");
    402     }
    403   } else {
    404     CatPrint (Str, L"AcpiEx(");
    405     if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
    406       CatPrint (Str, L"PNP%04x,", (UINTN)  EISA_ID_TO_NUM (ExtendedAcpi->HID));
    407     } else {
    408       CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
    409     }
    410     if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
    411       CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
    412     } else {
    413       CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
    414     }
    415     CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);
    416 
    417     if (HIDSTRIdx != 0) {
    418       CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
    419     } else {
    420       CatPrint (Str, L"\"\",");
    421     }
    422     if (CIDSTRIdx != 0) {
    423       CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
    424     } else {
    425       CatPrint (Str, L"\"\",");
    426     }
    427     if (UIDSTRIdx != 0) {
    428       CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
    429     } else {
    430       CatPrint (Str, L"\"\")");
    431     }
    432   }
    433 
    434 }
    435 
    436 /**
    437   Convert Device Path to a Unicode string for printing.
    438 
    439   @param Str             The buffer holding the output string.
    440                          This buffer contains the length of the
    441                          string and the maixmum length reserved
    442                          for the string buffer.
    443   @param DevPath         The device path.
    444 
    445 **/
    446 VOID
    447 DevPathAdrAcpi (
    448   IN OUT POOL_PRINT       *Str,
    449   IN VOID                 *DevPath
    450   )
    451 {
    452   ACPI_ADR_DEVICE_PATH    *AcpiAdr;
    453   UINT16                  Index;
    454   UINT16                  Length;
    455   UINT16                  AdditionalAdrCount;
    456 
    457   AcpiAdr            = DevPath;
    458   Length             = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
    459   AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
    460 
    461   CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);
    462   for (Index = 0; Index < AdditionalAdrCount; Index++) {
    463     CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
    464   }
    465   CatPrint (Str, L")");
    466 }
    467 
    468 /**
    469   Convert Device Path to a Unicode string for printing.
    470 
    471   @param Str             The buffer holding the output string.
    472                          This buffer contains the length of the
    473                          string and the maixmum length reserved
    474                          for the string buffer.
    475   @param DevPath         The device path.
    476 
    477 **/
    478 VOID
    479 DevPathAtapi (
    480   IN OUT POOL_PRINT       *Str,
    481   IN VOID                 *DevPath
    482   )
    483 {
    484   ATAPI_DEVICE_PATH *Atapi;
    485 
    486   Atapi = DevPath;
    487   CatPrint (
    488     Str,
    489     L"Ata(%s,%s)",
    490     (Atapi->PrimarySecondary != 0)? L"Secondary" : L"Primary",
    491     (Atapi->SlaveMaster != 0)? L"Slave" : L"Master"
    492     );
    493 }
    494 
    495 /**
    496   Convert Device Path to a Unicode string for printing.
    497 
    498   @param Str             The buffer holding the output string.
    499                          This buffer contains the length of the
    500                          string and the maixmum length reserved
    501                          for the string buffer.
    502   @param DevPath         The device path.
    503 
    504 **/
    505 VOID
    506 DevPathScsi (
    507   IN OUT POOL_PRINT       *Str,
    508   IN VOID                 *DevPath
    509   )
    510 {
    511   SCSI_DEVICE_PATH  *Scsi;
    512 
    513   Scsi = DevPath;
    514   CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);
    515 }
    516 
    517 /**
    518   Convert Device Path to a Unicode string for printing.
    519 
    520   @param Str             The buffer holding the output string.
    521                          This buffer contains the length of the
    522                          string and the maixmum length reserved
    523                          for the string buffer.
    524   @param DevPath         The device path.
    525 
    526 **/
    527 VOID
    528 DevPathFibre (
    529   IN OUT POOL_PRINT       *Str,
    530   IN VOID                 *DevPath
    531   )
    532 {
    533   FIBRECHANNEL_DEVICE_PATH  *Fibre;
    534 
    535   Fibre = DevPath;
    536   CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
    537 }
    538 
    539 /**
    540   Convert Device Path to a Unicode string for printing.
    541 
    542   @param Str             The buffer holding the output string.
    543                          This buffer contains the length of the
    544                          string and the maixmum length reserved
    545                          for the string buffer.
    546   @param DevPath         The device path.
    547 
    548 **/
    549 VOID
    550 DevPath1394 (
    551   IN OUT POOL_PRINT       *Str,
    552   IN VOID                 *DevPath
    553   )
    554 {
    555   F1394_DEVICE_PATH *F1394Path;
    556 
    557   F1394Path = DevPath;
    558   CatPrint (Str, L"1394(%lx)", &F1394Path->Guid);
    559 }
    560 
    561 /**
    562   Convert Device Path to a Unicode string for printing.
    563 
    564   @param Str             The buffer holding the output string.
    565                          This buffer contains the length of the
    566                          string and the maixmum length reserved
    567                          for the string buffer.
    568   @param DevPath         The device path.
    569 
    570 **/
    571 VOID
    572 DevPathUsb (
    573   IN OUT POOL_PRINT       *Str,
    574   IN VOID                 *DevPath
    575   )
    576 {
    577   USB_DEVICE_PATH *Usb;
    578 
    579   Usb = DevPath;
    580   CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);
    581 }
    582 
    583 /**
    584   Convert Device Path to a Unicode string for printing.
    585 
    586   @param Str             The buffer holding the output string.
    587                          This buffer contains the length of the
    588                          string and the maixmum length reserved
    589                          for the string buffer.
    590   @param DevPath         The device path.
    591 
    592 **/
    593 VOID
    594 DevPathUsbWWID (
    595   IN OUT POOL_PRINT       *Str,
    596   IN VOID                 *DevPath
    597   )
    598 {
    599   USB_WWID_DEVICE_PATH  *UsbWWId;
    600 
    601   UsbWWId = DevPath;
    602   CatPrint (
    603     Str,
    604     L"UsbWwid(%x,%x,%x,\"WWID\")",
    605     (UINTN) UsbWWId->VendorId,
    606     (UINTN) UsbWWId->ProductId,
    607     (UINTN) UsbWWId->InterfaceNumber
    608     );
    609 }
    610 
    611 /**
    612   Convert Device Path to a Unicode string for printing.
    613 
    614   @param Str             The buffer holding the output string.
    615                          This buffer contains the length of the
    616                          string and the maixmum length reserved
    617                          for the string buffer.
    618   @param DevPath         The device path.
    619 
    620 **/
    621 VOID
    622 DevPathLogicalUnit (
    623   IN OUT POOL_PRINT       *Str,
    624   IN VOID                 *DevPath
    625   )
    626 {
    627   DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
    628 
    629   LogicalUnit = DevPath;
    630   CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);
    631 }
    632 
    633 /**
    634   Convert Device Path to a Unicode string for printing.
    635 
    636   @param Str             The buffer holding the output string.
    637                          This buffer contains the length of the
    638                          string and the maixmum length reserved
    639                          for the string buffer.
    640   @param DevPath         The device path.
    641 
    642 **/
    643 VOID
    644 DevPathUsbClass (
    645   IN OUT POOL_PRINT       *Str,
    646   IN VOID                 *DevPath
    647   )
    648 {
    649   USB_CLASS_DEVICE_PATH *UsbClass;
    650 
    651   UsbClass = DevPath;
    652   CatPrint (
    653     Str,
    654     L"Usb Class(%x,%x,%x,%x,%x)",
    655     (UINTN) UsbClass->VendorId,
    656     (UINTN) UsbClass->ProductId,
    657     (UINTN) UsbClass->DeviceClass,
    658     (UINTN) UsbClass->DeviceSubClass,
    659     (UINTN) UsbClass->DeviceProtocol
    660     );
    661 }
    662 
    663 /**
    664   Convert Device Path to a Unicode string for printing.
    665 
    666   @param Str             The buffer holding the output string.
    667                          This buffer contains the length of the
    668                          string and the maixmum length reserved
    669                          for the string buffer.
    670   @param DevPath         The device path.
    671 
    672 **/
    673 VOID
    674 DevPathSata (
    675   IN OUT POOL_PRINT       *Str,
    676   IN VOID                 *DevPath
    677   )
    678 {
    679   SATA_DEVICE_PATH *Sata;
    680 
    681   Sata = DevPath;
    682   if ((Sata->PortMultiplierPortNumber & SATA_HBA_DIRECT_CONNECT_FLAG) != 0) {
    683     CatPrint (
    684       Str,
    685       L"Sata(%x,%x)",
    686       (UINTN) Sata->HBAPortNumber,
    687       (UINTN) Sata->Lun
    688       );
    689   } else {
    690     CatPrint (
    691       Str,
    692       L"Sata(%x,%x,%x)",
    693       (UINTN) Sata->HBAPortNumber,
    694       (UINTN) Sata->PortMultiplierPortNumber,
    695       (UINTN) Sata->Lun
    696       );
    697   }
    698 }
    699 
    700 /**
    701   Convert Device Path to a Unicode string for printing.
    702 
    703   @param Str             The buffer holding the output string.
    704                          This buffer contains the length of the
    705                          string and the maixmum length reserved
    706                          for the string buffer.
    707   @param DevPath         The device path.
    708 
    709 **/
    710 VOID
    711 DevPathI2O (
    712   IN OUT POOL_PRINT       *Str,
    713   IN VOID                 *DevPath
    714   )
    715 {
    716   I2O_DEVICE_PATH *I2OPath;
    717 
    718   I2OPath = DevPath;
    719   CatPrint (Str, L"I2O(%x)", (UINTN) I2OPath->Tid);
    720 }
    721 
    722 /**
    723   Convert Device Path to a Unicode string for printing.
    724 
    725   @param Str             The buffer holding the output string.
    726                          This buffer contains the length of the
    727                          string and the maixmum length reserved
    728                          for the string buffer.
    729   @param DevPath         The device path.
    730 
    731 **/
    732 VOID
    733 DevPathMacAddr (
    734   IN OUT POOL_PRINT       *Str,
    735   IN VOID                 *DevPath
    736   )
    737 {
    738   MAC_ADDR_DEVICE_PATH  *MACDevPath;
    739   UINTN                 HwAddressSize;
    740   UINTN                 Index;
    741 
    742   MACDevPath           = DevPath;
    743 
    744   HwAddressSize = sizeof (EFI_MAC_ADDRESS);
    745   if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {
    746     HwAddressSize = 6;
    747   }
    748 
    749   CatPrint (Str, L"Mac(");
    750 
    751   for (Index = 0; Index < HwAddressSize; Index++) {
    752     CatPrint (Str, L"%02x", (UINTN) MACDevPath->MacAddress.Addr[Index]);
    753   }
    754 
    755   CatPrint (Str, L")");
    756 }
    757 
    758 /**
    759   Convert Device Path to a Unicode string for printing.
    760 
    761   @param Str             The buffer holding the output string.
    762                          This buffer contains the length of the
    763                          string and the maixmum length reserved
    764                          for the string buffer.
    765   @param DevPath         The device path.
    766 
    767 **/
    768 VOID
    769 DevPathIPv4 (
    770   IN OUT POOL_PRINT       *Str,
    771   IN VOID                 *DevPath
    772   )
    773 {
    774   IPv4_DEVICE_PATH  *IPDevPath;
    775 
    776   IPDevPath = DevPath;
    777   CatPrint (
    778     Str,
    779     L"IPv4(%d.%d.%d.%d:%d)",
    780     (UINTN) IPDevPath->RemoteIpAddress.Addr[0],
    781     (UINTN) IPDevPath->RemoteIpAddress.Addr[1],
    782     (UINTN) IPDevPath->RemoteIpAddress.Addr[2],
    783     (UINTN) IPDevPath->RemoteIpAddress.Addr[3],
    784     (UINTN) IPDevPath->RemotePort
    785     );
    786 }
    787 
    788 /**
    789   Convert Device Path to a Unicode string for printing.
    790 
    791   @param Str             The buffer holding the output string.
    792                          This buffer contains the length of the
    793                          string and the maixmum length reserved
    794                          for the string buffer.
    795   @param DevPath         The device path.
    796 
    797 **/
    798 VOID
    799 DevPathIPv6 (
    800   IN OUT POOL_PRINT       *Str,
    801   IN VOID                 *DevPath
    802   )
    803 {
    804   IPv6_DEVICE_PATH  *IPv6DevPath;
    805 
    806   IPv6DevPath = DevPath;
    807   CatPrint (
    808     Str,
    809     L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
    810     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[0],
    811     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[1],
    812     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[2],
    813     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[3],
    814     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[4],
    815     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[5],
    816     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[6],
    817     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[7],
    818     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[8],
    819     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[9],
    820     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[10],
    821     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[11],
    822     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[12],
    823     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[13],
    824     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[14],
    825     (UINTN) IPv6DevPath->RemoteIpAddress.Addr[15]
    826     );
    827 }
    828 
    829 /**
    830   Convert Device Path to a Unicode string for printing.
    831 
    832   @param Str             The buffer holding the output string.
    833                          This buffer contains the length of the
    834                          string and the maixmum length reserved
    835                          for the string buffer.
    836   @param DevPath         The device path.
    837 
    838 **/
    839 VOID
    840 DevPathInfiniBand (
    841   IN OUT POOL_PRINT       *Str,
    842   IN VOID                 *DevPath
    843   )
    844 {
    845   INFINIBAND_DEVICE_PATH  *InfiniBand;
    846 
    847   InfiniBand = DevPath;
    848   CatPrint (
    849     Str,
    850     L"Infiniband(%x,%g,%lx,%lx,%lx)",
    851     (UINTN) InfiniBand->ResourceFlags,
    852     InfiniBand->PortGid,
    853     InfiniBand->ServiceId,
    854     InfiniBand->TargetPortId,
    855     InfiniBand->DeviceId
    856     );
    857 }
    858 
    859 /**
    860   Convert Device Path to a Unicode string for printing.
    861 
    862   @param Str             The buffer holding the output string.
    863                          This buffer contains the length of the
    864                          string and the maixmum length reserved
    865                          for the string buffer.
    866   @param DevPath         The device path.
    867 
    868 **/
    869 VOID
    870 DevPathUart (
    871   IN OUT POOL_PRINT       *Str,
    872   IN VOID                 *DevPath
    873   )
    874 {
    875   UART_DEVICE_PATH  *Uart;
    876   CHAR8             Parity;
    877 
    878   Uart = DevPath;
    879   switch (Uart->Parity) {
    880   case 0:
    881     Parity = 'D';
    882     break;
    883 
    884   case 1:
    885     Parity = 'N';
    886     break;
    887 
    888   case 2:
    889     Parity = 'E';
    890     break;
    891 
    892   case 3:
    893     Parity = 'O';
    894     break;
    895 
    896   case 4:
    897     Parity = 'M';
    898     break;
    899 
    900   case 5:
    901     Parity = 'S';
    902     break;
    903 
    904   default:
    905     Parity = 'x';
    906     break;
    907   }
    908 
    909   if (Uart->BaudRate == 0) {
    910     CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);
    911   } else {
    912     CatPrint (Str, L"Uart(%ld,%c,", Uart->BaudRate, Parity);
    913   }
    914 
    915   if (Uart->DataBits == 0) {
    916     CatPrint (Str, L"D,");
    917   } else {
    918     CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);
    919   }
    920 
    921   switch (Uart->StopBits) {
    922   case 0:
    923     CatPrint (Str, L"D)");
    924     break;
    925 
    926   case 1:
    927     CatPrint (Str, L"1)");
    928     break;
    929 
    930   case 2:
    931     CatPrint (Str, L"1.5)");
    932     break;
    933 
    934   case 3:
    935     CatPrint (Str, L"2)");
    936     break;
    937 
    938   default:
    939     CatPrint (Str, L"x)");
    940     break;
    941   }
    942 }
    943 
    944 /**
    945   Convert Device Path to a Unicode string for printing.
    946 
    947   @param Str             The buffer holding the output string.
    948                          This buffer contains the length of the
    949                          string and the maixmum length reserved
    950                          for the string buffer.
    951   @param DevPath         The device path.
    952 
    953 **/
    954 VOID
    955 DevPathiSCSI (
    956   IN OUT POOL_PRINT       *Str,
    957   IN VOID                 *DevPath
    958   )
    959 {
    960   ISCSI_DEVICE_PATH_WITH_NAME *IScsi;
    961   UINT16                      Options;
    962 
    963   IScsi = DevPath;
    964   CatPrint (
    965     Str,
    966     L"iSCSI(%a,%x,%lx,",
    967     IScsi->TargetName,
    968     (UINTN) IScsi->TargetPortalGroupTag,
    969     IScsi->Lun
    970     );
    971 
    972   Options = IScsi->LoginOption;
    973   CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
    974   CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
    975   if (((Options >> 11) & 0x0001) != 0) {
    976     CatPrint (Str, L"%s,", L"None");
    977   } else if (((Options >> 12) & 0x0001) != 0) {
    978     CatPrint (Str, L"%s,", L"CHAP_UNI");
    979   } else {
    980     CatPrint (Str, L"%s,", L"CHAP_BI");
    981 
    982   }
    983 
    984   CatPrint (Str, L"%s)", (IScsi->NetworkProtocol == 0) ? L"TCP" : L"reserved");
    985 }
    986 
    987 /**
    988   Convert Device Path to a Unicode string for printing.
    989 
    990   @param Str             The buffer holding the output string.
    991                          This buffer contains the length of the
    992                          string and the maixmum length reserved
    993                          for the string buffer.
    994   @param DevPath         The device path.
    995 
    996 **/
    997 VOID
    998 DevPathVlan (
    999   IN OUT POOL_PRINT       *Str,
    1000   IN VOID                 *DevPath
    1001   )
    1002 {
    1003   VLAN_DEVICE_PATH  *Vlan;
    1004 
    1005   Vlan = DevPath;
    1006   CatPrint (Str, L"Vlan(%d)", (UINTN) Vlan->VlanId);
    1007 }
    1008 
    1009 /**
    1010   Convert Device Path to a Unicode string for printing.
    1011 
    1012   @param Str             The buffer holding the output string.
    1013                          This buffer contains the length of the
    1014                          string and the maixmum length reserved
    1015                          for the string buffer.
    1016   @param DevPath         The device path.
    1017 
    1018 **/
    1019 VOID
    1020 DevPathHardDrive (
    1021   IN OUT POOL_PRINT       *Str,
    1022   IN VOID                 *DevPath
    1023   )
    1024 {
    1025   HARDDRIVE_DEVICE_PATH *Hd;
    1026 
    1027   Hd = DevPath;
    1028   switch (Hd->SignatureType) {
    1029   case SIGNATURE_TYPE_MBR:
    1030     CatPrint (
    1031       Str,
    1032       L"HD(Part%d,Sig%08x)",
    1033       (UINTN) Hd->PartitionNumber,
    1034       (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
    1035       );
    1036     break;
    1037 
    1038   case SIGNATURE_TYPE_GUID:
    1039     CatPrint (
    1040       Str,
    1041       L"HD(Part%d,Sig%g)",
    1042       (UINTN) Hd->PartitionNumber,
    1043       (EFI_GUID *) &(Hd->Signature[0])
    1044       );
    1045     break;
    1046 
    1047   default:
    1048     CatPrint (
    1049       Str,
    1050       L"HD(Part%d,MBRType=%02x,SigType=%02x)",
    1051       (UINTN) Hd->PartitionNumber,
    1052       (UINTN) Hd->MBRType,
    1053       (UINTN) Hd->SignatureType
    1054       );
    1055     break;
    1056   }
    1057 }
    1058 
    1059 /**
    1060   Convert Device Path to a Unicode string for printing.
    1061 
    1062   @param Str             The buffer holding the output string.
    1063                          This buffer contains the length of the
    1064                          string and the maixmum length reserved
    1065                          for the string buffer.
    1066   @param DevPath         The device path.
    1067 
    1068 **/
    1069 VOID
    1070 DevPathCDROM (
    1071   IN OUT POOL_PRINT       *Str,
    1072   IN VOID                 *DevPath
    1073   )
    1074 {
    1075   CDROM_DEVICE_PATH *Cd;
    1076 
    1077   Cd = DevPath;
    1078   CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
    1079 }
    1080 
    1081 /**
    1082   Convert Device Path to a Unicode string for printing.
    1083 
    1084   @param Str             The buffer holding the output string.
    1085                          This buffer contains the length of the
    1086                          string and the maixmum length reserved
    1087                          for the string buffer.
    1088   @param DevPath         The device path.
    1089 
    1090 **/
    1091 VOID
    1092 DevPathFilePath (
    1093   IN OUT POOL_PRINT       *Str,
    1094   IN VOID                 *DevPath
    1095   )
    1096 {
    1097   FILEPATH_DEVICE_PATH  *Fp;
    1098 
    1099   Fp = DevPath;
    1100   CatPrint (Str, L"%s", Fp->PathName);
    1101 }
    1102 
    1103 /**
    1104   Convert Device Path to a Unicode string for printing.
    1105 
    1106   @param Str             The buffer holding the output string.
    1107                          This buffer contains the length of the
    1108                          string and the maixmum length reserved
    1109                          for the string buffer.
    1110   @param DevPath         The device path.
    1111 
    1112 **/
    1113 VOID
    1114 DevPathMediaProtocol (
    1115   IN OUT POOL_PRINT       *Str,
    1116   IN VOID                 *DevPath
    1117   )
    1118 {
    1119   MEDIA_PROTOCOL_DEVICE_PATH  *MediaProt;
    1120 
    1121   MediaProt = DevPath;
    1122   CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
    1123 }
    1124 
    1125 /**
    1126   Convert Device Path to a Unicode string for printing.
    1127 
    1128   @param Str             The buffer holding the output string.
    1129                          This buffer contains the length of the
    1130                          string and the maixmum length reserved
    1131                          for the string buffer.
    1132   @param DevPath         The device path.
    1133 
    1134 **/
    1135 VOID
    1136 DevPathFvFilePath (
    1137   IN OUT POOL_PRINT       *Str,
    1138   IN VOID                 *DevPath
    1139   )
    1140 {
    1141   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
    1142 
    1143   FvFilePath = DevPath;
    1144   CatPrint (Str, L"%g", &FvFilePath->FvFileName);
    1145 }
    1146 
    1147 /**
    1148   Convert Device Path to a Unicode string for printing.
    1149 
    1150   @param Str             The buffer holding the output string.
    1151                          This buffer contains the length of the
    1152                          string and the maixmum length reserved
    1153                          for the string buffer.
    1154   @param DevPath         The device path.
    1155 
    1156 **/
    1157 VOID
    1158 DevPathRelativeOffsetRange (
    1159   IN OUT POOL_PRINT       *Str,
    1160   IN VOID                 *DevPath
    1161   )
    1162 {
    1163   MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
    1164 
    1165   Offset = DevPath;
    1166   CatPrint (
    1167     Str,
    1168     L"Offset(%lx,%lx)",
    1169     Offset->StartingOffset,
    1170     Offset->EndingOffset
    1171     );
    1172 }
    1173 
    1174 /**
    1175   Convert Device Path to a Unicode string for printing.
    1176 
    1177   @param Str             The buffer holding the output string.
    1178                          This buffer contains the length of the
    1179                          string and the maixmum length reserved
    1180                          for the string buffer.
    1181   @param DevPath         The device path.
    1182 
    1183 **/
    1184 VOID
    1185 DevPathBssBss (
    1186   IN OUT POOL_PRINT       *Str,
    1187   IN VOID                 *DevPath
    1188   )
    1189 {
    1190   BBS_BBS_DEVICE_PATH *Bbs;
    1191   CHAR16              *Type;
    1192 
    1193   Bbs = DevPath;
    1194   switch (Bbs->DeviceType) {
    1195   case BBS_TYPE_FLOPPY:
    1196     Type = L"Floppy";
    1197     break;
    1198 
    1199   case BBS_TYPE_HARDDRIVE:
    1200     Type = L"Harddrive";
    1201     break;
    1202 
    1203   case BBS_TYPE_CDROM:
    1204     Type = L"CDROM";
    1205     break;
    1206 
    1207   case BBS_TYPE_PCMCIA:
    1208     Type = L"PCMCIA";
    1209     break;
    1210 
    1211   case BBS_TYPE_USB:
    1212     Type = L"Usb";
    1213     break;
    1214 
    1215   case BBS_TYPE_EMBEDDED_NETWORK:
    1216     Type = L"Net";
    1217     break;
    1218 
    1219   case BBS_TYPE_BEV:
    1220     Type = L"BEV";
    1221     break;
    1222 
    1223   default:
    1224     Type = L"?";
    1225     break;
    1226   }
    1227   CatPrint (Str, L"Legacy-%s", Type);
    1228 }
    1229 
    1230 /**
    1231   Convert Device Path to a Unicode string for printing.
    1232 
    1233   @param Str             The buffer holding the output string.
    1234                          This buffer contains the length of the
    1235                          string and the maixmum length reserved
    1236                          for the string buffer.
    1237   @param DevPath         The device path.
    1238 
    1239 **/
    1240 VOID
    1241 DevPathEndInstance (
    1242   IN OUT POOL_PRINT       *Str,
    1243   IN VOID                 *DevPath
    1244   )
    1245 {
    1246   CatPrint (Str, L",");
    1247 }
    1248 
    1249 /**
    1250   Convert Device Path to a Unicode string for printing.
    1251 
    1252   @param Str             The buffer holding the output string.
    1253                          This buffer contains the length of the
    1254                          string and the maixmum length reserved
    1255                          for the string buffer.
    1256   @param DevPath         The device path.
    1257 
    1258 **/
    1259 VOID
    1260 DevPathNodeUnknown (
    1261   IN OUT POOL_PRINT       *Str,
    1262   IN VOID                 *DevPath
    1263   )
    1264 {
    1265   CatPrint (Str, L"?");
    1266 }
    1267 /**
    1268   Convert Device Path to a Unicode string for printing.
    1269 
    1270   @param Str             The buffer holding the output string.
    1271                          This buffer contains the length of the
    1272                          string and the maximum length reserved
    1273                          for the string buffer.
    1274   @param DevPath         The device path.
    1275 
    1276 **/
    1277 VOID
    1278 DevPathFvPath (
    1279   IN OUT POOL_PRINT       *Str,
    1280   IN VOID                 *DevPath
    1281   )
    1282 {
    1283   MEDIA_FW_VOL_DEVICE_PATH *FvPath;
    1284 
    1285   FvPath = DevPath;
    1286   CatPrint (Str, L"Fv(%g)", &FvPath->FvName);
    1287 }
    1288 
    1289 DEVICE_PATH_STRING_TABLE  DevPathTable[] = {
    1290   {
    1291     HARDWARE_DEVICE_PATH,
    1292     HW_PCI_DP,
    1293     DevPathPci
    1294   },
    1295   {
    1296     HARDWARE_DEVICE_PATH,
    1297     HW_PCCARD_DP,
    1298     DevPathPccard
    1299   },
    1300   {
    1301     HARDWARE_DEVICE_PATH,
    1302     HW_MEMMAP_DP,
    1303     DevPathMemMap
    1304   },
    1305   {
    1306     HARDWARE_DEVICE_PATH,
    1307     HW_VENDOR_DP,
    1308     DevPathVendor
    1309   },
    1310   {
    1311     HARDWARE_DEVICE_PATH,
    1312     HW_CONTROLLER_DP,
    1313     DevPathController
    1314   },
    1315   {
    1316     ACPI_DEVICE_PATH,
    1317     ACPI_DP,
    1318     DevPathAcpi
    1319   },
    1320   {
    1321     ACPI_DEVICE_PATH,
    1322     ACPI_EXTENDED_DP,
    1323     DevPathExtendedAcpi
    1324   },
    1325   {
    1326     ACPI_DEVICE_PATH,
    1327     ACPI_ADR_DP,
    1328     DevPathAdrAcpi
    1329   },
    1330   {
    1331     MESSAGING_DEVICE_PATH,
    1332     MSG_ATAPI_DP,
    1333     DevPathAtapi
    1334   },
    1335   {
    1336     MESSAGING_DEVICE_PATH,
    1337     MSG_SCSI_DP,
    1338     DevPathScsi
    1339   },
    1340   {
    1341     MESSAGING_DEVICE_PATH,
    1342     MSG_FIBRECHANNEL_DP,
    1343     DevPathFibre
    1344   },
    1345   {
    1346     MESSAGING_DEVICE_PATH,
    1347     MSG_1394_DP,
    1348     DevPath1394
    1349   },
    1350   {
    1351     MESSAGING_DEVICE_PATH,
    1352     MSG_USB_DP,
    1353     DevPathUsb
    1354   },
    1355   {
    1356     MESSAGING_DEVICE_PATH,
    1357     MSG_USB_WWID_DP,
    1358     DevPathUsbWWID
    1359   },
    1360   {
    1361     MESSAGING_DEVICE_PATH,
    1362     MSG_DEVICE_LOGICAL_UNIT_DP,
    1363     DevPathLogicalUnit
    1364   },
    1365   {
    1366     MESSAGING_DEVICE_PATH,
    1367     MSG_USB_CLASS_DP,
    1368     DevPathUsbClass
    1369   },
    1370   {
    1371     MESSAGING_DEVICE_PATH,
    1372     MSG_SATA_DP,
    1373     DevPathSata
    1374   },
    1375   {
    1376     MESSAGING_DEVICE_PATH,
    1377     MSG_I2O_DP,
    1378     DevPathI2O
    1379   },
    1380   {
    1381     MESSAGING_DEVICE_PATH,
    1382     MSG_MAC_ADDR_DP,
    1383     DevPathMacAddr
    1384   },
    1385   {
    1386     MESSAGING_DEVICE_PATH,
    1387     MSG_IPv4_DP,
    1388     DevPathIPv4
    1389   },
    1390   {
    1391     MESSAGING_DEVICE_PATH,
    1392     MSG_IPv6_DP,
    1393     DevPathIPv6
    1394   },
    1395   {
    1396     MESSAGING_DEVICE_PATH,
    1397     MSG_INFINIBAND_DP,
    1398     DevPathInfiniBand
    1399   },
    1400   {
    1401     MESSAGING_DEVICE_PATH,
    1402     MSG_UART_DP,
    1403     DevPathUart
    1404   },
    1405   {
    1406     MESSAGING_DEVICE_PATH,
    1407     MSG_VENDOR_DP,
    1408     DevPathVendor
    1409   },
    1410   {
    1411     MESSAGING_DEVICE_PATH,
    1412     MSG_ISCSI_DP,
    1413     DevPathiSCSI
    1414   },
    1415   {
    1416     MESSAGING_DEVICE_PATH,
    1417     MSG_VLAN_DP,
    1418     DevPathVlan
    1419   },
    1420   {
    1421     MEDIA_DEVICE_PATH,
    1422     MEDIA_HARDDRIVE_DP,
    1423     DevPathHardDrive
    1424   },
    1425   {
    1426     MEDIA_DEVICE_PATH,
    1427     MEDIA_CDROM_DP,
    1428     DevPathCDROM
    1429   },
    1430   {
    1431     MEDIA_DEVICE_PATH,
    1432     MEDIA_VENDOR_DP,
    1433     DevPathVendor
    1434   },
    1435   {
    1436     MEDIA_DEVICE_PATH,
    1437     MEDIA_FILEPATH_DP,
    1438     DevPathFilePath
    1439   },
    1440   {
    1441     MEDIA_DEVICE_PATH,
    1442     MEDIA_PROTOCOL_DP,
    1443     DevPathMediaProtocol
    1444   },
    1445   {
    1446     MEDIA_DEVICE_PATH,
    1447     MEDIA_PIWG_FW_VOL_DP,
    1448     DevPathFvPath,
    1449   },
    1450   {
    1451     MEDIA_DEVICE_PATH,
    1452     MEDIA_PIWG_FW_FILE_DP,
    1453     DevPathFvFilePath
    1454   },
    1455   {
    1456     MEDIA_DEVICE_PATH,
    1457     MEDIA_RELATIVE_OFFSET_RANGE_DP,
    1458     DevPathRelativeOffsetRange,
    1459   },
    1460   {
    1461     BBS_DEVICE_PATH,
    1462     BBS_BBS_DP,
    1463     DevPathBssBss
    1464   },
    1465   {
    1466     END_DEVICE_PATH_TYPE,
    1467     END_INSTANCE_DEVICE_PATH_SUBTYPE,
    1468     DevPathEndInstance
    1469   },
    1470   {
    1471     0,
    1472     0,
    1473     NULL
    1474   }
    1475 };
    1476 
    147717
    147818/**
     
    149030  )
    149131{
    1492   POOL_PRINT                Str;
    1493   EFI_DEVICE_PATH_PROTOCOL  *DevPathNode;
    1494   VOID (*DumpNode) (POOL_PRINT *, VOID *);
    1495 
    1496   UINTN Index;
    1497   UINTN NewSize;
    1498 
    1499   EFI_STATUS                       Status;
    1500   CHAR16                           *ToText;
    1501   EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
    1502 
    1503   ZeroMem (&Str, sizeof (Str));
    1504 
    1505   if (DevPath == NULL) {
    1506     goto Done;
    1507   }
    1508 
    1509   Status = gBS->LocateProtocol (
    1510                   &gEfiDevicePathToTextProtocolGuid,
    1511                   NULL,
    1512                   (VOID **) &DevPathToText
    1513                   );
    1514   if (!EFI_ERROR (Status)) {
    1515     ToText = DevPathToText->ConvertDevicePathToText (
    1516                               DevPath,
    1517                               FALSE,
    1518                               TRUE
    1519                               );
    1520     ASSERT (ToText != NULL);
    1521     return ToText;
    1522   }
    1523 
    1524   //
    1525   // Process each device path node
    1526   //
    1527   DevPathNode = DevPath;
    1528   while (!IsDevicePathEnd (DevPathNode)) {
    1529     //
    1530     // Find the handler to dump this device path node
    1531     //
    1532     DumpNode = NULL;
    1533     for (Index = 0; DevPathTable[Index].Function != NULL; Index += 1) {
    1534 
    1535       if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
    1536           DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
    1537           ) {
    1538         DumpNode = DevPathTable[Index].Function;
    1539         break;
    1540       }
    1541     }
    1542     //
    1543     // If not found, use a generic function
    1544     //
    1545     if (!DumpNode) {
    1546       DumpNode = DevPathNodeUnknown;
    1547     }
    1548     //
    1549     //  Put a path seperator in if needed
    1550     //
    1551     if ((Str.Len != 0) && (DumpNode != DevPathEndInstance)) {
    1552       CatPrint (&Str, L"/");
    1553     }
    1554     //
    1555     // Print this node of the device path
    1556     //
    1557     DumpNode (&Str, DevPathNode);
    1558 
    1559     //
    1560     // Next device path node
    1561     //
    1562     DevPathNode = NextDevicePathNode (DevPathNode);
    1563   }
    1564 
    1565 Done:
    1566   NewSize = (Str.Len + 1) * sizeof (CHAR16);
    1567   Str.Str = ReallocatePool (NewSize, NewSize, Str.Str);
    1568   ASSERT (Str.Str != NULL);
    1569   Str.Str[Str.Len] = 0;
    1570   return Str.Str;
     32  return ConvertDevicePathToText (DevPath, TRUE, TRUE);
    157133}
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf

    r48674 r58459  
    11## @file
     2#  General BDS library.
    23
    34#  General BDS defines and produce general interfaces for platform BDS driver including:
     
    67#  3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
    78
    8 #  Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
     9#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
    910#  This program and the accompanying materials
    1011#  are licensed and made available under the terms and conditions of the BSD License
     
    2021  INF_VERSION                    = 0x00010005
    2122  BASE_NAME                      = GenericBdsLib
     23  MODULE_UNI_FILE                = GenericBdsLib.uni
    2224  FILE_GUID                      = e405ec31-ccaa-4dd4-83e8-0aec01703f7e
    2325  MODULE_TYPE                    = DXE_DRIVER
    2426  VERSION_STRING                 = 1.0
    25   LIBRARY_CLASS                  = GenericBdsLib|DXE_DRIVER UEFI_APPLICATION
     27  LIBRARY_CLASS                  = GenericBdsLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
    2628  CONSTRUCTOR                    = GenericBdsLibConstructor
    2729
     
    7173
    7274[Guids]
    73   gEfiVT100PlusGuid                             ## CONSUMES ## GUID (The type of terminal)
    74   gEfiVT100Guid                                 ## CONSUMES ## GUID (The type of terminal)
    75                                                 ## CONSUMES ## GUID HOB (The hob holding memory type information)
    76   gEfiMemoryTypeInformationGuid                 ## CONSUMES ## GUID (The identifier of memory type information type in system table)
    77   gEfiVTUTF8Guid                                ## CONSUMES ## GUID (The type of terminal)
    78                                                 ## SOMETIMES_CONSUMES ## Variable:L"BootXX" (Boot option variable)
    79                                                 ## CONSUMES           ## Variable:L"Timeout" (The time out value in second of showing progress bar)
    80                                                 ## SOMETIMES_CONSUMES ## Variable:L"BootOrder" (The boot option array)
    81                                                 ## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" (The driver order list)
    82                                                 ## SOMETIMES_CONSUMES ## Variable:L"ConIn" (The device path of console in device)
    83                                                 ## SOMETIMES_CONSUMES ## Variable:L"ConOut" (The device path of console out device)
    84                                                 ## SOMETIMES_CONSUMES ## Variable:L"ErrOut" (The device path of error out device)
    85   gEfiGlobalVariableGuid                        ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" (The boot option of current boot)
    86   gEfiFileInfoGuid                              ## CONSUMES ## GUID
    87   gEfiPcAnsiGuid                                ## CONSUMES ## GUID (The type of terminal)
    88   gPerformanceProtocolGuid                      ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" (The ACPI address of performance data)
    89   gEfiUartDevicePathGuid                        ## CONSUMES ## GUID (Identify the device path for UARD device)
    90   gEfiSasDevicePathGuid                         ## CONSUMES ## GUID (Identify the device path for SAS device)
    91   gLastEnumLangGuid                             ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" (Platform language at last time enumeration.)
    92   gHdBootDevicePathVariablGuid                  ## SOMETIMES_PRODUCES ## Variable:L"HDDP" (The device path of Boot file on Hard device.)
    93   gBdsLibStringPackageGuid                      ## PRODUCES ## GUID (HII String PackageList Guid)
     75  ## SOMETIMES_CONSUMES ## HOB         # The hob holding memory type information
     76  ## SOMETIMES_CONSUMES ## SystemTable # The identifier of memory type information type in system table
     77  ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"
     78  ## SOMETIMES_PRODUCES ## Variable:L"MemoryTypeInformation"
     79  gEfiMemoryTypeInformationGuid                 
     80  ## SOMETIMES_CONSUMES ## Variable:L"BootXXXX"    # Boot option variable
     81  ## SOMETIMES_PRODUCES ## Variable:L"BootXXXX"    # Boot option variable
     82  ## SOMETIMES_CONSUMES ## Variable:L"DriverXXXX"  # Driver load option.
     83  ## SOMETIMES_PRODUCES ## Variable:L"DriverXXXX"  # Driver load option.
     84  ## SOMETIMES_CONSUMES ## Variable:L"BootNext"    # Next Boot Option
     85  ## SOMETIMES_PRODUCES ## Variable:L"BootNext"    # Next Boot Option
     86  ## SOMETIMES_CONSUMES ## Variable:L"BootOrder"   # The boot option array
     87  ## SOMETIMES_PRODUCES ## Variable:L"BootOrder"   # The boot option array
     88  ## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" # The driver order list
     89  ## SOMETIMES_CONSUMES ## Variable:L"ConIn"       # The device path of console in device
     90  ## SOMETIMES_PRODUCES ## Variable:L"ConIn"       # The device path of console in device
     91  ## SOMETIMES_CONSUMES ## Variable:L"ConOut"      # The device path of console out device
     92  ## SOMETIMES_PRODUCES ## Variable:L"ConOut"      # The device path of console out device
     93  ## SOMETIMES_CONSUMES ## Variable:L"ErrOut"      # The device path of error out device
     94  ## SOMETIMES_PRODUCES ## Variable:L"ErrOut"      # The device path of error out device
     95  ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" # The boot option of current boot
     96  ## SOMETIMES_PRODUCES ## Variable:L"BootNext"    # The number of next boot option
     97  gEfiGlobalVariableGuid
     98  gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## GUID
     99  gPerformanceProtocolGuid                      ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" # The ACPI address of performance data
     100  gLastEnumLangGuid                             ## SOMETIMES_PRODUCES ## Variable:L"LastEnumLang" # Platform language at last time enumeration.
     101  gHdBootDevicePathVariablGuid                  ## SOMETIMES_PRODUCES ## Variable:L"HDDP" # The device path of Boot file on Hard device.
     102  gBdsLibStringPackageGuid                      ## CONSUMES ## HII # HII String PackageList Guid
     103  ## SOMETIMES_PRODUCES ## Variable:L"LegacyDevOrder"
     104  ## SOMETIMES_CONSUMES ## Variable:L"LegacyDevOrder"
     105  gEfiLegacyDevOrderVariableGuid
     106  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES ## GUID
    94107
    95108[Protocols]
    96   gEfiSimpleFileSystemProtocolGuid              # PROTOCOL CONSUMES
    97   gEfiLoadFileProtocolGuid                      # PROTOCOL CONSUMES
    98   gEfiSimpleTextOutProtocolGuid                 # PROTOCOL CONSUMES
    99   gEfiPciIoProtocolGuid                         # PROTOCOL CONSUMES
    100   gEfiLoadedImageProtocolGuid                   # PROTOCOL CONSUMES
    101   gEfiDevicePathToTextProtocolGuid              # PROTOCOL SOMETIMES_CONSUMES
    102   gEfiSimpleNetworkProtocolGuid                 # PROTOCOL CONSUMES
    103   gEfiDebugPortProtocolGuid                     # PROTOCOL CONSUMES
    104   gEfiSimpleTextInProtocolGuid                  # PROTOCOL CONSUMES
    105   gEfiBlockIoProtocolGuid                       # PROTOCOL CONSUMES
    106   gEfiFirmwareVolume2ProtocolGuid               # PROTOCOL CONSUMES
    107   gEfiLegacyBiosProtocolGuid                    # PROTOCOL SOMETIMES_CONSUMES
    108   gEfiCpuArchProtocolGuid                       # PROTOCOL CONSUMES
    109   gEfiDevicePathProtocolGuid                    # PROTOCOL CONSUMES
    110   gEfiAcpiS3SaveProtocolGuid                    # PROTOCOL CONSUMES
    111   gEfiGraphicsOutputProtocolGuid                # PROTOCOL SOMETIMES_CONSUMES
    112   gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport # PROTOCOL SOMETIMES_CONSUMES
    113   gEfiOEMBadgingProtocolGuid                    # PROTOCOL CONSUMES
    114   gEfiHiiFontProtocolGuid                       # PROTOCOL CONSUMES
    115   gEfiUserManagerProtocolGuid                   # PROTOCOL CONSUMES
    116   gEfiUsbIoProtocolGuid                         # PROTOCOL SOMETIMES_CONSUMES
    117   gEfiBootLogoProtocolGuid                      # PROTOCOL SOMETIMES_CONSUMES
     109  gEfiSimpleFileSystemProtocolGuid              ## SOMETIMES_CONSUMES
     110  gEfiLoadFileProtocolGuid                      ## SOMETIMES_CONSUMES
     111  gEfiSimpleTextOutProtocolGuid                 ## CONSUMES
     112  gEfiPciIoProtocolGuid                         ## SOMETIMES_CONSUMES
     113  gEfiLoadedImageProtocolGuid                   ## SOMETIMES_CONSUMES
     114  gEfiSimpleNetworkProtocolGuid                 ## SOMETIMES_CONSUMES
     115  gEfiDebugPortProtocolGuid                     ## SOMETIMES_CONSUMES
     116  gEfiSimpleTextInProtocolGuid                  ## CONSUMES
     117  gEfiBlockIoProtocolGuid                       ## SOMETIMES_CONSUMES
     118  gEfiFirmwareVolume2ProtocolGuid               ## SOMETIMES_CONSUMES
     119  gEfiLegacyBiosProtocolGuid                    ## SOMETIMES_CONSUMES
     120  gEfiCpuArchProtocolGuid                       ## CONSUMES
     121  gEfiDevicePathProtocolGuid                    ## CONSUMES
     122  gEfiAcpiS3SaveProtocolGuid                    ## SOMETIMES_CONSUMES
     123  gEfiGraphicsOutputProtocolGuid                ## SOMETIMES_CONSUMES
     124  gEfiUgaDrawProtocolGuid |gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport ## SOMETIMES_CONSUMES
     125  gEfiOEMBadgingProtocolGuid                    ## SOMETIMES_CONSUMES
     126  gEfiHiiFontProtocolGuid                       ## CONSUMES
     127  gEfiUserManagerProtocolGuid                   ## SOMETIMES_CONSUMES
     128  gEfiUsbIoProtocolGuid                         ## SOMETIMES_CONSUMES
     129  gEfiBootLogoProtocolGuid                      ## SOMETIMES_CONSUMES
    118130
    119131[FeaturePcd]
    120   gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport
    121   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable
     132  gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport                   ## CONSUMES
     133  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootlogoOnlyEnable ## CONSUMES
    122134
    123135[Pcd]
    124   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange
    125   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad
    126   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart
    127   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile
     136  gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange ## SOMETIMES_CONSUMES
     137  gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad  ## SOMETIMES_CONSUMES
     138  gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart ## SOMETIMES_CONSUMES
     139  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable      ## CONSUMES
     140  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile      ## CONSUMES
     141
     142#
     143# [BootMode]
     144#   RECOVERY_FULL    ## SOMETIMES_CONSUMES # Memory Type Information variable
     145#
    128146
    129147[BuildOptions.common]
     
    131149   MSFT:*_*_*_CC_FLAGS = -DEFI_LOG_ENABLED=1
    132150  INTEL:*_*_*_CC_FLAGS = -DEFI_LOG_ENABLED=1
     151
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h

    r48749 r58459  
    22  BDS library definition, include the file and data structure
    33
    4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    3232#include <Protocol/SimpleTextOut.h>
    3333#include <Protocol/SimpleNetwork.h>
    34 #include <Protocol/DevicePathToText.h>
    3534#include <Protocol/FirmwareVolume2.h>
    3635#include <Protocol/PciIo.h>
     
    5251#include <Guid/HdBootVariable.h>
    5352#include <Guid/LastEnumLang.h>
     53#include <Guid/LegacyDevOrder.h>
     54#include <Guid/StatusCodeDataTypeVariable.h>
    5455
    5556#include <Library/PrintLib.h>
     
    9697/**
    9798
    98   Allocates a block of memory and writes performance data of booting into it.
    99   OS can processing these record.
    100  
     99  Writes performance data of booting into the allocated memory.
     100  OS can process these records.
     101
     102  @param  Event                 The triggered event.
     103  @param  Context               Context for this event.
     104
    101105**/
    102106VOID
     107EFIAPI
    103108WriteBootToOsPerformanceData (
    104   VOID
     109  IN EFI_EVENT  Event,
     110  IN VOID       *Context
    105111  );
    106112
     
    152158  );
    153159
     160/**
     161  Set the variable and report the error through status code upon failure.
     162
     163  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.
     164                                 Each VariableName is unique for each VendorGuid. VariableName must
     165                                 contain 1 or more characters. If VariableName is an empty string,
     166                                 then EFI_INVALID_PARAMETER is returned.
     167  @param  VendorGuid             A unique identifier for the vendor.
     168  @param  Attributes             Attributes bitmask to set for the variable.
     169  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
     170                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
     171                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
     172                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
     173                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to
     174                                 the variable value (the timestamp associated with the variable may be updated however
     175                                 even if no new data value is provided,see the description of the
     176                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
     177                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
     178  @param  Data                   The contents for the variable.
     179
     180  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as
     181                                 defined by the Attributes.
     182  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the
     183                                 DataSize exceeds the maximum allowed.
     184  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
     185  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.
     186  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.
     187  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
     188  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
     189  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
     190                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
     191                                 does NOT pass the validation check carried out by the firmware.
     192
     193  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.
     194**/
     195EFI_STATUS
     196SetVariableAndReportStatusCodeOnError (
     197  IN CHAR16     *VariableName,
     198  IN EFI_GUID   *VendorGuid,
     199  IN UINT32     Attributes,
     200  IN UINTN      DataSize,
     201  IN VOID       *Data
     202  );
     203
    154204#endif // _BDS_LIB_H_
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/Performance.c

    r48674 r58459  
    44  switch is set.
    55
    6 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
     6Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
    77This program and the accompanying materials
    88are licensed and made available under the terms and conditions of the BSD License
     
    136136/**
    137137
    138   Allocates a block of memory and writes performance data of booting into it.
    139   OS can processing these record.
    140  
     138  Writes performance data of booting into the allocated memory.
     139  OS can process these records.
     140
     141  @param  Event                 The triggered event.
     142  @param  Context               Context for this event.
     143
    141144**/
    142145VOID
     146EFIAPI
    143147WriteBootToOsPerformanceData (
    144   VOID
     148  IN EFI_EVENT  Event,
     149  IN VOID       *Context
    145150  )
    146151{
    147152  EFI_STATUS                Status;
    148   UINT32                    AcpiLowMemoryLength;
    149153  UINT32                    LimitCount;
    150154  EFI_HANDLE                *Handles;
     
    171175  //
    172176  BOOLEAN                   *PerfEntriesAsDxeHandle;
     177  UINTN                     VarSize;
     178
     179  //
     180  // Record the performance data for End of BDS
     181  //
     182  PERF_END(NULL, "BDS", NULL, 0);
    173183
    174184  //
     
    192202    mPerfHeader.BDSRaw = StartValue - Ticker;
    193203    CountUp            = FALSE;
     204  }
     205
     206  if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
     207    VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
     208    Status = gRT->GetVariable (
     209                    L"PerfDataMemAddr",
     210                    &gPerformanceProtocolGuid,
     211                    NULL,
     212                    &VarSize,
     213                    &mAcpiLowMemoryBase
     214                    );
     215    if (EFI_ERROR (Status)) {
     216      //
     217      // Fail to get the variable, return.
     218      //
     219      return;
     220    }
    194221  }
    195222
     
    209236  }
    210237
    211 
    212   AcpiLowMemoryLength = 0x4000;
    213   if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
    214     //
    215     // Allocate a block of memory that contain performance data to OS
    216     //
    217     Status = gBS->AllocatePages (
    218                     AllocateMaxAddress,
    219                     EfiReservedMemoryType,
    220                     EFI_SIZE_TO_PAGES (AcpiLowMemoryLength),
    221                     &mAcpiLowMemoryBase
    222                     );
    223     if (EFI_ERROR (Status)) {
    224       FreePool (Handles);
    225       return ;
    226     }
    227   }
    228 
    229 
    230238  Ptr        = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));
    231   LimitCount = (AcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
     239  LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
    232240
    233241  NumPerfEntries = 0;
     
    347355    );
    348356
    349   gRT->SetVariable (
    350         L"PerfDataMemAddr",
    351         &gPerformanceProtocolGuid,
    352         EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
    353         sizeof (EFI_PHYSICAL_ADDRESS),
    354         &mAcpiLowMemoryBase
    355         );
    356 
    357357  return ;
    358358}
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf

    r48674 r58459  
    33#
    44#  It is based on the LZMA SDK 4.65.
    5 #  LZMA SDK 4.65 was placed in the public domain on 2009-02-03. 
     5#  LZMA SDK 4.65 was placed in the public domain on 2009-02-03.
    66#  It was released on the http://www.7-zip.org/sdk.html website.
    77#
    8 #  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     8#  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    99#
    1010#  This program and the accompanying materials
     
    2121  INF_VERSION                    = 0x00010005
    2222  BASE_NAME                      = LzmaDecompressLib
     23  MODULE_UNI_FILE                = LzmaDecompressLib.uni
    2324  FILE_GUID                      = 35194660-7421-44ad-9636-e44885f092d1
    2425  MODULE_TYPE                    = BASE
     
    4950[Packages]
    5051  MdePkg/MdePkg.dec
    51   IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
     52  MdeModulePkg/MdeModulePkg.dec
    5253
    5354[Guids]
    54   gLzmaCustomDecompressGuid  ## PRODUCED  ## GUID specifies LZMA custom decompress algorithm.
     55  gLzmaCustomDecompressGuid  ## PRODUCES  ## UNDEFINED # specifies LZMA custom decompress algorithm.
    5556
    5657[LibraryClasses]
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c

    r48674 r58459  
    55  record length, then the debug message will be ignored directly.
    66
    7   Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
     7  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
    88  This program and the accompanying materials
    99  are licensed and made available under the terms and conditions of the BSD License
     
    1616**/
    1717
    18 #include <FrameworkPei.h>
     18#include <PiPei.h>
    1919
    2020#include <Guid/StatusCodeDataTypeId.h>
     
    259259  UINT64                 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];
    260260  EFI_DEBUG_ASSERT_DATA  *AssertData;
     261  UINTN                  HeaderSize;
    261262  UINTN                  TotalSize;
    262263  CHAR8                  *Temp;
     
    265266
    266267  //
    267   // Make sure it will all fit in the passed in buffer
    268   //
    269   FileNameSize    = AsciiStrSize (FileName);
    270   DescriptionSize = AsciiStrSize (Description);
    271   TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameSize + DescriptionSize;
    272   if (TotalSize <= sizeof (Buffer)) {
    273     //
    274     // Fill in EFI_DEBUG_ASSERT_DATA
    275     //
    276     AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;
    277     AssertData->LineNumber = (UINT32)LineNumber;
    278 
    279     //
    280     // Copy Ascii FileName including NULL.
    281     //
    282     Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);
    283 
    284     //
    285     // Copy Ascii Description
    286     //
    287     AsciiStrCpy (Temp + FileNameSize, Description);
    288 
    289     REPORT_STATUS_CODE_EX (
    290       (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
    291       (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
    292       0,
    293       NULL,
    294       NULL,
    295       AssertData,
    296       TotalSize
    297       );
     268  // Get string size
     269  //
     270  HeaderSize       = sizeof (EFI_DEBUG_ASSERT_DATA);
     271  FileNameSize     = AsciiStrSize (FileName);
     272  DescriptionSize  = AsciiStrSize (Description);
     273
     274  //
     275  // Make sure it will all fit in the passed in buffer.
     276  //
     277  if (HeaderSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {
     278    //
     279    // FileName + Description is too long to be filled into buffer.
     280    //
     281    if (HeaderSize + FileNameSize < sizeof (Buffer)) {
     282      //
     283      // Description has enough buffer to be truncated.
     284      //
     285      DescriptionSize = sizeof (Buffer) - HeaderSize - FileNameSize;
     286    } else {
     287      //
     288      // FileName is too long to be filled into buffer.
     289      // FileName will be truncated. Reserved one byte for Description NULL terminator.
     290      //
     291      DescriptionSize = 1;
     292      FileNameSize    = sizeof (Buffer) - HeaderSize - DescriptionSize;
     293    }
    298294  }
     295 
     296  //
     297  // Fill in EFI_DEBUG_ASSERT_DATA
     298  //
     299  AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;
     300  AssertData->LineNumber = (UINT32)LineNumber;
     301  TotalSize  = sizeof (EFI_DEBUG_ASSERT_DATA);
     302
     303  //
     304  // Copy Ascii FileName including NULL terminator.
     305  //
     306  Temp = CopyMem (AssertData + 1, FileName, FileNameSize);
     307  Temp[FileNameSize - 1] = 0;
     308  TotalSize += FileNameSize;
     309
     310  //
     311  // Copy Ascii Description include NULL terminator.
     312  //
     313  Temp = CopyMem (Temp + FileNameSize, Description, DescriptionSize);
     314  Temp[DescriptionSize - 1] = 0;
     315  TotalSize += DescriptionSize;
     316
     317  REPORT_STATUS_CODE_EX (
     318    (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
     319    (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
     320    0,
     321    NULL,
     322    NULL,
     323    AssertData,
     324    TotalSize
     325    );
    299326
    300327  //
     
    415442  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
    416443}
     444
     445/**
     446  Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
     447
     448  This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
     449
     450  @retval  TRUE    Current ErrorLevel is supported.
     451  @retval  FALSE   Current ErrorLevel is not supported.
     452
     453**/
     454BOOLEAN
     455EFIAPI
     456DebugPrintLevelEnabled (
     457  IN  CONST UINTN        ErrorLevel
     458  )
     459{
     460  return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);
     461}
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf

    r48674 r58459  
    33#
    44#  Debug Library for PEIMs and DXE drivers that sends debug messages to ReportStatusCode
    5 #  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
     5#  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
    66#
    77#  This program and the accompanying materials
     
    1818  INF_VERSION                    = 0x00010005
    1919  BASE_NAME                      = PeiDxeDebugLibReportStatusCode
     20  MODULE_UNI_FILE                = PeiDxeDebugLibReportStatusCode.uni
    2021  FILE_GUID                      = bda39d3a-451b-4350-8266-81ab10fa0523
    2122  MODULE_TYPE                    = PEIM
     
    3637  MdePkg/MdePkg.dec
    3738  MdeModulePkg/MdeModulePkg.dec
    38   IntelFrameworkPkg/IntelFrameworkPkg.dec
    39   IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
    4039 
    4140[LibraryClasses]
     
    4746
    4847[Pcd]
    49   gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue
    50   gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
     48  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue  ## SOMETIMES_CONSUMES
     49  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask      ## CONSUMES
     50  gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES
    5151
    5252[Guids]
    53   gEfiStatusCodeDataTypeDebugGuid    ## CONSUMES
    54  
    55  
     53  gEfiStatusCodeDataTypeDebugGuid    ## SOMETIMES_CONSUMES ## GUID
     54
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/PeiRecoveryLib/PeiRecoveryLib.inf

    r48674 r58459  
    66#  in PI 1.2 specification.
    77#
    8 #  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     8#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    99#
    1010#  This program and the accompanying materials
     
    2121  INF_VERSION                    = 0x00010005
    2222  BASE_NAME                      = PeiRecoveryLib
     23  MODULE_UNI_FILE                = PeiRecoveryLib.uni
    2324  FILE_GUID                      = C0227547-0811-4cbb-ABEA-DECD22829122
    2425  MODULE_TYPE                    = PEIM
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/PeiS3Lib/PeiS3Lib.inf

    r48674 r58459  
    11## @file
     2#  This library provides API to invoke the S3 resume vector in the ACPI Table in S3 resume mode.
    23#
    3 #  This library provides API to invoke the S3 resume vector in the APCI Table in S3 resume mode.
    44#  This library instance is no longer used and module using this library
    55#  class should update to directly locate EFI_PEI_S3_RESUME_PPI defined
    66#  in PI 1.2 specification.
    77#
    8 #  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     8#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    99#
    1010#  This program and the accompanying materials
     
    2121  INF_VERSION                    = 0x00010005
    2222  BASE_NAME                      = PeiS3Lib
     23  MODULE_UNI_FILE                = PeiS3Lib.uni
    2324  FILE_GUID                      = EFB7D3A8-DEB9-4bed-B6D6-3B09BEEB835A
    2425  MODULE_TYPE                    = PEIM
     
    4546
    4647[Ppis]
    47   gEfiPeiS3ResumePpiGuid                # ALWAYS_CONSUMES
     48  gEfiPeiS3ResumePpiGuid                ## CONSUMES
    4849
    49 
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/PlatformBdsLibNull/PlatformBdsLibNull.inf

    r48674 r58459  
    11## @file
     2#  NULL implementation for PlatformBdsLib library class interfaces.
    23
    3 #  Provide NULL implementation for PlatformBdsLib library class interfaces which
    4 #  should be implemented by OEM.
    5 
    6 #  Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
     4#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
    75#  This program and the accompanying materials
    86#  are licensed and made available under the terms and conditions of the BSD License
     
    1816  INF_VERSION                    = 0x00010005
    1917  BASE_NAME                      = PlatformBdsLib
     18  MODULE_UNI_FILE                = PlatformBdsLib.uni
    2019  FILE_GUID                      = 143B5044-7C1B-4904-9778-EA16F1F3D554
    2120  MODULE_TYPE                    = DXE_DRIVER
  • trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeReportStatusCodeLibFramework.inf

    r48674 r58459  
    11## @file
    2 Report status code library instance which supports logging message in SMM, as well as DXE & runtime phase.
     2Framework Report status code library instance which supports logging message in SMM, as well as DXE & runtime phase.
    33#
    44#  This library instance supports status code report in SMM, as well as DXE & runtime phase.
     
    66#  Otherwise, it logs message to ReportStatusCode() in framework runtime services table or runtime report status code protocol.
    77#
    8 #  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     8#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    99#
    1010#  This program and the accompanying materials
     
    2121  INF_VERSION                    = 0x00010005
    2222  BASE_NAME                      = SmmRuntimeDxeReportStatusCodeLibFramework
     23  MODULE_UNI_FILE                = SmmRuntimeDxeReportStatusCodeLibFramework.uni
    2324  FILE_GUID                      = D65D9F72-7BCE-4f73-A673-47AF446A1A31
    2425  MODULE_TYPE                    = DXE_RUNTIME_DRIVER
     
    5758
    5859[Guids]
    59   gEfiStatusCodeSpecificDataGuid                ## CONSUMES
    60   gEfiStatusCodeDataTypeDebugGuid               ## CONSUMES
     60  gEfiStatusCodeSpecificDataGuid                ## SOMETIMES_CONSUMES ## UNDEFINED
     61  gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES ## UNDEFINED
    6162  gEfiEventExitBootServicesGuid                 ## CONSUMES ## Event
    6263  gEfiEventVirtualAddressChangeGuid             ## CONSUMES ## Event
     
    6465
    6566[Protocols]
    66   gEfiStatusCodeRuntimeProtocolGuid             ## CONSUMES
    67   gEfiSmmBaseProtocolGuid                       ## CONSUMES
    68   gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
     67  gEfiStatusCodeRuntimeProtocolGuid             ## SOMETIMES_CONSUMES
     68  gEfiSmmBaseProtocolGuid                       ## SOMETIMES_CONSUMES
     69  gEfiSmmStatusCodeProtocolGuid                 ## SOMETIMES_CONSUMES
    6970
    7071[Pcd]
    71   gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask
     72  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask ## CONSUMES
    7273
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette