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
config.script = v[2];
config.reader = &DRIVER_KAZZO;
config.compare = false;
+ config.testrun = false;
switch(v[1][0]){
case 'a':
config.reader = &DRIVER_DUMMY;
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)
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;
}
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;
};
}
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)
["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)
},
["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
},
["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)
}
{
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);
{
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);
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);
}
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);
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;
}
}
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;
{
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;
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;
}
#include <assert.h>
#include <stdlib.h>
+//#include <stdbool.h>
#include <usb.h>
#include <kazzo_request.h>
#include <kazzo_task.h>
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);
}
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)
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){
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])
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);