blob: 66f90a5a34dfdffc94b5948e1b5e3a6dff019724 [file] [log] [blame]
Andrew F. Davis2ed41072019-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. Davis2dc1e6e2020-01-07 18:22:29 -050010#include <cpu_func.h>
Andrew F. Davis2ed41072019-04-12 12:54:45 -040011#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -070012#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060013#include <image.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Andrew F. Davis2ed41072019-04-12 12:54:45 -040016#include <linux/soc/ti/ti_sci_protocol.h>
17#include <mach/spl.h>
18#include <spl.h>
Lokesh Vutlaac9ca952019-09-09 12:47:38 +053019#include <asm/arch/sys_proto.h>
Andrew F. Davis2ed41072019-04-12 12:54:45 -040020
21void board_fit_image_post_process(void **p_image, size_t *p_size)
22{
Lokesh Vutlaac9ca952019-09-09 12:47:38 +053023 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
24 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andrew F. Davis2ed41072019-04-12 12:54:45 -040025 u64 image_addr;
26 u32 image_size;
27 int ret;
28
Andrew F. Davis2ed41072019-04-12 12:54:45 -040029 image_addr = (uintptr_t)*p_image;
Andrew F. Davis2dc1e6e2020-01-07 18:22:29 -050030 image_size = *p_size;
Andrew F. Davis2ed41072019-04-12 12:54:45 -040031
32 debug("Authenticating image at address 0x%016llx\n", image_addr);
Andrew F. Davis2dc1e6e2020-01-07 18:22:29 -050033 debug("Authenticating image of size %d bytes\n", image_size);
34
35 flush_dcache_range((unsigned long)image_addr,
36 ALIGN((unsigned long)image_addr + image_size,
37 ARCH_DMA_MINALIGN));
Andrew F. Davis2ed41072019-04-12 12:54:45 -040038
39 /* Authenticate image */
40 ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
41 if (ret) {
42 printf("Authentication failed!\n");
43 hang();
44 }
45
Andrew F. Davis2dc1e6e2020-01-07 18:22:29 -050046 if (image_size)
47 invalidate_dcache_range((unsigned long)image_addr,
48 ALIGN((unsigned long)image_addr +
49 image_size, ARCH_DMA_MINALIGN));
50
Andrew F. Davis2ed41072019-04-12 12:54:45 -040051 /*
52 * The image_size returned may be 0 when the authentication process has
53 * moved the image. When this happens no further processing on the
54 * image is needed or often even possible as it may have also been
55 * placed behind a firewall when moved.
56 */
57 *p_size = image_size;
58
59 /*
60 * Output notification of successful authentication to re-assure the
61 * user that the secure code is being processed as expected. However
62 * suppress any such log output in case of building for SPL and booting
63 * via YMODEM. This is done to avoid disturbing the YMODEM serial
64 * protocol transactions.
65 */
66 if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
67 IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
68 spl_boot_device() == BOOT_DEVICE_UART))
69 printf("Authentication passed\n");
70}