xref: /linux/kernel/elfcorehdr.c (revision 2c44b67e)
1*2c44b67eSBaoquan He // SPDX-License-Identifier: GPL-2.0-only
2*2c44b67eSBaoquan He #include <linux/kernel.h>
3*2c44b67eSBaoquan He #include <linux/crash_dump.h>
4*2c44b67eSBaoquan He #include <linux/init.h>
5*2c44b67eSBaoquan He #include <linux/errno.h>
6*2c44b67eSBaoquan He #include <linux/export.h>
7*2c44b67eSBaoquan He 
8*2c44b67eSBaoquan He /*
9*2c44b67eSBaoquan He  * stores the physical address of elf header of crash image
10*2c44b67eSBaoquan He  *
11*2c44b67eSBaoquan He  * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
12*2c44b67eSBaoquan He  * is_kdump_kernel() to determine if we are booting after a panic. Hence put
13*2c44b67eSBaoquan He  * it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
14*2c44b67eSBaoquan He  */
15*2c44b67eSBaoquan He unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
16*2c44b67eSBaoquan He EXPORT_SYMBOL_GPL(elfcorehdr_addr);
17*2c44b67eSBaoquan He 
18*2c44b67eSBaoquan He /*
19*2c44b67eSBaoquan He  * stores the size of elf header of crash image
20*2c44b67eSBaoquan He  */
21*2c44b67eSBaoquan He unsigned long long elfcorehdr_size;
22*2c44b67eSBaoquan He 
23*2c44b67eSBaoquan He /*
24*2c44b67eSBaoquan He  * elfcorehdr= specifies the location of elf core header stored by the crashed
25*2c44b67eSBaoquan He  * kernel. This option will be passed by kexec loader to the capture kernel.
26*2c44b67eSBaoquan He  *
27*2c44b67eSBaoquan He  * Syntax: elfcorehdr=[size[KMG]@]offset[KMG]
28*2c44b67eSBaoquan He  */
setup_elfcorehdr(char * arg)29*2c44b67eSBaoquan He static int __init setup_elfcorehdr(char *arg)
30*2c44b67eSBaoquan He {
31*2c44b67eSBaoquan He 	char *end;
32*2c44b67eSBaoquan He 	if (!arg)
33*2c44b67eSBaoquan He 		return -EINVAL;
34*2c44b67eSBaoquan He 	elfcorehdr_addr = memparse(arg, &end);
35*2c44b67eSBaoquan He 	if (*end == '@') {
36*2c44b67eSBaoquan He 		elfcorehdr_size = elfcorehdr_addr;
37*2c44b67eSBaoquan He 		elfcorehdr_addr = memparse(end + 1, &end);
38*2c44b67eSBaoquan He 	}
39*2c44b67eSBaoquan He 	return end > arg ? 0 : -EINVAL;
40*2c44b67eSBaoquan He }
41*2c44b67eSBaoquan He early_param("elfcorehdr", setup_elfcorehdr);
42