From 54e5627a269dddcd00fd1476f7dee62c5b207a52 Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Sat, 20 Jun 2020 01:44:25 +0200 Subject: [PATCH 1/2] Add support for FreeBSD's libusb reimplementation FreeBSD reimplemented the libusb API, but their implementation of libusb_set_debug() expects an enum libusb_debug_level instead of an enum libusb_log_level. This causes excessive logging on FreeBSD drowning out all expected output. To keep the changes to other platforms minimal the FreeBSD specific code is kept inside an ifdef block and the enum values are recreated as magic numbers just like the log levels for other platforms. --- src/stlink-lib/logging.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/stlink-lib/logging.c b/src/stlink-lib/logging.c index a5eef9e17..744f1759d 100644 --- a/src/stlink-lib/logging.c +++ b/src/stlink-lib/logging.c @@ -66,12 +66,25 @@ int ugly_log(int level, const char *tag, const char *format, ...) { * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr */ int ugly_libusb_log_level(enum ugly_loglevel v) { +#if __FreeBSD__ + // FreeBSD includes its own reimplementation of libusb. + // Its libusb_set_debug() function expects a lib_debug_level + // instead of a lib_log_level and is verbose enough to drown out + // all other output. switch (v) { - case UDEBUG: return(4); - case UINFO: return(3); - case UWARN: return(2); - case UERROR: return(1); + case UDEBUG: return (3); // LIBUSB_DEBUG_FUNCTION + LIBUSB_DEBUG_TRANSFER + case UINFO: return (1); // LIBUSB_DEBUG_FUNCTION only + case UWARN: return (0); // LIBUSB_DEBUG_NO + case UERROR: return (0); // LIBUSB_DEBUG_NO } - - return(2); + return (0); +#else + switch (v) { + case UDEBUG: return (4); + case UINFO: return (3); + case UWARN: return (2); + case UERROR: return (1); + } + return (2); +#endif } From ff263131cf0d00657c308402762cdd591d313d5e Mon Sep 17 00:00:00 2001 From: Jan Bramkamp Date: Sun, 21 Jun 2020 16:40:51 +0200 Subject: [PATCH 2/2] Use #ifdef instead of #if --- src/stlink-lib/logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stlink-lib/logging.c b/src/stlink-lib/logging.c index 744f1759d..ce0a2baab 100644 --- a/src/stlink-lib/logging.c +++ b/src/stlink-lib/logging.c @@ -66,7 +66,7 @@ int ugly_log(int level, const char *tag, const char *format, ...) { * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr */ int ugly_libusb_log_level(enum ugly_loglevel v) { -#if __FreeBSD__ +#ifdef __FreeBSD__ // FreeBSD includes its own reimplementation of libusb. // Its libusb_set_debug() function expects a lib_debug_level // instead of a lib_log_level and is verbose enough to drown out