Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 May 2023 21:28:48 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: cf6044857e2b - main - stand: Testing program for smbios
Message-ID:  <202305012128.341LSmDU085867@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=cf6044857e2b20f2ecf90929027e9dd335b38803

commit cf6044857e2b20f2ecf90929027e9dd335b38803
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-05-01 21:12:19 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-05-01 21:12:19 +0000

    stand: Testing program for smbios
    
    Write a quick and dirty testing program to dump physical memory to help
    test and debug the smbios.c code in new environments.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D39791
---
 tools/boot/smbios/Makefile | 11 ++++++
 tools/boot/smbios/main.c   | 96 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/boot/smbios/stand.h  | 18 +++++++++
 3 files changed, 125 insertions(+)

diff --git a/tools/boot/smbios/Makefile b/tools/boot/smbios/Makefile
new file mode 100644
index 000000000000..a555470aab14
--- /dev/null
+++ b/tools/boot/smbios/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+PROG=	smbios
+MAN=
+.PATH:	${SRCTOP}/stand/libsa
+SRCS=	main.c
+CFLAGS+= -I${.CURDIR} -I${SRCTOP}/stand/libsa
+
+.include <bsd.prog.mk>
+
+CFLAGS+= -Wno-cast-align
diff --git a/tools/boot/smbios/main.c b/tools/boot/smbios/main.c
new file mode 100644
index 000000000000..60263d2ea8d9
--- /dev/null
+++ b/tools/boot/smbios/main.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2023 Warner Losh
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * Test program for smbios support in the boot loader. This program will mmap
+ * physical memory, and print the smbios table at the passed in PA. This is
+ * intended to test the code and debug problems in a debugger friendly
+ * environment.
+ */
+
+#include <sys/param.h>
+#define setenv my_setenv
+
+#define SMBIOS_SERIAL_NUMBERS 1
+#define SMBIOS_LITTLE_ENDIAN_UUID 1
+
+#include <arpa/inet.h>
+
+#include "smbios.h"
+#include "smbios.c"
+
+#include <sys/mman.h>
+
+#define MAX_MAP	10
+#define PAGE	(64<<10)
+
+static struct mapping 
+{
+	uintptr_t pa;
+	caddr_t va;
+} map[MAX_MAP];
+static int fd;
+static int nmap;
+
+caddr_t ptov(uintptr_t pa)
+{
+	caddr_t va;
+	uintptr_t pa2;
+	struct mapping *m = map;
+
+	pa2 = rounddown(pa, PAGE);
+	for (int i = 0; i < nmap; i++, m++) {
+		if (m->pa == pa2) {
+			return (m->va + pa - m->pa);
+		}
+	}
+	if (nmap == MAX_MAP)
+		errx(1, "Too many maps");
+	va = mmap(0, PAGE, PROT_READ, MAP_SHARED, fd, pa2);
+	if (va == MAP_FAILED)
+		err(1, "mmap offset %#lx", (long)pa2);
+	m = &map[nmap++];
+	m->pa = pa2;
+	m->va = va;
+	return (m->va + pa - m->pa);
+}
+
+static void
+cleanup(void)
+{
+	for (int i = 0; i < nmap; i++) {
+		munmap(map[i].va, PAGE);
+	}
+}
+
+int
+my_setenv(const char *name, const char *value, int overwrite __unused)
+{
+	printf("%s=%s\n", name, value);
+	return 0;
+}
+
+static void
+usage(void)
+{
+	errx(1, "smbios address");
+}
+
+int
+main(int argc, char **argv)
+{
+	uintptr_t addr;
+	
+	if (argc != 2)
+		usage();
+	addr = strtoull(argv[1], NULL, 0);
+	/* For mmap later */
+	fd = open("/dev/mem", O_RDONLY);
+	if (fd < 0)
+		err(1, "Opening /dev/mem");
+	smbios_detect(ptov(addr));
+	cleanup();
+}
diff --git a/tools/boot/smbios/stand.h b/tools/boot/smbios/stand.h
new file mode 100644
index 000000000000..d754189fad13
--- /dev/null
+++ b/tools/boot/smbios/stand.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2023 Warner Losh
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/types.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+caddr_t ptov(uintptr_t pa);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202305012128.341LSmDU085867>