Skip to content

Commit 0f3f9c0

Browse files
committed
rimage: debugability: include fw_version in .ldc file
Extract fw_version from fw_ready section of elf and include it in header of .ldc file to allow verification by sof-logger. Signed-off-by: ArturX Kloniecki <arturx.kloniecki@linux.intel.com>
1 parent f59e706 commit 0f3f9c0

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

rimage/elf.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ static int elf_read_sections(struct image *image, struct module *module)
8787
fprintf(stdout, " BSS module metadata section at index %d\n",
8888
man_section_idx);
8989

90-
/* find log entries section */
91-
module->logs_index = elf_find_section(image, module,
92-
".static_log_entries");
90+
/* find log entries and fw ready sections */
91+
module->logs_index = elf_find_section(image, module,
92+
".static_log_entries");
9393
fprintf(stdout, " static log entries section at index %d\n",
9494
module->logs_index);
95+
module->fw_ready_index = elf_find_section(image, module,
96+
".fw_ready");
97+
fprintf(stdout, " fw ready section at index %d\n",
98+
module->fw_ready_index);
9599

96100
/* parse each section */
97101
for (i = 0; i < hdr->e_shnum; i++) {
@@ -352,7 +356,8 @@ static void elf_module_limits(struct image *image, struct module *module)
352356
section = &module->section[i];
353357

354358
/* module bss can sometimes be missed */
355-
if (i != module->bss_index && i != module->logs_index) {
359+
if (i != module->bss_index && i != module->logs_index &&
360+
i != module->fw_ready_index) {
356361

357362
/* only check valid sections */
358363
if (!(section->sh_flags & valid))

rimage/file_format.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
#ifndef __INCLUDE_UAPI_SOF_FW_H__
6464
#define __INCLUDE_UAPI_SOF_FW_H__
6565

66+
/* Skip inclusion of <sof/io.h> which causes errors */
67+
#define __INCLUDE_IO__
68+
#include <uapi/ipc.h>
69+
6670
#define SND_SOF_FW_SIG_SIZE 4
6771
#define SND_SOF_FW_ABI 1
6872
#define SND_SOF_FW_SIG "Reef"
@@ -125,5 +129,6 @@ struct snd_sof_logs_header {
125129
uint32_t base_address; /* address of log entries section */
126130
uint32_t data_length; /* amount of bytes following this header */
127131
uint32_t data_offset; /* offset to first entry in this file */
132+
struct sof_ipc_fw_version version;
128133
};
129134
#endif

rimage/file_simple.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,37 @@ int write_logs_dictionary(struct image *image)
357357
for (i = 0; i < image->num_modules; i++) {
358358
struct module *module = &image->module[i];
359359

360+
/* extract fw_version from fw_ready message located
361+
* in .fw_ready section
362+
*/
363+
if (module->fw_ready_index > 0) {
364+
Elf32_Shdr *section =
365+
&module->section[module->fw_ready_index];
366+
367+
buffer = calloc(1, sizeof(struct sof_ipc_fw_ready));
368+
if (!buffer)
369+
return -ENOMEM;
370+
371+
fseek(module->fd, section->sh_offset, SEEK_SET);
372+
size_t count = fread(buffer, 1,
373+
sizeof(struct sof_ipc_fw_ready), module->fd);
374+
375+
if (count != sizeof(struct sof_ipc_fw_ready)) {
376+
fprintf(stderr,
377+
"error: can't read ready section %d\n",
378+
-errno);
379+
ret = -errno;
380+
goto out;
381+
}
382+
383+
memcpy(&header.version,
384+
&((struct sof_ipc_fw_ready *)buffer)->version,
385+
sizeof(header.version));
386+
387+
free(buffer);
388+
buffer = NULL;
389+
}
390+
360391
if (module->logs_index > 0) {
361392
Elf32_Shdr *section = &module->section[module->logs_index];
362393

@@ -374,7 +405,8 @@ int write_logs_dictionary(struct image *image)
374405
size_t count = fread(buffer, 1, section->sh_size,
375406
module->fd);
376407
if (count != section->sh_size) {
377-
fprintf(stderr, "error: can't read section %d\n",
408+
fprintf(stderr,
409+
"error: can't read logs section %d\n",
378410
-errno);
379411
ret = -errno;
380412
goto out;
@@ -388,8 +420,10 @@ int write_logs_dictionary(struct image *image)
388420
goto out;
389421
}
390422

391-
fprintf(stdout, "logs dictionary: size %d\n\n",
423+
fprintf(stdout, "logs dictionary: size %u\n",
392424
header.data_length + header.data_offset);
425+
fprintf(stdout, "including fw version of size: %lu\n\n",
426+
sizeof(header.version));
393427
}
394428
}
395429
out:

rimage/rimage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct module {
7070
int fw_size;
7171
int bss_index;
7272
int logs_index;
73+
int fw_ready_index;
7374

7475
/* sizes do not include any gaps */
7576
int bss_size;

0 commit comments

Comments
 (0)