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"
61 " %s -f checksum inputs [...] host_cpu\n"
65 "This script is used by febootstrap to build the supermin appliance\n"
66 "(kernel and initrd output files). You should NOT need to run this\n"
67 "program directly except if you are debugging tricky supermin\n"
68 "appliance problems.\n"
70 "NB: The kernel and initrd parameters are OUTPUT parameters. If\n"
71 "those files exist, they are overwritten by the output.\n"
75 " Display this help text and exit.\n"
76 " -f cpio|ext2|checksum | --format cpio|ext2|checksum\n"
77 " Specify output format (default: cpio).\n"
78 " -k file | --kmods file\n"
79 " Specify kernel module whitelist.\n"
81 " Enable verbose messages (give multiple times for more verbosity).\n"
83 " Display version number and exit.\n",
84 progname, progname, progname, progname, progname, progname);
88 main (int argc, char *argv[])
90 /* First thing: start the clock. */
91 gettimeofday (&start_t, NULL);
93 const char *whitelist = NULL;
95 /* Command line arguments. */
97 int c = getopt_long (argc, argv, options, long_options, NULL);
118 printf (PACKAGE_NAME " " PACKAGE_VERSION "\n");
127 /* Select the correct writer module. */
128 struct writer *writer;
131 if (strcmp (format, "cpio") == 0) {
132 writer = &cpio_writer;
133 nr_outputs = 2; /* kernel and appliance (== initrd) */
135 else if (strcmp (format, "ext2") == 0) {
136 writer = &ext2_writer;
137 nr_outputs = 3; /* kernel, initrd, appliance */
139 else if (strcmp (format, "checksum") == 0) {
140 writer = &checksum_writer;
141 nr_outputs = 0; /* (none) */
145 "%s: incorrect output format (-f): must be cpio|ext2|checksum\n",
150 /* [optind .. optind+nr_inputs-1] hostcpu [argc-nr_outputs-1 .. argc-1]
151 * <---- nr_inputs ----> 1 <---- nr_outputs ---->
153 char **inputs = &argv[optind];
154 int nr_inputs = argc - nr_outputs - 1 - optind;
155 char **outputs = &argv[optind+nr_inputs+1];
156 /*assert (outputs [nr_outputs] == NULL);
157 assert (inputs [nr_inputs + 1 + nr_outputs] == NULL);*/
160 fprintf (stderr, "%s: not enough files specified on the command line\n",
165 /* See: https://bugzilla.redhat.com/show_bug.cgi?id=558593 */
166 const char *hostcpu = outputs[-1];
169 const char *kernel = NULL, *initrd = NULL, *appliance = NULL;
173 initrd = appliance = outputs[1];
175 appliance = outputs[2];
178 print_timestamped_message ("whitelist = %s, "
183 whitelist ? : "(not specified)",
184 hostcpu, kernel, initrd, appliance);
186 for (i = 0; i < nr_inputs; ++i)
187 print_timestamped_message ("inputs[%d] = %s", i, inputs[i]);
190 /* Remove the output files if they exist. */
195 if (appliance && initrd != appliance)
198 /* Create kernel output file. */
199 const char *modpath = create_kernel (hostcpu, kernel);
202 print_timestamped_message ("finished creating kernel");
204 /* Create the appliance. */
205 create_appliance (hostcpu, inputs, nr_inputs, whitelist, modpath,
206 initrd, appliance, writer);
209 print_timestamped_message ("finished creating appliance");