summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-11-13 07:45:45 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2014-02-11 02:07:50 (GMT)
commitd968971f04a1c843350e37009da36abd29c0b042 (patch)
tree2148d44d43c80d82144abf6fa5f40879927e8422
parentfa0da67856a709eda3de3921b2a9733012990bec (diff)
downloadabc8000-d968971f04a1c843350e37009da36abd29c0b042.zip
abc8000-d968971f04a1c843350e37009da36abd29c0b042.tar.gz
abc8000-d968971f04a1c843350e37009da36abd29c0b042.tar.bz2
abc8000-d968971f04a1c843350e37009da36abd29c0b042.tar.xz
sysrom, sdcard: advance the buf pointer between sectors!
Advance the buf pointer between sectors in a single transaction! Checksum the boot file for now, so we can tell if it actually works. With this, we can now genuinely boot a file from disk!
-rw-r--r--data/sysrom/abc/init.asm3
-rw-r--r--data/sysrom/sdcard.c38
2 files changed, 24 insertions, 17 deletions
diff --git a/data/sysrom/abc/init.asm b/data/sysrom/abc/init.asm
index 94cda14..ec16de9 100644
--- a/data/sysrom/abc/init.asm
+++ b/data/sysrom/abc/init.asm
@@ -6,6 +6,9 @@
.section ".init","ax"
.globl _start
_start:
+ /* Show light on the LEDs */
+ move.b #0xff, IO_SYS_LED
+
/* Write Hello, World! on the serial port */
move.l #IO_SERIAL_DATA, %a0 /* Data port */
lea.l 2(%a0), %a2 /* Status port */
diff --git a/data/sysrom/sdcard.c b/data/sysrom/sdcard.c
index 0263969..e877716 100644
--- a/data/sysrom/sdcard.c
+++ b/data/sysrom/sdcard.c
@@ -217,18 +217,6 @@ static int sdcard_read_block(void *buf, int len, int timeout, const void *xcmd)
}
}
- {
- int i, j;
- const uint8_t *p = buf;
-
- for (i = 0; p < pb; i += 16) {
- for (j = 0; j < 16; j++) {
- printf("%02x ", *p++);
- }
- printf("\n");
- }
- }
-
/*
* Now the CRC is latched in the shift register, and the CRC
* in the CRC generator should be zero. Shift in the first
@@ -256,6 +244,7 @@ int sdcard_read_sectors(void *buf, uint32_t lba, int count)
static const uint16_t stop_transmission[3] =
{ (0x40|CMD_STOP_TRANSMISSION) << 8, 0x0000, 0x0061 };
uint8_t resp;
+ uint8_t *p = buf;
if (!count)
return 0;
@@ -272,11 +261,13 @@ int sdcard_read_sectors(void *buf, uint32_t lba, int count)
}
while (count--) {
- rv = sdcard_read_block(buf, SECTOR_SIZE, 200000,
+ rv = sdcard_read_block(p, SECTOR_SIZE, 200000,
count ? NULL : stop_transmission);
if (rv)
return okcount;
+
okcount++;
+ p += SECTOR_SIZE;
}
/* The first byte after the stop command is undefined */
@@ -330,7 +321,7 @@ int sdcard_write_sectors(const void *buf, uint32_t lba, int count)
int okcount = 0;
const uint8_t *p = buf;
uint16_t crc;
- uint8_t resp;
+ uint8_t resp;
if (!count)
return 0;
@@ -665,12 +656,17 @@ DSTATUS disk_status(BYTE drive)
*/
static FATFS sd_fs;
+#define BOOT_ADDR 0x10000
+
void disk_boot(void)
{
static const char boot_filename[] = "abc8000.sys";
FRESULT fr;
FIL file;
UINT bytesread;
+ uint32_t csum;
+ const uint32_t *csump;
+ unsigned int size, i;
printf("Mounting SD card...\n");
f_mount(0, &sd_fs);
@@ -681,12 +677,20 @@ void disk_boot(void)
return;
printf("Reading boot file...\n");
- fr = f_read(&file, (void *)0x10000, file.fsize, &bytesread);
+ size = file.fsize;
+ fr = f_read(&file, (void *)BOOT_ADDR, size, &bytesread);
f_close(&file);
- if (fr != FR_OK)
+ if (fr != FR_OK || bytesread != size)
return;
+ csum = 0;
+ csump = (const uint32_t *)BOOT_ADDR;
+ for (i = 0; i < size; i += 4)
+ csum += *csump++;
+
+ printf("Boot file checksum: 0x%08x\n", csum);
+
printf("Jumping to boot file...\n");
- ((void (*)(void))0x10000)();
+ ((void (*)(void))BOOT_ADDR)();
}