mirror of
https://github.com/openhwgroup/cvw.git
synced 2025-06-28 09:36:01 -04:00
Progress made on implementing new disk read function.
This commit is contained in:
parent
db13ed63b9
commit
a95106b516
4 changed files with 44 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "boot.h"
|
#include "boot.h"
|
||||||
#include "gpt.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) { */
|
/* 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) {
|
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: --------------------------------------------------------
|
// copyFlash: --------------------------------------------------------
|
||||||
|
@ -48,7 +71,7 @@ void copyFlash(QWORD address, QWORD * Dst, DWORD numBlocks) {
|
||||||
// Print the wally banner
|
// Print the wally banner
|
||||||
print_uart(BANNER);
|
print_uart(BANNER);
|
||||||
|
|
||||||
|
// Intialize the SD card
|
||||||
init_sd();
|
init_sd();
|
||||||
|
|
||||||
ret = gpt_load_partitions(card_type);
|
ret = gpt_load_partitions(card_type);
|
||||||
|
|
|
@ -99,6 +99,7 @@ uint64_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) {
|
||||||
return r;
|
return r;
|
||||||
} // sd_cmd
|
} // sd_cmd
|
||||||
|
|
||||||
|
|
||||||
// Utility defines for CMD0, CMD8, CMD55, and ACMD41
|
// Utility defines for CMD0, CMD8, CMD55, and ACMD41
|
||||||
#define CMD0() sd_cmd( 0, 0x00000000, 0x95) // Reset SD card into IDLE state
|
#define CMD0() sd_cmd( 0, 0x00000000, 0x95) // Reset SD card into IDLE state
|
||||||
#define CMD8() sd_cmd( 8, 0x000001aa, 0x87) //
|
#define CMD8() sd_cmd( 8, 0x000001aa, 0x87) //
|
||||||
|
|
|
@ -58,6 +58,24 @@ inline void waitrx() {
|
||||||
while(read_reg(SPI_IP) & 2)) {}
|
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
|
// Initialize Sifive FU540 based SPI Controller
|
||||||
void spi_init() {
|
void spi_init() {
|
||||||
|
|
|
@ -55,7 +55,7 @@ inline void waittx();
|
||||||
inline void waitrx();
|
inline void waitrx();
|
||||||
uint8_t spi_txrx(uint8_t byte);
|
uint8_t spi_txrx(uint8_t byte);
|
||||||
inline uint8_t spi_readbyte();
|
inline uint8_t spi_readbyte();
|
||||||
|
uint64_t spi_read64();
|
||||||
void spi_init();
|
void spi_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue