Merge tag '2020-01-20-ti-2020.04' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/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 <cpu_func.h>
11 #include <dm.h>
12 #include <hang.h>
13 #include <linux/soc/ti/ti_sci_protocol.h>
14 #include <mach/spl.h>
15 #include <spl.h>
16 #include <asm/arch/sys_proto.h>
17
18 void board_fit_image_post_process(void **p_image, size_t *p_size)
19 {
20         struct ti_sci_handle *ti_sci = get_ti_sci_handle();
21         struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
22         u64 image_addr;
23         u32 image_size;
24         int ret;
25
26         image_addr = (uintptr_t)*p_image;
27         image_size = *p_size;
28
29         debug("Authenticating image at address 0x%016llx\n", image_addr);
30         debug("Authenticating image of size %d bytes\n", image_size);
31
32         flush_dcache_range((unsigned long)image_addr,
33                            ALIGN((unsigned long)image_addr + image_size,
34                                  ARCH_DMA_MINALIGN));
35
36         /* Authenticate image */
37         ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
38         if (ret) {
39                 printf("Authentication failed!\n");
40                 hang();
41         }
42
43         if (image_size)
44                 invalidate_dcache_range((unsigned long)image_addr,
45                                         ALIGN((unsigned long)image_addr +
46                                               image_size, ARCH_DMA_MINALIGN));
47
48         /*
49          * The image_size returned may be 0 when the authentication process has
50          * moved the image. When this happens no further processing on the
51          * image is needed or often even possible as it may have also been
52          * placed behind a firewall when moved.
53          */
54         *p_size = image_size;
55
56         /*
57          * Output notification of successful authentication to re-assure the
58          * user that the secure code is being processed as expected. However
59          * suppress any such log output in case of building for SPL and booting
60          * via YMODEM. This is done to avoid disturbing the YMODEM serial
61          * protocol transactions.
62          */
63         if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
64               IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
65               spl_boot_device() == BOOT_DEVICE_UART))
66                 printf("Authentication passed\n");
67 }