diff options
author | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2015-03-04 00:55:03 +0100 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2015-03-04 19:53:20 +0100 |
commit | 2dd161f556eb0bfb4f092d35397fd04c98d1a3fb (patch) | |
tree | d6f2383983dcd849c4a78459ef7aa9d68c616915 | |
parent | 3aca2cdced54ff525022366bc6dee949b0152d83 (diff) | |
download | coreboot-2dd161f556eb0bfb4f092d35397fd04c98d1a3fb.tar.xz |
cbfstool: Clean up code
cbfstool has diverged between coreboot upstream and the chromium tree.
Bring in some of the chromium changes, in particular the useful remainders
of cbf37fe (https://chromium-review.googlesource.com/176710)
- fix coding style
- mark unused variables explicitly unused
- remove some dead code
Change-Id: I354aaede8ce425ebe99d4c60c232feea62bf8a11
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/8577
Tested-by: build bot (Jenkins)
Reviewed-by: Marc Jones <marc.jones@se-eng.com>
-rw-r--r-- | util/cbfstool/Makefile | 3 | ||||
-rw-r--r-- | util/cbfstool/cbfs.h | 1 | ||||
-rw-r--r-- | util/cbfstool/cbfs_image.c | 26 | ||||
-rw-r--r-- | util/cbfstool/cbfstool.c | 10 | ||||
-rw-r--r-- | util/cbfstool/common.c | 12 | ||||
-rw-r--r-- | util/cbfstool/common.h | 16 | ||||
-rw-r--r-- | util/cbfstool/lzma/lzma.c | 8 |
7 files changed, 32 insertions, 44 deletions
diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile index 4f282f9fc1..05a96ee90a 100644 --- a/util/cbfstool/Makefile +++ b/util/cbfstool/Makefile @@ -4,8 +4,7 @@ HOSTCC ?= $(CC) CFLAGS ?= -g CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -CFLAGS += -Wstrict-aliasing -Werror -CFLAGS += -Wshadow +CFLAGS += -Wstrict-aliasing -Wshadow -Werror CBFSTOOL_BINARY:=$(obj)/cbfstool diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h index f7cd39a20f..e5011d6e1e 100644 --- a/util/cbfstool/cbfs.h +++ b/util/cbfstool/cbfs.h @@ -125,7 +125,6 @@ struct cbfs_payload { #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) ) /* cbfs_image.c */ uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value); -const char *get_cbfs_entry_type_name(uint32_t type); uint32_t get_cbfs_compression(const char *name, uint32_t unknown); /* common.c */ diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 6775b069dd..6b0ed59efc 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -69,16 +69,6 @@ static uint32_t align_up(uint32_t value, uint32_t align) return value; } -static uint32_t lookup_type_by_name(const struct typedesc_t *desc, const char *name, - uint32_t default_value) -{ - int i; - for (i = 0; desc[i].name; i++) - if (strcmp(desc[i].name, name) == 0) - return desc[i].type; - return default_value; -} - static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t type, const char *default_value) { @@ -89,21 +79,11 @@ static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t t return default_value; } -uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value) -{ - return lookup_type_by_name(types_cbfs_entry, name, default_value); -} - -const char *get_cbfs_entry_type_name(uint32_t type) +static const char *get_cbfs_entry_type_name(uint32_t type) { return lookup_name_by_type(types_cbfs_entry, type, "(unknown)"); } -uint32_t get_cbfs_compression(const char *name, uint32_t unknown) -{ - return lookup_type_by_name(types_cbfs_compression, name, unknown); -} - /* CBFS image */ static int cbfs_calculate_file_header_size(const char *name) @@ -186,7 +166,7 @@ void cbfs_get_header(struct cbfs_header *header, const void *src) } int cbfs_image_create(struct cbfs_image *image, - uint32_t myarch, + uint32_t architecture, size_t size, uint32_t align, struct buffer *bootblock, @@ -253,7 +233,7 @@ int cbfs_image_create(struct cbfs_image *image, image->header->bootblocksize = bootblock->size; image->header->align = align; image->header->offset = entries_offset; - image->header->architecture = myarch; + image->header->architecture = architecture; header_loc = (image->buffer.data + header_offset); cbfs_put_header(header_loc, image->header); diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 41df15745a..80331e7e37 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -118,7 +118,8 @@ static int cbfs_add_component(const char *cbfs_name, const char *name, uint32_t type, uint32_t offset, - convert_buffer_t convert) { + convert_buffer_t convert) +{ struct cbfs_image image; struct buffer buffer; @@ -194,7 +195,9 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset) return 0; } -static int cbfstool_convert_mkpayload(struct buffer *buffer, uint32_t *offset) { +static int cbfstool_convert_mkpayload(struct buffer *buffer, + unused uint32_t *offset) +{ struct buffer output; int ret; /* per default, try and see if payload is an ELF binary */ @@ -222,7 +225,8 @@ static int cbfstool_convert_mkpayload(struct buffer *buffer, uint32_t *offset) { } static int cbfstool_convert_mkflatpayload(struct buffer *buffer, - uint32_t *offset) { + unused uint32_t *offset) +{ struct buffer output; if (parse_flat_binary_to_payload(buffer, &output, param.loadaddress, diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index bd9cdc0aa5..6ac39ef826 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -53,7 +53,8 @@ static off_t get_file_size(FILE *f) } /* Buffer and file I/O */ -int buffer_create(struct buffer *buffer, size_t size, const char *name) { +int buffer_create(struct buffer *buffer, size_t size, const char *name) +{ buffer->name = strdup(name); buffer->size = size; buffer->data = (char *)malloc(buffer->size); @@ -64,7 +65,8 @@ int buffer_create(struct buffer *buffer, size_t size, const char *name) { return (buffer->data == NULL); } -int buffer_from_file(struct buffer *buffer, const char *filename) { +int buffer_from_file(struct buffer *buffer, const char *filename) +{ FILE *fp = fopen(filename, "rb"); if (!fp) { perror(filename); @@ -88,7 +90,8 @@ int buffer_from_file(struct buffer *buffer, const char *filename) { return 0; } -int buffer_write_file(struct buffer *buffer, const char *filename) { +int buffer_write_file(struct buffer *buffer, const char *filename) +{ FILE *fp = fopen(filename, "wb"); if (!fp) { perror(filename); @@ -104,7 +107,8 @@ int buffer_write_file(struct buffer *buffer, const char *filename) { return 0; } -void buffer_delete(struct buffer *buffer) { +void buffer_delete(struct buffer *buffer) +{ assert(buffer); if (buffer->name) { free(buffer->name); diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index 41659a268e..02a1076488 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -31,7 +31,7 @@ #endif #define ntohll(x) (is_big_endian() ? (x) : swab64(x)) #define htonll(x) (is_big_endian() ? (x) : swab64(x)) -extern int is_big_endian(void); +int is_big_endian(void); /* Message output */ extern int verbose; @@ -41,6 +41,12 @@ extern int verbose; #define INFO(x...) { if (verbose > 0) fprintf(stderr, "INFO: " x); } #define DEBUG(x...) { if (verbose > 1) fprintf(stderr, "DEBUG: " x); } +/* Helpers */ +#define ARRAY_SIZE(a) (int)(sizeof(a) / sizeof((a)[0])) +#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1)) + +#define unused __attribute__((unused)) + /* Buffer and file I/O */ struct buffer { char *name; @@ -72,8 +78,7 @@ static inline void buffer_init(struct buffer *b, char *name, void *data, b->size = size; } -/* - * Splice a buffer into another buffer. If size is zero the entire buffer +/* Splice a buffer into another buffer. If size is zero the entire buffer * is spliced while if size is non-zero the buffer is spliced starting at * offset for size bytes. Note that it's up to caller to bounds check. */ @@ -115,8 +120,6 @@ void buffer_delete(struct buffer *buffer); const char *arch_to_string(uint32_t a); uint32_t string_to_arch(const char *arch_string); -#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1)) - typedef int (*comp_func_ptr) (char *, int, char *, int *); typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo; @@ -144,10 +147,10 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, void print_supported_filetypes(void); -#define ARRAY_SIZE(a) (int)(sizeof(a) / sizeof((a)[0])) /* lzma/lzma.c */ int do_lzma_compress(char *in, int in_len, char *out, int *out_len); int do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len); + /* xdr.c */ struct xdr { uint8_t (*get8)(struct buffer *input); @@ -160,7 +163,6 @@ struct xdr { void (*put64)(struct buffer *input, uint64_t val); }; -/* xdr.c */ extern struct xdr xdr_le, xdr_be; size_t bgets(struct buffer *input, void *output, size_t len); size_t bputs(struct buffer *b, const void *data, size_t len); diff --git a/util/cbfstool/lzma/lzma.c b/util/cbfstool/lzma/lzma.c index abd1bfd9b5..0944b1ff08 100644 --- a/util/cbfstool/lzma/lzma.c +++ b/util/cbfstool/lzma/lzma.c @@ -31,12 +31,12 @@ static void put_64(void *p, uint64_t value) /* Memory Allocation API */ -static void *SzAlloc(void *unused, size_t size) +static void *SzAlloc(unused void *u, size_t size) { return malloc(size); } -static void SzFree(void *unused, void *address) +static void SzFree(unused void *u, void *address) { free(address); } @@ -53,7 +53,7 @@ struct vector_t { static struct vector_t instream, outstream; -static SRes Read(void *unused, void *buf, size_t *size) +static SRes Read(unused void *u, void *buf, size_t *size) { if ((instream.size - instream.pos) < *size) *size = instream.size - instream.pos; @@ -62,7 +62,7 @@ static SRes Read(void *unused, void *buf, size_t *size) return SZ_OK; } -static size_t Write(void *unused, const void *buf, size_t size) +static size_t Write(unused void *u, const void *buf, size_t size) { if(outstream.size - outstream.pos < size) size = outstream.size - outstream.pos; |