cavaliercoder / dmidecode-osx Goto Github PK
View Code? Open in Web Editor NEWAn OS X native port of dmidecode
Home Page: http://cavaliercoder.com/blog/dmidecode-for-apple-osx.html
License: GNU General Public License v2.0
An OS X native port of dmidecode
Home Page: http://cavaliercoder.com/blog/dmidecode-for-apple-osx.html
License: GNU General Public License v2.0
** INTRODUCTION ** Dmidecode reports information about your system's hardware as described in your system BIOS according to the SMBIOS/DMI standard. This information typically includes system manufacturer, model name, serial number, BIOS version, asset tag as well as a lot of other details of varying level of interest and reliability depending on the manufacturer. This will often include usage status for the CPU sockets, expansion slots (e.g. AGP, PCI, ISA) and memory module slots, and the list of I/O ports (e.g. serial, parallel, USB). DMI data can be used to enable or disable specific portions of kernel code depending on the specific hardware. Thus, one use of dmidecode is for kernel developers to detect system "signatures" and add them to the kernel source code when needed. Beware that DMI data have proven to be too unreliable to be blindly trusted. Dmidecode does not scan your hardware, it only reports what the BIOS told it to. ** INSTALLATION ** The home web page for dmidecode is hosted on Savannah: http://www.nongnu.org/dmidecode/ You will find the latest version (including CVS) there, as well as fresh news and other interesting material, such as a list of related projects and articles. This program was first written for Linux, and has since been reported to work on FreeBSD, NetBSD, OpenBSD, BeOS and Solaris as well. There's no configure script, so simply run "make" to build dmidecode, and "make install" to install it. You also can use "make uninstall" to remove all the files you installed. By default, files are installed in /usr/local but you can change this behavior by editing the Makefile file and setting prefix to wherever you want. You may change the C compiler and the compilation flags as well. Optionally, you can run "make strip" prior to "make install" if you want smaller binaries. However, be aware that this will prevent any further attempt to debug the programs. Two parameters can be set in the Makefile file to make dmidecode work on non-i386 systems. They should be used if your system uses the big endian byte ordering (Motorola) or doesn't support unaligned memory accesses, respectively. For example, compiling for a SPARC processor would require both (but I am not aware of SPARC-based systems implementing SMBIOS). Compiling for an IA64 processor requires the memory alignment workaround, and it is enabled automatically. ** DOCUMENTATION ** Each tool has a manual page, found in the "man" subdirectory. Manual pages are installed by "make install". See these manual pages for command line interface details and tool specific information. For an history of the changes made to dmidecode, see the CHANGELOG file. If you need help, your best chances are to visit the web page (see the INSTALLATION section above) or to get in touch with the developers directly. Have a look at the AUTHORS file and contact one of the maintainers. If you want to help with the development of dmidecode, please consider joining the dmidecode-devel discussion list: http://lists.nongnu.org/mailman/listinfo/dmidecode-devel ** COMMON PROBLEMS ** IA-64 Non-Linux systems are not yet supported. MMAP Note that mmap() is now used by default wherever possible, since this seems to solve a number of problems. This default behavior can be changed in config.h. Just to make sure this is clear, mmap() is not used for performance reasons but to increase the number of systems on which dmidecode can be successfully run. CYGWIN Dmidecode used to work under Cygwin. However the /dev/mem interface was removed at some point in time so it no longer works. ** MISCELLANEOUS TOOLS ** Three other tools come along with dmidecode: biosdecode, ownership and vpddecode. These tools are only useful on systems with a BIOS, so they are not built on IA-64 by default. BIOSDECODE This one prints all BIOS related information it can find in /dev/mem. It used to be part of dmidecode itself, but as dmidecode was growing, we felt that the non-DMI part had to be moved to a separate tool. OWNERSHIP This tool was written on a request by Luc Van de Velde for use with Novell tools in his company. It retrieves the "ownership tag" that can be set on most Compaq computers. Since it uses the same mechanisms dmidecode and biosdecode use, and could be of some use for other people as well, we decided to make it part of the project. VPDDECODE This tool prints the contents of the "vital product data" structure as found in most IBM and Lenovo computers. It used to have a lookup table for the machine name, but it was unreliable and hard to maintain so it was ultimately dropped. It has a command line interface.
dmidecode
Getting SMBIOS data from Apple SMBIOS service.
SMBIOS 2.4 present.
61 structures occupying 2888 bytes.
Trace/BPT trap: 5
No way to get any further, any ideas?
dmidecode v3.1 was recently released and should be merged down.
Doesn't seem to work on mini M1 (2020). Suggestions? MacOSX 11.2.
% sudo ./dmidecode
Password:
Getting SMBIOS data from Apple SMBIOS service.
AppleSMBIOS service is unreachable, sorry.%
%
% uname -ar
Darwin srl-minim1.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64
dmidecode compiled with -O0 -g3 on a Mid-2010 Mac Mini, MacOS 10.13.6. I am not really a Mac person and I'm at a loss as to how to proceed:
bash-3.2# gmake dmidecode
gcc -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -D_FILE_OFFSET_BITS=64 -O0 -g3 -Wno-constant-logical-operand -c dmidecode.c -o dmidecode.o
gcc -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -D_FILE_OFFSET_BITS=64 -O0 -g3 -Wno-constant-logical-operand -c dmiopt.c -o dmiopt.o
gcc -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -D_FILE_OFFSET_BITS=64 -O0 -g3 -Wno-constant-logical-operand -c dmioem.c -o dmioem.o
gcc -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -D_FILE_OFFSET_BITS=64 -O0 -g3 -Wno-constant-logical-operand -c util.c -o util.o
gcc -framework CoreServices -framework IOKit dmidecode.o dmiopt.o dmioem.o util.o -o dmidecode
bash-3.2# ./dmidecode
Getting SMBIOS data from Apple SMBIOS service.
SMBIOS 2.4 present.
44 structures occupying 1946 bytes.
Bad address
Illegal instruction: 4
bash-3.2# gdb ./dmidecode
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...unable to read unknown load command 0x80000028
Reading symbols for shared libraries ..... done
unable to read unknown load command 0x80000028
(gdb) run
Starting program: /usr/local/src/dmidecode-osx/dmidecode
Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
On http://cavaliercoder.com/blog/dmidecode-for-apple-osx.html, it says
make && make install
will install to /usr/local/bin/
, but the actual install location is /usr/local/sbin/
because the makefile uses $(prefix)/sbin
.
Clang just pointed out this to me:
dmidecode.c:4514:26: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
DWORD(data + 0x0A) && 0xFF);
^ ~~~~
dmidecode.c:4514:26: note: use '&' for a bitwise operation
DWORD(data + 0x0A) && 0xFF);
^~
&
dmidecode.c:4514:26: note: remove constant to silence this warning
DWORD(data + 0x0A) && 0xFF);
~^~~~~~~
2 warnings generated.
Looking at the code:
printf("\tFirmware Revision: %u.%u\n",
DWORD(data + 0x0A) >> 16,
DWORD(data + 0x0A) && 0xFF);
I think that clang is right, a bitwise AND is intended here.
When running on macOS Ventura I get the following assertion failure:
Getting SMBIOS data from Apple SMBIOS service.
Assertion failed: (range.location + range.length <= dataLength), function __CFDataValidateRange, file CFData.c, line 235.
zsh: abort dmidecode
Tracing this back the root cause was the CFDataRef was 31 bytes instead of 32. Viewing the apple documentation the correct fix is it should use the CFDataGetLength call to get the actual size rather than hardcoding it. I also had to add an ifdef to remove the Problematic CFRelease(properties) as per the comments. I believe this should be a compile option for the Makefile, as I don't need a signed binary. Here is a diff of my version:
diff --git a/dmidecode.c b/dmidecode.c
index bb651da..194108c 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -4811,8 +4811,10 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
* This CFRelease throws 'Segmentation fault: 11' since macOS 10.12, if
* the compiled binary is not signed with an Apple developer profile.
*/
+ #ifdef SIGNED_BINARY // So don't do that unless you signed it
if (NULL != properties)
CFRelease(properties);
+ #endif
IOObjectRelease(service);
}
@@ -5147,7 +5149,7 @@ int main(int argc, char * const argv[])
goto exit_free;
}
- CFDataGetBytes(dataRef, CFRangeMake(0, 0x20), (UInt8*)buf);
+ CFDataGetBytes(dataRef, CFRangeMake(0, CFDataGetLength(dataRef)), (UInt8*)buf);
if (NULL != dataRef)
CFRelease(dataRef);
Using ./dmidecode I get about 40 of the 42 structures before getting a:
Invalid entry length (0). DMI table is broken! Stop.
Investigating the raw buffer I discover that the last few entries are separated by multiple pairs of zeros, rather than the expected one pair. To address this oddity I changed:
in dmidecode.c:dmi_table_decode(..)
/* look for the next handle */
next = data + h.length;
while ((unsigned long)(next - buf + 1) < len
&& (next[0] != 0 || next[1] != 0)) {
next++;
}
next+=2;
Replacing the final next+=2 with:
while((unsigned long)(next - buf + 1) < len && (next[0] == 0 && next[1] == 0)) {
next+=2;
}
MacBookAir6,1 - osx 10.11.2
I've attached a zip of '--dump-bin' file so you can try it yourself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.