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