aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2023-05-01 21:12:19 +0000
committerWarner Losh <imp@FreeBSD.org>2023-05-01 21:12:19 +0000
commitcf6044857e2b20f2ecf90929027e9dd335b38803 (patch)
tree7074f880851afcc4f7d3ee7b3cf53f41d68b3663 /tools
parent83eabc64efec4aaf46f87bf2ba5560ecd4c336d7 (diff)
downloadsrc-cf6044857e2b20f2ecf90929027e9dd335b38803.tar.gz
src-cf6044857e2b20f2ecf90929027e9dd335b38803.zip
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
Diffstat (limited to 'tools')
-rw-r--r--tools/boot/smbios/Makefile11
-rw-r--r--tools/boot/smbios/main.c96
-rw-r--r--tools/boot/smbios/stand.h18
3 files changed, 125 insertions, 0 deletions
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);