|
From: Erik M. <er...@us...> - 2001-09-18 20:23:26
|
Update of /cvsroot/blob/blob/src
In directory usw-pr-cvs1:/tmp/cvs-serv22423/src
Modified Files:
main.c
Log Message:
Download() and Flash() also converted to the new command system
Index: main.c
===================================================================
RCS file: /cvsroot/blob/blob/src/main.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- main.c 2001/09/18 19:55:29 1.12
+++ main.c 2001/09/18 20:23:24 1.13
@@ -54,8 +54,6 @@
-void Download(char *commandline);
-void Flash(char *commandline);
static int do_reload(char *what);
static void PrintSerialSpeed(eBauds speed);
@@ -173,11 +171,7 @@
numRead = GetCommand(commandline, MAX_COMMANDLINE_LENGTH, 600);
if(numRead > 0) {
- if(strncmp(commandline, "download ", 9) == 0) {
- Download(commandline + 9);
- } else if(strncmp(commandline, "flash ", 6) == 0) {
- Flash(commandline + 6);
- } else if(parse_command(commandline) != 0 ) {
+ if(parse_command(commandline) != 0 ) {
SerialOutputString("*** Unknown command: ");
SerialOutputString(commandline);
SerialOutputByte('\n');
@@ -191,33 +185,40 @@
-void Download(char *commandline)
+static int Download(int argc, char *argv[])
{
u32 startAddress = 0;
int bufLen;
int *numRead = 0;
- if(strncmp(commandline, "blob", 4) == 0) {
+ if(argc < 2) {
+ SerialOutputString("*** not enough parameters\n");
+ /* FIXME: let the command line parser print the error
+ message */
+ return 0;
+ }
+
+ if(strncmp(argv[1], "blob", 4) == 0) {
/* download blob */
startAddress = BLOB_RAM_BASE;
bufLen = blob_status.blockSize - BLOB_BLOCK_OFFSET;
numRead = &blob_status.blobSize;
blob_status.blobType = fromDownload;
#ifdef PARAM_START
- } else if(strncmp(commandline, "param", 5) == 0) {
+ } else if(strncmp(argv[1], "param", 5) == 0) {
/* download kernel */
startAddress = PARAM_RAM_BASE;
bufLen = PARAM_LEN;
numRead = &blob_status.paramSize;
blob_status.paramType = fromDownload;
#endif
- } else if(strncmp(commandline, "kernel", 6) == 0) {
+ } else if(strncmp(argv[1], "kernel", 6) == 0) {
/* download kernel */
startAddress = KERNEL_RAM_BASE;
bufLen = blob_status.blockSize - KERNEL_BLOCK_OFFSET;
numRead = &blob_status.kernelSize;
blob_status.kernelType = fromDownload;
- } else if(strncmp(commandline, "ramdisk", 7) == 0) {
+ } else if(strncmp(argv[1], "ramdisk", 7) == 0) {
/* download ramdisk */
startAddress = RAMDISK_RAM_BASE;
bufLen = blob_status.blockSize - RAMDISK_BLOCK_OFFSET;
@@ -225,9 +226,9 @@
blob_status.ramdiskType = fromDownload;
} else {
SerialOutputString("*** Don't know how to download \"");
- SerialOutputString(commandline);
+ SerialOutputString(argv[1]);
SerialOutputString("\"\n");
- return;
+ return 0;
}
@@ -253,10 +254,10 @@
SerialOutputString("*** Uudecode receive failed\n");
/* reload the correct memory */
- do_reload(commandline);
+ do_reload(argv[1]);
SerialInit(blob_status.terminalSpeed);
- return;
+ return 0;
}
SerialOutputString("Received ");
SerialOutputDec(*numRead);
@@ -266,19 +267,33 @@
SerialInit(blob_status.terminalSpeed);
+
+ return 0;
}
+static char downloadhelp[] = "download {blob|param|kernel|ramdisk}\n"
+"Download <argument> image to RAM\n";
+__commandlist(Download, "download", downloadhelp);
-void Flash(char *commandline)
+
+
+static int Flash(int argc, char *argv[])
{
u32 startAddress = 0;
tBlockType block;
int numBytes = 0;
int maxSize = 0;
- if(strncmp(commandline, "blob", 4) == 0) {
+ if(argc < 2) {
+ SerialOutputString("*** not enough parameters\n");
+ /* FIXME: let the command line parser print the error
+ message */
+ return 0;
+ }
+
+ if(strncmp(argv[1], "blob", 4) == 0) {
startAddress = BLOB_RAM_BASE;
block = blBlob;
numBytes = blob_status.blobSize;
@@ -286,12 +301,12 @@
if(blob_status.blobType == fromFlash) {
SerialOutputString("*** No blob downloaded\n");
- return;
+ return 0;
}
SerialOutputString("Saving blob to flash ");
#ifdef PARAM_START
- } else if(strncmp(commandline, "param", 5) == 0) {
+ } else if(strncmp(argv[1], "param", 5) == 0) {
startAddress = PARAM_RAM_BASE;
block = blParam;
numBytes = blob_status.paramSize;
@@ -299,12 +314,12 @@
if(blob_status.paramType == fromFlash) {
SerialOutputString("*** No paramater block downloaded\n");
- return;
+ return 0;
}
SerialOutputString("Saving paramater block to flash ");
#endif
- } else if(strncmp(commandline, "kernel", 6) == 0) {
+ } else if(strncmp(argv[1], "kernel", 6) == 0) {
startAddress = KERNEL_RAM_BASE;
block = blKernel;
numBytes = blob_status.kernelSize;
@@ -312,11 +327,11 @@
if(blob_status.kernelType == fromFlash) {
SerialOutputString("*** No kernel downloaded\n");
- return;
+ return 0;
}
SerialOutputString("Saving kernel to flash ");
- } else if(strncmp(commandline, "ramdisk", 7) == 0) {
+ } else if(strncmp(argv[1], "ramdisk", 7) == 0) {
startAddress = RAMDISK_RAM_BASE;
block = blRamdisk;
numBytes = blob_status.ramdiskSize;
@@ -324,15 +339,15 @@
if(blob_status.ramdiskType == fromFlash) {
SerialOutputString("*** No ramdisk downloaded\n");
- return;
+ return 0;
}
SerialOutputString("Saving ramdisk to flash ");
} else {
SerialOutputString("*** Don't know how to flash \"");
- SerialOutputString(commandline);
+ SerialOutputString(argv[1]);
SerialOutputString("\"\n");
- return;
+ return 0;
}
if(numBytes > maxSize) {
@@ -343,24 +358,27 @@
SerialOutputHex(maxSize);
SerialOutputString(" bytes)\n");
- return;
+ return 0;
}
EraseBlocks(block);
SerialOutputByte(' ');
WriteBlocksFromMem(block, (u32 *)startAddress, numBytes);
SerialOutputString(" done\n");
+
+ return 0;
}
+static char flashhelp[] = "flash {blob|param|kernel|ramdisk}\n"
+"Write <argument> image to flash\n";
+__commandlist(Flash, "flash", flashhelp);
+
+
static int PrintHelp(int argc, char *argv[])
{
-#if 0
- SerialOutputString("* download {blob|param|kernel|ramdisk} Download <argument> image to RAM\n");
- SerialOutputString("* flash {blob|param|kernel|ramdisk} Copy <argument> from RAM to flash\n");
-#endif
commandlist_t *cmd;
/* help on a command? */
|