From e616100eab84464f09baa93b3fe5c15087a385c1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 11 Mar 2019 22:04:51 +0100 Subject: efi_loader: fix build error for freestanding.o Since commit f51a226436a87 ("efi_loader: provide freestanding library") in parallel builds errors lib/efi_selftest/../efi_loader/efi_freestanding.o: file not recognized: File truncated occur. Obviously make cannot correctly sequence parallel builds with a dependency like ../efi_loader/efi_freestanding.o. Fixes: f51a226436a87 ("efi_loader: provide freestanding library") Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_freestanding.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/efi_selftest/efi_freestanding.c (limited to 'lib') diff --git a/lib/efi_selftest/efi_freestanding.c b/lib/efi_selftest/efi_freestanding.c new file mode 100644 index 00000000000..4b6c27e99fb --- /dev/null +++ b/lib/efi_selftest/efi_freestanding.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Library for freestanding binary + * + * Copyright 2019, Heinrich Schuchardt + * + * GCC requires that freestanding programs provide memcpy(), memmove(), + * memset(), and memcmp(). + */ + +#include "../efi_loader/efi_freestanding.c" -- cgit v1.2.3 From 306b16718edddd660b84bf3c6627ce5d41b53ce7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 18 Mar 2019 20:01:59 +0100 Subject: efi_loader: correct parameter size in efi_allocate_pool efi_allocate_pages() expects a (uint64_t *) pointer to pass the address of the assigned memory. If we pass the address of a pointer here, an illegal memory access occurs on 32bit systems. Fixes: 282a06cbcae8 ("efi_loader: Expose U-Boot addresses in memory map for sandbox") Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index ebd2b36c03d..55622d2fb40 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -440,6 +440,7 @@ efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages) efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size, void **buffer) { efi_status_t r; + u64 addr; struct efi_pool_allocation *alloc; u64 num_pages = efi_size_in_pages(size + sizeof(struct efi_pool_allocation)); @@ -453,9 +454,9 @@ efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size, void **buffer) } r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, pool_type, num_pages, - (uint64_t *)&alloc); - + &addr); if (r == EFI_SUCCESS) { + alloc = (struct efi_pool_allocation *)(uintptr_t)addr; alloc->num_pages = num_pages; *buffer = alloc->data; } -- cgit v1.2.3 From bd3b7478d1e17b4d487d276f5cc0e4f4ef9fc4b7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Mar 2019 12:30:27 +0100 Subject: efi_loader: endless loop in add_strings_package() Avoid an endless loop in add_strings_package(). Suggested-by: Takahiro Akashi Reported-by: Coverity (CID 185833) Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_hii.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 3a966fa4dff..61b71dec621 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -227,9 +227,8 @@ out: error: if (stbl) { free(stbl->language); - if (idx > 0) - while (--idx >= 0) - free(stbl->strings[idx].string); + while (idx > 0) + free(stbl->strings[--idx].string); free(stbl->strings); } free(stbl); -- cgit v1.2.3 From e7dae584b05feaf507c5b85a704a2c1d25abffc9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Mar 2019 18:36:21 +0100 Subject: efi_loader: missing return in efi_get_next_variable_name() Add a missing return statement in efi_get_next_variable_name(). Reported-by: Coverity (CID 185834) Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index e0d7f5736db..699f4184d93 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -335,7 +335,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor); if (!variable_name_size || !variable_name || !vendor) - EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_EXIT(EFI_INVALID_PARAMETER); if (variable_name[0]) { /* check null-terminated string */ -- cgit v1.2.3 From d5974af7f7626777b5c41894f75c813ff35c1793 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Mar 2019 18:58:58 +0100 Subject: efi_loader: remove superfluous check in efi_setup_loaded_image() It does not make any sense to check if a pointer is NULL if we have dereferenced it before. Reported-by: Coverity (CID 185827) Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index bd8b8a17ae7..4fc550d9f37 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1581,10 +1581,8 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, goto failure; #endif - if (info_ptr) - *info_ptr = info; - if (handle_ptr) - *handle_ptr = obj; + *info_ptr = info; + *handle_ptr = obj; return ret; failure: -- cgit v1.2.3 From 1646e0928c8eb052bfa2283a6ab8d9f2a92a10e9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Mar 2019 19:16:23 +0100 Subject: efi_loader: superfluous conversion in efi_file_open() printf("%ls", ..) expects u16 * as argument to print. There is not need for a conversion to wchar_t *. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 3a7323765bd..bc715218a1b 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -226,7 +226,7 @@ static efi_status_t EFIAPI efi_file_open(struct efi_file_handle *file, efi_status_t ret; EFI_ENTRY("%p, %p, \"%ls\", %llx, %llu", file, new_handle, - (wchar_t *)file_name, open_mode, attributes); + file_name, open_mode, attributes); /* Check parameters */ if (!file || !new_handle || !file_name) { -- cgit v1.2.3 From d0bd87612f410a723d5ddb3001e805485e3efb4f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 19 Mar 2019 20:08:46 +0100 Subject: efi_selftest: fix test_hii_string_get_string() The check testing the string result of get_string() returned the wrong result. The result was ignored. Use efi_st_strcmp_16_8() for the string comparison. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_hii.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/efi_selftest/efi_selftest_hii.c b/lib/efi_selftest/efi_selftest_hii.c index 8a0b3bc3536..f4b70f79508 100644 --- a/lib/efi_selftest/efi_selftest_hii.c +++ b/lib/efi_selftest/efi_selftest_hii.c @@ -783,19 +783,10 @@ static int test_hii_string_get_string(void) goto out; } -#if 1 - u16 *c1, *c2; - - for (c1 = string, c2 = L"Japanese"; *c1 == *c2; c1++, c2++) - ; - if (!*c1 && !*c2) - result = EFI_ST_SUCCESS; - else - result = EFI_ST_FAILURE; -#else - /* TODO: %ls */ - efi_st_printf("got string is %s (can be wrong)\n", string); -#endif + if (efi_st_strcmp_16_8(string, "Japanese")) { + efi_st_error("get_string returned incorrect string\n"); + goto out; + } result = EFI_ST_SUCCESS; -- cgit v1.2.3 From b02f2e79c6272d97bf0bd191e6ec8e748a39ad58 Mon Sep 17 00:00:00 2001 From: Philippe Reynes Date: Tue, 19 Mar 2019 10:55:40 +0100 Subject: rsa: check that pointer checksum isn't NULL before using it The pointer checksum were used before checking that it isn't NULL. We move the code that use it after the check. Reported-by: Coverity (CID: 185835) Signed-off-by: Philippe Reynes Reviewed-by: Simon Glass --- lib/rsa/rsa-verify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c index 9734f6d3bd6..287fcc4d234 100644 --- a/lib/rsa/rsa-verify.c +++ b/lib/rsa/rsa-verify.c @@ -295,7 +295,7 @@ static int rsa_verify_key(struct image_sign_info *info, #endif struct checksum_algo *checksum = info->checksum; struct padding_algo *padding = info->padding; - int hash_len = checksum->checksum_len; + int hash_len; if (!prop || !sig || !hash || !checksum) return -EIO; @@ -315,6 +315,7 @@ static int rsa_verify_key(struct image_sign_info *info, } uint8_t buf[sig_len]; + hash_len = checksum->checksum_len; #if !defined(USE_HOSTCC) ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev); -- cgit v1.2.3 From d0826507e2d24974cb99bfa8cac39d7684107994 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 26 Mar 2019 05:56:31 +0100 Subject: efi_selftest: avoid double free in dp utilities test Avoid duplicate FreePool() in unit test for the device patch utilities protocol. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_devicepath_util.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib') diff --git a/lib/efi_selftest/efi_selftest_devicepath_util.c b/lib/efi_selftest/efi_selftest_devicepath_util.c index 5fef5cfccd7..c846e057d35 100644 --- a/lib/efi_selftest/efi_selftest_devicepath_util.c +++ b/lib/efi_selftest/efi_selftest_devicepath_util.c @@ -256,11 +256,6 @@ static int execute(void) efi_st_error("GetNextDevicePathInstance did not signal end\n"); return EFI_ST_FAILURE; } - ret = boottime->free_pool(dp2); - if (ret != EFI_ST_SUCCESS) { - efi_st_error("FreePool failed\n"); - return EFI_ST_FAILURE; - } /* Clean up */ ret = boottime->free_pool(dp2); -- cgit v1.2.3 From 17394f9a66e1b8caf2bb43419668dcd26e722ffe Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 27 Mar 2019 21:41:04 +0100 Subject: efi_loader: TODO for the EFI file protocol We currently only support EFI_FILE_PROTOCOL_REVISION while UEFI specs 2.4 - 2.7 prescribe EFI_FILE_PROTOCOL_REVISION2. Add a todo. Add missing constants for the EFI file protocol revision. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index bc715218a1b..0483403be0d 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -628,6 +628,10 @@ static efi_status_t EFIAPI efi_file_flush(struct efi_file_handle *file) } static const struct efi_file_handle efi_file_handle_protocol = { + /* + * TODO: We currently only support EFI file protocol revision 0x00010000 + * while UEFI specs 2.4 - 2.7 prescribe revision 0x00020000. + */ .rev = EFI_FILE_PROTOCOL_REVISION, .open = efi_file_open, .close = efi_file_close, -- cgit v1.2.3 From f00c26284ec0aa3e9b01ebe4996aa8fc01526d03 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Fri, 29 Mar 2019 22:17:33 +0800 Subject: lib: time: update module enable MACRO We'd better use correct way to check if module has enabled. for we have 3 timer MACRO: - CONFIG_TIMER - CONFIG_SPL_TIMER - CONFIG_TPL_TIMER Signed-off-by: Kever Yang Reviewed-by: Philipp Tomsich --- lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/time.c b/lib/time.c index 3bf678a2327..9c55da6f1b3 100644 --- a/lib/time.c +++ b/lib/time.c @@ -56,7 +56,7 @@ ulong timer_get_boot_us(void) extern unsigned long __weak timer_read_counter(void); #endif -#ifdef CONFIG_TIMER +#if CONFIG_IS_ENABLED(TIMER) ulong notrace get_tbclk(void) { if (!gd->timer) { -- cgit v1.2.3