1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2008-2015 Freescale Semiconductor, Inc.
5 * Command for encapsulating DEK blob
11 #include <asm/byteorder.h>
12 #include <linux/compiler.h>
14 #include <asm/arch/clock.h>
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
23 * Returns zero on success,and negative on error.
25 static int blob_encap_dek(const u8 *src, u8 *dst, u32 len)
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);
36 if (!((len == 128) | (len == 192) | (len == 256))) {
37 debug("Invalid DEK size. Valid sizes are 128, 192 and 256b\n");
42 ret = blob_dek(src, dst, len);
48 * do_dek_blob() - Handle the "dek_blob" command-line command
49 * @cmdtp: Command data struct pointer
51 * @argc: Command-line argument count
52 * @argv: Array of command-line arguments
54 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
57 static int do_dek_blob(struct cmd_tbl *cmdtp, int flag, int argc,
60 uint32_t src_addr, dst_addr, len;
61 uint8_t *src_ptr, *dst_ptr;
67 src_addr = simple_strtoul(argv[1], NULL, 16);
68 dst_addr = simple_strtoul(argv[2], NULL, 16);
69 len = simple_strtoul(argv[3], NULL, 10);
71 src_ptr = map_sysmem(src_addr, len/8);
72 dst_ptr = map_sysmem(dst_addr, BLOB_SIZE(len/8));
74 ret = blob_encap_dek(src_ptr, dst_ptr, len);
79 /***************************************************/
80 static char dek_blob_help_text[] =
81 "src dst len - Encapsulate and create blob of data\n"
82 " $len bits long at address $src and\n"
83 " store the result at address $dst.\n";
86 dek_blob, 4, 1, do_dek_blob,
87 "Data Encryption Key blob encapsulation",