Ronald G. Minnich (rminnich@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5105
-gerrit
commit 5af94260490c8083c5b297e7990abd9bd61a9cbd Author: Alexandru Gagniuc mr.nuke.me@gmail.com Date: Sun Feb 2 22:37:28 2014 -0600
cbfstool: Eliminate global variable "arch"
Now that unused functions have been removed, the global "arch" is only used in very few places. We can pack "arch" in the "param" structure and pass it down to where it is actually used.
Change-Id: I255d1e2bc6b5ead91b6b4e94a0202523c4ab53dc Signed-off-by: Alexandru Gagniuc mr.nuke.me@gmail.com --- util/cbfstool/cbfs-mkpayload.c | 4 ++-- util/cbfstool/cbfs-mkstage.c | 4 ++-- util/cbfstool/cbfs.h | 1 + util/cbfstool/cbfstool.c | 19 ++++++++++------ util/cbfstool/common.c | 50 ------------------------------------------ util/cbfstool/common.h | 10 ++------- util/cbfstool/elfheaders.c | 1 + 7 files changed, 20 insertions(+), 69 deletions(-)
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c index b1dd1c0..6e6e418 100644 --- a/util/cbfstool/cbfs-mkpayload.c +++ b/util/cbfstool/cbfs-mkpayload.c @@ -51,7 +51,7 @@ static void xdr_segs(struct buffer *output, } } int parse_elf_to_payload(const struct buffer *input, - struct buffer *output, comp_algo algo) + struct buffer *output, uint32_t arch, comp_algo algo) { Elf64_Phdr *phdr; Elf64_Ehdr ehdr; @@ -69,7 +69,7 @@ int parse_elf_to_payload(const struct buffer *input, if (!compress) return -1;
- if (elf_headers(input, &ehdr, &phdr, &shdr) < 0) + if (elf_headers(input, arch, &ehdr, &phdr, &shdr) < 0) return -1;
DEBUG("start: parse_elf_to_payload\n"); diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index 6a5f6f7..233ec57 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -33,7 +33,7 @@ * works for all elf files, not just the restricted set. */ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, - comp_algo algo, uint32_t *location) + uint32_t arch, comp_algo algo, uint32_t *location) { Elf64_Phdr *phdr; Elf64_Ehdr ehdr; @@ -50,7 +50,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
DEBUG("start: parse_elf_to_stage(location=0x%x)\n", *location);
- if (elf_headers(input, &ehdr, &phdr, NULL) < 0) + if (elf_headers(input, arch, &ehdr, &phdr, NULL) < 0) return -1;
headers = ehdr.e_phnum; diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h index 585a26d..7a0c120 100644 --- a/util/cbfstool/cbfs.h +++ b/util/cbfstool/cbfs.h @@ -136,6 +136,7 @@ const char *strfiletype(uint32_t number); /* elfheaders.c */ int elf_headers(const struct buffer *pinput, + uint32_t arch, Elf64_Ehdr *ehdr, Elf64_Phdr **pphdr, Elf64_Shdr **pshdr); diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 9935f51..1d93981 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -56,6 +56,7 @@ static struct param { uint32_t pagesize; uint32_t offset; uint32_t top_aligned; + uint32_t arch; int fit_empty_entries; comp_algo algo; /* for linux payloads */ @@ -63,6 +64,7 @@ static struct param { char *cmdline; } param = { /* All variables not listed are initialized as zero. */ + .arch = CBFS_ARCHITECTURE_UNKNOWN, .algo = CBFS_COMPRESS_NONE, };
@@ -178,9 +180,13 @@ static int cbfs_add_component(const char *cbfs_name, return 0; }
-static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset) { +static int cbfstool_convert_mkstage(struct buffer *buffer, uint32_t *offset) +{ struct buffer output; - if (parse_elf_to_stage(buffer, &output, param.algo, offset) != 0) + int ret; + ret = parse_elf_to_stage(buffer, &output, param.arch, param.algo, + offset); + if (ret != 0) return -1; buffer_delete(buffer); // direct assign, no dupe. @@ -192,7 +198,7 @@ static int cbfstool_convert_mkpayload(struct buffer *buffer, uint32_t *offset) { struct buffer output; int ret; /* per default, try and see if payload is an ELF binary */ - ret = parse_elf_to_payload(buffer, &output, param.algo); + ret = parse_elf_to_payload(buffer, &output, param.arch, param.algo);
/* If it's not an ELF, see if it's a UEFI FV */ if (ret != 0) @@ -334,8 +340,7 @@ static int cbfs_create(void) return 1; }
- // TODO Remove arch or pack into param. - if (arch == CBFS_ARCHITECTURE_UNKNOWN) { + if (param.arch == CBFS_ARCHITECTURE_UNKNOWN) { ERROR("You need to specify -m/--machine arch.\n"); return 1; } @@ -368,7 +373,7 @@ static int cbfs_create(void) }
if (cbfs_image_create(&image, - arch, + param.arch, param.size, param.alignment, &bootblock, @@ -701,7 +706,7 @@ int main(int argc, char **argv) verbose++; break; case 'm': - arch = string_to_arch(optarg); + param.arch = string_to_arch(optarg); break; case 'I': param.initrd = optarg; diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index e10d9fb..f697a03 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -103,56 +103,6 @@ void buffer_delete(struct buffer *buffer) { buffer->size = 0; }
-size_t getfilesize(const char *filename) -{ - size_t size; - FILE *file = fopen(filename, "rb"); - if (file == NULL) - return -1; - - fseek(file, 0, SEEK_END); - size = ftell(file); - fclose(file); - return size; -} - -void *loadfile(const char *filename, uint32_t * romsize_p, void *content, - int place) -{ - FILE *file = fopen(filename, "rb"); - if (file == NULL) - return NULL; - - fseek(file, 0, SEEK_END); - *romsize_p = ftell(file); - fseek(file, 0, SEEK_SET); - if (!content) { - content = malloc(*romsize_p); - if (!content) { - ERROR("Could not get %d bytes for file %s\n", - *romsize_p, filename); - exit(1); - } - } else if (place == SEEK_END) - content -= *romsize_p; - - if (!fread(content, *romsize_p, 1, file)) { - ERROR("Failed to read %s\n", filename); - return NULL; - } - fclose(file); - return content; -} - -/* N.B.: there are declarations here that were shadowed in functions. - * Hence the rather clumsy cbfstool_ prefixes. - */ -static struct cbfs_header *cbfstool_master_header; -static uint32_t phys_start, phys_end, align; -uint32_t romsize; -void *cbfstool_offset; -uint32_t arch = CBFS_ARCHITECTURE_UNKNOWN; - static struct { uint32_t arch; const char *name; diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index e41618f..36aa995 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -62,12 +62,6 @@ int buffer_write_file(struct buffer *buffer, const char *filename); /* Destroys a memory buffer. */ void buffer_delete(struct buffer *buffer);
-extern void *cbfstool_offset; -extern uint32_t romsize; -extern int host_bigendian; -extern uint32_t arch; - -const char *arch_to_string(uint32_t a); uint32_t string_to_arch(const char *arch_string);
static inline void *phys_to_virt(uint32_t addr) @@ -99,7 +93,7 @@ uint64_t intfiletype(const char *name);
/* cbfs-mkpayload.c */ int parse_elf_to_payload(const struct buffer *input, - struct buffer *output, comp_algo algo); + struct buffer *output, uint32_t arch, 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, @@ -112,7 +106,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, - comp_algo algo, uint32_t *location); + uint32_t arch, comp_algo algo, uint32_t *location);
void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize, uint32_t type, uint32_t * location); diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c index fd7a1a1..0d874a1 100644 --- a/util/cbfstool/elfheaders.c +++ b/util/cbfstool/elfheaders.c @@ -241,6 +241,7 @@ elf_shdr(struct buffer *pinput, Elf64_Shdr *shdr, */ int elf_headers(const struct buffer *pinput, + uint32_t arch, Elf64_Ehdr *ehdr, Elf64_Phdr **pphdr, Elf64_Shdr **pshdr)