From cae734cd7479be6f63e3914cd837521cfabb9c4d Mon Sep 17 00:00:00 2001 From: Antonio Nino Diaz Date: Wed, 9 Nov 2016 15:20:38 +0000 Subject: Isolate fwu-specific IO code Added `plat_fwu_io_setup`, which is defined for arm platforms. Added it to the documentation. Renamed `arm_io_setup()` to `arm_fwu_io_setup()` and made it a weak function. Removed the `plat_arm_io_setup()` associated to it because this is not platform code and it's problematic for the actual `plat_arm_io_setup()` that will be implemented in a following patch. `plat_fwu_io_setup` calls `arm_fwu_io_storage` in ARM platforms. Change-Id: Ibfb63139a6c0b0991ab70e935a3723d454d8d70c --- plat/arm/common/arm_fwu_io_storage.c | 195 +++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 plat/arm/common/arm_fwu_io_storage.c (limited to 'plat/arm') diff --git a/plat/arm/common/arm_fwu_io_storage.c b/plat/arm/common/arm_fwu_io_storage.c new file mode 100644 index 0000000..706fa27 --- /dev/null +++ b/plat/arm/common/arm_fwu_io_storage.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2014-2015, ARM Limited and Contributors. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* May be overridden in specific ARM standard platform */ +#pragma weak plat_arm_fwu_io_setup + +/* IO devices */ +static const io_dev_connector_t *fwu_fip_dev_con; +static uintptr_t fwu_fip_dev_handle; +static const io_dev_connector_t *memmap_dev_con; +static uintptr_t memmap_dev_handle; + +static const io_block_spec_t fwu_fip_block_spec = { + .offset = PLAT_ARM_FWU_FIP_BASE, + .length = PLAT_ARM_FWU_FIP_SIZE +}; +static const io_uuid_spec_t fwu_cert_uuid_spec = { + .uuid = UUID_FIRMWARE_UPDATE_FWU_CERT, +}; +static const io_uuid_spec_t scp_bl2u_uuid_spec = { + .uuid = UUID_FIRMWARE_UPDATE_SCP_BL2U, +}; +static const io_uuid_spec_t bl2u_uuid_spec = { + .uuid = UUID_FIRMWARE_UPDATE_BL2U, +}; +static const io_uuid_spec_t ns_bl2u_uuid_spec = { + .uuid = UUID_FIRMWARE_UPDATE_NS_BL2U, +}; + +static int open_fwu_fip(const uintptr_t spec); +static int open_memmap(const uintptr_t spec); + +struct plat_io_policy { + uintptr_t *dev_handle; + uintptr_t image_spec; + int (*check)(const uintptr_t spec); +}; + +static const struct plat_io_policy policies[] = { + [FWU_FIP_IMAGE_ID] = { + &memmap_dev_handle, + (uintptr_t)&fwu_fip_block_spec, + open_memmap + }, + [FWU_CERT_ID] = { + &fwu_fip_dev_handle, + (uintptr_t)&fwu_cert_uuid_spec, + open_fwu_fip + }, + [SCP_BL2U_IMAGE_ID] = { + &fwu_fip_dev_handle, + (uintptr_t)&scp_bl2u_uuid_spec, + open_fwu_fip + }, + [BL2U_IMAGE_ID] = { + &fwu_fip_dev_handle, + (uintptr_t)&bl2u_uuid_spec, + open_fwu_fip + }, + [NS_BL2U_IMAGE_ID] = { + &fwu_fip_dev_handle, + (uintptr_t)&ns_bl2u_uuid_spec, + open_fwu_fip + }, +}; + + +/* Weak definitions may be overridden in each specific platform */ +#pragma weak plat_get_image_source + +static int open_fwu_fip(const uintptr_t spec) +{ + int result; + uintptr_t local_image_handle; + + /* See if a Firmware Image Package is available */ + result = io_dev_init(fwu_fip_dev_handle, + (uintptr_t)FWU_FIP_IMAGE_ID); + if (result == IO_SUCCESS) { + result = io_open(fwu_fip_dev_handle, spec, + &local_image_handle); + if (result == IO_SUCCESS) { + VERBOSE("Using FIP\n"); + io_close(local_image_handle); + } + } + return result; +} + + +static int open_memmap(const uintptr_t spec) +{ + int result; + uintptr_t local_image_handle; + + result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); + if (result == IO_SUCCESS) { + result = io_open(memmap_dev_handle, spec, &local_image_handle); + if (result == IO_SUCCESS) { + VERBOSE("Using Memmap\n"); + io_close(local_image_handle); + } + } + return result; +} + + +void plat_arm_fwu_io_setup(void) +{ + int io_result; + + io_result = register_io_dev_fip(&fwu_fip_dev_con); + assert(io_result == IO_SUCCESS); + + io_result = register_io_dev_memmap(&memmap_dev_con); + assert(io_result == IO_SUCCESS); + + /* Open connections to devices and cache the handles */ + io_result = io_dev_open(fwu_fip_dev_con, (uintptr_t)NULL, + &fwu_fip_dev_handle); + assert(io_result == IO_SUCCESS); + + io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, + &memmap_dev_handle); + assert(io_result == IO_SUCCESS); + + /* Ignore improbable errors in release builds */ + (void)io_result; +} + + +/* Return an IO device handle and specification which can be used to access + * an image. Use this to enforce platform load policy */ +int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, + uintptr_t *image_spec) +{ + int result = IO_FAIL; + const struct plat_io_policy *policy; + + assert(image_id < ARRAY_SIZE(policies)); + + policy = &policies[image_id]; + result = policy->check(policy->image_spec); + if (result == IO_SUCCESS) { + *image_spec = policy->image_spec; + *dev_handle = *(policy->dev_handle); + } + + return result; +} + +void plat_fwu_io_setup(void) +{ + plat_arm_fwu_io_setup(); +} -- cgit v1.2.3