From 709c4d66e0b107ca606941b988bad717c0b45d9b Mon Sep 17 00:00:00 2001 From: Denys Dmytriyenko Date: Tue, 17 Mar 2009 14:32:59 -0400 Subject: rename packages/ to recipes/ per earlier agreement See links below for more details: http://thread.gmane.org/gmane.comp.handhelds.openembedded/21326 http://thread.gmane.org/gmane.comp.handhelds.openembedded/21816 Signed-off-by: Denys Dmytriyenko Acked-by: Mike Westerhof Acked-by: Philip Balister Acked-by: Khem Raj Acked-by: Marcin Juszkiewicz Acked-by: Koen Kooi Acked-by: Frans Meulenbroeks --- recipes/simpad-utilities/serload/main.cpp | 136 ++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 recipes/simpad-utilities/serload/main.cpp (limited to 'recipes/simpad-utilities/serload/main.cpp') diff --git a/recipes/simpad-utilities/serload/main.cpp b/recipes/simpad-utilities/serload/main.cpp new file mode 100644 index 0000000000..b65d71753c --- /dev/null +++ b/recipes/simpad-utilities/serload/main.cpp @@ -0,0 +1,136 @@ +//============================================================================= +// Project: SIMpad +//============================================================================= +// FILE-NAME: main.cpp +// FUNCTION: Serial download of a new image from PC to SIMpad +// +// AUTHOR: Juergen Messerer, Peter Voser +// CREAT.-DATE: 01.04.2001 (dd.mm.yy) +// +// NOTES: - +// +//============================================================================= + +#include +#include +#include +#include "serialdownload.h" +using namespace std; + +const int STRING_LENGTH = 128; + +//============================================================================= +//============================================================================= +void printHelp(void) +{ + cout << "serload V1.0 for Linux " << endl; + cout << "Downloading a new image to the SIMpad " + << "using the serial interface." << endl << endl; + cout << "Invocation: serload [IMAGEFILE] [ttyS-PORT]" << endl; + cout << "IMAGEFILE: the file with the new image prepared for the" + << " SIMpad Bootloader." + << endl; + cout << "ttyS-PORT: number of the ttyS-Port for the download." + << endl; + cout << "Note: ttyS0 = COM1, ttyS1 = COM2, ..." << endl << endl; +} + +//============================================================================= +//============================================================================= +int main(int argc, char *argv[]) +{ + int i; + for(i = 0; i < argc; ++i) + { + if(strcmp(argv[i], "--help") == 0) + { + // The user asks for help. + printHelp(); + exit(0); + } + } + + if(argc != 3 && argc != 2) + { + cerr << endl << "Usage: serload [IMAGEFILE] [ttyS-PORT]" << endl; + cerr << "See also \"serload --help\"!" << endl << endl; + exit(1); + } + + char device[STRING_LENGTH]; + if(argc == 3) + { + strcpy(device, "/dev/ttyS"); + strcat(device, argv[2]); + } + else + { + // If no serial port is given, use ttyS0 as default. + strcpy(device, "/dev/ttyS0"); + } + + SerialDownload serload; + int myError, imagesize; + static char *image; + + int success = serload.openSerialPort(device, myError); + if(success != 0) + { + cerr << "Error: cannot open " << device << ". Aborting." + << endl << endl; + exit(2); + } + + myError = serload.loadFile(argv[1], image, imagesize); + if(myError != 0) + { + cerr << "Error: cannot load file " + << argv[1] << "! Aborting." << endl << endl; + exit(3); + } + + cout << "Please press RESET at the back of the SIMpad!" << endl; + int reply = serload.connectToSimpad(115200, myError); + + if(reply != 0) + { + cerr << "Error: cannot connect to SIMpad! Aborting." + << endl << endl; + exit(4); + } + + // Determine number of blocks to send without remaining bytes! + int progress = 0; + int size = imagesize; + int totalBlocks = size / 512; + int numberOfBlocksToSend = totalBlocks; + int numberOfBlocksSent = 0; + + // Send blocks. + while(numberOfBlocksToSend) + { + serload.sendBlock(image, 512, myError); + image += 512; + --numberOfBlocksToSend; + // Update progress info every 100th block. + if(!(numberOfBlocksSent % 100)) + { + progress = 100 * numberOfBlocksSent / totalBlocks; + } + ++numberOfBlocksSent; + } + + // Determine, if there are remaining bytes. + int numberOfRemainingBytes = size % 512; + if(numberOfRemainingBytes) + { + serload.sendBlock(image, numberOfRemainingBytes, myError); + } + + // The bootloader burns the new image. + serload.waitForEndOfBurning(); + + cout << "Update successfully finished! Swich the SIMpad on." << endl; + + return 0; +} -- cgit v1.2.3