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" |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 22 | #define HW_CONFIG_NAME "hw_config.dtb" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 23 | |
| 24 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 25 | #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 26 | #define TRUSTED_KEY_CERT_NAME "trusted_key.crt" |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 27 | #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt" |
| 28 | #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt" |
| 29 | #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt" |
| 30 | #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt" |
| 31 | #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt" |
| 32 | #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt" |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 33 | #endif /* TRUSTED_BOARD_BOOT */ |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 34 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 35 | /* IO devices */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 36 | static const io_dev_connector_t *sh_dev_con; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 37 | static uintptr_t sh_dev_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 38 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 39 | static const io_file_spec_t sh_file_spec[] = { |
| 40 | [BL2_IMAGE_ID] = { |
| 41 | .path = BL2_IMAGE_NAME, |
| 42 | .mode = FOPEN_MODE_RB |
| 43 | }, |
| 44 | [BL31_IMAGE_ID] = { |
| 45 | .path = BL31_IMAGE_NAME, |
| 46 | .mode = FOPEN_MODE_RB |
| 47 | }, |
| 48 | [BL32_IMAGE_ID] = { |
| 49 | .path = BL32_IMAGE_NAME, |
| 50 | .mode = FOPEN_MODE_RB |
| 51 | }, |
| 52 | [BL33_IMAGE_ID] = { |
| 53 | .path = BL33_IMAGE_NAME, |
| 54 | .mode = FOPEN_MODE_RB |
| 55 | }, |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 56 | [TB_FW_CONFIG_ID] = { |
| 57 | .path = TB_FW_CONFIG_NAME, |
| 58 | .mode = FOPEN_MODE_RB |
| 59 | }, |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 60 | [HW_CONFIG_ID] = { |
| 61 | .path = HW_CONFIG_NAME, |
| 62 | .mode = FOPEN_MODE_RB |
| 63 | }, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 64 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 65 | [TRUSTED_BOOT_FW_CERT_ID] = { |
| 66 | .path = TRUSTED_BOOT_FW_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 67 | .mode = FOPEN_MODE_RB |
| 68 | }, |
| 69 | [TRUSTED_KEY_CERT_ID] = { |
| 70 | .path = TRUSTED_KEY_CERT_NAME, |
| 71 | .mode = FOPEN_MODE_RB |
| 72 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 73 | [SOC_FW_KEY_CERT_ID] = { |
| 74 | .path = SOC_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 75 | .mode = FOPEN_MODE_RB |
| 76 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 77 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
| 78 | .path = TOS_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 79 | .mode = FOPEN_MODE_RB |
| 80 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 81 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
| 82 | .path = NT_FW_KEY_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 83 | .mode = FOPEN_MODE_RB |
| 84 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 85 | [SOC_FW_CONTENT_CERT_ID] = { |
| 86 | .path = SOC_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 87 | .mode = FOPEN_MODE_RB |
| 88 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 89 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
| 90 | .path = TOS_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 91 | .mode = FOPEN_MODE_RB |
| 92 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 93 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
| 94 | .path = NT_FW_CONTENT_CERT_NAME, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 95 | .mode = FOPEN_MODE_RB |
| 96 | }, |
| 97 | #endif /* TRUSTED_BOARD_BOOT */ |
| 98 | }; |
| 99 | |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 100 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 101 | static int open_semihosting(const uintptr_t spec) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 102 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 103 | int result; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 104 | uintptr_t local_image_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 105 | |
| 106 | /* See if the file exists on semi-hosting.*/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 107 | result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 108 | if (result == 0) { |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 109 | result = io_open(sh_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 110 | if (result == 0) { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 111 | VERBOSE("Using Semi-hosting IO\n"); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 112 | io_close(local_image_handle); |
| 113 | } |
| 114 | } |
| 115 | return result; |
| 116 | } |
| 117 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 118 | void plat_arm_io_setup(void) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 119 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 120 | int io_result; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 121 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 122 | arm_io_setup(); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 123 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 124 | /* Register the additional IO devices on this platform */ |
| 125 | io_result = register_io_dev_sh(&sh_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 126 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 127 | |
| 128 | /* Open connections to devices and cache the handles */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 129 | 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] | 130 | assert(io_result == 0); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 131 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 132 | /* Ignore improbable errors in release builds */ |
| 133 | (void)io_result; |
| 134 | } |
| 135 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 136 | /* |
| 137 | * FVP provides semihosting as an alternative to load images |
| 138 | */ |
| 139 | int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 140 | uintptr_t *image_spec) |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 141 | { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 142 | int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 143 | if (result == 0) { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 144 | *dev_handle = sh_dev_handle; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 145 | *image_spec = (uintptr_t)&sh_file_spec[image_id]; |
| 146 | } |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 147 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 148 | return result; |
| 149 | } |