[PATCH 8/8] cmd: printenv: simplify printing GUIDs

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sun Jan 16 16:14:41 CET 2022


Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 cmd/nvedit_efi.c | 39 ++-------------------------------------
 lib/uuid.c       | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 710d923a91..7ebb14e25f 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -39,40 +39,6 @@ static const struct {
 	{EFI_VARIABLE_READ_ONLY, "RO"},
 };
 
-static const struct {
-	efi_guid_t guid;
-	char *text;
-} efi_guid_text[] = {
-	/* signature database */
-	{EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"},
-	{EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"},
-	/* certificate type */
-	{EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"},
-	{EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"},
-	{EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"},
-};
-
-static const char unknown_guid[] = "";
-
-/**
- * efi_guid_to_str() - convert guid to readable name
- *
- * @guid:	GUID
- * Return:	string for GUID
- *
- * convert guid to readable name
- */
-static const char *efi_guid_to_str(const efi_guid_t *guid)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(efi_guid_text); i++)
-		if (!guidcmp(guid, &efi_guid_text[i].guid))
-			return efi_guid_text[i].text;
-
-	return unknown_guid;
-}
-
 /**
  * efi_dump_single_var() - show information about a UEFI variable
  *
@@ -111,7 +77,7 @@ static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose)
 		goto out;
 
 	rtc_to_tm(time, &tm);
-	printf("%ls:\n    %pUl %s\n", name, guid, efi_guid_to_str(guid));
+	printf("%ls:\n    %pUl (%pUs)\n", name, guid, guid);
 	if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
 		printf("    %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year,
 		       tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
@@ -497,8 +463,7 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	if (verbose) {
-		printf("GUID: %pUl %s\n", &guid,
-		       efi_guid_to_str((const efi_guid_t *)&guid));
+		printf("GUID: %pUl (%pUs)\n", &guid, &guid);
 		printf("Attributes: 0x%x\n", attributes);
 	}
 
diff --git a/lib/uuid.c b/lib/uuid.c
index 60b7ca17f1..3ffaab7d15 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -217,6 +217,30 @@ static const struct {
 		EFI_TCG2_FINAL_EVENTS_TABLE_GUID,
 	},
 #endif
+#ifdef CONFIG_CMD_NVEDIT_EFI
+	/* signature database */
+	{
+		"EFI_GLOBAL_VARIABLE_GUID",
+		EFI_GLOBAL_VARIABLE_GUID,
+	},
+	{
+		"EFI_IMAGE_SECURITY_DATABASE_GUID",
+		EFI_IMAGE_SECURITY_DATABASE_GUID,
+	},
+	/* certificate types */
+	{
+		"EFI_CERT_SHA256_GUID",
+		EFI_CERT_SHA256_GUID,
+	},
+	{
+		"EFI_CERT_X509_GUID",
+		EFI_CERT_X509_GUID,
+	},
+	{
+		"EFI_CERT_TYPE_PKCS7_GUID",
+		EFI_CERT_TYPE_PKCS7_GUID,
+	},
+#endif
 };
 
 /*
-- 
2.33.1



More information about the U-Boot mailing list