blob: f18303ffa06a0053066d4a1472be44fbbf73fae6 [file] [log] [blame]
James Morrissey9d72b4e2014-02-10 17:04:32 +00001/*
Soby Mathew7c6df5b2018-01-15 14:43:42 +00002 * Copyright (c) 2014-2018, 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"
Soby Mathew7c6df5b2018-01-15 14:43:42 +000021#define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb"
Juan Castillo3a66aca2015-04-13 17:36:19 +010022
23#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000024#define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010025#define TRUSTED_KEY_CERT_NAME "trusted_key.crt"
Juan Castillobe801202015-12-03 10:19:21 +000026#define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt"
27#define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt"
28#define NT_FW_KEY_CERT_NAME "nt_fw_key.crt"
29#define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt"
30#define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt"
31#define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt"
Juan Castillo3a66aca2015-04-13 17:36:19 +010032#endif /* TRUSTED_BOARD_BOOT */
James Morrissey9d72b4e2014-02-10 17:04:32 +000033
James Morrissey9d72b4e2014-02-10 17:04:32 +000034/* IO devices */
Dan Handleya4cb68e2014-04-23 13:47:06 +010035static const io_dev_connector_t *sh_dev_con;
Dan Handleya4cb68e2014-04-23 13:47:06 +010036static uintptr_t sh_dev_handle;
Harry Liebel561cd332014-02-14 14:42:48 +000037
Juan Castillo3a66aca2015-04-13 17:36:19 +010038static const io_file_spec_t sh_file_spec[] = {
39 [BL2_IMAGE_ID] = {
40 .path = BL2_IMAGE_NAME,
41 .mode = FOPEN_MODE_RB
42 },
43 [BL31_IMAGE_ID] = {
44 .path = BL31_IMAGE_NAME,
45 .mode = FOPEN_MODE_RB
46 },
47 [BL32_IMAGE_ID] = {
48 .path = BL32_IMAGE_NAME,
49 .mode = FOPEN_MODE_RB
50 },
51 [BL33_IMAGE_ID] = {
52 .path = BL33_IMAGE_NAME,
53 .mode = FOPEN_MODE_RB
54 },
Soby Mathew7c6df5b2018-01-15 14:43:42 +000055 [TB_FW_CONFIG_ID] = {
56 .path = TB_FW_CONFIG_NAME,
57 .mode = FOPEN_MODE_RB
58 },
Juan Castillo3a66aca2015-04-13 17:36:19 +010059#if TRUSTED_BOARD_BOOT
Juan Castillobe801202015-12-03 10:19:21 +000060 [TRUSTED_BOOT_FW_CERT_ID] = {
61 .path = TRUSTED_BOOT_FW_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010062 .mode = FOPEN_MODE_RB
63 },
64 [TRUSTED_KEY_CERT_ID] = {
65 .path = TRUSTED_KEY_CERT_NAME,
66 .mode = FOPEN_MODE_RB
67 },
Juan Castillobe801202015-12-03 10:19:21 +000068 [SOC_FW_KEY_CERT_ID] = {
69 .path = SOC_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010070 .mode = FOPEN_MODE_RB
71 },
Juan Castillobe801202015-12-03 10:19:21 +000072 [TRUSTED_OS_FW_KEY_CERT_ID] = {
73 .path = TOS_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010074 .mode = FOPEN_MODE_RB
75 },
Juan Castillobe801202015-12-03 10:19:21 +000076 [NON_TRUSTED_FW_KEY_CERT_ID] = {
77 .path = NT_FW_KEY_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010078 .mode = FOPEN_MODE_RB
79 },
Juan Castillobe801202015-12-03 10:19:21 +000080 [SOC_FW_CONTENT_CERT_ID] = {
81 .path = SOC_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010082 .mode = FOPEN_MODE_RB
83 },
Juan Castillobe801202015-12-03 10:19:21 +000084 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
85 .path = TOS_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010086 .mode = FOPEN_MODE_RB
87 },
Juan Castillobe801202015-12-03 10:19:21 +000088 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
89 .path = NT_FW_CONTENT_CERT_NAME,
Juan Castillo3a66aca2015-04-13 17:36:19 +010090 .mode = FOPEN_MODE_RB
91 },
92#endif /* TRUSTED_BOARD_BOOT */
93};
94
Harry Liebel561cd332014-02-14 14:42:48 +000095
Dan Handleya4cb68e2014-04-23 13:47:06 +010096static int open_semihosting(const uintptr_t spec)
Harry Liebel561cd332014-02-14 14:42:48 +000097{
Juan Castillo6e762062015-11-02 10:47:01 +000098 int result;
Dan Handleya4cb68e2014-04-23 13:47:06 +010099 uintptr_t local_image_handle;
Harry Liebel561cd332014-02-14 14:42:48 +0000100
101 /* See if the file exists on semi-hosting.*/
Dan Handley2b6b5742015-03-19 19:17:53 +0000102 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +0000103 if (result == 0) {
Harry Liebel561cd332014-02-14 14:42:48 +0000104 result = io_open(sh_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000105 if (result == 0) {
Dan Handley91b624e2014-07-29 17:14:00 +0100106 VERBOSE("Using Semi-hosting IO\n");
Harry Liebel561cd332014-02-14 14:42:48 +0000107 io_close(local_image_handle);
108 }
109 }
110 return result;
111}
112
Dan Handley2b6b5742015-03-19 19:17:53 +0000113void plat_arm_io_setup(void)
Harry Liebel561cd332014-02-14 14:42:48 +0000114{
Dan Handley2b6b5742015-03-19 19:17:53 +0000115 int io_result;
Harry Liebel561cd332014-02-14 14:42:48 +0000116
Dan Handley2b6b5742015-03-19 19:17:53 +0000117 arm_io_setup();
Harry Liebel561cd332014-02-14 14:42:48 +0000118
Dan Handley2b6b5742015-03-19 19:17:53 +0000119 /* Register the additional IO devices on this platform */
120 io_result = register_io_dev_sh(&sh_dev_con);
Juan Castillo6e762062015-11-02 10:47:01 +0000121 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000122
123 /* Open connections to devices and cache the handles */
Dan Handley2b6b5742015-03-19 19:17:53 +0000124 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle);
Juan Castillo6e762062015-11-02 10:47:01 +0000125 assert(io_result == 0);
Harry Liebel561cd332014-02-14 14:42:48 +0000126
James Morrissey9d72b4e2014-02-10 17:04:32 +0000127 /* Ignore improbable errors in release builds */
128 (void)io_result;
129}
130
Juan Castillo3a66aca2015-04-13 17:36:19 +0100131/*
132 * FVP provides semihosting as an alternative to load images
133 */
134int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle,
135 uintptr_t *image_spec)
James Morrissey9d72b4e2014-02-10 17:04:32 +0000136{
Juan Castillo3a66aca2015-04-13 17:36:19 +0100137 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]);
Juan Castillo6e762062015-11-02 10:47:01 +0000138 if (result == 0) {
Dan Handley2b6b5742015-03-19 19:17:53 +0000139 *dev_handle = sh_dev_handle;
Juan Castillo3a66aca2015-04-13 17:36:19 +0100140 *image_spec = (uintptr_t)&sh_file_spec[image_id];
141 }
James Morrissey9d72b4e2014-02-10 17:04:32 +0000142
James Morrissey9d72b4e2014-02-10 17:04:32 +0000143 return result;
144}