From 64b4452bca04af433f1c98ab782c0e93cd5c88c0 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 19 Feb 2019 18:47:12 +0000 Subject: [efi] Blacklist the Dell Ip4ConfigDxe driver On a Dell OptiPlex 7010, calling DisconnectController() on the LOM device handle will lock up the system. Debugging shows that execution is trapped in an infinite loop that is somehow trying to reconnect drivers (without going via ConnectController()). The problem can be reproduced in the UEFI shell with no iPXE code present, by using the "disconnect" command. Experimentation shows that the only fix is to unload (rather than just disconnect) the "Ip4ConfigDxe" driver. Add the concept of a blacklist of UEFI drivers that will be automatically unloaded when iPXE runs as an application, and add the Dell Ip4ConfigDxe driver to this blacklist. Signed-off-by: Michael Brown --- src/interface/efi/efi_blacklist.c | 237 ++++++++++++++++++++++++++++++++++++++ src/interface/efi/efiprefix.c | 6 + 2 files changed, 243 insertions(+) create mode 100644 src/interface/efi/efi_blacklist.c (limited to 'src/interface/efi') diff --git a/src/interface/efi/efi_blacklist.c b/src/interface/efi/efi_blacklist.c new file mode 100644 index 000000000..292b28e8c --- /dev/null +++ b/src/interface/efi/efi_blacklist.c @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2019 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** @file + * + * EFI driver blacklist + * + */ + +/** A blacklisted driver */ +struct efi_blacklist { + /** Name */ + const char *name; + /** + * Check if driver is blacklisted + * + * @v binding Driver binding protocol + * @v loaded Loaded image protocol + * @v wtf Component name protocol, if present + * @ret blacklisted Driver is the blacklisted driver + */ + int ( * blacklist ) ( EFI_DRIVER_BINDING_PROTOCOL *binding, + EFI_LOADED_IMAGE_PROTOCOL *loaded, + EFI_COMPONENT_NAME_PROTOCOL *wtf ); +}; + +/** + * Blacklist Dell Ip4ConfigDxe driver + * + * @v binding Driver binding protocol + * @v loaded Loaded image protocol + * @v wtf Component name protocol, if present + * @ret blacklisted Driver is the blacklisted driver + */ +static int +efi_blacklist_dell_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding __unused, + EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, + EFI_COMPONENT_NAME_PROTOCOL *wtf ) { + static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver"; + static const char dell[] = "Dell Inc."; + char manufacturer[ sizeof ( dell ) ]; + CHAR16 *name; + + /* Check driver name */ + if ( ! wtf ) + return 0; + if ( wtf->GetDriverName ( wtf, "eng", &name ) != 0 ) + return 0; + if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 ) + return 0; + + /* Check manufacturer */ + fetch_string_setting ( NULL, &manufacturer_setting, manufacturer, + sizeof ( manufacturer ) ); + if ( strcmp ( manufacturer, dell ) != 0 ) + return 0; + + return 1; +} + +/** Blacklisted drivers */ +static struct efi_blacklist efi_blacklists[] = { + { + .name = "Dell Ip4Config", + .blacklist = efi_blacklist_dell_ip4config, + }, +}; + +/** + * Find driver blacklisting, if any + * + * @v driver Driver binding handle + * @ret blacklist Driver blacklisting, or NULL + * @ret rc Return status code + */ +static int efi_blacklist ( EFI_HANDLE driver, + struct efi_blacklist **blacklist ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + union { + EFI_DRIVER_BINDING_PROTOCOL *binding; + void *interface; + } binding; + union { + EFI_LOADED_IMAGE_PROTOCOL *loaded; + void *interface; + } loaded; + union { + EFI_COMPONENT_NAME_PROTOCOL *wtf; + void *interface; + } wtf; + unsigned int i; + EFI_HANDLE image; + EFI_STATUS efirc; + int rc; + + DBGC2 ( &efi_blacklists, "EFIBL checking %s\n", + efi_handle_name ( driver ) ); + + /* Mark as not blacklisted */ + *blacklist = NULL; + + /* Open driver binding protocol */ + if ( ( efirc = bs->OpenProtocol ( + driver, &efi_driver_binding_protocol_guid, + &binding.interface, efi_image_handle, driver, + EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { + rc = -EEFI ( efirc ); + DBGC ( driver, "EFIBL %s could not open driver binding " + "protocol: %s\n", efi_handle_name ( driver ), + strerror ( rc ) ); + goto err_binding; + } + image = binding.binding->ImageHandle; + + /* Open loaded image protocol */ + if ( ( efirc = bs->OpenProtocol ( + image, &efi_loaded_image_protocol_guid, + &loaded.interface, efi_image_handle, image, + EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { + rc = -EEFI ( efirc ); + DBGC ( driver, "EFIBL %s could not open", + efi_handle_name ( driver ) ); + DBGC ( driver, " %s loaded image protocol: %s\n", + efi_handle_name ( image ), strerror ( rc ) ); + goto err_loaded; + } + + /* Open component name protocol, if present*/ + if ( ( efirc = bs->OpenProtocol ( + driver, &efi_component_name_protocol_guid, + &wtf.interface, efi_image_handle, driver, + EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { + /* Ignore failure; is not required to be present */ + wtf.interface = NULL; + } + + /* Check blacklistings */ + for ( i = 0 ; i < ( sizeof ( efi_blacklists ) / + sizeof ( efi_blacklists[0] ) ) ; i++ ) { + if ( efi_blacklists[i].blacklist ( binding.binding, + loaded.loaded, wtf.wtf ) ) { + *blacklist = &efi_blacklists[i]; + break; + } + } + + /* Success */ + rc = 0; + + /* Close protocols */ + if ( wtf.wtf ) { + bs->CloseProtocol ( driver, &efi_component_name_protocol_guid, + efi_image_handle, driver ); + } + bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid, + efi_image_handle, image ); + err_loaded: + bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid, + efi_image_handle, driver ); + err_binding: + return rc; +} + +/** + * Unload any blacklisted drivers + * + */ +void efi_unload_blacklist ( void ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + struct efi_blacklist *blacklist; + EFI_HANDLE *drivers; + EFI_HANDLE driver; + UINTN num_drivers; + unsigned int i; + EFI_STATUS efirc; + int rc; + + /* Locate all driver binding protocol handles */ + if ( ( efirc = bs->LocateHandleBuffer ( + ByProtocol, &efi_driver_binding_protocol_guid, + NULL, &num_drivers, &drivers ) ) != 0 ) { + rc = -EEFI ( efirc ); + DBGC ( &efi_blacklists, "EFIBL could not list all drivers: " + "%s\n", strerror ( rc ) ); + return; + } + + /* Unload any blacklisted drivers */ + for ( i = 0 ; i < num_drivers ; i++ ) { + driver = drivers[i]; + if ( ( rc = efi_blacklist ( driver, &blacklist ) ) != 0 ) { + DBGC ( driver, "EFIBL could not determine " + "blacklisting for %s: %s\n", + efi_handle_name ( driver ), strerror ( rc ) ); + continue; + } + if ( ! blacklist ) + continue; + DBGC ( driver, "EFIBL unloading %s (%s)\n", + efi_handle_name ( driver ), blacklist->name ); + if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) { + DBGC ( driver, "EFIBL could not unload %s: %s\n", + efi_handle_name ( driver ), strerror ( rc ) ); + } + } + + /* Free handle list */ + bs->FreePool ( drivers ); +} diff --git a/src/interface/efi/efiprefix.c b/src/interface/efi/efiprefix.c index 18b931e68..de3572c75 100644 --- a/src/interface/efi/efiprefix.c +++ b/src/interface/efi/efiprefix.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include /** * EFI entry point @@ -75,6 +76,10 @@ EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle, */ static int efi_probe ( struct root_device *rootdev __unused ) { + /* Unloaded any blacklisted drivers */ + efi_unload_blacklist(); + + /* Connect our drivers */ return efi_driver_connect_all(); } @@ -85,6 +90,7 @@ static int efi_probe ( struct root_device *rootdev __unused ) { */ static void efi_remove ( struct root_device *rootdev __unused ) { + /* Disconnect our drivers */ efi_driver_disconnect_all(); } -- cgit v1.2.3-55-g7522 From a385e2376859dc0195ec77aeab220876b201c16b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 15 Jul 2019 12:49:47 +0100 Subject: [efi] Return only registered EFI devices from efidev_parent() efidev_parent() currently assumes that any device with BUS_TYPE_EFI is part of a struct efi_device. This assumption is not valid, since the code in efi_device_info() may also create a device with BUS_TYPE_EFI. Fix by searching through the list of registered EFI devices when looking for a match, instead of relying on the bus type value. Signed-off-by: Michael Brown --- src/interface/efi/efi_driver.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/interface/efi') diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index 04796414a..7be2e585d 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -73,11 +73,14 @@ static struct efi_device * efidev_find ( EFI_HANDLE device ) { */ struct efi_device * efidev_parent ( struct device *dev ) { struct device *parent; + struct efi_device *efidev; - /* Walk upwards until we find an EFI device */ + /* Walk upwards until we find a registered EFI device */ while ( ( parent = dev->parent ) ) { - if ( parent->desc.bus_type == BUS_TYPE_EFI ) - return container_of ( parent, struct efi_device, dev ); + list_for_each_entry ( efidev, &efi_devices, dev.siblings ) { + if ( parent == &efidev->dev ) + return efidev; + } dev = parent; } -- cgit v1.2.3-55-g7522 From 6dde0f60bfab458208a763532c9e776b32deebb3 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 19 Jul 2019 17:42:12 +0100 Subject: [efi] Register a device tree if provided by the platform firmware Signed-off-by: Michael Brown --- src/config/config_fdt.c | 3 ++ src/config/defaults/efi.h | 1 + src/interface/efi/efi_fdt.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/interface/efi/efi_fdt.c (limited to 'src/interface/efi') diff --git a/src/config/config_fdt.c b/src/config/config_fdt.c index 85d62ace1..e8d425933 100644 --- a/src/config/config_fdt.c +++ b/src/config/config_fdt.c @@ -36,3 +36,6 @@ PROVIDE_REQUIRING_SYMBOL(); /* * Drag in devicetree sources */ +#ifdef FDT_EFI +REQUIRE_OBJECT ( efi_fdt ); +#endif diff --git a/src/config/defaults/efi.h b/src/config/defaults/efi.h index 74effa425..53a7a7b4b 100644 --- a/src/config/defaults/efi.h +++ b/src/config/defaults/efi.h @@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define TIME_EFI #define REBOOT_EFI #define ACPI_EFI +#define FDT_EFI #define DOWNLOAD_PROTO_FILE /* Local filesystem access */ diff --git a/src/interface/efi/efi_fdt.c b/src/interface/efi/efi_fdt.c new file mode 100644 index 000000000..cd3f109df --- /dev/null +++ b/src/interface/efi/efi_fdt.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * You can also choose to distribute this program under the terms of + * the Unmodified Binary Distribution Licence (as given in the file + * COPYING.UBDL), provided that you have satisfied its requirements. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include +#include +#include +#include + +/** @file + * + * EFI Flattened Device Tree + * + */ + +#define DEVICE_TREE_TABLE_GUID \ + { 0xb1b621d5, 0xf19c, 0x41a5, \ + { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } } + +/** EFI Flattened Device Tree configuration table */ +static struct fdt_header *efi_fdt; +EFI_USE_TABLE ( DEVICE_TREE_TABLE, &efi_fdt, 0 ); + +/** + * Initialise EFI Flattened Device Tree + * + */ +static void efi_fdt_init ( void ) { + int rc; + + /* Do nothing if no configuration table is present */ + if ( ! efi_fdt ) { + DBGC ( &efi_fdt, "EFIFDT has no configuration table\n" ); + return; + } + DBGC ( &efi_fdt, "EFIFDT configuration table at %p\n", efi_fdt ); + + /* Register device tree */ + if ( ( rc = register_fdt ( efi_fdt ) ) != 0 ) { + DBGC ( &efi_fdt, "EFIFDT could not register: %s\n", + strerror ( rc ) ); + return; + } +} + +/** EFI Flattened Device Tree initialisation function */ +struct init_fn efi_fdt_init_fn __init_fn ( INIT_EARLY ) = { + .initialise = efi_fdt_init, +}; -- cgit v1.2.3-55-g7522 From 412acd7854de10e7194f362a6b1a3257a17974f7 Mon Sep 17 00:00:00 2001 From: Valentine Barshak Date: Sun, 9 Jun 2019 13:30:11 +0300 Subject: [build] Fix "'%s' directive argument is null" error Use '%p' directive, and print handle's address if the address is null and the handle doesn't have a name. This fixes the following compilation error: interface/efi/efi_debug.c:334:3: error: '%s' directive argument is null [-Werror=format-overflow=] Signed-off-by: Valentine Barshak Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/interface/efi') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 8ea0a822d..de9b1af55 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -331,8 +331,7 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) { /* Sanity check */ if ( ! handle ) { - printf ( "HANDLE %s could not retrieve protocols\n", - efi_handle_name ( handle ) ); + printf ( "HANDLE %p could not retrieve protocols\n", handle ); return; } -- cgit v1.2.3-55-g7522