Skip to content

Commit

Permalink
staging: android: ram_console: pass in a boot info string
Browse files Browse the repository at this point in the history
Allow the board file to pass a boot info string through the
platform data that is appended to the /proc/last_kmsg file.

[moved the .h file to drivers/staging/android/ to be self-contained - gregkh]

Signed-off-by: Colin Cross <ccross@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Colin Cross authored and Greg Kroah-Hartman committed Nov 30, 2011
1 parent 2b37495 commit a6707f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
45 changes: 35 additions & 10 deletions drivers/staging/android/ram_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include "ram_console.h"

#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
#include <linux/rslib.h>
Expand Down Expand Up @@ -155,14 +156,20 @@ void ram_console_enable_console(int enabled)
}

static void __init
ram_console_save_old(struct ram_console_buffer *buffer, char *dest)
ram_console_save_old(struct ram_console_buffer *buffer, const char *bootinfo,
char *dest)
{
size_t old_log_size = buffer->size;
size_t bootinfo_size = 0;
size_t total_size = old_log_size;
char *ptr;
const char *bootinfo_label = "Boot info:\n";

#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
uint8_t *block;
uint8_t *par;
char strbuf[80];
int strbuf_len;
int strbuf_len = 0;

block = buffer->data;
par = ram_console_par_buffer;
Expand Down Expand Up @@ -197,11 +204,15 @@ ram_console_save_old(struct ram_console_buffer *buffer, char *dest)
"\nNo errors detected\n");
if (strbuf_len >= sizeof(strbuf))
strbuf_len = sizeof(strbuf) - 1;
old_log_size += strbuf_len;
total_size += strbuf_len;
#endif

if (bootinfo)
bootinfo_size = strlen(bootinfo) + strlen(bootinfo_label);
total_size += bootinfo_size;

if (dest == NULL) {
dest = kmalloc(old_log_size, GFP_KERNEL);
dest = kmalloc(total_size, GFP_KERNEL);
if (dest == NULL) {
printk(KERN_ERR
"ram_console: failed to allocate buffer\n");
Expand All @@ -210,19 +221,27 @@ ram_console_save_old(struct ram_console_buffer *buffer, char *dest)
}

ram_console_old_log = dest;
ram_console_old_log_size = old_log_size;
ram_console_old_log_size = total_size;
memcpy(ram_console_old_log,
&buffer->data[buffer->start], buffer->size - buffer->start);
memcpy(ram_console_old_log + buffer->size - buffer->start,
&buffer->data[0], buffer->start);
ptr = ram_console_old_log + old_log_size;
#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
memcpy(ram_console_old_log + old_log_size - strbuf_len,
strbuf, strbuf_len);
memcpy(ptr, strbuf, strbuf_len);
ptr += strbuf_len;
#endif
if (bootinfo) {
memcpy(ptr, bootinfo_label, strlen(bootinfo_label));
ptr += strlen(bootinfo_label);
memcpy(ptr, bootinfo, bootinfo_size);
ptr += bootinfo_size;
}
}

static int __init ram_console_init(struct ram_console_buffer *buffer,
size_t buffer_size, char *old_buf)
size_t buffer_size, const char *bootinfo,
char *old_buf)
{
#ifdef CONFIG_ANDROID_RAM_CONSOLE_ERROR_CORRECTION
int numerr;
Expand Down Expand Up @@ -289,7 +308,7 @@ static int __init ram_console_init(struct ram_console_buffer *buffer,
printk(KERN_INFO "ram_console: found existing buffer, "
"size %d, start %d\n",
buffer->size, buffer->start);
ram_console_save_old(buffer, old_buf);
ram_console_save_old(buffer, bootinfo, old_buf);
}
} else {
printk(KERN_INFO "ram_console: no valid data in buffer "
Expand All @@ -313,6 +332,7 @@ static int __init ram_console_early_init(void)
return ram_console_init((struct ram_console_buffer *)
CONFIG_ANDROID_RAM_CONSOLE_EARLY_ADDR,
CONFIG_ANDROID_RAM_CONSOLE_EARLY_SIZE,
NULL,
ram_console_old_log_init_buffer);
}
#else
Expand All @@ -322,6 +342,8 @@ static int ram_console_driver_probe(struct platform_device *pdev)
size_t start;
size_t buffer_size;
void *buffer;
const char *bootinfo = NULL;
struct ram_console_platform_data *pdata = pdev->dev.platform_data;

if (res == NULL || pdev->num_resources != 1 ||
!(res->flags & IORESOURCE_MEM)) {
Expand All @@ -339,7 +361,10 @@ static int ram_console_driver_probe(struct platform_device *pdev)
return -ENOMEM;
}

return ram_console_init(buffer, buffer_size, NULL/* allocate */);
if (pdata)
bootinfo = pdata->bootinfo;

return ram_console_init(buffer, buffer_size, bootinfo, NULL/* allocate */);
}

static struct platform_driver ram_console_driver = {
Expand Down
22 changes: 22 additions & 0 deletions drivers/staging/android/ram_console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/

#ifndef _INCLUDE_LINUX_PLATFORM_DATA_RAM_CONSOLE_H_
#define _INCLUDE_LINUX_PLATFORM_DATA_RAM_CONSOLE_H_

struct ram_console_platform_data {
const char *bootinfo;
};

#endif /* _INCLUDE_LINUX_PLATFORM_DATA_RAM_CONSOLE_H_ */

0 comments on commit a6707f8

Please sign in to comment.