mb/dell: Add Latitude E5520 (Sandy Bridge)
[coreboot.git] / util / smmstoretool / guids.c
blob4ba92b97983846c2505771146aeb04f562bd9eae
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include "guids.h"
5 #include <stdio.h>
6 #include <string.h>
8 #include <commonlib/bsd/helpers.h>
10 #include "udk2017.h"
11 #include "utils.h"
13 const struct guid_alias_t known_guids[] = {
15 "coreboot",
17 0xceae4c1d, 0x335b, 0x4685,
18 { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 }
22 "dasharo",
24 0xd15b327e, 0xff2d, 0x4fc1,
25 { 0xab, 0xf6, 0xc1, 0x2b, 0xd0, 0x8c, 0x13, 0x59 }
29 "global",
31 0x8be4df61, 0x93ca, 0x11d2,
32 { 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c }
36 "microsoft",
38 0x77fa9abd, 0x0359, 0x4d32,
39 { 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b }
44 const int known_guid_count = ARRAY_SIZE(known_guids);
46 char *format_guid(const EFI_GUID *guid, bool use_alias)
48 if (use_alias) {
49 for (int i = 0; i < known_guid_count; ++i) {
50 const struct guid_alias_t *known_guid = &known_guids[i];
51 if (memcmp(&known_guid->guid, guid, sizeof(*guid)) == 0)
52 return strdup(known_guid->alias);
56 char *str = xmalloc(GUID_LEN + 1);
57 snprintf(str, GUID_LEN + 1,
58 "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x",
59 guid->Data1, guid->Data2, guid->Data3,
60 guid->Data4[0], guid->Data4[1],
61 guid->Data4[2], guid->Data4[3],
62 guid->Data4[4], guid->Data4[5],
63 guid->Data4[6], guid->Data4[7]);
64 return str;
67 bool parse_guid(const char str[], EFI_GUID *guid)
69 for (int i = 0; i < known_guid_count; ++i) {
70 const struct guid_alias_t *known_guid = &known_guids[i];
71 if (str_eq(known_guid->alias, str)) {
72 *guid = known_guid->guid;
73 return true;
77 if (strlen(str) != GUID_LEN)
78 return false;
80 int n = sscanf(str,
81 "%08x-%04hx-%04hx-"
82 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
83 &guid->Data1, &guid->Data2, &guid->Data3,
84 &guid->Data4[0], &guid->Data4[1],
85 &guid->Data4[2], &guid->Data4[3],
86 &guid->Data4[4], &guid->Data4[5],
87 &guid->Data4[6], &guid->Data4[7]);
88 return n == 11;