erase flash command added
authorfb@frank-buss.de <fb@frank-buss.de>
Thu, 7 Nov 2019 18:19:54 +0000 (19:19 +0100)
committerfb@frank-buss.de <fb@frank-buss.de>
Thu, 7 Nov 2019 18:19:54 +0000 (19:19 +0100)
litex/soc/software/bios/main.c
litex/soc/software/include/base/spiflash.h
litex/soc/software/libbase/spiflash.c

index a19e7ce9d6a57aa1a241f3dd48a8b8ca7041df84..c18cccfb1c8604b8710a313311aa589d07ea236c 100644 (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));
index a4ff495ab9717923671be9e9d75887fcfbdd8ab4..7d6171bde3d8ff65b13b9ca5d1bcbde36008a5d8 100644 (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 */
index 31d56a106d7410da69362c33a6d95677965bfb54..38a22dce9729de468bf151b1d1b00f3107bc91ed 100644 (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;