1 /* febootstrap-supermin-helper reimplementation in C.
2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
36 struct timeval start_t;
39 static const char *format = "cpio";
41 enum { HELP_OPTION = CHAR_MAX + 1 };
43 static const char *options = "f:k:vV";
44 static const struct option long_options[] = {
45 { "help", 0, 0, HELP_OPTION },
46 { "format", required_argument, 0, 'f' },
47 { "kmods", required_argument, 0, 'k' },
48 { "verbose", 0, 0, 'v' },
49 { "version", 0, 0, 'V' },
54 usage (const char *progname)
56 printf ("%s: build the supermin appliance on the fly\n"
59 " %s [-options] inputs [...] host_cpu kernel initrd\n"
60 " %s -f ext2 inputs [...] host_cpu kernel initrd appliance\n"
64 "This script is used by febootstrap to build the supermin appliance\n"
65 "(kernel and initrd output files). You should NOT need to run this\n"
66 "program directly except if you are debugging tricky supermin\n"
67 "appliance problems.\n"
69 "NB: The kernel and initrd parameters are OUTPUT parameters. If\n"
70 "those files exist, they are overwritten by the output.\n"
74 " Display this help text and exit.\n"
75 " -f cpio|ext2 | --format cpio|ext2\n"
76 " Specify output format (default: cpio).\n"
77 " -k file | --kmods file\n"
78 " Specify kernel module whitelist.\n"
80 " Enable verbose messages (give multiple times for more verbosity).\n"
82 " Display version number and exit.\n",
83 progname, progname, progname, progname, progname);
87 main (int argc, char *argv[])
89 /* First thing: start the clock. */
90 gettimeofday (&start_t, NULL);
92 const char *whitelist = NULL;
94 /* Command line arguments. */
96 int c = getopt_long (argc, argv, options, long_options, NULL);
117 printf (PACKAGE_NAME " " PACKAGE_VERSION "\n");
126 /* Select the correct writer module. */
127 struct writer *writer;
130 if (strcmp (format, "cpio") == 0) {
131 writer = &cpio_writer;
132 nr_outputs = 2; /* kernel and appliance (== initrd) */
134 else if (strcmp (format, "ext2") == 0) {
135 writer = &ext2_writer;
136 nr_outputs = 3; /* kernel, initrd, appliance */
139 fprintf (stderr, "%s: incorrect output format (-f): must be cpio|ext2\n",
144 /* [optind .. optind+nr_inputs-1] hostcpu [argc-nr_outputs-1 .. argc-1]
145 * <---- nr_inputs ----> 1 <---- nr_outputs ---->
147 char **inputs = &argv[optind];
148 int nr_inputs = argc - nr_outputs - 1 - optind;
149 char **outputs = &argv[optind+nr_inputs+1];
150 /*assert (outputs [nr_outputs] == NULL);
151 assert (inputs [nr_inputs + 1 + nr_outputs] == NULL);*/
154 fprintf (stderr, "%s: not enough files specified on the command line\n",
159 /* See: https://bugzilla.redhat.com/show_bug.cgi?id=558593 */
160 const char *hostcpu = outputs[-1];
163 const char *kernel = outputs[0];
165 const char *appliance;
166 initrd = appliance = outputs[1];
168 appliance = outputs[2];
171 print_timestamped_message ("whitelist = %s, "
176 whitelist ? : "(not specified)",
177 hostcpu, kernel, initrd, appliance);
179 for (i = 0; i < nr_inputs; ++i)
180 print_timestamped_message ("inputs[%d] = %s", i, inputs[i]);
183 /* Remove the output files if they exist. */
186 if (initrd != appliance)
189 /* Create kernel output file. */
191 modpath = create_kernel (hostcpu, kernel);
194 print_timestamped_message ("finished creating kernel");
196 /* Create the appliance. */
197 create_appliance (inputs, nr_inputs, whitelist, modpath,
198 initrd, appliance, writer);
201 print_timestamped_message ("finished creating appliance");