2009-05-16 Bean <bean123ch@gmail.com>
* 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.
This commit is contained in:
parent
5cb5c9c210
commit
5e898c9d71
4 changed files with 70 additions and 4 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2009-05-16 Bean <bean123ch@gmail.com>
|
||||||
|
|
||||||
|
* 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 <franke@computer.org>
|
2009-05-14 Christian Franke <franke@computer.org>
|
||||||
|
|
||||||
* commands/i386/pc/drivemap_int13h.S: Add missing EXT_C for symbols.
|
* commands/i386/pc/drivemap_int13h.S: Add missing EXT_C for symbols.
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct grub_module_header
|
||||||
{
|
{
|
||||||
OBJ_TYPE_ELF,
|
OBJ_TYPE_ELF,
|
||||||
OBJ_TYPE_MEMDISK,
|
OBJ_TYPE_MEMDISK,
|
||||||
|
OBJ_TYPE_CONFIG
|
||||||
} grub_module_header_types;
|
} grub_module_header_types;
|
||||||
|
|
||||||
/* The size of object (including this header). */
|
/* The size of object (including this header). */
|
||||||
|
|
19
kern/main.c
19
kern/main.c
|
@ -74,6 +74,24 @@ grub_load_modules (void)
|
||||||
grub_module_iterate (hook);
|
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
|
/* Write hook for the environment variables of root. Remove surrounding
|
||||||
parentheses, if any. */
|
parentheses, if any. */
|
||||||
static char *
|
static char *
|
||||||
|
@ -153,6 +171,7 @@ grub_main (void)
|
||||||
grub_register_rescue_parser ();
|
grub_register_rescue_parser ();
|
||||||
grub_register_rescue_reader ();
|
grub_register_rescue_reader ();
|
||||||
|
|
||||||
|
grub_load_config ();
|
||||||
grub_load_normal_mode ();
|
grub_load_normal_mode ();
|
||||||
grub_reader_loop (0);
|
grub_reader_loop (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,11 +129,13 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
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;
|
grub_addr_t module_addr = 0;
|
||||||
char *kernel_img, *boot_img, *core_img;
|
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;
|
char *kernel_path, *boot_path;
|
||||||
unsigned num;
|
unsigned num;
|
||||||
size_t offset;
|
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);
|
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)
|
for (p = path_list; p; p = p->next)
|
||||||
total_module_size += (grub_util_get_image_size (p->name)
|
total_module_size += (grub_util_get_image_size (p->name)
|
||||||
+ sizeof (struct grub_module_header));
|
+ 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;
|
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,
|
compress_kernel (kernel_img, kernel_size + total_module_size,
|
||||||
&core_img, &core_size);
|
&core_img, &core_size);
|
||||||
|
|
||||||
|
@ -276,6 +299,7 @@ static struct option options[] =
|
||||||
{"directory", required_argument, 0, 'd'},
|
{"directory", required_argument, 0, 'd'},
|
||||||
{"prefix", required_argument, 0, 'p'},
|
{"prefix", required_argument, 0, 'p'},
|
||||||
{"memdisk", required_argument, 0, 'm'},
|
{"memdisk", required_argument, 0, 'm'},
|
||||||
|
{"config", required_argument, 0, 'c'},
|
||||||
{"output", required_argument, 0, 'o'},
|
{"output", required_argument, 0, 'o'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"version", no_argument, 0, 'V'},
|
{"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\
|
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
|
||||||
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
|
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
|
||||||
-m, --memdisk=FILE embed FILE as a memdisk image\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\
|
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
|
||||||
-h, --help display this message and exit\n\
|
-h, --help display this message and exit\n\
|
||||||
-V, --version print version information and exit\n\
|
-V, --version print version information and exit\n\
|
||||||
|
@ -315,13 +340,14 @@ main (int argc, char *argv[])
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
char *prefix = NULL;
|
char *prefix = NULL;
|
||||||
char *memdisk = NULL;
|
char *memdisk = NULL;
|
||||||
|
char *config = NULL;
|
||||||
FILE *fp = stdout;
|
FILE *fp = stdout;
|
||||||
|
|
||||||
progname = "grub-mkimage";
|
progname = "grub-mkimage";
|
||||||
|
|
||||||
while (1)
|
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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -354,6 +380,13 @@ main (int argc, char *argv[])
|
||||||
prefix = xstrdup ("(memdisk)/boot/grub");
|
prefix = xstrdup ("(memdisk)/boot/grub");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
if (config)
|
||||||
|
free (config);
|
||||||
|
|
||||||
|
config = xstrdup (optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
usage (0);
|
usage (0);
|
||||||
break;
|
break;
|
||||||
|
@ -386,7 +419,8 @@ main (int argc, char *argv[])
|
||||||
grub_util_error ("cannot open %s", output);
|
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);
|
fclose (fp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue