You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
1.3 KiB

#include <stdio.h>
#include "platform.h"
#include "cfi_flash.h"
#define DOT_LEN (64)
#define APPNAME "c6xapp.bin"
static int __get_file_size(const char *name)
{
int len = 0;
FILE *sfp = fopen(name, "rb");
if (sfp == NULL) {
printf("can't open file to read: %s\n", name);
return -1;
}
fseek(sfp, 0L, SEEK_END);
len = ftell(sfp);
fclose(sfp);
return (len);
}
static int __write_to_flash(const char *name, int off)
{
FILE *sfp = fopen(name, "rb");
unsigned char buf[256];
int n, cnt = 0;
if (sfp == NULL) {
return -1;
}
off = 0;
printf("write to %s flash at: 0x%x\n", name, off);
while (!feof(sfp)) {
n = fread(buf, 1, sizeof buf, sfp);
if (n > 0) {
printf(".");
++cnt;
if (cnt == DOT_LEN) {
printf("\r\n");
cnt = 0;
}
cfi_flash_write(off, buf, n);
off += n;
}
}
fclose(sfp);
return 0;
}
int main()
{
int len, ch;
platform_init();
printf("erase the flash: Y/N ? ");
ch = getchar();
if (ch != 'y' && ch != 'Y') {
printf("flash burn abort\n");
return -1;
}
len = __get_file_size(APPNAME);
printf("flash erasing ...\n");
cfi_flash_erase(0, len);
printf("flash erase done\n");
__write_to_flash(APPNAME, 0);
printf("write %s to flash done\n", APPNAME);
return 0;
}