blob: aa2ee305661f241eeca84b129f7f40b352f5ca1a [file] [log] [blame]
James Morrissey9d72b4e2014-02-10 17:04:32 +00001/*
Dan Handley2b6b5742015-03-19 19:17:53 +00002 * Copyright (c) 2014-2015, ARM Limited and Contributors. All rights reserved.
James Morrissey9d72b4e2014-02-10 17:04:32 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
James Morrissey9d72b4e2014-02-10 17:04:32 +00005 */
6
7#include <assert.h>
Juan Castillo3a66aca2015-04-13 17:36:19 +01008#include <common_def.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +01009#include <debug.h>
Dan Handley714a0d22014-04-09 13:13:04 +010010#include <io_driver.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010011#include <io_semihosting.h>
Isla Mitchelld2548792017-07-14 10:48:25 +010012#include <io_storage.h>
Dan Handley2b6b5742015-03-19 19:17:53 +000013#include <plat_arm.h>
Juan Castillo3a66aca2015-04-13 17:36:19 +010014#include <semihosting.h> /* For FOPEN_MODE_... */
15
16/* Semihosting filenames */
17#define BL2_IMAGE_NAME "bl2.bin"
18#define BL31_IMAGE_NAME "bl31.bin"
19#define BL32_IMAGE_NAME "bl32.bin"
20#define BL33_IMAGE_NAME "bl33.bin"
21
22#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000023#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010024#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Juan Castillobe801202015-12-03 10:19:21 +000025#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
26#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
27#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
28#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
29#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
30#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010031#endif /* TRUSTED_BOARD_BOOT */
James Morrissey9d72b4e2014-02-10 17:04:32 +000032
James Morrissey9d72b4e2014-02-10 17:04:32 +000033/* IO devices */
Dan Handleya4cb68e2014-04-23 13:47:06 +010034static const io_dev_connector_t *sh_dev_con;
Dan Handleya4cb68e2014-04-23 13:47:06 +010035static uintptr_t sh_dev_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000036
Juan Castillo3a66aca2015-04-13 17:36:19 +010037static const io_file_spec_t sh_file_spec[] = {
38 [BL2_IMAGE_ID] = {
39 .path = BL2_IMAGE_NAME,
40 .mode = FOPEN_MODE_RB
41 },
42 [BL31_IMAGE_ID] = {
43 .path = BL31_IMAGE_NAME,
44 .mode = FOPEN_MODE_RB
45 },
46 [BL32_IMAGE_ID] = {
47 .path = BL32_IMAGE_NAME,
48 .mode = FOPEN_MODE_RB
49 },
50 [BL33_IMAGE_ID] = {
51 .path = BL33_IMAGE_NAME,
52 .mode = FOPEN_MODE_RB
53 },
54#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000055 [TRUSTED_BOOT_FW_CERT_ID] = {
56 .path = TRUSTED_BOOT_FW_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010057 .mode = FOPEN_MODE_RB
58 },
59 [TRUSTED_KEY_CERT_ID] = {
60 .path = TRUSTED_KEY_CERT_NAME,
61 .mode = FOPEN_MODE_RB
62 },
Juan Castillobe801202015-12-03 10:19:21 +000063 [SOC_FW_KEY_CERT_ID] = {
64 .path = SOC_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010065 .mode = FOPEN_MODE_RB
66 },
Juan Castillobe801202015-12-03 10:19:21 +000067 [TRUSTED_OS_FW_KEY_CERT_ID] = {
68 .path = TOS_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010069 .mode = FOPEN_MODE_RB
70 },
Juan Castillobe801202015-12-03 10:19:21 +000071 [NON_TRUSTED_FW_KEY_CERT_ID] = {
72 .path = NT_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010073 .mode = FOPEN_MODE_RB
74 },
Juan Castillobe801202015-12-03 10:19:21 +000075 [SOC_FW_CONTENT_CERT_ID] = {
76 .path = SOC_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010077 .mode = FOPEN_MODE_RB
78 },
Juan Castillobe801202015-12-03 10:19:21 +000079 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
80 .path = TOS_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010081 .mode = FOPEN_MODE_RB
82 },
Juan Castillobe801202015-12-03 10:19:21 +000083 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
84 .path = NT_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010085 .mode = FOPEN_MODE_RB
86 },
87#endif /* TRUSTED_BOARD_BOOT */
88};
89
Harry Liebel561cd332014-02-14 14:42:48 +000090
Dan Handleya4cb68e2014-04-23 13:47:06 +010091static int open_semihosting(const uintptr_t spec)
Harry Liebel561cd332014-02-14 14:42:48 +000092{
Juan Castillo6e762062015-11-02 10:47:01 +000093 int result;
Dan Handleya4cb68e2014-04-23 13:47:06 +010094 uintptr_t local_image_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000095
96 /* See if the file exists on semi-hosting.*/
Dan Handley2b6b5742015-03-19 19:17:53 +000097 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +000098 if (result == 0) {
Harry Liebel561cd332014-02-14 14:42:48 +000099 result = io_open(sh_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000100 if (result == 0) {
Dan Handley91b624e2014-07-29 17:14:00 +0100101 VERBOSE("Using Semi-hosting IO\n");
Harry Liebel561cd332014-02-14 14:42:48 +0000102 io_close(local_image_handle);
103 }
104 }
105 return result;
106}
107
Dan Handley2b6b5742015-03-19 19:17:53 +0000108void plat_arm_io_setup(void)
Harry Liebel561cd332014-02-14 14:42:48 +0000109{
Dan Handley2b6b5742015-03-19 19:17:53 +0000110 int io_result;
Harry Liebel561cd332014-02-14 14:42:48 +0000111
Dan Handley2b6b5742015-03-19 19:17:53 +0000112 arm_io_setup();
Harry Liebel561cd332014-02-14 14:42:48 +0000113
Dan Handley2b6b5742015-03-19 19:17:53 +0000114 /* Register the additional IO devices on this platform */
115 io_result = register_io_dev_sh(&sh_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000116 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000117
118 /* Open connections to devices and cache the handles */
Dan Handley2b6b5742015-03-19 19:17:53 +0000119 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000120 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000121
James Morrissey9d72b4e2014-02-10 17:04:32 +0000122 /* Ignore improbable errors in release builds */
123 (void)io_result;
124}
125
Juan Castillo3a66aca2015-04-13 17:36:19 +0100126/*
127 * FVP provides semihosting as an alternative to load images
128 */
129int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
130 uintptr_t *image_spec)
James Morrissey9d72b4e2014-02-10 17:04:32 +0000131{
Juan Castillo3a66aca2015-04-13 17:36:19 +0100132 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
Juan Castillo6e762062015-11-02 10:47:01 +0000133 if (result == 0) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000134 *dev_handle = sh_dev_handle;
Juan Castillo3a66aca2015-04-13 17:36:19 +0100135 *image_spec = (uintptr_t)&sh_file_spec[image_id];
136 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000137
James Morrissey9d72b4e2014-02-10 17:04:32 +0000138 return result;
139}