Port yaboot logic for various powerpc machine types
authorColin Watson <cjwatson@debian.org>
Tue, 28 Jan 2014 14:40:02 +0000 (14:40 +0000)
committerPeter Michael Green <plugwash@raspbian.org>
Sun, 28 Jul 2024 22:42:11 +0000 (22:42 +0000)
Some powerpc machines require not updating the NVRAM.  This can be handled
by existing grub-install command-line options, but it's friendlier to detect
this automatically.

On chrp_ibm machines, use the nvram utility rather than nvsetenv.  (This
is possibly suitable for other machines too, but that needs to be
verified.)

Forwarded: no
Last-Update: 2014-10-15

Patch-Name: install-powerpc-machtypes.patch

Gbp-Pq: Name install-powerpc-machtypes.patch

grub-core/osdep/basic/platform.c
grub-core/osdep/linux/platform.c
grub-core/osdep/unix/platform.c
grub-core/osdep/windows/platform.c
include/grub/util/install.h
util/grub-install.c

index 68813de9a3277372746089ca45b8d0b84a5ad651..ec2a2c5a1460c369cd8326a0e228fbd009b9ebfe 100644 (file)
@@ -30,3 +30,8 @@ grub_install_get_default_x86_platform (void)
   return "i386-pc";
 }
 
+const char *
+grub_install_get_default_powerpc_machtype (void)
+{
+  return "generic";
+}
index 2e7f7208691ecd43e399c823fdb6194f84defabf..5b37366d4d8a260f4870358f8dbe2eb72e1d0594 100644 (file)
@@ -24,6 +24,7 @@
 #include <grub/emu/misc.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -184,3 +185,74 @@ grub_install_get_default_x86_platform (void)
   grub_util_info ("... not found");
   return "i386-pc";
 }
+
+const char *
+grub_install_get_default_powerpc_machtype (void)
+{
+  FILE *fp;
+  char *buf = NULL;
+  size_t len = 0;
+  const char *machtype = "generic";
+
+  fp = grub_util_fopen ("/proc/cpuinfo", "r");
+  if (! fp)
+    return machtype;
+
+  while (getline (&buf, &len, fp) > 0)
+    {
+      if (strncmp (buf, "pmac-generation",
+                  sizeof ("pmac-generation") - 1) == 0)
+       {
+         if (strstr (buf, "NewWorld"))
+           {
+             machtype = "pmac_newworld";
+             break;
+           }
+         if (strstr (buf, "OldWorld"))
+           {
+             machtype = "pmac_oldworld";
+             break;
+           }
+       }
+
+      if (strncmp (buf, "motherboard", sizeof ("motherboard") - 1) == 0 &&
+         strstr (buf, "AAPL"))
+       {
+         machtype = "pmac_oldworld";
+         break;
+       }
+
+      if (strncmp (buf, "machine", sizeof ("machine") - 1) == 0 &&
+         strstr (buf, "CHRP IBM"))
+       {
+         if (strstr (buf, "qemu"))
+           {
+             machtype = "chrp_ibm_qemu";
+             break;
+           }
+         else
+           {
+             machtype = "chrp_ibm";
+             break;
+           }
+       }
+
+      if (strncmp (buf, "platform", sizeof ("platform") - 1) == 0)
+       {
+         if (strstr (buf, "Maple"))
+           {
+             machtype = "maple";
+             break;
+           }
+         if (strstr (buf, "Cell"))
+           {
+             machtype = "cell";
+             break;
+           }
+       }
+    }
+
+  free (buf);
+  fclose (fp);
+  return machtype;
+}
index de712211cf0909f732bbe95f1e959e6ab182b638..035a99fd74c14991bc7294f39fbf32ace2034303 100644 (file)
@@ -218,13 +218,29 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
   else
     boot_device = get_ofpathname (install_device);
 
-  if (grub_util_exec ((const char * []){ "nvsetenv", "boot-device",
-         boot_device, NULL }))
+  if (strcmp (grub_install_get_default_powerpc_machtype (), "chrp_ibm") == 0)
     {
-      char *cmd = xasprintf ("setenv boot-device %s", boot_device);
-      grub_util_error (_("`nvsetenv' failed. \nYou will have to set `boot-device' variable manually.  At the IEEE1275 prompt, type:\n  %s\n"),
-                      cmd);
-      free (cmd);
+      char *arg = xasprintf ("boot-device=%s", boot_device);
+      if (grub_util_exec ((const char * []){ "nvram",
+         "--update-config", arg, NULL }))
+       {
+         char *cmd = xasprintf ("setenv boot-device %s", boot_device);
+         grub_util_error (_("`nvram' failed. \nYou will have to set `boot-device' variable manually.  At the IEEE1275 prompt, type:\n  %s\n"),
+                          cmd);
+         free (cmd);
+       }
+      free (arg);
+    }
+  else
+    {
+      if (grub_util_exec ((const char * []){ "nvsetenv", "boot-device",
+             boot_device, NULL }))
+       {
+         char *cmd = xasprintf ("setenv boot-device %s", boot_device);
+         grub_util_error (_("`nvsetenv' failed. \nYou will have to set `boot-device' variable manually.  At the IEEE1275 prompt, type:\n  %s\n"),
+                          cmd);
+         free (cmd);
+       }
     }
 
   free (boot_device);
index af04c1a1ea73ee45dcf0fb2e5564b05d9698d4df..e9156af5f398471396dbb9d7bc3e4941f9a807da 100644 (file)
@@ -128,6 +128,12 @@ grub_install_get_default_x86_platform (void)
     return "i386-efi";
 }
 
+const char *
+grub_install_get_default_powerpc_machtype (void)
+{
+  return "generic";
+}
+
 static void *
 get_efi_variable (const wchar_t *varname, ssize_t *len)
 {
index 35cf17a8d932b1e65044a4895941f465f0fb65cc..ca102b4069468883905f7ba3c4426741180476b0 100644 (file)
@@ -224,6 +224,9 @@ grub_install_get_default_arm_platform (void);
 const char *
 grub_install_get_default_x86_platform (void);
 
+const char *
+grub_install_get_default_powerpc_machtype (void);
+
 int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
                           const char *efifile_path,
index 1f691871eb9de59e3479fa75ad51a30df9f94315..4c155ec8cb469774246bf878ce7933dcc3e53d00 100644 (file)
@@ -1228,7 +1228,18 @@ main (int argc, char *argv[])
 
   if (platform == GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
     {
+      const char *machtype = grub_install_get_default_powerpc_machtype ();
       int is_guess = 0;
+
+      if (strcmp (machtype, "pmac_oldworld") == 0)
+       update_nvram = 0;
+      else if (strcmp (machtype, "cell") == 0)
+       update_nvram = 0;
+      else if (strcmp (machtype, "generic") == 0)
+       update_nvram = 0;
+      else if (strcmp (machtype, "chrp_ibm_qemu") == 0)
+       update_nvram = 0;
+
       if (!macppcdir)
        {
          char *d;