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)
14 #include <asm/arch/clock.h>
18 * blob_decap() - Decapsulate the data as a blob
19 * @key_mod: - Pointer to key modifier/key
20 * @src: - Address of data to be decapsulated
21 * @dst: - Address of data to be decapsulated
22 * @len: - Size of data to be decapsulated
24 * Returns zero on success,and negative on error.
26 __weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
32 * blob_encap() - Encapsulate the data as a blob
33 * @key_mod: - Pointer to key modifier/key
34 * @src: - Address of data to be encapsulated
35 * @dst: - Address of data to be encapsulated
36 * @len: - Size of data to be encapsulated
38 * Returns zero on success,and negative on error.
40 __weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
46 * do_blob() - Handle the "blob" command-line command
47 * @cmdtp: Command data struct pointer
49 * @argc: Command-line argument count
50 * @argv: Array of command-line arguments
52 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
55 static int do_blob(struct cmd_tbl *cmdtp, int flag, int argc,
58 ulong key_addr, src_addr, dst_addr, len;
59 uint8_t *km_ptr, *src_ptr, *dst_ptr;
65 if (!strncmp(argv[1], "enc", 3))
67 else if (!strncmp(argv[1], "dec", 3))
72 src_addr = simple_strtoul(argv[2], NULL, 16);
73 dst_addr = simple_strtoul(argv[3], NULL, 16);
74 len = simple_strtoul(argv[4], NULL, 16);
75 key_addr = simple_strtoul(argv[5], NULL, 16);
77 km_ptr = (uint8_t *)(uintptr_t)key_addr;
78 src_ptr = (uint8_t *)(uintptr_t)src_addr;
79 dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
81 #if defined(CONFIG_ARCH_MX6) || defined(CONFIG_ARCH_MX7)
83 hab_caam_clock_enable(1);
85 u32 out_jr_size = sec_in32(CONFIG_SYS_FSL_JR0_ADDR +
86 FSL_CAAM_ORSR_JRa_OFFSET);
87 if (out_jr_size != FSL_CAAM_MAX_JR_SIZE)
92 ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
94 ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
99 /***************************************************/
100 static char blob_help_text[] =
101 "enc src dst len km - Encapsulate and create blob of data\n"
102 " $len bytes long at address $src and\n"
103 " store the result at address $dst.\n"
104 " $km is the address where the key\n"
105 " modifier is stored.\n"
106 " The modifier is required for generation\n"
107 " /use as key for cryptographic operation.\n"
108 " Key modifier should be 16 byte long.\n"
109 "blob dec src dst len km - Decapsulate the blob of data at address\n"
110 " $src and store result of $len byte at\n"
112 " $km is the address where the key\n"
113 " modifier is stored.\n"
114 " The modifier is required for generation\n"
115 " /use as key for cryptographic operation.\n"
116 " Key modifier should be 16 byte long.\n";
120 "Blob encapsulation/decryption",