Since cbfstool is so simple right now, it makes sense to have -Werr in
CFLAGS so that we are more careful with the code.  It will be a bigger
pain later.

I didn't want to touch lzma so the tools directory has its own CFLAGS now.

I chose to make all sizes int.  They could have been unsigned int.  If
anyone really cares we can change it.  It just needs to be consistent.

I cleaned up some of the parameters (usage and checking.)  There's no
need to have an empty add call, etc.

Signed-off-by: Myles Watson <[email protected]>

Thanks,
Myles
Index: cbfstool/create.c
===================================================================
--- cbfstool.orig/create.c	2009-05-08 12:25:58.000000000 -0600
+++ cbfstool/create.c	2009-05-08 12:26:15.000000000 -0600
@@ -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 @@
 	char *bootblock = NULL;
 	int bootblocksize;
 
-	if (argc < 2) {
+	if (argc < 3) {
 		create_usage();
 		return -1;
 	}
@@ -42,11 +42,10 @@
 
 	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) {
Index: cbfstool/add.c
===================================================================
--- cbfstool.orig/add.c	2009-05-08 12:25:58.000000000 -0600
+++ cbfstool/add.c	2009-05-08 12:26:15.000000000 -0600
@@ -205,25 +205,25 @@
 
 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 @@
 
 	/* 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);
 }
 
Index: cbfstool/print.c
===================================================================
--- cbfstool.orig/print.c	2009-05-08 12:25:58.000000000 -0600
+++ cbfstool/print.c	2009-05-08 12:31:47.000000000 -0600
@@ -27,6 +27,9 @@
 
 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 @@
 		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;
Index: cbfstool/Makefile
===================================================================
--- cbfstool.orig/Makefile	2009-05-08 12:27:36.000000000 -0600
+++ cbfstool/Makefile	2009-05-08 12:27:47.000000000 -0600
@@ -9,7 +9,7 @@
 INC=cbfstool.h cbfs.h
 
 CC=gcc
-CFLAGS=-g -Wall # -W -Werror
+CFLAGS=-g -Wall -W -Werror
 
 DESTDIR ?= /usr/local/bin
 
Index: cbfstool/cbfstool.c
===================================================================
--- cbfstool.orig/cbfstool.c	2009-05-08 12:34:51.000000000 -0600
+++ cbfstool/cbfstool.c	2009-05-08 12:35:07.000000000 -0600
@@ -66,7 +66,7 @@
 	"extract", extract_handler, extract_usage}, {
 	"print", print_handler, print_usage}, {
 	"resize", resize_handler, resize_usage}, {
-"", NULL},};
+"", NULL, NULL},};
 
 static struct rom rom;
 
Index: cbfstool/cbfstool.h
===================================================================
--- cbfstool.orig/cbfstool.h	2009-05-08 12:30:03.000000000 -0600
+++ cbfstool/cbfstool.h	2009-05-08 13:05:49.000000000 -0600
@@ -67,13 +67,13 @@
 
 /* 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_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
Index: cbfstool/extract.c
===================================================================
--- cbfstool.orig/extract.c	2009-05-08 12:28:19.000000000 -0600
+++ cbfstool/extract.c	2009-05-08 12:29:32.000000000 -0600
@@ -28,7 +28,7 @@
 {
 	void *buf;
 	int fd, ret;
-	unsigned long size;
+	int size;
 
 	ret = rom_extract(rom, name, &buf, &size);
 
@@ -43,7 +43,7 @@
 	}
 
 	if (write(fd, buf, size) != size) {
-		ERROR("Couldn't write %ld bytes!\n", size);
+		ERROR("Couldn't write %d bytes!\n", size);
 		ret = -1;
 	}
 
Index: cbfstool/fs.c
===================================================================
--- cbfstool.orig/fs.c	2009-05-08 12:35:42.000000000 -0600
+++ cbfstool/fs.c	2009-05-08 13:05:49.000000000 -0600
@@ -20,7 +20,7 @@
 #include <string.h>
 #include "cbfstool.h"
 
-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 =
@@ -51,8 +51,8 @@
 
 struct cbfs_file *rom_find_empty(struct rom *rom)
 {
-	unsigned int offset = ntohl(rom->header->offset);
-	unsigned int ret = ntohl(rom->header->offset);
+	int offset = ntohl(rom->header->offset);
+	int ret = ntohl(rom->header->offset);
 
 	while (offset < rom->fssize) {
 
@@ -86,7 +86,7 @@
 	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;
@@ -133,7 +133,7 @@
 	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;
@@ -153,8 +153,8 @@
 int rom_add(struct rom *rom, const char *name, void *buffer, int size, int type)
 {
 	struct cbfs_file *c = rom_find_empty(rom);
-	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);
Index: cbfstool/resize.c
===================================================================
--- cbfstool.orig/resize.c	2009-05-08 12:32:10.000000000 -0600
+++ cbfstool/resize.c	2009-05-08 12:33:10.000000000 -0600
@@ -32,7 +32,8 @@
 
 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);
 
Index: cbfstool/tools/Makefile
===================================================================
--- cbfstool.orig/tools/Makefile	2009-05-08 12:43:01.000000000 -0600
+++ cbfstool/tools/Makefile	2009-05-08 12:43:52.000000000 -0600
@@ -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
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to