Package: grub2 / 2.02+dfsg1-20

install_powerpc_machtypes.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
From 4ee18c4a571e455f1a14762006f91d6f0ae76f41 Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@debian.org>
Date: Tue, 28 Jan 2014 14:40:02 +0000
Subject: Port yaboot logic for various powerpc machine types

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
---
 grub-core/osdep/basic/platform.c   |  5 +++
 grub-core/osdep/linux/platform.c   | 72 ++++++++++++++++++++++++++++++
 grub-core/osdep/unix/platform.c    | 28 +++++++++---
 grub-core/osdep/windows/platform.c |  6 +++
 include/grub/util/install.h        |  3 ++
 util/grub-install.c                | 11 +++++
 6 files changed, 119 insertions(+), 6 deletions(-)

diff --git a/grub-core/osdep/basic/platform.c b/grub-core/osdep/basic/platform.c
index 4b5502aeb..2ab907976 100644
--- a/grub-core/osdep/basic/platform.c
+++ b/grub-core/osdep/basic/platform.c
@@ -24,3 +24,8 @@ grub_install_get_default_x86_platform (void)
   return "i386-pc";
 }
 
+const char *
+grub_install_get_default_powerpc_machtype (void)
+{
+  return "generic";
+}
diff --git a/grub-core/osdep/linux/platform.c b/grub-core/osdep/linux/platform.c
index 35f1bcc0e..9805c36d4 100644
--- a/grub-core/osdep/linux/platform.c
+++ b/grub-core/osdep/linux/platform.c
@@ -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>
 
@@ -145,3 +146,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;
+}
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
index a3fcfcaca..28cb37e15 100644
--- a/grub-core/osdep/unix/platform.c
+++ b/grub-core/osdep/unix/platform.c
@@ -212,13 +212,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);
diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c
index 912269191..c30025b13 100644
--- a/grub-core/osdep/windows/platform.c
+++ b/grub-core/osdep/windows/platform.c
@@ -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)
 {
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index 5ca4811cd..9f517a1bb 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -206,6 +206,9 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
+const char *
+grub_install_get_default_powerpc_machtype (void);
+
 void
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
diff --git a/util/grub-install.c b/util/grub-install.c
index a73d12e87..57d6aab76 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -1155,7 +1155,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;