diff options
author | Myles Watson <mylesgw@gmail.com> | 2009-05-08 19:39:15 +0000 |
---|---|---|
committer | Myles Watson <mylesgw@gmail.com> | 2009-05-08 19:39:15 +0000 |
commit | 475aeda9d6d62d0249276bff657adc67d206ff31 (patch) | |
tree | 6b3d9371ce61197417ed308faca8cc36691ac58e /util/cbfstool | |
parent | 83b8f0c48550bb1b2cb1a6610b1f0010bf8533a4 (diff) |
Add -Werror to help us keep the code clean.
Change sizes from unsigned int to int.
Clean up some usage and parameter checking.
Signed-off-by: Myles Watson <mylesgw@gmail.com>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4262 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/cbfstool')
-rw-r--r-- | util/cbfstool/Makefile | 2 | ||||
-rw-r--r-- | util/cbfstool/add.c | 20 | ||||
-rw-r--r-- | util/cbfstool/cbfstool.c | 2 | ||||
-rw-r--r-- | util/cbfstool/cbfstool.h | 6 | ||||
-rw-r--r-- | util/cbfstool/create.c | 13 | ||||
-rw-r--r-- | util/cbfstool/extract.c | 4 | ||||
-rw-r--r-- | util/cbfstool/fs.c | 10 | ||||
-rw-r--r-- | util/cbfstool/print.c | 6 | ||||
-rw-r--r-- | util/cbfstool/resize.c | 3 | ||||
-rw-r--r-- | util/cbfstool/tools/Makefile | 2 |
10 files changed, 37 insertions, 31 deletions
diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile index 39af38b280..a779eab126 100644 --- a/util/cbfstool/Makefile +++ b/util/cbfstool/Makefile @@ -9,7 +9,7 @@ OBJ=$(COMMANDS) cbfstool.o util.o fs.o INC=cbfstool.h cbfs.h CC=gcc -CFLAGS=-g -Wall # -W -Werror +CFLAGS=-g -Wall -W -Werror DESTDIR ?= /usr/local/bin diff --git a/util/cbfstool/add.c b/util/cbfstool/add.c index aadb68d841..83f8d29462 100644 --- a/util/cbfstool/add.c +++ b/util/cbfstool/add.c @@ -205,25 +205,25 @@ static int add_blob(struct rom *rom, const char *filename, void add_usage(void) { - printf("add [FILE] [NAME] [TYPE]\tAdd a component\n"); + printf("add FILE NAME TYPE\tAdd a component\n"); } void add_stage_usage(void) { - printf("add-stage [FILE] [NAME] [OPTIONS]\tAdd a stage to the ROM\n"); + printf("add-stage FILE NAME [OPTIONS]\tAdd a stage to the ROM\n"); } void add_payload_usage(void) { printf - ("add-payload [FILE] [NAME] [OPTIONS]\tAdd a payload to the ROM\n"); + ("add-payload FILE NAME [OPTIONS]\tAdd a payload to the ROM\n"); } int add_handler(struct rom *rom, int argc, char **argv) { unsigned int type = CBFS_COMPONENT_NULL; - if (argc < 2) { + if (argc != 3) { add_usage(); return -1; } @@ -235,15 +235,13 @@ int add_handler(struct rom *rom, int argc, char **argv) /* There are two ways to specify the type - a string or a number */ - if (argc == 3) { - if (isdigit(*(argv[2]))) - type = strtoul(argv[2], 0, 0); + if (isdigit(*(argv[2]))) + type = strtoul(argv[2], 0, 0); + else { + ERROR("String types (%s) aren't implemented yet.\n", argv[2]); + return -1; } - if (type == CBFS_COMPONENT_NULL) - WARN("No file type was given for %s - using default\n", - argv[0]); - return add_blob(rom, argv[0], argv[1], type); } diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index cbf448163f..7760a56109 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -66,7 +66,7 @@ struct { "extract", extract_handler, extract_usage}, { "print", print_handler, print_usage}, { "resize", resize_handler, resize_usage}, { -"", NULL},}; +"", NULL, NULL},}; static struct rom rom; diff --git a/util/cbfstool/cbfstool.h b/util/cbfstool/cbfstool.h index 51abd29b58..dc52bfb16b 100644 --- a/util/cbfstool/cbfstool.h +++ b/util/cbfstool/cbfstool.h @@ -67,15 +67,15 @@ int add_bootblock(struct rom *rom, const char *filename); /* fs.c */ -struct cbfs_file *rom_find(struct rom *rom, unsigned int offset); +struct cbfs_file *rom_find(struct rom *rom, int offset); struct cbfs_file *rom_find_first(struct rom *); struct cbfs_file *rom_find_next(struct rom *, struct cbfs_file *); int rom_add(struct rom *rom, const char *name, void *, int size, int type); int rom_set_header(struct rom *rom, struct cbfs_file *c, const char*name, int size, int type); -int rom_extract(struct rom *rom, const char *name, void **buf, unsigned long *size); +int rom_extract(struct rom *rom, const char *name, void **buf, int *size); int rom_remove(struct rom *rom, const char *name); -unsigned int rom_used_space(struct rom *rom); +int rom_used_space(struct rom *rom); int rom_exists(struct rom *rom); #endif diff --git a/util/cbfstool/create.c b/util/cbfstool/create.c index ecfb21c956..e83758c992 100644 --- a/util/cbfstool/create.c +++ b/util/cbfstool/create.c @@ -24,7 +24,7 @@ void create_usage(void) { - printf("create SIZE BOOTBLOCKSIZE [ALIGN] [BOOTBLOCK]\tCreate a ROM file\n"); + printf("create SIZE BOOTBLOCKSIZE BOOTBLOCK [ALIGN]\tCreate a ROM file\n"); } int create_handler(struct rom *rom, int argc, char **argv) @@ -33,7 +33,7 @@ int create_handler(struct rom *rom, int argc, char **argv) char *bootblock = NULL; int bootblocksize; - if (argc < 2) { + if (argc < 3) { create_usage(); return -1; } @@ -42,11 +42,10 @@ int create_handler(struct rom *rom, int argc, char **argv) bootblocksize = get_size(argv[1]); - if (argc == 3) { - bootblock = argv[2]; - } else if (argc >= 4) { - align = strtoul(argv[2], NULL, 0); - bootblock = argv[3]; + bootblock = argv[2]; + + if (argc >= 4) { + align = strtoul(argv[3], NULL, 0); } if (size < bootblocksize) { diff --git a/util/cbfstool/extract.c b/util/cbfstool/extract.c index d6944763b7..5a30553d29 100644 --- a/util/cbfstool/extract.c +++ b/util/cbfstool/extract.c @@ -28,7 +28,7 @@ static int extract_blob(struct rom *rom, const char *filename, const char *name) { void *buf; int fd, ret; - unsigned long size; + int size; ret = rom_extract(rom, name, &buf, &size); @@ -43,7 +43,7 @@ static int extract_blob(struct rom *rom, const char *filename, const char *name) } if (write(fd, buf, size) != size) { - ERROR("Couldn't write %ld bytes!\n", size); + ERROR("Couldn't write %d bytes!\n", size); ret = -1; } diff --git a/util/cbfstool/fs.c b/util/cbfstool/fs.c index 8292163961..d724ddae99 100644 --- a/util/cbfstool/fs.c +++ b/util/cbfstool/fs.c @@ -152,7 +152,7 @@ struct cbfs_file * rom_alloc(struct rom *rom, unsigned long size) return ((struct cbfs_file *)ROM_PTR(rom, ret)); } -struct cbfs_file *rom_find(struct rom *rom, unsigned int offset) +struct cbfs_file *rom_find(struct rom *rom, int offset) { while (offset < rom->fssize) { struct cbfs_file *c = @@ -195,7 +195,7 @@ struct cbfs_file *rom_find_by_name(struct rom *rom, const char *name) return NULL; } -unsigned int rom_used_space(struct rom *rom) +int rom_used_space(struct rom *rom) { struct cbfs_file *c = rom_find_first(rom); unsigned int ret = 0; @@ -235,7 +235,7 @@ int rom_remove(struct rom *rom, const char *name) return 0; } -int rom_extract(struct rom *rom, const char *name, void** buf, unsigned long *size ) +int rom_extract(struct rom *rom, const char *name, void** buf, int *size ) { struct cbfs_file *c = rom_find_by_name(rom, name); unsigned int csize; @@ -265,8 +265,8 @@ int rom_extract(struct rom *rom, const char *name, void** buf, unsigned long *si int rom_add(struct rom *rom, const char *name, void *buffer, int size, int type) { struct cbfs_file *c = rom_alloc(rom, size); - unsigned int offset; - unsigned int csize; + int offset; + int csize; if (rom_find_by_name(rom, name)) { ERROR("Component %s already exists in this rom\n", name); diff --git a/util/cbfstool/print.c b/util/cbfstool/print.c index 7eb9ee452c..b23f949e06 100644 --- a/util/cbfstool/print.c +++ b/util/cbfstool/print.c @@ -27,6 +27,9 @@ void print_usage(void) int print_handler(struct rom *rom, int argc, char **argv) { + if (argc > 0 || argv[1] != NULL) + printf("print\t\t\t\tShow the contents of the ROM\n"); + printf("%s: %d kB, bootblocksize %d, romsize %d, offset 0x%x\n", rom->name, rom->size / 1024, ntohl(rom->header->bootblocksize), ntohl(rom->header->romsize), ntohl(rom->header->offset)); printf("Alignment: %d bytes\n\n", ntohl(rom->header->align)); @@ -48,6 +51,9 @@ int print_handler(struct rom *rom, int argc, char **argv) case CBFS_COMPONENT_OPTIONROM: strcpy(type, "optionrom"); break; + case CBFS_COMPONENT_NULL: + strcpy(type, "free"); + break; default: sprintf(type, "0x%8.8x", htonl(c->type)); break; diff --git a/util/cbfstool/resize.c b/util/cbfstool/resize.c index 157515619c..d70c6d04ef 100644 --- a/util/cbfstool/resize.c +++ b/util/cbfstool/resize.c @@ -32,7 +32,8 @@ void resize_usage(void) int resize_handler(struct rom *rom, int argc, char **argv) { - unsigned int size, align, offset; + unsigned int align, offset; + int size; char null = '\0'; int bootblocksize = ntohl(rom->header->bootblocksize); diff --git a/util/cbfstool/tools/Makefile b/util/cbfstool/tools/Makefile index f5b0e04bcc..65ba375fc3 100644 --- a/util/cbfstool/tools/Makefile +++ b/util/cbfstool/tools/Makefile @@ -1,6 +1,8 @@ tobj ?= $(shell pwd) tsrc ?= $(shell pwd) +CFLAGS=-g -Wall + TARGETS += $(tobj)/cbfs-mkstage $(tobj)/cbfs-mkpayload tools: $(tobj)/cbfs-mkstage $(tobj)/cbfs-mkpayload |