1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
14 #include <sys/types.h>
25 #define dprintf(fmt, args...) if (verbose) printf(fmt, ##args)
31 ("Usage: build_romfs [-?] [--help] [-s|--romfs-size <romfs_size>]\n"
32 "\t[-p|--smart-pad] [-n|--notime] <config-file> <output-file>\n");
36 str_to_num(const char *str)
38 char *s = (char *) str;
39 unsigned long num = strtoul(s, &s, 0);
50 * NOTE: We should consider to install an exit handler which does the
51 * unlink() of the output file. In case of error we just do exit() and
52 * forget about all the clumsy error handling free/close code, which
53 * blows up the code significantly and makes it hard to read.
56 main(int argc, char *argv[])
59 struct ffs_chain_t ffs_chain;
61 int smart_pad = 0; /* default */
63 const char *config_file = "boot_rom.ffs";
64 const char *output_file = "boot_rom.bin";
66 memset((void *) &ffs_chain, 0, sizeof(struct ffs_chain_t));
70 static struct option long_options[] = {
71 {"romfs-size", 1, 0, 's'},
72 {"smart-pad", 0, 0, 'p'},
73 {"notime", 0, 0, 'n'},
74 {"verbose", 0, 0, 'v'},
78 c = getopt_long(argc, argv, "s:ph?nv", long_options,
85 ffs_chain.romfs_size = str_to_num(optarg);
101 printf("?? getopt returned character code 0%o ??\n", c);
105 /* two files must always be specified: config-file and output-file */
106 if (optind + 2 != argc) {
111 config_file = argv[optind++];
112 output_file = argv[optind++];
114 dprintf("ROMFS FILESYSTEM CREATION V0.3 (bad parser)\n"
115 "Build directory structure...\n"
116 " smart padding %s, maximum romfs size %d bytes\n",
117 smart_pad ? "enabled" : "disabled", ffs_chain.romfs_size);
119 conf_file = open(config_file, O_RDONLY);
120 if (0 >= conf_file) {
121 perror("load config file:");
125 rc = read_config(conf_file, &ffs_chain);
128 fprintf(stderr, "flash cannot be built due to config errors\n");
135 dump_fs_contents(&ffs_chain);
137 /* FIXME: size is only verified during reorder */
138 rc = reorder_ffs_chain(&ffs_chain);
140 if (rc == EXIT_FAILURE)
143 dprintf("Build ffs and write to image file...\n");
144 if (build_ffs(&ffs_chain, output_file, notime) != 0) {
145 fprintf(stderr, "build ffs failed\n");
151 /* Check if there are any duplicate entries in the image,
152 print warning if this is the case. */
153 find_duplicates(&ffs_chain);
154 free_chain_memory(&ffs_chain);
158 /* If the build failed, remove the target image file */
159 if (rc == EXIT_FAILURE)