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