1 // SPDX-License-Identifier: GPL-2.0+
3 * K2HK: secure kernel command file
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
13 asm(".arch_extension sec\n\t");
15 int mon_install(u32 addr, u32 dpsc, u32 freq, u32 bm_addr)
19 __asm__ __volatile__ (
29 : "r" (addr), "r" (dpsc), "r" (freq), "r" (bm_addr)
30 : "cc", "r0", "r1", "r2", "r3", "memory");
34 int mon_power_on(int core_id, void *ep)
47 : "r" (core_id), "r" (ep)
48 : "cc", "r0", "r1", "r2", "memory");
52 int mon_power_off(int core_id)
65 : "cc", "r0", "r1", "memory");
69 #ifdef CONFIG_TI_SECURE_DEVICE
70 #define KS2_HS_SEC_HEADER_LEN 0x60
71 #define KS2_HS_SEC_TAG_OFFSET 0x34
72 #define KS2_AUTH_CMD 130
75 * k2_hs_bm_auth() - Invokes security functions using a
76 * proprietary TI interface. This binary and source for
77 * this is available in the secure development package or
78 * SECDEV. For details on how to access this please refer
79 * doc/README.ti-secure
81 * @cmd: Secure monitor command
82 * @arg1: Argument for command
84 * returns non-zero value on success, zero on error
86 static int k2_hs_bm_auth(int cmd, void *arg1)
91 "stmfd r13!, {r4-r12, lr}\n"
96 "ldmfd r13!, {r4-r12, lr}\n"
98 : "r" (cmd), "r" (arg1)
99 : "cc", "r0", "r1", "memory");
104 void board_fit_image_post_process(void **p_image, size_t *p_size)
107 void *image = *p_image;
109 if (strncmp(image + KS2_HS_SEC_TAG_OFFSET, "KEYS", 4)) {
110 printf("No signature found in image!\n");
114 result = k2_hs_bm_auth(KS2_AUTH_CMD, image);
116 printf("Authentication failed!\n");
121 * Overwrite the image headers after authentication
122 * and decryption. Update size to reflect removal
125 *p_size -= KS2_HS_SEC_HEADER_LEN;
126 memcpy(image, image + KS2_HS_SEC_HEADER_LEN, *p_size);
129 * Output notification of successful authentication to re-assure the
130 * user that the secure code is being processed as expected. However
131 * suppress any such log output in case of building for SPL and booting
132 * via YMODEM. This is done to avoid disturbing the YMODEM serial
133 * protocol transactions.
135 if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
136 IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
137 spl_boot_device() == BOOT_DEVICE_UART))
138 printf("Authentication passed\n");