mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 12/12] efi: add efi handle dump command
Date: Mon, 20 Feb 2017 04:10:51 +0100	[thread overview]
Message-ID: <1487560251-3005-3-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1487560251-3005-1-git-send-email-plagnioj@jcrosoft.com>

so we can inspect easly what is supported by the EFI implementation we running on

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/efi-guid.c        |   5 ++
 drivers/efi/efi-device.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++
 include/efi.h            |   8 +++
 3 files changed, 182 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 04a00ee87..71aa21ddd 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -77,6 +77,11 @@ const char *efi_guid_string(efi_guid_t *g)
 	EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID, "Network Interface Identifier Protocol", "EFI Network Interface Identifier Protocol");
 	EFI_GUID_STRING(EFI_TIMESTAMP_PROTOCOL_GUID, "Timestamp", "Timestamp");
 
+	/* TPM 1.2 */
+	EFI_GUID_STRING( EFI_TCG_PROTOCOL_GUID, "TcgService", "TCGServices Protocol");
+	/* TPM 2.0 */
+	EFI_GUID_STRING( EFI_TCG2_PROTOCOL_GUID, "Tcg2Service", "TCG2Services Protocol");
+
 	/* File */
 	EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI IdeBusDxe.inf File GUID");
 	EFI_GUID_STRING(EFI_TERMINALDXE_INF_GUID, "TerminalDxe.inf", "EFI TerminalDxe.inf File GUID");
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 1877794c6..db8b25147 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -382,3 +382,172 @@ static int efi_init_devices(void)
 	return 0;
 }
 core_initcall(efi_init_devices);
+
+static void efi_devpath(efi_handle_t handle)
+{
+	efi_status_t efiret;
+	void *devpath;
+	char *dev_path_str;
+
+	efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
+				   &devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+	if (EFI_ERROR(efiret))
+		return;
+
+	dev_path_str = device_path_to_str(devpath);
+	if (dev_path_str) {
+		printf("  Devpath: \n  %s\n", dev_path_str);
+		free(dev_path_str);
+	}
+}
+
+static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
+{
+	int i, j;
+	unsigned long num_guids;
+	efi_guid_t **guids;
+
+	if (!handles || !handle_count)
+		return;
+
+	for (i = 0; i < handle_count; i++) {
+		printf("handle-%p\n", handles[i]);
+
+		BS->protocols_per_handle(handles[i], &guids, &num_guids);
+		printf("  Protocols:\n");
+		for (j = 0; j < num_guids; j++)
+			printf("  %d: %pUl: %s\n", j, guids[j],
+					efi_guid_string(guids[j]));
+		efi_devpath(handles[i]);
+	}
+	printf("\n");
+}
+
+static unsigned char to_digit(unsigned char c)
+{
+	if (c >= '0' && c <= '9')
+		c -= '0';
+	else if (c >= 'A' && c <= 'F')
+		c -= 'A' - 10;
+	else
+		c -= 'a' - 10;
+
+	return c;
+}
+
+#define read_xbit(src, dest, bit) 					\
+	do {								\
+		int __i;						\
+		for (__i = (bit - 4); __i >= 0; __i -= 4, src++)	\
+			dest |= to_digit(*src) << __i;			\
+	} while (0)
+
+static int do_efi_protocol_dump(int argc, char **argv)
+{
+	unsigned long handle_count = 0;
+	efi_handle_t *handles = NULL;
+	int ret;
+	efi_guid_t guid;
+	u32 a = 0;
+	u16 b = 0;
+	u16 c = 0;
+	u8 d0 = 0;
+	u8 d1 = 0;
+	u8 d2 = 0;
+	u8 d3 = 0;
+	u8 d4 = 0;
+	u8 d5 = 0;
+	u8 d6 = 0;
+	u8 d7 = 0;
+
+	/* Format 220e73b6-6bdb-4413-8405-b974b108619a */
+	if (argc == 1) {
+		char *s = argv[0];
+		int len = strlen(s);
+
+		if (len != 36)
+			return -EINVAL;
+		
+		read_xbit(s, a, 32);
+		if (*s != '-')
+			return -EINVAL;
+		s++;
+		read_xbit(s, b, 16);
+		if (*s != '-')
+			return -EINVAL;
+		s++;
+		read_xbit(s, c, 16);
+		if (*s != '-')
+			return -EINVAL;
+		s++;
+		read_xbit(s, d0, 8);
+		read_xbit(s, d1, 8);
+		if (*s != '-')
+			return -EINVAL;
+		s++;
+		read_xbit(s, d2, 8);
+		read_xbit(s, d3, 8);
+		read_xbit(s, d4, 8);
+		read_xbit(s, d5, 8);
+		read_xbit(s, d6, 8);
+		read_xbit(s, d7, 8);
+	} else if (argc == 11) {
+		/* Format :
+		 *	220e73b6 6bdb 4413 84 05 b9 74 b1 08 61 9a
+		 *   or
+		 *	0x220e73b6 0x6bdb 0x14413 0x84 0x05 0xb9 0x74 0xb1 0x08 0x61 0x9a
+		 */
+		a = simple_strtoul(argv[0], NULL, 16);
+		b = simple_strtoul(argv[1], NULL, 16);
+		c = simple_strtoul(argv[2], NULL, 16);
+		d0 = simple_strtoul(argv[3], NULL, 16);
+		d1 = simple_strtoul(argv[4], NULL, 16);
+		d2 = simple_strtoul(argv[5], NULL, 16);
+		d3 = simple_strtoul(argv[6], NULL, 16);
+		d4 = simple_strtoul(argv[7], NULL, 16);
+		d5 = simple_strtoul(argv[8], NULL, 16);
+		d6 = simple_strtoul(argv[9], NULL, 16);
+		d7 = simple_strtoul(argv[10], NULL, 16);
+	} else {
+		return -EINVAL;
+	}
+
+	guid = EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7);
+
+	printf("Searching for:\n");
+	printf("  %pUl: %s\n", &guid, efi_guid_string(&guid));
+
+	ret = efi_locate_handle(by_protocol, &guid, NULL, &handle_count, &handles);
+	if (!ret)
+		efi_dump(handles, handle_count);
+
+	return 0;
+}
+
+static int do_efi_handle_dump(int argc, char *argv[])
+{
+	unsigned long handle_count = 0;
+	efi_handle_t *handles = NULL;
+	int ret;
+
+	if (argc > 1)
+		return do_efi_protocol_dump(--argc, ++argv);
+
+	ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
+	if (!ret)
+		efi_dump(handles, handle_count);
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(efi_handle_dump)
+BAREBOX_CMD_HELP_TEXT("Dump all the efi handle with protocol and devpath\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(efi_handle_dump)
+	.cmd = do_efi_handle_dump,
+	BAREBOX_CMD_DESC("Usage: efi_handle_dump")
+	BAREBOX_CMD_OPTS("[a-b-c-d0d1-d3d4d5d6d7] or [a b c d0 d1 d2 d3 d4 d5 d6 d7]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_HELP(cmd_efi_handle_dump_help)
+BAREBOX_CMD_END
diff --git a/include/efi.h b/include/efi.h
index d1b331ce5..5691f4e8f 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -480,6 +480,14 @@ extern efi_runtime_services_t *RT;
 #define EFI_SYSTEMD_VENDOR_GUID \
 	EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
 
+/* for TPM 1.2 */
+#define EFI_TCG_PROTOCOL_GUID \
+	EFI_GUID(0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd)
+
+/* for TPM 2.0 */
+#define EFI_TCG2_PROTOCOL_GUID \
+	EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
+
 extern efi_guid_t efi_file_info_id;
 extern efi_guid_t efi_simple_file_system_protocol_guid;
 extern efi_guid_t efi_device_path_protocol_guid;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-02-20  3:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15 19:29 [PATCH 0/12] EFI: drop arch efi Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34 ` [PATCH 01/12] efi: move block io driver to driver/block Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 02/12] efi: move clocksource out of arch Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 03/12] efi: move bus driver to driver/efi Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 04/12] efi: move debug_ll.h to include/efi Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 05/12] efi: move startup and payload to common/efi Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 06/12] x86: move bios bootup code to arch/x86/bios Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 07/12] efi: move x86 efi boot support to x86 arch Jean-Christophe PLAGNIOL-VILLARD
2017-02-16  7:27     ` Michael Olbrich
2017-02-23 11:39       ` Jean-Christophe PLAGNIOL-VILLARD
2017-02-27  7:50     ` Sascha Hauer
2017-03-07  8:31       ` [PATCH] fixup! " Michael Olbrich
2017-03-09  6:37         ` Sascha Hauer
2017-02-15 19:34   ` [PATCH 08/12] ARCH: efi: Finally drop it as now we can build efi bootup from x86 Jean-Christophe PLAGNIOL-VILLARD
2017-02-15 19:34   ` [PATCH 09/12] efi: bus: add firmware vendor and resision and tables info Jean-Christophe PLAGNIOL-VILLARD
2017-02-16  7:38 ` [PATCH 0/12] EFI: drop arch efi Michael Olbrich
2017-02-16  7:42   ` Michael Olbrich
2017-02-20  3:10 ` [PATCH 10/12] efi: add minor and major to the bus and display it at boot Jean-Christophe PLAGNIOL-VILLARD
2017-02-20  3:10   ` [PATCH 11/12] efi-gui: add Timestamp Protocol GUID definition Jean-Christophe PLAGNIOL-VILLARD
2017-02-20  3:10   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2017-03-11 16:26 ` [PATCH 0/12] EFI: drop arch efi Michael Olbrich
2017-03-12 12:05   ` Jean-Christophe PLAGNIOL-VILLARD
2017-03-13 10:27     ` Michael Olbrich
2017-03-13 10:48       ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487560251-3005-3-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox