4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
20 /* v2 compat: First, assumes a 64K bootblock.
21 * cbfstool coreboot.rom create 0x80000 coreboot.strip
22 * cbfstool coreboot.rom add-payload /tmp/filo.elf payload
23 * cbfstool coreboot.rom print
33 extern int create_handler(struct rom *, int, char **);
34 extern int bootblock_handler(struct rom *, int, char **);
35 extern int print_handler(struct rom *, int, char **);
36 extern int add_handler(struct rom *, int, char **);
37 extern int delete_handler(struct rom *, int, char **);
38 extern int resize_handler(struct rom *, int, char **);
39 extern int add_payload_handler(struct rom *, int, char **);
40 extern int add_stage_handler(struct rom *, int, char **);
42 extern void create_usage(void);
43 extern void bootblock_usage(void);
44 extern void print_usage(void);
45 extern void add_usage(void);
46 extern void delete_usage(void);
47 extern void resize_usage(void);
48 extern void add_payload_usage(void);
49 extern void add_stage_usage(void);
53 int (*handler) (struct rom *, int, char **);
57 "add", add_handler, add_usage}, {
58 "add-payload", add_payload_handler, add_payload_usage}, {
59 "add-stage", add_stage_handler, add_stage_usage}, {
60 "bootblock", bootblock_handler, bootblock_usage}, {
61 "create", create_handler, create_usage}, {
62 "delete", delete_handler, delete_usage}, {
63 "print", print_handler, print_usage}, {
64 "resize", resize_handler, resize_usage}, {
67 static struct rom rom;
69 char cbfstool_bindir[255];
75 printf("cbfstool [OPTION] [[FILE] [COMMAND] [PARAMETERS]...\n");
76 printf("Apply COMMANDS with PARAMETERS to FILE. If no COMMAND is\n");
77 printf("given, run in interactive mode\n\n");
79 printf(" -h\t\tDisplay this help message\n");
80 printf(" -C <dir>\tChange to the directory before operating\n\n");
81 printf("COMMANDs:\n");
83 for (i = 0; commands[i].handler != NULL; i++)
87 int main(int argc, char **argv)
94 strncpy(cbfstool_bindir, dirname(argv[0]), 254);
97 signed ch = getopt(argc, argv, "hC:");
110 if (optind >= argc) {
115 if (cdir != NULL && chdir(cdir)) {
116 ERROR("Unable to switch to %s: %m\n", cdir);
120 rname = argv[optind];
121 cmd = optind + 1 < argc ? argv[optind + 1] : NULL;
123 /* Open the ROM (if it exists) */
124 rom.name = (unsigned char *)strdup(rname);
126 if (!access(rname, F_OK)) {
127 if (open_rom(&rom, rname)) {
128 ERROR("Problem while reading the ROM\n");
134 /* Process the incoming comand */
136 for (i = 0; commands[i].handler != NULL; i++) {
137 if (!strcmp(commands[i].command, cmd)) {
138 ret = commands[i].handler(&rom,
144 ERROR("Command %s not valid\n", cmd);
146 printf("Interactive mode not ready yet!\n");
150 if (rom.ptr != NULL && rom.ptr != MAP_FAILED)
151 munmap(rom.ptr, rom.size);