klog: correct initial buffer copy

This commit is contained in:
James Sullins
2012-01-02 18:05:41 -06:00
parent 65db0ecb90
commit f981c26cfd
2 changed files with 15 additions and 7 deletions

View File

@@ -38,6 +38,8 @@
#define KLOG_MAGIC 0x6b6c6f67 // 'klog' #define KLOG_MAGIC 0x6b6c6f67 // 'klog'
#define KLOG_VERSION 1 #define KLOG_VERSION 1
extern int log_buf_get_len(void);
struct klog_header { struct klog_header {
uint32_t magic; uint32_t magic;
uint32_t ver; uint32_t ver;
@@ -63,6 +65,8 @@ struct klog_buffer_header {
static unsigned long klog_phys; static unsigned long klog_phys;
static unsigned long klog_len; static unsigned long klog_len;
static int init_done = 0;
static char *klog_buffer; static char *klog_buffer;
static struct klog_header *klog; static struct klog_header *klog;
@@ -151,11 +155,7 @@ static void klog_copy_logbuf()
if (klog_buf == NULL) if (klog_buf == NULL)
return; return;
count = 4096; count = log_buf_get_len();
/* trim the write if it happens to be huge */
if (count > klog_buf->len - 1)
count = klog_buf->len - 1;
while (count > 0) { while (count > 0) {
/* write up to the end of the buffer */ /* write up to the end of the buffer */
@@ -215,7 +215,7 @@ void klog_write_char(const char c)
spin_lock_irqsave(&klog_lock, flags); spin_lock_irqsave(&klog_lock, flags);
_klog_write_char(c); if (init_done) _klog_write_char(c);
spin_unlock_irqrestore(&klog_lock, flags); spin_unlock_irqrestore(&klog_lock, flags);
} }
@@ -223,6 +223,7 @@ void klog_write_char(const char c)
static int __init klog_init(void) static int __init klog_init(void)
{ {
void *base; void *base;
unsigned long flags;
printk("klog_init: entry\n"); printk("klog_init: entry\n");
printk("klog_init: phys buffer is at 0x%lx\n", klog_phys); printk("klog_init: phys buffer is at 0x%lx\n", klog_phys);
@@ -254,8 +255,14 @@ static int __init klog_init(void)
klog_buf = get_kbuf(klog->current_buf); klog_buf = get_kbuf(klog->current_buf);
spin_lock_irqsave(&klog_lock, flags);
klog_copy_logbuf(); klog_copy_logbuf();
init_done = 1;
spin_unlock_irqrestore(&klog_lock, flags);
klog_printf("welcome to klog, buffer at %p, length %d\n", klog_buf, klog_buf->len); klog_printf("welcome to klog, buffer at %p, length %d\n", klog_buf, klog_buf->len);
return 0; return 0;

View File

@@ -297,10 +297,11 @@ static inline void boot_delay_msec(void)
/* /*
* Return the number of unread characters in the log buffer. * Return the number of unread characters in the log buffer.
*/ */
static int log_buf_get_len(void) int log_buf_get_len(void)
{ {
return logged_chars; return logged_chars;
} }
EXPORT_SYMBOL(log_buf_get_len);
/* /*
* Clears the ring-buffer * Clears the ring-buffer