1 |
/* grub-mkimage.c - make a bootable image */ |
/* grub-mkimage.c - make a bootable image */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2002,2003,2004 Free Software Foundation, Inc. |
* Copyright (C) 2002,2003,2004,2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* GRUB is free software; you can redistribute it and/or modify |
* GRUB is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
79 |
unsigned num; |
unsigned num; |
80 |
size_t offset; |
size_t offset; |
81 |
struct grub_util_path_list *path_list, *p, *next; |
struct grub_util_path_list *path_list, *p, *next; |
82 |
|
struct grub_module_info *modinfo; |
83 |
|
|
84 |
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods); |
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods); |
85 |
|
|
86 |
kernel_path = grub_util_get_path (dir, "kernel.img"); |
kernel_path = grub_util_get_path (dir, "kernel.img"); |
87 |
kernel_size = grub_util_get_image_size (kernel_path); |
kernel_size = grub_util_get_image_size (kernel_path); |
88 |
|
|
89 |
total_module_size = 0; |
total_module_size = sizeof (struct grub_module_info); |
90 |
for (p = path_list; p; p = p->next) |
for (p = path_list; p; p = p->next) |
91 |
total_module_size += (grub_util_get_image_size (p->name) |
total_module_size += (grub_util_get_image_size (p->name) |
92 |
+ sizeof (struct grub_module_header)); |
+ sizeof (struct grub_module_header)); |
95 |
|
|
96 |
kernel_img = xmalloc (kernel_size + total_module_size); |
kernel_img = xmalloc (kernel_size + total_module_size); |
97 |
grub_util_load_image (kernel_path, kernel_img); |
grub_util_load_image (kernel_path, kernel_img); |
98 |
offset = kernel_size; |
|
99 |
|
/* Fill in the grub_module_info structure. */ |
100 |
|
modinfo = (struct grub_module_info *) (kernel_img + kernel_size); |
101 |
|
modinfo->magic = GRUB_MODULE_MAGIC; |
102 |
|
modinfo->offset = sizeof (struct grub_module_info); |
103 |
|
modinfo->size = total_module_size; |
104 |
|
|
105 |
|
offset = kernel_size + sizeof (struct grub_module_info); |
106 |
for (p = path_list; p; p = p->next) |
for (p = path_list; p; p = p->next) |
107 |
{ |
{ |
108 |
struct grub_module_header *header; |
struct grub_module_header *header; |