1 // SPDX-License-Identifier: GPL-2.0+
3 * K2x: Secure commands file
5 * Copyright (C) 2012-2019 Texas Instruments Incorporated - http://www.ti.com/
10 #include <asm/unaligned.h>
15 asm(".arch_extension sec\n\t");
17 int mon_install(u32 addr, u32 dpsc, u32 freq, u32 bm_addr)
21 __asm__ __volatile__ (
31 : "r" (addr), "r" (dpsc), "r" (freq), "r" (bm_addr)
32 : "cc", "r0", "r1", "r2", "r3", "memory");
36 int mon_power_on(int core_id, void *ep)
49 : "r" (core_id), "r" (ep)
50 : "cc", "r0", "r1", "r2", "memory");
54 int mon_power_off(int core_id)
67 : "cc", "r0", "r1", "memory");
71 #ifdef CONFIG_TI_SECURE_DEVICE
72 #define KS2_HS_SEC_HEADER_LEN 0x60
73 #define KS2_HS_SEC_TAG_OFFSET 0x34
74 #define KS2_AUTH_CMD 130
77 * k2_hs_bm_auth() - Invokes security functions using a
78 * proprietary TI interface. This binary and source for
79 * this is available in the secure development package or
80 * SECDEV. For details on how to access this please refer
81 * doc/README.ti-secure
83 * @cmd: Secure monitor command
84 * @arg1: Argument for command
86 * returns non-zero value on success, zero on error
88 static int k2_hs_bm_auth(int cmd, void *arg1)
93 "stmfd r13!, {r4-r12, lr}\n"
98 "ldmfd r13!, {r4-r12, lr}\n"
100 : "r" (cmd), "r" (arg1)
101 : "cc", "r0", "r1", "memory");
106 void board_fit_image_post_process(void **p_image, size_t *p_size)
109 void *image = *p_image;
111 if (strncmp(image + KS2_HS_SEC_TAG_OFFSET, "KEYS", 4)) {
112 printf("No signature found in image!\n");
116 result = k2_hs_bm_auth(KS2_AUTH_CMD, image);
118 printf("Authentication failed!\n");
123 * Overwrite the image headers after authentication
124 * and decryption. Update size to reflect removal
125 * of header and restore original file size.
127 *p_size = get_unaligned_le32(image + (*p_size - 4));
128 memcpy(image, image + KS2_HS_SEC_HEADER_LEN, *p_size);
131 * Output notification of successful authentication to re-assure the
132 * user that the secure code is being processed as expected. However
133 * suppress any such log output in case of building for SPL and booting
134 * via YMODEM. This is done to avoid disturbing the YMODEM serial
135 * protocol transactions.
137 if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
138 IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
139 spl_boot_device() == BOOT_DEVICE_UART))
140 printf("Authentication passed\n");