1
1
/* grub-mkimage.c - make a bootable image */
3
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
4
* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
6
* GRUB is free software; you can redistribute it and/or modify
6
* GRUB is free software: you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
8
* the Free Software Foundation, either version 3 of the License, or
9
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
11
* GRUB is distributed in the hope that it will be useful,
12
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
* GNU General Public License for more details.
16
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
20
#include <config.h>
79
generate_image (const char *dir, FILE *out, char *mods[])
78
generate_image (const char *dir, char *prefix, FILE *out, char *mods[])
81
80
grub_addr_t module_addr = 0;
82
81
char *kernel_img, *boot_img, *core_img;
102
101
kernel_img = xmalloc (kernel_size + total_module_size);
103
102
grub_util_load_image (kernel_path, kernel_img);
104
if (GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1 > GRUB_KERNEL_MACHINE_DATA_END)
105
grub_util_error ("prefix too long");
106
strcpy (kernel_img + GRUB_KERNEL_MACHINE_PREFIX, prefix);
105
108
/* Fill in the grub_module_info structure. */
106
109
modinfo = (struct grub_module_info *) (kernel_img + kernel_size);
107
110
modinfo->magic = GRUB_MODULE_MAGIC;
182
185
static struct option options[] =
184
187
{"directory", required_argument, 0, 'd'},
188
{"prefix", required_argument, 0, 'p'},
185
189
{"output", required_argument, 0, 'o'},
186
190
{"help", no_argument, 0, 'h'},
187
191
{"version", no_argument, 0, 'V'},
201
205
Make a bootable image of GRUB.\n\
203
207
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
208
-p, --prefix=DIR set grub_prefix directory [default=%s]\n\
204
209
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
205
210
-h, --help display this message and exit\n\
206
211
-V, --version print version information and exit\n\
207
212
-v, --verbose print verbose messages\n\
209
214
Report bugs to <%s>.\n\
210
", GRUB_LIBDIR, PACKAGE_BUGREPORT);
215
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
216
221
main (int argc, char *argv[])
220
226
FILE *fp = stdout;
222
228
progname = "grub-mkimage";
226
int c = getopt_long (argc, argv, "d:o:hVv", options, 0);
232
int c = getopt_long (argc, argv, "d:p:o:hVv", options, 0);
269
282
grub_util_error ("cannot open %s", output);
272
generate_image (dir ? : GRUB_LIBDIR, fp, argv + optind);
285
generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind);