Skip to content

Commit 05ef434

Browse files
committed
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 <liam.r.girdwood@linux.intel.com>
1 parent bf3c0f2 commit 05ef434

26 files changed

Lines changed: 2909 additions & 11 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ reef-*
4848
boot_ldr-*
4949
boot_module
5050
module
51+
rimage/rimage

‎Makefile.am‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
if BUILD_RIMAGE
2+
SUBDIRS = rimage
3+
else
14
SUBDIRS = src
5+
endif
26

37
ACLOCAL_AMFLAGS = -I m4
48

‎README‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ Build Instructions
33

44
1) Run "autogen.sh"
55

6-
2) Run the following configure based on your platform.
6+
2) Build and install the rimage ELF image creator and signing tool
7+
8+
./configure --enable-rimage
9+
make
10+
sudo make install
11+
12+
3) Run the following configure based on your platform.
713

814
Baytrail :-
915

@@ -20,8 +26,8 @@ headers
2026

2127
./configure --with-arch=host --enable-library=yes --host=x86_64-unknown-linux-gnu --prefix=$pwd/../host-root/
2228

23-
3) make
29+
4) make
2430

25-
4) make bin
31+
5) make bin
2632

2733

‎configure.ac‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ AC_DEFINE_UNQUOTED([REEF_MICRO], reef_micro, [Reef micro version])
1919
AC_CANONICAL_HOST
2020

2121
# General compiler flags
22-
CFLAGS="${CFLAGS:+$CFLAGS } -O2 -g -Wall -Werror -Wl,-EL -fno-inline-functions -nostdlib -Wmissing-prototypes"
22+
CFLAGS="${CFLAGS:+$CFLAGS } -O2 -g -Wall -Werror -Wl,-EL -Wmissing-prototypes"
2323

2424
# General assembler flags
2525
ASFLAGS="-DASSEMBLY"
@@ -37,6 +37,13 @@ if test "$have_library" = "yes"; then
3737
fi
3838
AM_CONDITIONAL(BUILD_LIB, test "$have_library" = "yes")
3939

40+
# check if we are building tools
41+
AC_ARG_ENABLE(rimage, [AS_HELP_STRING([--enable-rimage],[build rimage tool])], have_rimage=$enableval, have_rimage=no)
42+
if test "$have_rimage" = "yes"; then
43+
AC_DEFINE([CONFIG_RIMAGE], [1], [Configure to build rimage])
44+
fi
45+
AM_CONDITIONAL(BUILD_RIMAGE, test "$have_rimage" = "yes")
46+
4047
# Architecture support
4148
AC_ARG_WITH([arch],
4249
AS_HELP_STRING([--with-arch], [Specify DSP architecture]),
@@ -52,7 +59,7 @@ case "$with_arch" in
5259
AC_SUBST(XTENSA_LDFLAGS)
5360

5461
# extra CFLAGS defined here otherwise configure working gcc tests fails.
55-
CFLAGS="${CFLAGS:+$CFLAGS }-mlongcalls"
62+
CFLAGS="${CFLAGS:+$CFLAGS }-fno-inline-functions -nostdlib -mlongcalls"
5663
LDFLAGS="${LDFLAGS:+$LDFLAGS }-nostdlib"
5764

5865
#ARCH_ASFLAGS=""
@@ -79,7 +86,9 @@ case "$with_arch" in
7986
AC_SUBST(ARCH)
8087
;;
8188
*)
82-
AC_MSG_ERROR([DSP architecture not specified])
89+
if test "$have_rimage" = "no"; then
90+
AC_MSG_ERROR([DSP architecture not specified])
91+
fi
8392
;;
8493
esac
8594

@@ -197,11 +206,13 @@ case "$with_platform" in
197206
AC_DEFINE([CONFIG_DMA_GW], [1], [Configure DMA Gateway])
198207
;;
199208
*)
200-
if test "$ARCH" = "host"; then
201-
PLATFORM="host"
202-
AC_SUBST(PLATFORM)
203-
else
204-
AC_MSG_ERROR([Host platform not specified])
209+
if test "$have_rimage" = "no"; then
210+
if test "$ARCH" = "host"; then
211+
PLATFORM="host"
212+
AC_SUBST(PLATFORM)
213+
else
214+
AC_MSG_ERROR([Host platform not specified])
215+
fi
205216
fi
206217
;;
207218
esac
@@ -315,12 +326,26 @@ LT_INIT
315326
AC_CHECK_TOOL([OBJCOPY], [objcopy], [])
316327
AC_CHECK_TOOL([OBJDUMP], [objdump], [])
317328

329+
# Check for openssl - used by rimage
330+
AC_CHECK_LIB([crypto], [OPENSSL_config], , [have_openssl="no"])
331+
if test "$have_rimage" = "yes"; then
332+
if test "$have_openssl" = "no"; then
333+
AC_MSG_ERROR([Need OpenSSL libcrypto for rimage code signing])
334+
fi
335+
fi
336+
337+
PEM_KEY_PREFIX="/usr/local/share/rimage"
338+
AC_DEFINE_UNQUOTED([PEM_KEY_PREFIX], ["$PEM_KEY_PREFIX"], ["Path for PEM keys"])
339+
AC_SUBST(PEM_KEY_PREFIX)
340+
318341
AM_EXTRA_RECURSIVE_TARGETS([bin])
319342

320343
AM_EXTRA_RECURSIVE_TARGETS([vminstall])
321344

322345
AC_CONFIG_FILES([
323346
Makefile
347+
rimage/Makefile
348+
rimage/keys/Makefile
324349
src/Makefile
325350
src/tasks/Makefile
326351
src/init/Makefile
@@ -380,6 +405,7 @@ echo "
380405
Target Architecture: ${ARCH}
381406
Target Platform: ${PLATFORM}
382407
Target Core: ${XTENSA_CORE}
408+
PEM: ${PEM_KEY_PREFIX}
383409

384410
Compiler: ${CC}
385411
CFLAGS: ${CFLAGS}

‎rimage/Makefile.am‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SUBDIRS=keys
2+
3+
bin_PROGRAMS = rimage
4+
5+
noinst_HEADERS = \
6+
rimage.h \
7+
css.h \
8+
cse.h \
9+
plat_auth.h \
10+
manifest.h \
11+
file_format.h
12+
13+
rimage_SOURCES = \
14+
file_simple.c \
15+
man_apl.c \
16+
man_cnl.c \
17+
cse.c \
18+
css.c \
19+
plat_auth.c \
20+
hash.c \
21+
pkcs1_5.c \
22+
manifest.c \
23+
elf.c \
24+
rimage.c
25+

‎rimage/cse.c‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
14+
* Keyon Jie <yang.jie@linux.intel.com>
15+
*/
16+
17+
#include <stdio.h>
18+
#include "rimage.h"
19+
#include "cse.h"
20+
#include "manifest.h"
21+
22+
void ri_cse_create(struct image *image)
23+
{
24+
struct CsePartitionDirHeader *cse_hdr = image->fw_image;
25+
struct sof_man_adsp_meta_file_ext *meta = image->fw_image +
26+
MAN_META_EXT_OFFSET;
27+
struct CsePartitionDirEntry *cse_entry =
28+
image->fw_image + sizeof(*cse_hdr);
29+
uint8_t csum = 0, *val = image->fw_image;
30+
int i, size;
31+
32+
fprintf(stdout, " cse: completing CSE manifest\n");
33+
34+
cse_entry[2].length = meta->comp_desc[0].limit_offset -
35+
MAN_DESC_OFFSET;
36+
37+
/* calculate checksum using BSD algo */
38+
size = sizeof(*cse_hdr) + sizeof(*cse_entry) * MAN_CSE_PARTS;
39+
for (i = 0; i < size; i++) {
40+
if (i == 11)
41+
continue;
42+
csum += val[i];
43+
}
44+
cse_hdr->checksum = 0x100 - csum;
45+
}

‎rimage/cse.h‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*/
13+
14+
#ifndef __CSE_H__
15+
#define __CSE_H__
16+
17+
#include <stdint.h>
18+
19+
struct image;
20+
21+
#define CSE_HEADER_MAKER 0x44504324 /* "DPC$" */
22+
23+
struct CsePartitionDirHeader {
24+
uint32_t header_marker;
25+
uint32_t nb_entries;
26+
uint8_t header_version;
27+
uint8_t entry_version;
28+
uint8_t header_length;
29+
uint8_t checksum;
30+
uint8_t partition_name[4];
31+
} __attribute__((packed));
32+
33+
struct CsePartitionDirEntry {
34+
uint8_t entry_name[12];
35+
uint32_t offset;
36+
uint32_t length;
37+
uint32_t reserved;
38+
} __attribute__((packed));
39+
40+
void ri_cse_create(struct image *image);
41+
42+
#endif

‎rimage/css.c‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
14+
* Keyon Jie <yang.jie@linux.intel.com>
15+
*/
16+
17+
#include <stdio.h>
18+
#include <sys/time.h>
19+
#include "rimage.h"
20+
#include "css.h"
21+
#include "manifest.h"
22+
23+
void ri_css_hdr_create(struct image *image)
24+
{
25+
struct css_header *css = image->fw_image + MAN_CSS_HDR_OFFSET;
26+
struct tm *date;
27+
struct timeval tv;
28+
int val;
29+
30+
fprintf(stdout, " cse: completing CSS manifest\n");
31+
32+
/* get local time and date */
33+
gettimeofday(&tv, NULL);
34+
date = localtime(&tv.tv_sec);
35+
date->tm_year += 1900;
36+
fprintf(stdout, " css: set build date to %d:%2.2d:%2.2d\n",
37+
date->tm_year, date->tm_mon, date->tm_mday);
38+
39+
/* year yYyy */
40+
val = date->tm_year / 1000;
41+
css->date |= val << 28;
42+
date->tm_year -= val * 1000;
43+
/* year yyYy */
44+
val = date->tm_year / 100;
45+
css->date |= val << 24;
46+
date->tm_year -= val * 100;
47+
/* year yyyY */
48+
val = date->tm_year / 10;
49+
css->date |= val << 20;
50+
date->tm_year -= val * 10;
51+
/* year Yyyy */
52+
val = date->tm_year;
53+
css->date |= val << 16;
54+
55+
/* month Mm - for some reason month starts at 0 */
56+
val = ++date->tm_mon / 10;
57+
css->date |= val << 12;
58+
date->tm_mon -= (val * 10);
59+
/* month mM */
60+
val = date->tm_mon;
61+
css->date |= val << 8;
62+
63+
/* Day Dd */
64+
val = date->tm_mday / 10;
65+
css->date |= val << 4;
66+
date->tm_mday -= (val * 10);
67+
/* Day dD */
68+
val = date->tm_mday;
69+
css->date |= val << 0;
70+
}

‎rimage/css.h‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*/
13+
14+
#ifndef __CSS_H__
15+
#define __CSS_H__
16+
17+
#include <stdint.h>
18+
19+
struct image;
20+
21+
#define MAN_CSS_MOD_TYPE 4
22+
#define MAN_CSS_HDR_SIZE 161 /* in words */
23+
#define MAN_CSS_HDR_VERSION 0x10000
24+
#define MAN_CSS_MOD_VENDOR 0x8086
25+
#define MAN_CSS_HDR_ID {'$', 'M', 'N', '2'}
26+
27+
#define MAN_CSS_KEY_SIZE (MAN_RSA_KEY_MODULUS_LEN >> 2)
28+
#define MAN_CSS_MOD_SIZE (MAN_RSA_KEY_MODULUS_LEN >> 2)
29+
#define MAN_CSS_EXP_SIZE (MAN_RSA_KEY_EXPONENT_LEN >> 2)
30+
#define MAN_CSS_MAN_SIZE \
31+
(sizeof(struct fw_image_manifest) >> 2)
32+
33+
/*
34+
* RSA Key and Crypto
35+
*/
36+
#define MAN_RSA_KEY_MODULUS_LEN 256
37+
#define MAN_RSA_KEY_EXPONENT_LEN 4
38+
#define MAN_RSA_SIGNATURE_LEN 256
39+
40+
struct fw_version {
41+
uint16_t major_version;
42+
uint16_t minor_version;
43+
uint16_t hotfix_version;
44+
uint16_t build_version;
45+
} __attribute__((packed));
46+
47+
struct css_header {
48+
uint32_t header_type;
49+
uint32_t header_len;
50+
uint32_t header_version;
51+
uint32_t reserved0; /* must be 0x0 */
52+
uint32_t module_vendor;
53+
uint32_t date;
54+
uint32_t size;
55+
uint8_t header_id[4];
56+
uint32_t padding; /* must be 0x0 */
57+
struct fw_version version;
58+
uint32_t svn;
59+
uint32_t reserved1[18]; /* must be 0x0 */
60+
uint32_t modulus_size;
61+
uint32_t exponent_size;
62+
uint8_t modulus[MAN_RSA_KEY_MODULUS_LEN];
63+
uint8_t exponent[MAN_RSA_KEY_EXPONENT_LEN];
64+
uint8_t signature[MAN_RSA_SIGNATURE_LEN];
65+
} __attribute__((packed));
66+
67+
void ri_css_hdr_create(struct image *image);
68+
69+
#endif

0 commit comments

Comments
 (0)