Index: current/src/load.c =================================================================== RCS file: /cvs/ecos/ecos/packages/redboot/current/src/load.c,v retrieving revision 1.33 diff -u -r1.33 load.c --- current/src/load.c 14 Apr 2003 16:45:37 -0000 1.33 +++ current/src/load.c 11 Jul 2003 07:48:09 -0000 @@ -69,8 +69,9 @@ #include #endif #endif +#include -static char usage[] = "[-r] [-v] " +static char usage[] = "[-r] [-v] [-f ] " #ifdef CYGPKG_COMPRESS_ZLIB "[-d] " #endif @@ -87,6 +88,48 @@ do_load ); +// program directly to flash +#define FLASH_DIRECT() 1 +#if FLASH_DIRECT() + +static char buffer[16]; +static int bufferPos=0; +static unsigned char *writeAddr; + +static void WRITE_FLUSH() +{ + void *error; + bufferPos=0; + flash_program_core(writeAddr, buffer, sizeof(buffer), &error, false); +} + +static void WRITE_BYTE(unsigned char *address, unsigned char value) +{ + + if (bufferPos==0) + { + writeAddr=address; + } + + buffer[bufferPos]=value; + bufferPos++; + if (bufferPos==sizeof(buffer)) + { + WRITE_FLUSH(); + + } +} + + + + + + +#else +#define WRITE_BYTE(address, value) *(address)=(value) +#endif + + // // Stream I/O support // @@ -577,6 +620,8 @@ int res, num_options; int i, err; bool verbose, raw; + bool write_to_flash; + unsigned long flash_length; bool base_addr_set, mode_str_set; char *mode_str; #ifdef CYGPKG_REDBOOT_NETWORKING @@ -593,7 +638,7 @@ unsigned long end = 0; char type[4]; char *filename = 0; - struct option_info opts[7]; + struct option_info opts[8]; connection_info_t info; getc_io_funcs_t *io = NULL; struct load_io_entry *io_tab; @@ -617,7 +662,10 @@ (void **)&base, (bool *)&base_addr_set, "load address"); init_opts(&opts[3], 'm', true, OPTION_ARG_TYPE_STR, (void **)&mode_str, (bool *)&mode_str_set, "download mode (TFTP, xyzMODEM, or disk)"); - num_options = 4; + init_opts(&opts[4], 'f', true, OPTION_ARG_TYPE_NUM, + (void **)&flash_length, &write_to_flash, "write to flash"); + num_options = 5; + #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1 init_opts(&opts[num_options], 'c', true, OPTION_ARG_TYPE_NUM, (void **)&chan, (bool *)&chan_set, "I/O channel"); @@ -710,7 +758,8 @@ if (base_addr_set && ((base < (unsigned long)user_ram_start) || (base > (unsigned long)user_ram_end))) { - if (!verify_action("Specified address (%p) is not believed to be in RAM", (void*)base)) + + if (!write_to_flash&&!verify_action("Specified address (%p) is not believed to be in RAM", (void*)base)) return; spillover_ok = true; } @@ -719,6 +768,15 @@ diag_printf("Raw load requires a memory address\n"); return; } + + // before we can start upload, we must erase previous flash data + if (raw&&write_to_flash) + { + void *error; + diag_printf("*** Erasing %p-%p\n",(void*)base, base+flash_length-1); + flash_erase(base, flash_length, &error); + } + info.filename = filename; info.chan = chan; info.mode = io_tab ? io_tab->mode : 0; @@ -746,8 +804,19 @@ break; } #endif - *mp++ = res; - } + if (write_to_flash) + { + WRITE_BYTE(mp, res); + } else + { + *mp=res; + } + mp++; + } + if (write_to_flash) + { + WRITE_FLUSH(); + } end = (unsigned long) mp; // Save load base/top Index: flash/current/include/flash.h =================================================================== RCS file: /cvs/ecos/ecos/packages/io/flash/current/include/flash.h,v retrieving revision 1.15 diff -u -r1.15 flash.h --- flash/current/include/flash.h 23 May 2002 23:06:14 -0000 1.15 +++ flash/current/include/flash.h 11 Jul 2003 07:48:10 -0000 @@ -63,6 +63,7 @@ externC int flash_init(void *work_space, int work_space_length, _printf *pf); externC int flash_erase(void *base, int len, void **err_address); externC int flash_program(void *flash_base, void *ram_base, int len, void **err_address); +externC int flash_program_core(void *flash_base, void *ram_base, int len, void **err_address, int log); externC void flash_dev_query(void *data); #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING externC int flash_lock(void *base, int len, void **err_address); Index: flash/current/src/flash.c =================================================================== RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flash.c,v retrieving revision 1.20 diff -u -r1.20 flash.c --- flash/current/src/flash.c 23 May 2002 23:06:16 -0000 1.20 +++ flash/current/src/flash.c 11 Jul 2003 07:48:10 -0000 @@ -255,7 +255,7 @@ } int -flash_program(void *_addr, void *_data, int len, void **err_addr) +flash_program_core(void *_addr, void *_data, int len, void **err_addr, int log) { int stat = 0; int size; @@ -291,9 +291,11 @@ } #endif + if (log) + { (*flash_info.pf)("... Program from %p-%p at %p: ", (void*)data, (void*)(((CYG_ADDRESS)data)+len), (void*)addr); - + } HAL_FLASH_CACHES_OFF(d_cache, i_cache); FLASH_Enable((unsigned short*)addr, (unsigned short *)(addr+len)); while (len > 0) { @@ -314,22 +316,36 @@ if (0 == stat) // Claims to be OK if (memcmp(addr, data, size) != 0) { stat = 0x0BAD; - (*flash_info.pf)("V"); +if (log) +{ (*flash_info.pf)("V"); +} } #endif if (stat) { *err_addr = (void *)addr; break; } + if (log) + { (*flash_info.pf)("."); + } len -= size; addr += size/sizeof(*addr); data += size/sizeof(*data); } FLASH_Disable((unsigned short*)addr, (unsigned short *)(addr+len)); HAL_FLASH_CACHES_ON(d_cache, i_cache); + if (log) + { (*flash_info.pf)("\n"); + } return (stat); +} + +int +flash_program(void *_addr, void *_data, int len, void **err_addr) +{ + flash_program_core(_addr, _data, len, err_addr, true); } #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING