diff options
Diffstat (limited to 'arch/mips/boot/addinitrd.c')
-rw-r--r-- | arch/mips/boot/addinitrd.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/arch/mips/boot/addinitrd.c b/arch/mips/boot/addinitrd.c index 8b3033304770..193e4be52e79 100644 --- a/arch/mips/boot/addinitrd.c +++ b/arch/mips/boot/addinitrd.c | |||
@@ -32,13 +32,13 @@ | |||
32 | 32 | ||
33 | #define SWAB(a) (swab ? swab32(a) : (a)) | 33 | #define SWAB(a) (swab ? swab32(a) : (a)) |
34 | 34 | ||
35 | void die (char *s) | 35 | void die(char *s) |
36 | { | 36 | { |
37 | perror (s); | 37 | perror(s); |
38 | exit (1); | 38 | exit(1); |
39 | } | 39 | } |
40 | 40 | ||
41 | int main (int argc, char *argv[]) | 41 | int main(int argc, char *argv[]) |
42 | { | 42 | { |
43 | int fd_vmlinux,fd_initrd,fd_outfile; | 43 | int fd_vmlinux,fd_initrd,fd_outfile; |
44 | FILHDR efile; | 44 | FILHDR efile; |
@@ -52,18 +52,18 @@ int main (int argc, char *argv[]) | |||
52 | int swab = 0; | 52 | int swab = 0; |
53 | 53 | ||
54 | if (argc != 4) { | 54 | if (argc != 4) { |
55 | printf ("Usage: %s <vmlinux> <initrd> <outfile>\n",argv[0]); | 55 | printf("Usage: %s <vmlinux> <initrd> <outfile>\n",argv[0]); |
56 | exit (1); | 56 | exit(1); |
57 | } | 57 | } |
58 | 58 | ||
59 | if ((fd_vmlinux = open (argv[1],O_RDONLY)) < 0) | 59 | if ((fd_vmlinux = open (argv[1],O_RDONLY)) < 0) |
60 | die ("open vmlinux"); | 60 | die("open vmlinux"); |
61 | if (read (fd_vmlinux, &efile, sizeof efile) != sizeof efile) | 61 | if (read (fd_vmlinux, &efile, sizeof efile) != sizeof efile) |
62 | die ("read file header"); | 62 | die("read file header"); |
63 | if (read (fd_vmlinux, &eaout, sizeof eaout) != sizeof eaout) | 63 | if (read (fd_vmlinux, &eaout, sizeof eaout) != sizeof eaout) |
64 | die ("read aout header"); | 64 | die("read aout header"); |
65 | if (read (fd_vmlinux, esecs, sizeof esecs) != sizeof esecs) | 65 | if (read (fd_vmlinux, esecs, sizeof esecs) != sizeof esecs) |
66 | die ("read section headers"); | 66 | die("read section headers"); |
67 | /* | 67 | /* |
68 | * check whether the file is good for us | 68 | * check whether the file is good for us |
69 | */ | 69 | */ |
@@ -82,13 +82,13 @@ int main (int argc, char *argv[]) | |||
82 | 82 | ||
83 | /* make sure we have an empty data segment for the initrd */ | 83 | /* make sure we have an empty data segment for the initrd */ |
84 | if (eaout.dsize || esecs[1].s_size) { | 84 | if (eaout.dsize || esecs[1].s_size) { |
85 | fprintf (stderr, "Data segment not empty. Giving up!\n"); | 85 | fprintf(stderr, "Data segment not empty. Giving up!\n"); |
86 | exit (1); | 86 | exit(1); |
87 | } | 87 | } |
88 | if ((fd_initrd = open (argv[2], O_RDONLY)) < 0) | 88 | if ((fd_initrd = open (argv[2], O_RDONLY)) < 0) |
89 | die ("open initrd"); | 89 | die("open initrd"); |
90 | if (fstat (fd_initrd, &st) < 0) | 90 | if (fstat (fd_initrd, &st) < 0) |
91 | die ("fstat initrd"); | 91 | die("fstat initrd"); |
92 | loadaddr = ((SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size) | 92 | loadaddr = ((SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size) |
93 | + MIPS_PAGE_SIZE-1) & ~MIPS_PAGE_MASK) - 8; | 93 | + MIPS_PAGE_SIZE-1) & ~MIPS_PAGE_MASK) - 8; |
94 | if (loadaddr < (SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size))) | 94 | if (loadaddr < (SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size))) |
@@ -99,33 +99,33 @@ int main (int argc, char *argv[]) | |||
99 | eaout.data_start = esecs[1].s_vaddr = esecs[1].s_paddr = SWAB(loadaddr); | 99 | eaout.data_start = esecs[1].s_vaddr = esecs[1].s_paddr = SWAB(loadaddr); |
100 | 100 | ||
101 | if ((fd_outfile = open (argv[3], O_RDWR|O_CREAT|O_TRUNC,0666)) < 0) | 101 | if ((fd_outfile = open (argv[3], O_RDWR|O_CREAT|O_TRUNC,0666)) < 0) |
102 | die ("open outfile"); | 102 | die("open outfile"); |
103 | if (write (fd_outfile, &efile, sizeof efile) != sizeof efile) | 103 | if (write (fd_outfile, &efile, sizeof efile) != sizeof efile) |
104 | die ("write file header"); | 104 | die("write file header"); |
105 | if (write (fd_outfile, &eaout, sizeof eaout) != sizeof eaout) | 105 | if (write (fd_outfile, &eaout, sizeof eaout) != sizeof eaout) |
106 | die ("write aout header"); | 106 | die("write aout header"); |
107 | if (write (fd_outfile, esecs, sizeof esecs) != sizeof esecs) | 107 | if (write (fd_outfile, esecs, sizeof esecs) != sizeof esecs) |
108 | die ("write section headers"); | 108 | die("write section headers"); |
109 | /* skip padding */ | 109 | /* skip padding */ |
110 | if(lseek(fd_vmlinux, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) | 110 | if(lseek(fd_vmlinux, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) |
111 | die ("lseek vmlinux"); | 111 | die("lseek vmlinux"); |
112 | if(lseek(fd_outfile, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) | 112 | if(lseek(fd_outfile, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) |
113 | die ("lseek outfile"); | 113 | die("lseek outfile"); |
114 | /* copy text segment */ | 114 | /* copy text segment */ |
115 | cnt = SWAB(eaout.tsize); | 115 | cnt = SWAB(eaout.tsize); |
116 | while (cnt) { | 116 | while (cnt) { |
117 | if ((i = read (fd_vmlinux, buf, sizeof buf)) <= 0) | 117 | if ((i = read (fd_vmlinux, buf, sizeof buf)) <= 0) |
118 | die ("read vmlinux"); | 118 | die("read vmlinux"); |
119 | if (write (fd_outfile, buf, i) != i) | 119 | if (write (fd_outfile, buf, i) != i) |
120 | die ("write vmlinux"); | 120 | die("write vmlinux"); |
121 | cnt -= i; | 121 | cnt -= i; |
122 | } | 122 | } |
123 | if (write (fd_outfile, initrd_header, sizeof initrd_header) != sizeof initrd_header) | 123 | if (write (fd_outfile, initrd_header, sizeof initrd_header) != sizeof initrd_header) |
124 | die ("write initrd header"); | 124 | die("write initrd header"); |
125 | while ((i = read (fd_initrd, buf, sizeof buf)) > 0) | 125 | while ((i = read (fd_initrd, buf, sizeof buf)) > 0) |
126 | if (write (fd_outfile, buf, i) != i) | 126 | if (write (fd_outfile, buf, i) != i) |
127 | die ("write initrd"); | 127 | die("write initrd"); |
128 | close (fd_vmlinux); | 128 | close(fd_vmlinux); |
129 | close (fd_initrd); | 129 | close(fd_initrd); |
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |