xref: /openbmc/linux/kernel/configs.c (revision 884caada)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * kernel/configs.c
4  * Echo the kernel .config file used to build the kernel
5  *
6  * Copyright (C) 2002 Khalid Aziz <khalid_aziz@hp.com>
7  * Copyright (C) 2002 Randy Dunlap <rdunlap@xenotime.net>
8  * Copyright (C) 2002 Al Stone <ahs3@fc.hp.com>
9  * Copyright (C) 2002 Hewlett-Packard Company
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/init.h>
17 #include <linux/uaccess.h>
18 
19 /*
20  * "IKCFG_ST" and "IKCFG_ED" are used to extract the config data from
21  * a binary kernel image or a module. See scripts/extract-ikconfig.
22  */
23 asm (
24 "	.pushsection .rodata, \"a\"		\n"
25 "	.ascii \"IKCFG_ST\"			\n"
26 "	.global kernel_config_data		\n"
27 "kernel_config_data:				\n"
28 "	.incbin \"kernel/config_data.gz\"	\n"
29 "	.global kernel_config_data_end		\n"
30 "kernel_config_data_end:			\n"
31 "	.ascii \"IKCFG_ED\"			\n"
32 "	.popsection				\n"
33 );
34 
35 #ifdef CONFIG_IKCONFIG_PROC
36 
37 extern char kernel_config_data;
38 extern char kernel_config_data_end;
39 
40 static ssize_t
41 ikconfig_read_current(struct file *file, char __user *buf,
42 		      size_t len, loff_t * offset)
43 {
44 	return simple_read_from_buffer(buf, len, offset,
45 				       &kernel_config_data,
46 				       &kernel_config_data_end -
47 				       &kernel_config_data);
48 }
49 
50 static const struct file_operations ikconfig_file_ops = {
51 	.owner = THIS_MODULE,
52 	.read = ikconfig_read_current,
53 	.llseek = default_llseek,
54 };
55 
56 static int __init ikconfig_init(void)
57 {
58 	struct proc_dir_entry *entry;
59 
60 	/* create the current config file */
61 	entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
62 			    &ikconfig_file_ops);
63 	if (!entry)
64 		return -ENOMEM;
65 
66 	proc_set_size(entry, &kernel_config_data_end - &kernel_config_data);
67 
68 	return 0;
69 }
70 
71 static void __exit ikconfig_cleanup(void)
72 {
73 	remove_proc_entry("config.gz", NULL);
74 }
75 
76 module_init(ikconfig_init);
77 module_exit(ikconfig_cleanup);
78 
79 #endif /* CONFIG_IKCONFIG_PROC */
80 
81 MODULE_LICENSE("GPL");
82 MODULE_AUTHOR("Randy Dunlap");
83 MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel");
84