From: Erik M. <er...@us...> - 2001-10-03 16:09:12
|
Update of /cvsroot/blob/blob/src In directory usw-pr-cvs1:/tmp/cvs-serv8731 Modified Files: clock.c command.c flash.c init.c main.c uucodec.c Log Message: And now for the cleanup: use the new error functions. Note that I didn't touch chkmem.c because I know Stefan is working on it. Index: clock.c =================================================================== RCS file: /cvsroot/blob/blob/src/clock.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- clock.c 2001/09/27 21:30:58 1.6 +++ clock.c 2001/10/03 16:09:09 1.7 @@ -36,6 +36,8 @@ #endif #include "command.h" +#include "errno.h" +#include "error.h" #include "types.h" #include "sa1100.h" #include "serial.h" @@ -61,17 +63,12 @@ u32 regs[5]; u32 startTime, currentTime; - if(argc < 6) { - /* FIXME: command loop should print error messages */ - SerialOutputString("*** not enough arguments\n"); - return 0; - } + if(argc < 6) + return -ENOPARAMS; for(i = 0; i < 5; i++) { if(strtoval(argv[i + 1], ®s[i]) < 0) { - SerialOutputString("*** not a number: "); - SerialOutputString(argv[i + 1]); - SerialOutputByte('\n'); + printerror(ENAN, argv[i + 1]); return 0; } } Index: command.c =================================================================== RCS file: /cvsroot/blob/blob/src/command.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- command.c 2001/10/02 21:54:48 1.8 +++ command.c 2001/10/03 16:09:09 1.9 @@ -36,6 +36,7 @@ #endif #include "command.h" +#include "errno.h" #include "init.h" #include "serial.h" #include "time.h" @@ -122,7 +123,8 @@ #ifdef BLOB_DEBUG for(i = 0; i < *argc; i++) { - SerialOutputString("*** argv["); + printerrprefix(); + SerialOutputString("argv["); SerialOutputDec(i); SerialOutputString("] = "); SerialOutputString(argv[i]); @@ -148,12 +150,14 @@ for(cmd = commands; cmd != NULL; cmd = cmd->next) { if(cmd->magic != COMMAND_MAGIC) { - SerialOutputString("*** Command magic failed for 0x"); +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("Address = 0x"); SerialOutputHex((u32)cmd); SerialOutputString("!\n"); +#endif - /* FIXME: should return a proper return value */ - return 0; + return -EMAGIC; } if(strcmp(cmd->name, cmdline) == 0) { @@ -162,7 +166,7 @@ } } - return -1; + return -ECOMMAND; } Index: flash.c =================================================================== RCS file: /cvsroot/blob/blob/src/flash.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- flash.c 2001/08/31 06:26:59 1.3 +++ flash.c 2001/10/03 16:09:09 1.4 @@ -35,6 +35,8 @@ # include "config.h" #endif +#include "errno.h" +#include "error.h" #include "led.h" #include "main.h" #include "util.h" @@ -180,7 +182,8 @@ SerialOutputByte('.'); led_toggle(); if((EraseOne(thisBlock) & STATUS_ERASE_ERR) != 0) { - SerialOutputString("\n*** Erase error at address 0x"); + printerrprefix(); + SerialOutputString("erase error at address 0x"); SerialOutputHex((u32)thisBlock); SerialOutputByte('\n'); return; @@ -203,9 +206,13 @@ #endif if((u32)source & 0x03) { - SerialOutputString("*** Source is not on a word boundary: 0x"); + printerror(EALIGN, NULL); +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("Address = 0x"); SerialOutputHex((u32)source); SerialOutputByte('\n'); +#endif return; } @@ -307,7 +314,8 @@ if((result & STATUS_PGM_ERR) != 0 || *flashBase != *source) { #endif - SerialOutputString("\n*** Write error at address 0x"); + printerrprefix(); + SerialOutputString("Write error at address 0x"); SerialOutputHex((u32)flashBase); SerialOutputByte('\n'); return; Index: init.c =================================================================== RCS file: /cvsroot/blob/blob/src/init.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- init.c 2001/10/02 21:39:54 1.2 +++ init.c 2001/10/03 16:09:09 1.3 @@ -27,8 +27,11 @@ # include "config.h" #endif +#include "errno.h" +#include "error.h" #include "init.h" #include "serial.h" +#include "types.h" /* int and exit list start and end. filled in by the linker */ @@ -45,10 +48,13 @@ for(item = start; item != end; item++) { if(item->magic != magic) { - SerialOutputString("*** Init magic failed for 0x"); + printerror(EMAGIC, NULL); +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("Address = 0x"); SerialOutputHex((u32)item); - SerialOutputString("!\n"); - + SerialOutputByte('\n'); +#endif return; } Index: main.c =================================================================== RCS file: /cvsroot/blob/blob/src/main.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- main.c 2001/10/02 21:54:48 1.15 +++ main.c 2001/10/03 16:09:09 1.16 @@ -39,6 +39,8 @@ #endif #include "command.h" +#include "errno.h" +#include "error.h" #include "flash.h" #include "init.h" #include "led.h" @@ -167,11 +169,8 @@ numRead = GetCommand(commandline, MAX_COMMANDLINE_LENGTH, 600); if(numRead > 0) { - if(parse_command(commandline) != 0 ) { - SerialOutputString("*** Unknown command: "); - SerialOutputString(commandline); - SerialOutputByte('\n'); - } + if((retval = parse_command(commandline)) < 0 ) + printerror(retval, NULL); } } @@ -186,13 +185,10 @@ u32 startAddress = 0; int bufLen; int *numRead = 0; + int retval; - if(argc < 2) { - SerialOutputString("*** not enough parameters\n"); - /* FIXME: let the command line parser print the error - message */ - return 0; - } + if(argc < 2) + return -ENOPARAMS; if(strncmp(argv[1], "blob", 4) == 0) { /* download blob */ @@ -221,9 +217,7 @@ numRead = &blob_status.ramdiskSize; blob_status.ramdiskType = fromDownload; } else { - SerialOutputString("*** Don't know how to download \""); - SerialOutputString(argv[1]); - SerialOutputString("\"\n"); + printerror(EINVAL, argv[1]); return 0; } @@ -247,13 +241,13 @@ if(*numRead < 0) { /* something went wrong */ - SerialOutputString("*** Uudecode receive failed\n"); + retval = *numRead; /* reload the correct memory */ do_reload(argv[1]); SerialInit(blob_status.terminalSpeed); - return 0; + return retval; } SerialOutputString("Received "); SerialOutputDec(*numRead); @@ -281,82 +275,64 @@ tBlockType block; int numBytes = 0; int maxSize = 0; + block_source_t type = fromFlash; - if(argc < 2) { - SerialOutputString("*** not enough parameters\n"); - /* FIXME: let the command line parser print the error - message */ - return 0; - } + if(argc < 2) + return -ENOPARAMS; if(strncmp(argv[1], "blob", 4) == 0) { startAddress = BLOB_RAM_BASE; block = blBlob; numBytes = blob_status.blobSize; maxSize = BLOB_LEN; - - if(blob_status.blobType == fromFlash) { - SerialOutputString("*** No blob downloaded\n"); - return 0; - } - - SerialOutputString("Saving blob to flash "); + type = blob_status.blobType; #ifdef PARAM_START } else if(strncmp(argv[1], "param", 5) == 0) { startAddress = PARAM_RAM_BASE; block = blParam; numBytes = blob_status.paramSize; maxSize = PARAM_LEN; - - if(blob_status.paramType == fromFlash) { - SerialOutputString("*** No paramater block downloaded\n"); - return 0; - } - - SerialOutputString("Saving paramater block to flash "); + type = blob_status.paramType; #endif } else if(strncmp(argv[1], "kernel", 6) == 0) { startAddress = KERNEL_RAM_BASE; block = blKernel; numBytes = blob_status.kernelSize; maxSize = KERNEL_LEN; - - if(blob_status.kernelType == fromFlash) { - SerialOutputString("*** No kernel downloaded\n"); - return 0; - } - - SerialOutputString("Saving kernel to flash "); + type = blob_status.kernelType; } else if(strncmp(argv[1], "ramdisk", 7) == 0) { startAddress = RAMDISK_RAM_BASE; block = blRamdisk; numBytes = blob_status.ramdiskSize; maxSize = INITRD_LEN; - - if(blob_status.ramdiskType == fromFlash) { - SerialOutputString("*** No ramdisk downloaded\n"); - return 0; - } - - SerialOutputString("Saving ramdisk to flash "); + type = blob_status.ramdiskType; } else { - SerialOutputString("*** Don't know how to flash \""); - SerialOutputString(argv[1]); - SerialOutputString("\"\n"); + printerror(EINVAL, argv[1]); return 0; } + if(type == fromFlash) { + /* error */ + printerrprefix(); + SerialOutputString(argv[1]); + SerialOutputString(" not downloaded\n"); + return -EINVAL; + } + if(numBytes > maxSize) { - SerialOutputString("*** Downloaded image too large for flash area\n"); - SerialOutputString("*** (0x"); + printerrprefix(); + SerialOutputString("image too large for flash: 0x"); SerialOutputHex(numBytes); - SerialOutputString(" downloaded, maximum size is 0x"); + SerialOutputString(" > 0x"); SerialOutputHex(maxSize); - SerialOutputString(" bytes)\n"); + SerialOutputByte('\n'); - return 0; + return -ETOOLONG; } + SerialOutputString("Saving "); + SerialOutputString(argv[1]); + SerialOutputString(" to flash "); EraseBlocks(block); SerialOutputByte(' '); WriteBlocksFromMem(block, (u32 *)startAddress, numBytes); @@ -388,10 +364,8 @@ return 0; } } - - SerialOutputString("*** Can't find help for '"); - SerialOutputString(argv[1]); - SerialOutputString("'\n"); + + printerror(EINVAL, argv[1]); return 0; } @@ -419,12 +393,8 @@ static int SetDownloadSpeed(int argc, char *argv[]) { - if(argc < 2) { - /* FIXME: return -EINVAL and let the command line - stuff print the error */ - SerialOutputString("*** not enough parameters\n"); - return 0; - } + if(argc < 2) + return -ENOPARAMS; if(strcmp(argv[1], "1200") == 0) { blob_status.downloadSpeed = baud1k2; @@ -455,11 +425,7 @@ } else if(strcmp(argv[1], "230k4") == 0) { blob_status.downloadSpeed = baud230k4; } else { - SerialOutputString("*** Invalid download speed value \""); - SerialOutputString(argv[1]); - SerialOutputString("\"\n*** Valid values are:\n"); - SerialOutputString("*** 1200, 9600, 19200, 38400, 57600, 115200, 230400\n"); - SerialOutputString("*** 1k2, 9k6, 19k2, 38k4, 57k6, 115k2, and 230k4\n"); + return -EINVAL; } SerialOutputString("Download speed set to "); @@ -469,8 +435,10 @@ return 0; } -static char speedhelp[] = "speed\n" -"Set download speed\n"; +static char speedhelp[] = "speed [baudrate]\n" +"Set download speed. Valid baudrates are:\n" +"1200, 9600, 19200, 38400, 57600, 115200, 230400,\n" +" 1k2, 9k6, 19k2, 38k4, 57k6, 115k2, 230k4\n"; __commandlist(SetDownloadSpeed, "speed", speedhelp); @@ -609,9 +577,7 @@ blob_status.ramdiskType = fromFlash; SerialOutputString("Loading ramdisk from flash "); } else { - SerialOutputString("*** Don't know how to reload \""); - SerialOutputString(what); - SerialOutputString("\"\n"); + printerror(EINVAL, what); return 0; } @@ -626,13 +592,9 @@ static int Reload(int argc, char *argv[]) { - if(argc < 2) { - /* FIXME: return -EINVAL and let the command line - stuff print the error */ - SerialOutputString("*** not enough parameters\n"); - return 0; - } - + if(argc < 2) + return -ENOPARAMS; + return do_reload(argv[1]); } Index: uucodec.c =================================================================== RCS file: /cvsroot/blob/blob/src/uucodec.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- uucodec.c 2001/09/16 15:44:00 1.3 +++ uucodec.c 2001/10/03 16:09:09 1.4 @@ -37,6 +37,7 @@ # include "config.h" #endif +#include "errno.h" #include "serial.h" #include "util.h" @@ -48,8 +49,7 @@ #define TEST_MAX_RETRIES do { \ if(retries++ > MAX_RETRIES) { \ - SerialOutputString("\n*** Timeout exceeded. Aborting.\n"); \ - return -1; \ + return -ETIMEOUT; \ } \ } while(0) @@ -60,8 +60,8 @@ #define OUT_OF_RANGE do { \ SerialOutputByte('\n'); \ SerialOutputString(buf); \ - SerialOutputString("\n*** Received character out of range. Aborting.\n"); \ - return -1; \ + SerialOutputByte('\n'); \ + return -ERANGE; \ } while(0) #define PUT_CHAR(x) do { \ @@ -94,8 +94,7 @@ /* for each input line */ for (;;) { if (SerialInputString(p = buf, sizeof(buf), 2) == 0) { - SerialOutputString("\n*** Short file. Aborting\n"); - return -1; + return -ETOOSHORT; } /* Status print to show where we are at right now */ if((linesReceived++ & 0x007F) == 0) { @@ -147,8 +146,8 @@ } SerialOutputByte('\n'); if (SerialInputString(p = buf, sizeof(buf), 2) == 0 || (strncmp(buf, "end", 3))) { - SerialOutputString("*** No \"end\" line. Aborting.\n"); - return(-1); + /* no "end" line */ + return -ETOOSHORT; } return(bytesWritten); } /* UUDecode */ |