diff options
author | Sam Ravnborg <sam@ravnborg.org> | 2011-01-04 06:39:15 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-04 22:25:05 -0500 |
commit | a020bb17b7046cd97ea6924ca99325b6e516bc2d (patch) | |
tree | cd88717b61fe4d86f3cf040a4a2669316b1206c3 /arch/sparc/boot | |
parent | 571e08f6e2ddd6ec5d547358f55342726c063072 (diff) |
sparc: add $BITS to piggyback arguments
Add new option to piggyback that identify if this is
for 32 or 64 bit.
Use this information to determine the alignment used.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/boot')
-rw-r--r-- | arch/sparc/boot/Makefile | 2 | ||||
-rw-r--r-- | arch/sparc/boot/piggyback_32.c | 45 |
2 files changed, 30 insertions, 17 deletions
diff --git a/arch/sparc/boot/Makefile b/arch/sparc/boot/Makefile index 97e3feb9ff1b..4c81fe59ab58 100644 --- a/arch/sparc/boot/Makefile +++ b/arch/sparc/boot/Makefile | |||
@@ -15,7 +15,7 @@ quiet_cmd_elftoaout = ELFTOAOUT $@ | |||
15 | 15 | ||
16 | ifeq ($(CONFIG_SPARC32),y) | 16 | ifeq ($(CONFIG_SPARC32),y) |
17 | quiet_cmd_piggy = PIGGY $@ | 17 | quiet_cmd_piggy = PIGGY $@ |
18 | cmd_piggy = $(obj)/piggyback_32 $@ System.map $(ROOT_IMG) | 18 | cmd_piggy = $(obj)/piggyback_32 $(BITS) $@ System.map $(ROOT_IMG) |
19 | quiet_cmd_btfix = BTFIX $@ | 19 | quiet_cmd_btfix = BTFIX $@ |
20 | cmd_btfix = $(OBJDUMP) -x vmlinux | $(obj)/btfixupprep > $@ | 20 | cmd_btfix = $(OBJDUMP) -x vmlinux | $(obj)/btfixupprep > $@ |
21 | quiet_cmd_sysmap = SYSMAP $(obj)/System.map | 21 | quiet_cmd_sysmap = SYSMAP $(obj)/System.map |
diff --git a/arch/sparc/boot/piggyback_32.c b/arch/sparc/boot/piggyback_32.c index 369634d8271e..c4b0843f56ad 100644 --- a/arch/sparc/boot/piggyback_32.c +++ b/arch/sparc/boot/piggyback_32.c | |||
@@ -38,6 +38,17 @@ | |||
38 | 38 | ||
39 | #define AOUT_TEXT_OFFSET 32 | 39 | #define AOUT_TEXT_OFFSET 32 |
40 | 40 | ||
41 | static int is64bit = 0; | ||
42 | |||
43 | /* align to power-of-two size */ | ||
44 | static int align(int n) | ||
45 | { | ||
46 | if (is64bit) | ||
47 | return (n + 0x1fff) & ~0x1fff; | ||
48 | else | ||
49 | return (n + 0xfff) & ~0xfff; | ||
50 | } | ||
51 | |||
41 | /* read two bytes as big endian */ | 52 | /* read two bytes as big endian */ |
42 | static unsigned short ld2(char *p) | 53 | static unsigned short ld2(char *p) |
43 | { | 54 | { |
@@ -62,7 +73,7 @@ static void die(const char *str) | |||
62 | static void usage(void) | 73 | static void usage(void) |
63 | { | 74 | { |
64 | /* fs_img.gz is an image of initial ramdisk. */ | 75 | /* fs_img.gz is an image of initial ramdisk. */ |
65 | fprintf(stderr, "Usage: piggyback vmlinux.aout System.map fs_img.gz\n"); | 76 | fprintf(stderr, "Usage: piggyback bits vmlinux.aout System.map fs_img.gz\n"); |
66 | fprintf(stderr, "\tKernel image will be modified in place.\n"); | 77 | fprintf(stderr, "\tKernel image will be modified in place.\n"); |
67 | exit(1); | 78 | exit(1); |
68 | } | 79 | } |
@@ -128,19 +139,21 @@ int main(int argc,char **argv) | |||
128 | struct stat s; | 139 | struct stat s; |
129 | int image, tail; | 140 | int image, tail; |
130 | 141 | ||
131 | if (argc != 4) | 142 | if (argc != 5) |
132 | usage(); | 143 | usage(); |
133 | if (stat (argv[3], &s) < 0) | 144 | if (strcmp(argv[1], "64") == 0) |
134 | die(argv[3]); | 145 | is64bit = 1; |
146 | if (stat (argv[4], &s) < 0) | ||
147 | die(argv[4]); | ||
135 | 148 | ||
136 | if (!get_start_end(argv[2], &start, &end)) { | 149 | if (!get_start_end(argv[3], &start, &end)) { |
137 | fprintf (stderr, "Could not determine start and end from %s\n", argv[2]); | 150 | fprintf (stderr, "Could not determine start and end from %s\n", argv[3]); |
138 | exit(1); | 151 | exit(1); |
139 | } | 152 | } |
140 | if ((image = open(argv[1], O_RDWR)) < 0) | 153 | if ((image = open(argv[2], O_RDWR)) < 0) |
141 | die(argv[1]); | 154 | die(argv[2]); |
142 | if (read(image, buffer, 512) != 512) | 155 | if (read(image, buffer, 512) != 512) |
143 | die(argv[1]); | 156 | die(argv[2]); |
144 | if (memcmp(buffer, aout_magic, 4) != 0) { | 157 | if (memcmp(buffer, aout_magic, 4) != 0) { |
145 | fprintf (stderr, "Not a.out. Don't blame me.\n"); | 158 | fprintf (stderr, "Not a.out. Don't blame me.\n"); |
146 | exit(1); | 159 | exit(1); |
@@ -157,7 +170,7 @@ int main(int argc,char **argv) | |||
157 | if (lseek(image, i, 0) < 0) | 170 | if (lseek(image, i, 0) < 0) |
158 | die("lseek"); | 171 | die("lseek"); |
159 | if (read(image, buffer, 1024) != 1024) | 172 | if (read(image, buffer, 1024) != 1024) |
160 | die(argv[1]); | 173 | die(argv[2]); |
161 | for (q = buffer, r = q + 512; q < r; q += 4) { | 174 | for (q = buffer, r = q + 512; q < r; q += 4) { |
162 | if (*q == 'H' && q[1] == 'd' && q[2] == 'r' && q[3] == 'S') | 175 | if (*q == 'H' && q[1] == 'd' && q[2] == 'r' && q[3] == 'S') |
163 | break; | 176 | break; |
@@ -179,20 +192,20 @@ int main(int argc,char **argv) | |||
179 | */ | 192 | */ |
180 | st4(buffer, 0); | 193 | st4(buffer, 0); |
181 | st4(buffer + 4, 0x01000000); | 194 | st4(buffer + 4, 0x01000000); |
182 | st4(buffer + 8, (end + 32 + 4095) & ~4095); | 195 | st4(buffer + 8, align(end + 32)); |
183 | st4(buffer + 12, s.st_size); | 196 | st4(buffer + 12, s.st_size); |
184 | 197 | ||
185 | if (write(image, buffer + 2, 14) != 14) | 198 | if (write(image, buffer + 2, 14) != 14) |
186 | die(argv[1]); | 199 | die(argv[2]); |
187 | 200 | ||
188 | /* seek page aligned boundary in the image file and add boot image */ | 201 | /* seek page aligned boundary in the image file and add boot image */ |
189 | if (lseek(image, AOUT_TEXT_OFFSET - start + ((end + 32 + 4095) & ~4095), 0) < 0) | 202 | if (lseek(image, AOUT_TEXT_OFFSET - start + align(end + 32), 0) < 0) |
190 | die("lseek"); | 203 | die("lseek"); |
191 | if ((tail = open(argv[3],O_RDONLY)) < 0) | 204 | if ((tail = open(argv[4], O_RDONLY)) < 0) |
192 | die(argv[3]); | 205 | die(argv[4]); |
193 | while ((i = read(tail, buffer, 1024)) > 0) | 206 | while ((i = read(tail, buffer, 1024)) > 0) |
194 | if (write(image, buffer, i) != i) | 207 | if (write(image, buffer, i) != i) |
195 | die(argv[1]); | 208 | die(argv[2]); |
196 | if (close(image) < 0) | 209 | if (close(image) < 0) |
197 | die("close"); | 210 | die("close"); |
198 | if (close(tail) < 0) | 211 | if (close(tail) < 0) |