OSDN Git Service

flash programming retry flag support
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Tue, 19 Jan 2010 22:03:25 +0000 (22:03 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Tue, 19 Jan 2010 22:03:25 +0000 (22:03 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@349 24ea1065-a21e-4ca1-99c9-f5125deb0858

client/trunk/anago/Makefile
client/trunk/anago/anago.c
client/trunk/anago/flash_device.c
client/trunk/anago/flash_device.h
client/trunk/anago/flashcore.nut
client/trunk/anago/flashdevice.nut
client/trunk/anago/reader_dummy.c
client/trunk/anago/script_flash.c
client/trunk/reader_kazzo.c
client/trunk/reader_master.h

index 516cac7..c018cf6 100644 (file)
@@ -3,8 +3,8 @@ LIBUSB = d:/dev/LibUSB-Win32
 SQUIRREL = ../SQUIRREL2
 KAZZO = ../../kazzo/firmware
 VPATH = ..
-#CFLAGS = -g -O0
-CFLAGS = -O2 -DNDEBUG
+CFLAGS = -g -O0
+#CFLAGS = -O2 -DNDEBUG
 CFLAGS += -Wall -Werror -I.. -I$(LIBUSB)/include -I$(SQUIRREL)/include -I$(KAZZO) -DDEBUG=1 -DANAGO=1
 LDFLAG = -L. -L$(LIBUSB)/lib/gcc -L$(SQUIRREL)/lib
 CC = gcc
index f6c37c0..4a53110 100644 (file)
@@ -94,6 +94,7 @@ static void program(int c, char **v)
        config.script = v[2];
        config.reader = &DRIVER_KAZZO;
        config.compare = false;
+       config.testrun = false;
        switch(v[1][0]){
        case 'a':
                config.reader = &DRIVER_DUMMY;
index 50dde3e..ce4c1dc 100644 (file)
@@ -17,7 +17,7 @@ static void call(HSQUIRRELVM v, const char *devicename)
                sq_pushstring(v, _SC(devicename), -1);
                SQRESULT r = sq_call(v, 2, SQTrue, SQTrue);
                assert(r == SQ_OK);
-               r++; //avoid unused variable with -DNDEBUG
+               r++; //avoid warning unused variable with -DNDEBUG
        }
 }
 static bool long_get(HSQUIRRELVM v, const char *field, long *ret)
@@ -88,6 +88,9 @@ bool flash_device_get(const char *name, struct flash_device *t)
        if(bool_get(v, "erase_require", &t->erase_require) == false){
                goto field_error;
        }
+       if(bool_get(v, "retry", &t->retry) == false){
+               goto field_error;
+       }
        if(long_get(v, "command_mask", &t->command_mask) == false){
                goto field_error;
        }
index 322ca5b..ec54445 100644 (file)
@@ -4,7 +4,7 @@ struct flash_device{
        const char *name;
        long capacity, pagesize;
        long erase_wait; //unit is msec
-       bool erase_require;
+       bool erase_require, retry;
        uint8_t id_manufacurer, id_device;
        long command_mask;
 };
index 2853bef..5305589 100644 (file)
@@ -68,11 +68,9 @@ function program(
        }
        erase_wait(d);
        if(cpu_trans != trans_empty){
-               //cpu_transfer(d, cpu_loop.start, cpu_loop.end, board.cpu.banksize);
                co_cpu.call(d, cpu_loop.start, cpu_loop.end, board.cpu.banksize);
        }
        if(ppu_trans != trans_empty){
-               //ppu_transfer(d, ppu_loop.start, ppu_loop.end, board.ppu.banksize);
                co_ppu.call(d, ppu_loop.start, ppu_loop.end, board.ppu.banksize);
        }
        program_main(d, co_cpu, co_ppu)
index 2a79abf..5d955f4 100644 (file)
@@ -12,36 +12,49 @@ function flash_device_get(name)
                ["dummy"] = {
                        capacity = 16 * mega, pagesize = 1,
                        erase_wait = 0, erase_require = false,
+                       retry = false,
                        id_manufacurer = 0xf1, id_device = 0xf1,
                        command_mask = 0
                },
                ["W29C020"] = {
                        capacity = 2 * mega, pagesize = 0x80,
                        erase_wait = 50, erase_require = false,
+                       retry = false,
                        id_manufacurer = 0xda, id_device = 0x45,
                        command_mask = MASK_A14
                },
                ["W29C040"] = {
                        capacity = 4 * mega, pagesize = 0x100,
                        erase_wait = 50, erase_require = false,
+                       retry = true,
                        id_manufacurer = 0xda, id_device = 0x46,
                        command_mask = MASK_A14
                },
                ["W49F002"] = {
                        capacity = 2 * mega, pagesize = 1,
                        erase_wait = 100, erase_require = true,
+                       retry = false,
                        id_manufacurer = 0xda, id_device = 0xae,
                        command_mask = MASK_A14
                },
+               ["AT49F002"] = {
+                       capacity = 2 * mega, pagesize = 1,
+                       erase_wait = 100, erase_require = true,
+                       retry = true,
+                       id_manufacurer = 0x1f, id_device = 0x08,
+                       command_mask = MASK_A14
+               },
                ["EN29F002T"] = {
                        capacity = 2 * mega, pagesize = 1,
                        erase_wait = 2000, erase_require = true,
+                       retry = false,
                        id_manufacurer = 0x1c, id_device = 0x92,
                        command_mask = MASK_A14
                },
                ["AM29F040B"] = {
                        capacity = 4 * mega, pagesize = 1,
                        erase_wait = 8000, erase_require = true,
+                       retry = false,
                        id_manufacurer = 0x01, id_device = 0xa4,
                        command_mask = mask_get(10)
                },
@@ -49,6 +62,7 @@ function flash_device_get(name)
                ["PM29F002T"] = {
                        capacity = 2 * mega, pagesize = 1,
                        erase_wait = 500, erase_require = true,
+                       retry = false,
                        id_manufacurer = 0x9d, id_device = 0x1d,
                        command_mask = mask_get(10) //maybe A10-A0
                },
@@ -56,6 +70,7 @@ function flash_device_get(name)
                ["MBM29F080A"] = {
                        capacity = 8 * mega, pagesize = 1,
                        erase_wait = 8000, erase_require = true,
+                       retry = false,
                        id_manufacurer = 0x04, id_device = 0xd5,
                        command_mask = mask_get(10)
                }
index 7d29457..4f897c9 100644 (file)
@@ -21,11 +21,11 @@ static void dummy_cpu_write_6502(long address, long length, const uint8_t *data)
 {
        printf("%s %04x %04x %02x\n", __FUNCTION__, (int) address, (int) length, (int) *data);
 }
-static void dummy_cpu_flash_config(long c000x, long c2aaa, long c5555, long unit)
+static void dummy_cpu_flash_config(long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
        printf("%s %04x %04x %04x %04x\n", __FUNCTION__, (int) c000x, (int) c2aaa, (int) c5555, (int) unit);
 }
-static long dummy_cpu_flash_program(long address, long length, const u8 *data, bool dowait)
+static long dummy_cpu_flash_program(long address, long length, const u8 *data, bool dowait, bool skip)
 {
        int i = 0x10;
        printf("%s %06x\n", __FUNCTION__, (int) address);
@@ -55,11 +55,11 @@ static void dummy_ppu_write(long address, long length, const uint8_t *data)
 {
        printf("%s %04x %04x %02x\n", __FUNCTION__, (int) address, (int) length, (int) *data);
 }
-static void dummy_ppu_flash_config(long c000x, long c2aaa, long c5555, long unit)
+static void dummy_ppu_flash_config(long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
        printf("%s %04x %04x %04x %04x\n", __FUNCTION__, (int) c000x, (int) c2aaa, (int) c5555, (int) unit);
 }
-static long dummy_ppu_flash_program(long address, long length, const u8 *data, bool dowait)
+static long dummy_ppu_flash_program(long address, long length, const u8 *data, bool dowait, bool skip)
 {
        int i = 0x10;
        printf("%s %06x\n", __FUNCTION__, (int) address);
index 5e1f8d2..ae037b2 100644 (file)
@@ -23,12 +23,12 @@ struct anago_driver{
                long c000x, c2aaa, c5555;
                struct memory *const memory;
                struct flash_device *const device;
-               void (*const config)(long c000x, long c2aaa, long c5555, long unit);
+               void (*const config)(long c000x, long c2aaa, long c5555, long unit, bool retry);
                void (*const device_get)(uint8_t s[2]);
                void (*const write)(long address, long length, const uint8_t *data);
                void (*const read)(long address, long length, u8 *data);
                void (*const erase)(long address, bool dowait);
-               long (*const program)(long address, long length, const u8 *data, bool dowait);
+               long (*const program)(long address, long length, const u8 *data, bool dowait, bool skip);
        }order_cpu, order_ppu;
        void (*const flash_status)(uint8_t s[2]);
        uint8_t (*const vram_connection)(void);
@@ -113,7 +113,7 @@ static SQInteger cpu_write(HSQUIRRELVM v)
 }
 static SQInteger erase_set(HSQUIRRELVM v, struct anago_flash_order *t, const char *region)
 {
-       t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize);
+       t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize, t->device->retry);
        t->command_change = false;
        if(t->device->erase_require == true){
                t->erase(t->c2aaa, false);
@@ -149,7 +149,7 @@ static SQInteger program_regist(HSQUIRRELVM v, const char *name, struct anago_fl
        t->compare = t->programming;
        t->compare.offset = t->memory->offset & (t->memory->size - 1);
        if(t->command_change == true){
-               t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize);
+               t->config(t->c000x, t->c2aaa, t->c5555, t->device->pagesize, t->device->retry);
                t->command_change = false;
        }
        
@@ -159,7 +159,7 @@ static SQInteger program_regist(HSQUIRRELVM v, const char *name, struct anago_fl
 }
 static void program_execute(struct anago_flash_order *t)
 {
-       const long w = t->program(t->programming.address, t->programming.length, t->memory->data + t->memory->offset, false);
+       const long w = t->program(t->programming.address, t->programming.length, t->memory->data + t->memory->offset, false, t->device->erase_require);
        t->programming.address += w;
        t->programming.length -= w;
        t->memory->offset += w;
@@ -171,6 +171,19 @@ static bool program_compare(struct anago_flash_order *t)
 {
        uint8_t *comparea = Malloc(t->compare.length);
        bool ret = false;
+       if(t->device->erase_require == true){
+               memset(comparea, 0xff, t->compare.length);
+               int doread = memcmp(comparea, t->memory->data + t->compare.offset, t->compare.length);
+               if(0){
+                       memset(comparea, 0, t->compare.length);
+                       doread &= memcmp(comparea, t->memory->data + t->compare.offset, t->compare.length);
+               }
+               if(doread == 0){
+                       Free(comparea);
+                       return true;
+               }
+       }
+       
        t->read(t->compare.address, t->compare.length, comparea);
        if(memcmp(comparea, t->memory->data + t->compare.offset, t->compare.length) == 0){
                ret = true;
@@ -227,7 +240,8 @@ static SQInteger erase_wait(HSQUIRRELVM v)
                do{
                        Sleep(2);
                        d->flash_status(s);
-               }while((s[0] != 0) && (s[1] != 0));
+               //ËÜÍè¤Î°Õ¿Þ¤«¤é¤Ç¤Ï¤³¤³¤Î¾ò·ï¼°¤Ï && ¤Ç¤Ï¤Ê¤¯ || ¤À¤¬¡¢Àè¤Ë erase ¤¬½ª¤ï¤Ã¤¿¥Ç¥Ð¥¤¥¹¤¬Æ°¤«¤»¤ë¤Î¤Ç»Ä¤·¤Æ¤ª¤¯
+               }while((s[0] != KAZZO_TASK_FLASH_IDLE) && (s[1] != KAZZO_TASK_FLASH_IDLE));
        }
        return 0;
 }
index a488b7b..6488a23 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <stdlib.h>
+//#include <stdbool.h>
 #include <usb.h>
 #include <kazzo_request.h>
 #include <kazzo_task.h>
@@ -142,30 +143,49 @@ static inline void pack_short_le(long l, uint8_t *t)
        t[0] = l & 0xff;
        t[1] = (l >> 8) & 0xff;
 }
-static void flash_config(enum request r, enum index index, long c000x, long c2aaa, long c5555, long unit)
+static void flash_config(enum request r, enum index index, long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
-       const int size = 2 * 4;
-       uint8_t t[size];
+       const int size = 2 * 4 + 1;
+       uint8_t buf[10]; //[size];
+       uint8_t *t = buf;
        assert(unit >= 1 && unit < 0x400);
        pack_short_le(c000x, t);
-       pack_short_le(c2aaa, t + 2);
-       pack_short_le(c5555, t + 4);
-       pack_short_le(unit, t + 6);
-       device_write(handle, r, index, 0, size, t);
+       t += 2;
+       pack_short_le(c2aaa, t);
+       t += 2;
+       pack_short_le(c5555, t);
+       t += 2;
+       pack_short_le(unit, t);
+       t += 2;
+       *t = retry == true ? 1 : 0;
+       device_write(handle, r, index, 0, size, buf);
 }
-static void kazzo_cpu_flash_config(long c000x, long c2aaa, long c5555, long unit)
+static void kazzo_cpu_flash_config(long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
-       flash_config(REQUEST_FLASH_CONFIG_SET, INDEX_CPU, c000x, c2aaa, c5555, unit);
+       flash_config(REQUEST_FLASH_CONFIG_SET, INDEX_CPU, c000x, c2aaa, c5555, unit, retry);
 }
-static void kazzo_ppu_flash_config(long c000x, long c2aaa, long c5555, long unit)
+static void kazzo_ppu_flash_config(long c000x, long c2aaa, long c5555, long unit, bool retry)
 {
-       flash_config(REQUEST_FLASH_CONFIG_SET, INDEX_PPU, c000x, c2aaa, c5555, unit);
+       flash_config(REQUEST_FLASH_CONFIG_SET, INDEX_PPU, c000x, c2aaa, c5555, unit, retry);
 }
 
-static inline void flash_execute(enum request p, enum request s, enum index index, long address, const uint8_t *data, int size, bool dowait)
+static inline void flash_execute(enum request p, enum request s, enum index index, long address, const uint8_t *data, int size, bool dowait, bool skip)
 {
        uint8_t status;
-       device_write(handle, p, index, address, size, data);
+       int filled = 1;
+       if(skip == true){
+               uint8_t *filldata = Malloc(size);
+               memset(filldata, 0xff, size);
+               filled = memcmp(filldata, data, size);
+               if(0){ //nesasm fill 0 to unused area. When this routine is enabled, programming will speed up and compare mode will not work.
+                       memset(filldata, 0, size);
+                       filled &= memcmp(filldata, data, size);
+               }
+               Free(filldata);
+       }
+       if(filled != 0){
+               device_write(handle, p, index, address, size, data);
+       }
        if(dowait == true){
                do{
                        wait(10);
@@ -175,11 +195,11 @@ static inline void flash_execute(enum request p, enum request s, enum index inde
 }
 static void kazzo_cpu_flash_erase(long address, bool dowait)
 {
-       flash_execute(REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_CPU, address, NULL, 0, dowait);
+       flash_execute(REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_CPU, address, NULL, 0, dowait, false);
 }
 static void kazzo_ppu_flash_erase(long address, bool dowait)
 {
-       flash_execute(REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_PPU, address, NULL, 0, dowait);
+       flash_execute(REQUEST_FLASH_ERASE, REQUEST_FLASH_STATUS, INDEX_PPU, address, NULL, 0, dowait, false);
 }
 
 static void dump(const uint8_t *w, const uint8_t *r, long length)
@@ -203,18 +223,18 @@ static void dump(const uint8_t *w, const uint8_t *r, long length)
                length -= 0x10;
        }
 }
-static long flash_program(enum index index, long address, long length, const uint8_t *data, bool dowait)
+static long flash_program(enum index index, long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
        enum request p = REQUEST_FLASH_PROGRAM;
        enum request s = REQUEST_FLASH_STATUS;
        if(dowait == false){
-               flash_execute(p, s, index, address, data, FLASH_PACKET_SIZE, dowait);
+               flash_execute(p, s, index, address, data, FLASH_PACKET_SIZE, dowait, skip);
                return FLASH_PACKET_SIZE;
        }
        long count = 0;
        uint8_t *d = Malloc(FLASH_PACKET_SIZE);
        while(length >= FLASH_PACKET_SIZE){
-               flash_execute(p, s, index, address, data, FLASH_PACKET_SIZE, dowait);
+               flash_execute(p, s, index, address, data, FLASH_PACKET_SIZE, dowait, skip);
                if(0){
                        //device_read(handle, REQUEST_FLASH_BUFFER_GET, index, 0, FLASH_PACKET_SIZE, d);
                        if(memcmp(d, data, FLASH_PACKET_SIZE) != 0){
@@ -230,13 +250,13 @@ static long flash_program(enum index index, long address, long length, const uin
        Free(d);
        return count;
 }
-static long kazzo_cpu_flash_program(long address, long length, const uint8_t *data, bool dowait)
+static long kazzo_cpu_flash_program(long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
-       return flash_program(INDEX_CPU, address, length, data, dowait);
+       return flash_program(INDEX_CPU, address, length, data, dowait, skip);
 }
-static long kazzo_ppu_flash_program(long address, long length, const uint8_t *data, bool dowait)
+static long kazzo_ppu_flash_program(long address, long length, const uint8_t *data, bool dowait, bool skip)
 {
-       return flash_program(INDEX_PPU, address, length, data, dowait);
+       return flash_program(INDEX_PPU, address, length, data, dowait, skip);
 }
 
 static void kazzo_flash_status(uint8_t s[2])
index dbb3413..f92d7ec 100644 (file)
@@ -15,13 +15,13 @@ struct reader_driver{
        void (*ppu_read)(long address, long length, uint8_t *data);
        void (*ppu_write)(long address, long length, const uint8_t *data);
        bool flash_support;
-       void (*cpu_flash_config)(long c000x, long c2aaa, long c5555, long unit);
+       void (*cpu_flash_config)(long c000x, long c2aaa, long c5555, long unit, bool retry);
        void (*cpu_flash_erase)(long address, bool wait);
-       long (*cpu_flash_program)(long address, long length, const uint8_t *data, bool wait);
+       long (*cpu_flash_program)(long address, long length, const uint8_t *data, bool wait, bool skip);
        void (*cpu_flash_device_get)(uint8_t s[2]);
-       void (*ppu_flash_config)(long c000x, long c2aaa, long c5555, long unit);
+       void (*ppu_flash_config)(long c000x, long c2aaa, long c5555, long unit, bool retry);
        void (*ppu_flash_erase)(long address, bool wait);
-       long (*ppu_flash_program)(long address, long length, const uint8_t *data, bool wait);
+       long (*ppu_flash_program)(long address, long length, const uint8_t *data, bool wait, bool skip);
        void (*ppu_flash_device_get)(uint8_t s[2]);
        void (*flash_status)(uint8_t s[2]);
        uint8_t (*vram_connection)(void);