2 * Copyright 2008-2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
6 * Command for encapsulating DEK blob
11 #include <environment.h>
13 #include <asm/byteorder.h>
14 #include <linux/compiler.h>
16 #include <asm/arch/clock.h>
18 DECLARE_GLOBAL_DATA_PTR;
21 * blob_dek() - Encapsulate the DEK as a blob using CAM's Key
22 * @src: - Address of data to be encapsulated
23 * @dst: - Desination address of encapsulated data
24 * @len: - Size of data to be encapsulated
26 * Returns zero on success,and negative on error.
28 static int blob_encap_dek(const u8 *src, u8 *dst, u32 len)
33 u32 out_jr_size = sec_in32(CONFIG_SYS_FSL_JR0_ADDR + 0x102c);
34 if (out_jr_size != jr_size) {
35 hab_caam_clock_enable(1);
39 if (!((len == 128) | (len == 192) | (len == 256))) {
40 debug("Invalid DEK size. Valid sizes are 128, 192 and 256b\n");
45 ret = blob_dek(src, dst, len);
51 * do_dek_blob() - Handle the "dek_blob" command-line command
52 * @cmdtp: Command data struct pointer
54 * @argc: Command-line argument count
55 * @argv: Array of command-line arguments
57 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
60 static int do_dek_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
62 uint32_t src_addr, dst_addr, len;
63 uint8_t *src_ptr, *dst_ptr;
69 src_addr = simple_strtoul(argv[1], NULL, 16);
70 dst_addr = simple_strtoul(argv[2], NULL, 16);
71 len = simple_strtoul(argv[3], NULL, 10);
73 src_ptr = map_sysmem(src_addr, len/8);
74 dst_ptr = map_sysmem(dst_addr, BLOB_SIZE(len/8));
76 ret = blob_encap_dek(src_ptr, dst_ptr, len);
81 /***************************************************/
82 static char dek_blob_help_text[] =
83 "src dst len - Encapsulate and create blob of data\n"
84 " $len bits long at address $src and\n"
85 " store the result at address $dst.\n";
88 dek_blob, 4, 1, do_dek_blob,
89 "Data Encryption Key blob encapsulation",