]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c
ArmVirtualizationPkg: PlatformIntelBdsLib: add basic policy
[mirror_edk2.git] / OvmfPkg / Library / PlatformBdsLib / QemuBootOrder.c
index c8379b8fcacc29dfcb8c802f4fb8af82ff9fe62a..bd0fb768779bd7c84ad4a299dfbae4bfbfb5b110 100644 (file)
@@ -763,37 +763,27 @@ TranslateOfwNodes (
       TargetLun[0],\r
       TargetLun[1]\r
       );\r
-  } else if (NumNodes >= 3 &&\r
-             SubstringEq (OfwNode[1].DriverName, "ethernet") &&\r
-             SubstringEq (OfwNode[2].DriverName, "ethernet-phy")\r
-             ) {\r
+  } else {\r
     //\r
-    // OpenFirmware device path (Ethernet NIC):\r
+    // Generic OpenFirmware device path for PCI devices:\r
     //\r
-    //   /pci@i0cf8/ethernet@3[,2]/ethernet-phy@0\r
-    //        ^              ^                  ^\r
-    //        |              |                  fixed\r
+    //   /pci@i0cf8/ethernet@3[,2]\r
+    //        ^              ^\r
     //        |              PCI slot[, function] holding Ethernet card\r
     //        PCI root at system bus port, PIO\r
     //\r
     // UEFI device path prefix (dependent on presence of nonzero PCI function):\r
     //\r
-    //   PciRoot(0x0)/Pci(0x3,0x0)/MAC(525400E15EEF,0x1)\r
-    //   PciRoot(0x0)/Pci(0x3,0x2)/MAC(525400E15EEF,0x1)\r
-    //                                 ^            ^\r
-    //                                 MAC address  IfType (1 == Ethernet)\r
-    //\r
-    // (Some UEFI NIC drivers don't set 0x1 for IfType.)\r
+    //   PciRoot(0x0)/Pci(0x3,0x0)\r
+    //   PciRoot(0x0)/Pci(0x3,0x2)\r
     //\r
     Written = UnicodeSPrintAsciiFormat (\r
       Translated,\r
       *TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
-      "PciRoot(0x0)/Pci(0x%x,0x%x)/MAC",\r
+      "PciRoot(0x0)/Pci(0x%x,0x%x)",\r
       PciDevFun[0],\r
       PciDevFun[1]\r
       );\r
-  } else {\r
-    return RETURN_UNSUPPORTED;\r
   }\r
 \r
   //\r
@@ -1120,6 +1110,47 @@ BootOrderComplete (
 }\r
 \r
 \r
+/**\r
+  Delete Boot#### variables that stand for such active boot options that have\r
+  been dropped (ie. have not been selected by either matching or "survival\r
+  policy").\r
+\r
+  @param[in]  ActiveOption  The array of active boot options to scan. Each\r
+                            entry not marked as appended will trigger the\r
+                            deletion of the matching Boot#### variable.\r
+\r
+  @param[in]  ActiveCount   Number of elements in ActiveOption.\r
+**/\r
+STATIC\r
+VOID\r
+PruneBootVariables (\r
+  IN  CONST ACTIVE_OPTION *ActiveOption,\r
+  IN  UINTN               ActiveCount\r
+  )\r
+{\r
+  UINTN Idx;\r
+\r
+  for (Idx = 0; Idx < ActiveCount; ++Idx) {\r
+    if (!ActiveOption[Idx].Appended) {\r
+      CHAR16 VariableName[9];\r
+\r
+      UnicodeSPrintAsciiFormat (VariableName, sizeof VariableName, "Boot%04x",\r
+        ActiveOption[Idx].BootOption->BootCurrent);\r
+\r
+      //\r
+      // "The space consumed by the deleted variable may not be available until\r
+      // the next power cycle", but that's good enough.\r
+      //\r
+      gRT->SetVariable (VariableName, &gEfiGlobalVariableGuid,\r
+             0,   // Attributes, 0 means deletion\r
+             0,   // DataSize, 0 means deletion\r
+             NULL // Data\r
+             );\r
+    }\r
+  }\r
+}\r
+\r
+\r
 /**\r
 \r
   Set the boot order based on configuration retrieved from QEMU.\r
@@ -1269,12 +1300,13 @@ SetBootOrderFromQemu (
                     BootOrder.Produced * sizeof (*BootOrder.Data),\r
                     BootOrder.Data\r
                     );\r
-    DEBUG ((\r
-      DEBUG_INFO,\r
-      "%a: setting BootOrder: %a\n",\r
-      __FUNCTION__,\r
-      Status == EFI_SUCCESS ? "success" : "error"\r
-      ));\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "%a: setting BootOrder: %r\n", __FUNCTION__, Status));\r
+      goto ErrorFreeActiveOption;\r
+    }\r
+\r
+    DEBUG ((DEBUG_INFO, "%a: setting BootOrder: success\n", __FUNCTION__));\r
+    PruneBootVariables (ActiveOption, ActiveCount);\r
   }\r
 \r
 ErrorFreeActiveOption:\r