From 99195d2ee6a7eeb926b6dd75be9a7ac23d6859fa Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Wed, 29 Mar 2023 17:00:36 +0200 Subject: [PATCH] rimage: manifest: Rename struct module to manifest_module Changing the name of the structure type is a prelude to separating information about the elf file from the information used during creation of a manifest. Signed-off-by: Adrian Warecki --- src/elf.c | 26 ++++++++-------- src/ext_manifest.c | 8 ++--- src/file_simple.c | 10 +++---- src/include/rimage/manifest.h | 51 +++++++++++++++++++++++++++++++ src/include/rimage/rimage.h | 56 ++++------------------------------- src/manifest.c | 14 ++++----- 6 files changed, 85 insertions(+), 80 deletions(-) diff --git a/src/elf.c b/src/elf.c index a8a98c961..e152b7588 100644 --- a/src/elf.c +++ b/src/elf.c @@ -20,7 +20,7 @@ static unsigned long uncache_to_cache(const struct image *image, unsigned long a return (address & ~image->adsp->mem.alias.mask) | image->adsp->mem.alias.cached; } -static int elf_read_sections(struct image *image, struct module *module, +static int elf_read_sections(struct image *image, struct manifest_module *module, int module_index) { Elf32_Ehdr *hdr = &module->hdr; @@ -151,7 +151,7 @@ static int elf_read_sections(struct image *image, struct module *module, return 0; } -static int elf_read_programs(struct image *image, struct module *module) +static int elf_read_programs(struct image *image, struct manifest_module *module) { Elf32_Ehdr *hdr = &module->hdr; Elf32_Phdr *prg = module->prg; @@ -207,7 +207,7 @@ static int elf_read_programs(struct image *image, struct module *module) return 0; } -static int elf_read_hdr(struct image *image, struct module *module) +static int elf_read_hdr(struct image *image, struct manifest_module *module) { Elf32_Ehdr *hdr = &module->hdr; size_t count; @@ -266,7 +266,7 @@ int elf_is_rom(struct image *image, Elf32_Shdr *section) return 1; } -static void elf_module_size(struct image *image, struct module *module, +static void elf_module_size(struct image *image, struct manifest_module *module, Elf32_Shdr *section, uint32_t lma, int index) { switch (section->type) { @@ -310,7 +310,7 @@ static void elf_module_size(struct image *image, struct module *module, } } -static void elf_module_size_reloc(struct image *image, struct module *module, +static void elf_module_size_reloc(struct image *image, struct manifest_module *module, Elf32_Shdr *section, int index) { switch (section->type) { @@ -346,7 +346,7 @@ static void elf_module_size_reloc(struct image *image, struct module *module, } } -static void elf_module_limits(struct image *image, struct module *module) +static void elf_module_limits(struct image *image, struct manifest_module *module) { Elf32_Shdr *section; uint32_t valid = (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR); @@ -408,10 +408,10 @@ static void elf_module_limits(struct image *image, struct module *module) } /* make sure no section overlap from any modules */ -int elf_validate_section(struct image *image, struct module *module, +int elf_validate_section(struct image *image, struct manifest_module *module, Elf32_Shdr *section, int index) { - struct module *m; + struct manifest_module *m; Elf32_Shdr *s; uint32_t valid = (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR); int i, j; @@ -464,7 +464,7 @@ err: /* make sure no section overlaps from any modules */ int elf_validate_modules(struct image *image) { - struct module *module; + struct manifest_module *module; Elf32_Shdr *section; uint32_t valid = (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR); int i, j, ret; @@ -498,7 +498,7 @@ int elf_validate_modules(struct image *image) return 0; } -int elf_find_section(const struct module *module, const char *name) +int elf_find_section(const struct manifest_module *module, const char *name) { const Elf32_Ehdr *hdr = &module->hdr; const Elf32_Shdr *section, *s; @@ -546,7 +546,7 @@ out: return ret; } -int elf_read_section(const struct module *module, const char *section_name, +int elf_read_section(const struct manifest_module *module, const char *section_name, const Elf32_Shdr **dst_section, void **dst_buff) { const Elf32_Shdr *section; @@ -585,7 +585,7 @@ int elf_read_section(const struct module *module, const char *section_name, int elf_parse_module(struct image *image, int module_index, const char *name) { - struct module *module; + struct manifest_module *module; uint32_t rem; int ret = 0; @@ -676,7 +676,7 @@ hdr_err: void elf_free_module(struct image *image, int module_index) { - struct module *module = &image->module[module_index]; + struct manifest_module *module = &image->module[module_index]; free(module->prg); free(module->section); diff --git a/src/ext_manifest.c b/src/ext_manifest.c index e670b4782..92360d6bb 100644 --- a/src/ext_manifest.c +++ b/src/ext_manifest.c @@ -41,9 +41,9 @@ static int ext_man_open_file(struct image *image) return 0; } -static const struct module *ext_man_find_module(const struct image *image) +static const struct manifest_module *ext_man_find_module(const struct image *image) { - const struct module *module; + const struct manifest_module *module; int i; /* when there is more than one module, then first one is bootloader */ @@ -86,7 +86,7 @@ static int ext_man_validate(uint32_t section_size, const void *section_data) } } -static int ext_man_build(const struct module *module, +static int ext_man_build(const struct manifest_module *module, struct ext_man_header **dst_buff) { struct ext_man_header ext_man; @@ -135,7 +135,7 @@ out: int ext_man_write(struct image *image) { - const struct module *module; + const struct manifest_module *module; struct ext_man_header *ext_man = NULL; int count; int ret; diff --git a/src/file_simple.c b/src/file_simple.c index b15d739ed..931bee3c3 100644 --- a/src/file_simple.c +++ b/src/file_simple.c @@ -37,7 +37,7 @@ static int get_mem_zone_type(const struct memory_config *memory, Elf32_Shdr *sec static int block_idx; -static int write_block(struct image *image, struct module *module, +static int write_block(struct image *image, struct manifest_module *module, Elf32_Shdr *section) { const struct adsp *adsp = image->adsp; @@ -109,7 +109,7 @@ out: return ret; } -static int simple_write_module(struct image *image, struct module *module) +static int simple_write_module(struct image *image, struct manifest_module *module) { struct snd_sof_mod_hdr hdr; Elf32_Shdr *section; @@ -191,7 +191,7 @@ static int simple_write_module(struct image *image, struct module *module) return padding; } -static int write_block_reloc(struct image *image, struct module *module) +static int write_block_reloc(struct image *image, struct manifest_module *module) { struct snd_sof_blk_hdr block; size_t count; @@ -240,7 +240,7 @@ out: return ret; } -static int simple_write_module_reloc(struct image *image, struct module *module) +static int simple_write_module_reloc(struct image *image, struct manifest_module *module) { struct snd_sof_mod_hdr hdr; size_t count; @@ -282,7 +282,7 @@ static int simple_write_module_reloc(struct image *image, struct module *module) int simple_write_firmware(struct image *image) { struct snd_sof_fw_header hdr; - struct module *module; + struct manifest_module *module; size_t count; int i, ret; diff --git a/src/include/rimage/manifest.h b/src/include/rimage/manifest.h index a1c9e39ec..2f345779a 100644 --- a/src/include/rimage/manifest.h +++ b/src/include/rimage/manifest.h @@ -7,10 +7,61 @@ #define __MANIFEST_H__ #include +#include #include #include #include #include +#include + +/* + * Manifest module data + */ +struct manifest_module { + /* This fields will be moved to module structure */ + const char *elf_file; + FILE *fd; + + Elf32_Ehdr hdr; + Elf32_Shdr *section; + Elf32_Phdr *prg; + char *strings; + + uint32_t text_start; + uint32_t text_end; + uint32_t data_start; + uint32_t data_end; + uint32_t bss_start; + uint32_t bss_end; + + int num_sections; + int num_bss; + int bss_index; + + /* sizes do not include any gaps */ + int bss_size; + int text_size; + int data_size; + + /* sizes do include gaps to nearest page */ + int bss_file_size; + int text_file_size; + int data_file_size; + + /* total file size */ + size_t file_size; + + /* Following fields are used in manifest creation process */ + int fw_size; + + /* executable header module */ + int exec_header; + + /* module offset in image file */ + size_t foffset; + + size_t text_fixup_size; +}; #define MAN_PAGE_SIZE 4096 #define MAN_MAX_SIZE_V1_8 (38 * 1024) diff --git a/src/include/rimage/rimage.h b/src/include/rimage/rimage.h index e682dc01c..ac0595bd8 100644 --- a/src/include/rimage/rimage.h +++ b/src/include/rimage/rimage.h @@ -6,11 +6,10 @@ #ifndef __RIMAGE_H__ #define __RIMAGE_H__ -#include "elf.h" - #include #include +#include #include #include @@ -18,51 +17,6 @@ #define MAX_MODULES 32 struct adsp; -struct manifest; -struct man_module; - -/* - * ELF module data - */ -struct module { - const char *elf_file; - FILE *fd; - - Elf32_Ehdr hdr; - Elf32_Shdr *section; - Elf32_Phdr *prg; - char *strings; - - uint32_t text_start; - uint32_t text_end; - uint32_t data_start; - uint32_t data_end; - uint32_t bss_start; - uint32_t bss_end; - uint32_t foffset; - - int num_sections; - int num_bss; - int fw_size; - int bss_index; - - /* sizes do not include any gaps */ - int bss_size; - int text_size; - int data_size; - - /* sizes do include gaps to nearest page */ - int bss_file_size; - int text_file_size; - int text_fixup_size; - int data_file_size; - - /* total file size */ - size_t file_size; - - /* executable header module */ - int exec_header; -}; /* * Firmware image context. @@ -79,7 +33,7 @@ struct image { int verbose; int reloc; /* ELF data is relocatable */ int num_modules; - struct module module[MAX_MODULES]; + struct manifest_module module[MAX_MODULES]; uint32_t image_end;/* module end, equal to output image size */ int meu_offset; const char *verify_file; @@ -219,10 +173,10 @@ int elf_parse_module(struct image *image, int module_index, const char *name); void elf_free_module(struct image *image, int module_index); int elf_is_rom(struct image *image, Elf32_Shdr *section); int elf_validate_modules(struct image *image); -int elf_find_section(const struct module *module, const char *name); -int elf_read_section(const struct module *module, const char *name, +int elf_find_section(const struct manifest_module *module, const char *name); +int elf_read_section(const struct manifest_module *module, const char *name, const Elf32_Shdr **dst_section, void **dst_buff); -int elf_validate_section(struct image *image, struct module *module, +int elf_validate_section(struct image *image, struct manifest_module *manifest_module, Elf32_Shdr *section, int index); #endif diff --git a/src/manifest.c b/src/manifest.c index f212b9d4e..76754a542 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -141,7 +141,7 @@ static int man_init_image_v2_5(struct image *image) /* we should call this after all segments size set up via iterate */ static uint32_t elf_to_file_offset(struct image *image, - struct module *module, + struct manifest_module *module, struct sof_man_module *man_module, Elf32_Shdr *section) { @@ -174,7 +174,7 @@ static uint32_t elf_to_file_offset(struct image *image, /* write SRAM sections */ static int man_copy_sram(struct image *image, Elf32_Shdr *section, - struct module *module, + struct manifest_module *module, struct sof_man_module *man_module, int section_idx) { @@ -227,7 +227,7 @@ static int man_copy_sram(struct image *image, Elf32_Shdr *section, } static int man_copy_elf_section(struct image *image, Elf32_Shdr *section, - struct module *module, + struct manifest_module *module, struct sof_man_module *man_module, int idx) { int ret; @@ -244,7 +244,7 @@ static int man_copy_elf_section(struct image *image, Elf32_Shdr *section, return 0; } -static int man_get_module_manifest(struct image *image, struct module *module, +static int man_get_module_manifest(struct image *image, struct manifest_module *module, struct sof_man_module *man_module) { Elf32_Shdr *section; @@ -371,7 +371,7 @@ err: return -EINVAL; } -static int man_module_create(struct image *image, struct module *module, +static int man_module_create(struct image *image, struct manifest_module *module, struct sof_man_module *man_module) { /* create module and segments */ @@ -502,7 +502,7 @@ out: return 0; } -static int man_module_create_reloc(struct image *image, struct module *module, +static int man_module_create_reloc(struct image *image, struct manifest_module *module, struct sof_man_module *man_module) { /* create module and segments */ @@ -634,7 +634,7 @@ static int man_write_fw_mod(struct image *image) static int man_create_modules(struct image *image, struct sof_man_fw_desc *desc, int file_text_offset) { - struct module *module; + struct manifest_module *module; struct sof_man_module *man_module; int err; int i = 0, offset = 0;