1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 //
5 // Author: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
6 
7 #ifndef __INCLUDE_ELF_H__
8 #define __INCLUDE_ELF_H__
9 
10 #include <stdbool.h>
11 #include <stdio.h>
12 #include <stdint.h>
13 #include "elf_defs.h"
14 
15 /*
16  * ELF module data
17  */
18 struct elf_module {
19 	const char *elf_file;
20 	FILE *fd;
21 
22 	Elf32_Ehdr hdr;
23 	Elf32_Shdr *section;
24 	Elf32_Phdr *prg;
25 	char *strings;
26 
27 	uint32_t text_start;
28 	uint32_t text_end;
29 	uint32_t data_start;
30 	uint32_t data_end;
31 	uint32_t bss_start;
32 	uint32_t bss_end;
33 	uint32_t foffset;
34 
35 	int num_sections;
36 	int num_bss;
37 	int fw_size;
38 	int bss_index;
39 
40 	/* sizes do not include any gaps */
41 	int bss_size;
42 	int text_size;
43 	int data_size;
44 
45 	/* sizes do include gaps to nearest page */
46 	int bss_file_size;
47 	int text_file_size;
48 	int text_fixup_size;
49 	int data_file_size;
50 
51 	/* total file size */
52 	int file_size;
53 
54 	/* executable header module */
55 	int exec_header;
56 };
57 
58 int elf_read_module(struct elf_module *module, const char *name, bool verbose);
59 void elf_free_module(struct elf_module *module);
60 int elf_find_section(const struct elf_module *module, const char *name);
61 int elf_read_section(const struct elf_module *module, const char *section_name,
62 		     const Elf32_Shdr **dst_section, void **dst_buff);
63 
64 #endif /* __INCLUDE_ELF_H__ */
65