3 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
5 * Code used from linux/kernel/printk.c
6 * Copyright (C) 1991, 1992 Linus Torvalds
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * After relocating the code, the environment variable "loglevel" is
29 * copied to console_loglevel. The functionality is similar to the
30 * handling in the Linux kernel, i.e. messages logged with a priority
31 * less than console_loglevel are also output to stdout.
33 * If you want messages with the default level (e.g. POST messages) to
34 * appear on stdout also, make sure the environment variable
35 * "loglevel" is set at boot time to a number higher than
36 * default_message_loglevel below.
40 * Logbuffer handling routines
49 #if defined(CONFIG_LOGBUFFER)
51 /* Local prototypes */
52 static void logbuff_putc (const char c
);
53 static void logbuff_puts (const char *s
);
54 static int logbuff_printk(const char *line
);
56 static char buf
[1024];
58 /* This combination will not print messages with the default loglevel */
59 static unsigned console_loglevel
= 3;
60 static unsigned default_message_loglevel
= 4;
61 static unsigned char *log_buf
= NULL
;
62 static unsigned long *ext_log_size
;
63 static unsigned long *ext_log_start
;
64 static unsigned long *ext_logged_chars
;
65 #define log_size (*ext_log_size)
66 #define log_start (*ext_log_start)
67 #define logged_chars (*ext_logged_chars)
69 /* Forced by code, eh! */
70 #define LOGBUFF_MAGIC 0xc0de4ced
72 /* The mapping used here has to be the same as in setup_ext_logbuff ()
73 in linux/kernel/printk */
74 void logbuff_init_ptrs (void)
76 DECLARE_GLOBAL_DATA_PTR
;
77 unsigned long *ext_tag
;
78 unsigned long post_word
;
81 log_buf
= (unsigned char *)(gd
->bd
->bi_memsize
-LOGBUFF_LEN
);
82 ext_tag
= (unsigned long *)(log_buf
)-4;
83 ext_log_start
= (unsigned long *)(log_buf
)-3;
84 ext_log_size
= (unsigned long *)(log_buf
)-2;
85 ext_logged_chars
= (unsigned long *)(log_buf
)-1;
86 post_word
= post_word_load();
88 /* The post routines have setup the word so we can simply test it */
89 if (post_word_load () & POST_COLDBOOT
) {
90 logged_chars
= log_size
= log_start
= 0;
91 *ext_tag
= LOGBUFF_MAGIC
;
94 /* No post routines, so we do our own checking */
95 if (post_word
!= LOGBUFF_MAGIC
) {
96 logged_chars
= log_size
= log_start
= 0;
97 post_word_store (LOGBUFF_MAGIC
);
98 *ext_tag
= LOGBUFF_MAGIC
;
101 /* Initialize default loglevel if present */
102 if ((s
= getenv ("loglevel")) != NULL
)
103 console_loglevel
= (int)simple_strtoul (s
, NULL
, 10);
105 gd
->post_log_word
|= LOGBUFF_INITIALIZED
;
108 int drv_logbuff_init (void)
113 /* Device initialization */
114 memset (&logdev
, 0, sizeof (logdev
));
116 strcpy (logdev
.name
, "logbuff");
117 logdev
.ext
= 0; /* No extensions */
118 logdev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
119 logdev
.putc
= logbuff_putc
; /* 'putc' function */
120 logdev
.puts
= logbuff_puts
; /* 'puts' function */
122 rc
= device_register (&logdev
);
124 return (rc
== 0) ? 1 : rc
;
127 static void logbuff_putc (const char c
)
132 logbuff_printk (buf
);
135 static void logbuff_puts (const char *s
)
140 void logbuff_log(char *msg
)
142 DECLARE_GLOBAL_DATA_PTR
;
144 if ((gd
->post_log_word
& LOGBUFF_INITIALIZED
)) {
145 logbuff_printk (msg
);
147 /* Can happen only for pre-relocated errors as logging */
148 /* at that stage should be disabled */
156 * Description: Handler for 'log' command..
158 * Inputs: argv[1] contains the subcommand
163 int do_log (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
168 if (strcmp(argv
[1],"append") == 0) {
169 /* Log concatenation of all arguments separated by spaces */
170 for (i
=2; i
<argc
; i
++) {
171 logbuff_printk (argv
[i
]);
172 logbuff_putc ((i
<argc
-1) ? ' ' : '\n');
180 if (strcmp(argv
[1],"show") == 0) {
181 for (i
=0; i
< (log_size
&LOGBUFF_MASK
); i
++) {
182 s
= (char *)log_buf
+((log_start
+i
)&LOGBUFF_MASK
);
186 } else if (strcmp(argv
[1],"reset") == 0) {
191 } else if (strcmp(argv
[1],"info") == 0) {
192 printf ("Logbuffer at %08lx\n", (unsigned long)log_buf
);
193 printf ("log_start = %08lx\n", log_start
);
194 printf ("log_size = %08lx\n", log_size
);
195 printf ("logged_chars = %08lx\n", logged_chars
);
198 printf ("Usage:\n%s\n", cmdtp
->usage
);
202 printf ("Usage:\n%s\n", cmdtp
->usage
);
206 #if defined(CONFIG_LOGBUFFER)
209 "log - manipulate logbuffer\n",
210 "info - show pointer details\n"
211 "log reset - clear contents\n"
212 "log show - show contents\n"
213 "log append <msg> - append <msg> to the logbuffer\n"
215 #endif /* CONFIG_LOGBUFFER */
216 static int logbuff_printk(const char *line
)
219 char *msg
, *p
, *buf_end
;
221 static signed char msg_level
= -1;
223 strcpy (buf
+ 3, line
);
225 buf_end
= buf
+ 3 + i
;
226 for (p
= buf
+ 3; p
< buf_end
; p
++) {
237 p
[1] = default_message_loglevel
+ '0';
241 msg_level
= p
[1] - '0';
244 for (; p
< buf_end
; p
++) {
245 log_buf
[(log_start
+log_size
) & LOGBUFF_MASK
] = *p
;
246 if (log_size
< LOGBUFF_LEN
)
257 if (msg_level
< console_loglevel
) {
266 #endif /* (CONFIG_LOGBUFFER) */