James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 1 | /* |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 2 | * Copyright (c) 2014-2015, ARM Limited and Contributors. All rights reserved. |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <assert.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 32 | #include <common_def.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <debug.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 34 | #include <io_driver.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 35 | #include <io_storage.h> |
| 36 | #include <io_semihosting.h> |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 37 | #include <plat_arm.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 38 | #include <semihosting.h> /* For FOPEN_MODE_... */ |
| 39 | |
| 40 | /* Semihosting filenames */ |
| 41 | #define BL2_IMAGE_NAME "bl2.bin" |
| 42 | #define BL31_IMAGE_NAME "bl31.bin" |
| 43 | #define BL32_IMAGE_NAME "bl32.bin" |
| 44 | #define BL33_IMAGE_NAME "bl33.bin" |
| 45 | |
| 46 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 47 | #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 48 | #define TRUSTED_KEY_CERT_NAME "trusted_key.crt" |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 49 | #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt" |
| 50 | #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt" |
| 51 | #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt" |
| 52 | #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt" |
| 53 | #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt" |
| 54 | #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 55 | #endif /* TRUSTED_BOARD_BOOT */ |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 56 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 57 | /* IO devices */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 58 | static const io_dev_connector_t *sh_dev_con; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 59 | static uintptr_t sh_dev_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 60 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 61 | static const io_file_spec_t sh_file_spec[] = { |
| 62 | [BL2_IMAGE_ID] = { |
| 63 | .path = BL2_IMAGE_NAME, |
| 64 | .mode = FOPEN_MODE_RB |
| 65 | }, |
| 66 | [BL31_IMAGE_ID] = { |
| 67 | .path = BL31_IMAGE_NAME, |
| 68 | .mode = FOPEN_MODE_RB |
| 69 | }, |
| 70 | [BL32_IMAGE_ID] = { |
| 71 | .path = BL32_IMAGE_NAME, |
| 72 | .mode = FOPEN_MODE_RB |
| 73 | }, |
| 74 | [BL33_IMAGE_ID] = { |
| 75 | .path = BL33_IMAGE_NAME, |
| 76 | .mode = FOPEN_MODE_RB |
| 77 | }, |
| 78 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 79 | [TRUSTED_BOOT_FW_CERT_ID] = { |
| 80 | .path = TRUSTED_BOOT_FW_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 81 | .mode = FOPEN_MODE_RB |
| 82 | }, |
| 83 | [TRUSTED_KEY_CERT_ID] = { |
| 84 | .path = TRUSTED_KEY_CERT_NAME, |
| 85 | .mode = FOPEN_MODE_RB |
| 86 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 87 | [SOC_FW_KEY_CERT_ID] = { |
| 88 | .path = SOC_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 89 | .mode = FOPEN_MODE_RB |
| 90 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 91 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
| 92 | .path = TOS_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 93 | .mode = FOPEN_MODE_RB |
| 94 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 95 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
| 96 | .path = NT_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 97 | .mode = FOPEN_MODE_RB |
| 98 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 99 | [SOC_FW_CONTENT_CERT_ID] = { |
| 100 | .path = SOC_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 101 | .mode = FOPEN_MODE_RB |
| 102 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 103 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
| 104 | .path = TOS_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 105 | .mode = FOPEN_MODE_RB |
| 106 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 107 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
| 108 | .path = NT_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 109 | .mode = FOPEN_MODE_RB |
| 110 | }, |
| 111 | #endif /* TRUSTED_BOARD_BOOT */ |
| 112 | }; |
| 113 | |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 114 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 115 | static int open_semihosting(const uintptr_t spec) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 116 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 117 | int result; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 118 | uintptr_t local_image_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 119 | |
| 120 | /* See if the file exists on semi-hosting.*/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 121 | result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 122 | if (result == 0) { |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 123 | result = io_open(sh_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 124 | if (result == 0) { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 125 | VERBOSE("Using Semi-hosting IO\n"); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 126 | io_close(local_image_handle); |
| 127 | } |
| 128 | } |
| 129 | return result; |
| 130 | } |
| 131 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 132 | void plat_arm_io_setup(void) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 133 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 134 | int io_result; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 135 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 136 | arm_io_setup(); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 137 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 138 | /* Register the additional IO devices on this platform */ |
| 139 | io_result = register_io_dev_sh(&sh_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 140 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 141 | |
| 142 | /* Open connections to devices and cache the handles */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 143 | io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 144 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 145 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 146 | /* Ignore improbable errors in release builds */ |
| 147 | (void)io_result; |
| 148 | } |
| 149 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 150 | /* |
| 151 | * FVP provides semihosting as an alternative to load images |
| 152 | */ |
| 153 | int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 154 | uintptr_t *image_spec) |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 155 | { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 156 | int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 157 | if (result == 0) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 158 | *dev_handle = sh_dev_handle; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 159 | *image_spec = (uintptr_t)&sh_file_spec[image_id]; |
| 160 | } |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 161 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 162 | return result; |
| 163 | } |