File grub2-efi-chainloader-root.patch of Package grub2.4793

From: Raymund Will <rw@suse.com>
Subject:  Use device part of chainloader target, if present.
References: bnc#871857, bnc#880177
Patch-Mainline: no

Otherwise chainloading is restricted to '$root', which might not even
be readable by EFI!

---
 grub-core/loader/efi/chainloader.c |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -706,12 +706,27 @@ grub_cmd_chainloader (grub_command_t cmd
       *(--p16) = 0;
     }
 
+  grub_dprintf ("chain", "cmd='%s'\n", filename);
   file = grub_file_open (filename);
   if (! file)
     goto fail;
 
   /* Get the root device's device path.  */
-  dev = grub_device_open (0);
+  if ( filename[0] != '(' ) {
+    dev = grub_device_open (0);
+  } else {
+    char *devname = grub_strdup (filename+1);
+    char *end;
+    if (! devname)
+      goto fail;
+    end = grub_strchr (devname, ')');
+    if (! end)
+      goto fail;
+    *end = '\0';
+    grub_dprintf ("chain", "cmd root='%s'\n", devname);
+    dev = grub_device_open (devname);
+    grub_free (devname);
+  }
   if (! dev)
     goto fail;