From: Erik M. <er...@us...> - 2001-07-20 18:39:06
|
Update of /cvsroot/blob/blob/src In directory usw-pr-cvs1:/tmp/cvs-serv23505/src Modified Files: Tag: blob_1_0_9_hack command.c flash.c main.c serial.c time.c uucodec.c Log Message: - Use OS counter for timeouts instead of Real Time Clock. Not completely clean yet, because we're not yet testing for overflows, but at least it fixes the 'doesn't time out after reboot' problem. - Comment out the uuencode uploading code. - Change \r into \n and change SerialOutputByte() to reflect the changes. It now looks more like real UNIX source :) Index: command.c =================================================================== RCS file: /cvsroot/blob/blob/src/command.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- command.c 2001/06/27 19:47:42 1.1.1.1 +++ command.c 2001/07/20 18:39:03 1.1.1.1.2.1 @@ -65,6 +65,8 @@ int numRead; int maxRead = len - 1; + TimerClearOverflow(); + startTime = TimerGetTime(); for(numRead = 0, i = 0; numRead < maxRead;) { @@ -85,7 +87,7 @@ command[i++] = '\0'; /* print newline */ - SerialOutputByte('\r'); + SerialOutputByte('\n'); return(numRead); } else if(c == '\b') { /* FIXME: is this backspace? */ if(i > 0) { Index: flash.c =================================================================== RCS file: /cvsroot/blob/blob/src/flash.c,v retrieving revision 1.1.1.1.2.3 retrieving revision 1.1.1.1.2.4 diff -u -r1.1.1.1.2.3 -r1.1.1.1.2.4 --- flash.c 2001/07/18 23:53:52 1.1.1.1.2.3 +++ flash.c 2001/07/20 18:39:03 1.1.1.1.2.4 @@ -156,9 +156,9 @@ for(i = 0; i < numBlocks; i++, thisBlock += MAIN_BLOCK_SIZE) { SerialOutputByte('.'); if((EraseOne(thisBlock) & STATUS_ERASE_ERR) != 0) { - SerialOutputString("\r*** Erase error at address 0x"); + SerialOutputString("\n*** Erase error at address 0x"); SerialOutputHex((u32)thisBlock); - SerialOutputByte('\r'); + SerialOutputByte('\n'); return; } } @@ -176,7 +176,7 @@ if((u32)source & 0x03) { SerialOutputString("*** Source is not on a word boundary: 0x"); SerialOutputHex((u32)source); - SerialOutputByte('\r'); + SerialOutputByte('\n'); return; } @@ -215,7 +215,7 @@ SerialOutputHex((u32)source); SerialOutputString(" to 0x"); SerialOutputHex((u32)flashBase); - SerialOutputByte('\r'); + SerialOutputByte('\n'); #endif for(i = 0; i < length; i+= 4, flashBase++, source++) { @@ -233,9 +233,9 @@ *flashBase = data_to_flash(READ_ARRAY); if((result & STATUS_PGM_ERR) != 0 || *flashBase != *source) { - SerialOutputString("\r*** Write error at address 0x"); + SerialOutputString("\n*** Write error at address 0x"); SerialOutputHex((u32)flashBase); - SerialOutputByte('\r'); + SerialOutputByte('\n'); return; } } @@ -254,7 +254,7 @@ #ifdef BLOB_DEBUG SerialOutputString(__FUNCTION__ "(): erasing block at address 0x"); SerialOutputHex((u32)whichOne); - SerialOutputByte('\r'); + SerialOutputByte('\n'); #endif *writeMe = data_to_flash(ERASE_SETUP); Index: main.c =================================================================== RCS file: /cvsroot/blob/blob/src/main.c,v retrieving revision 1.1.1.1.2.7 retrieving revision 1.1.1.1.2.8 diff -u -r1.1.1.1.2.7 -r1.1.1.1.2.8 --- main.c 2001/07/18 23:49:41 1.1.1.1.2.7 +++ main.c 2001/07/20 18:39:03 1.1.1.1.2.8 @@ -114,18 +114,18 @@ TimerInit(); /* Print the required GPL string */ - SerialOutputString("\rConsider yourself LARTed!\r\r"); - SerialOutputString(PACKAGE " version " VERSION "\r" + SerialOutputString("\nConsider yourself LARTed!\n\n"); + SerialOutputString(PACKAGE " version " VERSION "\n" "Copyright (C) 1999 2000 2001 " - "Jan-Derk Bakker and Erik Mouw\r" + "Jan-Derk Bakker and Erik Mouw\n" "Copyright (C) 2000 " - "Johan Pouwelse\r"); + "Johan Pouwelse\n"); SerialOutputString(PACKAGE " comes with ABSOLUTELY NO WARRANTY; " - "read the GNU GPL for details.\r"); + "read the GNU GPL for details.\n"); SerialOutputString("This is free software, and you are welcome " - "to redistribute it\r"); + "to redistribute it\n"); SerialOutputString("under certain conditions; " - "read the GNU GPL for details.\r\r"); + "read the GNU GPL for details.\n\n"); /* initialise status */ @@ -146,13 +146,13 @@ /* print some information */ SerialOutputString("Running from "); if(RunningFromInternal()) - SerialOutputString("internal flash\r"); + SerialOutputString("internal flash\n"); else - SerialOutputString("external flash\r"); + SerialOutputString("external flash\n"); SerialOutputString(", blockSize = 0x"); SerialOutputHex(blockSize); - SerialOutputByte('\r'); + SerialOutputByte('\n'); #endif /* wait 10 seconds before starting autoboot */ SerialOutputString("Autoboot in progress, press any key to stop "); @@ -171,15 +171,15 @@ BootKernel(commandline); } - SerialOutputString("\rAutoboot aborted\r"); - SerialOutputString("Type \"help\" to get a list of commands\r"); + SerialOutputString("\nAutoboot aborted\n"); + SerialOutputString("Type \"help\" to get a list of commands\n"); /* the command loop. endless, of course */ for(;;) { DisplayPrompt(NULL); - /* wait an hour to get a command */ - numRead = GetCommand(commandline, 128, 3600); + /* wait 10 minutes for a command */ + numRead = GetCommand(commandline, 128, 600); if(numRead > 0) { if(MyStrNCmp(commandline, "boot", 4) == 0) { @@ -206,7 +206,7 @@ } else { SerialOutputString("*** Unknown command: "); SerialOutputString(commandline); - SerialOutputByte('\r'); + SerialOutputByte('\n'); } } } @@ -225,12 +225,12 @@ #warning "FIXME: should set kernel commandline parameters -- Erik" #ifdef BLOB_DEBUG - SerialOutputString("\r*** Ignoring kernel parameters\r"); + SerialOutputString("\n*** Ignoring kernel parameters\n"); #endif /* we assume that the kernel is in place */ /* See linux/include/asm-arm/system.h for architecture numbers */ - SerialOutputString("\rStarting kernel ...\r\r"); + SerialOutputString("\nStarting kernel ...\n\n"); /* turn off I-cache */ asm ("mrc p15, 0, %0, c1, c0, 0": "=r" (i)); @@ -262,7 +262,7 @@ theKernel(0,18); #endif - SerialOutputString("Hey, the kernel returned! This should not happen.\r"); + SerialOutputString("Hey, the kernel returned! This should not happen.\n"); } @@ -295,27 +295,27 @@ } else { SerialOutputString("*** Don't know how to download \""); SerialOutputString(commandline); - SerialOutputString("\"\r"); + SerialOutputString("\"\n"); return; } SerialOutputString("Switching to "); PrintSerialSpeed(status->downloadSpeed); - SerialOutputString(" baud\r"); + SerialOutputString(" baud\n"); - SerialOutputString("You have 60 seconds to switch your terminal emulator to the same speed and\r"); - SerialOutputString("start downloading. After that " PACKAGE " will switch back to 9600 baud.\r"); + SerialOutputString("You have 60 seconds to switch your terminal emulator to the same speed and\n"); + SerialOutputString("start downloading. After that " PACKAGE " will switch back to 9600 baud.\n"); SerialInit(status->downloadSpeed); *numRead = UUDecode((char *)startAddress, bufLen); - SerialOutputString("\r(Please switch your terminal emulator back to 9600 baud)\r"); + SerialOutputString("\n(Please switch your terminal emulator back to 9600 baud)\n"); if(*numRead < 0) { /* something went wrong */ - SerialOutputString("*** Uudecode receive failed\r"); + SerialOutputString("*** Uudecode receive failed\n"); /* reload the correct memory */ Reload(commandline, status); @@ -327,7 +327,7 @@ SerialOutputDec(*numRead); SerialOutputString(" (0x"); SerialOutputHex(*numRead); - SerialOutputString(") bytes.\r"); + SerialOutputString(") bytes.\n"); SerialInit(baud9k6); @@ -348,7 +348,7 @@ numBytes = status->blobSize; if(status->blobType == fromFlash) { - SerialOutputString("*** No blob downloaded\r"); + SerialOutputString("*** No blob downloaded\n"); return; } @@ -359,7 +359,7 @@ numBytes = status->kernelSize; if(status->kernelType == fromFlash) { - SerialOutputString("*** No kernel downloaded\r"); + SerialOutputString("*** No kernel downloaded\n"); return; } @@ -370,7 +370,7 @@ numBytes = status->ramdiskSize; if(status->ramdiskType == fromFlash) { - SerialOutputString("*** No ramdisk downloaded\r"); + SerialOutputString("*** No ramdisk downloaded\n"); return; } @@ -378,14 +378,14 @@ } else { SerialOutputString("*** Don't know how to flash \""); SerialOutputString(commandline); - SerialOutputString("\"\r"); + SerialOutputString("\"\n"); return; } EraseBlocks(block); SerialOutputByte(' '); WriteBlocksFromMem(block, (u32 *)startAddress, numBytes); - SerialOutputString(" done\r"); + SerialOutputString(" done\n"); } @@ -393,20 +393,20 @@ void PrintHelp(void) { - SerialOutputString("Help for " PACKAGE " " VERSION ", the LART bootloader\r"); - SerialOutputString("The following commands are supported:\r"); - SerialOutputString("* boot [kernel options] Boot Linux with optional kernel options\r"); - SerialOutputString("* clock PPCR MDCNFG MDCAS0 MDCAS1 MDCAS2\r"); - SerialOutputString(" Set the SA1100 core clock and DRAM timings\r"); - SerialOutputString(" (WARNING: dangerous command!)\r"); - SerialOutputString("* download {blob|kernel|ramdisk} Download kernel or ramdisk image to RAM\r"); - SerialOutputString("* flash {blob|kernel|ramdisk} Copy kernel or ramdisk from RAM to flash\r"); - SerialOutputString("* help Get this help\r"); - SerialOutputString("* reboot Reboot system\r"); - SerialOutputString("* reload {blob|kernel|ramdisk} Reload kernel or ramdisk from flash to RAM\r"); - SerialOutputString("* reset Reset terminal\r"); - SerialOutputString("* speed Set download speed\r"); - SerialOutputString("* status Display current status\r"); + SerialOutputString("Help for " PACKAGE " " VERSION ", the LART bootloader\n"); + SerialOutputString("The following commands are supported:\n"); + SerialOutputString("* boot [kernel options] Boot Linux with optional kernel options\n"); + SerialOutputString("* clock PPCR MDCNFG MDCAS0 MDCAS1 MDCAS2\n"); + SerialOutputString(" Set the SA1100 core clock and DRAM timings\n"); + SerialOutputString(" (WARNING: dangerous command!)\n"); + SerialOutputString("* download {blob|kernel|ramdisk} Download kernel or ramdisk image to RAM\n"); + SerialOutputString("* flash {blob|kernel|ramdisk} Copy kernel or ramdisk from RAM to flash\n"); + SerialOutputString("* help Get this help\n"); + SerialOutputString("* reboot Reboot system\n"); + SerialOutputString("* reload {blob|kernel|ramdisk} Reload kernel or ramdisk from flash to RAM\n"); + SerialOutputString("* reset Reset terminal\n"); + SerialOutputString("* speed Set download speed\n"); + SerialOutputString("* status Display current status\n"); } @@ -441,14 +441,14 @@ } else { SerialOutputString("*** Invalid download speed value \""); SerialOutputString(commandline); - SerialOutputString("\"\r*** Valid values are:\r"); - SerialOutputString("*** 1200, 9600, 19200, 38400, 57600, 115200,\r"); - SerialOutputString("*** 1k2, 9k6, 19k2, 38k4, 57k6, and 115k2\r"); + SerialOutputString("\"\n*** Valid values are:\n"); + SerialOutputString("*** 1200, 9600, 19200, 38400, 57600, 115200,\n"); + SerialOutputString("*** 1k2, 9k6, 19k2, 38k4, 57k6, and 115k2\n"); } SerialOutputString("Download speed set to "); PrintSerialSpeed(status->downloadSpeed); - SerialOutputString(" baud\r"); + SerialOutputString(" baud\n"); } @@ -456,8 +456,8 @@ void PrintStatus(blobStatus *status) { - SerialOutputString("Bootloader : " PACKAGE "\r"); - SerialOutputString("Version : " VERSION "\r"); + SerialOutputString("Bootloader : " PACKAGE "\n"); + SerialOutputString("Version : " VERSION "\n"); SerialOutputString("Running from : "); if(RunningFromInternal()) @@ -465,38 +465,38 @@ else SerialOutputString("external"); - SerialOutputString(" flash\rBlocksize : 0x"); + SerialOutputString(" flash\nBlocksize : 0x"); SerialOutputHex(status->blockSize); - SerialOutputString("\rDownload speed: "); + SerialOutputString("\nDownload speed: "); PrintSerialSpeed(status->downloadSpeed); - SerialOutputString(" baud\r"); + SerialOutputString(" baud\n"); SerialOutputString("Blob : "); if(status->blobType == fromFlash) { - SerialOutputString("from flash\r"); + SerialOutputString("from flash\n"); } else { SerialOutputString("downloaded, "); SerialOutputDec(status->blobSize); - SerialOutputString(" bytes\r"); + SerialOutputString(" bytes\n"); } SerialOutputString("Kernel : "); if(status->kernelType == fromFlash) { - SerialOutputString("from flash\r"); + SerialOutputString("from flash\n"); } else { SerialOutputString("downloaded, "); SerialOutputDec(status->kernelSize); - SerialOutputString(" bytes\r"); + SerialOutputString(" bytes\n"); } SerialOutputString("Ramdisk : "); if(status->ramdiskType == fromFlash) { - SerialOutputString("from flash\r"); + SerialOutputString("from flash\n"); } else { SerialOutputString("downloaded, "); SerialOutputDec(status->ramdiskSize); - SerialOutputString(" bytes\r"); + SerialOutputString(" bytes\n"); } } @@ -510,7 +510,7 @@ SerialInit(baud9k6); SerialOutputString(" c"); for(i = 0; i < 100; i++) - SerialOutputByte('\r'); + SerialOutputByte('\n'); SerialOutputString("c"); } @@ -548,12 +548,12 @@ } else { SerialOutputString("*** Don't know how to reload \""); SerialOutputString(commandline); - SerialOutputString("\"\r"); + SerialOutputString("\"\n"); return; } MyMemCpy(src, dst, numWords); - SerialOutputString(" done\r"); + SerialOutputString(" done\n"); } @@ -597,6 +597,20 @@ void Reboot(void) { - SerialOutputString("Rebooting...\r\r"); + u32 startTime, currentTime; + + SerialOutputString("Rebooting...\n\n"); + + /* sleep for half a second */ + TimerClearOverflow(); + startTime = TimerGetTime(); + + do { + currentTime = TimerGetTime(); + if(TimerDetectOverflow()) + break; + } while((currentTime - startTime) < TICKS_PER_SECOND/2); + + RCSR = 0; RSRR = 1; } Index: serial.c =================================================================== RCS file: /cvsroot/blob/blob/src/serial.c,v retrieving revision 1.1.1.1.2.1 retrieving revision 1.1.1.1.2.2 diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2 --- serial.c 2001/07/07 21:19:57 1.1.1.1.2.1 +++ serial.c 2001/07/20 18:39:03 1.1.1.1.2.2 @@ -93,10 +93,6 @@ */ void SerialOutputByte(const char c) { - /* If \r, also do \n */ - if(c == '\r') - SerialOutputByte('\n'); - #if defined USE_SERIAL1 /* wait for room in the tx FIFO */ while((Ser1UTSR0 & UTSR0_TFS) == 0) ; @@ -110,6 +106,10 @@ #else #error "Configuration error: No serial port used at all!" #endif + + /* If \n, also do \r */ + if(c == '\n') + SerialOutputByte('\r'); } Index: time.c =================================================================== RCS file: /cvsroot/blob/blob/src/time.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- time.c 2001/06/27 19:47:42 1.1.1.1 +++ time.c 2001/07/20 18:39:03 1.1.1.1.2.1 @@ -44,32 +44,53 @@ +static int numOverflows; + + + + void TimerInit(void) { - u32 old_rcnr = RCNR; + /* clear counter */ + OSCR = 0; - /* Force 32-kHz oscillator on */ - PCFR |= PCFR_FO; + /* we don't want to be interrupted */ + OIER = 0; - /* disable timer interrupts and clear the AL and HZ bits*/ - RTSR = (RTSR_AL | RTSR_HZ); + /* wait until OSCR > 0 */ + while(OSCR == 0) + ; - /* put the counter to 0 */ - /* strange enough, this doesn't seem to work -- Erik */ - /* RCNR = 0x0; */ + /* clear match register 0 */ + OSMR0 = 0; - /* RCNR writes may be delayed by a 32-kHz clock cycle */ - RCNR = 0x0; + /* clear match bit for OSMR0 */ + OSSR = OSSR_M0; - while (RCNR > old_rcnr) - ; + numOverflows = 0; } -/* returns the time in seconds */ +/* returns the time in 1/TICKS_PER_SECOND seconds */ u32 TimerGetTime(void) +{ + return((u32) OSCR); +} + + +int TimerDetectOverflow(void) +{ + return(OSSR & OSSR_M0); +} + + + +void TimerClearOverflow(void) { - return((u32) RCNR); + if(TimerDetectOverflow()) + numOverflows++; + + OSSR = OSSR_M0; } Index: uucodec.c =================================================================== RCS file: /cvsroot/blob/blob/src/uucodec.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.2.1 diff -u -r1.1.1.1 -r1.1.1.1.2.1 --- uucodec.c 2001/06/27 19:47:42 1.1.1.1 +++ uucodec.c 2001/07/20 18:39:03 1.1.1.1.2.1 @@ -48,7 +48,7 @@ #define TEST_MAX_RETRIES do { \ if(retries++ > MAX_RETRIES) { \ - SerialOutputString("\r*** Timeout exceeded. Aborting.\r"); \ + SerialOutputString("\n*** Timeout exceeded. Aborting.\n"); \ return -1; \ } \ } while(0) @@ -58,9 +58,9 @@ /* #define IS_DEC(c) (1) */ #define OUT_OF_RANGE do { \ - SerialOutputByte('\r'); \ + SerialOutputByte('\n'); \ SerialOutputString(buf); \ - SerialOutputString("\r*** Received character out of range. Aborting.\r"); \ + SerialOutputString("\n*** Received character out of range. Aborting.\n"); \ return -1; \ } while(0) @@ -94,7 +94,7 @@ /* for each input line */ for (;;) { if (SerialInputString(p = buf, sizeof(buf), 2) == 0) { - SerialOutputString("\r*** Short file. Aborting\r"); + SerialOutputString("\n*** Short file. Aborting\n"); return -1; } /* Status print to show where we are at right now */ @@ -145,15 +145,17 @@ } } } - SerialOutputByte('\r'); + SerialOutputByte('\n'); if (SerialInputString(p = buf, sizeof(buf), 2) == 0 || (MyStrNCmp(buf, "end", 3))) { - SerialOutputString("*** No \"end\" line. Aborting.\r"); + SerialOutputString("*** No \"end\" line. Aborting.\n"); return(-1); } return(bytesWritten); } /* UUDecode */ +/* we currently don't need to upload files, so disable UUEncode() */ +#if 0 /* ENC is the basic 1 character encoding function to make a char printing */ #define ENC(c) ((c) ? ((c) & 077) + ' ': '`') @@ -163,7 +165,7 @@ register char *p; char buf[80]; - SerialOutputString("begin 644 testme.jdb\r"); + SerialOutputString("begin 644 testme.jdb\n"); while (bufLen > 0) { n = (bufLen > 45) ? 45 : bufLen; MyMemCpyChar(buf, bufBase, n); @@ -185,11 +187,12 @@ ch = ENC(ch); SerialOutputByte(ch); } - SerialOutputByte('\r'); + SerialOutputByte('\n'); } ch = ENC('\0'); SerialOutputByte(ch); - SerialOutputByte('\r'); - SerialOutputString("end\r"); + SerialOutputByte('\n'); + SerialOutputString("end\n"); } /* UUEncode */ +#endif |