1 /* 2 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <common_def.h> 9 #include <debug.h> 10 #include <io_driver.h> 11 #include <io_semihosting.h> 12 #include <io_storage.h> 13 #include <plat_arm.h> 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 #define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb" 22 23 #if TRUSTED_BOARD_BOOT 24 #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt" 25 #define TRUSTED_KEY_CERT_NAME "trusted_key.crt" 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" 32 #endif /* TRUSTED_BOARD_BOOT */ 33 34 /* IO devices */ 35 static const io_dev_connector_t *sh_dev_con; 36 static uintptr_t sh_dev_handle; 37 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 }, 55 [TB_FW_CONFIG_ID] = { 56 .path = TB_FW_CONFIG_NAME, 57 .mode = FOPEN_MODE_RB 58 }, 59 #if TRUSTED_BOARD_BOOT 60 [TRUSTED_BOOT_FW_CERT_ID] = { 61 .path = TRUSTED_BOOT_FW_CERT_NAME, 62 .mode = FOPEN_MODE_RB 63 }, 64 [TRUSTED_KEY_CERT_ID] = { 65 .path = TRUSTED_KEY_CERT_NAME, 66 .mode = FOPEN_MODE_RB 67 }, 68 [SOC_FW_KEY_CERT_ID] = { 69 .path = SOC_FW_KEY_CERT_NAME, 70 .mode = FOPEN_MODE_RB 71 }, 72 [TRUSTED_OS_FW_KEY_CERT_ID] = { 73 .path = TOS_FW_KEY_CERT_NAME, 74 .mode = FOPEN_MODE_RB 75 }, 76 [NON_TRUSTED_FW_KEY_CERT_ID] = { 77 .path = NT_FW_KEY_CERT_NAME, 78 .mode = FOPEN_MODE_RB 79 }, 80 [SOC_FW_CONTENT_CERT_ID] = { 81 .path = SOC_FW_CONTENT_CERT_NAME, 82 .mode = FOPEN_MODE_RB 83 }, 84 [TRUSTED_OS_FW_CONTENT_CERT_ID] = { 85 .path = TOS_FW_CONTENT_CERT_NAME, 86 .mode = FOPEN_MODE_RB 87 }, 88 [NON_TRUSTED_FW_CONTENT_CERT_ID] = { 89 .path = NT_FW_CONTENT_CERT_NAME, 90 .mode = FOPEN_MODE_RB 91 }, 92 #endif /* TRUSTED_BOARD_BOOT */ 93 }; 94 95 96 static int open_semihosting(const uintptr_t spec) 97 { 98 int result; 99 uintptr_t local_image_handle; 100 101 /* See if the file exists on semi-hosting.*/ 102 result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); 103 if (result == 0) { 104 result = io_open(sh_dev_handle, spec, &local_image_handle); 105 if (result == 0) { 106 VERBOSE("Using Semi-hosting IO\n"); 107 io_close(local_image_handle); 108 } 109 } 110 return result; 111 } 112 113 void plat_arm_io_setup(void) 114 { 115 int io_result; 116 117 arm_io_setup(); 118 119 /* Register the additional IO devices on this platform */ 120 io_result = register_io_dev_sh(&sh_dev_con); 121 assert(io_result == 0); 122 123 /* Open connections to devices and cache the handles */ 124 io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle); 125 assert(io_result == 0); 126 127 /* Ignore improbable errors in release builds */ 128 (void)io_result; 129 } 130 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) 136 { 137 int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]); 138 if (result == 0) { 139 *dev_handle = sh_dev_handle; 140 *image_spec = (uintptr_t)&sh_file_spec[image_id]; 141 } 142 143 return result; 144 } 145