/* Little-endian fallback for drivers not supporting 16 bit accesses */ uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr) { uint16_t val; val = chip_readb(flash, addr); val |= chip_readb(flash, addr + 1) << 8; return val; }
int probe_m29f400bt(struct flashctx *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; chip_writeb(flash, 0xAA, bios + 0xAAA); chip_writeb(flash, 0x55, bios + 0x555); chip_writeb(flash, 0x90, bios + 0xAAA); programmer_delay(10); id1 = chip_readb(flash, bios); /* The data sheet says id2 is at (bios + 0x01) and id2 listed in * flash.h does not match. It should be possible to use JEDEC probe. */ id2 = chip_readb(flash, bios + 0x02); chip_writeb(flash, 0xAA, bios + 0xAAA); chip_writeb(flash, 0x55, bios + 0x555); chip_writeb(flash, 0xF0, bios + 0xAAA); programmer_delay(10); msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id) return 1; return 0; }
int unlock_lh28f008bjt(struct flashctx *flash) { chipaddr bios = flash->virtual_memory; uint8_t mcfg, bcfg; uint8_t need_unlock = 0, can_unlock = 0; int i; /* Wait if chip is busy */ wait_82802ab(flash); /* Read identifier codes */ chip_writeb(flash, 0x90, bios); /* Read master lock-bit */ mcfg = chip_readb(flash, bios + 0x3); msg_cdbg("master lock is "); if (mcfg) { msg_cdbg("locked!\n"); } else { msg_cdbg("unlocked!\n"); can_unlock = 1; } /* Read block lock-bits, 8 * 8 KB + 15 * 64 KB */ for (i = 0; i < flash->chip->total_size * 1024; i += (i >= (64 * 1024) ? 64 * 1024 : 8 * 1024)) { bcfg = chip_readb(flash, bios + i + 2); /* read block lock config */ msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un"); if (bcfg) need_unlock = 1; } /* Reset chip */ chip_writeb(flash, 0xFF, bios); /* Unlock: clear block lock-bits, if needed */ if (can_unlock && need_unlock) { msg_cdbg("Unlock: "); chip_writeb(flash, 0x60, bios); chip_writeb(flash, 0xD0, bios); chip_writeb(flash, 0xFF, bios); wait_82802ab(flash); msg_cdbg("Done!\n"); } /* Error: master locked or a block is locked */ if (!can_unlock && need_unlock) { msg_cerr("At least one block is locked and lockdown is active!\n"); return -1; } return 0; }
int unlock_28f004s5(struct flashctx *flash) { chipaddr bios = flash->virtual_memory; uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0; int i; /* Clear status register */ chip_writeb(flash, 0x50, bios); /* Read identifier codes */ chip_writeb(flash, 0x90, bios); /* Read master lock-bit */ mcfg = chip_readb(flash, bios + 0x3); msg_cdbg("master lock is "); if (mcfg) { msg_cdbg("locked!\n"); } else { msg_cdbg("unlocked!\n"); can_unlock = 1; } /* Read block lock-bits */ for (i = 0; i < flash->chip->total_size * 1024; i+= (64 * 1024)) { bcfg = chip_readb(flash, bios + i + 2); // read block lock config msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un"); if (bcfg) { need_unlock = 1; } } /* Reset chip */ chip_writeb(flash, 0xFF, bios); /* Unlock: clear block lock-bits, if needed */ if (can_unlock && need_unlock) { msg_cdbg("Unlock: "); chip_writeb(flash, 0x60, bios); chip_writeb(flash, 0xD0, bios); chip_writeb(flash, 0xFF, bios); msg_cdbg("Done!\n"); } /* Error: master locked or a block is locked */ if (!can_unlock && need_unlock) { msg_cerr("At least one block is locked and lockdown is active!\n"); return -1; } return 0; }
int probe_82802ab(struct flashctx *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2, flashcontent1, flashcontent2; int shifted = (flash->chip->feature_bits & FEATURE_ADDR_SHIFTED) ? 1 : 0; /* Reset to get a clean state */ chip_writeb(flash, 0xFF, bios); programmer_delay(10); /* Enter ID mode */ chip_writeb(flash, 0x90, bios); programmer_delay(10); id1 = chip_readb(flash, bios + (0x00 << shifted)); id2 = chip_readb(flash, bios + (0x01 << shifted)); /* Leave ID mode */ chip_writeb(flash, 0xFF, bios); programmer_delay(10); msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2); if (!oddparity(id1)) msg_cdbg(", id1 parity violation"); /* * Read the product ID location again. We should now see normal * flash contents. */ flashcontent1 = chip_readb(flash, bios + (0x00 << shifted)); flashcontent2 = chip_readb(flash, bios + (0x01 << shifted)); if (id1 == flashcontent1) msg_cdbg(", id1 is normal flash content"); if (id2 == flashcontent2) msg_cdbg(", id2 is normal flash content"); msg_cdbg("\n"); if (id1 != flash->chip->manufacture_id || id2 != flash->chip->model_id) return 0; if (flash->chip->feature_bits & FEATURE_REGISTERMAP) map_flash_registers(flash); return 1; }
/* chunksize is 1 */ int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) { int i; chipaddr bios = flash->virtual_memory; chipaddr dst = flash->virtual_memory + start; for (i = 0; i < len; i++) { chip_writeb(flash, 0xAA, bios + 0xAAA); chip_writeb(flash, 0x55, bios + 0x555); chip_writeb(flash, 0xA0, bios + 0xAAA); /* transfer data from source to destination */ chip_writeb(flash, *src, dst); toggle_ready_jedec(flash, dst); #if 0 /* We only want to print something in the error case. */ msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n", (dst - bios), chip_readb(flash, dst), *src); #endif dst++; src++; } /* FIXME: Ignore errors for now. */ return 0; }
/* FIXME: needs timeout */ uint8_t wait_82802ab(struct flashctx *flash) { uint8_t status; chipaddr bios = flash->virtual_memory; chip_writeb(flash, 0x70, bios); if ((chip_readb(flash, bios) & 0x80) == 0) { // it's busy while ((chip_readb(flash, bios) & 0x80) == 0) ; } status = chip_readb(flash, bios); /* Reset to get a clean state */ chip_writeb(flash, 0xFF, bios); return status; }
void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len) { size_t i; for (i = 0; i < len; i++) buf[i] = chip_readb(flash, addr + i); return; }
/* According to the Winbond W29EE011, W29EE012, W29C010M, W29C011A * datasheets this is the only valid probe function for those chips. */ int probe_w29ee011(struct flashctx *flash) { chipaddr bios = flash->virtual_memory; uint8_t id1, id2; if (!chip_to_probe || strcmp(chip_to_probe, flash->chip->name)) { msg_cdbg("Old Winbond W29* probe method disabled because " "the probing sequence puts the AMIC A49LF040A in " "a funky state. Use 'flashrom -c %s' if you " "have a board with such a chip.\n", flash->chip->name); return 0; } /* Issue JEDEC Product ID Entry command */ chip_writeb(flash, 0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(flash, 0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(flash, 0x80, bios + 0x5555); programmer_delay(10); chip_writeb(flash, 0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(flash, 0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(flash, 0x60, bios + 0x5555); programmer_delay(10); /* Read product ID */ id1 = chip_readb(flash, bios); id2 = chip_readb(flash, bios + 0x01); /* Issue JEDEC Product ID Exit command */ chip_writeb(flash, 0xAA, bios + 0x5555); programmer_delay(10); chip_writeb(flash, 0x55, bios + 0x2AAA); programmer_delay(10); chip_writeb(flash, 0xF0, bios + 0x5555); programmer_delay(10); msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2); if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id) return 1; return 0; }
int unprotect_28sf040(struct flashchip *flash) { chipaddr bios = flash->virtual_memory; chip_readb(bios + 0x1823); chip_readb(bios + 0x1820); chip_readb(bios + 0x1822); chip_readb(bios + 0x0418); chip_readb(bios + 0x041B); chip_readb(bios + 0x0419); chip_readb(bios + 0x041A); return 0; }
static int unlock_w39_fwh_block(struct flashchip *flash, int offset) { chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; locking = chip_readb(wrprotect); /* Read or write lock present? */ if (locking & ((1 << 2) | (1 << 0))) { /* Lockdown active? */ if (locking & (1 << 1)) { msg_cerr("Can't unlock block at 0x%x!\n", offset); return -1; } else { msg_cdbg("Unlocking block at 0x%x\n", offset); chip_writeb(0, wrprotect); } } return 0; }
static uint8_t w39_idmode_readb(struct flashchip *flash, int offset) { chipaddr bios = flash->virtual_memory; uint8_t val; /* Product Identification Entry */ chip_writeb(0xAA, bios + 0x5555); chip_writeb(0x55, bios + 0x2AAA); chip_writeb(0x90, bios + 0x5555); programmer_delay(10); /* Read something, maybe hardware lock bits */ val = chip_readb(bios + offset); /* Product Identification Exit */ chip_writeb(0xAA, bios + 0x5555); chip_writeb(0x55, bios + 0x2AAA); chip_writeb(0xF0, bios + 0x5555); programmer_delay(10); return val; }
static int printlock_w39_fwh_block(struct flashchip *flash, int offset) { chipaddr wrprotect = flash->virtual_registers + offset + 2; uint8_t locking; locking = chip_readb(wrprotect); msg_cdbg("Lock status of block at 0x%08x is ", offset); switch (locking & 0x7) { case 0: msg_cdbg("Full Access.\n"); break; case 1: msg_cdbg("Write Lock (Default State).\n"); break; case 2: msg_cdbg("Locked Open (Full Access, Lock Down).\n"); break; case 3: msg_cerr("Error: Write Lock, Locked Down.\n"); break; case 4: msg_cdbg("Read Lock.\n"); break; case 5: msg_cdbg("Read/Write Lock.\n"); break; case 6: msg_cerr("Error: Read Lock, Locked Down.\n"); break; case 7: msg_cerr("Error: Read/Write Lock, Locked Down.\n"); break; } /* Read or write lock present? */ return (locking & ((1 << 2) | (1 << 0))) ? -1 : 0; }