]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Minor code enhancement.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
index 9042cc3428b624c0fa9a61c98ef1e94b5a5e50bd..7a9756e1f1d10dd2477e8e251cf8264ecc2ef414 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS Lib functions which relate with create or process the boot option.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2004 - 2010, Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -55,7 +55,7 @@ BdsLibDoLegacyBoot (
   BdsRefreshBbsTableForBoot (Option);\r
 \r
   //\r
-  // Write boot to OS performance data to a file\r
+  // Write boot to OS performance data for legacy boot.\r
   //\r
   PERF_CODE (\r
     WriteBootToOsPerformanceData ();\r
@@ -145,7 +145,6 @@ BdsLibBootViaBootOption (
   EFI_DEVICE_PATH_PROTOCOL  *WorkingDevicePath;\r
   EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;\r
   LIST_ENTRY                TempBootLists;\r
-  EFI_SECURITY_ARCH_PROTOCOL *SecurityProtocol;\r
 \r
   //\r
   // Record the performance data for End of BDS\r
@@ -241,20 +240,70 @@ BdsLibBootViaBootOption (
     DevicePath = Option->DevicePath;\r
   }\r
 \r
-  //\r
-  // Measure GPT Table by SAP protocol.\r
-  //\r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiSecurityArchProtocolGuid,\r
-                  NULL,\r
-                  (VOID**) &SecurityProtocol\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = SecurityProtocol->FileAuthenticationState (SecurityProtocol, 0, DevicePath);\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));\r
+  DEBUG_CODE_BEGIN();\r
+    UINTN                     DevicePathTypeValue;\r
+    CHAR16                    *HiiString;\r
+    CHAR16                    *BootStringNumber;\r
+    UINTN                     BufferSize;\r
+  \r
+    DevicePathTypeValue = BdsGetBootTypeFromDevicePath (Option->DevicePath);\r
+  \r
+    //\r
+    // store number string of boot option temporary.\r
+    //\r
+    HiiString = NULL;\r
+    switch (DevicePathTypeValue) {\r
+    case BDS_EFI_ACPI_FLOPPY_BOOT:\r
+      HiiString = L"EFI Floppy";\r
+      break;\r
+    case BDS_EFI_MEDIA_CDROM_BOOT:\r
+    case BDS_EFI_MESSAGE_SATA_BOOT:\r
+    case BDS_EFI_MESSAGE_ATAPI_BOOT:\r
+      HiiString = L"EFI DVD/CDROM";\r
+      break;\r
+    case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:\r
+      HiiString = L"EFI USB Device";\r
+      break;\r
+    case BDS_EFI_MESSAGE_SCSI_BOOT:\r
+      HiiString = L"EFI SCSI Device";\r
+      break;\r
+    case BDS_EFI_MESSAGE_MISC_BOOT:\r
+      HiiString = L"EFI Misc Device";\r
+      break;\r
+    case BDS_EFI_MESSAGE_MAC_BOOT:\r
+      HiiString = L"EFI Network";\r
+      break;\r
+    case BBS_DEVICE_PATH:\r
+      //\r
+      // Do nothing for legacy boot option.\r
+      //\r
+      break;\r
+    default:\r
+      DEBUG((EFI_D_INFO, "Can not find HiiString for given device path type 0x%x\n", DevicePathTypeValue));\r
+    }\r
 \r
+    //\r
+    // If found Hii description string then cat Hii string with original description.\r
+    //\r
+    if (HiiString != NULL) {\r
+      BootStringNumber = Option->Description;\r
+      BufferSize = StrSize(BootStringNumber);\r
+      BufferSize += StrSize(HiiString);\r
+      Option->Description = AllocateZeroPool(BufferSize);\r
+      ASSERT (Option->Description != NULL);\r
+      StrCpy (Option->Description, HiiString);\r
+      if (StrnCmp (BootStringNumber, L"0", 1) != 0) {\r
+        StrCat (Option->Description, L" ");\r
+        StrCat (Option->Description, BootStringNumber);\r
+      } \r
+      \r
+      FreePool (BootStringNumber);\r
+    }\r
+  \r
+    DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));\r
+    \r
+  DEBUG_CODE_END();\r
+  \r
   Status = gBS->LoadImage (\r
                   TRUE,\r
                   mBdsImageHandle,\r
@@ -265,7 +314,7 @@ BdsLibBootViaBootOption (
                   );\r
 \r
   //\r
-  // If we didn't find an image directly, we need to try as if it is a removable device boot opotion\r
+  // If we didn't find an image directly, we need to try as if it is a removable device boot option\r
   // and load the image according to the default boot behavior for removable device.\r
   //\r
   if (EFI_ERROR (Status)) {\r
@@ -323,6 +372,13 @@ BdsLibBootViaBootOption (
   //\r
   gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
 \r
+  //\r
+  // Write boot to OS performance data for UEFI boot\r
+  //\r
+  PERF_CODE (\r
+    WriteBootToOsPerformanceData ();\r
+  );\r
+\r
   Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);\r
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));\r
 \r
@@ -931,8 +987,8 @@ BdsLibEnumerateAllBootOption (
   EFI_HANDLE                    *BlockIoHandles;\r
   EFI_BLOCK_IO_PROTOCOL         *BlkIo;\r
   UINTN                         Index;\r
-  UINTN                         NumberSimpleNetworkHandles;\r
-  EFI_HANDLE                    *SimpleNetworkHandles;\r
+  UINTN                         NumberNetworkHandles;\r
+  EFI_HANDLE                    *NetworkHandles;\r
   UINTN                         FvHandleCount;\r
   EFI_HANDLE                    *FvHandleBuffer;\r
   EFI_FV_FILETYPE               Type;\r
@@ -1111,21 +1167,37 @@ BdsLibEnumerateAllBootOption (
   //\r
   // Parse Network Boot Device\r
   //\r
+  NumberNetworkHandles = 0;\r
+  //\r
+  // Search MNP Service Binding protocol for UEFI network stack\r
+  //\r
   gBS->LocateHandleBuffer (\r
         ByProtocol,\r
-        &gEfiSimpleNetworkProtocolGuid,\r
+        &gEfiManagedNetworkServiceBindingProtocolGuid,\r
         NULL,\r
-        &NumberSimpleNetworkHandles,\r
-        &SimpleNetworkHandles\r
+        &NumberNetworkHandles,\r
+        &NetworkHandles\r
         );\r
+  if (NumberNetworkHandles == 0) {\r
+    //\r
+    // MNP Service Binding protocol not found, search SNP for EFI network stack\r
+    //\r
+    gBS->LocateHandleBuffer (\r
+          ByProtocol,\r
+          &gEfiSimpleNetworkProtocolGuid,\r
+          NULL,\r
+          &NumberNetworkHandles,\r
+          &NetworkHandles\r
+          );\r
+  }\r
 \r
-  for (Index = 0; Index < NumberSimpleNetworkHandles; Index++) {\r
+  for (Index = 0; Index < NumberNetworkHandles; Index++) {\r
     UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", Index);\r
-    BdsLibBuildOptionFromHandle (SimpleNetworkHandles[Index], BdsBootOptionList, Buffer);\r
+    BdsLibBuildOptionFromHandle (NetworkHandles[Index], BdsBootOptionList, Buffer);\r
   }\r
 \r
-  if (NumberSimpleNetworkHandles != 0) {\r
-    FreePool (SimpleNetworkHandles);\r
+  if (NumberNetworkHandles != 0) {\r
+    FreePool (NetworkHandles);\r
   }\r
 \r
   //\r
@@ -1479,7 +1551,17 @@ BdsLibNetworkBootWithMediaPresent (
   MediaPresent = FALSE;\r
 \r
   UpdatedDevicePath = DevicePath;\r
-  Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
+  //\r
+  // Locate MNP Service Binding protocol for UEFI network stack first\r
+  //\r
+  Status = gBS->LocateDevicePath (&gEfiManagedNetworkServiceBindingProtocolGuid, &UpdatedDevicePath, &Handle);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // MNP Service Binding protocol not found, search SNP for EFI network stack\r
+    //\r
+    UpdatedDevicePath = DevicePath;\r
+    Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
+  }\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Device not present so see if we need to connect it\r
@@ -1489,12 +1571,32 @@ BdsLibNetworkBootWithMediaPresent (
       //\r
       // This one should work after we did the connect\r
       //\r
-      Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
+      Status = gBS->LocateDevicePath (&gEfiManagedNetworkServiceBindingProtocolGuid, &UpdatedDevicePath, &Handle);\r
+      if (EFI_ERROR (Status)) {\r
+        UpdatedDevicePath = DevicePath;\r
+        Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
+      }\r
     }\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
     Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Failed to open SNP from this handle, try to get SNP from parent handle\r
+      //\r
+      UpdatedDevicePath = DevicePathFromHandle (Handle);\r
+      if (UpdatedDevicePath != NULL) {\r
+        Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
+        if (!EFI_ERROR (Status)) {\r
+          //\r
+          // SNP handle found, get SNP from it\r
+          //\r
+          Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp);\r
+        }\r
+      }\r
+    }\r
+\r
     if (!EFI_ERROR (Status)) {\r
       if (Snp->Mode->MediaPresentSupported) {\r
         if (Snp->Mode->State == EfiSimpleNetworkInitialized) {\r
@@ -1558,7 +1660,7 @@ BdsGetBootTypeFromDevicePath (
   ACPI_HID_DEVICE_PATH          *Acpi;\r
   EFI_DEVICE_PATH_PROTOCOL      *TempDevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL      *LastDeviceNode;\r
-\r
+  UINT32                        BootType;\r
 \r
   if (NULL == DevicePath) {\r
     return BDS_EFI_UNSUPPORT;\r
@@ -1591,7 +1693,7 @@ BdsGetBootTypeFromDevicePath (
         if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {\r
           //\r
           // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),\r
-          // skit it\r
+          // skip it\r
           //\r
           LastDeviceNode = NextDevicePathNode (LastDeviceNode);\r
         }\r
@@ -1602,18 +1704,34 @@ BdsGetBootTypeFromDevicePath (
           break;\r
         }\r
 \r
-        if (DevicePathSubType(TempDevicePath) == MSG_ATAPI_DP) {\r
-          return BDS_EFI_MESSAGE_ATAPI_BOOT;\r
-        } else if (DevicePathSubType(TempDevicePath) == MSG_USB_DP) {\r
-          return BDS_EFI_MESSAGE_USB_DEVICE_BOOT;\r
-        } else if (DevicePathSubType(TempDevicePath) == MSG_SCSI_DP) {\r
-          return BDS_EFI_MESSAGE_SCSI_BOOT;\r
-        } else if (DevicePathSubType(TempDevicePath) == MSG_SATA_DP) {\r
-          return BDS_EFI_MESSAGE_SATA_BOOT;\r
-        } else if (DevicePathSubType(TempDevicePath) == MSG_MAC_ADDR_DP) {\r
-          return BDS_EFI_MESSAGE_MAC_BOOT;\r
+        switch (DevicePathSubType (TempDevicePath)) {\r
+        case MSG_ATAPI_DP:\r
+          BootType = BDS_EFI_MESSAGE_ATAPI_BOOT;\r
+          break;\r
+\r
+        case MSG_USB_DP:\r
+          BootType = BDS_EFI_MESSAGE_USB_DEVICE_BOOT;\r
+          break;\r
+\r
+        case MSG_SCSI_DP:\r
+          BootType = BDS_EFI_MESSAGE_SCSI_BOOT;\r
+          break;\r
+\r
+        case MSG_SATA_DP:\r
+          BootType = BDS_EFI_MESSAGE_SATA_BOOT;\r
+          break;\r
+\r
+        case MSG_MAC_ADDR_DP:\r
+        case MSG_VLAN_DP:\r
+          BootType = BDS_EFI_MESSAGE_MAC_BOOT;\r
+          break;\r
+\r
+        default:\r
+          BootType = BDS_EFI_MESSAGE_MISC_BOOT;\r
+          break;\r
         }\r
-        return BDS_EFI_MESSAGE_MISC_BOOT;\r
+        return BootType;\r
+\r
       default:\r
         break;\r
     }\r
@@ -1672,20 +1790,29 @@ BdsLibIsValidEFIBootOptDevicePathExt (
   EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *LastDeviceNode;\r
   EFI_BLOCK_IO_PROTOCOL     *BlockIo;\r
+  EFI_LOAD_FILE_PROTOCOL    *LoadFile;\r
 \r
   TempDevicePath = DevPath;\r
   LastDeviceNode = DevPath;\r
 \r
   //\r
   // Check if it's a valid boot option for network boot device\r
-  // Only check if there is SimpleNetworkProtocol installed. If yes, that means\r
-  // there is the network card there.\r
+  // Check if there is MNP Service Binding Protocol or SimpleNetworkProtocol\r
+  // installed. If yes, that means there is the network card there.\r
   //\r
   Status = gBS->LocateDevicePath (\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
                   &TempDevicePath,\r
                   &Handle\r
                   );\r
+  if (EFI_ERROR (Status)) {\r
+    TempDevicePath = DevPath;\r
+    Status = gBS->LocateDevicePath (\r
+                    &gEfiSimpleNetworkProtocolGuid,\r
+                    &TempDevicePath,\r
+                    &Handle\r
+                    );\r
+  }\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Device not present so see if we need to connect it\r
@@ -1693,22 +1820,43 @@ BdsLibIsValidEFIBootOptDevicePathExt (
     TempDevicePath = DevPath;\r
     BdsLibConnectDevicePath (TempDevicePath);\r
     Status = gBS->LocateDevicePath (\r
-                    &gEfiSimpleNetworkProtocolGuid,\r
+                    &gEfiManagedNetworkServiceBindingProtocolGuid,\r
                     &TempDevicePath,\r
                     &Handle\r
                     );\r
+    if (EFI_ERROR (Status)) {\r
+      TempDevicePath = DevPath;\r
+      Status = gBS->LocateDevicePath (\r
+                      &gEfiSimpleNetworkProtocolGuid,\r
+                      &TempDevicePath,\r
+                      &Handle\r
+                      );\r
+    }\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
-    if (CheckMedia) {\r
-      //\r
-      // Test if it is ready to boot now\r
-      //\r
-      if (BdsLibNetworkBootWithMediaPresent(DevPath)) {\r
+    //\r
+    // Check whether LoadFile protocol is installed\r
+    //\r
+    Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **)&LoadFile);\r
+    if (!EFI_ERROR (Status)) {\r
+      if (!IsDevicePathEnd (TempDevicePath)) {\r
+        //\r
+        // LoadFile protocol is not installed on handle with exactly the same DevPath\r
+        //\r
+        return FALSE;\r
+      }\r
+\r
+      if (CheckMedia) {\r
+        //\r
+        // Test if it is ready to boot now\r
+        //\r
+        if (BdsLibNetworkBootWithMediaPresent(DevPath)) {\r
+          return TRUE;\r
+        }\r
+      } else {\r
         return TRUE;\r
       }\r
-    } else {\r
-      return TRUE;\r
     }\r
   }\r
 \r