Skip to content

Commit 6b45d5c

Browse files
authored
Merge pull request #512 from akloniex/extract-fw_version
debugability: extract fw_version and copy it to .ldc file
2 parents 04b1ce4 + 0f3f9c0 commit 6b45d5c

14 files changed

Lines changed: 91 additions & 12 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;

src/platform/apollolake/apollolake.x.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,8 @@ SECTIONS
567567
*(*.static_log*)
568568
} > static_log_entries_seg :static_log_entries_phdr
569569

570+
.fw_ready : ALIGN(4)
571+
{
572+
KEEP (*(.fw_ready))
573+
} >sof_data :sof_data_phdr
570574
}

src/platform/baytrail/baytrail.x.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,9 @@ SECTIONS
513513
{
514514
*(*.static_log*)
515515
} > static_log_entries_seg :static_log_entries_phdr
516-
}
517516

517+
.fw_ready : ALIGN(4)
518+
{
519+
KEEP (*(.fw_ready))
520+
} >sof_data :sof_data_phdr
521+
}

src/platform/baytrail/platform.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
#include <string.h>
5858
#include <version.h>
5959

60-
static const struct sof_ipc_fw_ready ready = {
60+
static const struct sof_ipc_fw_ready ready
61+
__attribute__((section(".fw_ready"))) = {
6162
.hdr = {
6263
.cmd = SOF_IPC_FW_READY,
6364
.size = sizeof(struct sof_ipc_fw_ready),

src/platform/cannonlake/cannonlake.x.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,9 @@ SECTIONS
556556
{
557557
*(*.static_log*)
558558
} > static_log_entries_seg :static_log_entries_phdr
559+
560+
.fw_ready : ALIGN(4)
561+
{
562+
KEEP (*(.fw_ready))
563+
} >sof_data :sof_data_phdr
559564
}

src/platform/haswell/broadwell.x.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,9 @@ SECTIONS
513513
{
514514
*(*.static_log*)
515515
} > static_log_entries_seg :static_log_entries_phdr
516-
}
517516

517+
.fw_ready : ALIGN(4)
518+
{
519+
KEEP (*(.fw_ready))
520+
} >sof_data :sof_data_phdr
521+
}

src/platform/haswell/haswell.x.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,9 @@ SECTIONS
513513
{
514514
*(*.static_log*)
515515
} > static_log_entries_seg :static_log_entries_phdr
516-
}
517516

517+
.fw_ready : ALIGN(4)
518+
{
519+
KEEP (*(.fw_ready))
520+
} >sof_data :sof_data_phdr
521+
}

0 commit comments

Comments
 (0)