summaryrefslogtreecommitdiff
path: root/util/smmstoretool/guids.c
diff options
context:
space:
mode:
authorSergii Dmytruk <sergii.dmytruk@3mdeb.com>2023-11-17 19:31:20 +0200
committerMartin L Roth <gaumless@gmail.com>2024-03-09 23:22:55 +0000
commit04bd9651435843ce4b03c9717f2965fe344fe5cc (patch)
tree0193502b26818c738206a60862c689485d533a50 /util/smmstoretool/guids.c
parent7a51acfbe91c7f9d01837103341526abb6ea46f4 (diff)
util: add smmstoretool for editing SMMSTORE
Offline SMMSTORE variable modification tool. Can be used to pre-configure ROM image or debug EFI state stored in a dump. Change-Id: I6c1c06f1d0c39c13b5be76a3070f09b715aca6e0 Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/79080 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Michał Żygowski <michal.zygowski@3mdeb.com> Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Diffstat (limited to 'util/smmstoretool/guids.c')
-rw-r--r--util/smmstoretool/guids.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/util/smmstoretool/guids.c b/util/smmstoretool/guids.c
new file mode 100644
index 0000000000..4ba92b9798
--- /dev/null
+++ b/util/smmstoretool/guids.c
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "guids.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <commonlib/bsd/helpers.h>
+
+#include "udk2017.h"
+#include "utils.h"
+
+const struct guid_alias_t known_guids[] = {
+ {
+ "coreboot",
+ {
+ 0xceae4c1d, 0x335b, 0x4685,
+ { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 }
+ },
+ },
+ {
+ "dasharo",
+ {
+ 0xd15b327e, 0xff2d, 0x4fc1,
+ { 0xab, 0xf6, 0xc1, 0x2b, 0xd0, 0x8c, 0x13, 0x59 }
+ },
+ },
+ {
+ "global",
+ {
+ 0x8be4df61, 0x93ca, 0x11d2,
+ { 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c }
+ },
+ },
+ {
+ "microsoft",
+ {
+ 0x77fa9abd, 0x0359, 0x4d32,
+ { 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b }
+ },
+ },
+};
+
+const int known_guid_count = ARRAY_SIZE(known_guids);
+
+char *format_guid(const EFI_GUID *guid, bool use_alias)
+{
+ if (use_alias) {
+ for (int i = 0; i < known_guid_count; ++i) {
+ const struct guid_alias_t *known_guid = &known_guids[i];
+ if (memcmp(&known_guid->guid, guid, sizeof(*guid)) == 0)
+ return strdup(known_guid->alias);
+ }
+ }
+
+ char *str = xmalloc(GUID_LEN + 1);
+ snprintf(str, GUID_LEN + 1,
+ "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x",
+ guid->Data1, guid->Data2, guid->Data3,
+ guid->Data4[0], guid->Data4[1],
+ guid->Data4[2], guid->Data4[3],
+ guid->Data4[4], guid->Data4[5],
+ guid->Data4[6], guid->Data4[7]);
+ return str;
+}
+
+bool parse_guid(const char str[], EFI_GUID *guid)
+{
+ for (int i = 0; i < known_guid_count; ++i) {
+ const struct guid_alias_t *known_guid = &known_guids[i];
+ if (str_eq(known_guid->alias, str)) {
+ *guid = known_guid->guid;
+ return true;
+ }
+ }
+
+ if (strlen(str) != GUID_LEN)
+ return false;
+
+ int n = sscanf(str,
+ "%08x-%04hx-%04hx-"
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
+ &guid->Data1, &guid->Data2, &guid->Data3,
+ &guid->Data4[0], &guid->Data4[1],
+ &guid->Data4[2], &guid->Data4[3],
+ &guid->Data4[4], &guid->Data4[5],
+ &guid->Data4[6], &guid->Data4[7]);
+ return n == 11;
+}