Going to extend basflash.c to

1.) load srec files to their RAM destination without flashing for testing
2.) load and flash srec files from SD card
This commit is contained in:
Markus Fröschle
2013-01-31 14:06:51 +00:00
parent 0e34080b4c
commit 75e9007f00
4 changed files with 180 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* bas_types.h * s19reader.h
* *
* Created on: 17.11.2012 * Created on: 17.11.2012
* Author: mfro * Author: mfro
@@ -26,6 +26,6 @@
#ifndef _S19READER_H_ #ifndef _S19READER_H_
#define _S19READER_H_ #define _S19READER_H_
extern void flasher_load(char *flasher_filename); extern void srec_execute(char *filename);
#endif /* _S19READER_H_ */ #endif /* _S19READER_H_ */

View File

@@ -241,7 +241,7 @@ void BaS(void)
xprintf("finished\r\n"); xprintf("finished\r\n");
sd_card_init(); sd_card_init();
flasher_load("BASFLASH.S19"); srec_execute("BASFLASH.S19");
/* /*
* memory setup * memory setup

View File

@@ -6,9 +6,185 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include <bas_printf.h> #include <bas_printf.h>
#include <diskio.h>
#include <ff.h>
#include <s19reader.h>
typedef enum {OK, ERR} err_t;
bool memcpy()
{
return true;
}
bool verify()
{
return true;
}
bool simulate()
{
return true;
}
void srec_flash(char *flash_filename)
{
DRESULT res;
FRESULT fres;
FATFS fs;
FIL file;
err_t err;
void *start_address;
uint32_t length;
// disk_initialize(0);
res = disk_status(0);
if (res == RES_OK)
{
fres = f_mount(0, &fs);
if (fres == FR_OK)
{
if ((fres = f_open(&file, flash_filename, FA_READ) != FR_OK))
{
xprintf("flasher file %s not present on disk\r\n", flash_filename);
}
else
{
f_close(&file);
/* first pass: parse and check for inconsistencies */
xprintf("check file integrity: ");
err = read_srecords(flash_filename, &start_address, &length, simulate);
if (err == OK)
{
/* next pass: copy data to destination */
xprintf("OK.\r\ncopy/flash data: ");
err = read_srecords(flash_filename, &start_address, &length, memcpy);
if (err == OK)
{
/* next pass: verify data */
xprintf("OK.\r\nverify data: ");
err = read_srecords(flash_filename, &start_address, &length, verify);
if (err == OK)
{
xprintf("OK.\r\n");
typedef void void_func(void);
void_func *func;
xprintf("target successfully written and verified. Start address: %p\r\n", start_address);
func = start_address;
(*func)();
}
else
{
xprintf("failed\r\n");
}
}
else
{
xprintf("failed\r\n");
}
}
else
{
xprintf("failed\r\n");
}
}
}
else
{
// xprintf("could not mount FAT FS\r\n");
}
f_mount(0, 0L);
}
else
{
// xprintf("could not initialize SD card\r\n");
}
}
void srec_load(char *flash_filename)
{
DRESULT res;
FRESULT fres;
FATFS fs;
FIL file;
err_t err;
void *start_address;
uint32_t length;
// disk_initialize(0);
res = disk_status(0);
if (res == RES_OK)
{
fres = f_mount(0, &fs);
if (fres == FR_OK)
{
if ((fres = f_open(&file, flash_filename, FA_READ) != FR_OK))
{
xprintf("flasher file %s not present on disk\r\n", flash_filename);
}
else
{
f_close(&file);
/* first pass: parse and check for inconsistencies */
xprintf("check file integrity: ");
err = read_srecords(flash_filename, &start_address, &length, simulate);
if (err == OK)
{
/* next pass: copy data to destination */
xprintf("OK.\r\ncopy/flash data: ");
err = read_srecords(flash_filename, &start_address, &length, memcpy);
if (err == OK)
{
/* next pass: verify data */
xprintf("OK.\r\nverify data: ");
err = read_srecords(flash_filename, &start_address, &length, verify);
if (err == OK)
{
xprintf("OK.\r\n");
typedef void void_func(void);
void_func *func;
xprintf("target successfully written and verified. Start address: %p\r\n", start_address);
func = start_address;
(*func)();
}
else
{
xprintf("failed\r\n");
}
}
else
{
xprintf("failed\r\n");
}
}
else
{
xprintf("failed\r\n");
}
}
}
else
{
// xprintf("could not mount FAT FS\r\n");
}
f_mount(0, 0L);
}
else
{
// xprintf("could not initialize SD card\r\n");
}
}
void basflash(void) void basflash(void)
{ {
const char *basauto_str = "\\BASAUTO\\";
const char *bassimu_str = "\\BASSIMU\\";
xprintf("\r\nHello from BASFLASH.S19!\r\n\r\n"); xprintf("\r\nHello from BASFLASH.S19!\r\n\r\n");
} }

View File

@@ -329,7 +329,7 @@ err_t verify(uint8_t *dst, uint8_t *src, uint32_t length)
return OK; return OK;
} }
void flasher_load(char *flasher_filename) void srec_execute(char *flasher_filename)
{ {
DRESULT res; DRESULT res;
FRESULT fres; FRESULT fres;