From a95106b516abffb779206d51dbb09a48ab8c515d Mon Sep 17 00:00:00 2001 From: Jacob Pease Date: Tue, 23 Jul 2024 15:47:23 -0500 Subject: [PATCH] Progress made on implementing new disk read function. --- fpga/zsbl/boot.c | 25 ++++++++++++++++++++++++- fpga/zsbl/sd.c | 1 + fpga/zsbl/spi.c | 18 ++++++++++++++++++ fpga/zsbl/spi.h | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/fpga/zsbl/boot.c b/fpga/zsbl/boot.c index 484bddaac..16f7c0430 100644 --- a/fpga/zsbl/boot.c +++ b/fpga/zsbl/boot.c @@ -1,6 +1,9 @@ #include #include "boot.h" #include "gpt.h" +#include "uart.h" +#include "spi.h" +#include "sd.h" /* int disk_read(BYTE * buf, LBA_t sector, UINT count, BYTE card_type) { */ @@ -32,7 +35,27 @@ /* } */ int disk_read(BYTE * buf, LBA_t sector, UINT count) { + uint64_t r; + UINT i; + uint8_t crc = 0; + crc = crc7(crc, 0x40 | SD_CMD_READ_BLOCK_MULTIPLE); + crc = crc7(crc, (sector >> 24) & 0xff); + crc = crc7(crc, (sector >> 16) & 0xff); + crc = crc7(crc, (sector >> 8) & 0xff); + crc = crc7(crc, sector & 0xff); + crc = crc | 1; + + if (sd_cmd(18, sector &, crc) != 0x00) { + print_uart("disk_read: CMD18 failed. r = "); + print_byte(r & 0xff); + return -1; + } + + // Begin reading + for (i = 0; i < count; i++) { + + } } // copyFlash: -------------------------------------------------------- @@ -48,7 +71,7 @@ void copyFlash(QWORD address, QWORD * Dst, DWORD numBlocks) { // Print the wally banner print_uart(BANNER); - + // Intialize the SD card init_sd(); ret = gpt_load_partitions(card_type); diff --git a/fpga/zsbl/sd.c b/fpga/zsbl/sd.c index 4669aeb0b..c2a6eed54 100644 --- a/fpga/zsbl/sd.c +++ b/fpga/zsbl/sd.c @@ -99,6 +99,7 @@ uint64_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) { return r; } // sd_cmd + // Utility defines for CMD0, CMD8, CMD55, and ACMD41 #define CMD0() sd_cmd( 0, 0x00000000, 0x95) // Reset SD card into IDLE state #define CMD8() sd_cmd( 8, 0x000001aa, 0x87) // diff --git a/fpga/zsbl/spi.c b/fpga/zsbl/spi.c index c812327f4..687a98ceb 100644 --- a/fpga/zsbl/spi.c +++ b/fpga/zsbl/spi.c @@ -58,6 +58,24 @@ inline void waitrx() { while(read_reg(SPI_IP) & 2)) {} } +uint64_t spi_read64() { + uint64_t r; + uint8_t rbyte; + int i; + + for (i = 0; i < 8; i++) { + spi_sendbyte(0xFF); + } + + waittx(); + + for (i = 0; i < 8; i++) { + rbyte = spi_readbyte(); + r = r | (rbyte << ((8 - 1 - i)*8)); + } + + return r; +} // Initialize Sifive FU540 based SPI Controller void spi_init() { diff --git a/fpga/zsbl/spi.h b/fpga/zsbl/spi.h index a035f0ab5..e91bcc0ea 100644 --- a/fpga/zsbl/spi.h +++ b/fpga/zsbl/spi.h @@ -55,7 +55,7 @@ inline void waittx(); inline void waitrx(); uint8_t spi_txrx(uint8_t byte); inline uint8_t spi_readbyte(); - +uint64_t spi_read64(); void spi_init(); #endif