? dmidecode-m-option.diff
Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/dmidecode/Makefile,v
diff -u -p -u -p -r1.19 Makefile
--- Makefile	25 Apr 2024 11:53:34 -0000	1.19
+++ Makefile	11 Oct 2025 06:27:07 -0000
@@ -1,10 +1,9 @@
-# builds on aarch64 but for !x86 it requires code to lookup the entry
-# point from EFI and only FreeBSD/Linux implementations are present.
 ONLY_FOR_ARCHS=	amd64 i386
 
 COMMENT=	dump DMI/SMBIOS contents in human-readable format
 DISTNAME=	dmidecode-3.6
 EXTRACT_SUFX=	.tar.xz
+REVISION=	1
 
 CATEGORIES=	sysutils
 
Index: patches/patch-biosdecode_c
===================================================================
RCS file: patches/patch-biosdecode_c
diff -N patches/patch-biosdecode_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-biosdecode_c	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,11 @@
+Index: biosdecode.c
+--- biosdecode.c.orig
++++ biosdecode.c
+@@ -62,6 +62,7 @@
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <getopt.h>
++#include <stdint.h>
+ 
+ #include "version.h"
+ #include "config.h"
Index: patches/patch-dmidecode_c
===================================================================
RCS file: patches/patch-dmidecode_c
diff -N patches/patch-dmidecode_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-dmidecode_c	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,58 @@
+Index: dmidecode.c
+--- dmidecode.c.orig
++++ dmidecode.c
+@@ -66,6 +66,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <strings.h>
++#include <stdint.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <arpa/inet.h>
+@@ -6176,6 +6177,7 @@ int main(int argc, char * const argv[])
+ 	size_t size;
+ 	int efi;
+ 	u8 *buf = NULL;
++	uint64_t scan_base = 0xF0000ULL;
+ 
+ 	/*
+ 	 * We don't want stdout and stderr to be mixed up if both are
+@@ -6220,8 +6222,13 @@ int main(int argc, char * const argv[])
+ 	}
+ 
+ 	if (!(opt.flags & FLAG_QUIET))
++	{
+ 		pr_comment("dmidecode %s", VERSION);
+-
++			#ifdef __OpenBSD__
++			pr_info("Defaulting to --no-sysfs on OpenBSD.");
++			opt.flags |= FLAG_NO_SYSFS;
++			#endif
++	}
+ 	/* Read from dump if so instructed */
+ 	size = 0x20;
+ 	if (opt.flags & FLAG_FROM_DUMP)
+@@ -6326,10 +6333,21 @@ int main(int argc, char * const argv[])
+ 
+ memory_scan:
+ #if defined __i386__ || defined __x86_64__
++	/* Fallback to memory scan (x86, x86_64) */
+ 	if (!(opt.flags & FLAG_QUIET))
+ 		pr_info("Scanning %s for entry point.", opt.devmem);
+-	/* Fallback to memory scan (x86, x86_64) */
+-	if ((buf = mem_chunk(0xF0000, 0x10000, opt.devmem)) == NULL)
++
++	/* Use memory base address if provided */
++	if (opt.flags & FLAG_MEM_BASE)
++	{
++		scan_base = opt.mem_base;
++		if (!(opt.flags & FLAG_QUIET))
++			pr_info("Scanning from memory base 0x%llx.", scan_base);
++	}
++	else
++		scan_base = 0xF0000;
++
++	if ((buf = mem_chunk(scan_base, 0x10000, opt.devmem)) == NULL)
+ 	{
+ 		ret = 1;
+ 		goto exit_free;
Index: patches/patch-dmioem_c
===================================================================
RCS file: patches/patch-dmioem_c
diff -N patches/patch-dmioem_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-dmioem_c	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,11 @@
+Index: dmioem.c
+--- dmioem.c.orig
++++ dmioem.c
+@@ -22,6 +22,7 @@
+ 
+ #include <stdio.h>
+ #include <string.h>
++#include <stdint.h>
+ 
+ #include "types.h"
+ #include "util.h"
Index: patches/patch-dmiopt_c
===================================================================
RCS file: patches/patch-dmiopt_c
diff -N patches/patch-dmiopt_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-dmiopt_c	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,72 @@
+Index: dmiopt.c
+--- dmiopt.c.orig
++++ dmiopt.c
+@@ -30,10 +30,10 @@
+ #include "util.h"
+ #include "dmidecode.h"
+ #include "dmiopt.h"
++#include "dmioutput.h"
+ 
+-
+ /* Options are global */
+-struct opt opt;
++struct opt opt = {0};
+ 
+ 
+ /*
+@@ -266,11 +266,12 @@ int parse_command_line(int argc, char * const argv[])
+ {
+ 	int option;
+ 	unsigned int i;
+-	const char *optstring = "d:hqs:t:uH:V";
++	const char *optstring = "d:hqm:Qs:t:uB:F:H:O:SLTV";
+ 	struct option longopts[] = {
+ 		{ "dev-mem", required_argument, NULL, 'd' },
+ 		{ "help", no_argument, NULL, 'h' },
+ 		{ "quiet", no_argument, NULL, 'q' },
++		{ "mem-base", required_argument, NULL, 'm' },
+ 		{ "no-quirks", no_argument, NULL, 'Q' },
+ 		{ "string", required_argument, NULL, 's' },
+ 		{ "type", required_argument, NULL, 't' },
+@@ -303,6 +304,14 @@ int parse_command_line(int argc, char * const argv[])
+ 			case 'h':
+ 				opt.flags |= FLAG_HELP;
+ 				break;
++			case 'm':
++				if (sscanf(optarg, "0x%llx", &opt.mem_base) != 1)
++				{
++					pr_info("Memory base address in format 0x<address> required: %s\n", optarg);
++					return -1;
++				} else
++					opt.flags |= FLAG_MEM_BASE;
++				break;
+ 			case 'q':
+ 				opt.flags |= FLAG_QUIET;
+ 				break;
+@@ -387,18 +396,19 @@ void print_help(void)
+ 		"Options are:\n"
+ 		" -d, --dev-mem FILE     Read memory from device FILE (default: " DEFAULT_MEM_DEV ")\n"
+ 		" -h, --help             Display this help text and exit\n"
++		" -m, --mem-base 0xADDR  Memory-scan for Entrypoint from base ADDR\n"
+ 		" -q, --quiet            Less verbose output\n"
+-		"     --no-quirks        Decode everything without quirks\n"
++		" -Q, --no-quirks        Decode everything without quirks\n"
+ 		" -s, --string KEYWORD   Only display the value of the given DMI string\n"
+-		"     --list-strings     List available string keywords and exit\n"
++		" -L, --list-strings     List available string keywords and exit\n"
+ 		" -t, --type TYPE        Only display the entries of given type\n"
+-		"     --list-types       List available type keywords and exit\n"
++		" -T, --list-types       List available type keywords and exit\n"
+ 		" -H, --handle HANDLE    Only display the entry of given handle\n"
+ 		" -u, --dump             Do not decode the entries\n"
+-		"     --dump-bin FILE    Dump the DMI data to a binary file\n"
+-		"     --from-dump FILE   Read the DMI data from a binary file\n"
+-		"     --no-sysfs         Do not attempt to read DMI data from sysfs files\n"
+-		"     --oem-string N     Only display the value of the given OEM string\n"
++		" -B, --dump-bin FILE    Dump the DMI data to a binary file\n"
++		" -F, --from-dump FILE   Read the DMI data from a binary file\n"
++		" -S, --no-sysfs         Do not attempt to read DMI data from sysfs files\n"
++		" -O, --oem-string N     Only display the value of the given OEM string\n"
+ 		" -V, --version          Display the version and exit\n";
+ 
+ 	printf("%s", help);
Index: patches/patch-dmiopt_h
===================================================================
RCS file: patches/patch-dmiopt_h
diff -N patches/patch-dmiopt_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-dmiopt_h	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,19 @@
+Index: dmiopt.h
+--- dmiopt.h.orig
++++ dmiopt.h
+@@ -32,6 +32,7 @@ struct opt
+ {
+ 	const char *devmem;
+ 	unsigned int flags;
++	uint64_t mem_base;
+ 	u8 *type;
+ 	const struct string_keyword *string;
+ 	char *dumpfile;
+@@ -48,6 +49,7 @@ extern struct opt opt;
+ #define FLAG_NO_SYSFS           (1 << 6)
+ #define FLAG_NO_QUIRKS          (1 << 7)
+ #define FLAG_LIST               (1 << 8)
++#define FLAG_MEM_BASE           (1 << 9)
+ 
+ int parse_command_line(int argc, char * const argv[]);
+ void print_help(void);
Index: patches/patch-man_dmidecode_8
===================================================================
RCS file: patches/patch-man_dmidecode_8
diff -N patches/patch-man_dmidecode_8
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-man_dmidecode_8	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,70 @@
+Index: man/dmidecode.8
+--- man/dmidecode.8.orig
++++ man/dmidecode.8
+@@ -70,7 +70,7 @@ Read memory from device \fIFILE\fP (default: \fI/dev/m
+ Be less verbose. Unknown, inactive and \s-1OEM\s0-specific entries are not
+ displayed. Meta-data and handle references are hidden.
+ .TP
+-.BR "  " "  " "--no-quirks"
++.BR "-Q" ", " "--no-quirks"
+ Decode everything exactly as it is in the table, without trying to fix up
+ common mistakes or hide irrelevant fields.
+ This mode is primarily aimed at firmware developers.
+@@ -127,7 +127,7 @@ typically from files under
+ .IR /sys/devices/virtual/dmi/id .
+ Most of these files are even readable by regular users.
+ .TP
+-.BR "  " "  " "--list-strings"
++.BR "-L" ", " "--list-strings"
+ List available string keywords, which can then be passed to the \fB--string\fP
+ option.
+ .TP
+@@ -154,7 +154,7 @@ is printed and
+ .B dmidecode
+ exits with an error.
+ .TP
+-.BR "  " "  " "--list-types"
++.BR "-T" ", " "--list-types"
+ List available type keywords, which can then be passed to the \fB--type\fP
+ option.
+ .TP
+@@ -162,27 +162,35 @@ option.
+ Only display the entry whose handle matches \fIHANDLE\fP.
+ \fIHANDLE\fP is a 16-bit integer.
+ .TP
++.BR "-m" ", " "--mem-base \fIADDRESS\fP"
++If memory-scanning (default: /dev/mem, see -d option above) is used,
++scan a 64kB range starting at \fIADDRESS\fP rather than the Legacy BIOS
++range 0xF0000 to 0xFFFFF. \fIADDRESS\fP format: 0xnnnnnnnnnnnnnnnn ,
++a 64-bit integer. Leading zeros may be omitted.
++Useful for legacy-free systems that do not have EFI or sysfs structures,
++which are tried first.
++.TP
+ .BR "-u" ", " "--dump"
+ Do not decode the entries, dump their contents as hexadecimal instead.
+ Note that this is still a text output, no binary data will be thrown upon
+ you. The strings attached to each entry are displayed as both
+ hexadecimal and \s-1ASCII\s0. This option is mainly useful for debugging.
+ .TP
+-.BR "  " "  " "--dump-bin \fIFILE\fP"
++.BR "-B" ", " "--dump-bin \fIFILE\fP"
+ Do not decode the entries, instead dump the DMI data to a file in binary
+ form. The generated file is suitable to pass to \fB--from-dump\fP
+ later.
+ \fIFILE\fP must not exist.
+ .TP
+-.BR "  " "  " "--from-dump \fIFILE\fP"
++.BR "-F" ", " "--from-dump \fIFILE\fP"
+ Read the DMI data from a binary file previously generated using
+ \fB--dump-bin\fP.
+ .TP
+-.BR "  " "  " "--no-sysfs"
++.BR "-S" ",  " "--no-sysfs"
+ Do not attempt to read DMI data from sysfs files. This is mainly useful for
+ debugging.
+ .TP
+-.BR "  " "  " "--oem-string \fIN\fP"
++.BR "-O" ", " "--oem-string \fIN\fP"
+ Only display the value of the \s-1OEM\s0 string number \fIN\fP. The first
+ \s-1OEM\s0 string has number \fB1\fP. With special value \fBcount\fP, return the
+ number of OEM strings instead.
Index: patches/patch-ownership_c
===================================================================
RCS file: patches/patch-ownership_c
diff -N patches/patch-ownership_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-ownership_c	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,11 @@
+Index: ownership.c
+--- ownership.c.orig
++++ ownership.c
+@@ -34,6 +34,7 @@
+ #include <string.h>
+ #include <unistd.h>
+ #include <getopt.h>
++#include <stdint.h>
+ 
+ #include "version.h"
+ #include "config.h"
Index: patches/patch-types_h
===================================================================
RCS file: patches/patch-types_h
diff -N patches/patch-types_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-types_h	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,16 @@
+Index: types.h
+--- types.h.orig
++++ types.h
+@@ -51,9 +51,9 @@ static inline u64 U64(u32 low, u32 high)
+ #define DWORD(x) (u32)((x)[0] + ((x)[1] << 8) + ((x)[2] << 16) + ((x)[3] << 24))
+ #define QWORD(x) (U64(DWORD(x), DWORD(x + 4)))
+ #else /* ALIGNMENT_WORKAROUND || BIGENDIAN */
+-#define WORD(x) (u16)(*(const u16 *)(x))
+-#define DWORD(x) (u32)(*(const u32 *)(x))
+-#define QWORD(x) (*(const u64 *)(x))
++#define WORD(x) (*(const u16 *)((uintptr_t)(x) & ~1))  // Ensures 2-byte alignment
++#define DWORD(x) (*(const u32 *)((uintptr_t)(x) & ~3))  // Ensures 4-byte alignment
++#define QWORD(x) (*(const u64 *)((uintptr_t)(x) & ~7))  // Ensures 8-byte alignment
+ #endif /* ALIGNMENT_WORKAROUND || BIGENDIAN */
+ 
+ #endif
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/sysutils/dmidecode/pkg/PLIST,v
diff -u -p -u -p -r1.7 PLIST
--- pkg/PLIST	25 Apr 2024 11:53:34 -0000	1.7
+++ pkg/PLIST	11 Oct 2025 06:27:07 -0000
@@ -11,3 +11,4 @@ share/doc/dmidecode/
 share/doc/dmidecode/AUTHORS
 share/doc/dmidecode/NEWS
 share/doc/dmidecode/README
+share/doc/pkg-readmes/${PKGSTEM}
Index: pkg/README
===================================================================
RCS file: pkg/README
diff -N pkg/README
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pkg/README	11 Oct 2025 06:27:07 -0000
@@ -0,0 +1,29 @@
++-------------------------------------------------------------------------------
+| Running ${PKGSTEM} on OpenBSD
++-------------------------------------------------------------------------------
+
+On OpenBSD, dmidecode falls back to scanning /dev/mem for the SMBIOS
+Entry Point.
+
+By default, only the 'Legacy BIOS' region starting at 0xF0000 is
+scanned.
+
+On legacy-free systems, this region may not contain SMBIOS information,
+leading to a failure to find the correct Entry Point.
+
+The kernel-detected SMBIOS Entry Point can be shown by:
+
+$ grep bios /var/run/dmesg.boot
+
+and passed to dmidecode using the -m/--mem-base command-line option:
+
+$ doas dmidecode -m 0xa4df8000
+
+The sysctl kern.allowkmem=1 needs to be set to allow access to
+/dev/mem.
+
+The package builds on aarch64 but for !x86 it requires code to
+lookup the entry point from EFI, and only FreeBSD/Linux implementations
+are present.
+
+On OpenBSD, the -S/--no-sysfs option has been  enabled by default.
