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>
diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile
index 4f282f9..05a96ee 100644
--- a/util/cbfstool/Makefile
+++ b/util/cbfstool/Makefile
@@ -4,8 +4,7 @@
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 f7cd39a..e5011d6 100644
--- a/util/cbfstool/cbfs.h
+++ b/util/cbfstool/cbfs.h
@@ -125,7 +125,6 @@
#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 6775b06..6b0ed59 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -69,16 +69,6 @@
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 @@
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 @@
}
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 @@
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 41df157..80331e7 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -118,7 +118,8 @@
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 @@
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_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 bd9cdc0..6ac39ef 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -53,7 +53,8 @@
}
/* 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 @@
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 @@
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 @@
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 41659a2..02a1076 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 @@
#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 @@
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 @@
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 @@
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 @@
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 abd1bfd..0944b1f 100644
--- a/util/cbfstool/lzma/lzma.c
+++ b/util/cbfstool/lzma/lzma.c
@@ -31,12 +31,12 @@
/* 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 @@
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 @@
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;