summaryrefslogtreecommitdiff
path: root/util/cbfstool/elfheaders.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool/elfheaders.c')
-rw-r--r--util/cbfstool/elfheaders.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index 4cf3534a23..da11bfcb62 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -635,6 +635,30 @@ elf_headers(const struct buffer *pinput,
* +------------------+
*/
+void elf_init_eheader(Elf64_Ehdr *ehdr, int machine, int nbits, int endian)
+{
+ memset(ehdr, 0, sizeof(*ehdr));
+ ehdr->e_ident[EI_MAG0] = ELFMAG0;
+ ehdr->e_ident[EI_MAG1] = ELFMAG1;
+ ehdr->e_ident[EI_MAG2] = ELFMAG2;
+ ehdr->e_ident[EI_MAG3] = ELFMAG3;
+ ehdr->e_ident[EI_CLASS] = nbits;
+ ehdr->e_ident[EI_DATA] = endian;
+ ehdr->e_ident[EI_VERSION] = EV_CURRENT;
+ ehdr->e_type = ET_EXEC;
+ ehdr->e_machine = machine;
+ ehdr->e_version = EV_CURRENT;
+ if (nbits == ELFCLASS64) {
+ ehdr->e_ehsize = sizeof(Elf64_Ehdr);
+ ehdr->e_phentsize = sizeof(Elf64_Phdr);
+ ehdr->e_shentsize = sizeof(Elf64_Shdr);
+ } else {
+ ehdr->e_ehsize = sizeof(Elf32_Ehdr);
+ ehdr->e_phentsize = sizeof(Elf32_Phdr);
+ ehdr->e_shentsize = sizeof(Elf32_Shdr);
+ }
+}
+
/* Arbitray maximum number of sections. */
#define MAX_SECTIONS 16
struct elf_writer_section {