[coreboot-gerrit] Change in coreboot[master]: purism/librem13v2: Add reading of serial number from cbfs

Youness Alaoui (Code Review) gerrit at coreboot.org
Mon Oct 16 19:13:22 CEST 2017


Hello Matt DeVillier,

I'd like you to do a code review. Please visit

    https://review.coreboot.org/22040

to review the following change.


Change subject: purism/librem13v2: Add reading of serial number from cbfs
......................................................................

purism/librem13v2: Add reading of serial number from cbfs

Check CBFS for 'serial_number' field, and use value if exists;
otherwise use value set at compile time.

Change-Id: I4b50f6310ca32b9dd372db075a5b5729e3b06619
Signed-off-by: Matt DeVillier <matt.devillier at gmail.com>
Signed-off-by: Youness Alaoui <youness.alaoui at puri.sm>
---
A src/mainboard/purism/librem13v2/mainboard.c
1 file changed, 47 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/22040/1

diff --git a/src/mainboard/purism/librem13v2/mainboard.c b/src/mainboard/purism/librem13v2/mainboard.c
new file mode 100644
index 0000000..e941fc5
--- /dev/null
+++ b/src/mainboard/purism/librem13v2/mainboard.c
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2017 Purism SPC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <rules.h>
+#include <smbios.h>
+#include <string.h>
+#include <cbfs.h>
+
+#define MAX_SERIAL_LENGTH 0x100
+
+const char *smbios_mainboard_serial_number(void)
+{
+	static char serial_number[MAX_SERIAL_LENGTH + 1] = {0};
+	struct cbfsf file;
+
+	if (serial_number[0] != 0)
+		return serial_number;
+
+	if (cbfs_boot_locate(&file, "serial_number", NULL) == 0) {
+		struct region_device cbfs_region;
+		size_t serial_len;
+		cbfs_file_data(&cbfs_region, &file);
+
+		serial_len = region_device_sz(&cbfs_region);
+		if (serial_len < MAX_SERIAL_LENGTH) {
+			rdev_readat(&cbfs_region, serial_number, 0, serial_len);
+			serial_number[serial_len] = 0;
+		}
+	} else {
+		strncpy(serial_number, CONFIG_MAINBOARD_SERIAL_NUMBER,
+			MAX_SERIAL_LENGTH);
+	}
+
+	return serial_number;
+}

-- 
To view, visit https://review.coreboot.org/22040
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b50f6310ca32b9dd372db075a5b5729e3b06619
Gerrit-Change-Number: 22040
Gerrit-PatchSet: 1
Gerrit-Owner: Youness Alaoui <snifikino at gmail.com>
Gerrit-Reviewer: Matt DeVillier <matt.devillier at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20171016/fb2e39a9/attachment-0001.html>


More information about the coreboot-gerrit mailing list