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 | * |
| 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> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 32 | #include <debug.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 33 | #include <io_driver.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 34 | #include <io_storage.h> |
| 35 | #include <io_semihosting.h> |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 36 | #include <plat_arm.h> |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 37 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 38 | /* IO devices */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 39 | static const io_dev_connector_t *sh_dev_con; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 40 | static uintptr_t sh_dev_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 41 | |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 42 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 43 | static int open_semihosting(const uintptr_t spec) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 44 | { |
| 45 | int result = IO_FAIL; |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 46 | uintptr_t local_image_handle; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 47 | |
| 48 | /* See if the file exists on semi-hosting.*/ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 49 | result = io_dev_init(sh_dev_handle, (uintptr_t)NULL); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 50 | if (result == IO_SUCCESS) { |
| 51 | result = io_open(sh_dev_handle, spec, &local_image_handle); |
| 52 | if (result == IO_SUCCESS) { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 53 | VERBOSE("Using Semi-hosting IO\n"); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 54 | io_close(local_image_handle); |
| 55 | } |
| 56 | } |
| 57 | return result; |
| 58 | } |
| 59 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 60 | void plat_arm_io_setup(void) |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 61 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 62 | int io_result; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 63 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 64 | arm_io_setup(); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 65 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 66 | /* Register the additional IO devices on this platform */ |
| 67 | io_result = register_io_dev_sh(&sh_dev_con); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 68 | assert(io_result == IO_SUCCESS); |
| 69 | |
| 70 | /* Open connections to devices and cache the handles */ |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 71 | io_result = io_dev_open(sh_dev_con, (uintptr_t)NULL, &sh_dev_handle); |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 72 | assert(io_result == IO_SUCCESS); |
| 73 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 74 | /* Ignore improbable errors in release builds */ |
| 75 | (void)io_result; |
| 76 | } |
| 77 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 78 | int plat_arm_get_alt_image_source( |
| 79 | const uintptr_t image_spec, |
| 80 | uintptr_t *dev_handle) |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 81 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 82 | int result = open_semihosting(image_spec); |
| 83 | if (result == IO_SUCCESS) |
| 84 | *dev_handle = sh_dev_handle; |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 85 | |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 86 | return result; |
| 87 | } |