From 879b02470714766e625cb2d0f46f1e2bc63ef0fe Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 26 Dec 2023 12:28:50 -0700 Subject: [PATCH 1/2] Allow setting log level in config file Add a new Makefile config for controlling the log level instead of having to modify the `LEVEL` cflag directly. Signed-off-by: Tim Crawford --- docs/debugging.md | 18 +++++++++++++----- src/board/system76/common/common.mk | 29 ++++++++++++++++++++++------- src/common/include/common/debug.h | 5 ----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/docs/debugging.md b/docs/debugging.md index 90db7c2aa..fc0e0927c 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -15,11 +15,19 @@ Terms used: ```bash make BOARD=system76/ console_internal ``` -1. If you're not seeing seeing expected output, check the - [`LEVEL` cflag][level_cflag]. This is an EC compile time configuration and - changing will require a build and flash of the EC. - -[level_cflag]: https://github.com/system76/ec/blob/01907011bb63/src/board/system76/common/common.mk#L31-L39 +If you're not seeing seeing expected output, check the value of +`CONFIG_LOG_LEVEL` in `common.mk`. This is an EC compile time configuration +and changing it will require a build and flash of the EC. Supported log levels +are: + +- `none` +- `error` +- `warn` +- `info` +- `debug` +- `trace` + +The default value is `debug` if unspecified. ## Debugging with external device diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index f959d200a..d2fd14268 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -29,13 +29,28 @@ board-common-y += stdio.c board-common-y += wireless.c # Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 +# - none +# - error +# - warn +# - info +# - debug +# - trace +ifeq ($(CONFIG_LOG_LEVEL),none) +CFLAGS += -DLEVEL=0 +else ifeq ($(CONFIG_LOG_LEVEL),error) +CFLAGS += -DLEVEL=1 +else ifeq ($(CONFIG_LOG_LEVEL),warn) +CFLAGS += -DLEVEL=2 +else ifeq ($(CONFIG_LOG_LEVEL),info) +CFLAGS += -DLEVEL=3 +else ifeq ($(CONFIG_LOG_LEVEL),debug) +CFLAGS += -DLEVEL=4 +else ifeq ($(CONFIG_LOG_LEVEL),trace) +CFLAGS += -DLEVEL=5 +else +# XXX: Preserve old behavior of LEVEL always being set to DEBUG. +CFLAGS += -DLEVEL=4 +endif # Uncomment to enable debug logging over keyboard parallel port #CFLAGS+=-DPARALLEL_DEBUG diff --git a/src/common/include/common/debug.h b/src/common/include/common/debug.h index 24912c0cc..603d93e85 100644 --- a/src/common/include/common/debug.h +++ b/src/common/include/common/debug.h @@ -12,11 +12,6 @@ #define LEVEL_ERROR 1 #define LEVEL_NONE 0 -// This is the user-configurable log level -#ifndef LEVEL -#define LEVEL LEVEL_INFO -#endif - #if LEVEL >= LEVEL_TRACE #define TRACE(...) printf(__VA_ARGS__) #else From d61d360a78c481098c39f088fc612c00ed75be58 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Thu, 28 Dec 2023 07:12:31 -0700 Subject: [PATCH 2/2] Add config values to enable debug mechanisms Add new config values to control whether debug logging is enabled over parport or smbus instead of having to modify `CFLAGS` directly. Signed-off-by: Tim Crawford --- docs/debugging.md | 4 ++-- src/board/system76/common/common.mk | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/debugging.md b/docs/debugging.md index fc0e0927c..306f0434f 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -49,7 +49,7 @@ For details on configuring the Mega 2560 and breakout board, see #### Setup 1. Enable parallel port debugging in the EC firmware - - Uncomment `PARALLEL_DEBUG` in `src/board/system76/common/common.mk` + - Set `CONFIG_PARALLEL_DEBUG=y` in `config.mk` - Build and flash the firmware for the target 2. Power off target 3. Remove bottom panel @@ -120,7 +120,7 @@ Requirements: - USB-C cable 1. Enable I2C debugging in the EC firmware for the target - - Uncomment `I2C_DEBUGGER` in `src/board/system76/common/common.mk` + - Set `CONFIG_I2C_DEBUG=y` in `config.mk` - Build and flash firmware 2. Connect Trinket M0 to host - This will create an ACM device at `/dev/ttyACM*` diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index d2fd14268..b5a2aa0af 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -52,11 +52,15 @@ else CFLAGS += -DLEVEL=4 endif -# Uncomment to enable debug logging over keyboard parallel port -#CFLAGS+=-DPARALLEL_DEBUG +ifeq ($(CONFIG_PARALLEL_DEBUG),y) +# Enable debug logging over the keyboard parallel port +CFLAGS += -DPARALLEL_DEBUG=1 +endif -# Uncomment to enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 +ifeq ($(CONFIG_I2C_DEBUG),y) +# Enable debug logging over battery SMBus connection +CFLAGS += -DI2C_DEBUGGER=0x76 +endif ifeq ($(CONFIG_SECURITY),y) CFLAGS+=-DCONFIG_SECURITY=1