Logging API
-
enumlog_level_t
Log levels supported, ranging from most to least important
Constants
LOGL_EMERGU-Boot is unstable
LOGL_ALERTAction must be taken immediately
LOGL_CRITCritical conditions
LOGL_ERRError that prevents something from working
LOGL_WARNINGWarning may prevent optimal operation
LOGL_NOTICENormal but significant condition, printf()
LOGL_INFOGeneral information message
LOGL_DEBUGBasic debug-level message
LOGL_DEBUG_CONTENTDebug message showing full message content
LOGL_DEBUG_IODebug message showing hardware I/O access
LOGL_COUNTTotal number of valid log levels
LOGL_NONEUsed to indicate that there is no valid log level
LOGL_LEVEL_MASKMask for valid log levels
LOGL_FORCE_DEBUGMask to force output due to LOG_DEBUG
LOGL_FIRSTThe first, most-important log level
LOGL_MAXThe last, least-important log level
LOGL_CONTUse same log level as in previous call
-
enumlog_category_t
Log categories supported.
Constants
LOGC_FIRSTFirst log category
LOGC_NONEDefault log category
LOGC_ARCHRelated to arch-specific code
LOGC_BOARDRelated to board-specific code
LOGC_CORERelated to core features (non-driver-model)
LOGC_DMCore driver-model
LOGC_DTDevice-tree
LOGC_EFIEFI implementation
LOGC_ALLOCMemory allocation
LOGC_SANDBOXRelated to the sandbox board
LOGC_BLOBLISTBloblist
LOGC_DEVRESDevice resources (
devres_...functions)LOGC_ACPIAdvanced Configuration and Power Interface (ACPI)
LOGC_BOOTRelated to boot process / boot image processing
LOGC_EVENTRelated to event and event handling
LOGC_FSRelated to filesystems
LOGC_EXPORelated to expo handling
LOGC_CONSOLERelated to the console and stdio
LOGC_TESTRelated to testing
LOGC_COUNTNumber of log categories
LOGC_ENDSentinel value for lists of log categories
LOGC_CONTUse same category as in previous call
Description
Log categories between LOGC_FIRST and LOGC_NONE correspond to uclasses
(i.e. enum uclass_id), but there are also some more generic categories.
Remember to update log_cat_name[] after adding a new category.
-
int_log(enumlog_category_t cat, enumlog_level_t level, constchar*file, intline, constchar*func, constchar*fmt, ...)
Internal function to emit a new log record
Parameters
enum log_category_t catCategory of log record (indicating which subsystem generated it)
enum log_level_t levelLevel of log record (indicating its severity)
const char *fileFile name of file where log record was generated
int lineLine number in file where log record was generated
const char *funcFunction where log record was generated, NULL if not known
const char *fmtprintf() format string for log record
...Optional parameters, according to the format string fmt
Return
0 if log record was emitted, -ve on error
-
int_log_buffer(enumlog_category_t cat, enumlog_level_t level, constchar*file, intline, constchar*func, ulongaddr, constvoid*data, uintwidth, uintcount, uintlinelen)
Internal function to print data buffer in hex and ascii form
Parameters
enum log_category_t catCategory of log record (indicating which subsystem generated it)
enum log_level_t levelLevel of log record (indicating its severity)
const char *fileFile name of file where log record was generated
int lineLine number in file where log record was generated
const char *funcFunction where log record was generated, NULL if not known
ulong addrStarting address to display at start of line
const void *datapointer to data buffer
uint widthdata value width. May be 1, 2, or 4.
uint countnumber of values to display
uint linelenNumber of values to print per line; specify 0 for default length
-
assert
assert (x)
assert expression is true
Parameters
xexpression to test
Description
If the expression x evaluates to false and _DEBUG evaluates to true, a panic message is written and the system stalls. The value of _DEBUG is set to true if DEBUG is defined before including common.h.
The expression x is always executed irrespective of the value of _DEBUG.
-
structlog_rec
a single log record
Definition
struct log_rec {
enum log_category_t cat;
enum log_level_t level;
u16 line;
u8 flags;
const char *file;
const char *func;
const char *msg;
};
Members
catCategory, representing a uclass or part of U-Boot
levelSeverity level, less severe is higher
lineLine number where the log record was generated
flagsFlags for log record (enum log_rec_flags)
fileName of file where the log record was generated (not allocated)
funcFunction where the log record was generated (not allocated)
msgLog message (allocated)
Description
Holds information about a single record in the log
Members marked as ‘not allocated’ are stored as pointers and the caller is responsible for making sure that the data pointed to is not overwritten. Members marked as ‘allocated’ are allocated (e.g. via strdup()) by the log system.
TODO(sjg**chromium.org**): Compress this struct down a bit to reduce space, e.g. a single u32 for cat, level, line and force_debug
-
structlog_driver
a driver which accepts and processes log records
Definition
struct log_driver {
const char *name;
int (*emit)(struct log_device *ldev, struct log_rec *rec);
unsigned short flags;
};
Members
nameName of driver
emitemit a log record
Called by the log system to pass a log record to a particular driver for processing. The filter is checked before calling this function.
flagsInitial value for flags (use LOGDF_ENABLE to enable on start-up)
-
structlog_device
an instance of a log driver
Definition
struct log_device {
unsigned short next_filter_num;
unsigned short flags;
struct log_driver *drv;
struct list_head filter_head;
struct list_head sibling_node;
};
Members
next_filter_numSequence number of next filter filter added (0=no filters yet). This increments with each new filter on the device, but never decrements
flagsFlags for this filter (enum log_device_flags)
drvPointer to driver for this device
filter_headList of filters for this device
sibling_nodeNext device in the list of all devices
Description
Since drivers are set up at build-time we need to have a separate device for the run-time aspects of drivers (currently just a list of filters to apply to records send to this device).
-
enumlog_filter_flags
Flags which modify a filter
Constants
LOGFF_HAS_CATFilter has a category list
LOGFF_DENYFilter denies matching messages
LOGFF_LEVEL_MINFilter’s level is a minimum, not a maximum
-
structlog_filter
criteria to filter out log messages
Definition
struct log_filter {
int filter_num;
int flags;
enum log_category_t cat_list[LOGF_MAX_CATEGORIES];
enum log_level_t level;
const char *file_list;
const char *func_list;
struct list_head sibling_node;
};
Members
filter_numSequence number of this filter. This is returned when adding a new filter, and must be provided when removing a previously added filter.
flagsFlags for this filter (
LOGFF_...)cat_listList of categories to allow (terminated by
LOGC_END). If empty then all categories are permitted. Up toLOGF_MAX_CATEGORIESentries can be providedlevelMaximum (or minimum, if
LOGFF_MIN_LEVEL) log level to allowfile_listList of files to allow, separated by comma. If NULL then all files are permitted
func_listComma separated list of functions or NULL.
sibling_nodeNext filter in the list of filters for this log device
Description
If a message matches all criteria, then it is allowed. If LOGFF_DENY is set, then it is denied instead.
-
constchar*log_get_cat_name(enumlog_category_t cat)
Get the name of a category
Parameters
enum log_category_t catCategory to look up
Return
- category name (which may be a uclass driver name) if found, or
"<invalid>" if invalid, or "<missing>" if not found. All error responses begin with ‘<’.
-
enumlog_category_t log_get_cat_by_name(constchar*name)
Look up a category by name
Parameters
const char *nameName to look up
Return
Category, or LOGC_NONE if not found
-
constchar*log_get_level_name(enumlog_level_t level)
Get the name of a log level
Parameters
enum log_level_t levelLog level to look up
Return
Log level name (in ALL CAPS)
-
enumlog_level_t log_get_level_by_name(constchar*name)
Look up a log level by name
Parameters
const char *nameName to look up
Return
Log level, or LOGL_NONE if not found
-
structlog_device *log_device_find_by_name(constchar*drv_name)
Look up a log device by its driver’s name
Parameters
const char *drv_nameName of the driver
Return
the log device, or NULL if not found
-
boollog_has_cat(enumlog_category_t cat_list[], enumlog_category_t cat)
check if a log category exists within a list
Parameters
enum log_category_t cat_list[]List of categories to check, at most
LOGF_MAX_CATEGORIESentries long, terminated byLC_ENDif fewerenum log_category_t catCategory to search for
Return
true if cat is in cat_list, else false
-
intlog_add_filter_flags(constchar*drv_name, enumlog_category_t cat_list[], enumlog_level_t level, constchar*file_list, constchar*func_list, intflags)
Add a new filter to a log device, specifying flags
Parameters
const char *drv_nameDriver name to add the filter to (since each driver only has a single device)
enum log_category_t cat_list[]List of categories to allow (terminated by
LOGC_END). If empty then all categories are permitted. Up toLOGF_MAX_CATEGORIESentries can be providedenum log_level_t levelMaximum (or minimum, if
LOGFF_LEVEL_MIN) log level to allowconst char *file_listList of files to allow, separated by comma. If NULL then all files are permitted
const char *func_listComma separated list of functions or NULL.
int flagsFlags for this filter (
LOGFF_...)
Return
the sequence number of the new filter (>=0) if the filter was added, or a -ve value on error
-
intlog_add_filter(constchar*drv_name, enumlog_category_t cat_list[], enumlog_level_t max_level, constchar*file_list)
Add a new filter to a log device
Parameters
const char *drv_nameDriver name to add the filter to (since each driver only has a single device)
enum log_category_t cat_list[]List of categories to allow (terminated by
LOGC_END). If empty then all categories are permitted. Up toLOGF_MAX_CATEGORIESentries can be providedenum log_level_t max_levelMaximum log level to allow
const char *file_listList of files to allow, separated by comma. If
NULLthen all files are permitted
Return
the sequence number of the new filter (>=0) if the filter was added, or a -ve value on error
-
intlog_remove_filter(constchar*drv_name, intfilter_num)
Remove a filter from a log device
Parameters
const char *drv_nameDriver name to remove the filter from (since each driver only has a single device)
int filter_numFilter number to remove (as returned by log_add_filter())
Return
0 if the filter was removed, -
ENOENTif either the driver or the filter number was not found
-
intlog_device_set_enable(structlog_driver *drv, boolenable)
Enable or disable a log device
Parameters
struct log_driver *drvDriver of device to enable
bool enabletrue to enable, false to disable
Description
Devices are referenced by their driver, so use LOG_GET_DRIVER(name) to pass the driver to this function. For example if the driver is declared with LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here.
Return
0 if OK, -ENOENT if the driver was not found
-
intlog_init(void)
Set up the log system ready for use
Parameters
voidno arguments
Return
0 if OK, -ENOMEM if out of memory
-
intlog_get_default_format(void)
get default log format
Parameters
voidno arguments
Description
The default log format is configurable via
CONFIG_LOGF_FILE, CONFIG_LOGF_LINE, and CONFIG_LOGF_FUNC.
Return
default log format
-
voidlog_fixup_for_gd_move(structglobal_data *new_gd)
Handle global_data moving to a new place
Parameters
struct global_data *new_gdPointer to the new global data
Description
The log_head list is part of global_data. Due to the way lists work, moving the list will cause it to become invalid. This function fixes that up so that the log_head list will work correctly.