Repository navigation
Expand file tree
/
Copy pathldc.c
More file actions
173 lines (142 loc) · 4.21 KB
/
Copy pathldc.c
File metadata and controls
173 lines (142 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
#include <kernel/abi.h>
#include <kernel/ext_manifest.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ldc.h"
#include "smex.h"
static int fw_version_copy(const struct elf_module *src,
struct snd_sof_logs_header *header)
{
struct ext_man_elem_header *ext_hdr = NULL;
void *buffer = NULL;
int section_size;
section_size = elf_read_section(src, ".fw_ready", NULL, &buffer);
if (section_size < 0)
return section_size;
memcpy(&header->version,
&((struct sof_ipc_fw_ready *)buffer)->version,
sizeof(header->version));
free(buffer);
/* fw_ready structure contains main (primarily kernel)
* ABI version.
*/
fprintf(stdout, "fw abi main version:\t%d.%d.%d\n",
SOF_ABI_VERSION_MAJOR(header->version.abi_version),
SOF_ABI_VERSION_MINOR(header->version.abi_version),
SOF_ABI_VERSION_PATCH(header->version.abi_version));
/* let's find dbg abi version, which the log client
* is interested in and override the kernel's one.
*
* skip the base fw-ready record and begin from the first extension.
*/
section_size = elf_read_section(src, ".fw_metadata", NULL, &buffer);
if (section_size < 0)
return section_size;
ext_hdr = (struct ext_man_elem_header *)buffer;
while ((uintptr_t)ext_hdr < (uintptr_t)buffer + section_size) {
if (ext_hdr->type == EXT_MAN_ELEM_DBG_ABI) {
header->version.abi_version =
((struct ext_man_dbg_abi *)
ext_hdr)->dbg_abi.abi_dbg_version;
break;
}
//move to the next entry
ext_hdr = (struct ext_man_elem_header *)
((uint8_t *)ext_hdr + ext_hdr->elem_size);
}
free(buffer);
fprintf(stdout, "fw abi dbg version:\t%d.%d.%d\n",
SOF_ABI_VERSION_MAJOR(header->version.abi_version),
SOF_ABI_VERSION_MINOR(header->version.abi_version),
SOF_ABI_VERSION_PATCH(header->version.abi_version));
return 0;
}
static int write_logs_dictionary(struct image *image,
const struct elf_module *src)
{
struct snd_sof_logs_header header;
const Elf32_Shdr *section;
void *buffer = NULL;
int count;
int ret;
memcpy(header.sig, SND_SOF_LOGS_SIG, SND_SOF_LOGS_SIG_SIZE);
header.data_offset = sizeof(struct snd_sof_logs_header);
/* extract fw_version from fw_ready message located
* in .fw_ready section
*/
ret = fw_version_copy(src, &header);
if (ret < 0)
goto out;
ret = elf_read_section(src, ".static_log_entries", §ion, &buffer);
if (ret < 0)
goto out;
ret = 0;
header.base_address = section->vaddr;
header.data_length = section->size;
fwrite(&header, sizeof(struct snd_sof_logs_header), 1,
image->ldc_out_fd);
count = fwrite(buffer, 1, section->size, image->ldc_out_fd);
if (count != section->size) {
fprintf(stderr,
"error: can't write section %d\n",
-errno);
ret = -errno;
goto out;
}
fprintf(stdout, "logs dictionary size:\t%u\n",
header.data_length + header.data_offset);
fprintf(stdout, "including fw version of size:\t%lu\n",
(unsigned long)sizeof(header.version));
out:
if (buffer)
free(buffer);
return ret;
}
static int write_uids_dictionary(struct image *image,
const struct elf_module *src)
{
struct snd_sof_uids_header header;
const Elf32_Shdr *section;
void *buffer = NULL;
int ret;
memcpy(header.sig, SND_SOF_UIDS_SIG, SND_SOF_UIDS_SIG_SIZE);
header.data_offset = sizeof(struct snd_sof_uids_header);
ret = elf_read_section(src, ".static_uuid_entries", §ion, &buffer);
if (ret < 0)
goto out;
ret = 0;
header.base_address = section->vaddr;
header.data_length = section->size;
fwrite(&header, sizeof(struct snd_sof_uids_header), 1,
image->ldc_out_fd);
if (fwrite(buffer, 1, section->size, image->ldc_out_fd) !=
section->size) {
fprintf(stderr, "error: cant't write section %d\n",
-errno);
ret = -errno;
goto out;
}
fprintf(stdout, "uids dictionary size:\t%u\n",
header.data_length + header.data_offset);
out:
if (buffer)
free(buffer);
return ret;
}
int write_dictionaries(struct image *image, const struct elf_module *src)
{
int ret = 0;
ret = write_logs_dictionary(image, src);
if (ret)
goto out;
ret = write_uids_dictionary(image, src);
out:
return ret;
}