aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorSol Boucher <solb@chromium.org>2015-03-05 15:38:03 -0800
committerPatrick Georgi <pgeorgi@google.com>2015-04-25 12:14:25 +0200
commit0e53931fee0178c4f4ac4e2e6b355b103b5e8c42 (patch)
treef38674ea0f24986093c5852115966fa27db2130a /util
parentc13ad6c6df709fda1d70743a860a406643620b9e (diff)
downloadcoreboot-0e53931fee0178c4f4ac4e2e6b355b103b5e8c42.tar.gz
coreboot-0e53931fee0178c4f4ac4e2e6b355b103b5e8c42.tar.xz
coreboot-0e53931fee0178c4f4ac4e2e6b355b103b5e8c42.zip
cbfstool: Clean up in preparation for adding new files
This enables more warnings on the cbfstool codebase and fixes the issues that surface as a result. A memory leak that used to occur when compressing files with lzma is also found and fixed. Finally, there are several fixes for the Makefile: - Its autodependencies used to be broken because the target for the .dependencies file was misnamed; this meant that Make didn't know how to rebuild the file, and so would silently skip the step of updating it before including it. - The ability to build to a custom output directory by defining the obj variable had bitrotted. - The default value of the obj variable was causing implicit rules not to apply when specifying a file as a target without providing a custom value for obj. - Add a distclean target for removing the .dependencies file. BUG=chromium:461875 TEST=Build an image with cbfstool both before and after. BRANCH=None Change-Id: I951919d63443f2b053c2e67c1ac9872abc0a43ca Signed-off-by: Sol Boucher <solb@chromium.org> Original-Commit-Id: 49293443b4e565ca48d284e9a66f80c9c213975d Original-Change-Id: Ia7350c2c3306905984cfa711d5fc4631f0b43d5b Original-Signed-off-by: Sol Boucher <solb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/257340 Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Original-Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Reviewed-on: http://review.coreboot.org/9937 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/Makefile55
-rw-r--r--util/cbfstool/Makefile.inc20
-rw-r--r--util/cbfstool/cbfs-mkpayload.c12
-rw-r--r--util/cbfstool/cbfs-mkstage.c4
-rw-r--r--util/cbfstool/cbfs_image.c30
-rw-r--r--util/cbfstool/cbfs_image.h8
-rw-r--r--util/cbfstool/cbfstool.c18
-rw-r--r--util/cbfstool/common.c5
-rw-r--r--util/cbfstool/common.h24
-rw-r--r--util/cbfstool/elfheaders.c2
-rw-r--r--util/cbfstool/elfparsing.h1
-rw-r--r--util/cbfstool/fit.c2
-rw-r--r--util/cbfstool/lzma/lzma.c1
-rw-r--r--util/cbfstool/rmodule.c28
14 files changed, 121 insertions, 89 deletions
diff --git a/util/cbfstool/Makefile b/util/cbfstool/Makefile
index 05a96ee90..258fba3ec 100644
--- a/util/cbfstool/Makefile
+++ b/util/cbfstool/Makefile
@@ -1,50 +1,61 @@
-obj ?= $(shell pwd)
+obj ?= .
HOSTCC ?= $(CC)
-CFLAGS ?= -g
-CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
-CFLAGS += -Wstrict-aliasing -Wshadow -Werror
-CBFSTOOL_BINARY:=$(obj)/cbfstool
+CFLAGS += -Og -g3
+CFLAGS += -std=c99 -Werror -Wall -Wextra
+CFLAGS += -Wcast-qual -Wmissing-prototypes -Wredundant-decls -Wshadow
+CFLAGS += -Wstrict-prototypes -Wwrite-strings
+CPPFLAGS += -D_POSIX_C_SOURCE=200809L # strdup() from string.h
+LINKFLAGS += -g3
-CBFSTOOL_COMMON:=cbfstool.o common.o cbfs_image.o compress.o fit.o
+CBFSTOOL_BINARY:=$(obj)/cbfstool
+CBFSTOOL_COMMON:=common.o cbfs_image.o compress.o fit.o
CBFSTOOL_COMMON+=elfheaders.o cbfs-mkstage.o cbfs-mkpayload.o xdr.o
+CBFSTOOL_COMMON+=linux_trampoline.o cbfs-payload-linux.o
# LZMA
CBFSTOOL_COMMON+=lzma/lzma.o
CBFSTOOL_COMMON+=lzma/C/LzFind.o lzma/C/LzmaDec.o lzma/C/LzmaEnc.o
-CBFSTOOL_COMMON+=linux_trampoline.o cbfs-payload-linux.o
-
CBFSTOOL_COMMON:=$(addprefix $(obj)/,$(CBFSTOOL_COMMON))
RMODTOOL_BINARY:=$(obj)/rmodtool
-RMODTOOL_COMMON:=rmodtool.o rmodule.o common.o elfheaders.o xdr.o
+RMODTOOL_COMMON:=rmodule.o common.o elfheaders.o xdr.o
RMODTOOL_COMMON:=$(addprefix $(obj)/,$(RMODTOOL_COMMON))
-all: dep $(CBFSTOOL_BINARY) $(RMODTOOL_BINARY)
+.PHONY: all
+all: .dependencies $(CBFSTOOL_BINARY) $(RMODTOOL_BINARY)
+$(obj)/%: $(obj)/%.o
+ mkdir -p $(dir $@)
+ $(HOSTCC) $(LINKFLAGS) -o $@ $^ $(LDLIBS)
$(obj)/%.o: %.c
- $(HOSTCC) $(CFLAGS) -c -o $@ $<
+ mkdir -p $(dir $@)
+ $(HOSTCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+.PHONY: clean
clean:
- rm -f $(CBFSTOOL_COMMON) $(CBFSTOOL_BINARY)
- rm -f $(RMODTOOL_COMMON) $(RMODTOOL_BINARY)
+ $(RM) $(CBFSTOOL_COMMON) $(CBFSTOOL_BINARY).o $(CBFSTOOL_BINARY)
+ $(RM) $(RMODTOOL_COMMON) $(RMODTOOL_BINARY).o $(RMODTOOL_BINARY)
+.PHONY: distclean
+distclean: clean
+ $(RM) .dependencies
tags:
ctags *.[ch]
-$(obj)/cbfstool:$(CBFSTOOL_COMMON)
- $(HOSTCC) $(CFLAGS) -o $@ $^
+.dependencies:
+ @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM -MG *.c > $@
+ @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/*.c >> $@
+ @$(HOSTCC) $(CPPFLAGS) $(CFLAGS) -MM lzma/C/*.c >> $@
+ @sed -i 's|.*:.*|$$(obj)/&|' $@
-$(obj)/rmodtool:$(RMODTOOL_COMMON)
- $(HOSTCC) $(CFLAGS) -o $@ $^
+$(CBFSTOOL_BINARY): $(CBFSTOOL_COMMON)
+$(RMODTOOL_BINARY): $(RMODTOOL_COMMON)
-dep:
- @$(HOSTCC) $(CFLAGS) -MM *.c > .dependencies
- @$(HOSTCC) $(CFLAGS) -MM lzma/*.c >> .dependencies
- @$(HOSTCC) $(CFLAGS) -MM lzma/C/*.c >> .dependencies
+# Tolerate lzma sdk warnings
+$(obj)/lzma/C/LzmaEnc.o: CFLAGS += -Wno-sign-compare -Wno-cast-qual
-include .dependencies
diff --git a/util/cbfstool/Makefile.inc b/util/cbfstool/Makefile.inc
index 410d96c70..a846e9959 100644
--- a/util/cbfstool/Makefile.inc
+++ b/util/cbfstool/Makefile.inc
@@ -17,32 +17,42 @@ cbfsobj += LzmaEnc.o
cbfsobj += linux_trampoline.o
cbfsobj += cbfs-payload-linux.o
+rmodobj :=
rmodobj += rmodtool.o
rmodobj += rmodule.o
rmodobj += common.o
rmodobj += elfheaders.o
rmodobj += xdr.o
+TOOLCFLAGS ?= -std=c99 -Werror -Wall -Wextra
+TOOLCFLAGS += -Wcast-qual -Wmissing-prototypes -Wredundant-decls -Wshadow
+TOOLCFLAGS += -Wstrict-prototypes -Wwrite-strings
+TOOLCPPFLAGS ?= -D_POSIX_C_SOURCE=200809L # strdup() from string.h
+TOOLLINKFLAGS ?=
+
ifeq ($(shell uname -s | cut -c-7 2>/dev/null), MINGW32)
TOOLFLAGS+=-mno-ms-bitfields
endif
$(objutil)/cbfstool/%.o: $(top)/util/cbfstool/%.c
printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
- $(HOSTCC) $(TOOLFLAGS) $(HOSTCFLAGS) -c -o $@ $<
+ $(HOSTCC) $(TOOLCPPFLAGS) $(TOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $<
$(objutil)/cbfstool/%.o: $(top)/util/cbfstool/lzma/%.c
printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
- $(HOSTCC) $(TOOLFLAGS) $(HOSTCFLAGS) -c -o $@ $<
+ $(HOSTCC) $(TOOLCPPFLAGS) $(TOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $<
$(objutil)/cbfstool/%.o: $(top)/util/cbfstool/lzma/C/%.c
printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
- $(HOSTCC) $(TOOLFLAGS) $(HOSTCFLAGS) -c -o $@ $<
+ $(HOSTCC) $(TOOLCPPFLAGS) $(TOOLCFLAGS) $(HOSTCFLAGS) -c -o $@ $<
$(objutil)/cbfstool/cbfstool: $(addprefix $(objutil)/cbfstool/,$(cbfsobj))
printf " HOSTCC $(subst $(objutil)/,,$(@)) (link)\n"
- $(HOSTCC) $(TOOLFLAGS) -o $@ $(addprefix $(objutil)/cbfstool/,$(cbfsobj))
+ $(HOSTCC) $(TOOLLINKFLAGS) -o $@ $(addprefix $(objutil)/cbfstool/,$(cbfsobj))
$(objutil)/cbfstool/rmodtool: $(addprefix $(objutil)/cbfstool/,$(rmodobj))
printf " HOSTCC $(subst $(objutil)/,,$(@)) (link)\n"
- $(HOSTCC) $(TOOLFLAGS) -o $@ $(addprefix $(objutil)/cbfstool/,$(rmodobj))
+ $(HOSTCC) $(TOOLLINKFLAGS) -o $@ $(addprefix $(objutil)/cbfstool/,$(rmodobj))
+
+# Tolerate lzma sdk warnings
+$(objutil)/cbfstool/LzmaEnc.o: TOOLCFLAGS += -Wno-sign-compare -Wno-cast-qual
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c
index d5bcca011..6eebbef9d 100644
--- a/util/cbfstool/cbfs-mkpayload.c
+++ b/util/cbfstool/cbfs-mkpayload.c
@@ -67,8 +67,8 @@ void xdr_get_seg(struct cbfs_payload_segment *out,
out->mem_len = xdr_be.get32(&inheader);
}
-int parse_elf_to_payload(const struct buffer *input,
- struct buffer *output, uint32_t arch, comp_algo algo)
+int parse_elf_to_payload(const struct buffer *input, struct buffer *output,
+ comp_algo algo)
{
Elf64_Phdr *phdr;
Elf64_Ehdr ehdr;
@@ -87,7 +87,7 @@ int parse_elf_to_payload(const struct buffer *input,
if (!compress)
return -1;
- if (elf_headers(input, arch, &ehdr, &phdr, &shdr) < 0)
+ if (elf_headers(input, &ehdr, &phdr, &shdr) < 0)
return -1;
DEBUG("start: parse_elf_to_payload\n");
@@ -325,7 +325,7 @@ int parse_fv_to_payload(const struct buffer *input,
while (fh->file_type == FILETYPE_PAD) {
unsigned long offset = (fh->size[2] << 16) | (fh->size[1] << 8) | fh->size[0];
ERROR("skipping %lu bytes of FV padding\n", offset);
- fh = (ffs_file_header_t *)(((void*)fh) + offset);
+ fh = (ffs_file_header_t *)(((uintptr_t)fh) + offset);
}
if (fh->file_type != FILETYPE_SEC) {
ERROR("Not a usable UEFI firmware volume.\n");
@@ -337,7 +337,7 @@ int parse_fv_to_payload(const struct buffer *input,
while (cs->section_type == SECTION_RAW) {
unsigned long offset = (cs->size[2] << 16) | (cs->size[1] << 8) | cs->size[0];
ERROR("skipping %lu bytes of section padding\n", offset);
- cs = (common_section_header_t *)(((void*)cs) + offset);
+ cs = (common_section_header_t *)(((uintptr_t)cs) + offset);
}
if (cs->section_type != SECTION_PE32) {
ERROR("Not a usable UEFI firmware volume.\n");
@@ -355,7 +355,7 @@ int parse_fv_to_payload(const struct buffer *input,
dh_offset = (unsigned long)dh - (unsigned long)input->data;
DEBUG("dos header offset = %x\n", dh_offset);
- ch = (coff_header_t *)(((void *)dh)+dh->e_lfanew);
+ ch = (coff_header_t *)(((uintptr_t)dh)+dh->e_lfanew);
if (ch->machine == MACHINE_TYPE_X86) {
pe_opt_header_32_t *ph;
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index 135a6e771..f8a39bc50 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -95,7 +95,7 @@ static Elf64_Shdr *find_ignored_section_header(struct parsed_elf *pelf,
* works for all elf files, not just the restricted set.
*/
int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
- uint32_t arch, comp_algo algo, uint32_t *location,
+ comp_algo algo, uint32_t *location,
const char *ignore_section)
{
struct parsed_elf pelf;
@@ -245,7 +245,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
*/
if (compress(buffer, data_end - data_start,
(output->data + sizeof(struct cbfs_stage)),
- &outlen) < 0 || outlen > data_end - data_start) {
+ &outlen) < 0 || (unsigned)outlen > data_end - data_start) {
WARN("Compression failed or would make the data bigger "
"- disabled.\n");
memcpy(output->data + sizeof(struct cbfs_stage),
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index e3f3e4eec..b64f78e14 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include "common.h"
#include "cbfs_image.h"
@@ -83,7 +84,7 @@ static const char *get_cbfs_entry_type_name(uint32_t type)
/* CBFS image */
-static int cbfs_calculate_file_header_size(const char *name)
+static size_t cbfs_calculate_file_header_size(const char *name)
{
return (sizeof(struct cbfs_file) +
align_up(strlen(name) + 1, CBFS_FILENAME_ALIGN));
@@ -146,11 +147,11 @@ static void cbfs_decode_payload_segment(struct cbfs_payload_segment *output,
assert(seg.size == 0);
}
-void cbfs_get_header(struct cbfs_header *header, const void *src)
+void cbfs_get_header(struct cbfs_header *header, void *src)
{
struct buffer outheader;
- outheader.data = (void *)src; /* We're not modifying the data */
+ outheader.data = src; /* We're not modifying the data */
outheader.size = 0;
header->magic = xdr_be.get32(&outheader);
@@ -167,9 +168,9 @@ int cbfs_image_create(struct cbfs_image *image,
size_t size,
uint32_t align,
struct buffer *bootblock,
- int32_t bootblock_offset,
- int32_t header_offset,
- int32_t entries_offset)
+ uint32_t bootblock_offset,
+ uint32_t header_offset,
+ uint32_t entries_offset)
{
struct cbfs_header header;
struct cbfs_file *entry;
@@ -191,11 +192,11 @@ int cbfs_image_create(struct cbfs_image *image,
// Adjust legcay top-aligned address to ROM offset.
if (IS_TOP_ALIGNED_ADDRESS(entries_offset))
- entries_offset += (int32_t)size;
+ entries_offset = size + (int32_t)entries_offset;
if (IS_TOP_ALIGNED_ADDRESS(bootblock_offset))
- bootblock_offset += (int32_t)size;
+ bootblock_offset = size + (int32_t)bootblock_offset;
if (IS_TOP_ALIGNED_ADDRESS(header_offset))
- header_offset += (int32_t) size;
+ header_offset = size + (int32_t)header_offset;
DEBUG("cbfs_create_image: (real offset) bootblock=0x%x, "
"header=0x%x, entries_offset=0x%x\n",
@@ -358,7 +359,8 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset,
dst_entry = (struct cbfs_file *)(
(uintptr_t)dst_entry + align_up(entry_size, align));
- if (((char *)dst_entry - image->buffer.data) >= copy_end) {
+ if ((size_t)((char *)dst_entry - image->buffer.data) >=
+ copy_end) {
ERROR("Ran out of room in copy region.\n");
return 1;
}
@@ -486,7 +488,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
uint32_t theromsize = image->header->romsize;
INFO("Converting top-aligned address 0x%x to offset: 0x%x\n",
content_offset, content_offset + theromsize);
- content_offset += theromsize;
+ content_offset = theromsize + (int32_t)content_offset;
}
// Merge empty entries.
@@ -614,12 +616,14 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
buffer.data = CBFS_SUBHEADER(entry);
buffer.size = ntohl(entry->len);
- buffer.name = (char *)"(cbfs_export_entry)";
+ buffer.name = strdup("(cbfs_export_entry)");
if (buffer_write_file(&buffer, filename) != 0) {
ERROR("Failed to write %s into %s.\n",
entry_name, filename);
+ free(buffer.name);
return -1;
}
+ free(buffer.name);
INFO("Successfully dumped the file to: %s\n", filename);
return 0;
}
@@ -793,7 +797,7 @@ int cbfs_print_directory(struct cbfs_image *image)
}
int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
- void *arg)
+ unused void *arg)
{
struct cbfs_file *next;
uint32_t type, addr, last_addr;
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 55ce0289b..1c2b6fd56 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -35,7 +35,7 @@ struct cbfs_image {
* to cbfs format, i.e. big-endian. */
void cbfs_put_header(void *dest, const struct cbfs_header *header);
/* Or deserialize into host-native format */
-void cbfs_get_header(struct cbfs_header *header, const void *src);
+void cbfs_get_header(struct cbfs_header *header, void *src);
/* Creates an empty CBFS image by given size, and description to its content
* (bootblock, align, header location, starting offset of CBFS entries.
@@ -47,9 +47,9 @@ int cbfs_image_create(struct cbfs_image *image,
size_t size,
uint32_t align,
struct buffer *bootblock,
- int32_t bootblock_offset,
- int32_t header_offset,
- int32_t entries_offset);
+ uint32_t bootblock_offset,
+ uint32_t header_offset,
+ uint32_t entries_offset);
/* Loads a CBFS image from file. Returns 0 on success, otherwise non-zero. */
int cbfs_image_from_file(struct cbfs_image *image,
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 3554cfa2b..db521d67f 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
@@ -104,8 +105,10 @@ static int cbfs_add_integer_component(const char *cbfs_name,
goto done;
}
- if (cbfs_add_entry(&image, &buffer, name, CBFS_COMPONENT_RAW, param.baseaddress) != 0) {
- ERROR("Failed to add %llu into ROM image as '%s'.\n", (long long unsigned)u64val, name);
+ if (cbfs_add_entry(&image, &buffer, name, CBFS_COMPONENT_RAW, offset) !=
+ 0) {
+ ERROR("Failed to add %llu into ROM image as '%s'.\n",
+ (long long unsigned)u64val, name);
goto done;
}
@@ -189,8 +192,8 @@ static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset)
{
struct buffer output;
int ret;
- ret = parse_elf_to_stage(buffer, &output, param.arch, param.algo,
- offset, param.ignore_section);
+ ret = parse_elf_to_stage(buffer, &output, param.algo, offset,
+ param.ignore_section);
if (ret != 0)
return -1;
buffer_delete(buffer);
@@ -205,7 +208,7 @@ static int cbfstool_convert_mkpayload(struct buffer *buffer,
struct buffer output;
int ret;
/* per default, try and see if payload is an ELF binary */
- ret = parse_elf_to_payload(buffer, &output, param.arch, param.algo);
+ ret = parse_elf_to_payload(buffer, &output, param.algo);
/* If it's not an ELF, see if it's a UEFI FV */
if (ret != 0)
@@ -641,6 +644,11 @@ static void usage(char *name)
" update-fit -n MICROCODE_BLOB_NAME -x EMTPY_FIT_ENTRIES\n "
"Updates the FIT table with microcode entries\n"
"\n"
+ "OFFSETs:\n"
+ " Numbers accompanying -b, -H, and -o switches may be provided\n"
+ " in two possible formats: if their value is greater than\n"
+ " 0x80000000, they are interpreted as a top-aligned x86 memory\n"
+ " address; otherwise, they are treated as an offset into flash.\n"
"ARCHes:\n"
" arm64, arm, mips, x86\n"
"TYPEs:\n", name, name
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 9923ca344..e8c2ccc45 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -36,7 +37,7 @@ int verbose = 0;
int is_big_endian(void)
{
static const uint32_t inttest = 0x12345678;
- uint8_t inttest_lsb = *(uint8_t *)&inttest;
+ const uint8_t inttest_lsb = *(const uint8_t *)&inttest;
if (inttest_lsb == 0x12) {
return 1;
}
@@ -73,7 +74,7 @@ int buffer_from_file(struct buffer *buffer, const char *filename)
return -1;
}
buffer->size = get_file_size(fp);
- if (buffer->size == -1) {
+ if (buffer->size == -1u) {
fprintf(stderr, "could not determine size of %s\n", filename);
fclose(fp);
return -1;
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index 0284742cb..80d5789f0 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -26,20 +26,20 @@
/* Endianess */
#include "swab.h"
#ifndef __APPLE__
-#define ntohl(x) (is_big_endian() ? (x) : swab32(x))
-#define htonl(x) (is_big_endian() ? (x) : swab32(x))
+#define ntohl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
+#define htonl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
#endif
-#define ntohll(x) (is_big_endian() ? (x) : swab64(x))
-#define htonll(x) (is_big_endian() ? (x) : swab64(x))
+#define ntohll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
+#define htonll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
int is_big_endian(void);
/* Message output */
extern int verbose;
-#define ERROR(x...) { fprintf(stderr, "E: " x); }
-#define WARN(x...) { fprintf(stderr, "W: " x); }
-#define LOG(x...) { fprintf(stderr, x); }
-#define INFO(x...) { if (verbose > 0) fprintf(stderr, "INFO: " x); }
-#define DEBUG(x...) { if (verbose > 1) fprintf(stderr, "DEBUG: " x); }
+#define ERROR(...) { fprintf(stderr, "E: " __VA_ARGS__); }
+#define WARN(...) { fprintf(stderr, "W: " __VA_ARGS__); }
+#define LOG(...) { fprintf(stderr, __VA_ARGS__); }
+#define INFO(...) { if (verbose > 0) fprintf(stderr, "INFO: " __VA_ARGS__); }
+#define DEBUG(...) { if (verbose > 1) fprintf(stderr, "DEBUG: " __VA_ARGS__); }
/* Helpers */
#define ARRAY_SIZE(a) (int)(sizeof(a) / sizeof((a)[0]))
@@ -135,8 +135,8 @@ comp_func_ptr compression_function(comp_algo algo);
uint64_t intfiletype(const char *name);
/* cbfs-mkpayload.c */
-int parse_elf_to_payload(const struct buffer *input,
- struct buffer *output, uint32_t arch, comp_algo algo);
+int parse_elf_to_payload(const struct buffer *input, struct buffer *output,
+ comp_algo algo);
int parse_fv_to_payload(const struct buffer *input,
struct buffer *output, comp_algo algo);
int parse_bzImage_to_payload(const struct buffer *input,
@@ -149,7 +149,7 @@ int parse_flat_binary_to_payload(const struct buffer *input,
comp_algo algo);
/* cbfs-mkstage.c */
int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
- uint32_t arch, comp_algo algo, uint32_t *location,
+ comp_algo algo, uint32_t *location,
const char *ignore_section);
void print_supported_filetypes(void);
diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index 98a06c5b0..7dc5e6568 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -588,12 +588,10 @@ void parsed_elf_destroy(struct parsed_elf *pelf)
*/
int
elf_headers(const struct buffer *pinput,
- uint32_t arch,
Elf64_Ehdr *ehdr,
Elf64_Phdr **pphdr,
Elf64_Shdr **pshdr)
{
-
struct parsed_elf pelf;
int flags;
diff --git a/util/cbfstool/elfparsing.h b/util/cbfstool/elfparsing.h
index 048d31aa2..0db1c595a 100644
--- a/util/cbfstool/elfparsing.h
+++ b/util/cbfstool/elfparsing.h
@@ -69,7 +69,6 @@ void parsed_elf_destroy(struct parsed_elf *pelf);
int
elf_headers(const struct buffer *pinput,
- uint32_t arch,
Elf64_Ehdr *ehdr,
Elf64_Phdr **pphdr,
Elf64_Shdr **pshdr);
diff --git a/util/cbfstool/fit.c b/util/cbfstool/fit.c
index 065212931..7dbfc51bc 100644
--- a/util/cbfstool/fit.c
+++ b/util/cbfstool/fit.c
@@ -48,7 +48,7 @@ struct fit_entry {
struct fit_table {
struct fit_entry header;
- struct fit_entry entries[0];
+ struct fit_entry entries[];
} __attribute__ ((packed));
struct microcode_header {
diff --git a/util/cbfstool/lzma/lzma.c b/util/cbfstool/lzma/lzma.c
index 0944b1ff0..856932d22 100644
--- a/util/cbfstool/lzma/lzma.c
+++ b/util/cbfstool/lzma/lzma.c
@@ -142,6 +142,7 @@ int do_lzma_compress(char *in, int in_len, char *out, int *out_len)
Write(&os, propsEncoded, LZMA_PROPS_SIZE+8);
res = LzmaEnc_Encode(p, &os, &is, 0, &LZMAalloc, &LZMAalloc);
+ LzmaEnc_Destroy(p, &LZMAalloc, &LZMAalloc);
if (res != SZ_OK) {
ERROR("LZMA: LzmaEnc_Encode failed %d.\n", res);
return -1;
diff --git a/util/cbfstool/rmodule.c b/util/cbfstool/rmodule.c
index 23eb25f58..fa175db78 100644
--- a/util/cbfstool/rmodule.c
+++ b/util/cbfstool/rmodule.c
@@ -15,6 +15,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,9 +29,9 @@ struct rmod_context;
struct arch_ops {
int arch;
/* Determine if relocation is a valid type for the architecture. */
- int (*valid_type)(struct rmod_context *ctx, Elf64_Rela *rel);
+ int (*valid_type)(Elf64_Rela *rel);
/* Determine if relocation should be emitted. */
- int (*should_emit)(struct rmod_context *ctx, Elf64_Rela *rel);
+ int (*should_emit)(Elf64_Rela *rel);
};
struct rmod_context {
@@ -62,7 +63,7 @@ struct rmod_context {
/*
* Architecture specific support operations.
*/
-static int valid_reloc_386(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_386(Elf64_Rela *rel)
{
int type;
@@ -72,7 +73,7 @@ static int valid_reloc_386(struct rmod_context *ctx, Elf64_Rela *rel)
return (type == R_386_32 || type == R_386_PC32);
}
-static int should_emit_386(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_386(Elf64_Rela *rel)
{
int type;
@@ -82,7 +83,7 @@ static int should_emit_386(struct rmod_context *ctx, Elf64_Rela *rel)
return (type == R_386_32);
}
-static int valid_reloc_arm(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_arm(Elf64_Rela *rel)
{
int type;
@@ -94,7 +95,7 @@ static int valid_reloc_arm(struct rmod_context *ctx, Elf64_Rela *rel)
type == R_ARM_CALL || type == R_ARM_JUMP24);
}
-static int should_emit_arm(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_arm(Elf64_Rela *rel)
{
int type;
@@ -104,7 +105,7 @@ static int should_emit_arm(struct rmod_context *ctx, Elf64_Rela *rel)
return (type == R_ARM_ABS32);
}
-static int valid_reloc_aarch64(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_aarch64(Elf64_Rela *rel)
{
int type;
@@ -122,7 +123,7 @@ static int valid_reloc_aarch64(struct rmod_context *ctx, Elf64_Rela *rel)
type == R_AARCH64_ADR_PREL_LO21);
}
-static int should_emit_aarch64(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_aarch64(Elf64_Rela *rel)
{
int type;
@@ -176,13 +177,13 @@ static int for_each_reloc(struct rmod_context *ctx, int do_emit)
for (j = 0; j < nrelocs; j++) {
Elf64_Rela *r = &relocs[j];
- if (!ctx->ops->valid_type(ctx, r)) {
+ if (!ctx->ops->valid_type(r)) {
ERROR("Invalid reloc type: %u\n",
(unsigned int)ELF64_R_TYPE(r->r_info));
return -1;
}
- if (ctx->ops->should_emit(ctx, r)) {
+ if (ctx->ops->should_emit(r)) {
int n = ctx->nrelocs;
if (do_emit)
ctx->emitted_relocs[n] = r->r_offset;
@@ -306,7 +307,7 @@ static int vaddr_cmp(const void *a, const void *b)
static int collect_relocations(struct rmod_context *ctx)
{
- int nrelocs;
+ Elf64_Xword nrelocs;
/*
* The relocs array in the pelf should only contain relocations that
@@ -317,7 +318,7 @@ static int collect_relocations(struct rmod_context *ctx)
return -1;
nrelocs = ctx->nrelocs;
- INFO("%d relocations to be emitted.\n", nrelocs);
+ INFO("%" PRIu64 " relocations to be emitted.\n", nrelocs);
if (!nrelocs)
return 0;
@@ -457,7 +458,6 @@ static int
write_elf(const struct rmod_context *ctx, const struct buffer *in,
struct buffer *out)
{
- int i;
int ret;
int bit64;
size_t loc;
@@ -556,7 +556,7 @@ write_elf(const struct rmod_context *ctx, const struct buffer *in,
ctx->xdr->put32(&rmod_header, 0);
/* Write the relocations. */
- for (i = 0; i < ctx->nrelocs; i++) {
+ for (unsigned i = 0; i < ctx->nrelocs; i++) {
if (bit64)
ctx->xdr->put64(&relocs, ctx->emitted_relocs[i]);
else