New version: Improve reliability of utsname detection.
Add runtime and build environment info to the flashrom version message. This patch uses code from Idwer Vollering and Maciej Pijanka. I've added Makefile support and compiler version printing and restructured the code heavily. The code prints runtime system information and buildtime libpci information (I couldn't find any runtime libpci version function). Due to our ability to cross-compile flashrom, buildtime system information from "uname -mrs" doesn't help diagnosing any problems. That's why only libpci and gcc are buildtime info, and the rest is runtime info.
Examples: With PCI support: flashrom v0.9.1-r971 on Linux 2.6.22.19-0.2-default (i686), built with libpci 2.2.6, GCC 4.2.1 (SUSE Linux) flashrom v0.9.1-r971 on Linux 2.6.22.19-0.2-default (i686), built with libpci 2.2.6, LLVM 1/clang 1 flashrom v0.9.1-r972 on Linux 2.6.27.29-0.1-default (x86_64), built with libpci 3.0.1, GCC 4.3.2 [gcc-4_3-branch revision 141291]
Without PCI support: flashrom v0.9.1-r971 on Linux 2.6.22.19-0.2-default (i686), built with GCC 4.2.1 (SUSE Linux) flashrom v0.9.1-r971 on Linux 2.6.22.19-0.2-default (i686), built with LLVM 1/clang 1 flashrom v0.9.1-r972 on Linux 2.6.27.29-0.1-default (x86_64), built with GCC 4.3.2 [gcc-4_3-branch revision 141291]
Reviews appreciated, especially about the compiler part. I think this can be valuable (e.g. if someone compiles with clang and triggers the clang/flashrom miscompile), but I'm unsure if/how this works on Windows and DOS. I tried to make it non-explosive, but...
Output from "flashrom --version" for non-Linux platforms and unusual compilers would be appreciated.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-uname/Makefile =================================================================== --- flashrom-uname/Makefile (Revision 971) +++ flashrom-uname/Makefile (Arbeitskopie) @@ -230,6 +230,8 @@ CLI_OBJS += print_wiki.o endif
+FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "UTSNAME := yes" .features && printf "%s" "-D'HAVE_UTSNAME=1'") + # We could use PULLED_IN_LIBS, but that would be ugly. FEATURE_LIBS += $(shell LC_ALL=C grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
@@ -308,12 +310,29 @@ @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest $(FTDILIBS) $(LIBS) >/dev/null 2>&1 && \ ( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) || \ ( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp ) + @printf "Checking for utsname support... " + @$(shell ( echo "#include <sys/utsname.h>"; \ + echo "struct utsname osinfo;"; \ + echo "int main(int argc, char **argv)"; \ + echo "{ uname (&osinfo); return 0; }"; ) > .featuretest.c ) + @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest >/dev/null 2>&1 && \ + ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \ + ( echo "not found."; echo "UTSNAME := no" >> .features.tmp ) @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features @rm -f .featuretest.c .featuretest else features: compiler @echo "FEATURES := yes" > .features.tmp + @printf "Checking for utsname support... " + @$(shell ( echo "#include <sys/utsname.h>"; \ + echo "struct utsname osinfo;"; \ + echo "int main(int argc, char **argv)"; \ + echo "{ uname (&osinfo); return 0; }"; ) > .featuretest.c ) + @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest >/dev/null 2>&1 && \ + ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \ + ( echo "not found."; echo "UTSNAME := no" >> .features.tmp ) @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features + @rm -f .featuretest.c .featuretest endif
install: $(PROGRAM) Index: flashrom-uname/flashrom.c =================================================================== --- flashrom-uname/flashrom.c (Revision 971) +++ flashrom-uname/flashrom.c (Arbeitskopie) @@ -27,6 +27,9 @@ #include <string.h> #include <stdlib.h> #include <getopt.h> +#if HAVE_UTSNAME == 1 +#include <sys/utsname.h> +#endif #include "flash.h" #include "flashchips.h"
@@ -1133,9 +1136,44 @@ printf("\n"); }
+void print_sysinfo(void) +{ +#if HAVE_UTSNAME == 1 + struct utsname osinfo; + uname(&osinfo); + + msg_ginfo(" on %s %s (%s)", osinfo.sysname, osinfo.release, + osinfo.machine); +#else + msg_ginfo(" on unknown machine"); +#endif + msg_ginfo(", built with"); +#if NEED_PCI == 1 +#ifdef PCILIB_VERSION + msg_ginfo(" libpci %s,", PCILIB_VERSION); +#else + msg_ginfo(" unknown PCI library,"); +#endif +#endif +#ifdef __clang__ + msg_ginfo(" LLVM %i/clang %i", __llvm__, __clang__); +#elif defined(__GNUC__) + msg_ginfo(" GCC"); +#ifdef __VERSION__ + msg_ginfo(" %s", __VERSION__); +#else + msg_ginfo(" unknown version"); +#endif +#else + msg_ginfo(" unknown compiler"); +#endif + msg_ginfo("\n"); +} + void print_version(void) { - printf("flashrom v%s\n", flashrom_version); + printf("flashrom v%s", flashrom_version); + print_sysinfo(); }
int selfcheck(void)