summaryrefslogtreecommitdiff
path: root/util/cbfstool/elfparsing.h
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2014-03-11 11:48:56 -0500
committerStefan Reinauer <stefan.reinauer@coreboot.org>2014-03-18 18:59:25 +0100
commit36be8135d74964fa2eb03af44079d845c199486b (patch)
tree1b1e482a259111d321c1cf07c4e8c300342e37c4 /util/cbfstool/elfparsing.h
parent8089f1780635daae24ded0ac7fb9dc2d2f2a01bb (diff)
cbfstool: add ELF writing support
In order to generate rmodules in the format of ELF files there needs to be support for writing out ELF files. The ELF writer is fairly simple. It accpets sections that can be associated with an optional buffer (file data). For each section flagged with SHF_ALLOC a PT_LOAD segment is generated. There isn't smart merging of the sections into a single PT_LOAD segment. Change-Id: I4d1a11f2e65be2369fb3f8bff350cbb28e14c89d Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/5377 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/elfparsing.h')
-rw-r--r--util/cbfstool/elfparsing.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/util/cbfstool/elfparsing.h b/util/cbfstool/elfparsing.h
index 113301aae2..048d31aa2b 100644
--- a/util/cbfstool/elfparsing.h
+++ b/util/cbfstool/elfparsing.h
@@ -74,4 +74,35 @@ elf_headers(const struct buffer *pinput,
Elf64_Phdr **pphdr,
Elf64_Shdr **pshdr);
+/* ELF writing support. */
+struct elf_writer;
+
+/*
+ * Initialize a new ELF writer. Deafult machine type, endianness, etc is
+ * copied from the passed in Elf64_Ehdr. Returns NULL on failure, valid
+ * pointer on success.
+ */
+struct elf_writer *elf_writer_init(const Elf64_Ehdr *ehdr);
+
+/*
+ * Clean up any internal state represented by ew. Aftewards the elf_writer
+ * is invalid.
+ */
+void elf_writer_destroy(struct elf_writer *ew);
+
+/*
+ * Add a section to the ELF file. Section type, flags, and memsize are
+ * maintained from the passed in Elf64_Shdr. The buffer represents the
+ * content of the section while the name is the name of section itself.
+ * Returns < 0 on error, 0 on success.
+ */
+int elf_writer_add_section(struct elf_writer *ew, const Elf64_Shdr *shdr,
+ struct buffer *contents, const char *name);
+
+/*
+ * Serialize the ELF file to the output buffer. Return < 0 on error,
+ * 0 on success.
+ */
+int elf_writer_serialize(struct elf_writer *ew, struct buffer *out);
+
#endif /* ELFPARSING_H */