OSDN Git Service

append flash memory capacity check
authornaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 7 Dec 2009 16:35:00 +0000 (16:35 +0000)
committernaruko <naruko@24ea1065-a21e-4ca1-99c9-f5125deb0858>
Mon, 7 Dec 2009 16:35:00 +0000 (16:35 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/unagi@326 24ea1065-a21e-4ca1-99c9-f5125deb0858

client/trunk/anago/anago.c
client/trunk/anago/flashcore.nut
client/trunk/anago/flashdevice.nut
client/trunk/anago/script_flash.c

index ee56578..3f16897 100644 (file)
@@ -33,7 +33,7 @@ static bool transtype_flash_set(char mode, struct memory *t)
 static bool transtype_set(const char *mode, struct romimage *t)
 {
        switch(mode[0]){
-       case 'a': case 'f': case 'g':
+       case 'a': case 'f': case 'F':
                if(mode[1] == '\0'){
                        t->cpu_rom.transtype = TRANSTYPE_FULL;
                        t->ppu_rom.transtype = TRANSTYPE_FULL;
@@ -71,12 +71,18 @@ static bool config_parse(const char *romimage, const char *device_cpu, const cha
        }
        if(c->flash_cpu.id_device == FLASH_ID_DEVICE_DUMMY){
                c->rom.cpu_rom.transtype = TRANSTYPE_EMPTY;
+       }else if(c->flash_cpu.capacity < c->rom.cpu_rom.size){
+               puts("cpu area ROM image size is larger than target device");
+               return false;
        }
        if(
                (c->flash_ppu.id_device == FLASH_ID_DEVICE_DUMMY) ||
                (c->rom.ppu_rom.size == 0)
        ){
                c->rom.ppu_rom.transtype = TRANSTYPE_EMPTY;
+       }else if(c->flash_ppu.capacity < c->rom.ppu_rom.size){
+               puts("ppu area ROM image size is larger than target device");
+               return false;
        }
        return true;
 }
@@ -92,7 +98,7 @@ static void program(int c, char **v)
        case 'a':
                config.reader = &DRIVER_DUMMY;
                break;
-       case 'g':
+       case 'F':
                config.compare = true;
                break;
        }
@@ -185,7 +191,7 @@ int main(int c, char **v)
        mm_init();
        if(c >= 2){
                switch(v[1][0]){
-               case 'a': case 'f': case 'g':
+               case 'a': case 'f': case 'F':
                        program(c, v);
                        break;
                case 'd': case 'D':
index 2972301..c92e6ac 100644 (file)
@@ -1,16 +1,19 @@
 mega <- 0x20000;
-function loopsize_get(t, trans, romsize)
+function loopsize_get(t, trans, image_size, device_size)
 {
        local trans_full = 3, trans_top = 1, trans_bottom = 2; //header.h enum transtype
-       local loop = {start = 0, end = t.maxsize / t.banksize};
+       local loop = {start = 0, end = 0};
        switch(trans){
-       case trans_full:
-               break;
+       case trans_full:{
+               local size = device_size < t.maxsize ? device_size : t.maxsize;
+               loop.end = size / t.banksize;
+               }break;
        case trans_top:
-               loop.end = romsize / t.banksize;
+               loop.end = image_size / t.banksize;
                break;
        case trans_bottom:
-               loop.start = (t.maxsize - romsize) / t.banksize;
+               loop.start = (t.maxsize - image_size) / t.banksize;
+               loop.end = t.maxsize / t.banksize;
                break;
        default:
                loop.start = 0;
@@ -19,15 +22,19 @@ function loopsize_get(t, trans, romsize)
        }
        return loop;
 }
-function program(d, mapper, cpu_trans, cpu_size, ppu_trans, ppu_size)
+function program(
+       d, mapper, 
+       cpu_trans, cpu_image_size, cpu_device_size,
+       ppu_trans, ppu_image_size, ppu_device_size
+)
 {
        local trans_empty = 0;
        if(board.mappernum != mapper){
                print("mapper number not connected");
                return;
        }
-       local cpu_loop = loopsize_get(board.cpu, cpu_trans, cpu_size);
-       local ppu_loop = loopsize_get(board.ppu, ppu_trans, ppu_size);
+       local cpu_loop = loopsize_get(board.cpu, cpu_trans, cpu_image_size, cpu_device_size);
+       local ppu_loop = loopsize_get(board.ppu, ppu_trans, ppu_image_size, ppu_device_size);
        local co_cpu = newthread(cpu_transfer);
        local co_ppu = newthread(ppu_transfer);
        if(board.vram_mirrorfind == true){
index d809d9e..c49128a 100644 (file)
@@ -1,42 +1,62 @@
+//bit is masking MSB
+function mask_get(bit)
+{
+       local t = 1 << (bit + 1);
+       return t - 1;
+}
 function flash_device_get(name)
 {
        local mega = 0x20000;
+       local MASK_A14 = mask_get(14);
        local device = {
                ["dummy"] = {
                        capacity = 16 * mega, pagesize = 1,
                        erase_wait = 0, erase_require = false,
-                       id_manufacurer = 0xf1, id_device = 0xf1
+                       id_manufacurer = 0xf1, id_device = 0xf1,
+                       command_mask = 0
                },
                ["W29C020"] = {
                        capacity = 2 * mega, pagesize = 0x80,
                        erase_wait = 50, erase_require = false,
-                       id_manufacurer = 0xda, id_device = 0x45
+                       id_manufacurer = 0xda, id_device = 0x45,
+                       command_mask = MASK_A14
                },
                ["W29C040"] = {
                        capacity = 4 * mega, pagesize = 0x100,
                        erase_wait = 50, erase_require = false,
-                       id_manufacurer = 0xda, id_device = 0x46
+                       id_manufacurer = 0xda, id_device = 0x46,
+                       command_mask = MASK_A14
                },
                ["W49F002"] = {
                        capacity = 2 * mega, pagesize = 1,
                        erase_wait = 100, erase_require = true,
-                       id_manufacurer = 0xda, id_device = 0xae
+                       id_manufacurer = 0xda, id_device = 0xae,
+                       command_mask = MASK_A14
                },
                ["EN29F002T"] = {
                        capacity = 2 * mega, pagesize = 1,
                        erase_wait = 2000, erase_require = true,
-                       id_manufacurer = 0x1c, id_device = 0x92
+                       id_manufacurer = 0x1c, id_device = 0x92,
+                       command_mask = MASK_A14
                },
                ["AM29F040B"] = {
                        capacity = 4 * mega, pagesize = 1,
                        erase_wait = 8000, erase_require = true,
-                       id_manufacurer = 0x01, id_device = 0xa4
+                       id_manufacurer = 0x01, id_device = 0xa4,
+                       command_mask = mask_get(10)
+               },
+               ["AM29F002"] = {
+                       capacity = 2 * mega, pagesize = 1,
+                       erase_wait = 1000, erase_require = true,
+                       id_manufacurer = 0x01, id_device = 0xB0,
+                       command_mask = mask_get(11)
                },
                //chip erase time is not written in datasheet!!
                ["MBM29F080A"] = {
                        capacity = 8 * mega, pagesize = 1,
                        erase_wait = 8000, erase_require = true,
-                       id_manufacurer = 0x04, id_device = 0xd5
+                       id_manufacurer = 0x04, id_device = 0xd5,
+                       command_mask = mask_get(10)
                }
        };
        return device[name];
index 0e58ee2..7309e82 100644 (file)
@@ -344,9 +344,9 @@ static bool script_execute(HSQUIRRELVM v, struct config_flash *c, struct anago_d
        }else{
                SQRESULT r = qr_call(
                        v, "program", (SQUserPointer) d, true, 
-                       5, c->rom.mappernum, 
-                       d->order_cpu.memory->transtype, d->order_cpu.memory->size, 
-                       d->order_ppu.memory->transtype, d->order_ppu.memory->size
+                       1 + 3 * 2, c->rom.mappernum, 
+                       d->order_cpu.memory->transtype, d->order_cpu.memory->size, d->order_cpu.device->capacity,
+                       d->order_ppu.memory->transtype, d->order_ppu.memory->size, d->order_ppu.device->capacity
                );
                if(SQ_FAILED(r)){
                        ret = false;