/*
- * (C) Copyright 2002
+ * (C) Copyright 2002-2007
* Detlev Zundel, DENX Software Engineering, dzu@denx.de.
*
* Code used from linux/kernel/printk.c
* Copyright (C) 1991, 1992 Linus Torvalds
*
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier: GPL-2.0+
*
* Comments:
*
#include <common.h>
#include <command.h>
-#include <devices.h>
+#include <stdio_dev.h>
#include <post.h>
#include <logbuff.h>
-#if defined(CONFIG_LOGBUFFER)
+DECLARE_GLOBAL_DATA_PTR;
/* Local prototypes */
-static void logbuff_putc (const char c);
-static void logbuff_puts (const char *s);
+static void logbuff_putc(const char c);
+static void logbuff_puts(const char *s);
static int logbuff_printk(const char *line);
static char buf[1024];
/* This combination will not print messages with the default loglevel */
static unsigned console_loglevel = 3;
static unsigned default_message_loglevel = 4;
-static unsigned char *log_buf = NULL;
-static unsigned long *ext_log_size;
-static unsigned long *ext_log_start;
-static unsigned long *ext_logged_chars;
-#define log_size (*ext_log_size)
-#define log_start (*ext_log_start)
-#define logged_chars (*ext_logged_chars)
+static unsigned log_version = 1;
+#ifdef CONFIG_ALT_LB_ADDR
+static volatile logbuff_t *log;
+#else
+static logbuff_t *log;
+#endif
+static char *lbuf;
-/* Forced by code, eh! */
-#define LOGBUFF_MAGIC 0xc0de4ced
+unsigned long __logbuffer_base(void)
+{
+ return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
+}
+unsigned long logbuffer_base(void)
+__attribute__((weak, alias("__logbuffer_base")));
-/* The mapping used here has to be the same as in setup_ext_logbuff ()
- in linux/kernel/printk */
-void logbuff_init_ptrs (void)
+void logbuff_init_ptrs(void)
{
- DECLARE_GLOBAL_DATA_PTR;
- unsigned long *ext_tag;
- unsigned long post_word;
+ unsigned long tag, post_word;
char *s;
- log_buf = (unsigned char *)(gd->bd->bi_memsize-LOGBUFF_LEN);
- ext_tag = (unsigned long *)(log_buf)-4;
- ext_log_start = (unsigned long *)(log_buf)-3;
- ext_log_size = (unsigned long *)(log_buf)-2;
- ext_logged_chars = (unsigned long *)(log_buf)-1;
+#ifdef CONFIG_ALT_LB_ADDR
+ log = (logbuff_t *)CONFIG_ALT_LH_ADDR;
+ lbuf = (char *)CONFIG_ALT_LB_ADDR;
+#else
+ log = (logbuff_t *)(logbuffer_base()) - 1;
+ lbuf = (char *)log->buf;
+#endif
+
+ /* Set up log version */
+ if ((s = getenv ("logversion")) != NULL)
+ log_version = (int)simple_strtoul(s, NULL, 10);
+
+ if (log_version == 2)
+ tag = log->v2.tag;
+ else
+ tag = log->v1.tag;
post_word = post_word_load();
#ifdef CONFIG_POST
/* The post routines have setup the word so we can simply test it */
- if (post_word_load () & POST_COLDBOOT) {
- logged_chars = log_size = log_start = 0;
- *ext_tag = LOGBUFF_MAGIC;
- }
+ if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT))
+ logbuff_reset();
#else
/* No post routines, so we do our own checking */
- if (post_word != LOGBUFF_MAGIC) {
- logged_chars = log_size = log_start = 0;
+ if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) {
+ logbuff_reset ();
post_word_store (LOGBUFF_MAGIC);
- *ext_tag = LOGBUFF_MAGIC;
- }
+ }
#endif
+ if (log_version == 2 && (long)log->v2.start > (long)log->v2.con)
+ log->v2.start = log->v2.con;
+
/* Initialize default loglevel if present */
if ((s = getenv ("loglevel")) != NULL)
- console_loglevel = (int)simple_strtoul (s, NULL, 10);
+ console_loglevel = (int)simple_strtoul(s, NULL, 10);
- gd->post_log_word |= LOGBUFF_INITIALIZED;
+ gd->flags |= GD_FLG_LOGINIT;
}
-int drv_logbuff_init (void)
+void logbuff_reset(void)
{
- device_t logdev;
+#ifndef CONFIG_ALT_LB_ADDR
+ memset(log, 0, sizeof(logbuff_t));
+#endif
+ if (log_version == 2) {
+ log->v2.tag = LOGBUFF_MAGIC;
+#ifdef CONFIG_ALT_LB_ADDR
+ log->v2.start = 0;
+ log->v2.con = 0;
+ log->v2.end = 0;
+ log->v2.chars = 0;
+#endif
+ } else {
+ log->v1.tag = LOGBUFF_MAGIC;
+#ifdef CONFIG_ALT_LB_ADDR
+ log->v1.dummy = 0;
+ log->v1.start = 0;
+ log->v1.size = 0;
+ log->v1.chars = 0;
+#endif
+ }
+}
+
+int drv_logbuff_init(void)
+{
+ struct stdio_dev logdev;
int rc;
/* Device initialization */
logdev.putc = logbuff_putc; /* 'putc' function */
logdev.puts = logbuff_puts; /* 'puts' function */
- rc = device_register (&logdev);
+ rc = stdio_register(&logdev);
return (rc == 0) ? 1 : rc;
}
-static void logbuff_putc (const char c)
+static void logbuff_putc(const char c)
{
char buf[2];
buf[0] = c;
buf[1] = '\0';
- logbuff_printk (buf);
+ logbuff_printk(buf);
}
-static void logbuff_puts (const char *s)
+static void logbuff_puts(const char *s)
{
logbuff_printk (s);
}
void logbuff_log(char *msg)
{
- DECLARE_GLOBAL_DATA_PTR;
-
- if ((gd->post_log_word & LOGBUFF_INITIALIZED)) {
- logbuff_printk (msg);
+ if ((gd->flags & GD_FLG_LOGINIT)) {
+ logbuff_printk(msg);
} else {
- /* Can happen only for pre-relocated errors as logging */
- /* at that stage should be disabled */
+ /*
+ * Can happen only for pre-relocated errors as logging
+ * at that stage should be disabled
+ */
puts (msg);
}
}
* Return: None
*
*/
-int do_log (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char *s;
- unsigned long i;
+ unsigned long i, start, size;
- if (strcmp(argv[1],"append") == 0) {
+ if (strcmp(argv[1], "append") == 0) {
/* Log concatenation of all arguments separated by spaces */
- for (i=2; i<argc; i++) {
- logbuff_printk (argv[i]);
- logbuff_putc ((i<argc-1) ? ' ' : '\n');
+ for (i = 2; i < argc; i++) {
+ logbuff_printk(argv[i]);
+ logbuff_putc((i < argc - 1) ? ' ' : '\n');
}
return 0;
}
switch (argc) {
case 2:
- if (strcmp(argv[1],"show") == 0) {
- for (i=0; i < (log_size&LOGBUFF_MASK); i++) {
- s = (char *)log_buf+((log_start+i)&LOGBUFF_MASK);
- putc (*s);
+ if (strcmp(argv[1], "show") == 0) {
+ if (log_version == 2) {
+ start = log->v2.start;
+ size = log->v2.end - log->v2.start;
+ } else {
+ start = log->v1.start;
+ size = log->v1.size;
+ }
+ if (size > LOGBUFF_LEN)
+ size = LOGBUFF_LEN;
+ for (i = 0; i < size; i++) {
+ s = lbuf + ((start + i) & LOGBUFF_MASK);
+ putc(*s);
}
return 0;
- } else if (strcmp(argv[1],"reset") == 0) {
- log_start = 0;
- log_size = 0;
- logged_chars = 0;
+ } else if (strcmp(argv[1], "reset") == 0) {
+ logbuff_reset();
return 0;
- } else if (strcmp(argv[1],"info") == 0) {
- printf ("Logbuffer at %08lx\n", (unsigned long)log_buf);
- printf ("log_start = %08lx\n", log_start);
- printf ("log_size = %08lx\n", log_size);
- printf ("logged_chars = %08lx\n", logged_chars);
+ } else if (strcmp(argv[1], "info") == 0) {
+ printf("Logbuffer at %08lx\n", (unsigned long)lbuf);
+ if (log_version == 2) {
+ printf("log_start = %08lx\n",
+ log->v2.start);
+ printf("log_end = %08lx\n", log->v2.end);
+ printf("log_con = %08lx\n", log->v2.con);
+ printf("logged_chars = %08lx\n",
+ log->v2.chars);
+ }
+ else {
+ printf("log_start = %08lx\n",
+ log->v1.start);
+ printf("log_size = %08lx\n",
+ log->v1.size);
+ printf("logged_chars = %08lx\n",
+ log->v1.chars);
+ }
return 0;
}
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
+ return CMD_RET_USAGE;
default:
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
+ return CMD_RET_USAGE;
}
}
-#if defined(CONFIG_LOGBUFFER)
+
U_BOOT_CMD(
log, 255, 1, do_log,
- "log - manipulate logbuffer\n",
+ "manipulate logbuffer",
"info - show pointer details\n"
"log reset - clear contents\n"
"log show - show contents\n"
- "log append <msg> - append <msg> to the logbuffer\n"
+ "log append <msg> - append <msg> to the logbuffer"
);
-#endif /* CONFIG_LOGBUFFER */
+
static int logbuff_printk(const char *line)
{
int i;
int line_feed;
static signed char msg_level = -1;
- strcpy (buf + 3, line);
- i = strlen (line);
+ strcpy(buf + 3, line);
+ i = strlen(line);
buf_end = buf + 3 + i;
for (p = buf + 3; p < buf_end; p++) {
msg = p;
p[0] = '<';
p[1] = default_message_loglevel + '0';
p[2] = '>';
- } else
+ } else {
msg += 3;
+ }
msg_level = p[1] - '0';
}
line_feed = 0;
for (; p < buf_end; p++) {
- log_buf[(log_start+log_size) & LOGBUFF_MASK] = *p;
- if (log_size < LOGBUFF_LEN)
- log_size++;
- else
- log_start++;
-
- logged_chars++;
+ if (log_version == 2) {
+ lbuf[log->v2.end & LOGBUFF_MASK] = *p;
+ log->v2.end++;
+ if (log->v2.end - log->v2.start > LOGBUFF_LEN)
+ log->v2.start++;
+ log->v2.chars++;
+ } else {
+ lbuf[(log->v1.start + log->v1.size) &
+ LOGBUFF_MASK] = *p;
+ if (log->v1.size < LOGBUFF_LEN)
+ log->v1.size++;
+ else
+ log->v1.start++;
+ log->v1.chars++;
+ }
if (*p == '\n') {
line_feed = 1;
break;
}
return i;
}
-
-#endif /* (CONFIG_LOGBUFFER) */