Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F176328527
D39791.id120976.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D39791.id120976.diff
View Options
diff --git a/tools/boot/smbios/Makefile b/tools/boot/smbios/Makefile
new file mode 100644
--- /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
--- /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
--- /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);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 18, 11:20 PM (11 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41022070
Default Alt Text
D39791.id120976.diff (2 KB)
Attached To
Mode
D39791: stand: Testing program for smbios
Attached
Detach File
Event Timeline
Log In to Comment