All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Split 3: boot script support
@ 2009-04-11 16:50 Bean
  2009-04-17 11:22 ` phcoder
  0 siblings, 1 reply; 4+ messages in thread
From: Bean @ 2009-04-11 16:50 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

Hi,

This patch allows grub-mkimage to embed a boot script in core.img,
which would be executed by the rescue parser before switching to
normal mode.

-- 
Bean

[-- Attachment #2: s3.diff --]
[-- Type: application/octet-stream, Size: 5185 bytes --]

diff --git a/include/grub/kernel.h b/include/grub/kernel.h
index adaee58..6b17ea8 100644
--- a/include/grub/kernel.h
+++ b/include/grub/kernel.h
@@ -31,6 +31,7 @@ struct grub_module_header
   {
     OBJ_TYPE_ELF,
     OBJ_TYPE_MEMDISK,
+    OBJ_TYPE_CONFIG
   }  grub_module_header_types;
 
   /* The size of object (including this header).  */
diff --git a/kern/main.c b/kern/main.c
index 494f176..9215d55 100644
--- a/kern/main.c
+++ b/kern/main.c
@@ -74,6 +74,24 @@ grub_load_modules (void)
   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_main (void)
   grub_register_rescue_parser ();
   grub_register_rescue_reader ();
 
+  grub_load_config ();
   grub_load_normal_mode ();
   grub_reader_loop (0);
 }
diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c
index 4625b6d..1bdddac 100644
--- a/util/i386/pc/grub-mkimage.c
+++ b/util/i386/pc/grub-mkimage.c
@@ -129,11 +129,13 @@ compress_kernel (char *kernel_img, size_t kernel_size,
 #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 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *me
       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 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], char *me
       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 @@ static struct option options[] =
     {"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 @@ Make a bootable image of GRUB.\n\
   -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 @@ main (int argc, char *argv[])
   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 @@ main (int argc, char *argv[])
 	    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 @@ main (int argc, char *argv[])
 	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);
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Split 3: boot script support
  2009-04-11 16:50 [PATCH] Split 3: boot script support Bean
@ 2009-04-17 11:22 ` phcoder
  2009-05-03  4:35   ` Bean
  0 siblings, 1 reply; 4+ messages in thread
From: phcoder @ 2009-04-17 11:22 UTC (permalink / raw)
  To: The development of GRUB 2

Hello, I find this useful. It permits e.g. to have root by uuid.

 >/* Not an ELF module, skip.  */
This comment is out of sync

Bean wrote:
> Hi,
> 
> This patch allows grub-mkimage to embed a boot script in core.img,
> which would be executed by the rescue parser before switching to
> normal mode.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Split 3: boot script support
  2009-04-17 11:22 ` phcoder
@ 2009-05-03  4:35   ` Bean
  2009-05-16 12:13     ` Bean
  0 siblings, 1 reply; 4+ messages in thread
From: Bean @ 2009-05-03  4:35 UTC (permalink / raw)
  To: The development of GRUB 2

Hi,

Since the script split patch has been committed, this one should be
quite trivial. I'd commit it in a few days if there is no objection.

On Fri, Apr 17, 2009 at 7:22 PM, phcoder <phcoder@gmail.com> wrote:
> Hello, I find this useful. It permits e.g. to have root by uuid.
>
>>/* Not an ELF module, skip.  */
> This comment is out of sync
>
> Bean wrote:
>>
>> Hi,
>>
>> This patch allows grub-mkimage to embed a boot script in core.img,
>> which would be executed by the rescue parser before switching to
>> normal mode.
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
> --
>
> Regards
> Vladimir 'phcoder' Serbinenko
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Bean



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Split 3: boot script support
  2009-05-03  4:35   ` Bean
@ 2009-05-16 12:13     ` Bean
  0 siblings, 0 replies; 4+ messages in thread
From: Bean @ 2009-05-16 12:13 UTC (permalink / raw)
  To: The development of GRUB 2

Hi,

Committed.

On Sun, May 3, 2009 at 12:35 PM, Bean <bean123ch@gmail.com> wrote:
> Hi,
>
> Since the script split patch has been committed, this one should be
> quite trivial. I'd commit it in a few days if there is no objection.
>
> On Fri, Apr 17, 2009 at 7:22 PM, phcoder <phcoder@gmail.com> wrote:
>> Hello, I find this useful. It permits e.g. to have root by uuid.
>>
>>>/* Not an ELF module, skip.  */
>> This comment is out of sync
>>
>> Bean wrote:
>>>
>>> Hi,
>>>
>>> This patch allows grub-mkimage to embed a boot script in core.img,
>>> which would be executed by the rescue parser before switching to
>>> normal mode.
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>> --
>>
>> Regards
>> Vladimir 'phcoder' Serbinenko
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>
>
>
> --
> Bean
>



-- 
Bean



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-16 12:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-11 16:50 [PATCH] Split 3: boot script support Bean
2009-04-17 11:22 ` phcoder
2009-05-03  4:35   ` Bean
2009-05-16 12:13     ` Bean

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.