2 kexec/arch/arm/kexec-zImage-arm.c | 259 ++++++++++++++++++++++++++++++++++++--
3 1 file changed, 252 insertions(+), 7 deletions(-)
5 Index: 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
8 +++ kexec-tools-1.101/kexec/arch/arm/kexec-zImage-arm.c
11 + * - 08/21/2007 ATAG support added by Uli Luckas <u.luckas@road.de>
22 +#include <arch/options.h>
23 #include "../../kexec.h"
25 +#define COMMAND_LINE_SIZE 1024
26 +#define BOOT_PARAMS_SIZE 1536
33 +/* The list must start with an ATAG_CORE node */
34 +#define ATAG_CORE 0x54410001
37 + uint32_t flags; /* bit 0 = read-only */
42 +/* it is allowed to have multiple ATAG_MEM nodes */
43 +#define ATAG_MEM 0x54410002
47 + uint32_t start; /* physical start address */
50 +/* describes where the compressed ramdisk image lives (virtual address) */
52 + * this one accidentally used virtual addresses - as such,
55 +#define ATAG_INITRD 0x54410005
57 +/* describes where the compressed ramdisk image lives (physical address) */
58 +#define ATAG_INITRD2 0x54420005
61 + uint32_t start; /* physical start address */
62 + uint32_t size; /* size of compressed ramdisk image in bytes */
65 +/* command line: \0 terminated string */
66 +#define ATAG_CMDLINE 0x54410009
69 + char cmdline[1]; /* this is the minimum size */
72 +/* The list ends with an ATAG_NONE node. */
73 +#define ATAG_NONE 0x00000000
76 + struct tag_header hdr;
78 + struct tag_core core;
79 + struct tag_mem32 mem;
80 + struct tag_initrd initrd;
81 + struct tag_cmdline cmdline;
85 +#define tag_next(t) ((struct tag *)((uint32_t *)(t) + (t)->hdr.size))
86 +#define byte_size(t) ((t)->hdr.size << 2)
87 +#define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type) + 3) >> 2)
89 int zImage_arm_probe(const char *buf, off_t len)
92 @@ -14,21 +85,194 @@ int zImage_arm_probe(const char *buf, of
97 void zImage_arm_usage(void)
99 + printf( " --command-line=STRING Set the kernel command line to STRING.\n"
100 + " --append=STRING Set the kernel command line to STRING.\n"
101 + " --initrd=FILE Use FILE as the kernel's initial ramdisk.\n"
102 + " --ramdisk=FILE Use FILE as the kernel's initial ramdisk.\n"
107 +struct tag * atag_read_tags(void)
109 + static unsigned long buf[BOOT_PARAMS_SIZE];
110 + const char fn[]= "/proc/atags";
112 + fp = fopen(fn, "r");
114 + fprintf(stderr, "Cannot open %s: %s\n",
115 + fn, strerror(errno));
119 + fread(buf, sizeof(buf[1]), BOOT_PARAMS_SIZE, fp);
121 + fprintf(stderr, "Cannot read %s: %s\n",
122 + fn, strerror(errno));
128 + return (struct tag *) buf;
133 +int atag_arm_load(struct kexec_info *info, unsigned long base,
134 + const char *command_line, off_t command_line_len,
135 + const char *initrd, off_t initrd_len)
137 + struct tag *saved_tags = atag_read_tags();
140 + struct tag *params;
141 + uint32_t *initrd_start;
143 + buf = xmalloc(getpagesize());
145 + fprintf(stderr, "Compiling ATAGs: out of memory\n");
149 + memset(buf, 0xff, getpagesize());
150 + params = (struct tag *)buf;
154 + saved_tags = (struct tag *) saved_tags;
155 + while(byte_size(saved_tags)) {
156 + switch (saved_tags->hdr.tag) {
164 + // copy all other tags
165 + memcpy(params, saved_tags, byte_size(saved_tags));
166 + params = tag_next(params);
168 + saved_tags = tag_next(saved_tags);
171 + params->hdr.size = 2;
172 + params->hdr.tag = ATAG_CORE;
173 + params = tag_next(params);
177 + params->hdr.size = tag_size(tag_initrd);
178 + params->hdr.tag = ATAG_INITRD2;
179 + initrd_start = ¶ms->u.initrd.start;
180 + params->u.initrd.size = initrd_len;
181 + params = tag_next(params);
184 + if (command_line) {
185 + params->hdr.size = (sizeof(struct tag_header) + command_line_len + 3) >> 2;
186 + params->hdr.tag = ATAG_CMDLINE;
187 + memcpy(params->u.cmdline.cmdline, command_line,
189 + params->u.cmdline.cmdline[command_line_len - 1] = '\0';
190 + params = tag_next(params);
193 + params->hdr.size = 0;
194 + params->hdr.tag = ATAG_NONE;
196 + len = ((char *)params - buf) + sizeof(struct tag_header);
198 + add_segment(info, buf, len, base, len);
201 + struct memory_range *range;
203 + get_memory_ranges(&range, &ranges);
204 + *initrd_start = locate_hole(info, initrd_len, getpagesize(), range[0].start + 0x800000, ULONG_MAX, INT_MAX);
205 + if (*initrd_start == ULONG_MAX)
207 + add_segment(info, initrd, initrd_len, *initrd_start, initrd_len);
212 -int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
214 +int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
215 struct kexec_info *info)
218 - unsigned int offset = 0x8000; /* 32k offset from memory start */
219 + unsigned int atag_offset = 0x1000; /* 4k offset from memory start */
220 + unsigned int offset = 0x8000; /* 32k offset from memory start */
221 + const char *command_line;
222 + off_t command_line_len;
223 + const char *ramdisk;
225 + off_t ramdisk_length;
227 +#define OPT_APPEND 'a'
228 +#define OPT_RAMDISK 'r'
229 + static const struct option options[] = {
231 + { "command-line", 1, 0, OPT_APPEND },
232 + { "append", 1, 0, OPT_APPEND },
233 + { "initrd", 1, 0, OPT_RAMDISK },
234 + { "ramdisk", 1, 0, OPT_RAMDISK },
237 + static const char short_options[] = KEXEC_ARCH_OPT_STR "a:r:";
240 + * Parse the command line arguments
243 + command_line_len = 0;
246 + ramdisk_length = 0;
247 + while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
250 + /* Ignore core options */
251 + if (opt < OPT_ARCH_MAX) {
258 + command_line = optarg;
265 + if (command_line) {
266 + command_line_len = strlen(command_line) + 1;
267 + if (command_line_len > COMMAND_LINE_SIZE)
268 + command_line_len = COMMAND_LINE_SIZE;
271 + ramdisk_buf = slurp_file(ramdisk, &ramdisk_length);
274 base = locate_hole(info,len+offset,0,0,ULONG_MAX,INT_MAX);
275 if (base == ULONG_MAX)
280 - add_segment(info,buf,len,base,len);
281 - info->entry = (void*)base;
283 + if (atag_arm_load(info, base + atag_offset,
284 + command_line, command_line_len,
285 + ramdisk_buf, ramdisk_length) == -1)
288 + add_segment(info, buf, len, base + offset, len);
290 + info->entry = (void*)base + offset;