}
for (i=0;i<count2;i++) write_to_flash(addr2 + i * 4, (unsigned char *)&value2, 4);
}
+
+static void ef(void)
+{
+ erase_flash();
+ printf("flash erased\n");
+}
#endif
#ifdef CSR_ETHPHY_MDIO_W_ADDR
puts("mc - copy address space");
#if (defined CSR_SPIFLASH_BASE && defined SPIFLASH_PAGE_SIZE)
puts("fw - write to flash");
+ puts("ef - erase whole flash");
#endif
#ifdef CSR_ETHPHY_MDIO_W_ADDR
puts("mdiow - write MDIO register");
else if(strcmp(token, "mc") == 0) mc(get_token(&c), get_token(&c), get_token(&c));
#if (defined CSR_SPIFLASH_BASE && defined SPIFLASH_PAGE_SIZE)
else if(strcmp(token, "fw") == 0) fw(get_token(&c), get_token(&c), get_token(&c));
+ else if(strcmp(token, "ef") == 0) ef();
#endif
#ifdef CSR_ETHPHY_MDIO_W_ADDR
else if(strcmp(token, "mdiow") == 0) mdiow(get_token(&c), get_token(&c), get_token(&c));
void write_to_flash_page(unsigned int addr, const unsigned char *c, unsigned int len);
void erase_flash_sector(unsigned int addr);
+void erase_flash(void);
void write_to_flash(unsigned int addr, const unsigned char *c, unsigned int len);
#endif /* __SPIFLASH_H */
#define WRDI_CMD 0x04
#define RDSR_CMD 0x05
#define WREN_CMD 0x06
+#define CHIP_ERASE_CMD 0xc7
#define SE_CMD 0xd8
#define BITBANG_CLK (1 << 1)
spiflash_bitbang_en_write(0);
}
+void erase_flash(void)
+{
+ spiflash_bitbang_en_write(1);
+
+ wait_for_device_ready();
+
+ flash_write_byte(WREN_CMD);
+ spiflash_bitbang_write(BITBANG_CS_N);
+
+ flash_write_byte(CHIP_ERASE_CMD);
+ spiflash_bitbang_write(BITBANG_CS_N);
+
+ wait_for_device_ready();
+
+ spiflash_bitbang_en_write(0);
+}
+
void write_to_flash_page(unsigned int addr, const unsigned char *c, unsigned int len)
{
unsigned int i;