James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <assert.h> |
| 32 | #include <string.h> |
| 33 | #include "platform.h" |
| 34 | #include "io_storage.h" |
| 35 | #include "io_driver.h" |
| 36 | #include "io_semihosting.h" |
| 37 | #include "semihosting.h" /* For FOPEN_MODE_... */ |
| 38 | #include "debug.h" |
| 39 | |
| 40 | |
| 41 | /* IO devices */ |
| 42 | static struct io_plat_data io_data; |
| 43 | static struct io_dev_connector *sh_dev_con; |
| 44 | static void *const sh_dev_spec; |
| 45 | static void *const sh_init_params; |
| 46 | static io_dev_handle sh_dev_handle; |
| 47 | |
| 48 | static io_file_spec bl2_image_spec = { |
| 49 | .path = BL2_IMAGE_NAME, |
| 50 | .mode = FOPEN_MODE_R |
| 51 | }; |
| 52 | |
| 53 | static io_file_spec bl31_image_spec = { |
| 54 | .path = BL31_IMAGE_NAME, |
| 55 | .mode = FOPEN_MODE_R |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | /* Set up the IO devices present on this platform, ready for use */ |
| 60 | void io_setup(void) |
| 61 | { |
| 62 | /* Initialise the IO layer */ |
| 63 | io_init(&io_data); |
| 64 | |
| 65 | /* Register a semi-hosting device */ |
| 66 | int io_result = register_io_dev_sh(&sh_dev_con); |
| 67 | assert(io_result == IO_SUCCESS); |
| 68 | |
| 69 | /* Open a connection to the semi-hosting device and cache the handle */ |
| 70 | io_result = io_dev_open(sh_dev_con, sh_dev_spec, &sh_dev_handle); |
| 71 | assert(io_result == IO_SUCCESS); |
| 72 | |
| 73 | /* Ignore improbable errors in release builds */ |
| 74 | (void)io_result; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* Return an IO device handle and specification which can be used to access |
| 79 | * an image */ |
| 80 | int plat_get_image_source(const char *image_name, io_dev_handle *dev_handle, |
| 81 | void **image_spec) |
| 82 | { |
| 83 | int result = IO_FAIL; |
| 84 | assert((image_name != NULL) && (dev_handle != NULL) && |
| 85 | (image_spec != NULL)); |
| 86 | |
| 87 | if (strcmp(BL2_IMAGE_NAME, image_name) == 0) { |
| 88 | result = io_dev_init(sh_dev_handle, sh_init_params); |
| 89 | if (result == IO_SUCCESS) { |
| 90 | *dev_handle = sh_dev_handle; |
| 91 | *(io_file_spec **)image_spec = &bl2_image_spec; |
| 92 | } |
| 93 | } else if (strcmp(BL31_IMAGE_NAME, image_name) == 0) { |
| 94 | result = io_dev_init(sh_dev_handle, sh_init_params); |
| 95 | if (result == IO_SUCCESS) { |
| 96 | *dev_handle = sh_dev_handle; |
| 97 | *(io_file_spec **)image_spec = &bl31_image_spec; |
| 98 | } |
| 99 | } else |
| 100 | assert(0); |
| 101 | |
| 102 | return result; |
| 103 | } |