Skip to content

Commit f23b778

Browse files
lyakhlgirdwood
authored andcommitted
rimage: add a convenience function
Add a function to search for a TOML configuration entry by module name. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent b9d87a4 commit f23b778

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

tools/rimage/src/manifest.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,32 @@ static void man_module_fill_reloc(const struct manifest_module *module,
483483
man_module->segment[SOF_MAN_SEGMENT_BSS].flags.r.length = 0;
484484
}
485485

486+
/* Look for a name among module TOML manifests */
487+
static int man_module_find_cfg(const struct fw_image_manifest_module *modules,
488+
const struct sof_man_module *module)
489+
{
490+
unsigned int i;
491+
char name[SOF_MAN_MOD_NAME_LEN + 1];
492+
493+
strncpy(name, (const char *)module->name, SOF_MAN_MOD_NAME_LEN);
494+
/* Ensure null termination */
495+
name[SOF_MAN_MOD_NAME_LEN] = '\0';
496+
497+
for (i = 0; i < modules->mod_man_count; i++) {
498+
if (!strncmp(name, (const char *)modules->mod_man[i].name, SOF_MAN_MOD_NAME_LEN))
499+
return i;
500+
}
501+
502+
fprintf(stderr, "error: Module %s not found in TOML.\n", name);
503+
504+
return -ENOEXEC;
505+
}
506+
486507
static int man_module_create_reloc(struct image *image, struct manifest_module *module,
487508
struct sof_man_module **man_module)
488509
{
489510
/* create module and segments */
511+
struct fw_image_manifest_module *modules = image->adsp->modules;
490512
const struct sof_man_module_manifest *sof_mod;
491513
struct elf_section section;
492514
int err;
@@ -509,33 +531,21 @@ static int man_module_create_reloc(struct image *image, struct manifest_module *
509531
unsigned int i;
510532

511533
for (i = 0, sof_mod = section.data; i < n_mod; i++, sof_mod++) {
512-
char name[SOF_MAN_MOD_NAME_LEN + 1];
513-
unsigned int j;
514-
515-
strncpy(name, (char *)sof_mod->module.name, SOF_MAN_MOD_NAME_LEN);
516-
/* Ensure null termination */
517-
name[SOF_MAN_MOD_NAME_LEN] = '\0';
518-
519-
for (j = 0; j < image->adsp->modules->mod_man_count; j++) {
520-
if (!strncmp(name, (char *)image->adsp->modules->mod_man[j].name,
521-
SOF_MAN_MOD_NAME_LEN)) {
522-
/* Found a TOML manifest, matching ELF */
523-
if (i)
524-
(*man_module)++;
525-
/* Use manifest created using toml files as template */
526-
**man_module = image->adsp->modules->mod_man[j];
527-
/* Use .manifest to update individual fields */
528-
man_get_section_manifest(image, sof_mod, *man_module);
529-
man_module_fill_reloc(module, *man_module);
530-
break;
531-
}
532-
}
534+
int j = man_module_find_cfg(modules, &sof_mod->module);
533535

534-
if (j == image->adsp->modules->mod_man_count) {
535-
fprintf(stderr, "error: cannot find %s in manifest.\n", name);
536+
if (j < 0) {
536537
elf_section_free(&section);
537-
return -ENOEXEC;
538+
return j;
538539
}
540+
541+
/* Found a TOML manifest, matching ELF */
542+
if (i)
543+
(*man_module)++;
544+
/* Use manifest created using toml files as template */
545+
**man_module = modules->mod_man[j];
546+
/* Use .manifest to update individual fields */
547+
man_get_section_manifest(image, sof_mod, *man_module);
548+
man_module_fill_reloc(module, *man_module);
539549
}
540550

541551
elf_section_free(&section);

0 commit comments

Comments
 (0)