From 314bed6c854e41b2edd5cefb7009e3b6040abd28 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 28 Oct 2020 18:45:47 +0100 Subject: efi_loader: fix DisconnectController() for sole child If ChildHandle indicates the sole child of the driver, disconnect the driver. This fixes the test results for UEFI SCT 2.6 A sub-tests 5.1.3.12.43, 5.1.3.12.44, 5.1.3.12.45. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/efi_loader') diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index b26ac9fbfc7..dfa71b17743 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3523,6 +3523,7 @@ static efi_status_t EFIAPI efi_disconnect_controller( size_t number_of_children = 0; efi_status_t r; struct efi_object *efiobj; + bool sole_child; EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, child_handle); @@ -3545,16 +3546,18 @@ static efi_status_t EFIAPI efi_disconnect_controller( } /* Create list of child handles */ + r = efi_get_child_controllers(efiobj, + driver_image_handle, + &number_of_children, + &child_handle_buffer); + if (r != EFI_SUCCESS) + return r; + sole_child = (number_of_children == 1); + if (child_handle) { number_of_children = 1; + free(child_handle_buffer); child_handle_buffer = &child_handle; - } else { - r = efi_get_child_controllers(efiobj, - driver_image_handle, - &number_of_children, - &child_handle_buffer); - if (r != EFI_SUCCESS) - return r; } /* Get the driver binding protocol */ @@ -3579,7 +3582,7 @@ static efi_status_t EFIAPI efi_disconnect_controller( } } /* Remove the driver */ - if (!child_handle) { + if (!child_handle || sole_child) { r = EFI_CALL(binding_protocol->stop(binding_protocol, controller_handle, 0, NULL)); -- cgit v1.2.3 From c57c9439548a58a0c1f0eb2ec7b5ab5d7b7fd801 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Thu, 29 Oct 2020 13:47:45 +0900 Subject: efi_loader: add option to initialise EFI subsystem early If this option, CONFIG_EFI_SETUP_EARLY, is enabled, the initialisation of UEFI subsystem will be done as part of U-Boot initialisation. Please note that this option won't be enabled explicitly by users, instead, should be enabled implicitly by other configuration options. Specifically, this feature will be utilised in implementing capsule-on-disk feature. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/efi_loader') diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index ab42f3ba75b..075481428cd 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -27,6 +27,10 @@ config EFI_LOADER if EFI_LOADER +config EFI_SETUP_EARLY + bool + default n + choice prompt "Store for non-volatile UEFI variables" default EFI_VARIABLE_FILE_STORE -- cgit v1.2.3 From 077153e085b48e7683552667ab2247c991c1e1ff Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Thu, 29 Oct 2020 13:47:46 +0900 Subject: efi_loader: add efi_create_indexed_name() This function will be used from several places in UEFI subsystem to generate some specific form of utf-16 variable name. For example, L"Capsule0001" Signed-off-by: AKASHI Takahiro Move function to separate module. Use char * as argument instead of u16 *. Reviewed-by: Heinrich Schuchardt Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_string.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/efi_loader/efi_string.c (limited to 'lib/efi_loader') diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 9bad1d159b0..8892fb01e12 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -34,6 +34,7 @@ obj-y += efi_memory.o obj-y += efi_root_node.o obj-y += efi_runtime.o obj-y += efi_setup.o +obj-y += efi_string.o obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o obj-y += efi_var_common.o obj-y += efi_var_mem.o diff --git a/lib/efi_loader/efi_string.c b/lib/efi_loader/efi_string.c new file mode 100644 index 00000000000..3de721f06c7 --- /dev/null +++ b/lib/efi_loader/efi_string.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * String functions + * + * Copyright (c) 2020 AKASHI Takahiro, Linaro Limited + */ + +#include +#include + +/** + * efi_create_indexed_name - create a string name with an index + * @buffer: Buffer + * @name: Name string + * @index: Index + * + * Create a utf-16 string with @name, appending @index. + * For example, L"Capsule0001" + * + * The caller must ensure that the buffer has enough space for the resulting + * string including the trailing L'\0'. + * + * Return: A pointer to the next position after the created string + * in @buffer, or NULL otherwise + */ +u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int index) +{ + u16 *p = buffer; + char index_buf[5]; + + utf8_utf16_strcpy(&p, name); + sprintf(index_buf, "%04X", index); + utf8_utf16_strcpy(&p, index_buf); + + return p; +} -- cgit v1.2.3