Skip to content

Commit 3f2301c

Browse files
committed
ext_manifest: Add UUID dictionary
Such a dictionary will be used in kernel code to translate UUID value to memory address used in DSP in runtime. Translation will be used for the process component creation and runtime trace filtering. Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
1 parent 8912843 commit 3f2301c

3 files changed

Lines changed: 96 additions & 13 deletions

File tree

src/ext_manifest.c

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include "kernel/ext_manifest.h"
1414
#include "rimage.h"
1515

16+
#ifndef ALIGN_UP
17+
#define ALIGN_UP(size, alignment) \
18+
((size) + (((alignment) - ((size) % (alignment))) % (alignment)))
19+
#endif
20+
1621
const struct ext_man_header ext_man_template = {
1722
.magic = EXT_MAN_MAGIC_NUMBER,
1823
.header_version = EXT_MAN_VERSION,
@@ -81,53 +86,129 @@ static int ext_man_validate(uint32_t section_size, const void *section_data)
8186
}
8287
}
8388

89+
/*
90+
* Insert `section_name` content after `elem_type` header.
91+
* Save result in new buffer, then replace `meta_section_data`.
92+
* Return `section_name` size or error code.
93+
*/
94+
static int ext_man_update_element_with_list(const struct module *module,
95+
uint32_t* meta_section_size,
96+
uint8_t **meta_section_data,
97+
enum ext_man_elem_type elem_type,
98+
const char *section_name)
99+
{
100+
struct ext_man_elem_header* head = NULL;
101+
uint8_t *msd_buff = *meta_section_data;
102+
uint8_t *sec_buffer = NULL;
103+
const Elf32_Shdr *section;
104+
uint32_t offset = 0;
105+
uint32_t extra_size;
106+
uint8_t *temp_buff;
107+
int ret;
108+
109+
/* find `elem_type` in meta_section */
110+
while (offset < *meta_section_size) {
111+
head = (struct ext_man_elem_header*)&msd_buff[offset];
112+
if (head->type == elem_type || !head->elem_size)
113+
break;
114+
offset += head->elem_size;
115+
}
116+
117+
if (!head || head->type != elem_type) {
118+
fprintf(stdout,
119+
"Extended manifest element %d not found\n", elem_type);
120+
return -EINVAL;
121+
}
122+
123+
/* read section with list content */
124+
ret = elf_read_section(module, section_name, &section,
125+
(void **)&sec_buffer);
126+
if (ret < 0) {
127+
fprintf(stderr,
128+
"error: failed to read %s section content, code %d\n",
129+
section_name, ret);
130+
return ret;
131+
}
132+
133+
temp_buff = malloc(*meta_section_size + section->size);
134+
if (!temp_buff) {
135+
free(sec_buffer);
136+
return -ENOMEM;
137+
}
138+
139+
/* update element size and insert list after element header */
140+
offset += head->elem_size;
141+
extra_size = ALIGN_UP(head->elem_size + section->size, EXT_MAN_ALIGN) -
142+
head->elem_size;
143+
head->elem_size += extra_size;
144+
memcpy(&temp_buff[0], msd_buff, offset);
145+
memcpy(&temp_buff[offset], sec_buffer, section->size);
146+
memcpy(&temp_buff[offset + section->size], &msd_buff[offset],
147+
*meta_section_size - offset);
148+
149+
free(*meta_section_data);
150+
*meta_section_data = temp_buff;
151+
152+
return 0;
153+
}
154+
84155
static int ext_man_build(const struct module *module,
85156
struct ext_man_header **dst_buff)
86157
{
87158
struct ext_man_header ext_man;
88159
const Elf32_Shdr *section;
89160
uint8_t *buffer = NULL;
90161
uint8_t *sec_buffer = NULL;
91-
size_t offset;
162+
uint32_t sec_buffer_size;
92163
int ret;
93164

94-
ret = elf_read_section(module, EXT_MAN_DATA_SECTION, &section,
95-
(void **)&sec_buffer);
96-
if (ret < 0) {
165+
sec_buffer_size = elf_read_section(module, EXT_MAN_DATA_SECTION,
166+
&section, (void **)&sec_buffer);
167+
if (sec_buffer_size < 0) {
97168
fprintf(stderr,
98169
"error: failed to read %s section content, code %d\n",
99170
EXT_MAN_DATA_SECTION, ret);
100-
goto out;
171+
return sec_buffer_size;
172+
}
173+
174+
ret = ext_man_update_element_with_list(module, &sec_buffer_size,
175+
&sec_buffer,
176+
EXT_MAN_ELEM_UUID_DICT,
177+
EXT_MAN_UUID_DICT_SECTION);
178+
if (ret < 0) {
179+
fprintf(stderr,
180+
"error: failed to update extended manifest element with %s section content, code %d\n",
181+
EXT_MAN_UUID_DICT_SECTION, ret);
182+
goto err;
101183
}
102-
ret = 0;
103184

104185
/* fill ext_man struct, size aligned to 4 to avoid unaligned accesses */
105186
memcpy(&ext_man, &ext_man_template, sizeof(struct ext_man_header));
106187
ext_man.full_size = ext_man.header_size;
107-
ext_man.full_size += section->size;
188+
ext_man.full_size += sec_buffer_size;
108189
if (ext_man.full_size % 4) {
109190
fprintf(stderr,
110191
"error: extended manifest size must be aligned to 4\n");
111192
ret = -EINVAL;
112-
goto out;
193+
goto err;
113194
}
114195

115196
/* alloc buffer for ext_man */
116197
buffer = calloc(1, ext_man.full_size);
117198
if (!buffer) {
118199
ret = -ENOMEM;
119-
goto out;
200+
goto err;
120201
}
121202

122203
/* fill buffer with ext_man and section content */
123204
memcpy(buffer, &ext_man, ext_man.header_size);
124-
offset = ext_man.header_size;
125-
126-
memcpy(&buffer[offset],sec_buffer, section->size);
205+
memcpy(&buffer[ext_man.header_size], sec_buffer, sec_buffer_size);
127206

128207
*dst_buff = (struct ext_man_header *)buffer;
129208

130-
out:
209+
err:
210+
if (!sec_buffer)
211+
free(sec_buffer);
131212
return ret;
132213
}
133214

src/include/sof/kernel/ext_manifest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ enum ext_man_elem_type {
8383
EXT_MAN_ELEM_FW_VERSION = 0,
8484
EXT_MAN_ELEM_CC_VERSION = 1,
8585
EXT_MAN_ELEM_PROBE_INFO = 2,
86+
EXT_MAN_ELEM_UUID_DICT = 3,
8687
};
8788

8889
#endif /* __KERNEL_EXT_MANIFEST_H__ */

src/include/sof/kernel/ext_manifest_gen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "rimage.h"
3131

3232
#define EXT_MAN_DATA_SECTION ".fw_metadata"
33+
#define EXT_MAN_UUID_DICT_SECTION ".fw_metadata_uuid_dict"
3334

3435
int ext_man_write(struct image *image);
3536

0 commit comments

Comments
 (0)