1 // SPDX-License-Identifier: GPL-2.0+
4 * Command for encapsulating/decapsulating blob of memory.
10 #include <asm/byteorder.h>
11 #include <linux/compiler.h>
12 #if defined(CONFIG_ARCH_MX6) || defined(CONFIG_ARCH_MX7) || \
13 defined(CONFIG_ARCH_MX7ULP) || defined(CONFIG_ARCH_IMX8M)
15 #include <asm/arch/clock.h>
19 * blob_decap() - Decapsulate the data as a blob
20 * @key_mod: - Pointer to key modifier/key
21 * @src: - Address of data to be decapsulated
22 * @dst: - Address of data to be decapsulated
23 * @len: - Size of data to be decapsulated
25 * Returns zero on success,and negative on error.
27 __weak
int blob_decap(u8
*key_mod
, u8
*src
, u8
*dst
, u32 len
)
33 * blob_encap() - Encapsulate the data as a blob
34 * @key_mod: - Pointer to key modifier/key
35 * @src: - Address of data to be encapsulated
36 * @dst: - Address of data to be encapsulated
37 * @len: - Size of data to be encapsulated
39 * Returns zero on success,and negative on error.
41 __weak
int blob_encap(u8
*key_mod
, u8
*src
, u8
*dst
, u32 len
)
47 * do_blob() - Handle the "blob" command-line command
48 * @cmdtp: Command data struct pointer
50 * @argc: Command-line argument count
51 * @argv: Array of command-line arguments
53 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
56 static int do_blob(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
59 ulong key_addr
, src_addr
, dst_addr
, len
;
60 uint8_t *km_ptr
, *src_ptr
, *dst_ptr
;
66 if (!strncmp(argv
[1], "enc", 3))
68 else if (!strncmp(argv
[1], "dec", 3))
73 src_addr
= hextoul(argv
[2], NULL
);
74 dst_addr
= hextoul(argv
[3], NULL
);
75 len
= hextoul(argv
[4], NULL
);
76 key_addr
= hextoul(argv
[5], NULL
);
78 km_ptr
= (uint8_t *)(uintptr_t)key_addr
;
79 src_ptr
= (uint8_t *)(uintptr_t)src_addr
;
80 dst_ptr
= (uint8_t *)(uintptr_t)dst_addr
;
82 #if defined(CONFIG_ARCH_MX6) || defined(CONFIG_ARCH_MX7) || \
83 defined(CONFIG_ARCH_MX7ULP) || defined(CONFIG_ARCH_IMX8M)
85 hab_caam_clock_enable(1);
87 u32 out_jr_size
= sec_in32(CFG_SYS_FSL_JR0_ADDR
+
88 FSL_CAAM_ORSR_JRa_OFFSET
);
89 if (out_jr_size
!= FSL_CAAM_MAX_JR_SIZE
)
94 ret
= blob_encap(km_ptr
, src_ptr
, dst_ptr
, len
);
96 ret
= blob_decap(km_ptr
, src_ptr
, dst_ptr
, len
);
101 /***************************************************/
102 U_BOOT_LONGHELP(blob
,
103 "enc src dst len km - Encapsulate and create blob of data\n"
104 " $len bytes long at address $src and\n"
105 " store the result at address $dst.\n"
106 " $km is the address where the key\n"
107 " modifier is stored.\n"
108 " The modifier is required for generation\n"
109 " /use as key for cryptographic operation.\n"
110 " Key modifier should be 16 byte long.\n"
111 "blob dec src dst len km - Decapsulate the blob of data at address\n"
112 " $src and store result of $len byte at\n"
114 " $km is the address where the key\n"
115 " modifier is stored.\n"
116 " The modifier is required for generation\n"
117 " /use as key for cryptographic operation.\n"
118 " Key modifier should be 16 byte long.\n");
122 "Blob encapsulation/decryption",