1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
6 * These commands enable the use of the CAAM MPPubK-generation and MPSign
7 * functions in supported i.MX devices.
10 #include <asm/byteorder.h>
11 #include <asm/arch/clock.h>
12 #include <linux/compiler.h>
21 * do_mfgprot() - Handle the "mfgprot" command-line command
22 * @cmdtp: Command data struct pointer
24 * @argc: Command-line argument count
25 * @argv: Array of command-line arguments
27 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
30 static int do_mfgprot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
32 u8 *m_ptr, *dgst_ptr, *c_ptr, *d_ptr, *dst_ptr;
33 char *pubk, *sign, *sel;
41 /* Enable HAB clock */
42 hab_caam_clock_enable(1);
44 u32 out_jr_size = sec_in32(CONFIG_SYS_FSL_JR0_ADDR +
45 FSL_CAAM_ORSR_JRa_OFFSET);
47 if (out_jr_size != FSL_CAAM_MAX_JR_SIZE)
50 if (strcmp(sel, pubk) == 0) {
51 dst_ptr = malloc_cache_aligned(FSL_CAAM_MP_PUBK_BYTES);
55 ret = gen_mppubk(dst_ptr);
62 puts("Public key:\n");
63 for (i = 0; i < FSL_CAAM_MP_PUBK_BYTES; i++)
64 printf("%02X", (dst_ptr)[i]);
68 } else if (strcmp(sel, sign) == 0) {
72 m_addr = hextoul(argv[2], NULL);
73 m_size = dectoul(argv[3], NULL);
74 m_ptr = map_physmem(m_addr, m_size, MAP_NOCACHE);
78 dgst_ptr = malloc_cache_aligned(FSL_CAAM_MP_MES_DGST_BYTES);
84 c_ptr = malloc_cache_aligned(FSL_CAAM_MP_PRVK_BYTES);
90 d_ptr = malloc_cache_aligned(FSL_CAAM_MP_PRVK_BYTES);
96 ret = sign_mppubk(m_ptr, m_size, dgst_ptr, c_ptr, d_ptr);
102 for (i = 0; i < m_size; i++)
103 printf("%02X ", (m_ptr)[i]);
106 puts("Message Representative Digest(SHA-256):\n");
107 for (i = 0; i < FSL_CAAM_MP_MES_DGST_BYTES; i++)
108 printf("%02X", (dgst_ptr)[i]);
111 puts("Signature:\n");
113 for (i = 0; i < FSL_CAAM_MP_PRVK_BYTES; i++)
114 printf("%02X", (c_ptr)[i]);
118 for (i = 0; i < FSL_CAAM_MP_PRVK_BYTES; i++)
119 printf("%02X", (d_ptr)[i]);
131 return CMD_RET_USAGE;
136 /***************************************************/
137 static char mfgprot_help_text[] =
139 "Print the public key for Manufacturing Protection\n"
141 "Generates a Manufacturing Protection signature\n"
142 "\tmfgprot sign <data_addr> <size>";
145 mfgprot, 4, 1, do_mfgprot,
146 "Manufacturing Protection\n",