-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rimage: import rimage image creation and signing tool
rimage is being moved from tools repo to sof repo since there is now a cyclic dependency between both repos and sof needs rimage for it's build. Signed-off-by: Liam Girdwood <[email protected]>
- Loading branch information
Showing
26 changed files
with
2,909 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ reef-* | |
boot_ldr-* | ||
boot_module | ||
module | ||
rimage/rimage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
if BUILD_RIMAGE | ||
SUBDIRS = rimage | ||
else | ||
SUBDIRS = src | ||
endif | ||
|
||
ACLOCAL_AMFLAGS = -I m4 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
SUBDIRS=keys | ||
|
||
bin_PROGRAMS = rimage | ||
|
||
noinst_HEADERS = \ | ||
rimage.h \ | ||
css.h \ | ||
cse.h \ | ||
plat_auth.h \ | ||
manifest.h \ | ||
file_format.h | ||
|
||
rimage_SOURCES = \ | ||
file_simple.c \ | ||
man_apl.c \ | ||
man_cnl.c \ | ||
cse.c \ | ||
css.c \ | ||
plat_auth.c \ | ||
hash.c \ | ||
pkcs1_5.c \ | ||
manifest.c \ | ||
elf.c \ | ||
rimage.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2017, 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, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
* Keyon Jie <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "rimage.h" | ||
#include "cse.h" | ||
#include "manifest.h" | ||
|
||
void ri_cse_create(struct image *image) | ||
{ | ||
struct CsePartitionDirHeader *cse_hdr = image->fw_image; | ||
struct sof_man_adsp_meta_file_ext *meta = image->fw_image + | ||
MAN_META_EXT_OFFSET; | ||
struct CsePartitionDirEntry *cse_entry = | ||
image->fw_image + sizeof(*cse_hdr); | ||
uint8_t csum = 0, *val = image->fw_image; | ||
int i, size; | ||
|
||
fprintf(stdout, " cse: completing CSE manifest\n"); | ||
|
||
cse_entry[2].length = meta->comp_desc[0].limit_offset - | ||
MAN_DESC_OFFSET; | ||
|
||
/* calculate checksum using BSD algo */ | ||
size = sizeof(*cse_hdr) + sizeof(*cse_entry) * MAN_CSE_PARTS; | ||
for (i = 0; i < size; i++) { | ||
if (i == 11) | ||
continue; | ||
csum += val[i]; | ||
} | ||
cse_hdr->checksum = 0x100 - csum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2017, 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, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
*/ | ||
|
||
#ifndef __CSE_H__ | ||
#define __CSE_H__ | ||
|
||
#include <stdint.h> | ||
|
||
struct image; | ||
|
||
#define CSE_HEADER_MAKER 0x44504324 /* "DPC$" */ | ||
|
||
struct CsePartitionDirHeader { | ||
uint32_t header_marker; | ||
uint32_t nb_entries; | ||
uint8_t header_version; | ||
uint8_t entry_version; | ||
uint8_t header_length; | ||
uint8_t checksum; | ||
uint8_t partition_name[4]; | ||
} __attribute__((packed)); | ||
|
||
struct CsePartitionDirEntry { | ||
uint8_t entry_name[12]; | ||
uint32_t offset; | ||
uint32_t length; | ||
uint32_t reserved; | ||
} __attribute__((packed)); | ||
|
||
void ri_cse_create(struct image *image); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2017, 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, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* Author: Liam Girdwood <[email protected]> | ||
* Keyon Jie <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <sys/time.h> | ||
#include "rimage.h" | ||
#include "css.h" | ||
#include "manifest.h" | ||
|
||
void ri_css_hdr_create(struct image *image) | ||
{ | ||
struct css_header *css = image->fw_image + MAN_CSS_HDR_OFFSET; | ||
struct tm *date; | ||
struct timeval tv; | ||
int val; | ||
|
||
fprintf(stdout, " cse: completing CSS manifest\n"); | ||
|
||
/* get local time and date */ | ||
gettimeofday(&tv, NULL); | ||
date = localtime(&tv.tv_sec); | ||
date->tm_year += 1900; | ||
fprintf(stdout, " css: set build date to %d:%2.2d:%2.2d\n", | ||
date->tm_year, date->tm_mon, date->tm_mday); | ||
|
||
/* year yYyy */ | ||
val = date->tm_year / 1000; | ||
css->date |= val << 28; | ||
date->tm_year -= val * 1000; | ||
/* year yyYy */ | ||
val = date->tm_year / 100; | ||
css->date |= val << 24; | ||
date->tm_year -= val * 100; | ||
/* year yyyY */ | ||
val = date->tm_year / 10; | ||
css->date |= val << 20; | ||
date->tm_year -= val * 10; | ||
/* year Yyyy */ | ||
val = date->tm_year; | ||
css->date |= val << 16; | ||
|
||
/* month Mm - for some reason month starts at 0 */ | ||
val = ++date->tm_mon / 10; | ||
css->date |= val << 12; | ||
date->tm_mon -= (val * 10); | ||
/* month mM */ | ||
val = date->tm_mon; | ||
css->date |= val << 8; | ||
|
||
/* Day Dd */ | ||
val = date->tm_mday / 10; | ||
css->date |= val << 4; | ||
date->tm_mday -= (val * 10); | ||
/* Day dD */ | ||
val = date->tm_mday; | ||
css->date |= val << 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2017, 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, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
*/ | ||
|
||
#ifndef __CSS_H__ | ||
#define __CSS_H__ | ||
|
||
#include <stdint.h> | ||
|
||
struct image; | ||
|
||
#define MAN_CSS_MOD_TYPE 4 | ||
#define MAN_CSS_HDR_SIZE 161 /* in words */ | ||
#define MAN_CSS_HDR_VERSION 0x10000 | ||
#define MAN_CSS_MOD_VENDOR 0x8086 | ||
#define MAN_CSS_HDR_ID {'$', 'M', 'N', '2'} | ||
|
||
#define MAN_CSS_KEY_SIZE (MAN_RSA_KEY_MODULUS_LEN >> 2) | ||
#define MAN_CSS_MOD_SIZE (MAN_RSA_KEY_MODULUS_LEN >> 2) | ||
#define MAN_CSS_EXP_SIZE (MAN_RSA_KEY_EXPONENT_LEN >> 2) | ||
#define MAN_CSS_MAN_SIZE \ | ||
(sizeof(struct fw_image_manifest) >> 2) | ||
|
||
/* | ||
* RSA Key and Crypto | ||
*/ | ||
#define MAN_RSA_KEY_MODULUS_LEN 256 | ||
#define MAN_RSA_KEY_EXPONENT_LEN 4 | ||
#define MAN_RSA_SIGNATURE_LEN 256 | ||
|
||
struct fw_version { | ||
uint16_t major_version; | ||
uint16_t minor_version; | ||
uint16_t hotfix_version; | ||
uint16_t build_version; | ||
} __attribute__((packed)); | ||
|
||
struct css_header { | ||
uint32_t header_type; | ||
uint32_t header_len; | ||
uint32_t header_version; | ||
uint32_t reserved0; /* must be 0x0 */ | ||
uint32_t module_vendor; | ||
uint32_t date; | ||
uint32_t size; | ||
uint8_t header_id[4]; | ||
uint32_t padding; /* must be 0x0 */ | ||
struct fw_version version; | ||
uint32_t svn; | ||
uint32_t reserved1[18]; /* must be 0x0 */ | ||
uint32_t modulus_size; | ||
uint32_t exponent_size; | ||
uint8_t modulus[MAN_RSA_KEY_MODULUS_LEN]; | ||
uint8_t exponent[MAN_RSA_KEY_EXPONENT_LEN]; | ||
uint8_t signature[MAN_RSA_SIGNATURE_LEN]; | ||
} __attribute__((packed)); | ||
|
||
void ri_css_hdr_create(struct image *image); | ||
|
||
#endif |
Oops, something went wrong.