• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Commit MetaInfo

Revision82114c493d497732f711ed041d82bdfccd492af1 (tree)
Time2014-03-10 23:02:06
AuthorYoshinori Sato <ysato@sa76...>
CommiterYoshinori Sato

Log Message

fix typo

Change Summary

Incremental Difference

--- a/main.c
+++ b/main.c
@@ -171,19 +171,20 @@ static int write_srec(FILE *fp, struct writeinfo_t *writeinfo, struct port_t *p)
171171 return r;
172172 }
173173
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,
176176 struct port_t *p)
177177 {
178178 unsigned char *romimage = NULL;
179179 unsigned int romsize;
180180 int fd;
181- int n;
181+ size_t n;
182182 int i;
183183 Elf *elf = NULL;
184184 GElf_Phdr phdr;
185185 unsigned long last_addr = 0;
186186 int ret = -1;
187+ size_t sz;
187188
188189 romsize = writeinfo->area.end - writeinfo->area.start + 1;
189190 romimage = (unsigned char *)malloc(romsize);
@@ -205,19 +206,22 @@ static int writefile_elf(FILE *fp, struct writeinfo_t *writeinfo,
205206 }
206207 elf_getphdrnum(elf, &n);
207208 for (i = 0; i < n; i++) {
208- if (gelf_getphdr(elf, &phdr) == NULL) {
209+ if (gelf_getphdr(elf, i, &phdr) == NULL) {
209210 fputs(elf_errmsg(-1), stderr);
210211 goto error;
211212 }
213+ if (phdr.p_type != PT_LOAD)
214+ continue ;
212215 if (verbose) {
213216 printf(" offset paddr size\n");
214217 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);
216219 }
217220 if (phdr.p_paddr < writeinfo->area.start ||
218221 (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));
221225 goto error;
222226 }
223227 lseek(fd, phdr.p_offset, SEEK_SET);
@@ -227,8 +231,8 @@ static int writefile_elf(FILE *fp, struct writeinfo_t *writeinfo,
227231 fputs("File read error", stderr);
228232 goto error;
229233 }
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;
232236 }
233237 writeinfo->area.end = last_addr;
234238 ret = write_rom(p, romimage, writeinfo);
@@ -267,10 +271,10 @@ static int writefile_to_rom(char *fn, int force_binary, struct writeinfo_t *writ
267271 }
268272 fseek(fp,0,SEEK_SET);
269273
270-#ifdef HAVE_ELF_H
274+#ifdef HAVE_GELF_H
271275 /* 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);
274278 #endif
275279 /* check 'S??' */
276280 if (force_binary ||