]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: QemuBootOrder: expand relative device paths in UEFI boot options
authorLaszlo Ersek <lersek@redhat.com>
Fri, 13 Sep 2013 08:14:36 +0000 (08:14 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 13 Sep 2013 08:14:36 +0000 (08:14 +0000)
The prefix matching logic in Match()
[OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c] expects UEFI boot options
to specify full (absolute) device paths. However, partial (relative)
device paths starting with a HD() node are valid for booting. By not
recognizing them, QemuBootOrder.c misses (and deletes) valid boot options
that would otherwise match the user's preference.

Just like BdsLibBootViaBootOption() expands such paths with the
BdsExpandPartitionPartialDevicePathToFull() function for booting, do the
same in QemuBootOrder.c for prefix matching.

This moves the very first call to
BdsExpandPartitionPartialDevicePathToFull() to an earlier point. The
following call tree explains it:

BdsEntry()                                          [IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c]
  PlatformBdsPolicyBehavior()                       [OvmfPkg/Library/PlatformBdsLib/BdsPlatform.c]
    SetBootOrderFromQemu()                          [OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c]
      Match()                                       [OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c]
        BdsExpandPartitionPartialDevicePathToFull() [IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c]
  BdsBootDeviceSelect()                             [IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c]
    BdsLibBootViaBootOption()                       [IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c]
      BdsExpandPartitionPartialDevicePathToFull()   [IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c]

This should be fine, for two reasons:

- the new, earlier call is still under BdsEntry(),

- BdsExpandPartitionPartialDevicePathToFull() expects to be called
  repeatedly, even with the same set of HD() device paths. This function
  implements its own caching for device paths, likely for performance
  reasons.

  That fits this patch well because whatever device paths we expand under
  PlatformBdsPolicyBehavior() can be quickly looked up in
  BdsBootDeviceSelect(), so no work (ie.
  BdsLibConnectAllDriversToAllControllers()) should be wasted.

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@14665 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Library/PlatformBdsLib/QemuBootOrder.c

index c9b8556fab0f28c8932ce78deaa3ce640b9e8225..e9580b98d052465c8bc8aba12738aaa14bacb2fd 100644 (file)
@@ -881,6 +881,34 @@ Match (
     return FALSE;\r
   }\r
 \r
+  //\r
+  // Attempt to expand any relative UEFI device path starting with HD() to an\r
+  // absolute device path first. The logic imitates BdsLibBootViaBootOption().\r
+  // We don't have to free the absolute device path,\r
+  // BdsExpandPartitionPartialDevicePathToFull() has internal caching.\r
+  //\r
+  Result = FALSE;\r
+  if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH &&\r
+      DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP) {\r
+    EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath;\r
+    CHAR16                   *AbsConverted;\r
+\r
+    AbsDevicePath = BdsExpandPartitionPartialDevicePathToFull (\r
+                      (HARDDRIVE_DEVICE_PATH *) DevicePath);\r
+    if (AbsDevicePath == NULL) {\r
+      goto Exit;\r
+    }\r
+    AbsConverted = ConvertDevicePathToText (AbsDevicePath, FALSE, FALSE);\r
+    if (AbsConverted == NULL) {\r
+      goto Exit;\r
+    }\r
+    DEBUG ((DEBUG_VERBOSE,\r
+      "%a: expanded relative device path \"%s\" for prefix matching\n",\r
+      __FUNCTION__, Converted));\r
+    FreePool (Converted);\r
+    Converted = AbsConverted;\r
+  }\r
+\r
   //\r
   // Is Translated a prefix of Converted?\r
   //\r
@@ -892,6 +920,7 @@ Match (
     Converted,\r
     Result ? "match" : "no match"\r
     ));\r
+Exit:\r
   FreePool (Converted);\r
   return Result;\r
 }\r