- 了解uboot log
1.Logging information
1.1.Logging levels
There are a number logging levels available, in increasing order of verbosity:
- LOGL_EMERG - Printed before U-Boot halts
- LOGL_ALERT - Indicates action must be taken immediate or U-Boot will crash
- LOGL_CRIT - Indicates a critical error that will cause boot failure
- LOGL_ERR - Indicates an error that may cause boot failure
- LOGL_WARNING - Warning about an unexpected condition
- LOGL_NOTE - Important information about progress
- LOGL_INFO - Information about normal boot progress
- LOGL_DEBUG - Debug information (useful for debugging a driver or subsystem)
- LOGL_DEBUG_CONTENT - Debug message showing full message content
- LOGL_DEBUG_IO - Debug message showing hardware I/O access
1.2.Logging category
Logging can come from a wide variety of places within U-Boot. Each log message has a category which is intended to allow messages to be filtered according to their source.The following main categories are defined:
- LOGC_NONE - Unknown category (e.g. a debug() statement)
- UCLASS_… - Related to a particular uclass (e.g. UCLASS_USB)
- LOGC_ARCH - Related to architecture-specific code
- LOGC_BOARD - Related to board-specific code
- LOGC_CORE - Related to core driver-model support
- LOGC_DT - Related to device tree control
- LOGC_EFI - Related to EFI implementation
1.3.Log format
You can control the log format using the ‘log format’ command. The basic
format is:
LEVEL.category,file.c:123-func() message
In the above, file.c:123 is the filename where the log record was generated and func() is the function name. By default (‘log format default’) only the function name and message are displayed on the console. You can control which fields are present, but not the field order.
1.4.Convenience functions
A number of convenience functions are available to shorten the code needed
for logging:
- log_err(_fmt…)
- log_warning(_fmt…)
- log_notice(_fmt…)
- log_info(_fmt…)
- log_debug(_fmt…)
- log_content(_fmt…)
- log_io(_fmt…)
2.Macro definitions
2.1.Relevant configuration
- CONFIG_LOGLEVEL = 4
common/Kconfig:
300 config LOGLEVEL
301 int "loglevel"
302 default 4
303 range 0 8
304 help
305 All Messages with a loglevel smaller than the console loglevel will
306 be compiled in. The loglevels are defined as follows:
307
308 0 - emergency
309 1 - alert
310 2 - critical
311 3 - error
312 4 - warning
313 5 - note
314 6 - info
315 7 - debug
316 8 - debug content
317 9 - debug hardware I/O
- CONFIG_LOG=y
470 config LOG
471 bool "Enable logging support"
472 depends on DM
473 help
474 This enables support for logging of status and debug messages. These
475 can be displayed on the console, recorded in a memory buffer, or
476 discarded if not needed. Logging supports various categories and
477 levels of severity.
- CONFIG_ LOG_MAX_LEVEL=5
497 config LOG_MAX_LEVEL
498 int "Maximum log level to record"
499 depends on LOG
500 default 5
501 help
502 This selects the maximum log level that will be recorded. Any value
503 higher than this will be ignored. If possible log statements below
504 this level will be discarded at build time. Levels:
505
506 0 - emergency
507 1 - alert
508 2 - critical
509 3 - error
510 4 - warning
511 5 - note
512 6 - info
513 7 - debug
514 8 - debug content
515 9 - debug hardware I/O
- CONFIG_ LOG_DEFAULT_LEVEL=y
557 config LOG_DEFAULT_LEVEL
558 int "Default logging level to display"
559 default 6
560 help
561 This is the default logging level set when U-Boot starts. It can
562 be adjusted later using the 'log level' command. Note that setting
563 this to a value above LOG_MAX_LEVEL will be ineffective, since the
564 higher levels are not compiled in to U-Boot.
565
566 0 - emergency
567 1 - alert
568 2 - critical
569 3 - error
570 4 - warning
571 5 - note
572 6 - info
573 7 - debug
574 8 - debug content
575 9 - debug hardware I/O
- CONFIG_LOG_CONSOLE=y (默认编译:default y)
577 config LOG_CONSOLE
578 bool "Allow log output to the console"
579 depends on LOG
580 default y
581 help
582 Enables a log driver which writes log records to the console.
583 Generally the console is the serial port or LCD display. Only the
584 log message is shown - other details like level, category, file and
585 line number are omitted.
2.2.Enabling logging
The following options are used to enable logging at compile time:
- CONFIG_LOG - Enables the logging system
- CONFIG_LOG_MAX_LEVEL - Max log level to build (anything higher is compiled out)
- CONFIG_LOG_CONSOLE - Enable writing log records to the console
3.结构体
3.1.enum log_fmt:
include/log.h:
352 /* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */
353 enum log_fmt {
354 LOGF_CAT = 0,
355 LOGF_LEVEL,
356 LOGF_FILE,
357 LOGF_LINE,
358 LOGF_FUNC,
359 LOGF_MSG,
360
361 LOGF_COUNT,
362 LOGF_DEFAULT = (1 << LOGF_FUNC) | (1 << LOGF_MSG),
363 LOGF_ALL = 0x3f,
364 };
3.2.enum log_level_t:
16 enum log_level_t {
17 LOGL_EMERG = 0, /* U-Boot is unstable */
18 LOGL_ALERT, /* Action must be taken immediately */
19 LOGL_CRIT, /* Critical conditions */
20 LOGL_ERR, /* Error that prevents something from working */
21 LOGL_WARNING, /* Warning may prevent optimial operation */
22 LOGL_NOTICE, /* Normal but significant condition, printf() */
23 LOGL_INFO, /* General information message */
24 LOGL_DEBUG, /* Basic debug-level message */
25 LOGL_DEBUG_CONTENT, /* Debug message showing full message content */
26 LOGL_DEBUG_IO, /* Debug message showing hardware I/O access */
27
28 LOGL_COUNT,
29 LOGL_NONE,
30
31 LOGL_FIRST = LOGL_EMERG,
32 LOGL_MAX = LOGL_DEBUG_IO,
33 };
4.代码分析
4.1.log初始化
全局变量gd定义log变量:
124 #ifdef CONFIG_LOG
125 int log_drop_count; /* Number of dropped log messages */
126 int default_log_level; /* For devices with no filters */
127 struct list_head log_head; /* List of struct log_device */
128 int log_fmt; /* Mask containing log format info */
129 #endif
SPL和uboot 都进行log初始化,如下所示:
- SPL:spl_common_init()->log_init() (common/spl/spl.c)
- Uboot:
- log_init (common/board_f.c)
- log_init(common/board_r.c )
设置log level:
gd->default_log_level = CONFIG_LOG_DEFAULT_LEVEL;
gd->log_fmt = LOGF_DEFAULT;
5.Debug
=> log
log - log system
Usage:
log level - get/set log level
log test - run log tests
log format <fmt> - set log output format. <fmt> is a string where
each letter indicates something that should be displayed:
c=category, l=level, F=file, L=line number, f=function, m=msg
or 'default', equivalent to 'fm', or 'all' for all
log rec <category> <level> <file> <line> <func> <message> - output a log record