[2217] 2009-05-16 Bean <[email protected]>

Bean <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 2217
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2217
Author:   bean
Date:     2009-05-16 12:12:12 +0000 (Sat, 16 May 2009)
Log Message:
-----------
2009-05-16  Bean  <[email protected]>

	* include/grub/kernel.h (grub_module_header_types): Add type
	OBJ_TYPE_CONFIG.

	* kern/main.c (grub_load_config): New function.
	(grub_main): Call grub_load_config to read boot config.

	* grub-mkimage (generate_image): New parameter config_path.
	(options): New option --config.
	(main): Parse --config option, and pass it to generate_image.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/include/grub/kernel.h
    trunk/grub2/kern/main.c
    trunk/grub2/util/i386/pc/grub-mkimage.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2009-05-15 14:47:44 UTC (rev 2216)
+++ trunk/grub2/ChangeLog	2009-05-16 12:12:12 UTC (rev 2217)
@@ -1,3 +1,15 @@
+2009-05-16  Bean  <[email protected]>
+
+	* include/grub/kernel.h (grub_module_header_types): Add type
+	OBJ_TYPE_CONFIG.
+
+	* kern/main.c (grub_load_config): New function.
+	(grub_main): Call grub_load_config to read boot config.
+
+	* grub-mkimage (generate_image): New parameter config_path.
+	(options): New option --config.
+	(main): Parse --config option, and pass it to generate_image.
+
 2009-05-14  Christian Franke  <[email protected]>
 
 	* commands/i386/pc/drivemap_int13h.S: Add missing EXT_C for symbols.

Modified: trunk/grub2/include/grub/kernel.h
===================================================================
--- trunk/grub2/include/grub/kernel.h	2009-05-15 14:47:44 UTC (rev 2216)
+++ trunk/grub2/include/grub/kernel.h	2009-05-16 12:12:12 UTC (rev 2217)
@@ -31,6 +31,7 @@
   {
     OBJ_TYPE_ELF,
     OBJ_TYPE_MEMDISK,
+    OBJ_TYPE_CONFIG
   }  grub_module_header_types;
 
   /* The size of object (including this header).  */

Modified: trunk/grub2/kern/main.c
===================================================================
--- trunk/grub2/kern/main.c	2009-05-15 14:47:44 UTC (rev 2216)
+++ trunk/grub2/kern/main.c	2009-05-16 12:12:12 UTC (rev 2217)
@@ -74,6 +74,24 @@
   grub_module_iterate (hook);
 }
 
+static void
+grub_load_config (void)
+{
+  auto int hook (struct grub_module_header *);
+  int hook (struct grub_module_header *header)
+    {
+      /* Not an ELF module, skip.  */
+      if (header->type != OBJ_TYPE_CONFIG)
+	return 0;
+
+      grub_parser_execute ((char *) header +
+			   sizeof (struct grub_module_header));
+      return 1;
+    }
+
+  grub_module_iterate (hook);
+}
+
 /* Write hook for the environment variables of root. Remove surrounding
    parentheses, if any.  */
 static char *
@@ -153,6 +171,7 @@
   grub_register_rescue_parser ();
   grub_register_rescue_reader ();
   
+  grub_load_config ();
   grub_load_normal_mode ();
   grub_reader_loop (0);
 }

Modified: trunk/grub2/util/i386/pc/grub-mkimage.c
===================================================================
--- trunk/grub2/util/i386/pc/grub-mkimage.c	2009-05-15 14:47:44 UTC (rev 2216)
+++ trunk/grub2/util/i386/pc/grub-mkimage.c	2009-05-16 12:12:12 UTC (rev 2217)
@@ -129,11 +129,13 @@
 #endif
 
 static void
-generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *memdisk_path)
+generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
+		char *memdisk_path, char *config_path)
 {
   grub_addr_t module_addr = 0;
   char *kernel_img, *boot_img, *core_img;
-  size_t kernel_size, boot_size, total_module_size, core_size, memdisk_size = 0;
+  size_t kernel_size, boot_size, total_module_size, core_size;
+  size_t memdisk_size = 0, config_size = 0;
   char *kernel_path, *boot_path;
   unsigned num;
   size_t offset;
@@ -154,6 +156,13 @@
       total_module_size += memdisk_size + sizeof (struct grub_module_header);
     }
 
+  if (config_path)
+    {
+      config_size = grub_util_get_image_size (config_path) + 1;
+      grub_util_info ("the size of config file is 0x%x", config_size);
+      total_module_size += config_size + sizeof (struct grub_module_header);
+    }
+
   for (p = path_list; p; p = p->next)
     total_module_size += (grub_util_get_image_size (p->name)
 			  + sizeof (struct grub_module_header));
@@ -203,6 +212,20 @@
       offset += memdisk_size;
     }
 
+  if (config_path)
+    {
+      struct grub_module_header *header;
+
+      header = (struct grub_module_header *) (kernel_img + offset);
+      header->type = grub_cpu_to_le32 (OBJ_TYPE_CONFIG);
+      header->size = grub_cpu_to_le32 (config_size + sizeof (*header));
+      offset += sizeof (*header);
+
+      grub_util_load_image (config_path, kernel_img + offset);
+      offset += config_size;
+      *(kernel_img + offset - 1) = 0;
+    }
+
   compress_kernel (kernel_img, kernel_size + total_module_size,
 		   &core_img, &core_size);
 
@@ -276,6 +299,7 @@
     {"directory", required_argument, 0, 'd'},
     {"prefix", required_argument, 0, 'p'},
     {"memdisk", required_argument, 0, 'm'},
+    {"config", required_argument, 0, 'c'},
     {"output", required_argument, 0, 'o'},
     {"help", no_argument, 0, 'h'},
     {"version", no_argument, 0, 'V'},
@@ -297,6 +321,7 @@
   -d, --directory=DIR     use images and modules under DIR [default=%s]\n\
   -p, --prefix=DIR        set grub_prefix directory [default=%s]\n\
   -m, --memdisk=FILE      embed FILE as a memdisk image\n\
+  -c, --config=FILE       embed FILE as boot config\n\
   -o, --output=FILE       output a generated image to FILE [default=stdout]\n\
   -h, --help              display this message and exit\n\
   -V, --version           print version information and exit\n\
@@ -315,13 +340,14 @@
   char *dir = NULL;
   char *prefix = NULL;
   char *memdisk = NULL;
+  char *config = NULL;
   FILE *fp = stdout;
 
   progname = "grub-mkimage";
   
   while (1)
     {
-      int c = getopt_long (argc, argv, "d:p:m:o:hVv", options, 0);
+      int c = getopt_long (argc, argv, "d:p:m:c:o:hVv", options, 0);
 
       if (c == -1)
 	break;
@@ -354,6 +380,13 @@
 	    prefix = xstrdup ("(memdisk)/boot/grub");
 	    break;
 
+	  case 'c':
+	    if (config)
+	      free (config);
+
+	    config = xstrdup (optarg);
+	    break;
+
 	  case 'h':
 	    usage (0);
 	    break;
@@ -386,7 +419,8 @@
 	grub_util_error ("cannot open %s", output);
     }
 
-  generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind, memdisk);
+  generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp,
+		  argv + optind, memdisk, config);
 
   fclose (fp);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.