While writing a MISC driver, I forgot to enable CONFIG_MISC. The only thing
I got at boot was the following obscure error, with no hint about the root
cause:

  initcall_run_r(): initcall initr_dm() failed
  ### ERROR ### Please RESET the board ###

Commit 3346c87625b8 ("dm: Improve handling of a missing uclass") already
tried to improve this case by returning a strange error code and adding a
debug message. But since neither the debug message nor the return code are
displayed by default, it was not very helpful in practice.

This series improves the situation in a few ways:
 - a new dm_err() helper logs driver model errors at ERROR level, and the
   boolean DM_WARN option becomes a per-stage log verbosity choice
   (DM_NONE / DM_ERR / DM_WARN) with errors emitted by default. Note that
   a disabled level is not removed entirely but degraded to DEBUG level,
   which is compiled out by default, so even DM_NONE can still emit these
   messages as debug output when debug logging is enabled;
 - the missing-uclass message now uses dm_err(), so it shows up by default,
   with a shorter string to limit the code-size overhead;
 - the initcall failure now prints the actual error code (and its string
   when ERRNO_STR is enabled), for both INITCALL() and INITCALL_EVT().

The existing DM_DEBUG option is left as-is for now: it works differently
(it adds -DDEBUG to drivers/core/ via the Makefile and is not phase-aware).
Unifying it into the new choice, along with converting the DM core debug()
statements to log() as suggested in the "To Do" section of
doc/develop/logging.rst, could be a follow-up series.

Signed-off-by: Julien Stephan <[email protected]>
---
Changes in v2:
- dm: replace the boolean DM_WARN option with a per-stage log verbosity
  choice (DM_NONE / DM_ERR / DM_WARN) and add a dm_err() helper, rather
  than logging the missing-uclass message with a hardcoded log() call
  (suggested by Simon)
- dm: de-duplicate the util.h helpers to only select the log level
  (suggested by Simon)
- dm: split the change into the generic mechanism and its user in uclass.c
- dm: shorten the missing-uclass message to limit the SPL/TPL size overhead
- initcall: use the %dE format so no dangling ": " is printed when
  ERRNO_STR is disabled, and give INITCALL_EVT() the same treatment
- Link to v1: 
https://patch.msgid.link/20260806-improve-logging-on-missing-uclass-v1-0-d477f0054...@baylibre.com

To: [email protected]
Cc: GSS_MTK_Uboot_upstream <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: "Markus Schneider-Pargmann (TI)" <[email protected]>
Cc: Julien Stephan <[email protected]>

---
Julien Stephan (3):
      dm: add dm_err() and a driver model log verbosity choice
      dm: uclass: use dm_err() for a missing uclass
      initcall: initcall_evt: display error code on error

 drivers/core/Kconfig  | 75 ++++++++++++++++++++++++++++++++++++++++++---------
 drivers/core/uclass.c |  3 +--
 include/dm/util.h     | 19 +++++++++++--
 include/initcall.h    | 14 +++++-----
 4 files changed, 88 insertions(+), 23 deletions(-)
---
base-commit: f562ed02aa7ae4dc2775d90d2e6c40bab82e2715
change-id: 20260806-improve-logging-on-missing-uclass-a76c46acfa13

Best regards,
--  
Julien Stephan <[email protected]>

Reply via email to