]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_log.c
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 DECLARE_GLOBAL_DATA_PTR
;
51 #if defined(CONFIG_LOGBUFFER)
53 /* Local prototypes */
54 static void logbuff_putc (const char c
);
55 static void logbuff_puts (const char *s
);
56 static int logbuff_printk(const char *line
);
58 static char buf
[1024];
60 /* This combination will not print messages with the default loglevel */
61 static unsigned console_loglevel
= 3;
62 static unsigned default_message_loglevel
= 4;
63 static unsigned char *log_buf
= NULL
;
64 static unsigned long *ext_log_size
;
65 static unsigned long *ext_log_start
;
66 static unsigned long *ext_logged_chars
;
67 #define log_size (*ext_log_size)
68 #define log_start (*ext_log_start)
69 #define logged_chars (*ext_logged_chars)
71 /* Forced by code, eh! */
72 #define LOGBUFF_MAGIC 0xc0de4ced
74 /* The mapping used here has to be the same as in setup_ext_logbuff ()
75 in linux/kernel/printk */
76 void logbuff_init_ptrs (void)
78 unsigned long *ext_tag
;
79 unsigned long post_word
;
82 log_buf
= (unsigned char *)(gd
->bd
->bi_memsize
-LOGBUFF_LEN
);
83 ext_tag
= (unsigned long *)(log_buf
)-4;
84 ext_log_start
= (unsigned long *)(log_buf
)-3;
85 ext_log_size
= (unsigned long *)(log_buf
)-2;
86 ext_logged_chars
= (unsigned long *)(log_buf
)-1;
87 post_word
= post_word_load();
89 /* The post routines have setup the word so we can simply test it */
90 if (post_word_load () & POST_COLDBOOT
) {
91 logged_chars
= log_size
= log_start
= 0;
92 *ext_tag
= LOGBUFF_MAGIC
;
95 /* No post routines, so we do our own checking */
96 if (post_word
!= LOGBUFF_MAGIC
) {
97 logged_chars
= log_size
= log_start
= 0;
98 post_word_store (LOGBUFF_MAGIC
);
99 *ext_tag
= LOGBUFF_MAGIC
;
102 /* Initialize default loglevel if present */
103 if ((s
= getenv ("loglevel")) != NULL
)
104 console_loglevel
= (int)simple_strtoul (s
, NULL
, 10);
106 gd
->post_log_word
|= LOGBUFF_INITIALIZED
;
109 int drv_logbuff_init (void)
114 /* Device initialization */
115 memset (&logdev
, 0, sizeof (logdev
));
117 strcpy (logdev
.name
, "logbuff");
118 logdev
.ext
= 0; /* No extensions */
119 logdev
.flags
= DEV_FLAGS_OUTPUT
; /* Output only */
120 logdev
.putc
= logbuff_putc
; /* 'putc' function */
121 logdev
.puts
= logbuff_puts
; /* 'puts' function */
123 rc
= device_register (&logdev
);
125 return (rc
== 0) ? 1 : rc
;
128 static void logbuff_putc (const char c
)
133 logbuff_printk (buf
);
136 static void logbuff_puts (const char *s
)
141 void logbuff_log(char *msg
)
143 if ((gd
->post_log_word
& LOGBUFF_INITIALIZED
)) {
144 logbuff_printk (msg
);
146 /* Can happen only for pre-relocated errors as logging */
147 /* at that stage should be disabled */
155 * Description: Handler for 'log' command..
157 * Inputs: argv[1] contains the subcommand
162 int do_log (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
167 if (strcmp(argv
[1],"append") == 0) {
168 /* Log concatenation of all arguments separated by spaces */
169 for (i
=2; i
<argc
; i
++) {
170 logbuff_printk (argv
[i
]);
171 logbuff_putc ((i
<argc
-1) ? ' ' : '\n');
179 if (strcmp(argv
[1],"show") == 0) {
180 for (i
=0; i
< (log_size
&LOGBUFF_MASK
); i
++) {
181 s
= (char *)log_buf
+((log_start
+i
)&LOGBUFF_MASK
);
185 } else if (strcmp(argv
[1],"reset") == 0) {
190 } else if (strcmp(argv
[1],"info") == 0) {
191 printf ("Logbuffer at %08lx\n", (unsigned long)log_buf
);
192 printf ("log_start = %08lx\n", log_start
);
193 printf ("log_size = %08lx\n", log_size
);
194 printf ("logged_chars = %08lx\n", logged_chars
);
197 printf ("Usage:\n%s\n", cmdtp
->usage
);
201 printf ("Usage:\n%s\n", cmdtp
->usage
);
205 #if defined(CONFIG_LOGBUFFER)
208 "log - manipulate logbuffer\n",
209 "info - show pointer details\n"
210 "log reset - clear contents\n"
211 "log show - show contents\n"
212 "log append <msg> - append <msg> to the logbuffer\n"
214 #endif /* CONFIG_LOGBUFFER */
215 static int logbuff_printk(const char *line
)
218 char *msg
, *p
, *buf_end
;
220 static signed char msg_level
= -1;
222 strcpy (buf
+ 3, line
);
224 buf_end
= buf
+ 3 + i
;
225 for (p
= buf
+ 3; p
< buf_end
; p
++) {
236 p
[1] = default_message_loglevel
+ '0';
240 msg_level
= p
[1] - '0';
243 for (; p
< buf_end
; p
++) {
244 log_buf
[(log_start
+log_size
) & LOGBUFF_MASK
] = *p
;
245 if (log_size
< LOGBUFF_LEN
)
256 if (msg_level
< console_loglevel
) {
265 #endif /* (CONFIG_LOGBUFFER) */