リビジョン | 82114c493d497732f711ed041d82bdfccd492af1 (tree) |
---|---|
日時 | 2014-03-10 23:02:06 |
作者 | Yoshinori Sato <ysato@sa76...> |
コミッター | Yoshinori Sato |
fix typo
@@ -171,19 +171,20 @@ static int write_srec(FILE *fp, struct writeinfo_t *writeinfo, struct port_t *p) | ||
171 | 171 | return r; |
172 | 172 | } |
173 | 173 | |
174 | -#ifdef HAVE_ELF_H | |
175 | -static int writefile_elf(FILE *fp, struct writeinfo_t *writeinfo, | |
174 | +#ifdef HAVE_GELF_H | |
175 | +static int write_elf(FILE *fp, struct writeinfo_t *writeinfo, | |
176 | 176 | struct port_t *p) |
177 | 177 | { |
178 | 178 | unsigned char *romimage = NULL; |
179 | 179 | unsigned int romsize; |
180 | 180 | int fd; |
181 | - int n; | |
181 | + size_t n; | |
182 | 182 | int i; |
183 | 183 | Elf *elf = NULL; |
184 | 184 | GElf_Phdr phdr; |
185 | 185 | unsigned long last_addr = 0; |
186 | 186 | int ret = -1; |
187 | + size_t sz; | |
187 | 188 | |
188 | 189 | romsize = writeinfo->area.end - writeinfo->area.start + 1; |
189 | 190 | romimage = (unsigned char *)malloc(romsize); |
@@ -205,19 +206,22 @@ static int writefile_elf(FILE *fp, struct writeinfo_t *writeinfo, | ||
205 | 206 | } |
206 | 207 | elf_getphdrnum(elf, &n); |
207 | 208 | for (i = 0; i < n; i++) { |
208 | - if (gelf_getphdr(elf, &phdr) == NULL) { | |
209 | + if (gelf_getphdr(elf, i, &phdr) == NULL) { | |
209 | 210 | fputs(elf_errmsg(-1), stderr); |
210 | 211 | goto error; |
211 | 212 | } |
213 | + if (phdr.p_type != PT_LOAD) | |
214 | + continue ; | |
212 | 215 | if (verbose) { |
213 | 216 | printf(" offset paddr size\n"); |
214 | 217 | printf("%d: %08x %08x %08x\n", |
215 | - n, phdr.p_offset, phdr.p_pddr, phdr,p_filesz); | |
218 | + i, phdr.p_offset, phdr.p_paddr, phdr.p_filesz); | |
216 | 219 | } |
217 | 220 | if (phdr.p_paddr < writeinfo->area.start || |
218 | 221 | (phdr.p_paddr + phdr.p_filesz) > writeinfo->area.end) { |
219 | - fprintf("%08x - %08x is out of rom", | |
220 | - phdr.p_pddr, phdr.p_pddr + phdr,p_filesz); | |
222 | + fprintf(stderr, "%08lx - %08lx is out of rom", | |
223 | + (unsigned long)phdr.p_paddr, | |
224 | + (unsigned long)(phdr.p_paddr + phdr.p_filesz)); | |
221 | 225 | goto error; |
222 | 226 | } |
223 | 227 | lseek(fd, phdr.p_offset, SEEK_SET); |
@@ -227,8 +231,8 @@ static int writefile_elf(FILE *fp, struct writeinfo_t *writeinfo, | ||
227 | 231 | fputs("File read error", stderr); |
228 | 232 | goto error; |
229 | 233 | } |
230 | - if (last_addr < (phdr.p_paddr + pdhr.filesz)) | |
231 | - last_addr = phdr.p_paddr + pdhr.filesz; | |
234 | + if (last_addr < (phdr.p_paddr + phdr.p_filesz)) | |
235 | + last_addr = phdr.p_paddr + phdr.p_filesz; | |
232 | 236 | } |
233 | 237 | writeinfo->area.end = last_addr; |
234 | 238 | ret = write_rom(p, romimage, writeinfo); |
@@ -267,10 +271,10 @@ static int writefile_to_rom(char *fn, int force_binary, struct writeinfo_t *writ | ||
267 | 271 | } |
268 | 272 | fseek(fp,0,SEEK_SET); |
269 | 273 | |
270 | -#ifdef HAVE_ELF_H | |
274 | +#ifdef HAVE_GELF_H | |
271 | 275 | /* check ELF */ |
272 | - if (!force_binary && memcmp(linebuf, "\x7fELF", 4) == 0) | |
273 | - return write_elf(fp, writeinfo, port) | |
276 | + if (!force_binary && memcmp(linebuf, ELFMAG, SELFMAG) == 0) | |
277 | + return write_elf(fp, writeinfo, port); | |
274 | 278 | #endif |
275 | 279 | /* check 'S??' */ |
276 | 280 | if (force_binary || |