OSDN Git Service

program mode の出力文字列の修正
authorsato_tiff <sato_tiff@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 29 Dec 2008 13:05:07 +0000 (13:05 +0000)
committersato_tiff <sato_tiff@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 29 Dec 2008 13:05:07 +0000 (13:05 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@222 24ea1065-a21e-4ca1-99c9-f5125deb0858

client/trunk/flashmemory.c
client/trunk/script.c

index 3067060..34e3c17 100644 (file)
@@ -192,21 +192,11 @@ static int polling_check(const struct flash_order *d, long address, u8 truedata)
        return NG;
 }
 
-static void bootblock_lockout(const struct flash_order *d)
-{
-       u8 dummy[3];
-       command_set(d, PP);
-       d->read(0x8000 ,3, dummy);
-       printf("%02x %02x %02x \n", dummy[0], dummy[1], dummy[2]);
-       d->read(0xfff2 ,1, dummy);
-       command_set(d, PRODUCTID_EXIT);
-}
 /*
 ---- erase ----
 */
 static void flash_erase_chip(const struct flash_order *d)
 {
-       if(0) bootblock_lockout(d);
        command_set(d, ERASE_CHIP);
        toggle_check(d, d->command_2aaa);
        Sleep(200); //Tec 0.2 sec
@@ -222,6 +212,7 @@ static void sram_erase(const struct flash_order *d)
 /*
 ---- program ----
 */
+#define dprintf if(DEBUG==1) printf
 static int program_byte(const struct flash_order *d, long address, const u8 *data, long length)
 {
        int retry = 0;
@@ -231,9 +222,7 @@ static int program_byte(const struct flash_order *d, long address, const u8 *dat
                        command_set(d, PROTECT_DISABLE);
                        d->flash_write(address, *data);
                        if(toggle_check(d, address) == NG){
-                               if(DEBUG == 1){
-                                       printf("%s NG\n", __FUNCTION__);
-                               }
+                               dprintf("%s NG\n", __FUNCTION__);
                                return NG;
                        }
                }
@@ -245,11 +234,14 @@ static int program_byte(const struct flash_order *d, long address, const u8 *dat
                        length--;
                        retry = 0;
                }else if(retry > 8){
-                       printf("%s %06x error\n", __FUNCTION__, (int) address);
+                       dprintf("%s %06x error\n", __FUNCTION__, (int) address);
                        address++;
                        data++;
                        length--;
                        retry = 0;
+                       if(DEBUG == 0){
+                               return NG;
+                       }
                }else{
                        retry++;
                }
@@ -270,7 +262,6 @@ static int program_pagewrite(const struct flash_order *d, long address, const u8
        int ret = toggle_check(d, toggle_address);
        if(0){
                data--;
-               address -= 1;
                polling_check(d, address - 1, *data);
        }
 
@@ -292,7 +283,7 @@ byte program mode 
 static void w49f002_write(const struct flash_order *d, long address, long length, const struct memory *m)
 {
        program_byte(d, address, m->data, length);
-       printf("write %s 0x%06x done\n", m->name, (int) m->offset);
+//     dprintf("write %s 0x%06x done\n", m->name, (int) m->offset);
 }
 
 
@@ -322,7 +313,7 @@ static void w29c040_write(const struct flash_order *d, long address, long length
                        d->read(a, d->pagesize, cmp);
                        if(memcmp(cmp, dd, d->pagesize) != 0){
                                ngblock++;
-                               printf("write %s 0x%06x\n", m->name, (int) offset);
+                               dprintf("write %s 0x%06x\n", m->name, (int) offset);
                                int result = program_pagewrite(d, a, dd, d->pagesize);
                                if(result == NG){
                                        printf("%s: write error\n", __FUNCTION__);
@@ -335,13 +326,13 @@ static void w29c040_write(const struct flash_order *d, long address, long length
                        offset += d->pagesize;
                        i -= d->pagesize;
                }
-               printf("%s 0x%06x, ngblock %d\n", m->name, (int) m->offset, ngblock);
+               dprintf("%s 0x%06x, ngblock %d\n", m->name, (int) m->offset, ngblock);
                if(retry >= 3 && ngblock >= 16){
-                       printf("skip\n");
+                       dprintf("skip\n");
                        break;
                }
                else if(retry > 12){
-                       printf("skip\n");
+                       dprintf("skip\n");
                        break;
                }
                retry++;
index 663815d..26d8467 100644 (file)
@@ -973,6 +973,26 @@ static void read_result_print(const struct memory *m, long length)
        fflush(stdout);
 }
 
+static void execute_program_begin(const struct memory *m)
+{
+       if(DEBUG==1){
+               return;
+       }
+       printf("programming %s memory 0x%06x ... ", m->name, m->offset);
+       fflush(stdout);
+}
+
+//memcmp ¤ÎÌá¤êÃͤ¬Æþ¤ë¤Î¤Ç 0 ¤¬Àµ¾ï
+static void execute_program_finish(int result)
+{
+       const char *str;
+       str = "NG";
+       if(result == 0){
+               str = "OK";
+       }
+       printf("%s\n", str);
+       fflush(stdout);
+}
 const char EXECUTE_ERROR_PREFIX[] = "execute error:";
 static void execute_cpu_ramrw(const struct reader_driver *d, const struct memory *ram, int mode, long address, long length, long wait)
 {
@@ -1018,12 +1038,20 @@ static int execute(const struct script *s, const struct st_config *c, struct rom
                d->open_or_close(READER_CLOSE);
                return NG;
        }
+       u8 *program_compare;
+       program_compare = NULL;
        if(c->mode == MODE_ROM_PROGRAM){
                //device ¤è¤Ã¤Æ¤Ï erase
                c->cpu_flash_driver->init(&(r->cpu_flash));
                if(r->ppu_rom.size != 0){
                        c->ppu_flash_driver->init(&(r->ppu_flash));
                }
+               printf("flashmemory/SRAM program mode. you can abort programming Ctrl+C\n");
+               int size = r->cpu_rom.size;
+               if(size < r->ppu_rom.size){
+                       size = r->ppu_rom.size;
+               }
+               program_compare = malloc(size);
        }
        struct memory cpu_rom, ppu_rom, cpu_ram;
        cpu_rom = r->cpu_rom;
@@ -1061,11 +1089,14 @@ static int execute(const struct script *s, const struct st_config *c, struct rom
                case SCRIPT_OPCODE_CPU_PROGRAM:{
                        const long address = s->value[0];
                        const long length = s->value[1];
+                       execute_program_begin(&cpu_rom);
                        c->cpu_flash_driver->write(
                                &(r->cpu_flash),
                                address, length,
                                &cpu_rom
                        );
+                       d->cpu_read(address, length, program_compare);
+                       execute_program_finish(memcmp(program_compare, cpu_rom.data, length));
                        cpu_rom.data += length;
                        cpu_rom.offset += length;
                        }
@@ -1080,10 +1111,11 @@ static int execute(const struct script *s, const struct st_config *c, struct rom
                case SCRIPT_OPCODE_PPU_SRAMTEST:{
                        const long address = s->value[0];
                        const long length = s->value[1];
+                       printf("PPU_SRAMTEST: 0x%06x-0x%06x ", (int)ppu_rom.offset, (int) (ppu_rom.offset + length) - 1);
                        if(ppu_sramtest(d, address, length) == 0){
-                               printf("PPU_SRAMTEST: ok\n");
+                               printf("ok\n");
                        }else{
-                               printf("PPU_SRAMTEST: ng\n");
+                               printf("ng\n");
                                //end = 0;
                        }
                        }break;
@@ -1113,11 +1145,14 @@ static int execute(const struct script *s, const struct st_config *c, struct rom
                case SCRIPT_OPCODE_PPU_PROGRAM:{
                        const long address = s->value[0];
                        const long length = s->value[1];
+                       execute_program_begin(&ppu_rom);
                        c->ppu_flash_driver->write(
                                &(r->ppu_flash),
                                address, length,
                                &ppu_rom
                        );
+                       d->ppu_read(address, length, program_compare);
+                       execute_program_finish(memcmp(program_compare, ppu_rom.data, length));
                        ppu_rom.data += length;
                        ppu_rom.offset += length;
                        }
@@ -1140,6 +1175,9 @@ static int execute(const struct script *s, const struct st_config *c, struct rom
                }
        }
        d->open_or_close(READER_CLOSE);
+       if(program_compare != NULL){
+               free(program_compare);
+       }
        return OK;
 }