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"
34 const struct option long_options[] = {
35 {"params", 1, 0, 'p'},
36 {"cmdline", 1, 0, 'p'},
37 {"commandline", 1, 0, 'p'},
38 {"initrd", 1, 0, 'i'},
39 {"output", 1, 0, 'o'},
41 {"multiboot", 0, 0, 'M'},
44 {"version", 0, 0, 'V'},
48 #define OPTSTRING "p:i:o:EMNhV"
50 static void usage(int err)
54 "Usage: %s [options] kernel\n"
55 " --params -p kernel commandline parameters\n"
56 " --initrd -i initrd (multiple initrd options supported)\n"
57 " --output -o output filename (default stdout)\n"
58 " --elf -E output in ELF format (default)\n"
59 " --multiboot -M output in Multiboot ELF format\n"
60 " --nbi -N output in NBI format\n"
61 " --help -h display this help text\n"
62 " --version -V print the program version\n",
63 WRAPLINUX_PACKAGE, WRAPLINUX_VERSION,
68 int main(int argc, char *argv[])
72 struct string_list *ird = NULL, **irdp = &ird, *ip;
77 opt.output = output_elf;
79 while ((optch = getopt_long(argc, argv, OPTSTRING, long_options, NULL))
86 ip = xmalloc(sizeof *ip);
93 if (optarg[0] == '-' && !optarg[1]) {
96 out = fopen(optarg, "wb");
98 fprintf(stderr, "%s: %s: %s\n", program,
99 optarg, strerror(errno));
105 opt.output = output_elf;
108 opt.output = output_multiboot;
111 opt.output = output_nbi;
117 printf("%s %s\n", WRAPLINUX_PACKAGE, WRAPLINUX_VERSION);
125 if ((argc - optind) != 1)
128 kernel = argv[optind];
133 return wrap_kernel(kernel, opt.params, ird, out);