commit
0f507779ca
@ -0,0 +1,89 @@ |
||||
/*
|
||||
* Copyright (C) 2014 Marek Vasut <marex@denx.de> |
||||
* |
||||
* Command for en/de-crypting block of memory with AES-128-CBC cipher. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <command.h> |
||||
#include <environment.h> |
||||
#include <aes.h> |
||||
#include <malloc.h> |
||||
#include <asm/byteorder.h> |
||||
#include <linux/compiler.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
/**
|
||||
* do_aes() - Handle the "aes" command-line command |
||||
* @cmdtp: Command data struct pointer |
||||
* @flag: Command flag |
||||
* @argc: Command-line argument count |
||||
* @argv: Array of command-line arguments |
||||
* |
||||
* Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
||||
* on error. |
||||
*/ |
||||
static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
||||
{ |
||||
uint32_t key_addr, src_addr, dst_addr, len; |
||||
uint8_t *key_ptr, *src_ptr, *dst_ptr; |
||||
uint8_t key_exp[AES_EXPAND_KEY_LENGTH]; |
||||
uint32_t aes_blocks; |
||||
int enc; |
||||
|
||||
if (argc != 6) |
||||
return CMD_RET_USAGE; |
||||
|
||||
if (!strncmp(argv[1], "enc", 3)) |
||||
enc = 1; |
||||
else if (!strncmp(argv[1], "dec", 3)) |
||||
enc = 0; |
||||
else |
||||
return CMD_RET_USAGE; |
||||
|
||||
key_addr = simple_strtoul(argv[2], NULL, 16); |
||||
src_addr = simple_strtoul(argv[3], NULL, 16); |
||||
dst_addr = simple_strtoul(argv[4], NULL, 16); |
||||
len = simple_strtoul(argv[5], NULL, 16); |
||||
|
||||
key_ptr = (uint8_t *)key_addr; |
||||
src_ptr = (uint8_t *)src_addr; |
||||
dst_ptr = (uint8_t *)dst_addr; |
||||
|
||||
/* First we expand the key. */ |
||||
aes_expand_key(key_ptr, key_exp); |
||||
|
||||
/* Calculate the number of AES blocks to encrypt. */ |
||||
aes_blocks = DIV_ROUND_UP(len, AES_KEY_LENGTH); |
||||
|
||||
if (enc) |
||||
aes_cbc_encrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks); |
||||
else |
||||
aes_cbc_decrypt_blocks(key_exp, src_ptr, dst_ptr, aes_blocks); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
/***************************************************/ |
||||
#ifdef CONFIG_SYS_LONGHELP |
||||
static char aes_help_text[] = |
||||
"enc key src dst len - Encrypt block of data $len bytes long\n" |
||||
" at address $src using a key at address\n" |
||||
" $key and store the result at address\n" |
||||
" $dst. The $len size must be multiple of\n" |
||||
" 16 bytes and $key must be 16 bytes long.\n" |
||||
"aes dec key src dst len - Decrypt block of data $len bytes long\n" |
||||
" at address $src using a key at address\n" |
||||
" $key and store the result at address\n" |
||||
" $dst. The $len size must be multiple of\n" |
||||
" 16 bytes and $key must be 16 bytes long."; |
||||
#endif |
||||
|
||||
U_BOOT_CMD( |
||||
aes, 6, 1, do_aes, |
||||
"AES 128 CBC encryption", |
||||
aes_help_text |
||||
); |
@ -0,0 +1,24 @@ |
||||
/*
|
||||
* Copyright (c) 2013, Andreas Oetken. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef _RSA_CHECKSUM_H |
||||
#define _RSA_CHECKSUM_H |
||||
|
||||
#include <errno.h> |
||||
#include <image.h> |
||||
#include <sha1.h> |
||||
#include <sha256.h> |
||||
|
||||
extern const uint8_t padding_sha256_rsa4096[]; |
||||
extern const uint8_t padding_sha256_rsa2048[]; |
||||
extern const uint8_t padding_sha1_rsa2048[]; |
||||
|
||||
void sha256_calculate(const struct image_region region[], int region_count, |
||||
uint8_t *checksum); |
||||
void sha1_calculate(const struct image_region region[], int region_count, |
||||
uint8_t *checksum); |
||||
|
||||
#endif |
@ -0,0 +1,163 @@ |
||||
/*
|
||||
* Copyright (c) 2013, Andreas Oetken. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef USE_HOSTCC |
||||
#include <common.h> |
||||
#include <fdtdec.h> |
||||
#include <asm/byteorder.h> |
||||
#include <asm/errno.h> |
||||
#include <asm/unaligned.h> |
||||
#else |
||||
#include "fdt_host.h" |
||||
#endif |
||||
#include <rsa.h> |
||||
#include <sha1.h> |
||||
#include <sha256.h> |
||||
|
||||
/* PKCS 1.5 paddings as described in the RSA PKCS#1 v2.1 standard. */ |
||||
|
||||
const uint8_t padding_sha256_rsa2048[RSA2048_BYTES - SHA256_SUM_LEN] = { |
||||
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30, |
||||
0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, |
||||
0x00, 0x04, 0x20 |
||||
}; |
||||
|
||||
const uint8_t padding_sha1_rsa2048[RSA2048_BYTES - SHA1_SUM_LEN] = { |
||||
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x21, 0x30, |
||||
0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, |
||||
0x05, 0x00, 0x04, 0x14 |
||||
}; |
||||
|
||||
const uint8_t padding_sha256_rsa4096[RSA4096_BYTES - SHA256_SUM_LEN] = { |
||||
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30, |
||||
0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, |
||||
0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 |
||||
}; |
||||
|
||||
void sha1_calculate(const struct image_region region[], int region_count, |
||||
uint8_t *checksum) |
||||
{ |
||||
sha1_context ctx; |
||||
uint32_t i; |
||||
i = 0; |
||||
|
||||
sha1_starts(&ctx); |
||||
for (i = 0; i < region_count; i++) |
||||
sha1_update(&ctx, region[i].data, region[i].size); |
||||
sha1_finish(&ctx, checksum); |
||||
} |
||||
|
||||
void sha256_calculate(const struct image_region region[], int region_count, |
||||
uint8_t *checksum) |
||||
{ |
||||
sha256_context ctx; |
||||
uint32_t i; |
||||
i = 0; |
||||
|
||||
sha256_starts(&ctx); |
||||
for (i = 0; i < region_count; i++) |
||||
sha256_update(&ctx, region[i].data, region[i].size); |
||||
sha256_finish(&ctx, checksum); |
||||
} |
@ -0,0 +1,45 @@ |
||||
/dts-v1/; |
||||
|
||||
/ { |
||||
description = "Chrome OS kernel image with one or more FDT blobs"; |
||||
#address-cells = <1>; |
||||
|
||||
images { |
||||
kernel@1 { |
||||
data = /incbin/("test-kernel.bin"); |
||||
type = "kernel_noload"; |
||||
arch = "sandbox"; |
||||
os = "linux"; |
||||
compression = "none"; |
||||
load = <0x4>; |
||||
entry = <0x8>; |
||||
kernel-version = <1>; |
||||
hash@1 { |
||||
algo = "sha256"; |
||||
}; |
||||
}; |
||||
fdt@1 { |
||||
description = "snow"; |
||||
data = /incbin/("sandbox-kernel.dtb"); |
||||
type = "flat_dt"; |
||||
arch = "sandbox"; |
||||
compression = "none"; |
||||
fdt-version = <1>; |
||||
hash@1 { |
||||
algo = "sha256"; |
||||
}; |
||||
}; |
||||
}; |
||||
configurations { |
||||
default = "conf@1"; |
||||
conf@1 { |
||||
kernel = "kernel@1"; |
||||
fdt = "fdt@1"; |
||||
signature@1 { |
||||
algo = "sha256,rsa2048"; |
||||
key-name-hint = "dev"; |
||||
sign-images = "fdt", "kernel"; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
@ -0,0 +1,42 @@ |
||||
/dts-v1/; |
||||
|
||||
/ { |
||||
description = "Chrome OS kernel image with one or more FDT blobs"; |
||||
#address-cells = <1>; |
||||
|
||||
images { |
||||
kernel@1 { |
||||
data = /incbin/("test-kernel.bin"); |
||||
type = "kernel_noload"; |
||||
arch = "sandbox"; |
||||
os = "linux"; |
||||
compression = "none"; |
||||
load = <0x4>; |
||||
entry = <0x8>; |
||||
kernel-version = <1>; |
||||
signature@1 { |
||||
algo = "sha256,rsa2048"; |
||||
key-name-hint = "dev"; |
||||
}; |
||||
}; |
||||
fdt@1 { |
||||
description = "snow"; |
||||
data = /incbin/("sandbox-kernel.dtb"); |
||||
type = "flat_dt"; |
||||
arch = "sandbox"; |
||||
compression = "none"; |
||||
fdt-version = <1>; |
||||
signature@1 { |
||||
algo = "sha256,rsa2048"; |
||||
key-name-hint = "dev"; |
||||
}; |
||||
}; |
||||
}; |
||||
configurations { |
||||
default = "conf@1"; |
||||
conf@1 { |
||||
kernel = "kernel@1"; |
||||
fdt = "fdt@1"; |
||||
}; |
||||
}; |
||||
}; |
@ -0,0 +1 @@ |
||||
#include "../lib/fdtdec.c" |
@ -0,0 +1,85 @@ |
||||
/*
|
||||
* (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. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include "mkimage.h" |
||||
#include "fit_common.h" |
||||
#include <image.h> |
||||
#include <u-boot/crc.h> |
||||
|
||||
void usage(char *cmdname) |
||||
{ |
||||
fprintf(stderr, "Usage: %s -f fit file -k key file\n" |
||||
" -f ==> set fit file which should be checked'\n" |
||||
" -k ==> set key file which contains the key'\n", |
||||
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; |
||||
char cmdname[50]; |
||||
int ret; |
||||
void *key_blob; |
||||
int c; |
||||
|
||||
strcpy(cmdname, *argv); |
||||
while ((c = getopt(argc, argv, "f:k:")) != -1) |
||||
switch (c) { |
||||
case 'f': |
||||
fdtfile = optarg; |
||||
break; |
||||
case 'k': |
||||
keyfile = optarg; |
||||
break; |
||||
default: |
||||
usage(cmdname); |
||||
break; |
||||
} |
||||
|
||||
ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0); |
||||
if (ffd < 0) |
||||
return EXIT_FAILURE; |
||||
kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, 0); |
||||
if (ffd < 0) |
||||
return EXIT_FAILURE; |
||||
|
||||
image_set_host_blob(key_blob); |
||||
ret = fit_check_sign(fit_blob, key_blob); |
||||
|
||||
if (ret) |
||||
ret = EXIT_SUCCESS; |
||||
else |
||||
ret = EXIT_FAILURE; |
||||
|
||||
(void) munmap((void *)fit_blob, fsbuf.st_size); |
||||
(void) munmap((void *)key_blob, ksbuf.st_size); |
||||
|
||||
close(ffd); |
||||
close(kfd); |
||||
exit(ret); |
||||
} |
@ -0,0 +1,86 @@ |
||||
/*
|
||||
* (C) Copyright 2014 |
||||
* DENX Software Engineering |
||||
* Heiko Schocher <hs@denx.de> |
||||
* |
||||
* (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. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include "imagetool.h" |
||||
#include "mkimage.h" |
||||
#include "fit_common.h" |
||||
#include <image.h> |
||||
#include <u-boot/crc.h> |
||||
|
||||
int fit_verify_header(unsigned char *ptr, int image_size, |
||||
struct image_tool_params *params) |
||||
{ |
||||
return fdt_check_header(ptr); |
||||
} |
||||
|
||||
int fit_check_image_types(uint8_t type) |
||||
{ |
||||
if (type == IH_TYPE_FLATDT) |
||||
return EXIT_SUCCESS; |
||||
else |
||||
return EXIT_FAILURE; |
||||
} |
||||
|
||||
int mmap_fdt(char *cmdname, const char *fname, void **blobp, |
||||
struct stat *sbuf, int useunlink) |
||||
{ |
||||
void *ptr; |
||||
int fd; |
||||
|
||||
/* Load FIT blob into memory (we need to write hashes/signatures) */ |
||||
fd = open(fname, O_RDWR | O_BINARY); |
||||
|
||||
if (fd < 0) { |
||||
fprintf(stderr, "%s: Can't open %s: %s\n", |
||||
cmdname, fname, strerror(errno)); |
||||
if (useunlink) |
||||
unlink(fname); |
||||
return -1; |
||||
} |
||||
|
||||
if (fstat(fd, sbuf) < 0) { |
||||
fprintf(stderr, "%s: Can't stat %s: %s\n", |
||||
cmdname, fname, strerror(errno)); |
||||
if (useunlink) |
||||
unlink(fname); |
||||
return -1; |
||||
} |
||||
|
||||
errno = 0; |
||||
ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); |
||||
if ((ptr == MAP_FAILED) || (errno != 0)) { |
||||
fprintf(stderr, "%s: Can't read %s: %s\n", |
||||
cmdname, fname, strerror(errno)); |
||||
if (useunlink) |
||||
unlink(fname); |
||||
return -1; |
||||
} |
||||
|
||||
/* check if ptr has a valid blob */ |
||||
if (fdt_check_header(ptr)) { |
||||
fprintf(stderr, "%s: Invalid FIT blob\n", cmdname); |
||||
if (useunlink) |
||||
unlink(fname); |
||||
return -1; |
||||
} |
||||
|
||||
*blobp = ptr; |
||||
return fd; |
||||
} |
@ -0,0 +1,22 @@ |
||||
/*
|
||||
* (C) Copyright 2014 |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef _FIT_COMMON_H_ |
||||
#define _FIT_COMMON_H_ |
||||
|
||||
#include "imagetool.h" |
||||
#include "mkimage.h" |
||||
#include <image.h> |
||||
|
||||
int fit_verify_header(unsigned char *ptr, int image_size, |
||||
struct image_tool_params *params); |
||||
|
||||
int fit_check_image_types(uint8_t type); |
||||
|
||||
int mmap_fdt(char *cmdname, const char *fname, void **blobp, |
||||
struct stat *sbuf, int useunlink); |
||||
|
||||
#endif /* _FIT_COMMON_H_ */ |
@ -0,0 +1,96 @@ |
||||
/*
|
||||
* (C) Copyright 2014 |
||||
* DENX Software Engineering |
||||
* Heiko Schocher <hs@denx.de> |
||||
* |
||||
* fit_info: print the offset and the len of a property from |
||||
* node in a fit file. |
||||
* |
||||
* 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. |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include "mkimage.h" |
||||
#include "fit_common.h" |
||||
#include <image.h> |
||||
#include <u-boot/crc.h> |
||||
|
||||
void usage(char *cmdname) |
||||
{ |
||||
fprintf(stderr, "Usage: %s -f fit file -n node -p property\n" |
||||
" -f ==> set fit file which is used'\n" |
||||
" -n ==> set node name'\n" |
||||
" -p ==> set property name'\n", |
||||
cmdname); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
int ffd = -1; |
||||
struct stat fsbuf; |
||||
void *fit_blob; |
||||
int len; |
||||
int nodeoffset; /* node offset from libfdt */ |
||||
const void *nodep; /* property node pointer */ |
||||
char *fdtfile = NULL; |
||||
char *nodename = NULL; |
||||
char *propertyname = NULL; |
||||
char cmdname[50]; |
||||
int c; |
||||
|
||||
strcpy(cmdname, *argv); |
||||
while ((c = getopt(argc, argv, "f:n:p:")) != -1) |
||||
switch (c) { |
||||
case 'f': |
||||
fdtfile = optarg; |
||||
break; |
||||
case 'n': |
||||
nodename = optarg; |
||||
break; |
||||
case 'p': |
||||
propertyname = optarg; |
||||
break; |
||||
default: |
||||
usage(cmdname); |
||||
break; |
||||
} |
||||
|
||||
ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0); |
||||
|
||||
if (ffd < 0) { |
||||
printf("Could not open %s\n", fdtfile); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
|
||||
nodeoffset = fdt_path_offset(fit_blob, nodename); |
||||
if (nodeoffset < 0) { |
||||
printf("%s not found.", nodename); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
nodep = fdt_getprop(fit_blob, nodeoffset, propertyname, &len); |
||||
if (len == 0) { |
||||
printf("len == 0 %s\n", propertyname); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
|
||||
printf("NAME: %s\n", fit_get_name(fit_blob, nodeoffset, NULL)); |
||||
printf("LEN: %d\n", len); |
||||
printf("OFF: %d\n", (int)(nodep - fit_blob)); |
||||
(void) munmap((void *)fit_blob, fsbuf.st_size); |
||||
|
||||
close(ffd); |
||||
exit(EXIT_SUCCESS); |
||||
} |
@ -0,0 +1 @@ |
||||
#include "../lib/rsa/rsa-checksum.c" |
@ -0,0 +1 @@ |
||||
#include "../lib/rsa/rsa-verify.c" |
@ -0,0 +1 @@ |
||||
#include "../lib/sha256.c" |
Loading…
Reference in new issue