diff options
author | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-02-28 08:25:46 +0000 |
---|---|---|
committer | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-02-28 08:25:46 +0000 |
commit | d17e1cd93384d56886be7e67cf2b31e97118d811 (patch) | |
tree | 119eb57a4a078992cf5e79c4f59c410923e39adb /ecosflash/flash.c | |
parent | 0689e3dd6752f45f493eceb3edf040fbc7849846 (diff) | |
download | riscv-openocd-d17e1cd93384d56886be7e67cf2b31e97118d811.zip riscv-openocd-d17e1cd93384d56886be7e67cf2b31e97118d811.tar.gz riscv-openocd-d17e1cd93384d56886be7e67cf2b31e97118d811.tar.bz2 |
eCos flash driver.
git-svn-id: svn://svn.berlios.de/openocd/trunk@365 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'ecosflash/flash.c')
-rw-r--r-- | ecosflash/flash.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ecosflash/flash.c b/ecosflash/flash.c new file mode 100644 index 0000000..654273d --- /dev/null +++ b/ecosflash/flash.c @@ -0,0 +1,72 @@ +#include <string.h> +#define _FLASH_PRIVATE_ +#include <cyg/io/flash.h> + + + +int myprintf(char *format, ...) +{ + return 0; +} + +extern char _start_bss_clear; +extern char __bss_end__; + +int init() +{ + // set up runtime environment + char *t; + for (t=&_start_bss_clear; t<&__bss_end__; t++) + { + *t=0; + } + return flash_init((_printf *)&myprintf); + +} + + +int checkFlash(void *addr, int len) +{ + // Return error for illegal addresses + if ((addr<flash_info.start)||(addr>flash_info.end)) + return FLASH_ERR_INVALID; + if ((((cyg_uint8 *)addr)+len)>(cyg_uint8 *)flash_info.end) + return FLASH_ERR_INVALID; + return FLASH_ERR_OK; +} + + +int erase(void *address, int len) +{ + int retval; + void *failAddress; + + retval=checkFlash(address, len); + if (retval!=0) + return retval; + + retval=init(); + if (retval!=0) + return retval; + return flash_erase(address, len, &failAddress); +} + + + +extern char _end; + +// Data follows immediately after program, long word aligned. +int program(void *buffer, void *address, int len) +{ + int retval; + void *failAddress; + retval=checkFlash(address, len); + if (retval!=0) + return retval; + + retval=init(); + if (retval!=0) + return retval; + //int flash_program(void *_addr, void *_data, int len, void **err_addr) + return flash_program(address, buffer, len, &failAddress); +} |