diff options
Diffstat (limited to 'arch/ppc/boot/utils')
-rw-r--r-- | arch/ppc/boot/utils/.gitignore | 3 | ||||
-rw-r--r-- | arch/ppc/boot/utils/elf.pl | 33 | ||||
-rw-r--r-- | arch/ppc/boot/utils/mkbugboot.c | 147 | ||||
-rw-r--r-- | arch/ppc/boot/utils/mkprep.c | 241 | ||||
-rw-r--r-- | arch/ppc/boot/utils/mktree.c | 152 |
5 files changed, 0 insertions, 576 deletions
diff --git a/arch/ppc/boot/utils/.gitignore b/arch/ppc/boot/utils/.gitignore deleted file mode 100644 index bbdfb3b9c532..000000000000 --- a/arch/ppc/boot/utils/.gitignore +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | mkprep | ||
2 | mkbugboot | ||
3 | mktree | ||
diff --git a/arch/ppc/boot/utils/elf.pl b/arch/ppc/boot/utils/elf.pl deleted file mode 100644 index d3e9d9d5b84e..000000000000 --- a/arch/ppc/boot/utils/elf.pl +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | # | ||
2 | # ELF header field numbers | ||
3 | # | ||
4 | |||
5 | $e_ident = 0; # Identification bytes / magic number | ||
6 | $e_type = 1; # ELF file type | ||
7 | $e_machine = 2; # Target machine type | ||
8 | $e_version = 3; # File version | ||
9 | $e_entry = 4; # Start address | ||
10 | $e_phoff = 5; # Program header file offset | ||
11 | $e_shoff = 6; # Section header file offset | ||
12 | $e_flags = 7; # File flags | ||
13 | $e_ehsize = 8; # Size of ELF header | ||
14 | $e_phentsize = 9; # Size of program header | ||
15 | $e_phnum = 10; # Number of program header entries | ||
16 | $e_shentsize = 11; # Size of section header | ||
17 | $e_shnum = 12; # Number of section header entries | ||
18 | $e_shstrndx = 13; # Section header table string index | ||
19 | |||
20 | # | ||
21 | # Section header field numbers | ||
22 | # | ||
23 | |||
24 | $sh_name = 0; # Section name | ||
25 | $sh_type = 1; # Section header type | ||
26 | $sh_flags = 2; # Section header flags | ||
27 | $sh_addr = 3; # Virtual address | ||
28 | $sh_offset = 4; # File offset | ||
29 | $sh_size = 5; # Section size | ||
30 | $sh_link = 6; # Miscellaneous info | ||
31 | $sh_info = 7; # More miscellaneous info | ||
32 | $sh_addralign = 8; # Memory alignment | ||
33 | $sh_entsize = 9; # Entry size if this is a table | ||
diff --git a/arch/ppc/boot/utils/mkbugboot.c b/arch/ppc/boot/utils/mkbugboot.c deleted file mode 100644 index 1640c4199ca6..000000000000 --- a/arch/ppc/boot/utils/mkbugboot.c +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* | ||
2 | * Makes a Motorola PPCBUG ROM bootable image which can be flashed | ||
3 | * into one of the FLASH banks on a Motorola PowerPlus board. | ||
4 | * | ||
5 | * Author: Matt Porter <mporter@mvista.com> | ||
6 | * | ||
7 | * 2001 (c) MontaVista, Software, Inc. This file is licensed under | ||
8 | * the terms of the GNU General Public License version 2. This program | ||
9 | * is licensed "as is" without any warranty of any kind, whether express | ||
10 | * or implied. | ||
11 | */ | ||
12 | |||
13 | #define ELF_HEADER_SIZE 65536 | ||
14 | |||
15 | #include <unistd.h> | ||
16 | #include <sys/stat.h> | ||
17 | #include <string.h> | ||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <errno.h> | ||
21 | #include <fcntl.h> | ||
22 | #include <netinet/in.h> | ||
23 | #ifdef __sun__ | ||
24 | #include <inttypes.h> | ||
25 | #else | ||
26 | #include <stdint.h> | ||
27 | #endif | ||
28 | |||
29 | /* size of read buffer */ | ||
30 | #define SIZE 0x1000 | ||
31 | |||
32 | /* PPCBUG ROM boot header */ | ||
33 | typedef struct bug_boot_header { | ||
34 | uint8_t magic_word[4]; /* "BOOT" */ | ||
35 | uint32_t entry_offset; /* Offset from top of header to code */ | ||
36 | uint32_t routine_length; /* Length of code */ | ||
37 | uint8_t routine_name[8]; /* Name of the boot code */ | ||
38 | } bug_boot_header_t; | ||
39 | |||
40 | #define HEADER_SIZE sizeof(bug_boot_header_t) | ||
41 | |||
42 | void update_checksum(void *buf, size_t size, uint16_t *sum) | ||
43 | { | ||
44 | uint32_t csum = *sum; | ||
45 | |||
46 | while (size) { | ||
47 | csum += *(uint16_t *)buf; | ||
48 | if (csum > 0xffff) | ||
49 | csum -= 0xffff; | ||
50 | buf = (uint16_t *)buf + 1; | ||
51 | size -= 2; | ||
52 | } | ||
53 | *sum = csum; | ||
54 | } | ||
55 | |||
56 | uint32_t copy_image(int in_fd, int out_fd, uint16_t *sum) | ||
57 | { | ||
58 | uint8_t buf[SIZE]; | ||
59 | int offset = 0; | ||
60 | int n; | ||
61 | uint32_t image_size = 0; | ||
62 | |||
63 | lseek(in_fd, ELF_HEADER_SIZE, SEEK_SET); | ||
64 | |||
65 | /* Copy an image while recording its size */ | ||
66 | while ( (n = read(in_fd, buf + offset, SIZE - offset)) > 0 ) { | ||
67 | n += offset; | ||
68 | offset = n & 1; | ||
69 | n -= offset; | ||
70 | image_size = image_size + n; | ||
71 | /* who's going to deal with short writes? */ | ||
72 | write(out_fd, buf, n); | ||
73 | update_checksum(buf, n, sum); | ||
74 | if (offset) | ||
75 | buf[0] = buf[n]; | ||
76 | } | ||
77 | |||
78 | /* BUG romboot requires that our size is divisible by 2 */ | ||
79 | /* align image to 2 byte boundary */ | ||
80 | if (offset) { | ||
81 | image_size += 2; | ||
82 | buf[1] = '\0'; | ||
83 | write(out_fd, buf, 2); | ||
84 | update_checksum(buf, 2, sum); | ||
85 | } | ||
86 | return image_size; | ||
87 | } | ||
88 | |||
89 | void write_bugboot_header(int out_fd, uint32_t boot_size, uint16_t *sum) | ||
90 | { | ||
91 | static bug_boot_header_t bbh = { | ||
92 | .magic_word = "BOOT", | ||
93 | .routine_name = "LINUXROM" | ||
94 | }; | ||
95 | |||
96 | /* Fill in the PPCBUG ROM boot header */ | ||
97 | bbh.entry_offset = htonl(HEADER_SIZE); /* Entry address */ | ||
98 | bbh.routine_length= htonl(HEADER_SIZE+boot_size+2); /* Routine length */ | ||
99 | |||
100 | /* Output the header and bootloader to the file */ | ||
101 | write(out_fd, &bbh, sizeof(bug_boot_header_t)); | ||
102 | update_checksum(&bbh, sizeof(bug_boot_header_t), sum); | ||
103 | } | ||
104 | |||
105 | int main(int argc, char *argv[]) | ||
106 | { | ||
107 | int image_fd, bugboot_fd; | ||
108 | uint32_t kernel_size = 0; | ||
109 | uint16_t checksum = 0; | ||
110 | |||
111 | if (argc != 3) { | ||
112 | fprintf(stderr, "usage: %s <kernel_image> <bugboot>\n",argv[0]); | ||
113 | exit(-1); | ||
114 | } | ||
115 | |||
116 | /* Get file args */ | ||
117 | |||
118 | /* kernel image file */ | ||
119 | if ((image_fd = open(argv[1] , 0)) < 0) | ||
120 | exit(-1); | ||
121 | |||
122 | /* bugboot file */ | ||
123 | if (!strcmp(argv[2], "-")) | ||
124 | bugboot_fd = 1; /* stdout */ | ||
125 | else if ((bugboot_fd = creat(argv[2] , 0755)) < 0) | ||
126 | exit(-1); | ||
127 | |||
128 | /* Set file position after ROM header block where zImage will be written */ | ||
129 | lseek(bugboot_fd, HEADER_SIZE, SEEK_SET); | ||
130 | |||
131 | /* Copy kernel image into bugboot image */ | ||
132 | kernel_size = copy_image(image_fd, bugboot_fd, &checksum); | ||
133 | |||
134 | /* Set file position to beginning where header/romboot will be written */ | ||
135 | lseek(bugboot_fd, 0, SEEK_SET); | ||
136 | |||
137 | /* Write out BUG header/romboot */ | ||
138 | write_bugboot_header(bugboot_fd, kernel_size, &checksum); | ||
139 | |||
140 | /* Write out the calculated checksum */ | ||
141 | lseek(bugboot_fd, 0, SEEK_END); | ||
142 | write(bugboot_fd, &checksum, 2); | ||
143 | |||
144 | /* Close bugboot file */ | ||
145 | close(bugboot_fd); | ||
146 | return 0; | ||
147 | } | ||
diff --git a/arch/ppc/boot/utils/mkprep.c b/arch/ppc/boot/utils/mkprep.c deleted file mode 100644 index 192bb397126f..000000000000 --- a/arch/ppc/boot/utils/mkprep.c +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | /* | ||
2 | * Makes a prep bootable image which can be dd'd onto | ||
3 | * a disk device to make a bootdisk. Will take | ||
4 | * as input a elf executable, strip off the header | ||
5 | * and write out a boot image as: | ||
6 | * 1) default - strips elf header | ||
7 | * suitable as a network boot image | ||
8 | * 2) -pbp - strips elf header and writes out prep boot partition image | ||
9 | * cat or dd onto disk for booting | ||
10 | * 3) -asm - strips elf header and writes out as asm data | ||
11 | * useful for generating data for a compressed image | ||
12 | * -- Cort | ||
13 | * | ||
14 | * Modified for x86 hosted builds by Matt Porter <porter@neta.com> | ||
15 | * Modified for Sparc hosted builds by Peter Wahl <PeterWahl@web.de> | ||
16 | */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | #include <string.h> | ||
20 | #include <stdlib.h> | ||
21 | |||
22 | /* size of read buffer */ | ||
23 | #define SIZE 0x1000 | ||
24 | |||
25 | /* | ||
26 | * Partition table entry | ||
27 | * - from the PReP spec | ||
28 | */ | ||
29 | typedef struct partition_entry { | ||
30 | unsigned char boot_indicator; | ||
31 | unsigned char starting_head; | ||
32 | unsigned char starting_sector; | ||
33 | unsigned char starting_cylinder; | ||
34 | |||
35 | unsigned char system_indicator; | ||
36 | unsigned char ending_head; | ||
37 | unsigned char ending_sector; | ||
38 | unsigned char ending_cylinder; | ||
39 | |||
40 | unsigned char beginning_sector[4]; | ||
41 | unsigned char number_of_sectors[4]; | ||
42 | } partition_entry_t; | ||
43 | |||
44 | #define BootActive 0x80 | ||
45 | #define SystemPrep 0x41 | ||
46 | |||
47 | void copy_image(FILE *, FILE *); | ||
48 | void write_prep_partition(FILE *, FILE *); | ||
49 | void write_asm_data(FILE *, FILE *); | ||
50 | |||
51 | unsigned int elfhdr_size = 65536; | ||
52 | |||
53 | int main(int argc, char *argv[]) | ||
54 | { | ||
55 | FILE *in, *out; | ||
56 | int argptr = 1; | ||
57 | int prep = 0; | ||
58 | int asmoutput = 0; | ||
59 | |||
60 | if (argc < 3 || argc > 4) { | ||
61 | fprintf(stderr, "usage: %s [-pbp] [-asm] <boot-file> <image>\n", | ||
62 | argv[0]); | ||
63 | exit(-1); | ||
64 | } | ||
65 | |||
66 | /* needs to handle args more elegantly -- but this is a small/simple program */ | ||
67 | |||
68 | /* check for -pbp */ | ||
69 | if (!strcmp(argv[argptr], "-pbp")) { | ||
70 | prep = 1; | ||
71 | argptr++; | ||
72 | } | ||
73 | |||
74 | /* check for -asm */ | ||
75 | if (!strcmp(argv[argptr], "-asm")) { | ||
76 | asmoutput = 1; | ||
77 | argptr++; | ||
78 | } | ||
79 | |||
80 | /* input file */ | ||
81 | if (!strcmp(argv[argptr], "-")) | ||
82 | in = stdin; | ||
83 | else if (!(in = fopen(argv[argptr], "r"))) | ||
84 | exit(-1); | ||
85 | argptr++; | ||
86 | |||
87 | /* output file */ | ||
88 | if (!strcmp(argv[argptr], "-")) | ||
89 | out = stdout; | ||
90 | else if (!(out = fopen(argv[argptr], "w"))) | ||
91 | exit(-1); | ||
92 | argptr++; | ||
93 | |||
94 | /* skip elf header in input file */ | ||
95 | /*if ( !prep )*/ | ||
96 | fseek(in, elfhdr_size, SEEK_SET); | ||
97 | |||
98 | /* write prep partition if necessary */ | ||
99 | if (prep) | ||
100 | write_prep_partition(in, out); | ||
101 | |||
102 | /* write input image to bootimage */ | ||
103 | if (asmoutput) | ||
104 | write_asm_data(in, out); | ||
105 | else | ||
106 | copy_image(in, out); | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | void store_le32(unsigned int v, unsigned char *p) | ||
112 | { | ||
113 | p[0] = v; | ||
114 | p[1] = v >>= 8; | ||
115 | p[2] = v >>= 8; | ||
116 | p[3] = v >> 8; | ||
117 | } | ||
118 | |||
119 | void write_prep_partition(FILE *in, FILE *out) | ||
120 | { | ||
121 | unsigned char block[512]; | ||
122 | partition_entry_t pe; | ||
123 | unsigned char *entry = block; | ||
124 | unsigned char *length = block + 4; | ||
125 | long pos = ftell(in), size; | ||
126 | |||
127 | if (fseek(in, 0, SEEK_END) < 0) { | ||
128 | fprintf(stderr,"info failed\n"); | ||
129 | exit(-1); | ||
130 | } | ||
131 | size = ftell(in); | ||
132 | if (fseek(in, pos, SEEK_SET) < 0) { | ||
133 | fprintf(stderr,"info failed\n"); | ||
134 | exit(-1); | ||
135 | } | ||
136 | |||
137 | memset(block, '\0', sizeof(block)); | ||
138 | |||
139 | /* set entry point and boot image size skipping over elf header */ | ||
140 | store_le32(0x400/*+65536*/, entry); | ||
141 | store_le32(size-elfhdr_size+0x400, length); | ||
142 | |||
143 | /* sets magic number for msdos partition (used by linux) */ | ||
144 | block[510] = 0x55; | ||
145 | block[511] = 0xAA; | ||
146 | |||
147 | /* | ||
148 | * Build a "PReP" partition table entry in the boot record | ||
149 | * - "PReP" may only look at the system_indicator | ||
150 | */ | ||
151 | pe.boot_indicator = BootActive; | ||
152 | pe.system_indicator = SystemPrep; | ||
153 | /* | ||
154 | * The first block of the diskette is used by this "boot record" which | ||
155 | * actually contains the partition table. (The first block of the | ||
156 | * partition contains the boot image, but I digress...) We'll set up | ||
157 | * one partition on the diskette and it shall contain the rest of the | ||
158 | * diskette. | ||
159 | */ | ||
160 | pe.starting_head = 0; /* zero-based */ | ||
161 | pe.starting_sector = 2; /* one-based */ | ||
162 | pe.starting_cylinder = 0; /* zero-based */ | ||
163 | pe.ending_head = 1; /* assumes two heads */ | ||
164 | pe.ending_sector = 18; /* assumes 18 sectors/track */ | ||
165 | pe.ending_cylinder = 79; /* assumes 80 cylinders/diskette */ | ||
166 | |||
167 | /* | ||
168 | * The "PReP" software ignores the above fields and just looks at | ||
169 | * the next two. | ||
170 | * - size of the diskette is (assumed to be) | ||
171 | * (2 tracks/cylinder)(18 sectors/tracks)(80 cylinders/diskette) | ||
172 | * - unlike the above sector numbers, the beginning sector is zero-based! | ||
173 | */ | ||
174 | #if 0 | ||
175 | store_le32(1, pe.beginning_sector); | ||
176 | #else | ||
177 | /* This has to be 0 on the PowerStack? */ | ||
178 | store_le32(0, pe.beginning_sector); | ||
179 | #endif | ||
180 | |||
181 | store_le32(2*18*80-1, pe.number_of_sectors); | ||
182 | |||
183 | memcpy(&block[0x1BE], &pe, sizeof(pe)); | ||
184 | |||
185 | fwrite(block, sizeof(block), 1, out); | ||
186 | fwrite(entry, 4, 1, out); | ||
187 | fwrite(length, 4, 1, out); | ||
188 | /* set file position to 2nd sector where image will be written */ | ||
189 | fseek( out, 0x400, SEEK_SET ); | ||
190 | } | ||
191 | |||
192 | |||
193 | |||
194 | void copy_image(FILE *in, FILE *out) | ||
195 | { | ||
196 | char buf[SIZE]; | ||
197 | int n; | ||
198 | |||
199 | while ( (n = fread(buf, 1, SIZE, in)) > 0 ) | ||
200 | fwrite(buf, 1, n, out); | ||
201 | } | ||
202 | |||
203 | |||
204 | void | ||
205 | write_asm_data(FILE *in, FILE *out) | ||
206 | { | ||
207 | int i, cnt, pos = 0; | ||
208 | unsigned int cksum = 0, val; | ||
209 | unsigned char *lp; | ||
210 | unsigned char buf[SIZE]; | ||
211 | size_t len; | ||
212 | |||
213 | fputs("\t.data\n\t.globl input_data\ninput_data:\n", out); | ||
214 | while ((len = fread(buf, 1, sizeof(buf), in)) > 0) { | ||
215 | cnt = 0; | ||
216 | lp = buf; | ||
217 | /* Round up to longwords */ | ||
218 | while (len & 3) | ||
219 | buf[len++] = '\0'; | ||
220 | for (i = 0; i < len; i += 4) { | ||
221 | if (cnt == 0) | ||
222 | fputs("\t.long\t", out); | ||
223 | fprintf(out, "0x%02X%02X%02X%02X", | ||
224 | lp[0], lp[1], lp[2], lp[3]); | ||
225 | val = *(unsigned long *)lp; | ||
226 | cksum ^= val; | ||
227 | lp += 4; | ||
228 | if (++cnt == 4) { | ||
229 | cnt = 0; | ||
230 | fprintf(out, " # %x \n", pos+i-12); | ||
231 | } else { | ||
232 | fputs(",", out); | ||
233 | } | ||
234 | } | ||
235 | if (cnt) | ||
236 | fputs("0\n", out); | ||
237 | pos += len; | ||
238 | } | ||
239 | fprintf(out, "\t.globl input_len\ninput_len:\t.long\t0x%x\n", pos); | ||
240 | fprintf(stderr, "cksum = %x\n", cksum); | ||
241 | } | ||
diff --git a/arch/ppc/boot/utils/mktree.c b/arch/ppc/boot/utils/mktree.c deleted file mode 100644 index 2be22e28f2b3..000000000000 --- a/arch/ppc/boot/utils/mktree.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* | ||
2 | * Makes a tree bootable image for IBM Evaluation boards. | ||
3 | * Basically, just take a zImage, skip the ELF header, and stuff | ||
4 | * a 32 byte header on the front. | ||
5 | * | ||
6 | * We use htonl, which is a network macro, to make sure we're doing | ||
7 | * The Right Thing on an LE machine. It's non-obvious, but it should | ||
8 | * work on anything BSD'ish. | ||
9 | */ | ||
10 | |||
11 | #include <fcntl.h> | ||
12 | #include <stdio.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | #include <sys/stat.h> | ||
16 | #include <unistd.h> | ||
17 | #include <netinet/in.h> | ||
18 | #ifdef __sun__ | ||
19 | #include <inttypes.h> | ||
20 | #else | ||
21 | #include <stdint.h> | ||
22 | #endif | ||
23 | |||
24 | /* This gets tacked on the front of the image. There are also a few | ||
25 | * bytes allocated after the _start label used by the boot rom (see | ||
26 | * head.S for details). | ||
27 | */ | ||
28 | typedef struct boot_block { | ||
29 | uint32_t bb_magic; /* 0x0052504F */ | ||
30 | uint32_t bb_dest; /* Target address of the image */ | ||
31 | uint32_t bb_num_512blocks; /* Size, rounded-up, in 512 byte blks */ | ||
32 | uint32_t bb_debug_flag; /* Run debugger or image after load */ | ||
33 | uint32_t bb_entry_point; /* The image address to start */ | ||
34 | uint32_t bb_checksum; /* 32 bit checksum including header */ | ||
35 | uint32_t reserved[2]; | ||
36 | } boot_block_t; | ||
37 | |||
38 | #define IMGBLK 512 | ||
39 | char tmpbuf[IMGBLK]; | ||
40 | |||
41 | int main(int argc, char *argv[]) | ||
42 | { | ||
43 | int in_fd, out_fd; | ||
44 | int nblks, i; | ||
45 | uint cksum, *cp; | ||
46 | struct stat st; | ||
47 | boot_block_t bt; | ||
48 | |||
49 | if (argc < 3) { | ||
50 | fprintf(stderr, "usage: %s <zImage-file> <boot-image> [entry-point]\n",argv[0]); | ||
51 | exit(1); | ||
52 | } | ||
53 | |||
54 | if (stat(argv[1], &st) < 0) { | ||
55 | perror("stat"); | ||
56 | exit(2); | ||
57 | } | ||
58 | |||
59 | nblks = (st.st_size + IMGBLK) / IMGBLK; | ||
60 | |||
61 | bt.bb_magic = htonl(0x0052504F); | ||
62 | |||
63 | /* If we have the optional entry point parameter, use it */ | ||
64 | if (argc == 4) | ||
65 | bt.bb_dest = bt.bb_entry_point = htonl(strtoul(argv[3], NULL, 0)); | ||
66 | else | ||
67 | bt.bb_dest = bt.bb_entry_point = htonl(0x500000); | ||
68 | |||
69 | /* We know these from the linker command. | ||
70 | * ...and then move it up into memory a little more so the | ||
71 | * relocation can happen. | ||
72 | */ | ||
73 | bt.bb_num_512blocks = htonl(nblks); | ||
74 | bt.bb_debug_flag = 0; | ||
75 | |||
76 | bt.bb_checksum = 0; | ||
77 | |||
78 | /* To be neat and tidy :-). | ||
79 | */ | ||
80 | bt.reserved[0] = 0; | ||
81 | bt.reserved[1] = 0; | ||
82 | |||
83 | if ((in_fd = open(argv[1], O_RDONLY)) < 0) { | ||
84 | perror("zImage open"); | ||
85 | exit(3); | ||
86 | } | ||
87 | |||
88 | if ((out_fd = open(argv[2], (O_RDWR | O_CREAT | O_TRUNC), 0666)) < 0) { | ||
89 | perror("bootfile open"); | ||
90 | exit(3); | ||
91 | } | ||
92 | |||
93 | cksum = 0; | ||
94 | cp = (void *)&bt; | ||
95 | for (i=0; i<sizeof(bt)/sizeof(uint); i++) | ||
96 | cksum += *cp++; | ||
97 | |||
98 | /* Assume zImage is an ELF file, and skip the 64K header. | ||
99 | */ | ||
100 | if (read(in_fd, tmpbuf, IMGBLK) != IMGBLK) { | ||
101 | fprintf(stderr, "%s is too small to be an ELF image\n", | ||
102 | argv[1]); | ||
103 | exit(4); | ||
104 | } | ||
105 | |||
106 | if ((*(uint *)tmpbuf) != htonl(0x7f454c46)) { | ||
107 | fprintf(stderr, "%s is not an ELF image\n", argv[1]); | ||
108 | exit(4); | ||
109 | } | ||
110 | |||
111 | if (lseek(in_fd, (64 * 1024), SEEK_SET) < 0) { | ||
112 | fprintf(stderr, "%s failed to seek in ELF image\n", argv[1]); | ||
113 | exit(4); | ||
114 | } | ||
115 | |||
116 | nblks -= (64 * 1024) / IMGBLK; | ||
117 | |||
118 | /* And away we go...... | ||
119 | */ | ||
120 | if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) { | ||
121 | perror("boot-image write"); | ||
122 | exit(5); | ||
123 | } | ||
124 | |||
125 | while (nblks-- > 0) { | ||
126 | if (read(in_fd, tmpbuf, IMGBLK) < 0) { | ||
127 | perror("zImage read"); | ||
128 | exit(5); | ||
129 | } | ||
130 | cp = (uint *)tmpbuf; | ||
131 | for (i=0; i<sizeof(tmpbuf)/sizeof(uint); i++) | ||
132 | cksum += *cp++; | ||
133 | if (write(out_fd, tmpbuf, sizeof(tmpbuf)) != sizeof(tmpbuf)) { | ||
134 | perror("boot-image write"); | ||
135 | exit(5); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | /* rewrite the header with the computed checksum. | ||
140 | */ | ||
141 | bt.bb_checksum = htonl(cksum); | ||
142 | if (lseek(out_fd, 0, SEEK_SET) < 0) { | ||
143 | perror("rewrite seek"); | ||
144 | exit(1); | ||
145 | } | ||
146 | if (write(out_fd, &bt, sizeof(bt)) != sizeof(bt)) { | ||
147 | perror("boot-image rewrite"); | ||
148 | exit(1); | ||
149 | } | ||
150 | |||
151 | exit(0); | ||
152 | } | ||