Skip to content

Commit ec649f3

Browse files
lyakhlgirdwood
authored andcommitted
Convert all ELF addresses to cached for calculations
Rimage calculates sizes of ELF sections, for which it has to use addresses from the same address space: either all cached or all uncached. The ELF image itself can contain mixed addresses. Convert all to cached for internal calculations. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 7bc3cfc commit ec649f3

4 files changed

Lines changed: 76 additions & 15 deletions

File tree

config/tgl-cavs.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version = [2, 5]
33
[adsp]
44
name = "tgl"
55
image_size = "0x2F0000"
6+
alias_mask = "0xE0000000"
67

78
[[adsp.mem_zone]]
89
type = "ROM"
@@ -21,6 +22,13 @@ type = "LP-SRAM"
2122
base = "0xBE800000"
2223
size = "0x40"
2324

25+
[[adsp.mem_alias]]
26+
type = "uncached"
27+
base = "0x9E000000"
28+
[[adsp.mem_alias]]
29+
type = "cached"
30+
base = "0xBE000000"
31+
2432
[cse]
2533
partition_name = "ADSP"
2634
[[cse.entry]]

src/adsp_config.c

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int assert_everything_parsed(const toml_table_t *table, struct parse_ctx
122122
ctx->array_cnt = toml_table_narr(table) - ctx->array_cnt;
123123
ctx->table_cnt = toml_table_ntab(table) - ctx->table_cnt;
124124

125-
/* when eny field left unparsed, then raise error */
125+
/* when any field left unparsed, then raise error */
126126
if (ctx->key_cnt != 0)
127127
ret = log_err(-EINVAL, "error: %d unparsed keys left in '%s'\n", ctx->key_cnt, key);
128128
if (ctx->array_cnt != 0)
@@ -360,14 +360,15 @@ static void dump_adsp(const struct adsp *adsp)
360360
static int parse_adsp(const toml_table_t *toml, struct parse_ctx *pctx, struct adsp *out,
361361
bool verbose)
362362
{
363-
toml_array_t *mem_zone_array;
364-
toml_table_t *mem_zone;
363+
toml_array_t *mem_zone_array, *alias_array;
365364
struct mem_zone *zone;
366365
struct parse_ctx ctx;
367-
char zone_name[32];
368366
toml_table_t *adsp;
369367
toml_raw_t raw;
370368
int zone_idx;
369+
char a_kind;
370+
int a_size;
371+
bool alias_found;
371372
int ret;
372373
int i;
373374

@@ -403,25 +404,67 @@ static int parse_adsp(const toml_table_t *toml, struct parse_ctx *pctx, struct a
403404
if (ret < 0)
404405
return ret;
405406

406-
/* check everything parsed, 1 table should be present */
407-
ctx.array_cnt += 1;
407+
out->alias_mask = parse_uint32_hex_key(adsp, &ctx, "alias_mask", 0, &ret);
408+
alias_found = !ret;
409+
410+
/* check everything parsed, 1 or 2 tables should be present */
411+
ctx.array_cnt += 1 + alias_found;
408412
ret = assert_everything_parsed(adsp, &ctx);
409413
if (ret < 0)
410414
return ret;
411415

416+
if (alias_found) {
417+
alias_array = toml_array_in(adsp, "mem_alias");
418+
if (!alias_array)
419+
return err_key_not_found("mem_alias");
420+
a_kind = toml_array_kind(alias_array);
421+
a_size = toml_array_nelem(alias_array);
422+
if (a_kind != 't' || a_size != 2)
423+
return err_key_parse("mem_alias", "wrong array type %c or length %d",
424+
a_kind, a_size);
425+
426+
/* retrieve "cached" and "uncached" alias base addresses */
427+
for (i = 0; i < a_size; ++i) {
428+
toml_table_t *alias = toml_table_at(alias_array, i);
429+
char alias_name[16];
430+
uint32_t base;
431+
432+
if (!alias)
433+
return err_key_parse("mem_alias", NULL);
434+
435+
parse_str_key(alias, &ctx, "type", alias_name, sizeof(alias_name), &ret);
436+
if (ret < 0)
437+
return err_key_parse("mem_alias", NULL);
438+
439+
base = parse_uint32_hex_key(alias, &ctx, "base", -1, &ret);
440+
441+
if (!strncmp("cached", alias_name, sizeof("cached")))
442+
out->alias_cached = base & out->alias_mask;
443+
else if (!strncmp("uncached", alias_name, sizeof("uncached")))
444+
out->alias_uncached = base & out->alias_mask;
445+
}
446+
} else {
447+
/* Make uncache_to_cache() an identity transform */
448+
out->alias_cached = 0;
449+
out->alias_mask = 0;
450+
}
451+
412452
/* look for entry array */
413453
memset(out->mem_zones, 0, sizeof(out->mem_zones));
414454
mem_zone_array = toml_array_in(adsp, "mem_zone");
415455
if (!mem_zone_array)
416456
return err_key_not_found("mem_zone");
417-
if (toml_array_kind(mem_zone_array) != 't' ||
418-
toml_array_nelem(mem_zone_array) > SOF_FW_BLK_TYPE_NUM)
419-
return err_key_parse("mem_zone", "wrong array type or length > %d",
420-
SOF_FW_BLK_TYPE_NUM);
457+
a_kind = toml_array_kind(mem_zone_array);
458+
a_size = toml_array_nelem(mem_zone_array);
459+
if (a_kind != 't' || a_size > SOF_FW_BLK_TYPE_NUM)
460+
return err_key_parse("mem_zone", "wrong array type %c or length %d",
461+
a_kind, a_size);
421462

422463
/* parse entry array elements */
423-
for (i = 0; i < toml_array_nelem(mem_zone_array); ++i) {
424-
mem_zone = toml_table_at(mem_zone_array, i);
464+
for (i = 0; i < a_size; ++i) {
465+
toml_table_t *mem_zone = toml_table_at(mem_zone_array, i);
466+
char zone_name[32];
467+
425468
if (!mem_zone)
426469
return err_key_parse("mem_zone", NULL);
427470

@@ -2617,7 +2660,7 @@ static int adsp_parse_config_fd(FILE *fd, struct image *image)
26172660
goto error;
26182661
}
26192662

2620-
/* run dedicated parser */
2663+
/* run dedicated toml configuration parser */
26212664
ret = parser->parse(toml, image);
26222665
error:
26232666
toml_free(toml);

src/elf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <rimage/cse.h>
1313
#include <rimage/manifest.h>
1414

15+
static unsigned long uncache_to_cache(const struct image *image, unsigned long address)
16+
{
17+
return ((address & ~image->adsp->alias_mask) | image->adsp->alias_cached);
18+
}
19+
1520
static int elf_read_sections(struct image *image, struct module *module,
1621
int module_index)
1722
{
@@ -110,6 +115,7 @@ static int elf_read_sections(struct image *image, struct module *module,
110115
continue;
111116
}
112117

118+
section[i].vaddr = uncache_to_cache(image, section[i].vaddr);
113119
module->num_sections++;
114120

115121
if (!image->verbose)
@@ -367,8 +373,8 @@ static void elf_module_limits(struct image *image, struct module *module)
367373
/* check programs to get LMA */
368374
section_lma = section->vaddr;
369375
for (j = 0; j < module->hdr.phnum; j++) {
370-
if (section->vaddr == module->prg[j].vaddr) {
371-
section_lma = module->prg[j].paddr;
376+
if (section->vaddr == uncache_to_cache(image, module->prg[j].vaddr)) {
377+
section_lma = uncache_to_cache(image, module->prg[j].paddr);
372378
break;
373379
}
374380
}

src/include/rimage/rimage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ struct adsp {
153153
uint32_t image_size;
154154
uint32_t dram_offset;
155155

156+
uint32_t alias_cached;
157+
uint32_t alias_uncached;
158+
uint32_t alias_mask;
159+
156160
int (*write_firmware_ext_man)(struct image *image);
157161
int (*write_firmware)(struct image *image);
158162
int (*write_firmware_meu)(struct image *image);

0 commit comments

Comments
 (0)