Furquan Shaikh (furquan@google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7303
-gerrit
commit df2b6ae446bce1c46b66aef3ea94b9c2b3027178 Author: Furquan Shaikh furquan@google.com Date: Thu Oct 30 11:28:27 2014 -0700
cbfstool: Convert cbfs-mkstage.c into pelf
Change cbfs-mkstage to use parsed elf instead of calling elf_headers. That allows us to have access to the complete elf including the string table.
Change-Id: Ie767d28bdf41af38d1df0bce54bc0ada45123136 Signed-off-by: Furquan Shaikh furquan@google.com --- util/cbfstool/cbfs-mkstage.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c index 4a2f4d8..3da0836 100644 --- a/util/cbfstool/cbfs-mkstage.c +++ b/util/cbfstool/cbfs-mkstage.c @@ -35,10 +35,12 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, uint32_t arch, comp_algo algo, uint32_t *location) { + struct parsed_elf pelf; Elf64_Phdr *phdr; - Elf64_Ehdr ehdr; + Elf64_Ehdr *ehdr; char *buffer; struct buffer outheader; + int ret = -1;
int headers; int i, outlen; @@ -50,10 +52,17 @@ 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, arch, &ehdr, &phdr, NULL) < 0) + int flags = ELF_PARSE_PHDR | ELF_PARSE_SHDR | ELF_PARSE_STRTAB; + + if (parse_elf(input, &pelf, flags)) { + ERROR("Couldn't parse ELF\n"); return -1; + } + + ehdr = &pelf.ehdr; + phdr = &pelf.phdr[0];
- headers = ehdr.e_phnum; + headers = ehdr->e_phnum;
data_start = ~0; data_end = 0; @@ -102,7 +111,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output,
if (buffer == NULL) { ERROR("Unable to allocate memory: %m\n"); - return -1; + goto err; }
/* Copy the file data into the buffer */ @@ -135,7 +144,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, "File has %zu bytes left, segment end is %zu\n", input->size, (size_t)(phdr[i].p_offset + phdr[i].p_filesz)); free(buffer); - return -1; + goto err; } memcpy(buffer + (l_start - data_start), &input->data[phdr[i].p_offset + l_offset], @@ -147,7 +156,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, input->name) != 0) { ERROR("Unable to allocate memory: %m\n"); free(buffer); - return -1; + goto err; } memset(output->data, 0, output->size);
@@ -177,7 +186,7 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, * Maybe we should just change the spec. */ xdr_le.put32(&outheader, algo); - xdr_le.put64(&outheader, ehdr.e_entry); + xdr_le.put64(&outheader, ehdr->e_entry); xdr_le.put64(&outheader, data_start); xdr_le.put32(&outheader, outlen); xdr_le.put32(&outheader, mem_end - data_start); @@ -185,5 +194,9 @@ int parse_elf_to_stage(const struct buffer *input, struct buffer *output, if (*location) *location -= sizeof(struct cbfs_stage); output->size = sizeof(struct cbfs_stage) + outlen; - return 0; + ret = 0; + +err: + parsed_elf_destroy(&pelf); + return ret; }