From d0f61659238c3ed79fecf841c58cabedbf936ac8 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Wed, 5 Mar 2014 13:09:55 -0600 Subject: cbfstool: introduce struct parsed_elf and parse_elf() In order to make the ELF parsing more flexible introduce a parse_elf() function which takes a struct parsed_elf parameter. In addition take a flags parameter which instructs the ELF parser as to what data within the ELF file should be parsed. Change-Id: I3e30e84bf8043c3df96a6ab56cd077eef2632173 Signed-off-by: Aaron Durbin Reviewed-on: http://review.coreboot.org/5373 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones --- util/cbfstool/elfparsing.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'util/cbfstool/elfparsing.h') diff --git a/util/cbfstool/elfparsing.h b/util/cbfstool/elfparsing.h index 3cfa1cd6ba..4ad46b3928 100644 --- a/util/cbfstool/elfparsing.h +++ b/util/cbfstool/elfparsing.h @@ -22,6 +22,31 @@ struct buffer; +struct parsed_elf { + Elf64_Ehdr ehdr; + Elf64_Phdr *phdr; + Elf64_Shdr *shdr; +}; + +#define ELF_PARSE_PHDR (1 << 0) +#define ELF_PARSE_SHDR (1 << 1) + +#define ELF_PARSE_ALL (-1) + +/* + * Parse an ELF file contained within provide struct buffer. The ELF header + * is always parsed while the flags value containing the ELF_PARSE_* values + * determine if other parts of the ELF file will be parsed as well. + * Returns 0 on success, < 0 error. + */ +int parse_elf(const struct buffer *pinput, struct parsed_elf *pelf, int flags); + +/* + * Clean up memory associated with parsed_elf. + */ +void parsed_elf_destroy(struct parsed_elf *pelf); + + int elf_headers(const struct buffer *pinput, uint32_t arch, -- cgit v1.2.3