xref: /OK3568_Linux_fs/u-boot/doc/README.log (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunLogging in U-Boot
2*4882a593Smuzhiyun=================
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunIntroduction
5*4882a593Smuzhiyun------------
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunU-Boot's internal operation involves many different steps and actions. From
8*4882a593Smuzhiyunsetting up the board to displaying a start-up screen to loading an Operating
9*4882a593SmuzhiyunSystem, there are many component parts each with many actions.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunMost of the time this internal detail is not useful. Displaying it on the
12*4882a593Smuzhiyunconsole would delay booting (U-Boot's primary purpose) and confuse users.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunBut for digging into what is happening in a particular area, or for debugging
15*4882a593Smuzhiyuna problem it is often useful to see what U-Boot is doing in more detail than
16*4882a593Smuzhiyunis visible from the basic console output.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunU-Boot's logging feature aims to satisfy this goal for both users and
19*4882a593Smuzhiyundevelopers.
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunLogging levels
23*4882a593Smuzhiyun--------------
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunThere are a number logging levels available, in increasing order of verbosity:
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun   LOGL_EMERG	- Printed before U-Boot halts
28*4882a593Smuzhiyun   LOGL_ALERT	- Indicates action must be taken immediate or U-Boot will crash
29*4882a593Smuzhiyun   LOGL_CRIT	- Indicates a critical error that will cause boot failure
30*4882a593Smuzhiyun   LOGL_ERR	- Indicates an error that may cause boot failure
31*4882a593Smuzhiyun   LOGL_WARNING	- Warning about an unexpected condition
32*4882a593Smuzhiyun   LOGL_NOTE	- Important information about progress
33*4882a593Smuzhiyun   LOGL_INFO	- Information about normal boot progress
34*4882a593Smuzhiyun   LOGL_DEBUG	- Debug information (useful for debugging a driver or subsystem)
35*4882a593Smuzhiyun   LOGL_DEBUG_CONTENT	- Debug message showing full message content
36*4882a593Smuzhiyun   LOGL_DEBUG_IO	- Debug message showing hardware I/O access
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunLogging category
40*4882a593Smuzhiyun----------------
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunLogging can come from a wide variety of places within U-Boot. Each log message
43*4882a593Smuzhiyunhas a category which is intended to allow messages to be filtered according to
44*4882a593Smuzhiyuntheir source.
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunThe following main categories are defined:
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun   LOGC_NONE	- Unknown category (e.g. a debug() statement)
49*4882a593Smuzhiyun   UCLASS_...	- Related to a particular uclass (e.g. UCLASS_USB)
50*4882a593Smuzhiyun   LOGC_ARCH	- Related to architecture-specific code
51*4882a593Smuzhiyun   LOGC_BOARD	- Related to board-specific code
52*4882a593Smuzhiyun   LOGC_CORE	- Related to core driver-model support
53*4882a593Smuzhiyun   LOGC_DT	- Related to device tree control
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunEnabling logging
57*4882a593Smuzhiyun----------------
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunThe following options are used to enable logging at compile time:
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun   CONFIG_LOG		- Enables the logging system
62*4882a593Smuzhiyun   CONFIG_MAX_LOG_LEVEL - Max log level to build (anything higher is compiled
63*4882a593Smuzhiyun				out)
64*4882a593Smuzhiyun   CONFIG_LOG_CONSOLE	- Enable writing log records to the console
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunIf CONFIG_LOG is not set, then no logging will be available.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunThe above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunUsing DEBUG
72*4882a593Smuzhiyun-----------
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunU-Boot has traditionally used a #define called DEBUG to enable debugging on a
75*4882a593Smuzhiyunfile-by-file basis. The debug() macro compiles to a printf() statement if
76*4882a593SmuzhiyunDEBUG is enabled, and an empty statement if not.
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunWith logging enabled, debug() statements are interpreted as logging output
79*4882a593Smuzhiyunwith a level of LOGL_DEBUG and a category of LOGC_NONE.
80*4882a593Smuzhiyun
81*4882a593SmuzhiyunThe logging facilities are intended to replace DEBUG, but if DEBUG is defined
82*4882a593Smuzhiyunat the top of a file, then it takes precedence. This means that debug()
83*4882a593Smuzhiyunstatements will result in output to the console and this output will not be
84*4882a593Smuzhiyunlogged.
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunLogging destinations
88*4882a593Smuzhiyun--------------------
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunIf logging information goes nowhere then it serves no purpose. U-Boot provides
91*4882a593Smuzhiyunseveral possible determinations for logging information, all of which can be
92*4882a593Smuzhiyunenabled or disabled independently:
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun   console - goes to stdout
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunFilters
98*4882a593Smuzhiyun-------
99*4882a593Smuzhiyun
100*4882a593SmuzhiyunFilters are attached to log drivers to control what those drivers emit. Only
101*4882a593Smuzhiyunrecords that pass through the filter make it to the driver.
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunFilters can be based on several criteria:
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun   - maximum log level
106*4882a593Smuzhiyun   - in a set of categories
107*4882a593Smuzhiyun   - in a set of files
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunIf no filters are attached to a driver then a default filter is used, which
110*4882a593Smuzhiyunlimits output to records with a level less than CONFIG_LOG_MAX_LEVEL.
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunLogging statements
114*4882a593Smuzhiyun------------------
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunThe main logging function is:
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun   log(category, level, format_string, ...)
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunAlso debug() and error() will generate log records  - these use LOG_CATEGORY
121*4882a593Smuzhiyunas the category, so you should #define this right at the top of the source
122*4882a593Smuzhiyunfile to ensure the category is correct.
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun
125*4882a593SmuzhiyunCode size
126*4882a593Smuzhiyun---------
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunCode size impact depends largely on what is enabled. The following numbers are
129*4882a593Smuzhiyunfor snow, which is a Thumb-2 board:
130*4882a593Smuzhiyun
131*4882a593SmuzhiyunThis series: adds bss +20.0 data +4.0 rodata +4.0 text +44.0
132*4882a593SmuzhiyunCONFIG_LOG: bss -52.0 data +92.0 rodata -635.0 text +1048.0
133*4882a593SmuzhiyunCONFIG_LOG_MAX_LEVEL=7: bss +188.0 data +4.0 rodata +49183.0 text +98124.0
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunThe last option turns every debug() statement into a logging call, which
136*4882a593Smuzhiyunbloats the code hugely. The advantage is that it is then possible to enable
137*4882a593Smuzhiyunall logging within U-Boot.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun
140*4882a593SmuzhiyunTo Do
141*4882a593Smuzhiyun-----
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunThere are lots of useful additions that could be made. None of the below is
144*4882a593Smuzhiyunimplemented! If you do one, please add a test in test/py/tests/test_log.py
145*4882a593Smuzhiyun
146*4882a593SmuzhiyunConvenience functions to support setting the category:
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun   log_arch(level, format_string, ...) - category LOGC_ARCH
149*4882a593Smuzhiyun   log_board(level, format_string, ...) - category LOGC_BOARD
150*4882a593Smuzhiyun   log_core(level, format_string, ...) - category LOGC_CORE
151*4882a593Smuzhiyun   log_dt(level, format_string, ...) - category LOGC_DT
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunConvenience functions to support a category defined for a single file, for
154*4882a593Smuzhiyunexample:
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun   #define LOG_CATEGORY   UCLASS_USB
157*4882a593Smuzhiyun
158*4882a593Smuzhiyunall of these can use LOG_CATEGORY as the category, and a log level
159*4882a593Smuzhiyuncorresponding to the function name:
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun   logc(level, format_string, ...)
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunMore logging destinations:
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun   device - goes to a device (e.g. serial)
166*4882a593Smuzhiyun   buffer - recorded in a memory buffer
167*4882a593Smuzhiyun
168*4882a593SmuzhiyunConvert debug() statements in the code to log() statements
169*4882a593Smuzhiyun
170*4882a593SmuzhiyunSupport making printf() emit log statements a L_INFO level
171*4882a593Smuzhiyun
172*4882a593SmuzhiyunConvert error() statements in the code to log() statements
173*4882a593Smuzhiyun
174*4882a593SmuzhiyunFigure out what to do with BUG(), BUG_ON() and warn_non_spl()
175*4882a593Smuzhiyun
176*4882a593SmuzhiyunFigure out what to do with assert()
177*4882a593Smuzhiyun
178*4882a593SmuzhiyunAdd a way to browse log records
179*4882a593Smuzhiyun
180*4882a593SmuzhiyunAdd a way to record log records for browsing using an external tool
181*4882a593Smuzhiyun
182*4882a593SmuzhiyunAdd commands to add and remove filters
183*4882a593Smuzhiyun
184*4882a593SmuzhiyunAdd commands to add and remove log devices
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunAllow sharing of printf format strings in log records to reduce storage size
187*4882a593Smuzhiyunfor large numbers of log records
188*4882a593Smuzhiyun
189*4882a593SmuzhiyunAdd a command-line option to sandbox to set the default logging level
190*4882a593Smuzhiyun
191*4882a593SmuzhiyunConvert core driver model code to use logging
192*4882a593Smuzhiyun
193*4882a593SmuzhiyunConvert uclasses to use logging with the correct category
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunConsider making log() calls emit an automatic newline, perhaps with a logn()
196*4882a593Smuzhiyun   function to avoid that
197*4882a593Smuzhiyun
198*4882a593SmuzhiyunPassing log records through to linux (e.g. via device tree /chosen)
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunProvide a command to access the number of log records generated, and the
201*4882a593Smuzhiyunnumber dropped due to them being generated before the log system was ready.
202*4882a593Smuzhiyun
203*4882a593SmuzhiyunAdd a printf() format string pragma so that log statements are checked properly
204*4882a593Smuzhiyun
205*4882a593SmuzhiyunEnhance the log console driver to show level / category / file / line
206*4882a593Smuzhiyuninformation
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunAdd a command to add new log records and delete existing records.
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunProvide additional log() functions - e.g. logc() to specify the category
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun--
213*4882a593SmuzhiyunSimon Glass <sjg@chromium.org>
214*4882a593Smuzhiyun15-Sep-17
215