aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ixp4xx/patches-2.6.23/096-kexec_cmdline.patch
blob: d27a785789c155401d858c0995e0720367049b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Index: linux-2.6.23.17/kernel/ksysfs.c
===================================================================
--- linux-2.6.23.17.orig/kernel/ksysfs.c
+++ linux-2.6.23.17/kernel/ksysfs.c
@@ -49,6 +49,165 @@ KERNEL_ATTR_RW(uevent_helper);
 #endif
 
 #ifdef CONFIG_KEXEC
+
+#include <asm/setup.h>
+
+extern unsigned long kexec_boot_params;
+
+char kexec_cmdline[COMMAND_LINE_SIZE] = "";
+
+static void
+replace_cmdline_tag(void)
+{
+	char *t;
+	struct tag *real;
+	struct tag *copy;
+	struct tag *rend;
+	int i;
+
+/* TODO: check the return params */
+	t = kmalloc(KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE, GFP_KERNEL);
+	memset((void *)t, 0, KEXEC_BOOT_PARAMS_SIZE + COMMAND_LINE_SIZE);
+
+/* TODO: validate that the boot params are ATAGS, in fact */
+
+	copy = (struct tag *)t;
+	real = (struct tag *)kexec_boot_params;
+	rend = (struct tag *)(kexec_boot_params + KEXEC_BOOT_PARAMS_SIZE);
+	while ((real->hdr.size) && (real < rend)) {
+		if (real->hdr.tag != ATAG_CMDLINE) {
+			memcpy((void *)copy, (void *)real, real->hdr.size * 4);
+			copy = tag_next(copy);
+		}
+		real = tag_next(real);
+	}
+
+/* TODO: validate that we have enough space in the buffer */
+	
+	i = strlen(kexec_cmdline);
+	if (i) {
+		copy->hdr.tag = ATAG_CMDLINE;
+		copy->hdr.size = (sizeof(struct tag_header) + i + 1 + 4) >> 2;
+		strcpy(copy->u.cmdline.cmdline, kexec_cmdline);
+		copy = tag_next(copy);
+	}
+
+	copy->hdr.tag = ATAG_NONE;            /* Empty tag ends list */
+	copy->hdr.size = 0;                   /* zero length */
+
+/* TODO: validate that the temporary buffer isn't too full */
+
+	memcpy((void *)kexec_boot_params, (void *)t, KEXEC_BOOT_PARAMS_SIZE);
+
+	kfree(t);  /* Don't forget to free the big buffer we used */
+}
+
+static ssize_t kexec_cmdline_show(struct kset *kset, char *page)
+{
+	return sprintf(page, "%s\n", kexec_cmdline);
+}
+
+static ssize_t kexec_cmdline_store(struct kset *kset, const char *page,
+				   size_t count)
+{
+	if ((count + 1) > COMMAND_LINE_SIZE)
+		count = COMMAND_LINE_SIZE;
+	memcpy(kexec_cmdline, page, count);
+	kexec_cmdline[count] = '\0';
+	if (count && (kexec_cmdline[count - 1] == '\n'))
+		kexec_cmdline[count - 1] = '\0';
+	replace_cmdline_tag();
+	return count;
+}
+KERNEL_ATTR_RW(kexec_cmdline);
+
+static ssize_t kexec_boot_params_show(struct kset *kset, char *page)
+{
+	unsigned long *p;
+	char buf[PAGE_SIZE];
+	int keep_doing;
+
+	p = (unsigned long *)kexec_boot_params;
+
+	/* if this doesn't look like atags, just print first few words */
+	if (p[1] != ATAG_CORE)
+		return sprintf(page, "0x%lx 0x%lx 0x%lx 0x%lx\n",
+			       p[0], p[1], p[2], p[3]);
+
+	/* carefully walk the atag list, and print out the structure */
+	keep_doing = 1;
+	do {
+		switch (p[1]) {
+		case ATAG_CORE:
+			/* watch out, core tag is permitted to be empty */
+			if (p[0] == 5)
+				sprintf(buf,
+					"CORE flg=%ld pgsz=%ld rdev=0x%lx\n",
+					p[2], p[3], p[4]);
+			else
+				sprintf(buf,"CORE\n");
+			break;
+		case ATAG_MEM:
+			sprintf(buf,"MEM  %ldM@0x%lx\n", p[2] / (1024 * 1024),
+				p[3]);
+			break;
+		case ATAG_VIDEOTEXT:
+			sprintf(buf,"VIDEOTEXT sz=%ld\n", p[0]);
+			break;
+		case ATAG_RAMDISK:
+			sprintf(buf,"RAMDISK prmpt=%ld %ldK@0x%lx\n",
+				p[2], p[3], p[4]);
+			break;
+		case ATAG_INITRD2:
+			sprintf(buf,"INITRD2 %ldK@0x%lx\n", p[3] / 1024, p[2]);
+			break;
+		case ATAG_SERIAL:
+			sprintf(buf,"SERIAL high=0x%08lx low=0x%08lx\n",
+				p[3], p[2]);
+			break;
+		case ATAG_REVISION:
+			sprintf(buf,"REVISION rev=%ld\n", p[2]);
+			break;
+		case ATAG_VIDEOLFB:
+			sprintf(buf,"VIDEOLFB sz=%ld\n", p[0]);
+			break;
+		case ATAG_CMDLINE:
+			sprintf(buf,"CMD  \"%s\"\n", (char *)&p[2]);
+			break;
+		case ATAG_NONE:
+			sprintf(buf,"NONE\n");
+			keep_doing = 0;
+			break;
+		default:
+			sprintf(buf,"-unknown- sz=%ld\n", p[0]);
+			break;
+		}
+
+		/* carefully add to page */
+		if ((strlen(buf) + strlen(page)) < PAGE_SIZE) {
+			strcat(page, buf);
+		} else {
+			keep_doing = 0;
+		}
+
+		/* stop when we encounter a header length of 0 */
+		if (p[0] == 0)
+			keep_doing = 0;
+
+		/* go to the next tag */
+		p += p[0];
+
+		/* stop if we walked off the end of the buffer */
+		if (p > (unsigned long *)(kexec_boot_params +
+					  KEXEC_BOOT_PARAMS_SIZE))
+			keep_doing = 0;
+
+	} while (keep_doing);
+
+	return (strlen(page));
+}
+KERNEL_ATTR_RO(kexec_boot_params);
+
 static ssize_t kexec_loaded_show(struct kset *kset, char *page)
 {
 	return sprintf(page, "%d\n", !!kexec_image);
@@ -95,6 +254,8 @@ static struct attribute * kernel_attrs[]
 #ifdef CONFIG_KEXEC
 	&kexec_loaded_attr.attr,
 	&kexec_crash_loaded_attr.attr,
+	&kexec_cmdline_attr.attr,
+	&kexec_boot_params_attr.attr,
 #endif
 	NULL
 };