lib/cbfs: deserialize cbfs_stage objects correctly
[coreboot.git] / util / cbfstool / rmodule.h
bloba62562b98f192749f51efa0adf32ab885d41148b
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef TOOL_RMODULE_H
4 #define TOOL_RMODULE_H
6 #include "elfparsing.h"
7 #include "common.h"
9 struct arch_ops {
10 int arch;
11 /* Determine if relocation is a valid type for the architecture. */
12 int (*valid_type)(Elf64_Rela *rel);
13 /* Determine if relocation should be emitted. */
14 int (*should_emit)(Elf64_Rela *rel);
18 * The fields in rmod_context are read-only to the user. These are
19 * exposed for easy shareability.
21 struct rmod_context {
22 /* Ops to process relocations. */
23 const struct arch_ops *ops;
25 /* endian conversion ops */
26 struct xdr *xdr;
28 /* Parsed ELF structure. */
29 struct parsed_elf pelf;
30 /* Program segment. */
31 Elf64_Phdr *phdr;
33 /* Collection of relocation addresses fixup in the module. */
34 Elf64_Xword nrelocs;
35 Elf64_Addr *emitted_relocs;
37 /* The following fields are addresses within the linked program. */
38 Elf64_Addr parameters_begin;
39 Elf64_Addr parameters_end;
40 Elf64_Addr bss_begin;
41 Elf64_Addr bss_end;
44 struct reloc_filter {
45 /* Return < 0 on error. 0 to ignore relocation and 1 to include
46 * relocation. */
47 int (*filter)(struct reloc_filter *f, const Elf64_Rela *r);
48 /* Pointer for filter provides */
49 void *context;
53 * Parse an ELF file within the elfin buffer and fill in the elfout buffer
54 * with a created rmodule in ELF format. Return 0 on success, < 0 on error.
56 int rmodule_create(const struct buffer *elfin, struct buffer *elfout);
59 * Initialize an rmodule context from an ELF buffer. Returns 0 on scucess, < 0
60 * on error.
62 int rmodule_init(struct rmod_context *ctx, const struct buffer *elfin);
65 * Collect all the relocations that apply to the program in
66 * nrelocs/emitted_relocs. One can optionally provide a reloc_filter object
67 * to help in relocation filtering. The filter function will be called twice:
68 * once for counting and once for emitting. The same response should be
69 * provided for each call. Returns 0 on success, < 0 on error.
71 int rmodule_collect_relocations(struct rmod_context *c, struct reloc_filter *f);
73 /* Clean up the memory consumed by the rmodule context. */
74 void rmodule_cleanup(struct rmod_context *ctx);
77 * Create an ELF file from the passed in rmodule in the buffer. The buffer
78 * contents will be replaced with an ELF file. Returns 1 if buff doesn't
79 * contain an rmodule and < 0 on failure, 0 on success.
81 int rmodule_stage_to_elf(Elf64_Ehdr *ehdr, struct buffer *buff);
83 #endif /* TOOL_RMODULE_H */