1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 rPath, Inc. - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * Wrap a Linux image in an ELF (or other) container
27 #include <sys/types.h>
29 #include "wraplinux.h"
38 const struct option long_options[] = {
39 {"params", 1, 0, 'p'},
40 {"cmdline", 1, 0, 'p'},
41 {"commandline", 1, 0, 'p'},
42 {"initrd", 1, 0, 'i'},
43 {"output", 1, 0, 'o'},
44 {"loadhigh", 0, 0, 'l'},
45 {"noloadhigh", 0, 0, OPT_NOLOADHIGH},
47 {"multiboot", 0, 0, 'M'},
50 {"version", 0, 0, 'V'},
54 #define OPTSTRING "p:i:o:lEMNhV"
56 static void usage(int err)
60 "Usage: %s [options] kernel\n"
61 " --params -p kernel commandline parameters\n"
62 " --initrd -i initrd (multiple initrd options supported)\n"
63 " --output -o output filename (default stdout)\n"
64 " --elf -E output in ELF format (default)\n"
65 " --multiboot -M output in Multiboot ELF format\n"
66 " --nbi -N output in NBI format\n"
67 " --loadhigh -l load entirely above 1 MB\n"
68 " --help -h display this help text\n"
69 " --version -V print the program version\n",
70 WRAPLINUX_PACKAGE, WRAPLINUX_VERSION,
75 int main(int argc, char *argv[])
79 struct string_list *ird = NULL, **irdp = &ird, *ip;
81 bool loadhighopt = false;
85 opt.output = output_elf;
87 while ((optch = getopt_long(argc, argv, OPTSTRING, long_options, NULL))
94 ip = xmalloc(sizeof *ip);
101 if (optarg[0] == '-' && !optarg[1]) {
104 out = fopen(optarg, "wb");
106 fprintf(stderr, "%s: %s: %s\n", program,
107 optarg, strerror(errno));
117 opt.loadhigh = false;
121 opt.output = output_elf;
124 opt.output = output_multiboot;
127 opt.output = output_nbi;
133 printf("%s %s\n", WRAPLINUX_PACKAGE, WRAPLINUX_VERSION);
141 if ((argc - optind) != 1)
144 if (opt.output == output_multiboot && !loadhighopt)
147 kernel = argv[optind];
152 return wrap_kernel(kernel, opt.params, ird, out);