I've identified the root cause of the SDCard issue. According to the "SD Specifications Part 1 Physical Layer Simplified Specification", the SPI clock frequency during initialization must be less than 400 KHz. However, a recent Chipyard commit incorrectly sets this value higher, which causes the SD card to fail during the initialization sequence.
To resolve this, I modified sd.c as shown below to ensure proper initialization at 400 kHz and adjust the frequency afterward:
diff --git a/fpga/src/main/resources/vcu118/sdboot/sd.c b/fpga/src/main/resources/vcu118/sdboot/sd.c
index bc1a68e8..162ec295 100644
--- a/fpga/src/main/resources/vcu118/sdboot/sd.c
+++ b/fpga/src/main/resources/vcu118/sdboot/sd.c
@@ -27,7 +27,7 @@
// SPI SCLK frequency, in kHz
// We are using the 25MHz High Speed mode. If this speed is not supported by the
// SD card, consider changing to the Default Speed mode (12.5 MHz).
-#define SPI_CLK 25000
+#define SPI_CLK 12500
// SPI clock divisor value
// @see
https://ucb-bar.gitbook.io/baremetal-ide/baremetal-ide/using-peripheral-devices/sifive-ips/serial-peripheral-interface-spi@@ -90,7 +90,8 @@ static void sd_poweron(void)
long i;
// HACK: frequency change
- REG32(spi, SPI_REG_SCKDIV) = SPI_DIV;
+ // REG32(spi, SPI_REG_SCKDIV) = SPI_DIV;
+ REG32(spi, SPI_REG_SCKDIV) = (F_CLK / 0.4); // 400KHz for initialization
REG32(spi, SPI_REG_CSMODE) = SPI_CSMODE_OFF;
for (i = 10; i > 0; i--) {
sd_dummy();
@@ -185,7 +186,8 @@ static int copy(void)
kprintf("LOADING 0x%x B PAYLOAD\r\n", PAYLOAD_SIZE_B);
kprintf("LOADING ");
- REG32(spi, SPI_REG_SCKDIV) = SPI_DIV;
+ // REG32(spi, SPI_REG_SCKDIV) = SPI_DIV;
+ REG32(spi, SPI_REG_SCKDIV) = (F_CLK / 5); // 5MHz
if (sd_cmd(0x52, BBL_PARTITION_START_SECTOR, 0xE1) != 0x00) {
sd_cmd_end();
return 1;