- // could enter CFI directly, but there seems to be a "stack"
- // of modes, so 2 exits would be needed
- io->write_bus(fd, 0, 0xf0);
+ // see if this chip understands CFI (common flash interface)
+ io->write_bus(fd, 0xaa, 0x98);
+ resp_cfi[0] = io->read_bus(fd, 0x20);
+ resp_cfi[1] = io->read_bus(fd, 0x22);
+ resp_cfi[2] = io->read_bus(fd, 0x24);
+ if (memcmp(resp_cfi, qry, sizeof(resp_cfi)) == 0)
+ {
+ info.size = 1u << io->read_bus(fd, 0x4e);
+ info.region_cnt = io->read_bus(fd, 0x58);
+ assert(0 < info.region_cnt && info.region_cnt <= 4);
+ for (i = 0, a = 0x5a; i < info.region_cnt; i++, a += 8) {
+ info.region[i].block_count = io->read_bus(fd, a + 0) + 1;
+ info.region[i].block_count += io->read_bus(fd, a + 2) << 8;
+ info.region[i].block_size = io->read_bus(fd, a + 4) << 8;
+ info.region[i].block_size |= io->read_bus(fd, a + 6) << 16;
+ info.region[i].start = total;
+ info.region[i].size =
+ info.region[i].block_size * info.region[i].block_count;
+ assert(info.region[i].size);
+ total += info.region[i].size;
+ }
+ if (info.size != total)
+ fprintf(stderr, "warning: total is %u, bad CFI?\n", total);