3 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Logbuffer handling routines
33 #if defined(CONFIG_LOGBUFFER)
35 #define LOG_BUF_LEN (16384)
36 #define LOG_BUF_MASK (LOG_BUF_LEN-1)
38 /* Local prototypes */
39 static void logbuff_putc (const char c);
40 static void logbuff_puts (const char *s);
41 static int logbuff_printk(const char *line);
43 static char buf[1024];
45 static unsigned console_loglevel = 3;
46 static unsigned default_message_loglevel = 4;
47 static unsigned long log_size;
48 static unsigned char *log_buf=NULL;
49 static unsigned long *ext_log_start, *ext_logged_chars;
50 #define log_start (*ext_log_start)
51 #define logged_chars (*ext_logged_chars)
53 /* Forced by code, eh! */
54 #define LOGBUFF_MAGIC 0xc0de4ced
56 int drv_logbuff_init (void)
61 /* Device initialization */
62 memset (&logdev, 0, sizeof (logdev));
64 strcpy (logdev.name, "logbuff");
65 logdev.ext = 0; /* No extensions */
66 logdev.flags = DEV_FLAGS_OUTPUT; /* Output only */
67 logdev.putc = logbuff_putc; /* 'putc' function */
68 logdev.puts = logbuff_puts; /* 'puts' function */
70 rc = device_register (&logdev);
72 return (rc == 0) ? 1 : rc;
75 static void logbuff_putc (const char c)
83 static void logbuff_puts (const char *s)
87 sprintf(buf, "%s\n", s);
91 void logbuff_log(char *msg)
93 DECLARE_GLOBAL_DATA_PTR;
95 if ((gd->flags & GD_FLG_RELOC)&&(getenv ("logstart") != NULL)) {
102 void logbuff_reset (void)
105 unsigned long *ext_tag;
107 if ((s = getenv ("logstart")) != NULL) {
108 log_buf = (unsigned char *)simple_strtoul(s, NULL, 16);
109 ext_tag=(unsigned long *)(log_buf)-3;
110 ext_log_start=(unsigned long *)(log_buf)-2;
111 ext_logged_chars=(unsigned long *)(log_buf)-1;
112 /* if (*ext_tag!=LOGBUFF_MAGIC) { */
113 logged_chars=log_start=0;
114 *ext_tag=LOGBUFF_MAGIC;
116 log_size=logged_chars;
123 * Description: Handler for 'log' command..
125 * Inputs: argv[1] contains the subcommand
130 int do_log (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
136 printf ("No logbuffer defined! Set 'logstart' to use this feature.\n");
143 if (strcmp(argv[1],"show") == 0) {
144 for (i=0; i<logged_chars; i++) {
145 s=log_buf+((log_start+i)&LOG_BUF_MASK);
149 } else if (strcmp(argv[1],"reset") == 0) {
155 printf ("Usage:\n%s\n", cmdtp->usage);
159 if (strcmp(argv[1],"append") == 0) {
160 logbuff_puts(argv[2]);
164 printf ("Usage:\n%s\n", cmdtp->usage);
168 printf ("Usage:\n%s\n", cmdtp->usage);
173 static int logbuff_printk(const char *line)
176 char *msg, *p, *buf_end;
178 static signed char msg_level = -1;
180 strcpy(buf + 3, line);
182 buf_end = buf + 3 + i;
183 for (p = buf + 3; p < buf_end; p++) {
194 p[1] = default_message_loglevel + '0';
198 msg_level = p[1] - '0';
201 for (; p < buf_end; p++) {
202 log_buf[(log_start+log_size) & LOG_BUF_MASK] = *p;
203 if (log_size < LOG_BUF_LEN)
214 if (msg_level < console_loglevel) {
223 #endif /* (CONFIG_LOGBUFFER) */