static FILE * callibrate (const char *s, int len, FILE *fh) // brute force callibration { int32_t pos = ftell (fh); char buf[MAXBUFSIZE]; // malloc ((len + 1) * sizeof (char)); int size = 0; int tries = 0; //TODO: make this an arg fseek (fh, 0, SEEK_END); size = ftell (fh); fseek (fh, pos, SEEK_SET); for (; pos < size - len && tries < 32768; pos++, tries++) { fseek (fh, pos, SEEK_SET); fread (&buf, len, 1, fh); #ifdef DEBUG mem_hexdump (buf, len, ftell (fh) - len); mem_hexdump (s, len, ftell (fh) - len); #endif if (!memcmp (s, buf, len)) { fseek (fh, -len, SEEK_CUR); return fh; } } return NULL; }
int cmd_nand(FILE * f, int argc, char ** argv) { struct debugger * dbg = &debugger; value_t val; uint32_t addr; uint32_t size; int n; argc--; argv++; if (argc) { if ((n = eval_uint32(&val, argc, argv)) < 0) { DCC_LOG(LOG_WARNING, "eval_uint32(), addr"); return n; } argc -= n; argv += n; addr = val.uint32; DCC_LOG2(LOG_INFO, "addr=%08x n=%d", addr, n); } else addr = (uint32_t)dbg->dump.base; if (argc) { if ((n = eval_uint32(&val, argc, argv)) < 0) { DCC_LOG(LOG_WARNING, "eval_uint32(), size"); return n; } size = val.uint32; DCC_LOG2(LOG_TRACE, "size=%d n=%d", size, n); argc -= n; argv += n; } else size = (dbg->dump.size + 3) & ~0x03; if (argc) { fprintf(f, "Too many arguments...\n"); return -1; } if (size == 0) size = 64; dbg->dump.base = addr & ~0x03; dbg->dump.size = 0; size = mem_hexdump(f, dbg->dump.base, size); dbg->dump.base += size; dbg->dump.size = size; return 0; }