From 0d4614777b59150f493d65087b838284ac9c1e70 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Fri, 12 Aug 2022 13:07:51 +1000 Subject: flashrom.c: Move print logic to print.c This free's up flashrom.c from namespace pollution. BUG=b:242246291 TEST=builds Change-Id: I2724f7910fa3e01bcf49b8093260a4f1643df777 Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/66652 Tested-by: build bot (Jenkins) Reviewed-by: Thomas Heijligen --- print.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'print.c') diff --git a/print.c b/print.c index 8d55b8b7..9883c826 100644 --- a/print.c +++ b/print.c @@ -20,6 +20,15 @@ #include #include #include +#if HAVE_UTSNAME == 1 +#include +#endif +#if IS_WINDOWS +#include +#undef min +#undef max +#endif + #include "flash.h" #include "programmer.h" @@ -505,6 +514,86 @@ int print_supported(void) return 0; } +static void print_sysinfo(void) +{ +#if IS_WINDOWS + SYSTEM_INFO si = { 0 }; + OSVERSIONINFOEX osvi = { 0 }; + + msg_ginfo(" on Windows"); + /* Tell Windows which version of the structure we want. */ + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + if (GetVersionEx((OSVERSIONINFO*) &osvi)) + msg_ginfo(" %lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion); + else + msg_ginfo(" unknown version"); + GetSystemInfo(&si); + switch (si.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + msg_ginfo(" (x86_64)"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + msg_ginfo(" (x86)"); + break; + default: + msg_ginfo(" (unknown arch)"); + break; + } +#elif 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 +} + +void print_buildinfo(void) +{ + msg_gdbg("flashrom was built with"); +#ifdef __clang__ + msg_gdbg(" LLVM Clang"); +#ifdef __clang_version__ + msg_gdbg(" %s,", __clang_version__); +#else + msg_gdbg(" unknown version (before r102686),"); +#endif +#elif defined(__GNUC__) + msg_gdbg(" GCC"); +#ifdef __VERSION__ + msg_gdbg(" %s,", __VERSION__); +#else + msg_gdbg(" unknown version,"); +#endif +#else + msg_gdbg(" unknown compiler,"); +#endif +#if defined (__FLASHROM_LITTLE_ENDIAN__) + msg_gdbg(" little endian"); +#elif defined (__FLASHROM_BIG_ENDIAN__) + msg_gdbg(" big endian"); +#else +#error Endianness could not be determined +#endif + msg_gdbg("\n"); +} + +void print_version(void) +{ + msg_ginfo("flashrom %s", flashrom_version); + print_sysinfo(); + msg_ginfo("\n"); +} + +void print_banner(void) +{ + msg_ginfo("flashrom is free software, get the source code at " + "https://flashrom.org\n"); + msg_ginfo("\n"); +} + #if CONFIG_INTERNAL == 1 #ifdef CONFIG_PRINT_WIKI -- cgit v1.2.3