erase flash command added

This commit is contained in:
fb@frank-buss.de 2019-11-07 19:19:54 +01:00
parent f1714405c3
commit 468df3c857
3 changed files with 27 additions and 0 deletions

View File

@ -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));

View File

@ -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 */

View File

@ -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;