summaryrefslogtreecommitdiffstats
path: root/meta/packages/kexec
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2007-12-27 14:50:27 +0000
committerRichard Purdie <richard@openedhand.com>2007-12-27 14:50:27 +0000
commita5b44fe6a5f3b3b083a7bd3db8054664f6cf2bdd (patch)
tree633d87b69cc4ff3477b0273acf57ce17adea3efd /meta/packages/kexec
parenta34ccf9ec4f1837c280d96e78a2e5c227c715a81 (diff)
downloadpoky-a5b44fe6a5f3b3b083a7bd3db8054664f6cf2bdd.tar.gz
kexec-tools: Add arm atags support
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@3383 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/packages/kexec')
-rw-r--r--meta/packages/kexec/kexec-tools-1.101/kexec-arm-atags.patch294
-rw-r--r--meta/packages/kexec/kexec-tools_1.101.bb5
2 files changed, 297 insertions, 2 deletions
diff --git a/meta/packages/kexec/kexec-tools-1.101/kexec-arm-atags.patch b/meta/packages/kexec/kexec-tools-1.101/kexec-arm-atags.patch
new file mode 100644
index 0000000000..bf6f640035
--- /dev/null
+++ b/meta/packages/kexec/kexec-tools-1.101/kexec-arm-atags.patch
@@ -0,0 +1,294 @@
1---
2 kexec/arch/arm/kexec-zImage-arm.c | 259 ++++++++++++++++++++++++++++++++++++--
3 1 file changed, 252 insertions(+), 7 deletions(-)
4
5Index: kexec-tools-1.101/kexec/arch/arm/kexec-zImage-arm.c
6===================================================================
7--- kexec-tools-1.101.orig/kexec/arch/arm/kexec-zImage-arm.c 2007-12-26 21:17:07.000000000 +0000
8+++ kexec-tools-1.101/kexec/arch/arm/kexec-zImage-arm.c 2007-12-27 01:24:25.000000000 +0000
9@@ -1,11 +1,83 @@
10+/*
11+ * - 08/21/2007 ATAG support added by Uli Luckas <u.luckas@road.de>
12+ *
13+ */
14 #define _GNU_SOURCE
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <limits.h>
20+#include <stdint.h>
21+#include <getopt.h>
22+#include <arch/options.h>
23+#include <asm/page.h>
24 #include "../../kexec.h"
25
26+#define COMMAND_LINE_SIZE 1024
27+#define BOOT_PARAMS_SIZE 1536
28+
29+struct tag_header {
30+ uint32_t size;
31+ uint32_t tag;
32+};
33+
34+/* The list must start with an ATAG_CORE node */
35+#define ATAG_CORE 0x54410001
36+
37+struct tag_core {
38+ uint32_t flags; /* bit 0 = read-only */
39+ uint32_t pagesize;
40+ uint32_t rootdev;
41+};
42+
43+/* it is allowed to have multiple ATAG_MEM nodes */
44+#define ATAG_MEM 0x54410002
45+
46+struct tag_mem32 {
47+ uint32_t size;
48+ uint32_t start; /* physical start address */
49+};
50+
51+/* describes where the compressed ramdisk image lives (virtual address) */
52+/*
53+ * this one accidentally used virtual addresses - as such,
54+ * it's deprecated.
55+ */
56+#define ATAG_INITRD 0x54410005
57+
58+/* describes where the compressed ramdisk image lives (physical address) */
59+#define ATAG_INITRD2 0x54420005
60+
61+struct tag_initrd {
62+ uint32_t start; /* physical start address */
63+ uint32_t size; /* size of compressed ramdisk image in bytes */
64+};
65+
66+/* command line: \0 terminated string */
67+#define ATAG_CMDLINE 0x54410009
68+
69+struct tag_cmdline {
70+ char cmdline[1]; /* this is the minimum size */
71+};
72+
73+/* The list ends with an ATAG_NONE node. */
74+#define ATAG_NONE 0x00000000
75+
76+struct tag {
77+ struct tag_header hdr;
78+ union {
79+ struct tag_core core;
80+ struct tag_mem32 mem;
81+ struct tag_initrd initrd;
82+ struct tag_cmdline cmdline;
83+ } u;
84+};
85+
86+#define tag_next(t) ((struct tag *)((uint32_t *)(t) + (t)->hdr.size))
87+#define byte_size(t) ((t)->hdr.size << 2)
88+#define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type) + 3) >> 2)
89+
90 int zImage_arm_probe(const char *buf, off_t len)
91 {
92 /*
93@@ -14,21 +86,194 @@ int zImage_arm_probe(const char *buf, of
94 */
95 return 0;
96 }
97+
98 void zImage_arm_usage(void)
99 {
100+ printf( " --command-line=STRING Set the kernel command line to STRING.\n"
101+ " --append=STRING Set the kernel command line to STRING.\n"
102+ " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n"
103+ " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n"
104+ );
105 }
106-int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
107+
108+static
109+struct tag * atag_read_tags(void)
110+{
111+ static unsigned long buf[BOOT_PARAMS_SIZE];
112+ const char fn[]= "/proc/atags";
113+ FILE *fp;
114+ fp = fopen(fn, "r");
115+ if (!fp) {
116+ fprintf(stderr, "Cannot open %s: %s\n",
117+ fn, strerror(errno));
118+ return NULL;
119+ }
120+
121+ fread(buf, sizeof(buf[1]), BOOT_PARAMS_SIZE, fp);
122+ if (ferror(fp)) {
123+ fprintf(stderr, "Cannot read %s: %s\n",
124+ fn, strerror(errno));
125+ fclose(fp);
126+ return NULL;
127+ }
128+
129+ fclose(fp);
130+ return (struct tag *) buf;
131+}
132+
133+
134+static
135+int atag_arm_load(struct kexec_info *info, unsigned long base,
136+ const char *command_line, off_t command_line_len,
137+ const char *initrd, off_t initrd_len)
138+{
139+ struct tag *saved_tags = atag_read_tags();
140+ char *buf;
141+ off_t len;
142+ struct tag *params;
143+ uint32_t *initrd_start;
144+
145+ buf = xmalloc(getpagesize());
146+ if (!buf) {
147+ fprintf(stderr, "Compiling ATAGs: out of memory\n");
148+ return -1;
149+ }
150+
151+ memset(buf, 0xff, getpagesize());
152+ params = (struct tag *)buf;
153+
154+ if (saved_tags) {
155+ // Copy tags
156+ saved_tags = (struct tag *) saved_tags;
157+ while(byte_size(saved_tags)) {
158+ switch (saved_tags->hdr.tag) {
159+ case ATAG_INITRD:
160+ case ATAG_INITRD2:
161+ case ATAG_CMDLINE:
162+ case ATAG_NONE:
163+ // skip these tags
164+ break;
165+ default:
166+ // copy all other tags
167+ memcpy(params, saved_tags, byte_size(saved_tags));
168+ params = tag_next(params);
169+ }
170+ saved_tags = tag_next(saved_tags);
171+ }
172+ } else {
173+ params->hdr.size = 2;
174+ params->hdr.tag = ATAG_CORE;
175+ params = tag_next(params);
176+ }
177+
178+ if (initrd) {
179+ params->hdr.size = tag_size(tag_initrd);
180+ params->hdr.tag = ATAG_INITRD2;
181+ initrd_start = &params->u.initrd.start;
182+ params->u.initrd.size = initrd_len;
183+ params = tag_next(params);
184+ }
185+
186+ if (command_line) {
187+ params->hdr.size = (sizeof(struct tag_header) + command_line_len + 3) >> 2;
188+ params->hdr.tag = ATAG_CMDLINE;
189+ memcpy(params->u.cmdline.cmdline, command_line,
190+ command_line_len);
191+ params->u.cmdline.cmdline[command_line_len - 1] = '\0';
192+ params = tag_next(params);
193+ }
194+
195+ params->hdr.size = 0;
196+ params->hdr.tag = ATAG_NONE;
197+
198+ len = ((char *)params - buf) + sizeof(struct tag_header);
199+
200+ add_segment(info, buf, len, base, len);
201+
202+ if (initrd) {
203+ struct memory_range *range;
204+ int ranges;
205+ get_memory_ranges(&range, &ranges);
206+ *initrd_start = locate_hole(info, initrd_len, getpagesize(), range[0].start + 0x800000, ULONG_MAX, INT_MAX);
207+ if (*initrd_start == ULONG_MAX)
208+ return -1;
209+ add_segment(info, initrd, initrd_len, *initrd_start, initrd_len);
210+ }
211+
212+ return 0;
213+}
214+
215+int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
216 struct kexec_info *info)
217 {
218 unsigned long base;
219- unsigned int offset = 0x8000; /* 32k offset from memory start */
220+ unsigned int atag_offset = 0x1000; /* 4k offset from memory start */
221+ unsigned int offset = 0x8000; /* 32k offset from memory start */
222+ const char *command_line;
223+ off_t command_line_len;
224+ const char *ramdisk;
225+ char *ramdisk_buf;
226+ off_t ramdisk_length;
227+ int opt;
228+#define OPT_APPEND 'a'
229+#define OPT_RAMDISK 'r'
230+ static const struct option options[] = {
231+ KEXEC_ARCH_OPTIONS
232+ { "command-line", 1, 0, OPT_APPEND },
233+ { "append", 1, 0, OPT_APPEND },
234+ { "initrd", 1, 0, OPT_RAMDISK },
235+ { "ramdisk", 1, 0, OPT_RAMDISK },
236+ { 0, 0, 0, 0 },
237+ };
238+ static const char short_options[] = KEXEC_ARCH_OPT_STR "a:r:";
239+
240+ /*
241+ * Parse the command line arguments
242+ */
243+ command_line = 0;
244+ command_line_len = 0;
245+ ramdisk = 0;
246+ ramdisk_buf = 0;
247+ ramdisk_length = 0;
248+ while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
249+ switch(opt) {
250+ default:
251+ /* Ignore core options */
252+ if (opt < OPT_ARCH_MAX) {
253+ break;
254+ }
255+ case '?':
256+ usage();
257+ return -1;
258+ case OPT_APPEND:
259+ command_line = optarg;
260+ break;
261+ case OPT_RAMDISK:
262+ ramdisk = optarg;
263+ break;
264+ }
265+ }
266+ if (command_line) {
267+ command_line_len = strlen(command_line) + 1;
268+ if (command_line_len > COMMAND_LINE_SIZE)
269+ command_line_len = COMMAND_LINE_SIZE;
270+ }
271+ if (ramdisk) {
272+ ramdisk_buf = slurp_file(ramdisk, &ramdisk_length);
273+ }
274+
275 base = locate_hole(info,len+offset,0,0,ULONG_MAX,INT_MAX);
276 if (base == ULONG_MAX)
277- {
278 return -1;
279- }
280- base += offset;
281- add_segment(info,buf,len,base,len);
282- info->entry = (void*)base;
283+
284+ if (atag_arm_load(info, base + atag_offset,
285+ command_line, command_line_len,
286+ ramdisk_buf, ramdisk_length) == -1)
287+ return -1;
288+
289+ add_segment(info, buf, len, base + offset, len);
290+
291+ info->entry = (void*)base + offset;
292+
293 return 0;
294 }
diff --git a/meta/packages/kexec/kexec-tools_1.101.bb b/meta/packages/kexec/kexec-tools_1.101.bb
index 1d64ec8305..d152a678ed 100644
--- a/meta/packages/kexec/kexec-tools_1.101.bb
+++ b/meta/packages/kexec/kexec-tools_1.101.bb
@@ -4,7 +4,7 @@ HOMEPAGE = "http://www.xmission.com/~ebiederm/files/kexec/"
4SECTION = "kernel/userland" 4SECTION = "kernel/userland"
5DEPENDS = "virtual/kernel zlib" 5DEPENDS = "virtual/kernel zlib"
6LICENSE = "GPL" 6LICENSE = "GPL"
7PR = "r2" 7PR = "r3"
8 8
9inherit autotools 9inherit autotools
10 10
@@ -12,4 +12,5 @@ export LDFLAGS = "-L${STAGING_LIBDIR}"
12EXTRA_OECONF = " --with-zlib=yes" 12EXTRA_OECONF = " --with-zlib=yes"
13 13
14SRC_URI = "http://www.xmission.com/~ebiederm/files/kexec/kexec-tools-${PV}.tar.gz \ 14SRC_URI = "http://www.xmission.com/~ebiederm/files/kexec/kexec-tools-${PV}.tar.gz \
15 file://kexec-tools-arm.patch;patch=1 " 15 file://kexec-tools-arm.patch;patch=1 \
16 file://kexec-arm-atags.patch;patch=1"