2002-11-06 00:35:14 +08:00
|
|
|
/*
|
2007-04-18 18:55:19 +08:00
|
|
|
* (C) Copyright 2002-2007
|
2002-11-06 00:35:14 +08:00
|
|
|
* Detlev Zundel, DENX Software Engineering, dzu@denx.de.
|
|
|
|
*
|
2002-12-08 17:53:23 +08:00
|
|
|
* Code used from linux/kernel/printk.c
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-12-08 17:53:23 +08:00
|
|
|
*
|
|
|
|
* Comments:
|
|
|
|
*
|
|
|
|
* After relocating the code, the environment variable "loglevel" is
|
|
|
|
* copied to console_loglevel. The functionality is similar to the
|
|
|
|
* handling in the Linux kernel, i.e. messages logged with a priority
|
|
|
|
* less than console_loglevel are also output to stdout.
|
|
|
|
*
|
|
|
|
* If you want messages with the default level (e.g. POST messages) to
|
|
|
|
* appear on stdout also, make sure the environment variable
|
|
|
|
* "loglevel" is set at boot time to a number higher than
|
|
|
|
* default_message_loglevel below.
|
2002-11-06 00:35:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logbuffer handling routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2009-05-16 18:14:54 +08:00
|
|
|
#include <stdio_dev.h>
|
2002-12-08 17:53:23 +08:00
|
|
|
#include <post.h>
|
2002-11-06 00:35:14 +08:00
|
|
|
#include <logbuff.h>
|
|
|
|
|
2006-04-01 00:32:53 +08:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2002-11-06 00:35:14 +08:00
|
|
|
/* Local prototypes */
|
2014-07-23 20:54:59 +08:00
|
|
|
static void logbuff_putc(struct stdio_dev *dev, const char c);
|
|
|
|
static void logbuff_puts(struct stdio_dev *dev, const char *s);
|
2002-11-06 00:35:14 +08:00
|
|
|
static int logbuff_printk(const char *line);
|
|
|
|
|
|
|
|
static char buf[1024];
|
|
|
|
|
2002-12-08 17:53:23 +08:00
|
|
|
/* This combination will not print messages with the default loglevel */
|
2002-11-06 00:35:14 +08:00
|
|
|
static unsigned console_loglevel = 3;
|
|
|
|
static unsigned default_message_loglevel = 4;
|
2007-04-18 18:55:19 +08:00
|
|
|
static unsigned log_version = 1;
|
2008-02-07 01:48:36 +08:00
|
|
|
#ifdef CONFIG_ALT_LB_ADDR
|
|
|
|
static volatile logbuff_t *log;
|
|
|
|
#else
|
2007-04-18 18:55:19 +08:00
|
|
|
static logbuff_t *log;
|
2008-02-07 01:48:36 +08:00
|
|
|
#endif
|
|
|
|
static char *lbuf;
|
2002-11-06 00:35:14 +08:00
|
|
|
|
2008-05-13 21:53:29 +08:00
|
|
|
unsigned long __logbuffer_base(void)
|
|
|
|
{
|
2014-02-12 03:57:26 +08:00
|
|
|
return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN;
|
2008-05-13 21:53:29 +08:00
|
|
|
}
|
2012-02-15 06:21:06 +08:00
|
|
|
unsigned long logbuffer_base(void)
|
|
|
|
__attribute__((weak, alias("__logbuffer_base")));
|
2008-05-13 21:53:29 +08:00
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
void logbuff_init_ptrs(void)
|
2002-12-08 17:53:23 +08:00
|
|
|
{
|
2007-04-18 18:55:19 +08:00
|
|
|
unsigned long tag, post_word;
|
2002-12-08 17:53:23 +08:00
|
|
|
char *s;
|
|
|
|
|
2008-02-07 01:48:36 +08:00
|
|
|
#ifdef CONFIG_ALT_LB_ADDR
|
|
|
|
log = (logbuff_t *)CONFIG_ALT_LH_ADDR;
|
|
|
|
lbuf = (char *)CONFIG_ALT_LB_ADDR;
|
|
|
|
#else
|
2012-02-15 06:21:06 +08:00
|
|
|
log = (logbuff_t *)(logbuffer_base()) - 1;
|
2008-04-02 14:03:57 +08:00
|
|
|
lbuf = (char *)log->buf;
|
2008-02-07 01:48:36 +08:00
|
|
|
#endif
|
2007-04-18 18:55:19 +08:00
|
|
|
|
|
|
|
/* Set up log version */
|
|
|
|
if ((s = getenv ("logversion")) != NULL)
|
2012-02-15 06:21:06 +08:00
|
|
|
log_version = (int)simple_strtoul(s, NULL, 10);
|
2007-04-18 18:55:19 +08:00
|
|
|
|
|
|
|
if (log_version == 2)
|
|
|
|
tag = log->v2.tag;
|
|
|
|
else
|
|
|
|
tag = log->v1.tag;
|
2003-07-16 05:08:26 +08:00
|
|
|
post_word = post_word_load();
|
2003-06-29 01:24:46 +08:00
|
|
|
#ifdef CONFIG_POST
|
|
|
|
/* The post routines have setup the word so we can simply test it */
|
2012-02-15 06:21:06 +08:00
|
|
|
if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT))
|
|
|
|
logbuff_reset();
|
2003-06-29 01:24:46 +08:00
|
|
|
#else
|
|
|
|
/* No post routines, so we do our own checking */
|
2007-04-18 18:55:19 +08:00
|
|
|
if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) {
|
|
|
|
logbuff_reset ();
|
2003-06-29 01:24:46 +08:00
|
|
|
post_word_store (LOGBUFF_MAGIC);
|
2007-06-23 05:59:00 +08:00
|
|
|
}
|
2003-06-29 01:24:46 +08:00
|
|
|
#endif
|
2007-04-18 18:55:19 +08:00
|
|
|
if (log_version == 2 && (long)log->v2.start > (long)log->v2.con)
|
|
|
|
log->v2.start = log->v2.con;
|
|
|
|
|
2002-12-08 17:53:23 +08:00
|
|
|
/* Initialize default loglevel if present */
|
|
|
|
if ((s = getenv ("loglevel")) != NULL)
|
2012-02-15 06:21:06 +08:00
|
|
|
console_loglevel = (int)simple_strtoul(s, NULL, 10);
|
2002-12-08 17:53:23 +08:00
|
|
|
|
2008-05-08 21:46:42 +08:00
|
|
|
gd->flags |= GD_FLG_LOGINIT;
|
2002-12-08 17:53:23 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
void logbuff_reset(void)
|
2007-04-18 18:55:19 +08:00
|
|
|
{
|
2008-02-07 01:48:36 +08:00
|
|
|
#ifndef CONFIG_ALT_LB_ADDR
|
2012-02-15 06:21:06 +08:00
|
|
|
memset(log, 0, sizeof(logbuff_t));
|
2008-02-07 01:48:36 +08:00
|
|
|
#endif
|
|
|
|
if (log_version == 2) {
|
2007-04-18 18:55:19 +08:00
|
|
|
log->v2.tag = LOGBUFF_MAGIC;
|
2008-02-07 01:48:36 +08:00
|
|
|
#ifdef CONFIG_ALT_LB_ADDR
|
|
|
|
log->v2.start = 0;
|
|
|
|
log->v2.con = 0;
|
|
|
|
log->v2.end = 0;
|
|
|
|
log->v2.chars = 0;
|
|
|
|
#endif
|
|
|
|
} else {
|
2007-04-18 18:55:19 +08:00
|
|
|
log->v1.tag = LOGBUFF_MAGIC;
|
2008-02-07 01:48:36 +08:00
|
|
|
#ifdef CONFIG_ALT_LB_ADDR
|
|
|
|
log->v1.dummy = 0;
|
|
|
|
log->v1.start = 0;
|
|
|
|
log->v1.size = 0;
|
|
|
|
log->v1.chars = 0;
|
|
|
|
#endif
|
|
|
|
}
|
2007-04-18 18:55:19 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
int drv_logbuff_init(void)
|
2002-11-06 00:35:14 +08:00
|
|
|
{
|
2009-05-16 18:14:54 +08:00
|
|
|
struct stdio_dev logdev;
|
2002-11-06 00:35:14 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Device initialization */
|
|
|
|
memset (&logdev, 0, sizeof (logdev));
|
|
|
|
|
|
|
|
strcpy (logdev.name, "logbuff");
|
|
|
|
logdev.ext = 0; /* No extensions */
|
|
|
|
logdev.flags = DEV_FLAGS_OUTPUT; /* Output only */
|
|
|
|
logdev.putc = logbuff_putc; /* 'putc' function */
|
|
|
|
logdev.puts = logbuff_puts; /* 'puts' function */
|
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
rc = stdio_register(&logdev);
|
2002-11-06 00:35:14 +08:00
|
|
|
|
|
|
|
return (rc == 0) ? 1 : rc;
|
|
|
|
}
|
|
|
|
|
2014-07-23 20:54:59 +08:00
|
|
|
static void logbuff_putc(struct stdio_dev *dev, const char c)
|
2002-11-06 00:35:14 +08:00
|
|
|
{
|
|
|
|
char buf[2];
|
2002-12-08 17:53:23 +08:00
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
2012-02-15 06:21:06 +08:00
|
|
|
logbuff_printk(buf);
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
|
2014-07-23 20:54:59 +08:00
|
|
|
static void logbuff_puts(struct stdio_dev *dev, const char *s)
|
2002-11-06 00:35:14 +08:00
|
|
|
{
|
2002-12-08 17:53:23 +08:00
|
|
|
logbuff_printk (s);
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void logbuff_log(char *msg)
|
|
|
|
{
|
2008-05-08 21:46:42 +08:00
|
|
|
if ((gd->flags & GD_FLG_LOGINIT)) {
|
2012-02-15 06:21:06 +08:00
|
|
|
logbuff_printk(msg);
|
2002-11-06 00:35:14 +08:00
|
|
|
} else {
|
2012-02-15 06:21:06 +08:00
|
|
|
/*
|
|
|
|
* Can happen only for pre-relocated errors as logging
|
|
|
|
* at that stage should be disabled
|
|
|
|
*/
|
2002-12-08 17:53:23 +08:00
|
|
|
puts (msg);
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Subroutine: do_log
|
|
|
|
*
|
|
|
|
* Description: Handler for 'log' command..
|
|
|
|
*
|
|
|
|
* Inputs: argv[1] contains the subcommand
|
|
|
|
*
|
|
|
|
* Return: None
|
|
|
|
*
|
|
|
|
*/
|
2012-02-15 06:21:06 +08:00
|
|
|
int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-11-06 00:35:14 +08:00
|
|
|
{
|
2014-07-23 20:54:59 +08:00
|
|
|
struct stdio_dev *sdev = NULL;
|
2002-11-06 00:35:14 +08:00
|
|
|
char *s;
|
2007-04-18 18:55:19 +08:00
|
|
|
unsigned long i, start, size;
|
2002-11-06 00:35:14 +08:00
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
if (strcmp(argv[1], "append") == 0) {
|
2002-12-08 17:53:23 +08:00
|
|
|
/* Log concatenation of all arguments separated by spaces */
|
2012-02-15 06:21:06 +08:00
|
|
|
for (i = 2; i < argc; i++) {
|
|
|
|
logbuff_printk(argv[i]);
|
2014-07-23 20:54:59 +08:00
|
|
|
logbuff_putc(sdev, (i < argc - 1) ? ' ' : '\n');
|
2002-12-08 17:53:23 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
|
|
|
|
case 2:
|
2012-02-15 06:21:06 +08:00
|
|
|
if (strcmp(argv[1], "show") == 0) {
|
2007-04-18 18:55:19 +08:00
|
|
|
if (log_version == 2) {
|
|
|
|
start = log->v2.start;
|
|
|
|
size = log->v2.end - log->v2.start;
|
2012-02-15 06:21:06 +08:00
|
|
|
} else {
|
2007-04-18 18:55:19 +08:00
|
|
|
start = log->v1.start;
|
|
|
|
size = log->v1.size;
|
|
|
|
}
|
2012-02-16 09:02:21 +08:00
|
|
|
if (size > LOGBUFF_LEN)
|
|
|
|
size = LOGBUFF_LEN;
|
|
|
|
for (i = 0; i < size; i++) {
|
2012-02-15 06:21:06 +08:00
|
|
|
s = lbuf + ((start + i) & LOGBUFF_MASK);
|
|
|
|
putc(*s);
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2012-02-15 06:21:06 +08:00
|
|
|
} else if (strcmp(argv[1], "reset") == 0) {
|
|
|
|
logbuff_reset();
|
2002-11-06 00:35:14 +08:00
|
|
|
return 0;
|
2012-02-15 06:21:06 +08:00
|
|
|
} else if (strcmp(argv[1], "info") == 0) {
|
|
|
|
printf("Logbuffer at %08lx\n", (unsigned long)lbuf);
|
2007-04-18 18:55:19 +08:00
|
|
|
if (log_version == 2) {
|
2012-02-15 06:21:06 +08:00
|
|
|
printf("log_start = %08lx\n",
|
|
|
|
log->v2.start);
|
|
|
|
printf("log_end = %08lx\n", log->v2.end);
|
2012-02-15 06:21:07 +08:00
|
|
|
printf("log_con = %08lx\n", log->v2.con);
|
2012-02-15 06:21:06 +08:00
|
|
|
printf("logged_chars = %08lx\n",
|
|
|
|
log->v2.chars);
|
2007-04-18 18:55:19 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-02-15 06:21:06 +08:00
|
|
|
printf("log_start = %08lx\n",
|
|
|
|
log->v1.start);
|
|
|
|
printf("log_size = %08lx\n",
|
|
|
|
log->v1.size);
|
|
|
|
printf("logged_chars = %08lx\n",
|
|
|
|
log->v1.chars);
|
2007-04-18 18:55:19 +08:00
|
|
|
}
|
2002-11-06 00:35:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-11-06 00:35:14 +08:00
|
|
|
|
|
|
|
default:
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-11-06 00:35:14 +08:00
|
|
|
}
|
|
|
|
}
|
2007-04-18 18:55:19 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
log, 255, 1, do_log,
|
2009-01-28 08:03:12 +08:00
|
|
|
"manipulate logbuffer",
|
2003-07-01 00:24:52 +08:00
|
|
|
"info - show pointer details\n"
|
2003-06-28 05:31:46 +08:00
|
|
|
"log reset - clear contents\n"
|
|
|
|
"log show - show contents\n"
|
2009-05-24 23:06:54 +08:00
|
|
|
"log append <msg> - append <msg> to the logbuffer"
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
2007-04-18 18:55:19 +08:00
|
|
|
|
2002-11-06 00:35:14 +08:00
|
|
|
static int logbuff_printk(const char *line)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *msg, *p, *buf_end;
|
|
|
|
int line_feed;
|
|
|
|
static signed char msg_level = -1;
|
|
|
|
|
2012-02-15 06:21:06 +08:00
|
|
|
strcpy(buf + 3, line);
|
|
|
|
i = strlen(line);
|
2002-11-06 00:35:14 +08:00
|
|
|
buf_end = buf + 3 + i;
|
|
|
|
for (p = buf + 3; p < buf_end; p++) {
|
|
|
|
msg = p;
|
|
|
|
if (msg_level < 0) {
|
|
|
|
if (
|
|
|
|
p[0] != '<' ||
|
|
|
|
p[1] < '0' ||
|
|
|
|
p[1] > '7' ||
|
|
|
|
p[2] != '>'
|
|
|
|
) {
|
|
|
|
p -= 3;
|
|
|
|
p[0] = '<';
|
|
|
|
p[1] = default_message_loglevel + '0';
|
|
|
|
p[2] = '>';
|
2012-02-15 06:21:06 +08:00
|
|
|
} else {
|
2002-11-06 00:35:14 +08:00
|
|
|
msg += 3;
|
2012-02-15 06:21:06 +08:00
|
|
|
}
|
2002-11-06 00:35:14 +08:00
|
|
|
msg_level = p[1] - '0';
|
|
|
|
}
|
|
|
|
line_feed = 0;
|
|
|
|
for (; p < buf_end; p++) {
|
2007-04-18 18:55:19 +08:00
|
|
|
if (log_version == 2) {
|
2008-02-07 01:48:36 +08:00
|
|
|
lbuf[log->v2.end & LOGBUFF_MASK] = *p;
|
2007-04-18 18:55:19 +08:00
|
|
|
log->v2.end++;
|
|
|
|
if (log->v2.end - log->v2.start > LOGBUFF_LEN)
|
|
|
|
log->v2.start++;
|
|
|
|
log->v2.chars++;
|
2012-02-15 06:21:06 +08:00
|
|
|
} else {
|
2008-02-07 01:48:36 +08:00
|
|
|
lbuf[(log->v1.start + log->v1.size) &
|
2007-04-18 18:55:19 +08:00
|
|
|
LOGBUFF_MASK] = *p;
|
|
|
|
if (log->v1.size < LOGBUFF_LEN)
|
|
|
|
log->v1.size++;
|
|
|
|
else
|
|
|
|
log->v1.start++;
|
|
|
|
log->v1.chars++;
|
|
|
|
}
|
2002-11-06 00:35:14 +08:00
|
|
|
if (*p == '\n') {
|
|
|
|
line_feed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg_level < console_loglevel) {
|
|
|
|
printf("%s", msg);
|
|
|
|
}
|
|
|
|
if (line_feed)
|
|
|
|
msg_level = -1;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|