laurenw-arm | 7c7b198 | 2020-10-21 13:34:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <drivers/io/io_driver.h> |
| 11 | #include <drivers/io/io_semihosting.h> |
| 12 | #include <drivers/io/io_storage.h> |
| 13 | #include <lib/semihosting.h> |
| 14 | #include <plat/arm/common/plat_arm.h> |
| 15 | #include <plat/common/common_def.h> |
| 16 | |
| 17 | /* Semihosting filenames */ |
| 18 | #define TB_FW_CONFIG_NAME "fvp_tb_fw_config.dtb" |
| 19 | #define HW_CONFIG_NAME "hw_config.dtb" |
| 20 | |
| 21 | #if TRUSTED_BOARD_BOOT |
| 22 | #define TRUSTED_BOOT_FW_CERT_NAME "tb_fw.crt" |
| 23 | #define TRUSTED_KEY_CERT_NAME "trusted_key.crt" |
| 24 | #define SOC_FW_KEY_CERT_NAME "soc_fw_key.crt" |
| 25 | #define TOS_FW_KEY_CERT_NAME "tos_fw_key.crt" |
| 26 | #define NT_FW_KEY_CERT_NAME "nt_fw_key.crt" |
| 27 | #define SOC_FW_CONTENT_CERT_NAME "soc_fw_content.crt" |
| 28 | #define TOS_FW_CONTENT_CERT_NAME "tos_fw_content.crt" |
| 29 | #define NT_FW_CONTENT_CERT_NAME "nt_fw_content.crt" |
| 30 | #endif /* TRUSTED_BOARD_BOOT */ |
| 31 | |
| 32 | /* IO devices */ |
| 33 | static const io_dev_connector_t *sh_dev_con; |
| 34 | static uintptr_t sh_dev_handle; |
| 35 | |
| 36 | static const io_file_spec_t sh_file_spec[] = { |
| 37 | [TB_FW_CONFIG_ID] = { |
| 38 | .path = TB_FW_CONFIG_NAME, |
| 39 | .mode = FOPEN_MODE_RB |
| 40 | }, |
| 41 | [HW_CONFIG_ID] = { |
| 42 | .path = HW_CONFIG_NAME, |
| 43 | .mode = FOPEN_MODE_RB |
| 44 | }, |
| 45 | #if TRUSTED_BOARD_BOOT |
| 46 | [TRUSTED_KEY_CERT_ID] = { |
| 47 | .path = TRUSTED_KEY_CERT_NAME, |
| 48 | .mode = FOPEN_MODE_RB |
| 49 | }, |
| 50 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
| 51 | .path = NT_FW_KEY_CERT_NAME, |
| 52 | .mode = FOPEN_MODE_RB |
| 53 | }, |
| 54 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
| 55 | .path = NT_FW_CONTENT_CERT_NAME, |
| 56 | .mode = FOPEN_MODE_RB |
| 57 | }, |
| 58 | #endif /* TRUSTED_BOARD_BOOT */ |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | static int open_semihosting(const uintptr_t spec) |
| 63 | { |
| 64 | int result; |
| 65 | uintptr_t local_image_handle; |
| 66 | |
| 67 | /* See if the file exists on semi-hosting.*/ |
| 68 | result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); |
| 69 | if (result == 0) { |
| 70 | result = io_open(sh_dev_handle, spec, &local_image_handle); |
| 71 | if (result == 0) { |
| 72 | VERBOSE("Using Semi-hosting IO\n"); |
| 73 | io_close(local_image_handle); |
| 74 | } |
| 75 | } |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | void plat_arm_io_setup(void) |
| 80 | { |
| 81 | int io_result; |
| 82 | |
| 83 | io_result = arm_io_setup(); |
| 84 | if (io_result < 0) { |
| 85 | panic(); |
| 86 | } |
| 87 | |
| 88 | /* Register the additional IO devices on this platform */ |
| 89 | io_result = register_io_dev_sh(&sh_dev_con); |
| 90 | if (io_result < 0) { |
| 91 | panic(); |
| 92 | } |
| 93 | |
| 94 | /* Open connections to devices and cache the handles */ |
| 95 | io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle); |
| 96 | if (io_result < 0) { |
| 97 | panic(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * FVP_R provides semihosting as an alternative to load images |
| 103 | */ |
| 104 | int plat_arm_get_alt_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 105 | uintptr_t *image_spec) |
| 106 | { |
| 107 | int result = open_semihosting((const uintptr_t)&sh_file_spec[image_id]); |
| 108 | |
| 109 | if (result == 0) { |
| 110 | *dev_handle = sh_dev_handle; |
| 111 | *image_spec = (uintptr_t)&sh_file_spec[image_id]; |
| 112 | } |
| 113 | |
| 114 | return result; |
| 115 | } |