diff --git a/rimage/css.c b/rimage/css.c index 6c87025a0..9f5db485e 100644 --- a/rimage/css.c +++ b/rimage/css.c @@ -20,9 +20,9 @@ #include "css.h" #include "manifest.h" -void ri_css_hdr_create_v1_8(struct image *image) +void ri_css_hdr_create(struct image *image) { - struct css_header_v1_8 *css = image->fw_image + MAN_CSS_HDR_OFFSET_V1_8; + struct css_header_v1_8 *css = image->fw_image + MAN_CSS_HDR_OFFSET; struct tm *date; struct timeval tv; int val; diff --git a/rimage/css.h b/rimage/css.h index 13135c55e..b87d613dc 100644 --- a/rimage/css.h +++ b/rimage/css.h @@ -84,6 +84,6 @@ struct css_header_v1_5 { uint8_t signature[MAN_RSA_SIGNATURE_LEN]; } __attribute__((packed)); -void ri_css_hdr_create_v1_8(struct image *image); +void ri_css_hdr_create(struct image *image); #endif diff --git a/rimage/man_apl.c b/rimage/man_apl.c index 201e4361f..7ad330f6c 100644 --- a/rimage/man_apl.c +++ b/rimage/man_apl.c @@ -35,7 +35,7 @@ struct fw_image_manifest_v1_8 apl_manifest = { { /* CssHeader + platformFirmwareAuthenticationExtension - padding */ .entry_name = "ADSP.man", - .offset = MAN_CSS_HDR_OFFSET_V1_8, + .offset = MAN_CSS_HDR_OFFSET, .length = sizeof(struct css_header_v1_8) + PLAT_AUTH_SIZE, }, diff --git a/rimage/man_cnl.c b/rimage/man_cnl.c index 575b260a1..64d6424b0 100644 --- a/rimage/man_cnl.c +++ b/rimage/man_cnl.c @@ -34,7 +34,7 @@ struct fw_image_manifest_v1_8 cnl_manifest = { { /* CssHeader + platformFirmwareAuthenticationExtension - padding */ .entry_name = "ADSP.man", - .offset = MAN_CSS_HDR_OFFSET_V1_8, + .offset = MAN_CSS_HDR_OFFSET, .length = sizeof(struct css_header_v1_8) + PLAT_AUTH_SIZE, }, diff --git a/rimage/man_kbl.c b/rimage/man_kbl.c index 5e614f551..4d5f5464d 100644 --- a/rimage/man_kbl.c +++ b/rimage/man_kbl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation. + * Copyright (c) 2018, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -18,6 +18,11 @@ #include #include +/* + * TODO: check if all platform for 1.5 are the same base and length. + * if yes, define it as HARDWARE_BUFFER_BASE_V1_5, HARDWARE_BUFFER_LEN_v1_5 + * if not, define a platform specific base and length. + */ #define KBL_HARDWARE_BUFFER_BASE 0xBE500000 #define KBL_HARDWARE_BUFFER_LEN 0x4A000 diff --git a/rimage/manifest.c b/rimage/manifest.c index 6e7ff9bbe..49dc36a78 100644 --- a/rimage/manifest.c +++ b/rimage/manifest.c @@ -703,11 +703,7 @@ static int man_write_fw_v1_5(struct image *image) fprintf(stdout, "Firmware completing manifest v1.5\n"); /* create structures from end of file to start of file */ - ri_adsp_meta_data_create(image, MAN_META_EXT_OFFSET_V1_8, - MAN_FW_DESC_OFFSET_V1_8); - ri_plat_ext_data_create(image); - ri_css_hdr_create_v1_8(image); - ri_cse_create(image); + ri_css_hdr_create(image); fprintf(stdout, "Firmware file size 0x%x page count %d\n", FILE_TEXT_OFFSET - MAN_DESC_OFFSET + image->image_end, @@ -727,8 +723,8 @@ static int man_write_fw_v1_5(struct image *image) goto err; /* write the unsigned files*/ - ret = man_write_unsigned_mod(image, MAN_META_EXT_OFFSET_V1_8, - MAN_FW_DESC_OFFSET_V1_8); + ret = man_write_unsigned_mod(image, MAN_META_EXT_OFFSET_V1_5, + MAN_FW_DESC_OFFSET_V1_5); if (ret < 0) goto err; @@ -785,7 +781,7 @@ static int man_write_fw_v1_8(struct image *image) ri_adsp_meta_data_create(image, MAN_META_EXT_OFFSET_V1_8, MAN_FW_DESC_OFFSET_V1_8); ri_plat_ext_data_create(image); - ri_css_hdr_create_v1_8(image); + ri_css_hdr_create(image); ri_cse_create(image); fprintf(stdout, "Firmware file size 0x%x page count %d\n", @@ -985,6 +981,14 @@ err: #define ADSP_APL_DSP_ROM_SIZE 0x00002000 #define APL_DSP_BASE_ENTRY 0xa000a000 +#define ADSP_KBL_DSP_ROM_BASE 0xBEFE0000 +#define ADSP_KBL_DSP_ROM_SIZE 0x00002000 +#define KBL_DSP_BASE_ENTRY 0xa000a000 + +#define ADSP_SKL_DSP_ROM_BASE 0xBEFE0000 +#define ADSP_SKL_DSP_ROM_SIZE 0x00002000 +#define SKL_DSP_BASE_ENTRY 0xa000a000 + #define ADSP_CNL_DSP_ROM_BASE 0xBEFE0000 #define ADSP_CNL_DSP_ROM_SIZE 0x00002000 #define CNL_DSP_IMR_BASE_ENTRY 0xb0038000 @@ -1017,9 +1021,9 @@ const struct adsp machine_apl = { const struct adsp machine_kbl = { .name = "kbl", - .rom_base = ADSP_APL_DSP_ROM_BASE, - .rom_size = ADSP_APL_DSP_ROM_SIZE, - .sram_base = APL_DSP_BASE_ENTRY, + .rom_base = ADSP_KBL_DSP_ROM_BASE, + .rom_size = ADSP_KBL_DSP_ROM_SIZE, + .sram_base = KBL_DSP_BASE_ENTRY, .sram_size = 0x100000, .image_size = 0x100000, .dram_offset = 0, @@ -1031,9 +1035,9 @@ const struct adsp machine_kbl = { const struct adsp machine_skl = { .name = "skl", - .rom_base = ADSP_APL_DSP_ROM_BASE, - .rom_size = ADSP_APL_DSP_ROM_SIZE, - .sram_base = APL_DSP_BASE_ENTRY, + .rom_base = ADSP_SKL_DSP_ROM_BASE, + .rom_size = ADSP_SKL_DSP_ROM_SIZE, + .sram_base = SKL_DSP_BASE_ENTRY, .sram_size = 0x100000, .image_size = 0x100000, .dram_offset = 0, diff --git a/rimage/manifest.h b/rimage/manifest.h index 4c53a69a0..c57bcb0eb 100644 --- a/rimage/manifest.h +++ b/rimage/manifest.h @@ -39,13 +39,13 @@ #define MAN_EXT_PADDING 0x20 #define MAN_DESC_OFFSET 0x2000 -#define MAN_CSS_HDR_OFFSET_V1_8 \ +#define MAN_CSS_HDR_OFFSET \ (MAN_CSE_HDR_OFFSET + \ sizeof(struct CsePartitionDirHeader) + \ MAN_CSE_PARTS * sizeof(struct CsePartitionDirEntry)) #define MAN_SIG_PKG_OFFSET_V1_8 \ - (MAN_CSS_HDR_OFFSET_V1_8 + \ + (MAN_CSS_HDR_OFFSET + \ sizeof(struct css_header_v1_8)) #define MAN_PART_INFO_OFFSET_V1_8 \ @@ -66,6 +66,21 @@ #define MAN_DESC_PADDING_SIZE_V1_8 \ (MAN_DESC_OFFSET - MAN_FW_DESC_OFFSET_V1_8) +#define MAN_SIG_PKG_OFFSET_V1_5 \ + (MAN_CSS_HDR_OFFSET + \ + sizeof(struct css_header_v1_5)) + +#define MAN_META_EXT_OFFSET_V1_5 \ + (MAN_SIG_PKG_OFFSET_V1_5 + \ + sizeof(struct signed_pkg_info_ext) + \ + sizeof(struct partition_info_ext) + \ + MAN_CSE_PADDING_SIZE) + +#define MAN_FW_DESC_OFFSET_V1_5 \ + (MAN_META_EXT_OFFSET_V1_5 + \ + sizeof(struct sof_man_adsp_meta_file_ext) + \ + MAN_EXT_PADDING) + /* * Firmware manifest header V1.8 used on APL onwards */ @@ -99,6 +114,10 @@ struct fw_image_manifest_v1_5 { struct sof_man_fw_desc desc; } __attribute__((packed)); +/* + * TODO: verify if we need platform specific manifest, or just + * define manifest_v1_5 and manifest_v1_8. + */ extern struct fw_image_manifest_v1_5 skl_manifest; extern struct fw_image_manifest_v1_5 kbl_manifest; #endif diff --git a/rimage/pkcs1_5.c b/rimage/pkcs1_5.c index d78210968..309d3b472 100644 --- a/rimage/pkcs1_5.c +++ b/rimage/pkcs1_5.c @@ -68,8 +68,9 @@ static void bytes_swap(uint8_t *ptr, uint32_t size) * manifest header (Public Key, Exponent and Signature). */ -int pkcs_sign_v1_5(struct image *image, struct fw_image_manifest_v1_5 *man, - void *ptr1, unsigned int size1) +int pkcs_v1_5_sign_man_v1_5(struct image *image, + struct fw_image_manifest_v1_5 *man, + void *ptr1, unsigned int size1) { RSA *priv_rsa = NULL; EVP_PKEY *privkey; @@ -159,9 +160,10 @@ int pkcs_sign_v1_5(struct image *image, struct fw_image_manifest_v1_5 *man, * manifest header (Public Key, Exponent and Signature). */ -int pkcs_sign_v1_8(struct image *image, struct fw_image_manifest_v1_8 *man, - void *ptr1, unsigned int size1, void *ptr2, - unsigned int size2) +int pkcs_v1_5_sign_man_v1_8(struct image *image, + struct fw_image_manifest_v1_8 *man, + void *ptr1, unsigned int size1, void *ptr2, + unsigned int size2) { RSA *priv_rsa = NULL; EVP_PKEY *privkey; @@ -245,8 +247,9 @@ int ri_manifest_sign_v1_5(struct image *image) { struct fw_image_manifest_v1_5 *man = image->fw_image; - pkcs_sign_v1_5(image, man, (void *)man + MAN_CSS_MAN_SIZE_V1_5, - image->image_end - sizeof(*man)); + pkcs_v1_5_sign_man_v1_5(image, man, + (void *)man + MAN_CSS_MAN_SIZE_V1_5, + image->image_end - sizeof(*man)); return 0; } @@ -254,12 +257,13 @@ int ri_manifest_sign_v1_8(struct image *image) { struct fw_image_manifest_v1_8 *man = image->fw_image; - pkcs_sign_v1_8(image, man, (void *)man + MAN_CSS_HDR_OFFSET_V1_8, - sizeof(struct css_header_v1_8) - - (MAN_RSA_KEY_MODULUS_LEN + MAN_RSA_KEY_EXPONENT_LEN + - MAN_RSA_SIGNATURE_LEN), - (void *)man + MAN_SIG_PKG_OFFSET_V1_8, - (man->css.size - man->css.header_len) - * sizeof(uint32_t)); + pkcs_v1_5_sign_man_v1_8(image, man, (void *)man + MAN_CSS_HDR_OFFSET, + sizeof(struct css_header_v1_8) - + (MAN_RSA_KEY_MODULUS_LEN + + MAN_RSA_KEY_EXPONENT_LEN + + MAN_RSA_SIGNATURE_LEN), + (void *)man + MAN_SIG_PKG_OFFSET_V1_8, + (man->css.size - man->css.header_len) + * sizeof(uint32_t)); return 0; } diff --git a/rimage/rimage.h b/rimage/rimage.h index a1c7d4648..a9a161cdc 100644 --- a/rimage/rimage.h +++ b/rimage/rimage.h @@ -162,11 +162,13 @@ int ri_manifest_sign_v1_5(struct image *image); int ri_manifest_sign_v1_8(struct image *image); void ri_hash(struct image *image, unsigned offset, unsigned size, uint8_t *hash); -int pkcs_sign_v1_5(struct image *image, struct fw_image_manifest_v1_5 *man, - void *ptr1, unsigned int size1); -int pkcs_sign_v1_8(struct image *image, struct fw_image_manifest_v1_8 *man, - void *ptr1, unsigned int size1, void *ptr2, - unsigned int size2); +int pkcs_v1_5_sign_man_v1_5(struct image *image, + struct fw_image_manifest_v1_5 *man, + void *ptr1, unsigned int size1); +int pkcs_v1_5_sign_man_v1_8(struct image *image, + struct fw_image_manifest_v1_8 *man, + void *ptr1, unsigned int size1, void *ptr2, + unsigned int size2); int elf_parse_module(struct image *image, int module_index, const char *name); void elf_free_module(struct image *image, int module_index);