2019-06-02 02:01:02 +08:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//
|
|
|
|
// Copyright(c) 2015 Intel Corporation. All rights reserved.
|
2018-02-14 04:29:40 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "rimage.h"
|
|
|
|
#include "file_format.h"
|
|
|
|
#include "manifest.h"
|
|
|
|
|
|
|
|
static const struct adsp *machine[] = {
|
|
|
|
&machine_byt,
|
|
|
|
&machine_cht,
|
|
|
|
&machine_bsw,
|
|
|
|
&machine_hsw,
|
|
|
|
&machine_bdw,
|
|
|
|
&machine_apl,
|
|
|
|
&machine_cnl,
|
2018-08-31 21:19:33 +08:00
|
|
|
&machine_icl,
|
2018-09-28 22:48:29 +08:00
|
|
|
&machine_sue,
|
2018-11-05 16:52:21 +08:00
|
|
|
&machine_kbl,
|
|
|
|
&machine_skl,
|
2019-02-02 06:23:45 +08:00
|
|
|
&machine_imx8,
|
2018-02-14 04:29:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(char *name)
|
|
|
|
{
|
2018-04-13 04:07:35 +08:00
|
|
|
fprintf(stdout, "%s:\t -m machine -o outfile -k [key] ELF files\n",
|
|
|
|
name);
|
2018-02-14 04:29:40 +08:00
|
|
|
fprintf(stdout, "\t -v enable verbose output\n");
|
2018-04-13 04:07:35 +08:00
|
|
|
fprintf(stdout, "\t -r enable relocatable ELF files\n");
|
2018-06-04 19:03:42 +08:00
|
|
|
fprintf(stdout, "\t -s MEU signing offset\n");
|
2018-09-25 21:19:25 +08:00
|
|
|
fprintf(stdout, "\t -p log dictionary outfile\n");
|
2019-04-11 20:09:02 +08:00
|
|
|
fprintf(stdout, "\t -i set IMR type\n");
|
2018-02-14 04:29:40 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct image image;
|
|
|
|
const char *mach = NULL;
|
|
|
|
int opt, ret, i, elf_argc = 0;
|
2019-04-11 20:09:02 +08:00
|
|
|
int imr_type = MAN_DEFAULT_IMR_TYPE;
|
2018-02-14 04:29:40 +08:00
|
|
|
|
|
|
|
memset(&image, 0, sizeof(image));
|
|
|
|
|
2019-04-11 20:09:02 +08:00
|
|
|
while ((opt = getopt(argc, argv, "ho:p:m:vba:s:k:l:ri:")) != -1) {
|
2018-02-14 04:29:40 +08:00
|
|
|
switch (opt) {
|
|
|
|
case 'o':
|
|
|
|
image.out_file = optarg;
|
|
|
|
break;
|
2018-09-25 21:19:25 +08:00
|
|
|
case 'p':
|
|
|
|
image.ldc_out_file = optarg;
|
|
|
|
break;
|
2018-02-14 04:29:40 +08:00
|
|
|
case 'm':
|
|
|
|
mach = optarg;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
image.verbose = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
2018-06-04 19:03:42 +08:00
|
|
|
image.meu_offset = atoi(optarg);
|
2018-02-14 04:29:40 +08:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
image.abi = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
image.key_name = optarg;
|
|
|
|
break;
|
2018-04-13 04:07:35 +08:00
|
|
|
case 'r':
|
|
|
|
image.reloc = 1;
|
|
|
|
break;
|
2019-04-11 20:09:02 +08:00
|
|
|
case 'i':
|
|
|
|
imr_type = atoi(optarg);
|
|
|
|
break;
|
2018-02-14 04:29:40 +08:00
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elf_argc = optind;
|
|
|
|
|
|
|
|
/* make sure we have an outfile and machine */
|
2019-03-06 19:09:42 +08:00
|
|
|
if (!image.out_file || !mach)
|
2018-02-14 04:29:40 +08:00
|
|
|
usage(argv[0]);
|
|
|
|
|
2019-03-06 19:09:42 +08:00
|
|
|
if (!image.ldc_out_file)
|
2018-09-25 21:19:25 +08:00
|
|
|
image.ldc_out_file = "out.ldc";
|
2018-02-14 04:29:40 +08:00
|
|
|
|
|
|
|
/* find machine */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(machine); i++) {
|
|
|
|
if (!strcmp(mach, machine[i]->name)) {
|
|
|
|
image.adsp = machine[i];
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "error: machine %s not found\n", mach);
|
|
|
|
fprintf(stderr, "error: available machines ");
|
|
|
|
for (i = 0; i < ARRAY_SIZE(machine); i++)
|
|
|
|
fprintf(stderr, "%s, ", machine[i]->name);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
2019-04-11 20:09:02 +08:00
|
|
|
/* set IMR Type in found machine definition */
|
|
|
|
if (image.adsp->man_v1_8)
|
|
|
|
image.adsp->man_v1_8->adsp_file_ext.imr_type = imr_type;
|
|
|
|
|
2018-02-14 04:29:40 +08:00
|
|
|
/* parse input ELF files */
|
|
|
|
image.num_modules = argc - elf_argc;
|
|
|
|
for (i = elf_argc; i < argc; i++) {
|
|
|
|
fprintf(stdout, "\nModule Reading %s\n", argv[i]);
|
|
|
|
ret = elf_parse_module(&image, i - elf_argc, argv[i]);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validate all modules */
|
|
|
|
ret = elf_validate_modules(&image);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* open outfile for writing */
|
|
|
|
unlink(image.out_file);
|
2019-01-30 15:04:54 +08:00
|
|
|
image.out_fd = fopen(image.out_file, "wb");
|
2019-03-06 19:09:42 +08:00
|
|
|
if (!image.out_fd) {
|
2018-02-14 04:29:40 +08:00
|
|
|
fprintf(stderr, "error: unable to open %s for writing %d\n",
|
|
|
|
image.out_file, errno);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process and write output */
|
2018-06-04 19:03:42 +08:00
|
|
|
if (image.meu_offset)
|
|
|
|
ret = image.adsp->write_firmware_meu(&image);
|
|
|
|
else
|
|
|
|
ret = image.adsp->write_firmware(&image);
|
2018-09-25 21:19:25 +08:00
|
|
|
|
|
|
|
unlink(image.ldc_out_file);
|
2019-01-30 15:04:54 +08:00
|
|
|
image.ldc_out_fd = fopen(image.ldc_out_file, "wb");
|
2019-03-06 19:09:42 +08:00
|
|
|
if (!image.ldc_out_fd) {
|
2018-09-25 21:19:25 +08:00
|
|
|
fprintf(stderr, "error: unable to open %s for writing %d\n",
|
|
|
|
image.ldc_out_file, errno);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = write_logs_dictionary(&image);
|
2018-02-14 04:29:40 +08:00
|
|
|
out:
|
|
|
|
/* close files */
|
|
|
|
if (image.out_fd)
|
|
|
|
fclose(image.out_fd);
|
|
|
|
|
2018-09-25 21:19:25 +08:00
|
|
|
if (image.ldc_out_fd)
|
|
|
|
fclose(image.ldc_out_fd);
|
2018-02-14 04:29:40 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|