common: Move hang() to the same header as panic()
[platform/kernel/u-boot.git] / arch / arm / mach-k3 / security.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * K3: Security functions
4  *
5  * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6  *      Andrew F. Davis <afd@ti.com>
7  */
8
9 #include <common.h>
10 #include <dm.h>
11 #include <hang.h>
12 #include <linux/soc/ti/ti_sci_protocol.h>
13 #include <mach/spl.h>
14 #include <spl.h>
15 #include <asm/arch/sys_proto.h>
16
17 void board_fit_image_post_process(void **p_image, size_t *p_size)
18 {
19         struct ti_sci_handle *ti_sci = get_ti_sci_handle();
20         struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
21         u64 image_addr;
22         u32 image_size;
23         int ret;
24
25         image_addr = (uintptr_t)*p_image;
26
27         debug("Authenticating image at address 0x%016llx\n", image_addr);
28
29         /* Authenticate image */
30         ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
31         if (ret) {
32                 printf("Authentication failed!\n");
33                 hang();
34         }
35
36         /*
37          * The image_size returned may be 0 when the authentication process has
38          * moved the image. When this happens no further processing on the
39          * image is needed or often even possible as it may have also been
40          * placed behind a firewall when moved.
41          */
42         *p_size = image_size;
43
44         /*
45          * Output notification of successful authentication to re-assure the
46          * user that the secure code is being processed as expected. However
47          * suppress any such log output in case of building for SPL and booting
48          * via YMODEM. This is done to avoid disturbing the YMODEM serial
49          * protocol transactions.
50          */
51         if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
52               IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
53               spl_boot_device() == BOOT_DEVICE_UART))
54                 printf("Authentication passed\n");
55 }