diff --git a/tests/custom/boot/boot.c b/tests/custom/boot/boot.c index 8546861f9..9f4eaa6f9 100644 --- a/tests/custom/boot/boot.c +++ b/tests/custom/boot/boot.c @@ -1,4 +1,4 @@ - +#include "boot.h" /* Card type flags (card_type) */ #define CT_MMC 0x01 /* MMC ver 3 */ @@ -72,6 +72,7 @@ #define SDC_DAT_INT_STATUS_CRC 0x0008 // CRC error #define SDC_DAT_INT_STATUS_CFE 0x0010 // Data FIFO underrun or overrun + #define ERR_EOF 30 #define ERR_NOT_ELF 31 #define ERR_ELF_BITS 32 @@ -113,15 +114,10 @@ struct sdc_regs { static struct sdc_regs * const regs __attribute__((section(".rodata"))) = (struct sdc_regs *)0x00013100; static int errno __attribute__((section(".bss"))); -static DSTATUS drv_status __attribute__((section(".bss"))); +// static DSTATUS drv_status __attribute__((section(".bss"))); static BYTE card_type __attribute__((section(".bss"))); static uint32_t response[4] __attribute__((section(".bss"))); -static FATFS fatfs __attribute__((section(".bss"))); static int alt_mem __attribute__((section(".bss"))); -static FIL fd __attribute__((section(".bss"))); - -extern unsigned char _fbss[]; -extern unsigned char _ebss[]; static const char * errno_to_str(void) { switch (errno) { @@ -252,7 +248,7 @@ static int send_data_cmd(unsigned cmd, unsigned arg, void * buf, unsigned blocks case CMD2: case CMD9: case CMD10: - // R2 + // R2 command |= 2; // 136 bits command |= 1 << 3; // resp CRC break; @@ -305,13 +301,16 @@ static int ini_sd(void) { /* Reset controller */ regs->software_reset = 1; while ((regs->software_reset & 1) == 0) {} + + // This clock divider is meant to initialize the card at + // 400kHz regs->clock_divider = 0x7c; regs->software_reset = 0; while (regs->software_reset) {} usleep(5000); card_type = 0; - drv_status = STA_NOINIT; + // drv_status = STA_NOINIT; if (regs->capability & SDC_CAPABILITY_SD_RESET) { /* Power cycle SD card */ @@ -365,14 +364,20 @@ static int ini_sd(void) { /* Set R/W block length to 512 */ if (send_cmd(CMD16, 512) < 0) return -1; - drv_status &= ~STA_NOINIT; + // drv_status &= ~STA_NOINIT; return 0; } -DRESULT disk_read(BYTE drv, BYTE * buf, LBA_t sector, UINT count) { +int disk_read(BYTE * buf, LBA_t sector, UINT count) { - if (!count) return RES_PARERR; - if (drv_status & STA_NOINIT) return RES_NOTRDY; + /* This is not needed. This has everything to do with the FAT + filesystem stuff that I'm not including. All I need to do is + initialize the SD card and read from it. Anything in here that is + checking for potential errors, I'm going to have to temporarily + do without. + */ + // if (!count) return RES_PARERR; + /* if (drv_status & STA_NOINIT) return RES_NOTRDY; */ /* Convert LBA to byte address if needed */ if (!(card_type & CT_BLOCK)) sector *= 512; @@ -380,39 +385,28 @@ DRESULT disk_read(BYTE drv, BYTE * buf, LBA_t sector, UINT count) { UINT bcnt = count > MAX_BLOCK_CNT ? MAX_BLOCK_CNT : count; unsigned bytes = bcnt * 512; if (send_data_cmd(bcnt == 1 ? CMD17 : CMD18, sector, buf, bcnt) < 0) return RES_ERROR; - if (bcnt > 1 && send_cmd(CMD12, 0) < 0) return RES_ERROR; + if (bcnt > 1 && send_cmd(CMD12, 0) < 0) return 1; sector += (card_type & CT_BLOCK) ? bcnt : bytes; count -= bcnt; buf += bytes; } - return RES_OK; + return 0;; } -void disk_read(BYTE drv, BYTE * buf, LBA_t sector, UINT count) { +void copyFlash(QWORD address, QWORD * Dst, DWORD numBlocks) { + ini_sd(); - if (!count) return RES_PARERR; - if (drv_status & STA_NOINIT) return RES_NOTRDY; - - /* Convert LBA to byte address if needed */ - if (!(card_type & CT_BLOCK)) sector *= 512; - while (count > 0) { - UINT bcnt = count > MAX_BLOCK_CNT ? MAX_BLOCK_CNT : count; - unsigned bytes = bcnt * 512; - if (send_data_cmd(bcnt == 1 ? CMD17 : CMD18, sector, buf, bcnt) < 0) return RES_ERROR; - if (bcnt > 1 && send_cmd(CMD12, 0) < 0) return RES_ERROR; - sector += (card_type & CT_BLOCK) ? bcnt : bytes; - count -= bcnt; - buf += bytes; - } - - return RES_OK; + BYTE * buf = (BYTE *)Dst; + + if (disk_read(buf, (LBA_t)address, (UINT)numBlocks) < 0) /* UART Print function?*/; } +/* int main() { ini_sd(); - return 0; } +*/ diff --git a/tests/custom/boot/boot.h b/tests/custom/boot/boot.h new file mode 100644 index 000000000..ef620cda0 --- /dev/null +++ b/tests/custom/boot/boot.h @@ -0,0 +1,12 @@ +#ifndef WALLYBOOT +#define WALLYBOOT 10000 + +#include +typedef unsigned int UINT; /* int must be 16-bit or 32-bit */ +typedef unsigned char BYTE; /* char must be 8-bit */ +typedef uint16_t WORD; /* 16-bit unsigned integer */ +typedef uint32_t DWORD; /* 32-bit unsigned integer */ +typedef uint64_t QWORD; /* 64-bit unsigned integer */ +typedef WORD WCHAR; + +#endif // WALLYBOOT