SPI hardware bitbanging from SD CARD
authorrob-ng15 <58272847+rob-ng15@users.noreply.github.com>
Tue, 17 Mar 2020 09:50:16 +0000 (09:50 +0000)
committerGitHub <noreply@github.com>
Tue, 17 Mar 2020 09:50:16 +0000 (09:50 +0000)
litex/soc/software/bios/boot.c
litex/soc/software/bios/boot.h
litex/soc/software/bios/main.c

index f49d89e494f9fa8e1d3d2f6d5dc02101b60d8f5a..355f20a08f836c9a238afc956ce4014e074f4906 100644 (file)
@@ -487,3 +487,29 @@ void romboot(void)
        boot(0, 0, 0, ROM_BOOT_ADDRESS);
 }
 #endif
+
+// SPI HARDWARE BITBANG
+#ifdef CSR_SPI_BASE
+#include <spi.h>
+
+void spisdboot(void)
+{
+    printf("SD Card via SPI Initialising\n");
+    if(spi_sdcard_goidle() == 0) {
+        printf("SD Card Timeout\n");
+        return;
+    }
+    
+    if(spi_sdcard_readMBR() == 0) {
+        printf("SD Card MBR Timeout\n");
+        return;
+    }
+    
+    if(spi_sdcard_readFile("IMAGE","",MAIN_RAM_BASE+KERNEL_IMAGE_RAM_OFFSET)==0) return;
+    if(spi_sdcard_readFile("ROOTFS~1","CPI",MAIN_RAM_BASE+ROOTFS_IMAGE_RAM_OFFSET)==0) return;
+    if(spi_sdcard_readFile("RV32","DTB",MAIN_RAM_BASE+DEVICE_TREE_IMAGE_RAM_OFFSET)==0) return;
+    if(spi_sdcard_readFile("EMULATOR","BIN",EMULATOR_RAM_BASE)==0) return;
+    
+    boot(0,0,0,EMULATOR_RAM_BASE + EMULATOR_IMAGE_RAM_OFFSET);
+}
+#endif
index 65dcf4574b9d7b68007f4f919ee834fb6d6632d5..fd1d06a2e9814be24bbfb59f69a7f7122256081e 100644 (file)
@@ -6,4 +6,8 @@ void netboot(void);
 void flashboot(void);
 void romboot(void);
 
+#ifdef CSR_SPI_BASE
+void spisdboot(void);
+#endif
+
 #endif /* __BOOT_H */
index 83bff1e1048446c912a769bc503b492882e21267..d1ca017e240fd84453539a60652a9ffd7eefe1f0 100644 (file)
@@ -388,12 +388,8 @@ static void help(void)
        puts("sdinit         - SDCard initialization");
        puts("sdtest <loops> - SDCard test");
 #endif
-#ifdef USDDRPHY_DEBUG
-       puts("");
-       puts("sdram_cdly value                - Set SDRAM clk/cmd delay");
-       puts("sdram_cal                       - run SDRAM calibration");
-       puts("sdram_mpr                       - read SDRAM MPR");
-       puts("sdram_mrwr reg value            - write SDRAM mode registers");
+#ifdef CSR_SPI_BASE
+        puts("spisdboot   - boot from SDCard via SPI hardware bitbang");
 #endif
 }
 
@@ -486,24 +482,10 @@ static void do_command(char *c)
        else if(strcmp(token, "sdinit") == 0) sdcard_init();
        else if(strcmp(token, "sdtest") == 0) sdcard_test(atoi(get_token(&c)));
 #endif
-#ifdef USDDRPHY_DEBUG
-       else if(strcmp(token, "sdram_cdly") == 0)
-               ddrphy_cdly(atoi(get_token(&c)));
-       else if(strcmp(token, "sdram_cal") == 0)
-               sdrcal();
-       else if(strcmp(token, "sdram_mpr") == 0)
-               sdrmpr();
-       else if(strcmp(token, "sdram_mrwr") == 0) {
-               unsigned int reg;
-               unsigned int value;
-               reg = atoi(get_token(&c));
-               value = atoi(get_token(&c));
-               sdrsw();
-               printf("Writing 0x%04x to SDRAM mode register %d\n", value, reg);
-               sdrmrwr(reg, value);
-               sdrhw();
-       }
+#ifdef CSR_SPI_BASE
+        else if(strcmp(token, "spisdboot") == 0) spisdboot();
 #endif
+
        else if(strcmp(token, "") != 0)
                printf("Command not found\n");
 }