summaryrefslogtreecommitdiff
path: root/src/drivers/generic/cbfs-uuid/cbfs-uuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/generic/cbfs-uuid/cbfs-uuid.c')
-rw-r--r--src/drivers/generic/cbfs-uuid/cbfs-uuid.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/drivers/generic/cbfs-uuid/cbfs-uuid.c b/src/drivers/generic/cbfs-uuid/cbfs-uuid.c
new file mode 100644
index 0000000000..e657bdd922
--- /dev/null
+++ b/src/drivers/generic/cbfs-uuid/cbfs-uuid.c
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <cbfs.h>
+#include <device/device.h>
+#include <smbios.h>
+#include <string.h>
+#include <uuid.h>
+
+void smbios_system_set_uuid(u8 *uuid)
+{
+ /* Add 3 more bytes: 2 for possible CRLF and third for NULL char */
+ char uuid_str[UUID_STRLEN + 3] = {0};
+ uint8_t system_uuid[UUID_LEN];
+
+ size_t uuid_len = cbfs_load("system_uuid", uuid_str, UUID_STRLEN);
+
+ if (uuid_len >= UUID_STRLEN && uuid_len <= UUID_STRLEN + 3) {
+ /* Cut off any trailing whitespace like CR or LF */
+ uuid_str[UUID_STRLEN] = '\0';
+ if (!parse_uuid(system_uuid, uuid_str))
+ memcpy(uuid, system_uuid, UUID_LEN);
+ }
+}