blob: 1b111ba26b1397d881f7583f1deeef044f75afa1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Raul Cardenas02000202015-02-27 11:22:06 -06002/*
3 * Copyright 2008-2015 Freescale Semiconductor, Inc.
4 *
Raul Cardenas02000202015-02-27 11:22:06 -06005 * Command for encapsulating DEK blob
6 */
7
8#include <common.h>
9#include <command.h>
Raul Cardenas02000202015-02-27 11:22:06 -060010#include <malloc.h>
11#include <asm/byteorder.h>
12#include <linux/compiler.h>
13#include <fsl_sec.h>
14#include <asm/arch/clock.h>
Ulises Cardenas98a49e52015-05-04 09:53:28 -050015#include <mapmem.h>
Raul Cardenas02000202015-02-27 11:22:06 -060016
Raul Cardenas02000202015-02-27 11:22:06 -060017/**
18* blob_dek() - Encapsulate the DEK as a blob using CAM's Key
19* @src: - Address of data to be encapsulated
20* @dst: - Desination address of encapsulated data
21* @len: - Size of data to be encapsulated
22*
23* Returns zero on success,and negative on error.
24*/
25static int blob_encap_dek(const u8 *src, u8 *dst, u32 len)
26{
27 int ret = 0;
28 u32 jr_size = 4;
29
30 u32 out_jr_size = sec_in32(CONFIG_SYS_FSL_JR0_ADDR + 0x102c);
31 if (out_jr_size != jr_size) {
32 hab_caam_clock_enable(1);
33 sec_init();
34 }
35
36 if (!((len == 128) | (len == 192) | (len == 256))) {
37 debug("Invalid DEK size. Valid sizes are 128, 192 and 256b\n");
38 return -1;
39 }
40
41 len /= 8;
42 ret = blob_dek(src, dst, len);
43
44 return ret;
45}
46
47/**
48 * do_dek_blob() - Handle the "dek_blob" command-line command
49 * @cmdtp: Command data struct pointer
50 * @flag: Command flag
51 * @argc: Command-line argument count
52 * @argv: Array of command-line arguments
53 *
54 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
55 * on error.
56 */
57static int do_dek_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
58{
59 uint32_t src_addr, dst_addr, len;
60 uint8_t *src_ptr, *dst_ptr;
61 int ret = 0;
62
63 if (argc != 4)
64 return CMD_RET_USAGE;
65
66 src_addr = simple_strtoul(argv[1], NULL, 16);
67 dst_addr = simple_strtoul(argv[2], NULL, 16);
68 len = simple_strtoul(argv[3], NULL, 10);
69
70 src_ptr = map_sysmem(src_addr, len/8);
71 dst_ptr = map_sysmem(dst_addr, BLOB_SIZE(len/8));
72
73 ret = blob_encap_dek(src_ptr, dst_ptr, len);
74
75 return ret;
76}
77
78/***************************************************/
79static char dek_blob_help_text[] =
80 "src dst len - Encapsulate and create blob of data\n"
81 " $len bits long at address $src and\n"
82 " store the result at address $dst.\n";
83
84U_BOOT_CMD(
85 dek_blob, 4, 1, do_dek_blob,
86 "Data Encryption Key blob encapsulation",
87 dek_blob_help_text
88);