2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-03-03 11:19:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014
|
|
|
|
* DENX Software Engineering
|
|
|
|
* Heiko Schocher <hs@denx.de>
|
|
|
|
*
|
|
|
|
* Based on:
|
|
|
|
* (C) Copyright 2008 Semihalf
|
|
|
|
*
|
|
|
|
* (C) Copyright 2000-2004
|
|
|
|
* DENX Software Engineering
|
|
|
|
* Wolfgang Denk, wd@denx.de
|
|
|
|
*
|
|
|
|
* Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
|
|
|
|
* FIT image specific code abstracted from mkimage.c
|
|
|
|
* some functions added to address abstraction
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mkimage.h"
|
|
|
|
#include "fit_common.h"
|
|
|
|
#include <image.h>
|
|
|
|
#include <u-boot/crc.h>
|
|
|
|
|
|
|
|
void usage(char *cmdname)
|
|
|
|
{
|
2021-01-17 15:52:16 +00:00
|
|
|
fprintf(stderr, "Usage: %s -f fit file -k key file -c config name\n"
|
2014-03-03 11:19:30 +00:00
|
|
|
" -f ==> set fit file which should be checked'\n"
|
2021-11-12 19:28:03 +00:00
|
|
|
" -k ==> set key .dtb file which contains the key'\n"
|
2021-01-17 15:52:16 +00:00
|
|
|
" -c ==> set the configuration name'\n",
|
2014-03-03 11:19:30 +00:00
|
|
|
cmdname);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ffd = -1;
|
|
|
|
int kfd = -1;
|
|
|
|
struct stat fsbuf;
|
|
|
|
struct stat ksbuf;
|
|
|
|
void *fit_blob;
|
|
|
|
char *fdtfile = NULL;
|
|
|
|
char *keyfile = NULL;
|
2020-03-18 17:44:03 +00:00
|
|
|
char *config_name = NULL;
|
2014-05-20 13:58:58 +00:00
|
|
|
char cmdname[256];
|
2014-03-03 11:19:30 +00:00
|
|
|
int ret;
|
|
|
|
void *key_blob;
|
|
|
|
int c;
|
|
|
|
|
2014-05-20 13:58:58 +00:00
|
|
|
strncpy(cmdname, *argv, sizeof(cmdname) - 1);
|
|
|
|
cmdname[sizeof(cmdname) - 1] = '\0';
|
2020-03-18 17:44:03 +00:00
|
|
|
while ((c = getopt(argc, argv, "f:k:c:")) != -1)
|
2014-03-03 11:19:30 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
fdtfile = optarg;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
keyfile = optarg;
|
|
|
|
break;
|
2020-03-18 17:44:03 +00:00
|
|
|
case 'c':
|
|
|
|
config_name = optarg;
|
|
|
|
break;
|
2014-03-03 11:19:30 +00:00
|
|
|
default:
|
|
|
|
usage(cmdname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-12 13:24:44 +00:00
|
|
|
if (!fdtfile) {
|
|
|
|
fprintf(stderr, "%s: Missing fdt file\n", *argv);
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
if (!keyfile) {
|
|
|
|
fprintf(stderr, "%s: Missing key file\n", *argv);
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2019-05-14 18:35:02 +00:00
|
|
|
ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false, true);
|
2014-03-03 11:19:30 +00:00
|
|
|
if (ffd < 0)
|
|
|
|
return EXIT_FAILURE;
|
2019-05-14 18:35:02 +00:00
|
|
|
kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false, true);
|
2015-08-25 15:09:40 +00:00
|
|
|
if (kfd < 0)
|
2014-03-03 11:19:30 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
image_set_host_blob(key_blob);
|
2020-03-18 17:44:03 +00:00
|
|
|
ret = fit_check_sign(fit_blob, key_blob, config_name);
|
2014-06-12 13:24:53 +00:00
|
|
|
if (!ret) {
|
2014-03-03 11:19:30 +00:00
|
|
|
ret = EXIT_SUCCESS;
|
2014-06-12 13:24:53 +00:00
|
|
|
fprintf(stderr, "Signature check OK\n");
|
|
|
|
} else {
|
2014-03-03 11:19:30 +00:00
|
|
|
ret = EXIT_FAILURE;
|
2021-11-12 19:28:03 +00:00
|
|
|
fprintf(stderr, "Signature check bad (error %d)\n", ret);
|
2014-06-12 13:24:53 +00:00
|
|
|
}
|
2014-03-03 11:19:30 +00:00
|
|
|
|
|
|
|
(void) munmap((void *)fit_blob, fsbuf.st_size);
|
|
|
|
(void) munmap((void *)key_blob, ksbuf.st_size);
|
|
|
|
|
|
|
|
close(ffd);
|
|
|
|
close(kfd);
|
|
|
|
exit(ret);
|
|
|
|
}
|