~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to util/i386/pc/grub-mkimage.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2007-11-01 13:18:51 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20071101131851-63uqsb4dax2h1cbm
Tags: upstream-1.95+20071101
ImportĀ upstreamĀ versionĀ 1.95+20071101

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* grub-mkimage.c - make a bootable image */
2
2
/*
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.
5
5
 *
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.
10
10
 *
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.
15
15
 *
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/>.
19
18
 */
20
19
 
21
20
#include <config.h>
76
75
}
77
76
 
78
77
static void
79
 
generate_image (const char *dir, FILE *out, char *mods[])
 
78
generate_image (const char *dir, char *prefix, FILE *out, char *mods[])
80
79
{
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
103
 
 
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);
 
107
 
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[] =
183
186
  {
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\
202
206
\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\
208
213
\n\
209
214
Report bugs to <%s>.\n\
210
 
", GRUB_LIBDIR, PACKAGE_BUGREPORT);
 
215
", GRUB_LIBDIR, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
211
216
 
212
217
  exit (status);
213
218
}
215
220
int
216
221
main (int argc, char *argv[])
217
222
{
218
 
  char *output = 0;
219
 
  char *dir = 0;
 
223
  char *output = NULL;
 
224
  char *dir = NULL;
 
225
  char *prefix = NULL;
220
226
  FILE *fp = stdout;
221
227
 
222
228
  progname = "grub-mkimage";
223
229
  
224
230
  while (1)
225
231
    {
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);
227
233
 
228
234
      if (c == -1)
229
235
        break;
248
254
            usage (0);
249
255
            break;
250
256
 
 
257
          case 'p':
 
258
            if (prefix)
 
259
              free (prefix);
 
260
 
 
261
            prefix = xstrdup (optarg);
 
262
            break;
 
263
 
251
264
          case 'V':
252
265
            printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
253
266
            return 0;
269
282
        grub_util_error ("cannot open %s", output);
270
283
    }
271
284
 
272
 
  generate_image (dir ? : GRUB_LIBDIR, fp, argv + optind);
 
285
  generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, argv + optind);
273
286
 
274
287
  fclose (fp);
275
288