blob: 83b037f189b60b9e88b0391bf3ef04da3767f904 [file] [log] [blame]
Andrew F. Davis3a543a82019-04-12 12:54:45 -04001// 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. Davis95b256e2020-01-07 18:22:29 -050010#include <cpu_func.h>
Andrew F. Davis3a543a82019-04-12 12:54:45 -040011#include <dm.h>
12#include <linux/soc/ti/ti_sci_protocol.h>
13#include <mach/spl.h>
14#include <spl.h>
Lokesh Vutla78e51212019-09-09 12:47:38 +053015#include <asm/arch/sys_proto.h>
Andrew F. Davis3a543a82019-04-12 12:54:45 -040016
17void board_fit_image_post_process(void **p_image, size_t *p_size)
18{
Lokesh Vutla78e51212019-09-09 12:47:38 +053019 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
20 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andrew F. Davis3a543a82019-04-12 12:54:45 -040021 u64 image_addr;
22 u32 image_size;
23 int ret;
24
Andrew F. Davis3a543a82019-04-12 12:54:45 -040025 image_addr = (uintptr_t)*p_image;
Andrew F. Davis95b256e2020-01-07 18:22:29 -050026 image_size = *p_size;
Andrew F. Davis3a543a82019-04-12 12:54:45 -040027
28 debug("Authenticating image at address 0x%016llx\n", image_addr);
Andrew F. Davis95b256e2020-01-07 18:22:29 -050029 debug("Authenticating image of size %d bytes\n", image_size);
30
31 flush_dcache_range((unsigned long)image_addr,
32 ALIGN((unsigned long)image_addr + image_size,
33 ARCH_DMA_MINALIGN));
Andrew F. Davis3a543a82019-04-12 12:54:45 -040034
35 /* Authenticate image */
36 ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
37 if (ret) {
38 printf("Authentication failed!\n");
39 hang();
40 }
41
Andrew F. Davis95b256e2020-01-07 18:22:29 -050042 if (image_size)
43 invalidate_dcache_range((unsigned long)image_addr,
44 ALIGN((unsigned long)image_addr +
45 image_size, ARCH_DMA_MINALIGN));
46
Andrew F. Davis3a543a82019-04-12 12:54:45 -040047 /*
48 * The image_size returned may be 0 when the authentication process has
49 * moved the image. When this happens no further processing on the
50 * image is needed or often even possible as it may have also been
51 * placed behind a firewall when moved.
52 */
53 *p_size = image_size;
54
55 /*
56 * Output notification of successful authentication to re-assure the
57 * user that the secure code is being processed as expected. However
58 * suppress any such log output in case of building for SPL and booting
59 * via YMODEM. This is done to avoid disturbing the YMODEM serial
60 * protocol transactions.
61 */
62 if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
63 IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
64 spl_boot_device() == BOOT_DEVICE_UART))
65 printf("Authentication passed\n");
66}