started development of bootstrap flashing code load

This commit is contained in:
Markus Fröschle
2012-12-16 07:52:21 +00:00
parent fd76c01fe6
commit d9f3c5e3c5
5 changed files with 83 additions and 49 deletions

View File

@@ -63,6 +63,7 @@ CSRCS= \
$(SRCDIR)/mmc.c \ $(SRCDIR)/mmc.c \
$(SRCDIR)/unicode.c \ $(SRCDIR)/unicode.c \
$(SRCDIR)/ff.c \ $(SRCDIR)/ff.c \
$(SRCDIR)/sd_card.c \
$(SRCDIR)/wait.c $(SRCDIR)/wait.c
ASRCS= \ ASRCS= \

View File

@@ -34,6 +34,7 @@ SECTIONS
objs/unicode.o(.text) objs/unicode.o(.text)
objs/mmc.o(.text) objs/mmc.o(.text)
objs/ff.o(.text) objs/ff.o(.text)
objs/sd_card.o(.text)
objs/bas_printf.o(.text) objs/bas_printf.o(.text)
objs/printf_helper.o(.text) objs/printf_helper.o(.text)
objs/cache.o(.text) objs/cache.o(.text)

View File

@@ -33,12 +33,7 @@
#include <MCF5475.h> #include <MCF5475.h>
#include <stdint.h> #include <stdint.h>
extern void spi_init(void); extern void sd_card_init(void);
extern uint32_t sd_com(uint32_t data);
extern void sd_card_idle(void);
extern uint8_t sd_card_get_status(void);
extern uint8_t spi_send_byte(uint8_t byte);
extern uint16_t spi_send_word(uint16_t word);
/* MMC card type flags (MMC_GET_TYPE) */ /* MMC card type flags (MMC_GET_TYPE) */
#define CT_MMC 0x01 /* MMC ver 3 */ #define CT_MMC 0x01 /* MMC ver 3 */

View File

@@ -29,7 +29,7 @@
#include "cache.h" #include "cache.h"
#include "bas_printf.h" #include "bas_printf.h"
#include "bas_types.h" #include "bas_types.h"
#include "sd_card.h" #include <sd_card.h>
#include <wait.h> #include <wait.h>
#include <diskio.h> #include <diskio.h>
@@ -176,53 +176,12 @@ void BaS(void)
uint8_t *src; uint8_t *src;
uint8_t *dst = (uint8_t *)TOS; uint8_t *dst = (uint8_t *)TOS;
uint32_t *adr; uint32_t *adr;
DRESULT res;
FATFS fs;
FRESULT fres;
pic_init(); pic_init();
nvram_init(); nvram_init();
disk_initialize(0);
res = disk_status(0);
xprintf("disk status of SD card is %d\r\n", res);
if (res == RES_OK)
{
fres = f_mount(0, &fs);
xprintf("mount status of SD card fs is %d\r\n", fres);
if (fres == FR_OK)
{
DIR directory;
FIL file;
fres = f_opendir(&directory, "\\"); sd_card_init();
if (fres == FR_OK)
{
FILINFO fi;
while (((fres = f_readdir(&directory, &fi)) == FR_OK) && fi.fname[0])
{
xprintf("%13.13s %d\r\n", fi.fname, fi.fsize);
}
}
else
{
xprintf("could not open directory \"\\\" on SD-card! Error code: %d\r\n", fres);
}
fres = f_open(&file, "WELCOME.MSG", FA_READ);
if (fres == FR_OK)
{
char line[128];
while (f_gets(line, sizeof(line), &file))
{
xprintf("%s", line);
}
}
f_close(&file);
}
f_mount(0, 0L); /* release work area */
}
xprintf("copy EmuTOS: "); xprintf("copy EmuTOS: ");
/* copy EMUTOS */ /* copy EMUTOS */

78
BaS_gcc/sources/sd_card.c Normal file
View File

@@ -0,0 +1,78 @@
/*
* sd_card.c
*
* Created on: 16.12.2012
* Author: mfro
*/
#include <sd_card.h>
#include <diskio.h>
#include <ff.h>
#include <bas_printf.h>
#define WELCOME_NAME "WELCOME.MSG"
#define FLASHCODE_NAME "BASFLASH.BIN"
void sd_card_init(void)
{
DRESULT res;
FATFS fs;
FRESULT fres;
disk_initialize(0);
res = disk_status(0);
xprintf("disk status of SD card is %d\r\n", res);
if (res == RES_OK)
{
fres = f_mount(0, &fs);
xprintf("mount status of SD card fs is %d\r\n", fres);
if (fres == FR_OK)
{
DIR directory;
FIL file;
fres = f_opendir(&directory, "\\");
if (fres == FR_OK)
{
FILINFO fi;
while (((fres = f_readdir(&directory, &fi)) == FR_OK) && fi.fname[0])
{
xprintf("%13.13s %d\r\n", fi.fname, fi.fsize);
}
}
else
{
xprintf("could not open directory \"\\\" on SD-card! Error code: %d\r\n", fres);
}
fres = f_open(&file, WELCOME_NAME, FA_READ);
if (fres == FR_OK)
{
char line[128];
while (f_gets(line, sizeof(line), &file))
{
xprintf("%s", line);
}
}
f_close(&file);
/*
* let's see if we find our boot flashing executable on disk
*/
fres = f_open(&file, FLASHCODE_NAME, FA_READ);
if (fres == FR_OK)
{
/*
* yes, load and execute it
*
* FIXME: we will need some kind of user confirmation here
* to avoid unwanted flashing or "bootsector viruses" before going productive
*/
}
f_close(&file);
}
f_mount(0, 0L); /* release work area */
}
}