Skip to contentSkip to conversation

grub2 efi patches

PATCH Alexandre Boeglin 4 participants 33 messages Nov 3, 2007 – Feb 12, 2008

lore
Share & tools
lore
#0 lore raw

Hello,

Here are a few patches for grub2, against cvs head:

grub2_arg_doubledash.patch fixes a bug in the handling of the '--' argument,

grub2_efi_chainloader_options.patch adds support for efi chainload options, it is not really beautiful (for instance, the ascii to utf16 conversion), but it works for the MacOSX loader,

grub2_efi_grub_prefix.patch uses the grub_prefix variable to set the prefix environment variable, instead of the directory in which grub.efi is. This allows to have grub.efi and the modules in different folders, and the old behaviour should be preserved, if the grub_prefix is an empty string,

grub2_efi_halt_reboot.patch adds support for the reboot and halt commands, provided by efi runtime services.

Regards,
Alex

P.S.: I sent the patches as attachments, I don't know if they will be discarded by the list robot or not ...

Signature · 4 lines
Alexandre Boeglin
email: alex (at) boeglin (dot) org
jabber: alex (at) im (dot) apinc (dot) org
website: http://boeglin.org/

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7

arg.c +1 -1
diff -u -r1.7 arg.c
@@ -313,7 +313,7 @@
 	  if (grub_strlen (arg) == 2)
 	    {
 	      for (curarg++; curarg < argc; curarg++)
-		if (add_arg (arg) != 0)
+		if (add_arg (argv[curarg]) != 0)
 		  goto fail;
 	      break;
 	    }

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2

grub/efi/chainloader.h +1 -1
diff -u -r1.2 chainloader.h
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2

efi/chainloader.c +35 -7

78 lines not on this page · raw message

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2

efi/chainloader_normal.c +1 -4
diff -u -r1.2 chainloader_normal.c
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }
 

Index: kern/efi/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/efi/init.c,v
retrieving revision 1.5

efi/init.c +13 -1
diff -u -r1.5 init.c
@@ -53,7 +53,19 @@
       device = grub_efidisk_get_device_name (image->device_handle);
       file = grub_efi_get_filename (image->file_path);
       
-      if (device && file)
+      if (grub_prefix[0] != '\0' && device)
+	{
+	  char *prefix;
+	  prefix = grub_malloc (1 + grub_strlen (device) + 1
+				+ grub_strlen (grub_prefix) + 1);
+	  if (prefix)
+	    {
+	      grub_sprintf (prefix, "(%s)%s", device, grub_prefix);
+	      grub_env_set ("prefix", prefix);
+	      grub_free (prefix);
+	    }
+	}
+      else if (device && file)
 	{
 	  char *p;
 	  char *prefix;
commands/i386/efi/halt.c +47 -0

47 lines not on this page · raw message

commands/i386/efi/reboot.c +47 -0

47 lines not on this page · raw message

conf/i386-efi.rmk +11 -1
diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/conf/i386-efi.rmk grub2/conf/i386-efi.rmk
@@ -76,7 +76,7 @@
 
 # Modules.
 pkgdata_MODULES = kernel.mod normal.mod _chain.mod chain.mod \
-	_linux.mod linux.mod cpuid.mod
+	_linux.mod linux.mod cpuid.mod halt.mod reboot.mod
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -140,4 +140,14 @@
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
 cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+halt_mod_SOURCES = commands/i386/efi/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+reboot_mod_SOURCES = commands/i386/efi/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
include/grub/efi/efi.h +2 -0
diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/include/grub/efi/efi.h grub2/include/grub/efi/efi.h
@@ -54,6 +54,8 @@
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);
kern/efi/efi.c +16 -0
diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/kern/efi/efi.c grub2/kern/efi/efi.c
@@ -162,6 +162,22 @@
 					      0, 0);
 }
 
+void
+grub_reboot (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->reset_system (
+      GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
+void
+grub_halt (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->reset_system (
+      GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
 int
 grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
 {
#1 lore raw
Quoted 4 lines · Alexandre Boeglin

grub2_efi_chainloader_options.patch adds support for efi chainload options,
it is not really beautiful (for instance, the ascii to utf16 conversion), but it works for the MacOSX loader,

Sorry, there was a mistake in the previous one ...

By the way, it's using boot_services->allocate_pool instead of grub_malloc. I don't know if it's okay, but when I tried using grub_malloc, I was getting "free magic is broken 0x0" errors.

Alex

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2

grub/efi/chainloader.h +1 -1
diff -u -r1.2 chainloader.h
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2

efi/chainloader.c +35 -7

78 lines not on this page · raw message

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2

efi/chainloader_normal.c +1 -4
diff -u -r1.2 chainloader_normal.c
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }
 
#2 lore raw
Quoted 1 line · Alexandre Boeglin

Sorry, there was a mistake in the previous one ...

Oops, and line 91 of this one should be

+ loaded_image->load_options_size = options_len + sizeof (*options);

instead of

+ loaded_image->load_options_size = options_len + 1;

Alex

#3 lore raw
Quoted 3 lines · Alexandre Boeglin
Quoted 1 line · Alexandre Boeglin

Sorry, there was a mistake in the previous one ...

Oops, and line 91 of this one should be

Hi, here is a "more correct" version of this patch: it also frees the memory allocated to the options string when appropriate.

Alex

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2

grub/efi/chainloader.h +1 -1
diff -u -r1.2 chainloader.h
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2

efi/chainloader.c +44 -7

109 lines not on this page · raw message

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2

efi/chainloader_normal.c +1 -4
diff -u -r1.2 chainloader_normal.c
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }
 
#5 lore raw
In reply to Alexandre Boeglin
Quoted 8 lines · Alexandre Boeglin
Quoted 4 lines · Alexandre Boeglin

grub2_efi_chainloader_options.patch adds support for efi chainload options,
it is not really beautiful (for instance, the ascii to utf16 conversion), but it works for the MacOSX loader,

Sorry, there was a mistake in the previous one ...

Ok :-)

Quoted 3 lines

By the way, it's using boot_services->allocate_pool instead of grub_malloc. I don't know if it's okay, but when I tried using grub_malloc, I was getting "free magic is broken 0x0" errors.

Please use grub_malloc. If you get this error, something is most likely writing to unallocated memory or something like that...

Quoted 54 lines

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2
diff -u -r1.2 chainloader.h

grub/efi/chainloader.h +1 -1
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2
diff -u -r1.2 chainloader.c

efi/chainloader.c +6 -3
@@ -17,8 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* TODO: support load options.  */
-
 #include <grub/loader.h>
 #include <grub/file.h>
 #include <grub/err.h>
@@ -175,7 +173,7 @@
 }
 
 void
-grub_chainloader_cmd (const char *filename)
+grub_chainloader_cmd (int argc, char *argv[])
 {
   grub_file_t file = 0;
   grub_ssize_t size;
@@ -185,6 +183,11 @@
   grub_device_t dev = 0;
   grub_efi_device_path_t *dp = 0;
   grub_efi_loaded_image_t *loaded_image;
+  char *filename = argv[0];
+  grub_efi_char16_t *options = NULL, *p;
+  int i, j, options_len = 0;
+
+  b = grub_efi_system_table->boot_services;
 
   grub_dl_ref (my_mod);
 
@@ -192,6 +195,30 @@
   address = 0;

efi/chainloader.c line 205

Quoted 10 lines
efi/chainloader.c +8 -0
   image_handle = 0;
   file_path = 0;
+
+  if (argc == 0)
+  {
+    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
+    goto fail;
+  }
+
+  /* copy options */

/* Copy options. */

efi/chainloader.c line 213

Quoted 8 lines
efi/chainloader.c +8 -0
+  if (argc > 1)
+  {
+    for (i = 1; i < argc; i++)
+      options_len += (grub_strlen (argv[i]) + 1) * sizeof (*options);
+
+    status = b->allocate_pool (GRUB_EFI_LOADER_DATA, options_len + sizeof (*options), &options);
+    if (status != GRUB_EFI_SUCCESS)
+      goto fail;

Please use grub_malloc.

There are several ways to debug mm.c...

Quoted 57 lines
efi/chainloader.c +13 -4
+    p = options;
+
+    for (i = 1; i < argc; i++){
+      *p++ = ' ';
+      for (j = 0; j < grub_strlen (argv[i]) + 1; j++)
+        p[j] = argv[i][j];
+    }
+  }
 
   b = grub_efi_system_table->boot_services;
 
@@ -267,6 +294,10 @@
       goto fail;
     }
   loaded_image->device_handle = dev_handle;
+
+  if (options)
+    loaded_image->load_options = options;
+    loaded_image->load_options_size = options_len + 1;
 
   grub_file_close (file);
   grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0);
@@ -292,10 +323,7 @@
 static void
 grub_rescue_cmd_chainloader (int argc, char *argv[])
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (argv[0]);
+  grub_chainloader_cmd (argc, argv);
 }
 
 static const char loader_name[] = "chainloader";

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2
diff -u -r1.2 chainloader_normal.c

efi/chainloader_normal.c +1 -4
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }
 

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw
In reply to Alexandre Boeglin
Quoted 8 lines · Alexandre Boeglin
Quoted 3 lines · Alexandre Boeglin
Quoted 1 line · Alexandre Boeglin

Sorry, there was a mistake in the previous one ...

Oops, and line 91 of this one should be

Hi, here is a "more correct" version of this patch: it also frees the memory allocated to the options string when appropriate.

I should've started with this patch ;-)

I can better do a full review again for clarity :-)

Quoted 70 lines

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2
diff -u -r1.2 chainloader.h

grub/efi/chainloader.h +1 -1
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2
diff -u -r1.2 chainloader.c

efi/chainloader.c +8 -3
@@ -17,8 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* TODO: support load options.  */
-
 #include <grub/loader.h>
 #include <grub/file.h>
 #include <grub/err.h>
@@ -38,6 +36,8 @@
 
 static grub_efi_physical_address_t address;
 static grub_efi_uintn_t pages;
+static grub_efi_char16_t *options;
+static grub_efi_uintn_t options_len;
 static grub_efi_device_path_t *file_path;
 static grub_efi_handle_t image_handle;
 
@@ -49,6 +49,8 @@
   b = grub_efi_system_table->boot_services;
   b->unload_image (image_handle);
   b->free_pages (address, pages);
+  if (options)
+    b->free_pool (options);
   grub_free (file_path);
 
   grub_dl_unref (my_mod);
@@ -175,7 +177,7 @@
 }
 
 void
-grub_chainloader_cmd (const char *filename)
+grub_chainloader_cmd (int argc, char *argv[])
 {
   grub_file_t file = 0;
   grub_ssize_t size;
@@ -185,16 +187,47 @@
   grub_device_t dev = 0;
   grub_efi_device_path_t *dp = 0;
   grub_efi_loaded_image_t *loaded_image;
+  char *filename = argv[0];
 
   grub_dl_ref (my_mod);
 
   /* Initialize some global variables.  */
   address = 0;
+  options = 0;
+  options_len = 0;

efi/chainloader.c line 207

Quoted 10 lines
efi/chainloader.c +5 -0
   image_handle = 0;
   file_path = 0;
 
   b = grub_efi_system_table->boot_services;
 
+  if (argc == 0)
+  {
+    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
+    goto fail;
+  }

The indentation is not right.

efi/chainloader.c line 209

Quoted 1 line
efi/chainloader.c +1 -0
+  /* copy options */

/* Copy options. */

efi/chainloader.c line 211

Quoted 2 lines
efi/chainloader.c +2 -0
+  if (argc > 1)
+  {

The indentation is not right.

efi/chainloader.c line 222

Quoted 11 lines
efi/chainloader.c +11 -0
+    grub_efi_char16_t *p;
+    grub_efi_int16_t i;
+    grub_efi_uint16_t j;
+    for (i = 1; i < argc; i++)
+      options_len += (grub_strlen (argv[i]) + 1) * sizeof (*options);
+    options_len += sizeof (*options); /* \0 */
+
+    status = b->allocate_pool (GRUB_EFI_LOADER_DATA, options_len, (void *) &options);
+    if (status != GRUB_EFI_SUCCESS)
+      goto fail;
+    p = options;

Please use grub_malloc here, I think it should work for what you are doing, right?

Quoted 11 lines
efi/chainloader.c +7 -0
+    for (i = 1; i < argc; i++){
+      *p++ = ' ';
+      for (j = 0; j < grub_strlen (argv[i]) + 1; j++)
+        p[j] = (grub_efi_char16_t) argv[i][j];
+    }
+  }
+
   file = grub_file_open (filename);
   if (! file)
     goto fail;

efi/chainloader.c line 306

Quoted 6 lines
efi/chainloader.c +3 -0
@@ -268,6 +301,10 @@
     }
   loaded_image->device_handle = dev_handle;
 
+  if (options_len)
+    loaded_image->load_options = options;
+    loaded_image->load_options_size = options_len;

The second loaded_image... line seems to be incorrectly indented.

Quoted 42 lines
efi/chainloader.c +4 -4
   grub_file_close (file);
   grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0);
   return;
@@ -286,16 +323,16 @@
   if (address)
     b->free_pages (address, pages);
 
+  if (options)
+    b->free_pool (options);
+
   grub_dl_unref (my_mod);
 }
 
 static void
 grub_rescue_cmd_chainloader (int argc, char *argv[])
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (argv[0]);
+  grub_chainloader_cmd (argc, argv);
 }
 
 static const char loader_name[] = "chainloader";

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2
diff -u -r1.2 chainloader_normal.c

efi/chainloader_normal.c +1 -4
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }
#6 lore raw
In reply to Alexandre Boeglin

Alexandre Boeglin <[email protected]> writes:

Hi,

Quoted 1 line

Here are a few patches for grub2, against cvs head:

Great! Thanks for working on this! Can you please send in ChangeLog entries for these patches?

Quoted 11 lines

grub2_arg_doubledash.patch fixes a bug in the handling of the '--' argument,

grub2_efi_chainloader_options.patch adds support for efi chainload options, it is not really beautiful (for instance, the ascii to utf16 conversion), but it works for the MacOSX loader,

grub2_efi_grub_prefix.patch uses the grub_prefix variable to set the prefix environment variable, instead of the directory in which grub.efi is. This allows to have grub.efi and the modules in different folders, and the old behaviour should be preserved, if the grub_prefix is an empty string,

How about passing it as an argument to GRUB 2? I assume EFI can do this? This is what we do on open firmware, IIRC.

Quoted 8 lines

grub2_efi_halt_reboot.patch adds support for the reboot and halt commands, provided by efi runtime services.

Regards,
Alex

P.S.: I sent the patches as attachments, I don't know if they will be discarded by the list robot or not ...

No, this is even preferred. Could you use "diff -up" for future patches?

Quoted 13 lines

Alexandre Boeglin
email: alex (at) boeglin (dot) org
jabber: alex (at) im (dot) apinc (dot) org
website: http://boeglin.org/

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7
diff -u -r1.7 arg.c

arg.c line 319

Quoted 8 lines
arg.c +1 -1
@@ -313,7 +313,7 @@
 	  if (grub_strlen (arg) == 2)
 	    {
 	      for (curarg++; curarg < argc; curarg++)
-		if (add_arg (arg) != 0)
+		if (add_arg (argv[curarg]) != 0)
 		  goto fail;
 	      break;
 	    }

Looks fine to me.

Quoted 53 lines

Index: include/grub/efi/chainloader.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v retrieving revision 1.2
diff -u -r1.2 chainloader.h

grub/efi/chainloader.h +1 -1
@@ -19,6 +19,6 @@
 #ifndef GRUB_EFI_CHAINLOADER_HEADER
 #define GRUB_EFI_CHAINLOADER_HEADER	1
 
-void grub_chainloader_cmd (const char *filename);
+void grub_chainloader_cmd (int argc, char *argv[]);
 
 #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */

Index: loader/efi/chainloader.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v retrieving revision 1.2
diff -u -r1.2 chainloader.c

efi/chainloader.c +6 -3
@@ -17,8 +17,6 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* TODO: support load options.  */
-
 #include <grub/loader.h>
 #include <grub/file.h>
 #include <grub/err.h>
@@ -175,7 +173,7 @@
 }
 
 void
-grub_chainloader_cmd (const char *filename)
+grub_chainloader_cmd (int argc, char *argv[])
 {
   grub_file_t file = 0;
   grub_ssize_t size;
@@ -185,6 +183,11 @@
   grub_device_t dev = 0;
   grub_efi_device_path_t *dp = 0;
   grub_efi_loaded_image_t *loaded_image;
+  char *filename = argv[0];
+  grub_efi_char16_t **options = NULL, *p;
+  int i, j, options_len = 0;
+
+  b = grub_efi_system_table->boot_services;
 
   grub_dl_ref (my_mod);
 

efi/chainloader.c line 203

Quoted 9 lines
efi/chainloader.c +6 -0
@@ -192,6 +195,30 @@
   address = 0;
   image_handle = 0;
   file_path = 0;
+
+  if (argc == 0)
+  {
+    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
+    goto fail;
+  }

This indentation doesn't look right. Same for the other "if"s.

efi/chainloader.c line 211

Quoted 7 lines
efi/chainloader.c +7 -0
+  /* copy options */
+  if (argc > 1)
+  {
+    for (i = 1; i < argc; i++)
+      options_len += (grub_strlen (argv[i]) + 1) * sizeof (**options);
+
+    status = b->allocate_pool (GRUB_EFI_LOADER_DATA, options_len + sizeof (**options), options);

Do you deallocate when an error occurs?

efi/chainloader.c line 220

Quoted 9 lines
efi/chainloader.c +9 -0
+    if (status != GRUB_EFI_SUCCESS)
+      goto fail;
+    p = *options;
+
+    for (i = 1; i < argc; i++){
+      *p++ = ' ';
+      for (j = 0; j < grub_strlen (argv[i]) + 1; j++)
+        p[j] = argv[i][j];
+    }

This indentation is not right.

efi/chainloader.c line 300

Quoted 12 lines
efi/chainloader.c +5 -0
+  }
 
   b = grub_efi_system_table->boot_services;
 
@@ -267,6 +294,10 @@
       goto fail;
     }
   loaded_image->device_handle = dev_handle;
+
+  if (*options)
+    loaded_image->load_options = *options;
+    loaded_image->load_options_size = options_len + 1;

This indentation is weird. Did you forget { and }? That's what this indentation suggests.

Quoted 22 lines
efi/chainloader.c +1 -4
   grub_file_close (file);
   grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0);
@@ -292,10 +323,7 @@
 static void
 grub_rescue_cmd_chainloader (int argc, char *argv[])
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (argv[0]);
+  grub_chainloader_cmd (argc, argv);
 }
 
 static const char loader_name[] = "chainloader";

Index: loader/efi/chainloader_normal.c
===================================================================
RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v retrieving revision 1.2
diff -u -r1.2 chainloader_normal.c

efi/chainloader_normal.c line 31

Quoted 10 lines
efi/chainloader_normal.c +1 -4
@@ -26,10 +26,7 @@
 chainloader_command (struct grub_arg_list *state __attribute__ ((unused)),
 		     int argc, char **args)
 {
-  if (argc == 0)
-    grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
-  else
-    grub_chainloader_cmd (args[0]);
+  grub_chainloader_cmd (argc, args);
   return grub_errno;
 }

Did you have a look at GRUB_COMMAND_FLAG_NO_ARG_PARSE? I think it might be useful in your case. It disables the argument parser so you do not have to use "--".

Quoted 174 lines

Index: kern/efi/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/efi/init.c,v
retrieving revision 1.5
diff -u -r1.5 init.c

efi/init.c +13 -1
@@ -53,7 +53,19 @@
       device = grub_efidisk_get_device_name (image->device_handle);
       file = grub_efi_get_filename (image->file_path);
 
-      if (device && file)
+      if (grub_prefix[0] != '\0' && device)
+	{
+	  char *prefix;
+	  prefix = grub_malloc (1 + grub_strlen (device) + 1
+				+ grub_strlen (grub_prefix) + 1);
+	  if (prefix)
+	    {
+	      grub_sprintf (prefix, "(%s)%s", device, grub_prefix);
+	      grub_env_set ("prefix", prefix);
+	      grub_free (prefix);
+	    }
+	}
+      else if (device && file)
 	{
 	  char *p;
 	  char *prefix;

diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/commands/i386/efi/halt.c grub2/commands/i386/efi/halt.c

commands/i386/efi/halt.c +47 -0
@@ -0,0 +1,47 @@
+/* halt.c - command to halt the computer.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/efi/efi.h>
+
+static grub_err_t
+grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
+		 int argc __attribute__ ((unused)),
+		 char **args __attribute__ ((unused)))
+
+{
+  grub_halt ();
+  return 0;
+}
+
+
+
+GRUB_MOD_INIT(halt)
+{
+  (void)mod;			/* To stop warning. */
+  grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
+			 "halt", "Halt the computer", 0);
+}
+
+GRUB_MOD_FINI(halt)
+{
+  grub_unregister_command ("halt");
+}

diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/commands/i386/efi/reboot.c grub2/commands/i386/efi/reboot.c

commands/i386/efi/reboot.c +47 -0
@@ -0,0 +1,47 @@
+/* reboot.c - command to reboot the computer.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/efi/efi.h>
+
+static grub_err_t
+grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)),
+		 int argc __attribute__ ((unused)),
+		 char **args __attribute__ ((unused)))
+
+{
+  grub_reboot ();
+  return 0;
+}
+
+
+
+GRUB_MOD_INIT(reboot)
+{
+  (void)mod;			/* To stop warning. */
+  grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH,
+			 "reboot", "Reboot the computer", 0);
+}
+
+GRUB_MOD_FINI(reboot)
+{
+  grub_unregister_command ("reboot");
+}

diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/conf/i386-efi.rmk grub2/conf/i386-efi.rmk

conf/i386-efi.rmk +11 -1
@@ -76,7 +76,7 @@
 
 # Modules.
 pkgdata_MODULES = kernel.mod normal.mod _chain.mod chain.mod \
-	_linux.mod linux.mod cpuid.mod
+	_linux.mod linux.mod cpuid.mod halt.mod reboot.mod
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -140,4 +140,14 @@
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
 cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+halt_mod_SOURCES = commands/i386/efi/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+reboot_mod_SOURCES = commands/i386/efi/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk

diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/include/grub/efi/efi.h grub2/include/grub/efi/efi.h

include/grub/efi/efi.h +2 -0
@@ -54,6 +54,8 @@
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);

diff -ruNa -x CVS -x '*.mk' -x grub.efi -x '*.d' grub2_orig/kern/efi/efi.c grub2/kern/efi/efi.c

kern/efi/efi.c line 170

Quoted 9 lines
kern/efi/efi.c +6 -0
@@ -162,6 +162,22 @@
 					      0, 0);
 }
 
+void
+grub_reboot (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->reset_system (
+      GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);

Please move the "(" to the next line.

kern/efi/efi.c line 179

Quoted 9 lines
kern/efi/efi.c +9 -0
+}
+
+void
+grub_halt (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->reset_system (
+      GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+}

Same here.

--
Marco

#7 lore raw

Hello,

Sorry for not replying earlier, I'm currently busy trying to figure out how to access the Compatibility Support Module, and possibly enable lecagy boot.

Quoted 8 lines · Marco Gerards
Quoted 4 lines · Alexandre Boeglin

grub2_efi_grub_prefix.patch uses the grub_prefix variable to set the prefix environment variable, instead of the directory in which grub.efi is. This allows to have grub.efi and the modules in different folders, and the old behaviour should be preserved, if the grub_prefix is an empty string,

How about passing it as an argument to GRUB 2? I assume EFI can do this? This is what we do on open firmware, IIRC.

Well, this should also work if grub is the main bootloader of your machine, but I think it would be a bit harder in the case you have grub on a EFI bootable CD or USB stick (or that would depend on the primary bootloader in this case). But actually, I don't know this part very well ...

I also still have to clean the chainloader options patch, but here is the changelog for the others:

2007-11-18 Alexandre Boeglin <[email protected]>

* normal/arg.c (grub_arg_parse): If one of the args is "--", add remaining N args, instead of "--" N times.

* commands/i386/efi/halt.c: New file.

* commands/i386/efi/reboot.c: New file.

* conf/i386-efi.rmk (grub_emu_SOURCES): Replace i386/pc/halt.c and reboot.c by i386/efi/halt.c and reboot.c.
(grub_install_SOURCES): Add halt.mod and reboot.mod. (halt_mod_SOURCES): New variable.
(halt_mod_CFLAGS): Likewise.
(halt_mod_LDFLAGS): Likewise.
(reboot_mod_SOURCES): Likewise.
(reboot_mod_CFLAGS): Likewise.
(reboot_mod_LDFLAGS): Likewise.

* include/grub/efi/efi.h (grub_reboot): New function declaration. (grub_halt): Likewise.

* kern/efi/efi.c (grub_reboot): New function.
(grub_halt): Likewise.

And I just received the copyright assignment papers yesterday. I will post them on monday.

Regards,
Alex

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7

arg.c +1 -1
diff -u -p -r1.7 arg.c
@@ -313,7 +313,7 @@ grub_arg_parse (grub_command_t cmd, int 
 	  if (grub_strlen (arg) == 2)
 	    {
 	      for (curarg++; curarg < argc; curarg++)
-		if (add_arg (arg) != 0)
+		if (add_arg (argv[curarg]) != 0)
 		  goto fail;
 	      break;
 	    }

Index: commands/i386/efi/halt.c
===================================================================
RCS file: commands/i386/efi/halt.c

i386/efi/halt.c new file +47 -0

47 lines not on this page · raw message

Index: commands/i386/efi/reboot.c
===================================================================
RCS file: commands/i386/efi/reboot.c

i386/efi/reboot.c new file +47 -0

47 lines not on this page · raw message

Index: conf/i386-efi.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/i386-efi.rmk,v
retrieving revision 1.24

i386-efi.rmk +12 -2
diff -u -p -r1.24 i386-efi.rmk
@@ -45,7 +45,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/help.c				\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/hexdump.c				\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/i386/efi/halt.c commands/i386/efi/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/loopback.c							\
 	fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c	\
@@ -76,7 +76,7 @@ grub_install_SOURCES = util/i386/efi/gru
 
 # Modules.
 pkgdata_MODULES = kernel.mod normal.mod _chain.mod chain.mod \
-	_linux.mod linux.mod cpuid.mod
+	_linux.mod linux.mod cpuid.mod halt.mod reboot.mod
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -140,4 +140,14 @@ cpuid_mod_SOURCES = commands/i386/cpuid.
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
 cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+halt_mod_SOURCES = commands/i386/efi/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+reboot_mod_SOURCES = commands/i386/efi/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk

Index: include/grub/efi/efi.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/efi.h,v retrieving revision 1.8

grub/efi/efi.h +2 -0
diff -u -p -r1.8 efi.h
@@ -54,6 +54,8 @@ char *EXPORT_FUNC(grub_efi_get_filename)
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);

Index: kern/efi/efi.c
===================================================================
RCS file: /sources/grub/grub2/kern/efi/efi.c,v
retrieving revision 1.9

efi/efi.c +16 -0
diff -u -p -r1.9 efi.c
@@ -162,6 +162,22 @@ grub_exit (void)
 					      0, 0);
 }
 
+void
+grub_reboot (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
+void
+grub_halt (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
 int
 grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
 {
#8 lore raw
Quoted 2 lines · Alexandre Boeglin

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Hi,

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Regards,
Alex

#9 lore raw
Quoted 9 lines · Alexandre Boeglin
Quoted 2 lines · Alexandre Boeglin

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Hi,

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Just to be very sure: did this happen?

--
Marco

#20 lore raw
In reply to Alexandre Boeglin
Quoted 20 lines · Alexandre Boeglin

Index: commands/i386/efi/halt.c
===================================================================
RCS file: commands/i386/efi/halt.c
diff -N commands/i386/efi/halt.c

[...]

i386/efi/halt.c new file +13 -0
+static grub_err_t
+grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+
+{
+  grub_halt ();
+  return 0;
+}
+
+
+
+GRUB_MOD_INIT(halt)

i386/efi/halt.c line 47

Quoted 10 lines
i386/efi/halt.c new file +10 -0
+{
+  (void)mod;			/* To stop warning. */
+  grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
+			 "halt", "Halt the computer", 0);
+}
+
+GRUB_MOD_FINI(halt)
+{
+  grub_unregister_command ("halt");
+}

commands/ieee1275/halt.c looks like the same thing to me. Perhaps it'd make more sense to move that to commands/halt.c and use it as the "generic" version of halt command?

i386/efi/reboot.c

Quoted 6 lines

Index: commands/i386/efi/reboot.c
===================================================================
RCS file: commands/i386/efi/reboot.c
diff -N commands/i386/efi/reboot.c

i386/efi/reboot.c new file +0 -0

Possibly the same applies here.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#10 lore raw
In reply to Marco Gerards
Quoted 7 lines · Marco Gerards
Quoted 5 lines · Alexandre Boeglin
Quoted 2 lines · Alexandre Boeglin

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Quoted 6 lines
Quoted 4 lines

Hi,

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Just to be very sure: did this happen?

I don't know about this particular question, but Okuji added him to CVS group. This should mean the paperwork is sorted out?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#11 lore raw
Quoted 10 lines · Robert Millan
Quoted 9 lines · Marco Gerards
Quoted 7 lines · Alexandre Boeglin
Quoted 2 lines · Alexandre Boeglin

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Hi,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Just to be very sure: did this happen?

I don't know about this particular question, but Okuji added him to CVS group. This should mean the paperwork is sorted out?

Yes.

--
Marco

#12 lore raw
In reply to Robert Millan
Quoted 11 lines · Robert Millan
Quoted 10 lines · Marco Gerards
Quoted 9 lines · Alexandre Boeglin

On Sun, 18 Nov 2007 19:14:03 +0100, Alexandre Boeglin <[email protected]>

Quoted 2 lines · wrote:

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Hi,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Just to be very sure: did this happen?

I don't know about this particular question, but Okuji added him to CVS group. This should mean the paperwork is sorted out?

His name is already in the copyright.list on fencepost. This means that it has been done (although I even didn't know that Marco had ask him to do so).

Okuji

#13 lore raw
Quoted 15 lines · Yoshinori K. Okuji
Quoted 14 lines · Robert Millan
Quoted 13 lines · Marco Gerards
Quoted 11 lines · Alexandre Boeglin

On Sun, 18 Nov 2007 19:14:03 +0100, Alexandre Boeglin <[email protected]>

Quoted 2 lines · wrote:

I also still have to clean the chainloader options patch, but here is the changelog for the others:

Hi,

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Just to be very sure: did this happen?

I don't know about this particular question, but Okuji added him to CVS group. This should mean the paperwork is sorted out?

His name is already in the copyright.list on fencepost. This means that it has been done (although I even didn't know that Marco had ask him to do so).

Hopefully I didn't forget to CC you when I mailed him? If so, it was not intentionally and I am sorry.

--
Marco

#14 lore raw
In reply to Marco Gerards
Quoted 5 lines · Marco Gerards
Quoted 2 lines · Alexandre Boeglin

As Marco finally received my copyright application papers, could someone have a look at these patches ?

Just to be very sure: did this happen?

Hi,

I'm sorry, I've been a bit busy recently. So, here's a recap of the four initial patches I posted:

- "--" handling is trivial, I think this can be commited.

- loader/efi/chainloader options support needs to be fixed.

- efi halt and reboot support is trivial too, but as Robert proposed halt.c and maybe reboot.c could be reused between different platforms.

- about prefix handling, more discussion is needed, I think.

I also have a "few" mails to catch up with...

Alex

#21 lore raw
In reply to Robert Millan
Quoted 3 lines · Robert Millan

commands/ieee1275/halt.c looks like the same thing to me. Perhaps it'd make more sense to move that to commands/halt.c and use it as the "generic" version of halt command?

Ok, is there any objection ?

#22 lore raw
Quoted 6 lines · Alexandre Boeglin
Quoted 3 lines · Robert Millan

commands/ieee1275/halt.c looks like the same thing to me. Perhaps it'd make more sense to move that to commands/halt.c and use it as the "generic" version of halt command?

Ok, is there any objection ?

Please post a patch first; it'd be preferred if someone (maybe me!) tests it on ieee1275 to make sure it didn't break anything.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#15 lore raw
In reply to Alexandre Boeglin
Quoted 7 lines · Alexandre Boeglin

Hi,

I'm sorry, I've been a bit busy recently. So, here's a recap of the four initial patches I posted:

- "--" handling is trivial, I think this can be commited.

Please can you add a follow-up in the relevant thread(s) ? I get easily confused in this gazillon of mails. Not to mention those who check the list less frequently...

Thanks

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#16 lore raw
Quoted 6 lines · Robert Millan
Quoted 1 line · Alexandre Boeglin

- "--" handling is trivial, I think this can be commited.

Please can you add a follow-up in the relevant thread(s) ? I get easily confused in this gazillon of mails. Not to mention those who check the list less frequently...

This was just a one line fix:

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7

arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +1 -1
diff -u -p -r1.7 arg.c
@@ -313,7 +313,7 @@ grub_arg_parse (grub_command_t cmd, int
          if (grub_strlen (arg) == 2)
            {
              for (curarg++; curarg < argc; curarg++)
-               if (add_arg (arg) != 0)
+               if (add_arg (argv[curarg]) != 0)
                  goto fail;
              break;
            }
#17 lore raw
Quoted 18 lines · Alexandre Boeglin
Quoted 6 lines · Robert Millan
Quoted 1 line · Alexandre Boeglin

- "--" handling is trivial, I think this can be commited.

Please can you add a follow-up in the relevant thread(s) ? I get easily confused in this gazillon of mails. Not to mention those who check the list less frequently...

This was just a one line fix:

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7
diff -u -p -r1.7 arg.c

arg.c 18 Nov 2007 15:12:05 -0000 grub_arg_parse (grub_command_t cmd, int · line 319

Quoted 8 lines
arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +1 -1
@@ -313,7 +313,7 @@ grub_arg_parse (grub_command_t cmd, int
          if (grub_strlen (arg) == 2)
            {
              for (curarg++; curarg < argc; curarg++)
-               if (add_arg (arg) != 0)
+               if (add_arg (argv[curarg]) != 0)
                  goto fail;
              break;
            }

No idea what this is about. Is there a thread that explains it? :-)

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#18 lore raw
Quoted 13 lines · Robert Millan
Quoted 12 lines · Alexandre Boeglin

This was just a one line fix:

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7
diff -u -p -r1.7 arg.c

arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +0 -0
@@ -313,7 +313,7 @@ grub_arg_parse (grub_command_t cmd, int
          if (grub_strlen (arg) == 2)
            {
Quoted 8 lines

arg.c 18 Nov 2007 15:12:05 -0000 grub_arg_parse (grub_command_t cmd, int · line 319

Quoted 6 lines
arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +1 -1
              for (curarg++; curarg < argc; curarg++)
-               if (add_arg (arg) != 0)
+               if (add_arg (argv[curarg]) != 0)
                  goto fail;
              break;
            }

No idea what this is about. Is there a thread that explains it? :-)

Sorry, I should have been more verbose ... This is discussed in the beginning of this thread. Basically, when you type in the grub console "echo -- a b", it will echo "-- --" instead of "a b"

Alex

#19 lore raw
Quoted 23 lines · Alexandre Boeglin
Quoted 13 lines · Robert Millan
Quoted 12 lines · Alexandre Boeglin

This was just a one line fix:

Index: normal/arg.c
===================================================================
RCS file: /sources/grub/grub2/normal/arg.c,v
retrieving revision 1.7
diff -u -p -r1.7 arg.c

arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +0 -0
@@ -313,7 +313,7 @@ grub_arg_parse (grub_command_t cmd, int
          if (grub_strlen (arg) == 2)
            {
Quoted 8 lines

arg.c 18 Nov 2007 15:12:05 -0000 grub_arg_parse (grub_command_t cmd, int · line 319

Quoted 6 lines
arg.c 18 Nov 2007 15:12:05 -0000 renamed from arg.c 21 Jul 2007 23:32:28 -0000 1.7 +1 -1
              for (curarg++; curarg < argc; curarg++)
-               if (add_arg (arg) != 0)
+               if (add_arg (argv[curarg]) != 0)
                  goto fail;
              break;
            }

No idea what this is about. Is there a thread that explains it? :-)

Quoted 3 lines

Sorry, I should have been more verbose ... This is discussed in the beginning of this thread. Basically, when you type in the grub console "echo -- a b", it will echo "-- --" instead of "a b"

Looks fine to me. Since nobody seems to object, I suggest you check that in.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#23 lore raw

Generic halt and reboot commands (was: Re: grub2 efi patches)

In reply to Robert Millan
Quoted 10 lines · Robert Millan
Quoted 6 lines · Alexandre Boeglin
Quoted 3 lines · Robert Millan

commands/ieee1275/halt.c looks like the same thing to me. Perhaps it'd make more sense to move that to commands/halt.c and use it as the "generic" version of halt command?

Ok, is there any objection ?

Please post a patch first; it'd be preferred if someone (maybe me!) tests it on ieee1275 to make sure it didn't break anything.

Here is the Changelog, patch is attached.

* conf/i386-efi.rmk (grub_emu_SOURCES): Replace commands/i386/pc/halt.c and reboot.c by commands/halt.c and reboot.c. (grub_install_SOURCES): Add halt.mod and reboot.mod. (halt_mod_SOURCES): New variable.
(halt_mod_CFLAGS): Likewise.
(halt_mod_LDFLAGS): Likewise.
(reboot_mod_SOURCES): Likewise.
(reboot_mod_CFLAGS): Likewise.
(reboot_mod_LDFLAGS): Likewise.

* conf/i386-ieee1275.rmk (grub_emu_SOURCES): Replace commands/ieee1275/halt.c and reboot.c by commands/halt.c and reboot.c. (halt_mod_SOURCES): Likewise.
(reboot_mod_SOURCES): Likewise.

* conf/i386-pc.rmk (grub_emu_SOURCES): Replace commands/i386/pc/reboot.c by commands/reboot.c.
(reboot_mod_SOURCES): Likewise.

* commands/i386/pc/reboot.c: merge this file ...

* commands/ieee1275/reboot.c: ... and this file ...

* commands/reboot.c: ... to this file.
Add some precompiler directive to include the correct header for each machine.

* commands/ieee1275/halt.c: move this file ...

* commands/halt.c: ... to here.
Add some precompiler directive to include the correct header for each machine.

* include/grub/efi/efi.h (grub_reboot): New function declaration. (grub_halt): Likewise.

* kern/efi/efi.c (grub_reboot): New function.
(grub_halt): Likewise.

conf/i386-efi.rmk +12 -2
diff -ruNap -x CVS -x '*.mk' grub2_commit/conf/i386-efi.rmk grub2_clean/conf/i386-efi.rmk
@@ -37,7 +37,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/help.c				\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/hexdump.c				\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/halt.c commands/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/loopback.c							\
 	\
@@ -72,7 +72,7 @@ grub_install_SOURCES = util/i386/efi/gru
 
 # Modules.
 pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod \
-	_linux.mod linux.mod cpuid.mod
+	_linux.mod linux.mod cpuid.mod halt.mod reboot.mod
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -135,4 +135,14 @@ cpuid_mod_SOURCES = commands/i386/cpuid.
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
 cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+halt_mod_SOURCES = commands/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+reboot_mod_SOURCES = commands/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +3 -3
diff -ruNap -x CVS -x '*.mk' grub2_commit/conf/i386-ieee1275.rmk grub2_clean/conf/i386-ieee1275.rmk
@@ -62,7 +62,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
-	commands/ieee1275/halt.c commands/ieee1275/reboot.c		\
+	commands/halt.c commands/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c	disk/raid.c disk/lvm.c		\
 	\
@@ -122,12 +122,12 @@ suspend_mod_CFLAGS = $(COMMON_CFLAGS)
 suspend_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For reboot.mod
-reboot_mod_SOURCES = commands/ieee1275/reboot.c
+reboot_mod_SOURCES = commands/reboot.c
 reboot_mod_CFLAGS = $(COMMON_CFLAGS)
 reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For halt.mod
-halt_mod_SOURCES = commands/ieee1275/halt.c
+halt_mod_SOURCES = commands/halt.c
 halt_mod_CFLAGS = $(COMMON_CFLAGS)
 halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
conf/i386-pc.rmk +2 -2
diff -ruNap -x CVS -x '*.mk' grub2_commit/conf/i386-pc.rmk grub2_clean/conf/i386-pc.rmk
@@ -103,7 +103,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/i386/pc/halt.c commands/reboot.c		\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c	disk/raid.c disk/lvm.c		\
 	fs/fshelp.c 	\
@@ -185,7 +185,7 @@ normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
 normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For reboot.mod.
-reboot_mod_SOURCES = commands/i386/pc/reboot.c
+reboot_mod_SOURCES = commands/reboot.c
 reboot_mod_CFLAGS = $(COMMON_CFLAGS)
 reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
commands/halt.c +51 -0

51 lines not on this page · raw message

commands/i386/pc/reboot.c +0 -47

47 lines not on this page · raw message

commands/ieee1275/halt.c +0 -46

46 lines not on this page · raw message

commands/ieee1275/reboot.c +0 -45

45 lines not on this page · raw message

commands/reboot.c +53 -0

53 lines not on this page · raw message

kern/efi/efi.c +16 -0
diff -ruNap -x CVS grub2_commit/kern/efi/efi.c grub2_clean/kern/efi/efi.c
@@ -162,6 +162,22 @@ grub_exit (void)
 					      0, 0);
 }
 
+void
+grub_reboot (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
+void
+grub_halt (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
 int
 grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
 {
include/grub/efi/efi.h +2 -0
diff -ruNap -x CVS grub2_commit/include/grub/efi/efi.h grub2_clean/include/grub/efi/efi.h
@@ -54,6 +54,8 @@ char *EXPORT_FUNC(grub_efi_get_filename)
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);
#24 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 4 lines · Alexandre Boeglin

* commands/halt.c: ... to here.
Add some precompiler directive to include the correct header for each machine.

Can we simplify this? Since grub_halt() is put in kernel anyway, why not always export it from kernel.h ?

Also, could you provide the diff after you have issued
"mv commands/ieee1275/halt.c commands/halt.c" or so? That will make it much easier to read than comparing files by hand.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#25 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 8 lines · Robert Millan
Quoted 4 lines · Alexandre Boeglin

* commands/halt.c: ... to here.
Add some precompiler directive to include the correct header for each machine.

Can we simplify this? Since grub_halt() is put in kernel anyway, why not always export it from kernel.h ?

Well, efi, for instance, is not machine dependant, and so the header is not located in include/grub/i386/efi but in include/grub/efi

Quoted 3 lines

Also, could you provide the diff after you have issued
"mv commands/ieee1275/halt.c commands/halt.c" or so? That will make it much easier to read than comparing files by hand.

Ok, here are the diffs.

================================================================================

commands/halt.c 2008-02-10 17:07:47.847689750 +0100 renamed from commands/ieee1275/halt.c 2007-07-22 01:32:19.000000000 +0200 +7 -2
@@ -19,8 +19,13 @@
 
 #include <grub/normal.h>
 #include <grub/dl.h>
-#include <grub/misc.h>
+#include <grub/machine/machine.h>
+
+#ifdef GRUB_MACHINE_IEEE1275
 #include <grub/machine/kernel.h>
+#elif defined GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#endif
 
 static grub_err_t
 grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
@@ -32,7 +37,7 @@ grub_cmd_halt (struct grub_arg_list *sta
 }
 
 
 
-GRUB_MOD_INIT(ieee1275_halt)
+GRUB_MOD_INIT(halt)
 {
   (void)mod;                   /* To stop warning. */

grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
@@ -40,7 +45,7 @@ GRUB_MOD_INIT(ieee1275_halt)

                         " work on all firmware.", 0);

}

-GRUB_MOD_FINI(ieee1275_halt)
+GRUB_MOD_FINI(halt)
{
grub_unregister_command ("halt");
}
================================================================================

commands/reboot.c 2008-02-10 17:04:14.486355500 +0100 renamed from commands/ieee1275/reboot.c 2007-07-22 01:32:20.000000000 +0200 +11 -3
@@ -19,8 +19,16 @@
 
 #include <grub/normal.h>
 #include <grub/dl.h>
-#include <grub/misc.h>
+#include <grub/machine/machine.h>
+
+#ifdef GRUB_MACHINE_IEEE1275
 #include <grub/machine/kernel.h>
+#elif defined GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#elif defined GRUB_MACHINE_PCBIOS
+#include <grub/machine/init.h>
+#endif
+
 
 static grub_err_t
 grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)),
@@ -32,14 +40,14 @@ grub_cmd_reboot (struct grub_arg_list *s
 }
 
 
 
-GRUB_MOD_INIT(ieee1275_reboot)
+GRUB_MOD_INIT(reboot)
 {
   (void)mod;                   /* To stop warning. */
   grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH,
                         "reboot", "Reboot the computer", 0);
 }
 
-GRUB_MOD_FINI(ieee1275_reboot)
+GRUB_MOD_FINI(reboot)
 {
   grub_unregister_command ("reboot");

}
================================================================================

commands/reboot.c 2008-02-10 17:04:14.486355500 +0100 renamed from commands/i386/pc/reboot.c 2007-07-22 01:32:19.000000000 +0200 +9 -3
@@ -19,20 +19,26 @@
 
 #include <grub/normal.h>
 #include <grub/dl.h>
-#include <grub/arg.h>
+#include <grub/machine/machine.h>
+
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/machine/kernel.h>
+#elif defined GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#elif defined GRUB_MACHINE_PCBIOS
 #include <grub/machine/init.h>
+#endif
+
 
 static grub_err_t
 grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)),
                 int argc __attribute__ ((unused)),
                 char **args __attribute__ ((unused)))
-
 {
   grub_reboot ();
   return 0;
 }
 
-
 
 
 GRUB_MOD_INIT(reboot)

{
================================================================================

#26 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

commands/halt.c 2008-02-10 17:07:47.847689750 +0100 line 28

Quoted 5 lines · Alexandre Boeglin
commands/halt.c 2008-02-10 17:07:47.847689750 +0100 renamed from commands/ieee1275/halt.c 2007-07-22 01:32:19.000000000 +0200 +4 -0
+#ifdef GRUB_MACHINE_IEEE1275
 #include <grub/machine/kernel.h>
+#elif defined GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#endif

For consistency with similar code elsewhere in GRUB, I think it's better if you made this:

#if defined(foo)
#elif defined(bar)
#endif

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#27 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 6 lines · Robert Millan

For consistency with similar code elsewhere in GRUB, I think it's better if you made this:

#if defined(foo)
#elif defined(bar)
#endif

No whitespace before the opening bracket in this case ?

By the way, this case is a good example of when it's 10 times easier to produce a patch with SVN than with CVS ;)

Alex

#28 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 9 lines · Alexandre Boeglin
Quoted 6 lines · Robert Millan

For consistency with similar code elsewhere in GRUB, I think it's better if you made this:

#if defined(foo)
#elif defined(bar)
#endif

No whitespace before the opening bracket in this case ?

No. See how other parts of GRUB do it.

Quoted 2 lines

By the way, this case is a good example of when it's 10 times easier to produce a patch with SVN than with CVS ;)

I know...

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#29 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 1 line · Robert Millan

No. See how other parts of GRUB do it.

Ok, here's the patch. I also added 2008 to the copyright statement of modified files.

Alex

commands/halt.c +51 -0
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/commands/halt.c grub2_clean/commands/halt.c
@@ -0,0 +1,51 @@
+/* halt.c - command to halt the computer.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005,2007,2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/machine/machine.h>
+
+#if defined(GRUB_MACHINE_IEEE1275)
+#include <grub/machine/kernel.h>
+#elif defined(GRUB_MACHINE_EFI)
+#include <grub/efi/efi.h>
+#endif
+
+static grub_err_t
+grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+{
+  grub_halt ();
+  return 0;
+}
+
+
+GRUB_MOD_INIT(halt)
+{
+  (void)mod;			/* To stop warning. */
+  grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
+			 "halt", "halts the computer.  This command does not"
+			 " work on all firmware.", 0);
+}
+
+GRUB_MOD_FINI(halt)
+{
+  grub_unregister_command ("halt");
+}
commands/i386/pc/reboot.c +0 -47

47 lines not on this page · raw message

commands/ieee1275/halt.c +0 -46

46 lines not on this page · raw message

commands/ieee1275/reboot.c +0 -45

45 lines not on this page · raw message

commands/reboot.c +53 -0

53 lines not on this page · raw message

conf/i386-efi.rmk +12 -2
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/conf/i386-efi.rmk grub2_clean/conf/i386-efi.rmk
@@ -37,7 +37,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/help.c				\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/hexdump.c				\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/halt.c commands/reboot.c				\
 	commands/i386/cpuid.c						\
 	disk/loopback.c							\
 	\
@@ -75,7 +75,7 @@ grub_install_SOURCES = util/i386/efi/gru
 
 # Modules.
 pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod \
-	_linux.mod linux.mod cpuid.mod
+	_linux.mod linux.mod cpuid.mod halt.mod reboot.mod
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -138,4 +138,14 @@ cpuid_mod_SOURCES = commands/i386/cpuid.
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)
 cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For halt.mod.
+halt_mod_SOURCES = commands/halt.c
+halt_mod_CFLAGS = $(COMMON_CFLAGS)
+halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For reboot.mod.
+reboot_mod_SOURCES = commands/reboot.c
+reboot_mod_CFLAGS = $(COMMON_CFLAGS)
+reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +3 -3
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/conf/i386-ieee1275.rmk grub2_clean/conf/i386-ieee1275.rmk
@@ -62,7 +62,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
-	commands/ieee1275/halt.c commands/ieee1275/reboot.c		\
+	commands/halt.c commands/reboot.c				\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c					\
 	\
@@ -125,12 +125,12 @@ suspend_mod_CFLAGS = $(COMMON_CFLAGS)
 suspend_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For reboot.mod
-reboot_mod_SOURCES = commands/ieee1275/reboot.c
+reboot_mod_SOURCES = commands/reboot.c
 reboot_mod_CFLAGS = $(COMMON_CFLAGS)
 reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For halt.mod
-halt_mod_SOURCES = commands/ieee1275/halt.c
+halt_mod_SOURCES = commands/halt.c
 halt_mod_CFLAGS = $(COMMON_CFLAGS)
 halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
conf/i386-pc.rmk +2 -2
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/conf/i386-pc.rmk grub2_clean/conf/i386-pc.rmk
@@ -106,7 +106,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	commands/configfile.c commands/echo.c commands/help.c		\
 	commands/terminal.c commands/ls.c commands/test.c 		\
 	commands/search.c commands/blocklist.c commands/hexdump.c	\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/i386/pc/halt.c commands/reboot.c			\
 	commands/i386/cpuid.c						\
 	disk/host.c disk/loopback.c					\
 	fs/fshelp.c 	\
@@ -191,7 +191,7 @@ normal_mod_ASFLAGS = $(COMMON_ASFLAGS)
 normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For reboot.mod.
-reboot_mod_SOURCES = commands/i386/pc/reboot.c
+reboot_mod_SOURCES = commands/reboot.c
 reboot_mod_CFLAGS = $(COMMON_CFLAGS)
 reboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
include/grub/efi/efi.h +3 -1
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/include/grub/efi/efi.h grub2_clean/include/grub/efi/efi.h
@@ -1,7 +1,7 @@
 /* efi.h - declare variables and functions for EFI support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -54,6 +54,8 @@ char *EXPORT_FUNC(grub_efi_get_filename)
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 void grub_efi_mm_init (void);
 void grub_efi_mm_fini (void);
kern/efi/efi.c +17 -1
diff -ruNap -x CVS -x '*.lst' -x '*.mk' -x '.*' -x '*.d' -x '*.o' grub2_commit/kern/efi/efi.c grub2_clean/kern/efi/efi.c
@@ -1,7 +1,7 @@
 /* efi.c - generic EFI support */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -162,6 +162,22 @@ grub_exit (void)
 					      0, 0);
 }
 
+void
+grub_reboot (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
+void
+grub_halt (void)
+{
+  grub_efi_fini ();
+  grub_efi_system_table->runtime_services->
+    reset_system (GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
+}
+
 int
 grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
 {
#30 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 5 lines · Alexandre Boeglin
Quoted 1 line · Robert Millan

No. See how other parts of GRUB do it.

Ok, here's the patch. I also added 2008 to the copyright statement of modified files.

You forgot the changelog entry ;-)

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#31 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 8 lines · Robert Millan
Quoted 5 lines · Alexandre Boeglin
Quoted 1 line · Robert Millan

No. See how other parts of GRUB do it.

Ok, here's the patch. I also added 2008 to the copyright statement of modified files.

You forgot the changelog entry ;-)

Yes, but it's the same as the one I provided a few emails back, I think.

Alex

#32 lore raw

Re: Generic halt and reboot commands (was: Re: grub2 efi patches)

Quoted 11 lines · Alexandre Boeglin
Quoted 8 lines · Robert Millan
Quoted 5 lines · Alexandre Boeglin
Quoted 1 line · Robert Millan

No. See how other parts of GRUB do it.

Ok, here's the patch. I also added 2008 to the copyright statement of modified files.

You forgot the changelog entry ;-)

Yes, but it's the same as the one I provided a few emails back, I think.

Ah, ok. You forgot to tab-indent it, and also added two extra spaces in "non-*" lines.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)