James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 8 | #include <common_def.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 9 | #include <debug.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 10 | #include <io_driver.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 11 | #include <io_semihosting.h> |
Isla Mitchell | d254879 | 2017-07-14 10:48:25 +0100 | [diff] [blame] | 12 | #include <io_storage.h> |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 13 | #include <plat_arm.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 14 | #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 Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame^] | 21 | #define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 22 | |
| 23 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 24 | #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 25 | #define TRUSTED_KEY_CERT_NAME "trusted_key.crt" |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 26 | #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 Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 32 | #endif /* TRUSTED_BOARD_BOOT */ |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 33 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 34 | /* IO devices */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 35 | static const io_dev_connector_t *sh_dev_con; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 36 | static uintptr_t sh_dev_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 37 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 38 | static 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 Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame^] | 55 | [TB_FW_CONFIG_ID] = { |
| 56 | .path = TB_FW_CONFIG_NAME, |
| 57 | .mode = FOPEN_MODE_RB |
| 58 | }, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 59 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 60 | [TRUSTED_BOOT_FW_CERT_ID] = { |
| 61 | .path = TRUSTED_BOOT_FW_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 62 | .mode = FOPEN_MODE_RB |
| 63 | }, |
| 64 | [TRUSTED_KEY_CERT_ID] = { |
| 65 | .path = TRUSTED_KEY_CERT_NAME, |
| 66 | .mode = FOPEN_MODE_RB |
| 67 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 68 | [SOC_FW_KEY_CERT_ID] = { |
| 69 | .path = SOC_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 70 | .mode = FOPEN_MODE_RB |
| 71 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 72 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
| 73 | .path = TOS_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 74 | .mode = FOPEN_MODE_RB |
| 75 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 76 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
| 77 | .path = NT_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 78 | .mode = FOPEN_MODE_RB |
| 79 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 80 | [SOC_FW_CONTENT_CERT_ID] = { |
| 81 | .path = SOC_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 82 | .mode = FOPEN_MODE_RB |
| 83 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 84 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
| 85 | .path = TOS_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 86 | .mode = FOPEN_MODE_RB |
| 87 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 88 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
| 89 | .path = NT_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 90 | .mode = FOPEN_MODE_RB |
| 91 | }, |
| 92 | #endif /* TRUSTED_BOARD_BOOT */ |
| 93 | }; |
| 94 | |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 95 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 96 | static int open_semihosting(const uintptr_t spec) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 97 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 98 | int result; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 99 | uintptr_t local_image_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 100 | |
| 101 | /* See if the file exists on semi-hosting.*/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 102 | result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 103 | if (result == 0) { |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 104 | result = io_open(sh_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 105 | if (result == 0) { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 106 | VERBOSE("Using Semi-hosting IO\n"); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 107 | io_close(local_image_handle); |
| 108 | } |
| 109 | } |
| 110 | return result; |
| 111 | } |
| 112 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 113 | void plat_arm_io_setup(void) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 114 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 115 | int io_result; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 116 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 117 | arm_io_setup(); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 118 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 119 | /* Register the additional IO devices on this platform */ |
| 120 | io_result = register_io_dev_sh(&sh_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 121 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 122 | |
| 123 | /* Open connections to devices and cache the handles */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 124 | 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] | 125 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 126 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 127 | /* Ignore improbable errors in release builds */ |
| 128 | (void)io_result; |
| 129 | } |
| 130 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 131 | /* |
| 132 | * FVP provides semihosting as an alternative to load images |
| 133 | */ |
| 134 | int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 135 | uintptr_t *image_spec) |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 136 | { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 137 | int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 138 | if (result == 0) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 139 | *dev_handle = sh_dev_handle; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 140 | *image_spec = (uintptr_t)&sh_file_spec[image_id]; |
| 141 | } |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 142 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 143 | return result; |
| 144 | } |