Merge pull request #302 from FrankBuss/master
erase flash command added
This commit is contained in:
commit
7fb9cfeb64
|
@ -212,6 +212,12 @@ static void fw(char *addr, char *value, char *count)
|
|||
}
|
||||
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
|
||||
|
@ -341,6 +347,7 @@ static void help(void)
|
|||
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");
|
||||
|
@ -404,6 +411,7 @@ static void do_command(char *c)
|
|||
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));
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
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 */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#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)
|
||||
|
@ -89,6 +90,23 @@ void erase_flash_sector(unsigned int addr)
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue