config FSL_MFGPROT
bool "Support the 'mfgprot' command"
- depends on IMX_HAB && ARCH_MX7
+ depends on IMX_HAB || AHAB_BOOT
+ select IMX_CAAM_MFG_PROT if ARCH_MX7
+ select IMX_SECO_MFG_PROT if ARCH_IMX8
help
This option enables the manufacturing protection command
which can be used has a protection feature for Manufacturing
process. With this tool is possible to authenticate the
chip to the OEM's server.
+config IMX_CAAM_MFG_PROT
+ bool "Support the manufacturing protection with CAAM U-Boot driver"
+ help
+ This enables the manufacturing protection feature with the U-Boot
+ CAAM driver. This option is only available on iMX7D/S.
+
+config IMX_SECO_MFG_PROT
+ bool "Support the manufacturing protection with SECO API"
+ help
+ This enables the manufacturing protection feature with the SECO API.
+ This option is only available on iMX8/8x series.
+
config DBG_MONITOR
bool "Enable the AXI debug monitor"
depends on ARCH_MX6 || ARCH_MX7
* functions in supported i.MX devices.
*/
-#include <asm/byteorder.h>
-#include <asm/arch/clock.h>
-#include <linux/compiler.h>
#include <command.h>
#include <common.h>
#include <environment.h>
-#include <fsl_sec.h>
#include <mapmem.h>
#include <memalign.h>
+#ifdef CONFIG_IMX_CAAM_MFG_PROT
+#include <asm/arch/clock.h>
+#include <fsl_sec.h>
+#endif
+#ifdef CONFIG_IMX_SECO_MFG_PROT
+#include <asm/io.h>
+#include <asm/arch/sci/sci.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
* Returns zero on success, CMD_RET_USAGE in case of misuse and negative
* on error.
*/
+#ifdef CONFIG_IMX_CAAM_MFG_PROT
+
static int do_mfgprot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
u8 *m_ptr, *dgst_ptr, *c_ptr, *d_ptr, *dst_ptr;
}
return ret;
}
+#endif /* CONFIG_IMX_CAAM_MFG_PROT */
+
+#ifdef CONFIG_IMX_SECO_MFG_PROT
+
+#define FSL_CAAM_MP_PUBK_BYTES 96
+#define FSL_CAAM_MP_SIGN_BYTES 96
+#define SCU_SEC_SECURE_RAM_BASE (0x20800000UL)
+#define SEC_SECURE_RAM_BASE (0x31800000UL)
+
+static int do_mfgprot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+ u8 *m_ptr, *sign_ptr, *dst_ptr;
+ char *pubk, *sign, *sel;
+ int m_size, i, ret;
+ u32 m_addr;
+
+ pubk = "pubk";
+ sign = "sign";
+ sel = argv[1];
+
+ if (!sel)
+ return CMD_RET_USAGE;
+
+ if (strcmp(sel, pubk) == 0) {
+ dst_ptr = malloc_cache_aligned(FSL_CAAM_MP_PUBK_BYTES);
+ if (!dst_ptr)
+ return -ENOMEM;
+
+ puts("\nGenerating Manufacturing Protection Public Key\n");
+
+ ret = sc_seco_get_mp_key(-1, SCU_SEC_SECURE_RAM_BASE,
+ FSL_CAAM_MP_PUBK_BYTES);
+ if (ret) {
+ printf("SECO get MP key failed, return %d\n", ret);
+ ret = -EIO;
+ free(dst_ptr);
+ return ret;
+ }
+
+ memcpy((void *)dst_ptr, (const void *)SEC_SECURE_RAM_BASE,
+ ALIGN(FSL_CAAM_MP_PUBK_BYTES,
+ CONFIG_SYS_CACHELINE_SIZE));
+
+ /* Output results */
+ puts("\nPublic key:\n");
+ for (i = 0; i < FSL_CAAM_MP_PUBK_BYTES; i++)
+ printf("%02X", (dst_ptr)[i]);
+ puts("\n");
+ free(dst_ptr);
+
+ } else if (strcmp(sel, sign) == 0) {
+ if (argc != 4)
+ return CMD_RET_USAGE;
+
+ m_addr = simple_strtoul(argv[2], NULL, 16);
+ m_size = simple_strtoul(argv[3], NULL, 10);
+ m_ptr = map_physmem(m_addr, m_size, MAP_NOCACHE);
+ if (!m_ptr)
+ return -ENOMEM;
+
+ sign_ptr = malloc_cache_aligned(FSL_CAAM_MP_SIGN_BYTES);
+ if (!sign_ptr) {
+ ret = -ENOMEM;
+ goto free_m;
+ }
+
+ memcpy((void *)SEC_SECURE_RAM_BASE, (const void *)m_ptr,
+ ALIGN(m_size, CONFIG_SYS_CACHELINE_SIZE));
+
+ puts("\nSigning message with SECO MP signature function\n");
+
+ ret = sc_seco_get_mp_sign(-1, SCU_SEC_SECURE_RAM_BASE, m_size,
+ SCU_SEC_SECURE_RAM_BASE + 0x1000,
+ FSL_CAAM_MP_SIGN_BYTES);
+
+ if (ret) {
+ printf("SECO get MP signature failed, return %d\n",
+ ret);
+ ret = -EIO;
+ goto free_sign;
+ }
+
+ memcpy((void *)sign_ptr, (const void *)SEC_SECURE_RAM_BASE
+ + 0x1000, ALIGN(FSL_CAAM_MP_SIGN_BYTES,
+ CONFIG_SYS_CACHELINE_SIZE));
+
+ /* Output results */
+ puts("\nMessage: ");
+ for (i = 0; i < m_size; i++)
+ printf("%02X", (m_ptr)[i]);
+ puts("\n");
+
+ puts("\nSignature:\n");
+ puts("c:\n");
+ for (i = 0; i < FSL_CAAM_MP_SIGN_BYTES / 2; i++)
+ printf("%02X", (sign_ptr)[i]);
+ puts("\n");
+
+ puts("d:\n");
+ for (i = FSL_CAAM_MP_SIGN_BYTES / 2; i < FSL_CAAM_MP_SIGN_BYTES;
+ i++)
+ printf("%02X", (sign_ptr)[i]);
+ puts("\n");
+
+free_sign:
+ free(sign_ptr);
+free_m:
+ unmap_sysmem(m_ptr);
+
+ } else {
+ return CMD_RET_USAGE;
+ }
+ return ret;
+}
+#endif /* CONFIG_IMX_SECO_MFG_PROT */
/***************************************************/
static char mfgprot_help_text[] =