From 5c38088881ffd10f9a2dc1cc2af7300295eb6f04 Mon Sep 17 00:00:00 2001 From: Scott Branden Date: Fri, 8 Jul 2016 12:09:23 -0700 Subject: drivers: Add support to retrieve plat_toc_flags Add support to retrieve plat_toc_flags value from FIP header flags. plat_toc_flags is for platform specific use. It is stored in FIP header by fiptool using --plat-toc-flags option. Change-Id: Ibadd91b4f28e6503f4426e4efd404bbe512ad124 Signed-off-by: Scott Branden Signed-off-by: Sheetal Tigadoli --- drivers/io/io_fip.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'drivers/io/io_fip.c') diff --git a/drivers/io/io_fip.c b/drivers/io/io_fip.c index 5d49fffaa..02f85d603 100644 --- a/drivers/io/io_fip.c +++ b/drivers/io/io_fip.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -46,6 +46,7 @@ typedef struct { */ typedef struct { uintptr_t dev_spec; + uint16_t plat_toc_flag; } fip_dev_state_t; static const uuid_t uuid_null; @@ -220,6 +221,11 @@ static int fip_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params) uintptr_t backend_handle; fip_toc_header_t header; size_t bytes_read; + fip_dev_state_t *state; + + assert(dev_info != NULL); + + state = (fip_dev_state_t *)dev_info->info; /* Obtain a reference to the image by querying the platform layer */ result = plat_get_image_source(image_id, &backend_dev_handle, @@ -248,6 +254,11 @@ static int fip_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params) result = -ENOENT; } else { VERBOSE("FIP header looks OK.\n"); + /* + * Store 16-bit Platform ToC flags field which occupies + * bits [32-47] in fip header. + */ + state->plat_toc_flag = (header.flags >> 32) & 0xffff; } } @@ -453,3 +464,17 @@ int register_io_dev_fip(const io_dev_connector_t **dev_con) return result; } + +/* Function to retrieve plat_toc_flags, previously saved in FIP dev */ +int fip_dev_get_plat_toc_flag(io_dev_info_t *dev_info, uint16_t *plat_toc_flag) +{ + fip_dev_state_t *state; + + assert(dev_info != NULL); + + state = (fip_dev_state_t *)dev_info->info; + + *plat_toc_flag = state->plat_toc_flag; + + return 0; +} -- cgit v1.2.3 From 6eb75a1a2febdf089c2a432dc46c94a0da16520d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 9 Jul 2020 23:05:45 +0900 Subject: io_fip: return -ENFILE when a file is already open The cause of failure is not memory shortage. The comment for ENFILE in include/lib/libc/errno.h /* Too many open files in system */ ... is a better match to the warning message here. Change-Id: I45a1740995d464edd8b3e32b93f1f92ba17e5874 Signed-off-by: Masahiro Yamada --- drivers/io/io_fip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/io/io_fip.c') diff --git a/drivers/io/io_fip.c b/drivers/io/io_fip.c index 02f85d603..7aa717da8 100644 --- a/drivers/io/io_fip.c +++ b/drivers/io/io_fip.c @@ -302,7 +302,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, */ if (current_file.entry.offset_address != 0) { WARN("fip_file_open : Only one open file at a time.\n"); - return -ENOMEM; + return -ENFILE; } /* Attempt to access the FIP image */ -- cgit v1.2.3 From d471bd9cfc58bce8efa8fa2d355a20950022f44d Mon Sep 17 00:00:00 2001 From: johpow01 Date: Wed, 1 Jul 2020 17:09:57 -0500 Subject: IO Driver Misra Cleanup This patch cleans up MISRA C violations in the IO driver files. Some things did not make sense to fix or would require sweeping changes but the simple issues have been resolved. Defects Fixed File Line Rule drivers/io/io_fip.c 39 MISRA C-2012 Rule 5.6 (required) drivers/io/io_fip.c 52 MISRA C-2012 Rule 8.9 (advisory) drivers/io/io_fip.c 60 MISRA C-2012 Rule 5.9 (advisory) drivers/io/io_fip.c 285 MISRA C-2012 Rule 8.9 (advisory) drivers/io/io_fip.c 336 MISRA C-2012 Rule 15.4 (advisory) drivers/io/io_fip.c 340 MISRA C-2012 Rule 15.4 (advisory) drivers/io/io_fip.c 342 MISRA C-2012 Rule 15.4 (advisory) drivers/io/io_memmap.c 30 MISRA C-2012 Rule 5.6 (required) drivers/io/io_memmap.c 32 MISRA C-2012 Rule 5.9 (advisory) drivers/io/io_memmap.c 85 MISRA C-2012 Rule 11.8 (required) drivers/io/io_semihosting.c 66 MISRA C-2012 Rule 11.8 (required) drivers/io/io_storage.c 73 MISRA C-2012 Rule 5.9 (advisory) drivers/io/io_storage.c 116 MISRA C-2012 Rule 13.4 (advisory) Signed-off-by: John Powell Change-Id: Id9b1b2b684588d4eaab674ed4ed04f3950dd21f4 --- drivers/io/io_fip.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'drivers/io/io_fip.c') diff --git a/drivers/io/io_fip.c b/drivers/io/io_fip.c index 02f85d603..c11ef115a 100644 --- a/drivers/io/io_fip.c +++ b/drivers/io/io_fip.c @@ -36,7 +36,7 @@ typedef struct { unsigned int file_pos; fip_toc_entry_t entry; -} file_state_t; +} fip_file_state_t; /* * Maintain dev_spec per FIP Device @@ -49,7 +49,6 @@ typedef struct { uint16_t plat_toc_flag; } fip_dev_state_t; -static const uuid_t uuid_null; /* * Only one file can be open across all FIP device * as backends like io_memmap don't support @@ -57,7 +56,7 @@ static const uuid_t uuid_null; * backend handle should be maintained per FIP device * if the same support is available in the backend */ -static file_state_t current_file = {0}; +static fip_file_state_t current_fip_file = {0}; static uintptr_t backend_dev_handle; static uintptr_t backend_image_spec; @@ -288,6 +287,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, int result; uintptr_t backend_handle; const io_uuid_spec_t *uuid_spec = (io_uuid_spec_t *)spec; + static const uuid_t uuid_null = { {0} }; /* Double braces for clang */ size_t bytes_read; int found_file = 0; @@ -300,7 +300,7 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, * When the system supports dynamic memory allocation we can allow more * than one open file at a time if needed. */ - if (current_file.entry.offset_address != 0) { + if (current_fip_file.entry.offset_address != 0U) { WARN("fip_file_open : Only one open file at a time.\n"); return -ENOMEM; } @@ -326,31 +326,32 @@ static int fip_file_open(io_dev_info_t *dev_info, const uintptr_t spec, found_file = 0; do { result = io_read(backend_handle, - (uintptr_t)¤t_file.entry, - sizeof(current_file.entry), + (uintptr_t)¤t_fip_file.entry, + sizeof(current_fip_file.entry), &bytes_read); if (result == 0) { - if (compare_uuids(¤t_file.entry.uuid, + if (compare_uuids(¤t_fip_file.entry.uuid, &uuid_spec->uuid) == 0) { found_file = 1; - break; } } else { WARN("Failed to read FIP (%i)\n", result); goto fip_file_open_close; } - } while (compare_uuids(¤t_file.entry.uuid, &uuid_null) != 0); + } while ((found_file == 0) && + (compare_uuids(¤t_fip_file.entry.uuid, + &uuid_null) != 0)); if (found_file == 1) { /* All fine. Update entity info with file state and return. Set - * the file position to 0. The 'current_file.entry' holds the - * base and size of the file. + * the file position to 0. The 'current_fip_file.entry' holds + * the base and size of the file. */ - current_file.file_pos = 0; - entity->info = (uintptr_t)¤t_file; + current_fip_file.file_pos = 0; + entity->info = (uintptr_t)¤t_fip_file; } else { /* Did not find the file in the FIP. */ - current_file.entry.offset_address = 0; + current_fip_file.entry.offset_address = 0; result = -ENOENT; } @@ -368,7 +369,7 @@ static int fip_file_len(io_entity_t *entity, size_t *length) assert(entity != NULL); assert(length != NULL); - *length = ((file_state_t *)entity->info)->entry.size; + *length = ((fip_file_state_t *)entity->info)->entry.size; return 0; } @@ -379,7 +380,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, size_t *length_read) { int result; - file_state_t *fp; + fip_file_state_t *fp; size_t file_offset; size_t bytes_read; uintptr_t backend_handle; @@ -397,7 +398,7 @@ static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length, goto fip_file_read_exit; } - fp = (file_state_t *)entity->info; + fp = (fip_file_state_t *)entity->info; /* Seek to the position in the FIP where the payload lives */ file_offset = fp->entry.offset_address + fp->file_pos; @@ -436,8 +437,8 @@ static int fip_file_close(io_entity_t *entity) /* Clear our current file pointer. * If we had malloc() we would free() here. */ - if (current_file.entry.offset_address != 0) { - zeromem(¤t_file, sizeof(current_file)); + if (current_fip_file.entry.offset_address != 0U) { + zeromem(¤t_fip_file, sizeof(current_fip_file)); } /* Clear the Entity info. */ -- cgit v1.2.3