mkimage fix
This commit is contained in:
parent
7d4cfd00ee
commit
65e64ea4b1
1 changed files with 37 additions and 5 deletions
|
@ -97,7 +97,7 @@ load_note (Elf32_Phdr *phdr, FILE *out)
|
||||||
|
|
||||||
void
|
void
|
||||||
load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
||||||
char *mods[], FILE *out, char *memdisk_path)
|
char *mods[], FILE *out, char *memdisk_path, char *config_path)
|
||||||
{
|
{
|
||||||
char *module_img;
|
char *module_img;
|
||||||
struct grub_util_path_list *path_list;
|
struct grub_util_path_list *path_list;
|
||||||
|
@ -106,6 +106,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
||||||
size_t offset;
|
size_t offset;
|
||||||
size_t total_module_size;
|
size_t total_module_size;
|
||||||
size_t memdisk_size = 0;
|
size_t memdisk_size = 0;
|
||||||
|
size_t config_size = 0;
|
||||||
|
|
||||||
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
||||||
|
|
||||||
|
@ -119,6 +120,13 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
||||||
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 = ALIGN_UP(grub_util_get_image_size (config_path), 512);
|
||||||
|
grub_util_info ("the size of memory disk 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)
|
||||||
|
@ -165,6 +173,19 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
||||||
offset += memdisk_size;
|
offset += memdisk_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config_path)
|
||||||
|
{
|
||||||
|
struct grub_module_header *header;
|
||||||
|
|
||||||
|
header = (struct grub_module_header *) (module_img + offset);
|
||||||
|
header->type = OBJ_TYPE_CONFIG;
|
||||||
|
header->size = grub_host_to_target32 (config_size + sizeof (*header));
|
||||||
|
offset += sizeof (*header);
|
||||||
|
|
||||||
|
grub_util_load_image (config_path, module_img + offset);
|
||||||
|
offset += config_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write the module data to the new segment. */
|
/* Write the module data to the new segment. */
|
||||||
grub_util_write_image_at (module_img, total_module_size,
|
grub_util_write_image_at (module_img, total_module_size,
|
||||||
|
@ -181,7 +202,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path)
|
add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path, char *config_path)
|
||||||
{
|
{
|
||||||
Elf32_Ehdr ehdr;
|
Elf32_Ehdr ehdr;
|
||||||
Elf32_Phdr *phdrs = NULL;
|
Elf32_Phdr *phdrs = NULL;
|
||||||
|
@ -270,7 +291,7 @@ add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *
|
||||||
phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out),
|
phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out),
|
||||||
GRUB_TARGET_SIZEOF_LONG));
|
GRUB_TARGET_SIZEOF_LONG));
|
||||||
|
|
||||||
load_modules (modbase, phdr, dir, mods, out, memdisk_path);
|
load_modules (modbase, phdr, dir, mods, out, memdisk_path, config_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chrp)
|
if (chrp)
|
||||||
|
@ -313,6 +334,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'},
|
||||||
{"note", no_argument, 0, 'n'},
|
{"note", no_argument, 0, 'n'},
|
||||||
|
@ -335,6 +357,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\n\
|
-p, --prefix=DIR set grub_prefix directory\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\n\
|
-o, --output=FILE output a generated image to FILE\n\
|
||||||
-h, --help display this message and exit\n\
|
-h, --help display this message and exit\n\
|
||||||
-n, --note add NOTE segment for CHRP Open Firmware\n\
|
-n, --note add NOTE segment for CHRP Open Firmware\n\
|
||||||
|
@ -355,13 +378,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;
|
||||||
int chrp = 0;
|
int chrp = 0;
|
||||||
|
|
||||||
progname = "grub-mkimage";
|
progname = "grub-mkimage";
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "d:p:m:o:hVvn", options, 0);
|
int c = getopt_long (argc, argv, "d:p:m:c:o:hVvn", options, 0);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -387,6 +411,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;
|
||||||
|
@ -417,7 +448,8 @@ main (int argc, char *argv[])
|
||||||
if (! fp)
|
if (! fp)
|
||||||
grub_util_error ("cannot open %s", output);
|
grub_util_error ("cannot open %s", output);
|
||||||
|
|
||||||
add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk);
|
add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk,
|
||||||
|
config);
|
||||||
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue