Skip to content

Commit

Permalink
rimage: add ACE V1.5 handling
Browse files Browse the repository at this point in the history
Add ACE 1.5 set of functions to support v3.0 manifest

Signed-off-by: Krzysztof Frydryk <krzysztofx.frydryk@intel.com>
  • Loading branch information
bkolodzi authored and lgirdwood committed May 26, 2022
1 parent 1b233f6 commit c484d99
Show file tree
Hide file tree
Showing 11 changed files with 574 additions and 3 deletions.
192 changes: 190 additions & 2 deletions src/adsp_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,129 @@ static int parse_signed_pkg_v2_5(const toml_table_t *toml, struct parse_ctx *pct
return 0;
}

static void dump_signed_pkg_ace_v1_5(const struct signed_pkg_info_ext_ace_v1_5 *signed_pkg)
{
int i;

DUMP("\nsigned_pkg");
DUMP_KEY("name", "'%s'", signed_pkg->name);
DUMP_KEY("vcn", "%d", signed_pkg->vcn);
DUMP_KEY("svn", "%d", signed_pkg->svn);
DUMP_KEY("fw_type", "%d", signed_pkg->fw_type);
DUMP_KEY("fw_sub_type", "%d", signed_pkg->fw_sub_type);
for (i = 0; i < ARRAY_SIZE(signed_pkg->module); ++i) {
DUMP_KEY("meta.name", "'%s'", signed_pkg->module[i].name);
DUMP_KEY("meta.type", "0x%x", signed_pkg->module[i].type);
}
}

static int parse_signed_pkg_ace_v1_5(const toml_table_t *toml, struct parse_ctx *pctx,
struct signed_pkg_info_ext_ace_v1_5 *out, bool verbose)
{
struct signed_pkg_info_module_ace_v1_5 *mod;
toml_array_t *module_array;
toml_table_t *signed_pkg;
struct parse_ctx ctx;
toml_table_t *module;
int ret;
int i;

/* look for subtable in toml, increment pctx parsed table cnt and initialize local ctx */
signed_pkg = toml_table_in(toml, "signed_pkg");
if (!signed_pkg)
return err_key_not_found("signed_pkg");
++pctx->table_cnt;
parse_ctx_init(&ctx);

/* non-configurable fields */
out->ext_type = SIGN_PKG_EXT_TYPE_ACE_V1_5;
out->ext_len = sizeof(struct signed_pkg_info_ext_ace_v1_5);

/* configurable fields */
parse_str_key(signed_pkg, &ctx, "name", (char *)out->name, sizeof(out->name), &ret);
if (ret < 0)
return ret;

out->vcn = parse_uint32_key(signed_pkg, &ctx, "vcn", 0, &ret);
if (ret < 0)
return ret;

out->svn = parse_uint32_key(signed_pkg, &ctx, "svn", 0, &ret);
if (ret < 0)
return ret;

out->fw_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
if (ret < 0)
return ret;

out->fw_sub_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
if (ret < 0)
return ret;

out->partition_usage = parse_uint32_hex_key(signed_pkg, &ctx, "partition_usage", 0, &ret);
if (ret < 0)
return ret;

/* check everything parsed, expect 1 more array */
ctx.array_cnt += 1;
ret = assert_everything_parsed(signed_pkg, &ctx);
if (ret < 0)
return ret;

/* modules array */
module_array = toml_array_in(signed_pkg, "module");
if (!module_array)
return err_key_not_found("module");
if (toml_array_kind(module_array) != 't' ||
toml_array_nelem(module_array) != ARRAY_SIZE(out->module))
return err_key_parse("module", "wrong array type or length != %d",
ARRAY_SIZE(out->module));

/* parse modules array elements */
for (i = 0; i < toml_array_nelem(module_array); ++i) {
module = toml_table_at(module_array, i);
if (!module)
return err_key_parse("module", NULL);
mod = &out->module[i];

/* initialize parse context for each array element */
parse_ctx_init(&ctx);

/* non-configurable fields */

/* configurable fields */
parse_str_key(module, &ctx, "name", (char *)mod->name, sizeof(mod->name), &ret);
if (ret < 0)
return err_key_parse("module", NULL);

mod->type = parse_uint32_hex_key(module, &ctx, "type", 0x03, &ret);
if (ret < 0)
return err_key_parse("module", NULL);

mod->hash_algo = parse_uint32_hex_key(module, &ctx, "hash_algo", 0x00, &ret);
if (ret < 0)
return err_key_parse("module", NULL);

mod->meta_size = parse_uint32_key(module, &ctx, "meta_size", 112, &ret);
if (ret < 0)
return err_key_parse("module", NULL);

/* check everything parsed */
ret = assert_everything_parsed(module, &ctx);
if (ret < 0)
return ret;
}

if (verbose)
dump_signed_pkg_ace_v1_5(out);

/*
* values set in other places in code:
* - module.hash
*/

return 0;
}

static void dump_partition_info_ext(const struct partition_info_ext *part_info)
{
Expand Down Expand Up @@ -1664,7 +1787,7 @@ static void dump_fw_desc(const struct sof_man_fw_desc *fw_desc)
DUMP_KEY("preload_page_count", "%d", fw_desc->header.preload_page_count);
DUMP_KEY("fw_image_flags", "0x%x", fw_desc->header.fw_image_flags);
DUMP_KEY("feature_mask", "0x%x", fw_desc->header.feature_mask);
DUMP_KEY("hw_buf_base_addr", "0x%x", fw_desc->header.hw_buf_base_addr);
DUMP_KEY("hw_buf_base_addr", "0x%x", fw_desc->header.fw_compat);
DUMP_KEY("hw_buf_length", "0x%x", fw_desc->header.hw_buf_length);
DUMP_KEY("load_offset", "0x%x", fw_desc->header.load_offset);
}
Expand Down Expand Up @@ -1723,7 +1846,7 @@ static int parse_fw_desc(const toml_table_t *toml, struct parse_ctx *pctx,
if (ret < 0)
return err_key_parse("header", NULL);

out->header.hw_buf_base_addr =
out->header.fw_compat =
parse_uint32_hex_key(header, &ctx, "hw_buf_base_addr", 0, &ret);
if (ret < 0)
return err_key_parse("header", NULL);
Expand Down Expand Up @@ -2342,6 +2465,70 @@ static int parse_adsp_config_v2_5(const toml_table_t *toml, struct adsp *out,
return 0;
}

static int parse_adsp_config_ace_v1_5(const toml_table_t *toml, struct adsp *out,
bool verbose)
{
struct parse_ctx ctx;
int ret;

out->man_ace_v1_5 = malloc(sizeof(struct fw_image_manifest_ace_v1_5));
if (!out->man_ace_v1_5)
return err_malloc("man_ace_v1_5");

/* clear memory */
memset(out->man_ace_v1_5, 0, sizeof(*out->man_ace_v1_5));

/* assign correct write functions */
out->write_firmware = man_write_fw_ace_v1_5;
out->write_firmware_meu = man_write_fw_meu_v2_5;
out->verify_firmware = ri_manifest_verify_v2_5;

/* version array has already been parsed, so increment ctx.array_cnt */
parse_ctx_init(&ctx);
++ctx.array_cnt;

/* parse each toml subtable */
ret = parse_adsp(toml, &ctx, out, verbose);
if (ret < 0)
return err_key_parse("adsp", NULL);

ret = parse_cse_v2_5(toml, &ctx, &out->man_ace_v1_5->cse_partition_dir_header,
out->man_ace_v1_5->cse_partition_dir_entry, 3, verbose);
if (ret < 0)
return err_key_parse("cse", NULL);

ret = parse_css_v2_5(toml, &ctx, &out->man_ace_v1_5->css, verbose);
if (ret < 0)
return err_key_parse("css", NULL);

ret = parse_signed_pkg_ace_v1_5(toml, &ctx, &out->man_ace_v1_5->signed_pkg, verbose);
if (ret < 0)
return err_key_parse("signed_pkg", NULL);

ret = parse_info_ext_0x16(toml, &ctx, &out->man_ace_v1_5->info_0x16, verbose);
if (ret < 0)
return err_key_parse("partition_info", NULL);

ret = parse_adsp_file_ext_v2_5(toml, &ctx, &out->man_ace_v1_5->adsp_file_ext, verbose);
if (ret < 0)
return err_key_parse("adsp_file", NULL);

ret = parse_fw_desc(toml, &ctx, &out->man_ace_v1_5->desc, verbose);
if (ret < 0)
return err_key_parse("fw_desc", NULL);

ret = parse_module(toml, &ctx, out, verbose);
if (ret < 0)
return err_key_parse("module", NULL);

/* check everything parsed */
ret = assert_everything_parsed(toml, &ctx);
if (ret < 0)
return ret;

return 0;
}

/** version is stored as toml array with integer number, something like:
* "version = [1, 8]"
*/
Expand Down Expand Up @@ -2386,6 +2573,7 @@ static const struct config_parser *find_config_parser(int64_t version[2])
{1, 5, parse_adsp_config_v1_5},
{1, 8, parse_adsp_config_v1_8},
{2, 5, parse_adsp_config_v2_5},
{3, 0, parse_adsp_config_ace_v1_5},
};
int i;

Expand Down
30 changes: 30 additions & 0 deletions src/cse.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,33 @@ void ri_cse_create_v2_5(struct image *image)

fprintf(stdout, " cse: cse checksum %x\n", cse_hdr->checksum);
}

void ri_cse_create_ace_v1_5(struct image *image)
{
struct CsePartitionDirHeader_v2_5 *cse_hdr = image->fw_image;
struct sof_man_adsp_meta_file_ext_v2_5 *meta = image->fw_image +
MAN_META_EXT_OFFSET_ACE_V1_5;
struct CsePartitionDirEntry *cse_entry =
image->fw_image + sizeof(*cse_hdr);
uint8_t *val = image->fw_image;
int size;

fprintf(stdout, " cse: completing CSE V2.5 manifest\n");

cse_entry[2].length = meta->comp_desc[0].limit_offset -
MAN_DESC_OFFSET_V1_8;

/*
* calculate checksum using crc-32/iso-hdlc
*
* polynomial: 0x04c11db7
* initial value: 0xffffffff
* reverse input: true
* reverse output: true
* xor output: 0xffffffff
*/
size = (sizeof(*cse_hdr) + (sizeof(*cse_entry) * MAN_CSE_PARTS));
cse_hdr->checksum = crc32(val, size, 0x04c11db7, 0xffffffff, true, true, 0xffffffff);

fprintf(stdout, " cse: cse checksum %x\n", cse_hdr->checksum);
}
1 change: 1 addition & 0 deletions src/include/rimage/cse.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ struct CsePartitionDirEntry {

void ri_cse_create(struct image *image);
void ri_cse_create_v2_5(struct image *image);
void ri_cse_create_ace_v1_5(struct image *image);

#endif
41 changes: 41 additions & 0 deletions src/include/rimage/manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@
sizeof(struct CsePartitionDirHeader_v2_5) + \
MAN_CSE_PARTS * sizeof(struct CsePartitionDirEntry))

#define MAN_FW_DESC_OFFSET_ACE_V1_5 \
(MAN_META_EXT_OFFSET_ACE_V1_5 + \
sizeof(struct sof_man_adsp_meta_file_ext_v2_5) + \
MAN_EXT_PADDING)

#define MAN_FW_DESC_OFFSET_V2_5 \
(MAN_META_EXT_OFFSET_V2_5 + \
sizeof(struct sof_man_adsp_meta_file_ext_v2_5) + \
MAN_EXT_PADDING)

#define MAN_DESC_PADDING_SIZE_ACE_V1_5 \
(MAN_DESC_OFFSET_V1_8 - MAN_FW_DESC_OFFSET_ACE_V1_5)

#define MAN_DESC_PADDING_SIZE_V2_5 \
(MAN_DESC_OFFSET_V1_8 - MAN_FW_DESC_OFFSET_V2_5)

Expand All @@ -66,6 +74,10 @@
(MAN_SIG_PKG_OFFSET_V1_8 + \
sizeof(struct signed_pkg_info_ext))

#define MAN_PART_INFO_OFFSET_ACE_V1_5 \
(MAN_SIG_PKG_OFFSET_V2_5 + \
sizeof(struct signed_pkg_info_ext_ace_v1_5))

#define MAN_PART_INFO_OFFSET_V2_5 \
(MAN_SIG_PKG_OFFSET_V2_5 + \
sizeof(struct signed_pkg_info_ext_v2_5))
Expand All @@ -76,6 +88,12 @@
sizeof(struct partition_info_ext) + \
MAN_CSE_PADDING_SIZE)

#define MAN_META_EXT_OFFSET_ACE_V1_5 \
(MAN_SIG_PKG_OFFSET_V2_5 + \
sizeof(struct signed_pkg_info_ext_ace_v1_5) + \
sizeof(struct info_ext_0x16) + \
0)

#define MAN_META_EXT_OFFSET_V2_5 \
(MAN_SIG_PKG_OFFSET_V2_5 + \
sizeof(struct signed_pkg_info_ext_v2_5) + \
Expand Down Expand Up @@ -105,6 +123,28 @@
sizeof(struct sof_man_adsp_meta_file_ext_v1_8) + \
MAN_EXT_PADDING)

/*
* Firmware manifest header ACE V1_5 used on MTL onwards
*/
struct fw_image_manifest_ace_v1_5 {
/* MEU tool needs these sections to be 0s */
struct CsePartitionDirHeader_v2_5 cse_partition_dir_header;
struct CsePartitionDirEntry cse_partition_dir_entry[MAN_CSE_PARTS];
struct css_header_v2_5 css;
struct signed_pkg_info_ext_ace_v1_5 signed_pkg;
struct info_ext_0x16 info_0x16;

struct sof_man_adsp_meta_file_ext_v2_5 adsp_file_ext;

/* reserved / pading at end of ext data - all 0s*/
uint8_t reserved[MAN_EXT_PADDING];

/* start of the unsigned binary for MEU input must start at MAN_DESC_OFFSET */
uint8_t padding[MAN_DESC_PADDING_SIZE_ACE_V1_5];

struct sof_man_fw_desc desc; /* at offset MAN_DESC_OFFSET */
} __attribute__((packed));

/*
* Firmware manifest header V2.5 used on TGL onwards
*/
Expand Down Expand Up @@ -167,6 +207,7 @@ int man_write_fw_v1_5(struct image *image);
int man_write_fw_v1_5_sue(struct image *image);
int man_write_fw_v1_8(struct image *image);
int man_write_fw_v2_5(struct image *image);
int man_write_fw_ace_v1_5(struct image *image);
int man_write_fw_meu_v1_5(struct image *image);
int man_write_fw_meu_v1_8(struct image *image);
int man_write_fw_meu_v2_5(struct image *image);
Expand Down
30 changes: 30 additions & 0 deletions src/include/rimage/plat_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct image;
#define SIGN_PKG_EXT_TYPE 15
#define SIGN_PKG_NUM_MODULE 1

#define SIGN_PKG_EXT_TYPE_ACE_V1_5 0x23

struct signed_pkg_info_module {
uint8_t name[PLAT_AUTH_NAME_LEN]; /* must be padded with 0 */
uint8_t type;
Expand Down Expand Up @@ -68,6 +70,33 @@ struct signed_pkg_info_ext_v2_5 {
struct signed_pkg_info_module_v2_5 module[SIGN_PKG_NUM_MODULE];
} __attribute__((packed));

struct signed_pkg_info_module_ace_v1_5 {
uint8_t name[PLAT_AUTH_NAME_LEN]; /* must be padded with 0 */
uint8_t type;
uint8_t hash_algo;
uint8_t reserved[2];
uint32_t meta_size;
uint8_t hash[PLAT_AUTH_SHA384_LEN];
} __attribute__((packed));

struct signed_pkg_info_ext_ace_v1_5 {
uint32_t ext_type;
uint32_t ext_len;

uint8_t name[4];
uint32_t vcn; /* 0 */
uint32_t svn;
uint8_t partition_usage;
uint8_t reserved0;
uint8_t fw_type;
uint8_t fw_sub_type;
uint8_t number_of_modules;
uint8_t boot_strap_svn;
uint8_t reserved[14]; /* must be 0 */

/* variable length of modules */
struct signed_pkg_info_module_ace_v1_5 module[SIGN_PKG_NUM_MODULE];
} __attribute__((packed));

#define PART_INFO_EXT_TYPE 3
#define PART_INFO_NUM_MODULE 1
Expand Down Expand Up @@ -121,5 +150,6 @@ void ri_adsp_meta_data_create_v2_5(struct image *image, int meta_start_offset,
int meta_end_offset);
void ri_plat_ext_data_create(struct image *image);
void ri_plat_ext_data_create_v2_5(struct image *image);
void ri_plat_ext_data_create_ace_v1_5(struct image *image);

#endif
Loading

0 comments on commit c484d99

Please sign in to comment.