blob: 52f49bf01fe2a1c360f920a885ec933e64c54b62 [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>
10#include <dm.h>
11#include <linux/soc/ti/ti_sci_protocol.h>
12#include <mach/spl.h>
13#include <spl.h>
14
15void board_fit_image_post_process(void **p_image, size_t *p_size)
16{
17 struct udevice *dev;
18 struct ti_sci_handle *ti_sci;
19 struct ti_sci_proc_ops *proc_ops;
20 u64 image_addr;
21 u32 image_size;
22 int ret;
23
24 /* Get handle to Device Management and Security Controller (SYSFW) */
25 ret = uclass_get_device_by_name(UCLASS_FIRMWARE, "dmsc", &dev);
26 if (ret) {
27 printf("Failed to get handle to SYSFW (%d)\n", ret);
28 hang();
29 }
30 ti_sci = (struct ti_sci_handle *)(ti_sci_get_handle_from_sysfw(dev));
31 proc_ops = &ti_sci->ops.proc_ops;
32
33 image_addr = (uintptr_t)*p_image;
34
35 debug("Authenticating image at address 0x%016llx\n", image_addr);
36
37 /* Authenticate image */
38 ret = proc_ops->proc_auth_boot_image(ti_sci, &image_addr, &image_size);
39 if (ret) {
40 printf("Authentication failed!\n");
41 hang();
42 }
43
44 /*
45 * The image_size returned may be 0 when the authentication process has
46 * moved the image. When this happens no further processing on the
47 * image is needed or often even possible as it may have also been
48 * placed behind a firewall when moved.
49 */
50 *p_size = image_size;
51
52 /*
53 * Output notification of successful authentication to re-assure the
54 * user that the secure code is being processed as expected. However
55 * suppress any such log output in case of building for SPL and booting
56 * via YMODEM. This is done to avoid disturbing the YMODEM serial
57 * protocol transactions.
58 */
59 if (!(IS_ENABLED(CONFIG_SPL_BUILD) &&
60 IS_ENABLED(CONFIG_SPL_YMODEM_SUPPORT) &&
61 spl_boot_device() == BOOT_DEVICE_UART))
62 printf("Authentication passed\n");
63}