git: 50af79ac2d71 - stable/13 - loader: lsefi: Print more information

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 14 Jan 2022 13:42:10 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=50af79ac2d711daf1c37aacfd1ef7cbb3b3f10a7

commit 50af79ac2d711daf1c37aacfd1ef7cbb3b3f10a7
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-11-15 11:12:50 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-14 13:38:25 +0000

    loader: lsefi: Print more information
    
    Printing the EFI_HANDLE pointer isn't very useful.
    If the handle have a IMAGE_DEVICE_PATH or a DEVICE_PATH protocol print it.
    This makes it easier to see which devices are present and what protocol they
    expose.
    
    Reviewed by:    imp, tsoome
    Differential Revision:  https://reviews.freebsd.org/D32991
    Sponsored by: Beckhoff Automation GmbH & Co. KG
    
    (cherry picked from commit 2e0d67c3ed7ec760b2d54f8258304b2e6359418b)
---
 stand/efi/loader/main.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index 97bdb7f31e97..a1a62381e45c 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -1378,6 +1378,30 @@ command_mode(int argc, char *argv[])
 
 COMMAND_SET(lsefi, "lsefi", "list EFI handles", command_lsefi);
 
+static void
+lsefi_print_handle_info(EFI_HANDLE handle)
+{
+	EFI_DEVICE_PATH *devpath;
+	EFI_DEVICE_PATH *imagepath;
+	CHAR16 *dp_name;
+
+	imagepath = efi_lookup_image_devpath(handle);
+	if (imagepath != NULL) {
+		dp_name = efi_devpath_name(imagepath);
+		printf("Handle for image %S", dp_name);
+		efi_free_devpath_name(dp_name);
+		return;
+	}
+	devpath = efi_lookup_devpath(handle);
+	if (devpath != NULL) {
+		dp_name = efi_devpath_name(devpath);
+		printf("Handle for device %S", dp_name);
+		efi_free_devpath_name(dp_name);
+		return;
+	}
+	printf("Handle %p", handle);
+}
+
 static int
 command_lsefi(int argc __unused, char *argv[] __unused)
 {
@@ -1413,7 +1437,7 @@ command_lsefi(int argc __unused, char *argv[] __unused)
 		EFI_GUID **protocols = NULL;
 
 		handle = buffer[i];
-		printf("Handle %p", handle);
+		lsefi_print_handle_info(handle);
 		if (pager_output("\n"))
 			break;
 		/* device path */