" tfsstore copy TFSRAM to SPIF",
" tfserase erase SPIF space allocated to TFS",
" tfsrm {name} remove file directly out of SPI flash",
- " tfsadd {name} {src} {sz} add file directly to SPI flash",
+ " tfsadd {name} [src sz] add file directly to SPI flash",
#endif
" berase {addr bsize} block erase (bsize=4K,32K,64K)",
" read {addr dest len} read block",
char *arg4 = argv[optind+3];
char *icomma, *fcomma;
- if (argc != optind+4)
- return(CMD_PARAM_ERROR);
-
- // Extract flags and info fields (if any) from the name...
info = "";
bflags = 0;
name = arg2;
- fcomma = strchr(name,',');
- if (fcomma) {
- icomma = strchr(fcomma+1,',');
- if (icomma) {
- *icomma = 0;
- info = icomma+1;
+ addr = BASE_OF_SERIALTFS;
+
+ /* The incoming arguments can be either just the filename (in which
+ * case we assume the source is the file in TFS with the same name),
+ * or the filename, source address and size...
+ */
+ if (argc == optind+2) { // Just filename?
+ if ((fp = tfsstat(name)) == (TFILE *)0) {
+ printf("File '%s' not in TFS\n",name);
+ return(CMD_FAILURE);
+ }
+ name = fp->name;
+ info = fp->info;
+ bflags = fp->flags;
+ size = fp->filsize;
+ src = (char *)(fp + 1);
+ fp = &tfshdr;
+ memset((char *)fp,0,TFSHDRSIZ);
+ }
+ else if (argc == optind+4) { // Filename with addr and len
+ // Extract flags and info fields (if any) from the name...
+ fcomma = strchr(name,',');
+ if (fcomma) {
+ icomma = strchr(fcomma+1,',');
+ if (icomma) {
+ *icomma = 0;
+ info = icomma+1;
+ }
+ *fcomma = 0;
+ bflags = tfsctrl(TFS_FATOB,(long)(fcomma+1),0);
}
- *fcomma = 0;
- bflags = tfsctrl(TFS_FATOB,(long)(fcomma+1),0);
+
+ fp = &tfshdr;
+ memset((char *)fp,0,TFSHDRSIZ);
+ size = (int)strtol(arg4,0,0);
+ src = (char *)strtoul(arg3,0,0);
}
+ else
+ return(CMD_PARAM_ERROR);
- fp = &tfshdr;
- memset((char *)fp,0,TFSHDRSIZ);
- addr = BASE_OF_SERIALTFS;
- size = (int)strtol(arg4,0,0);
- src = (char *)strtoul(arg3,0,0);
while(addr < END_OF_SERIALTFS) {
if ((rc = spifReadBlock(addr,(char *)fp,TFSHDRSIZ)) < 0)
break;
fp->flags &= ~TFS_ACTIVE;
spifWriteEnable();
spifGlobalUnprotect();
+ spifWaitForReady();
+ spifWriteEnable();
if ((rc = spifWriteBlock(addr,(char *)fp,TFSHDRSIZ)) < 0)
printf(" write_hdr failed %d\n",rc);
spifGlobalProtect();