2019-04-13 01:54:45 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* K3: Security functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
* Andrew F. Davis <afd@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-01-08 08:22:29 +09:00
|
|
|
#include <cpu_func.h>
|
2019-04-13 01:54:45 +09:00
|
|
|
#include <dm.h>
|
2019-12-29 02:45:07 +09:00
|
|
|
#include <hang.h>
|
2020-05-11 02:39:56 +09:00
|
|
|
#include <asm/cache.h>
|
2019-04-13 01:54:45 +09:00
|
|
|
#include <linux/soc/ti/ti_sci_protocol.h>
|
|
|
|
#include <mach/spl.h>
|
|
|
|
#include <spl.h>
|
2019-09-09 16:17:38 +09:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2019-04-13 01:54:45 +09:00
|
|
|
|
|
|
|
void board_fit_image_post_process(void **p_image, size_t *p_size)
|
|
|
|
{
|
2019-09-09 16:17:38 +09:00
|
|
|
struct ti_sci_handle *ti_sci = get_ti_sci_handle();
|
|
|
|
struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
|
2019-04-13 01:54:45 +09:00
|
|
|
u64 image_addr;
|
|
|
|
u32 image_size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
image_addr = (uintptr_t)*p_image;
|
2020-01-08 08:22:29 +09:00
|
|
|
image_size = *p_size;
|
2019-04-13 01:54:45 +09:00
|
|
|
|
|
|
|
debug("Authenticating image at address 0x%016llx\n", image_addr);
|
2020-01-08 08:22:29 +09:00
|
|
|
debug("Authenticating image of size %d bytes\n", image_size);
|
|
|
|
|
|
|
|
flush_dcache_range((unsigned long)image_addr,
|
|
|
|
ALIGN((unsigned long)image_addr + image_size,
|
|
|
|
ARCH_DMA_MINALIGN));
|
2019-04-13 01:54:45 +09:00
|
|
|
|
|
|
|
/* Authenticate image */
|
|
|
|
ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
|
|
|
|
if (ret) {
|
|
|
|
printf("Authentication failed!\n");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2020-01-08 08:22:29 +09:00
|
|
|
if (image_size)
|
|
|
|
invalidate_dcache_range((unsigned long)image_addr,
|
|
|
|
ALIGN((unsigned long)image_addr +
|
|
|
|
image_size, ARCH_DMA_MINALIGN));
|
|
|
|
|
2019-04-13 01:54:45 +09:00
|
|
|
/*
|
|
|
|
* The image_size returned may be 0 when the authentication process has
|
|
|
|
* moved the image. When this happens no further processing on the
|
|
|
|
* image is needed or often even possible as it may have also been
|
|
|
|
* placed behind a firewall when moved.
|
|
|
|
*/
|
|
|
|
*p_size = image_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output notification of successful authentication to re-assure the
|
|
|
|
* user that the secure code is being processed as expected. However
|
|
|
|
* suppress any such log output in case of building for SPL and booting
|
|
|
|
* via YMODEM. This is done to avoid disturbing the YMODEM serial
|
|
|
|
* protocol transactions.
|
|
|
|
*/
|
|
|
|
if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
|
|
|
|
IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
|
|
|
|
spl_boot_device() == BOOT_DEVICE_UART))
|
|
|
|
printf("Authentication passed\n");
|
|
|
|
}
|