ieee1275: split up grub_machine_get_bootlocation
[grub.git] / grub-core / kern / ieee1275 / openfw.c
index ddb7783..62929d9 100644 (file)
@@ -561,3 +561,30 @@ grub_ieee1275_canonicalise_devname (const char *path)
   return NULL;
 }
 
+char *
+grub_ieee1275_get_boot_dev (void)
+{
+  char *bootpath;
+  grub_ssize_t bootpath_size;
+
+  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
+                                        &bootpath_size)
+      || bootpath_size <= 0)
+    {
+      /* Should never happen. */
+      grub_printf ("/chosen/bootpath property missing!\n");
+      return NULL;
+    }
+
+  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
+  if (! bootpath)
+    {
+      grub_print_error ();
+      return NULL;
+    }
+  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
+                              (grub_size_t) bootpath_size + 1, 0);
+  bootpath[bootpath_size] = '\0';
+
+  return bootpath;
+}