]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: QemuBootOrder: keep some boot options that have not been selected
authorLaszlo Ersek <lersek@redhat.com>
Fri, 13 Sep 2013 08:14:57 +0000 (08:14 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 13 Sep 2013 08:14:57 +0000 (08:14 +0000)
Some of the active boot options that have not been selected over fw_cfg
should be preserved at the end of the boot order. For now we're adding
back everything that starts with neither PciRoot() nor HD(). This includes
the UEFI shell, memory-mapped from the firmware image.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Michael Chang <mchang@suse.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14668 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c

index 31c3378856da2fd6458770e335a39a484d212e4d..daab658a1fe5ec6d4ab415baf86970500521ebfa 100644 (file)
@@ -1012,6 +1012,105 @@ Exit:
 }\r
 \r
 \r
+/**\r
+  Append some of the unselected active boot options to the boot order.\r
+\r
+  This function should accommodate any further policy changes in "boot option\r
+  survival". Currently we're adding back everything that starts with neither\r
+  PciRoot() nor HD().\r
+\r
+  @param[in,out] BootOrder     The structure holding the boot order to\r
+                               complete. The caller is responsible for\r
+                               initializing (and potentially populating) it\r
+                               before calling this function.\r
+\r
+  @param[in,out] ActiveOption  The array of active boot options to scan.\r
+                               Entries marked as Appended will be skipped.\r
+                               Those of the rest that satisfy the survival\r
+                               policy will be added to BootOrder with\r
+                               BootOrderAppend().\r
+\r
+  @param[in]     ActiveCount   Number of elements in ActiveOption.\r
+\r
+\r
+  @retval RETURN_SUCCESS  BootOrder has been extended with any eligible boot\r
+                          options.\r
+\r
+  @return                 Error codes returned by BootOrderAppend().\r
+**/\r
+STATIC\r
+RETURN_STATUS\r
+BootOrderComplete (\r
+  IN OUT  BOOT_ORDER    *BootOrder,\r
+  IN OUT  ACTIVE_OPTION *ActiveOption,\r
+  IN      UINTN         ActiveCount\r
+  )\r
+{\r
+  RETURN_STATUS Status;\r
+  UINTN         Idx;\r
+\r
+  Status = RETURN_SUCCESS;\r
+  Idx = 0;\r
+  while (!RETURN_ERROR (Status) && Idx < ActiveCount) {\r
+    if (!ActiveOption[Idx].Appended) {\r
+      CONST BDS_COMMON_OPTION        *Current;\r
+      CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode;\r
+\r
+      Current = ActiveOption[Idx].BootOption;\r
+      FirstNode = Current->DevicePath;\r
+      if (FirstNode != NULL) {\r
+        CHAR16        *Converted;\r
+        STATIC CHAR16 ConvFallBack[] = L"<unable to convert>";\r
+        BOOLEAN       Keep;\r
+\r
+        Converted = ConvertDevicePathToText (FirstNode, FALSE, FALSE);\r
+        if (Converted == NULL) {\r
+          Converted = ConvFallBack;\r
+        }\r
+\r
+        Keep = TRUE;\r
+        if (DevicePathType(FirstNode) == MEDIA_DEVICE_PATH &&\r
+            DevicePathSubType(FirstNode) == MEDIA_HARDDRIVE_DP) {\r
+          //\r
+          // drop HD()\r
+          //\r
+          Keep = FALSE;\r
+        } else if (DevicePathType(FirstNode) == ACPI_DEVICE_PATH &&\r
+                   DevicePathSubType(FirstNode) == ACPI_DP) {\r
+          ACPI_HID_DEVICE_PATH *Acpi;\r
+\r
+          Acpi = (ACPI_HID_DEVICE_PATH *) FirstNode;\r
+          if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST &&\r
+              EISA_ID_TO_NUM (Acpi->HID) == 0x0a03) {\r
+            //\r
+            // drop PciRoot()\r
+            //\r
+            Keep = FALSE;\r
+          }\r
+        }\r
+\r
+        if (Keep) {\r
+          Status = BootOrderAppend (BootOrder, &ActiveOption[Idx]);\r
+          if (!RETURN_ERROR (Status)) {\r
+            DEBUG ((DEBUG_VERBOSE, "%a: keeping \"%s\"\n", __FUNCTION__,\r
+              Converted));\r
+          }\r
+        } else {\r
+          DEBUG ((DEBUG_VERBOSE, "%a: dropping \"%s\"\n", __FUNCTION__,\r
+            Converted));\r
+        }\r
+\r
+        if (Converted != ConvFallBack) {\r
+          FreePool (Converted);\r
+        }\r
+      }\r
+    }\r
+    ++Idx;\r
+  }\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
 \r
   Set the boot order based on configuration retrieved from QEMU.\r
@@ -1140,6 +1239,15 @@ SetBootOrderFromQemu (
   if (Status == RETURN_NOT_FOUND && BootOrder.Produced > 0) {\r
     //\r
     // No more OpenFirmware paths, some matches found: rewrite BootOrder NvVar.\r
+    // Some of the active boot options that have not been selected over fw_cfg\r
+    // should be preserved at the end of the boot order.\r
+    //\r
+    Status = BootOrderComplete (&BootOrder, ActiveOption, ActiveCount);\r
+    if (RETURN_ERROR (Status)) {\r
+      goto ErrorFreeActiveOption;\r
+    }\r
+\r
+    //\r
     // See Table 10 in the UEFI Spec 2.3.1 with Errata C for the required\r
     // attributes.\r
     //\r