[package] libpcap: explicitely disable libnl support to prevent different build resul...
[openwrt.git] / target / linux / generic / patches-3.1 / 930-crashlog.patch
1 --- /dev/null
2 +++ b/include/linux/crashlog.h
3 @@ -0,0 +1,12 @@
4 +#ifndef __CRASHLOG_H
5 +#define __CRASHLOG_H
6 +
7 +#ifdef CONFIG_CRASHLOG
8 +void __init crashlog_init_mem(struct bootmem_data *bdata);
9 +#else
10 +static inline void crashlog_init_mem(struct bootmem_data *bdata)
11 +{
12 +}
13 +#endif
14 +
15 +#endif
16 --- a/init/Kconfig
17 +++ b/init/Kconfig
18 @@ -879,6 +879,10 @@ config RELAY
19
20 If unsure, say N.
21
22 +config CRASHLOG
23 + bool "Crash logging"
24 + depends on !NO_BOOTMEM && !HAVE_MEMBLOCK
25 +
26 config BLK_DEV_INITRD
27 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
28 depends on BROKEN || !FRV
29 --- a/kernel/Makefile
30 +++ b/kernel/Makefile
31 @@ -108,6 +108,7 @@ obj-$(CONFIG_USER_RETURN_NOTIFIER) += us
32 obj-$(CONFIG_PADATA) += padata.o
33 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
34 obj-$(CONFIG_JUMP_LABEL) += jump_label.o
35 +obj-$(CONFIG_CRASHLOG) += crashlog.o
36
37 ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
38 # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
39 --- /dev/null
40 +++ b/kernel/crashlog.c
41 @@ -0,0 +1,171 @@
42 +/*
43 + * Crash information logger
44 + * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
45 + *
46 + * Based on ramoops.c
47 + * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
48 + *
49 + * This program is free software; you can redistribute it and/or
50 + * modify it under the terms of the GNU General Public License
51 + * version 2 as published by the Free Software Foundation.
52 + *
53 + * This program is distributed in the hope that it will be useful, but
54 + * WITHOUT ANY WARRANTY; without even the implied warranty of
55 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
56 + * General Public License for more details.
57 + *
58 + * You should have received a copy of the GNU General Public License
59 + * along with this program; if not, write to the Free Software
60 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
61 + * 02110-1301 USA
62 + *
63 + */
64 +
65 +#include <linux/module.h>
66 +#include <linux/bootmem.h>
67 +#include <linux/debugfs.h>
68 +#include <linux/crashlog.h>
69 +#include <linux/kmsg_dump.h>
70 +#include <linux/module.h>
71 +#include <linux/pfn.h>
72 +#include <asm/io.h>
73 +
74 +#define CRASHLOG_PAGES 4
75 +#define CRASHLOG_SIZE (CRASHLOG_PAGES * PAGE_SIZE)
76 +#define CRASHLOG_MAGIC 0xa1eedead
77 +
78 +/*
79 + * Start the log at 1M before the end of RAM, as some boot loaders like
80 + * to use the end of the RAM for stack usage and other things
81 + * If this fails, fall back to using the last part.
82 + */
83 +#define CRASHLOG_OFFSET (1024 * 1024)
84 +
85 +struct crashlog_data {
86 + u32 magic;
87 + u32 len;
88 + u8 data[];
89 +};
90 +
91 +static struct debugfs_blob_wrapper crashlog_blob;
92 +static unsigned long crashlog_addr = 0;
93 +static struct crashlog_data *crashlog_buf;
94 +static struct kmsg_dumper dump;
95 +static bool first = true;
96 +
97 +extern struct list_head *crashlog_modules;
98 +
99 +void __init crashlog_init_mem(bootmem_data_t *bdata)
100 +{
101 + unsigned long addr;
102 +
103 + if (crashlog_addr)
104 + return;
105 +
106 + addr = PFN_PHYS(bdata->node_low_pfn) - CRASHLOG_OFFSET;
107 + if (reserve_bootmem(addr, CRASHLOG_SIZE, BOOTMEM_EXCLUSIVE) < 0) {
108 + printk("Crashlog failed to allocate RAM at address 0x%lx\n", addr);
109 + bdata->node_low_pfn -= CRASHLOG_PAGES;
110 + addr = PFN_PHYS(bdata->node_low_pfn);
111 + }
112 + crashlog_addr = addr;
113 +}
114 +
115 +static void __init crashlog_copy(void)
116 +{
117 + if (crashlog_buf->magic != CRASHLOG_MAGIC)
118 + return;
119 +
120 + if (!crashlog_buf->len || crashlog_buf->len >
121 + CRASHLOG_SIZE - sizeof(*crashlog_buf))
122 + return;
123 +
124 + crashlog_blob.size = crashlog_buf->len;
125 + crashlog_blob.data = kmemdup(crashlog_buf->data,
126 + crashlog_buf->len, GFP_KERNEL);
127 +
128 + debugfs_create_blob("crashlog", 0700, NULL, &crashlog_blob);
129 +}
130 +
131 +static int get_maxlen(void)
132 +{
133 + return CRASHLOG_SIZE - sizeof(*crashlog_buf) - crashlog_buf->len;
134 +}
135 +
136 +static void crashlog_printf(const char *fmt, ...)
137 +{
138 + va_list args;
139 + int len = get_maxlen();
140 +
141 + if (!len)
142 + return;
143 +
144 + va_start(args, fmt);
145 + crashlog_buf->len += vsnprintf(
146 + &crashlog_buf->data[crashlog_buf->len],
147 + len, fmt, args);
148 + va_end(args);
149 +}
150 +
151 +static void crashlog_do_dump(struct kmsg_dumper *dumper,
152 + enum kmsg_dump_reason reason, const char *s1, unsigned long l1,
153 + const char *s2, unsigned long l2)
154 +{
155 + unsigned long s1_start, s2_start;
156 + unsigned long l1_cpy, l2_cpy;
157 + struct timeval tv;
158 + struct module *m;
159 + char *buf;
160 + int len;
161 +
162 + if (!first)
163 + crashlog_printf("\n===================================\n");
164 +
165 + do_gettimeofday(&tv);
166 + crashlog_printf("Time: %lu.%lu\n",
167 + (long)tv.tv_sec, (long)tv.tv_usec);
168 +
169 + if (first) {
170 + crashlog_printf("Modules:");
171 + list_for_each_entry(m, crashlog_modules, list) {
172 + crashlog_printf("\t%s@%p+%x", m->name,
173 + m->module_core, m->core_size,
174 + m->module_init, m->init_size);
175 + }
176 + crashlog_printf("\n");
177 + first = false;
178 + }
179 +
180 + buf = (char *)&crashlog_buf->data[crashlog_buf->len];
181 + len = get_maxlen();
182 +
183 + l2_cpy = min(l2, (unsigned long)len);
184 + l1_cpy = min(l1, (unsigned long)len - l2_cpy);
185 +
186 + s2_start = l2 - l2_cpy;
187 + s1_start = l1 - l1_cpy;
188 +
189 + memcpy(buf, s1 + s1_start, l1_cpy);
190 + memcpy(buf + l1_cpy, s2 + s2_start, l2_cpy);
191 + crashlog_buf->len += l1_cpy + l2_cpy;
192 +}
193 +
194 +
195 +int __init crashlog_init_fs(void)
196 +{
197 + if (!crashlog_addr)
198 + return -ENOMEM;
199 +
200 + crashlog_buf = ioremap(crashlog_addr, CRASHLOG_SIZE);
201 +
202 + crashlog_copy();
203 +
204 + crashlog_buf->magic = CRASHLOG_MAGIC;
205 + crashlog_buf->len = 0;
206 +
207 + dump.dump = crashlog_do_dump;
208 + kmsg_dump_register(&dump);
209 +
210 + return 0;
211 +}
212 +module_init(crashlog_init_fs);
213 --- a/mm/bootmem.c
214 +++ b/mm/bootmem.c
215 @@ -15,6 +15,7 @@
216 #include <linux/module.h>
217 #include <linux/kmemleak.h>
218 #include <linux/range.h>
219 +#include <linux/crashlog.h>
220 #include <linux/memblock.h>
221
222 #include <asm/bug.h>
223 @@ -178,6 +179,7 @@ static unsigned long __init free_all_boo
224 if (!bdata->node_bootmem_map)
225 return 0;
226
227 + crashlog_init_mem(bdata);
228 start = bdata->node_min_pfn;
229 end = bdata->node_low_pfn;
230
231 --- a/kernel/module.c
232 +++ b/kernel/module.c
233 @@ -107,6 +107,9 @@ static LIST_HEAD(modules);
234 #ifdef CONFIG_KGDB_KDB
235 struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
236 #endif /* CONFIG_KGDB_KDB */
237 +#ifdef CONFIG_CRASHLOG
238 +struct list_head *crashlog_modules = &modules;
239 +#endif
240
241
242 /* Block module loading/unloading? */
This page took 0.050305 seconds and 5 git commands to generate.