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>
15 #include <environment.h>
20 DECLARE_GLOBAL_DATA_PTR;
23 * do_mfgprot() - Handle the "mfgprot" command-line command
24 * @cmdtp: Command data struct pointer
26 * @argc: Command-line argument count
27 * @argv: Array of command-line arguments
29 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
32 static int do_mfgprot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
34 u8 *m_ptr, *dgst_ptr, *c_ptr, *d_ptr, *dst_ptr;
35 char *pubk, *sign, *sel;
43 /* Enable HAB clock */
44 hab_caam_clock_enable(1);
46 u32 out_jr_size = sec_in32(CONFIG_SYS_FSL_JR0_ADDR +
47 FSL_CAAM_ORSR_JRa_OFFSET);
49 if (out_jr_size != FSL_CAAM_MAX_JR_SIZE)
52 if (strcmp(sel, pubk) == 0) {
53 dst_ptr = malloc_cache_aligned(FSL_CAAM_MP_PUBK_BYTES);
57 ret = gen_mppubk(dst_ptr);
64 puts("Public key:\n");
65 for (i = 0; i < FSL_CAAM_MP_PUBK_BYTES; i++)
66 printf("%02X", (dst_ptr)[i]);
70 } else if (strcmp(sel, sign) == 0) {
74 m_addr = hextoul(argv[2], NULL);
75 m_size = dectoul(argv[3], NULL);
76 m_ptr = map_physmem(m_addr, m_size, MAP_NOCACHE);
80 dgst_ptr = malloc_cache_aligned(FSL_CAAM_MP_MES_DGST_BYTES);
86 c_ptr = malloc_cache_aligned(FSL_CAAM_MP_PRVK_BYTES);
92 d_ptr = malloc_cache_aligned(FSL_CAAM_MP_PRVK_BYTES);
98 ret = sign_mppubk(m_ptr, m_size, dgst_ptr, c_ptr, d_ptr);
104 for (i = 0; i < m_size; i++)
105 printf("%02X ", (m_ptr)[i]);
108 puts("Message Representative Digest(SHA-256):\n");
109 for (i = 0; i < FSL_CAAM_MP_MES_DGST_BYTES; i++)
110 printf("%02X", (dgst_ptr)[i]);
113 puts("Signature:\n");
115 for (i = 0; i < FSL_CAAM_MP_PRVK_BYTES; i++)
116 printf("%02X", (c_ptr)[i]);
120 for (i = 0; i < FSL_CAAM_MP_PRVK_BYTES; i++)
121 printf("%02X", (d_ptr)[i]);
133 return CMD_RET_USAGE;
138 /***************************************************/
139 static char mfgprot_help_text[] =
141 "Print the public key for Manufacturing Protection\n"
143 "Generates a Manufacturing Protection signature\n"
144 "\tmfgprot sign <data_addr> <size>";
147 mfgprot, 4, 1, do_mfgprot,
148 "Manufacturing Protection\n",