deprecated/w32repro/w32repro.cpp
author andy simpson <andrews@symbian.org>
Fri, 30 Jul 2010 15:14:33 +0100
changeset 622 c26070468a42
parent 600 6d08f4a05d93
permissions -rw-r--r--
Add export for s60ibymacros.pm (re-applies missing part of fix for Bug 2901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
// All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
// This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
// which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
// Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
// Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
// Description:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
// Based on PREPRO.CPP and ROMBUILD.CPP
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
// 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#define WIN32_LEAN_AND_MEAN
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <windows.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <winbase.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include <stdio.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include <stdlib.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include "h_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#include "h_ver.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
// need to pretend we've done e32image.h, to avoid clashes with winnt.h
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
#define __E32IMAGE_H__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
struct E32ImageFile
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
	};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
class CBytePair;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
#include "r_rom.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
#define READ_BUFFER_SIZE 0x1000		// allows for exuberant T_REPRO without delays in it
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
#define WRITE_BUFFER_SIZE 0x1000
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
TRomLoad TheRomHeader;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
TUint ImageDataSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
TUint FileSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
TText PortNumber='1';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
TUint BaudRate=115200;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
TBool Kick=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
TBool UseHex=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
TBool Verbose=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
TBool RawImage=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
TText* BootstrapName=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
const TUint KReproWrapperSize = 0x100;	// REPRO protocol assumes a wrapper size of 256 bytes
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
HANDLE comPort;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
TUint32 BytesWritten;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
TText *processCommandLine(int argc, char *argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
// Process the command line arguments, printing a helpful message if none are supplied
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	char HelpText[] = 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
		"* Syntax: W32REPRO [options] filename[.bin]\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
		"* \n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
		"* Option: -P<n>        port number, defaults to COM1,\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
		"* Option: -K           kick the other end, to force another repro attempt\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
		"* Option: -B<rate>     baud rate, minimum 9600, defaults to 115200\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		"* Option: -RAW         raw image with no header\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		"* Option: -BOOT <file> bootstrap with <file> transmitted at 9600 baud\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
		"* Option: -HEX         use base 16 (for use with ReproC)\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
		"* Option: -V           display raw protocol messages\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
		"* \n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
		"* All messages from W32REPRO begin with '*', every thing else comes from the\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
		"* machine being reprogrammed.\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
	TText *filename=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
	if (argc == 1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	for (int i=1; i<argc; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
		strupr(argv[i]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
		if ((argv[i][0] == '-') || (argv[i][0] == '/'))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
			if (strcmp(argv[i],"-RAW")==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
				RawImage=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
			else if (strcmp(argv[i],"-HEX")==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
				UseHex=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
			else if (strcmp(argv[i],"-BOOT")==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
				if (++i==argc)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
					cout << "**** Missing argument for -BOOT\n*\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
					cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
					return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
				BootstrapName=(TText*)argv[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
			else if (argv[i][1] == 'P')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
				PortNumber=argv[i][2];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
			else if (argv[i][1] == 'K')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
				Kick=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
			else if (argv[i][1] == 'V')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
				Verbose=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
			else if (argv[i][1] == 'B')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
				TInt rate=atoi(argv[i]+2);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
				if (rate>=9600)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
					BaudRate=rate;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
				else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
					cout << "**** Invalid baud rate: " << argv[i] << "\n*\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
					cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
					return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
			else if (argv[i][1] == '?')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
				cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
				return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
			else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
				cout << "**** Unrecognised argument " << argv[i] << "\n*\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
				cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
				return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
		else // Must be the image filename
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
			filename=(TText *)argv[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
	if (filename==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
		cout << "**** Missing image filename\n*\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
		cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
	return filename;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
TInt openComPort()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
// Open the com port and configure it
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	char port[5]="COM1";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	port[3]=PortNumber;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
	comPort=CreateFile(port,GENERIC_READ+GENERIC_WRITE,0,0,OPEN_EXISTING,0,NULL);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
	if (comPort==INVALID_HANDLE_VALUE)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
		return Print(EError,"* Cannot open %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	DCB settings;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
	if (!GetCommState(comPort,&settings))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
		return Print(EError,"* Cannot read settings for %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
	if (!SetupComm(comPort,READ_BUFFER_SIZE,WRITE_BUFFER_SIZE))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
		return Print(EError,"* Cannot set buffer sizes for %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
	settings.fBinary=TRUE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
	settings.fParity=FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
	settings.fAbortOnError=TRUE;	// overrides EV_ERR
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	settings.BaudRate=BaudRate;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	settings.ByteSize=8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
	settings.Parity=NOPARITY;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
	settings.StopBits=ONESTOPBIT;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
	settings.fRtsControl=RTS_CONTROL_ENABLE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
	settings.fDtrControl=DTR_CONTROL_ENABLE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	settings.fOutxCtsFlow=FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
	settings.fOutxDsrFlow=FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
	settings.fDsrSensitivity=FALSE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	settings.fOutX=FALSE;		// no XON/XOFF for transmission
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
	settings.fInX=FALSE;		// no XON/XOFF for reception
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	settings.fNull=FALSE;		// don't discard null bytes
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
	settings.EvtChar='\001';	// REPRO command separator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
	if (!SetCommState(comPort,&settings))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
		return Print(EError,"* Cannot configure %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
	if (!SetCommMask(comPort,EV_RXFLAG+EV_ERR))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
		return Print(EError,"* Cannot set CommMask for %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
	COMMTIMEOUTS timeouts = {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
		//20,0,0,	// allow up to 20 milliseconds between characters, i.e. buffer them properly
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
		MAXDWORD,0,0,	// return immediately
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
		0,0	// no write timeouts
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
		};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
	if (!SetCommTimeouts(comPort,&timeouts))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
		return Print(EError,"* Cannot set timeouts for %s\n",port);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
	if (!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
		Print(EError,"* Failed to raise priority of this thread err=%d\n",GetLastError());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
	if (!SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
		Print(EError,"* Failed to raise priority of this process err=%d\n",GetLastError());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	Print(EScreen,"* Using %s at %d baud\n\n",port,BaudRate);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
BOOL WriteToComPort(char* data, DWORD length, char* comment)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
	if (Verbose)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
		if (comment==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
			Print(EScreen, "* TX=%*s\n", length, data);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
		else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
			Print(EScreen, "* TX <%d bytes of %s>\n", length, comment);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
	return WriteFile(comPort, data, length, &BytesWritten, NULL);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
TInt Bootstrap9600()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
	DCB settings;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
	if (!GetCommState(comPort,&settings))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
		return Print(EError,"* Cannot read COM settings\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
	settings.BaudRate=9600;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
	if (!SetCommState(comPort,&settings))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
		return Print(EError,"* Cannot reconfigure to 9600 baud\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
	FILE* bootstrapFile=fopen((const char*)BootstrapName,"rb");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
	if (bootstrapFile==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
		return Print(EError,"* Cannot open bootstrap file %s for input (errno=%d)\n",BootstrapName,errno);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
	Print(EScreen,"* Sending bootstrap %s at 9600 baud\n",BootstrapName,BaudRate);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
	char bootdata[WRITE_BUFFER_SIZE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
	TUint32 imageBytes=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
	while (!feof(bootstrapFile))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
		imageBytes=fread(bootdata,1,WRITE_BUFFER_SIZE,bootstrapFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
		if (imageBytes==0 && feof(bootstrapFile))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
		if (imageBytes!=WRITE_BUFFER_SIZE && ferror(bootstrapFile))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
			return Print(ESevereError,"* Read only %d bytes of bootstrap err=%d\n",imageBytes,ferror(bootstrapFile));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
		if (!WriteToComPort(bootdata,imageBytes,"bootstrap data"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
			return Print(ESevereError,"* Wrote only %d of %d bytes of bootstrap err=%d\n",
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
				BytesWritten,imageBytes,GetLastError());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
	fclose(bootstrapFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
	settings.BaudRate=BaudRate;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
	if (!SetCommState(comPort,&settings))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
		return Print(EError,"* Cannot reconfigure to %d baud\n",BaudRate);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
	Print(EScreen,"* Bootstrap downloaded\n\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
TInt main(int argc, char *argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
	TInt err=KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
	Print(EScreen,"\n* W32REPRO - Win32 version of PREPRO");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
  	Print(EScreen," V%02d.%02d (Build %03d)\n",MajorVersion,MinorVersion,Build);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
  	Print(EScreen,"* %s",Copyright);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
	TText *imageFileName = processCommandLine(argc, argv);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
	if (imageFileName==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
	FILE* romFile=fopen((const char*)imageFileName,"rb");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
	if (romFile==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
		return Print(EError,"* Cannot open ROM Image file %s for input (errno=%d)\n",imageFileName,errno);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
	if (RawImage)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
		TheRomHeader.wrapSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
		if (fread(&TheRomHeader,sizeof(TheRomHeader),1,romFile)!=1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
			return Print(EError,"* Cannot read ROM Image header\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
		if (TheRomHeader.wrapSize!=KRomWrapperSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
			return Print(EError,"* Incorrect ROM header - wrong wrapper size\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
	if (fseek(romFile,0,SEEK_END)!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
		return Print(EError,"* Cannot seek in ROM Image file\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
	FileSize=ftell(romFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
	ImageDataSize=FileSize-TheRomHeader.wrapSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
	Print(EAlways,"\n* ROM Image %s - 0x%06x bytes\n",imageFileName,ImageDataSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
	err=openComPort();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
	if (err!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
		return err;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
	if (BootstrapName != NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
		err=Bootstrap9600();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
		if (err!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
			return err;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
	char romdata[WRITE_BUFFER_SIZE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
	if (Kick)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
		memset(romdata,'!',64);		// string of non-numeric characters, won't harm old REPRO
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
		WriteToComPort(romdata,64,NULL);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
	//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
	// Wait around for REPRO on the other end to send us commands
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
	//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
	char command[READ_BUFFER_SIZE+1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
	char* cp=command;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
	TInt length=READ_BUFFER_SIZE;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
	TUint expectedOffset=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
	TInt done=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
	while (!done)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
		TUint32 bytesRead=0,imageBytes=0,offset=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
		TUint32 event;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
		if (!WaitCommEvent(comPort,&event,NULL))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
			if (GetLastError()!=ERROR_OPERATION_ABORTED)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
				Print(EAlways,"\n* Unexpected WaitCommEvent failure %d event %x\n",GetLastError(),event);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
			TUint32 commError;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
			if (!ClearCommError(comPort,&commError,NULL))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
				Print(ESevereError,"\n* Failed to clear CommError - give up now!\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
				return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
			if (commError!=CE_OVERRUN)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
				Print(EAlways,"\n* Unexpected comms error %x\n",commError);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
		if (!ReadFile(comPort,cp,length,&bytesRead,NULL))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
			if (GetLastError()!=ERROR_OPERATION_ABORTED)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
				Print(EAlways,"\n* Unexpected ReadFile failure %d bytes %d\n",GetLastError(),bytesRead);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
		if (bytesRead==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
			continue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
		char* next;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
		char* end = cp+bytesRead;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
		*end='\0';	// stick a terminator on the end, just in case
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
		for (cp=(char*)command; (next=(char*)memchr(cp,'\001',end-cp))!=NULL ;cp=next+1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
			*next='\0';	// drop the terminator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
			if (Verbose)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
				Print(EScreen, " * RX=%s\n", cp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
			switch (cp[0])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
			case 'D':	// disconnect after successful REPRO
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
				Print(EScreen,"* Disconnect\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
				done=1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
			case 'M':	// print message
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
				Print(EScreen,"%s",cp+1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
			case 'P':	// panic
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
				Print(ESevereError,"%s",cp+1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
			case 'R':	// request for data from the image at specified address
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
				if (end-next>1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
					break;	// must be the last command in the buffer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
				offset=strtoul(cp+1,NULL,UseHex?16:10)-KReproWrapperSize; // REPRO assumes wrapSize=256	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
				if ((offset&4095)!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
					Print(ESevereError,"* Image offset %x not a multiple of 4k (%s)\n", offset,cp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
				if (offset>expectedOffset)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
					Print(ESevereError,"* Image offset %x should have been %x\n", offset,expectedOffset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
				Print(EScreen,"%x       \r",offset);		// in case we lost the message
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
				expectedOffset=offset+WRITE_BUFFER_SIZE;	// what we expect next time
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
				offset+=TheRomHeader.wrapSize;	// offset into the file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
				if (fseek(romFile,offset,SEEK_SET)!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
					Print(ESevereError,"* Can't seek to file offset %x", offset);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
				memset(romdata,0xff,WRITE_BUFFER_SIZE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
				imageBytes=fread(romdata,1,WRITE_BUFFER_SIZE,romFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
				if (imageBytes!=WRITE_BUFFER_SIZE && offset+imageBytes!=FileSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
					Print(ESevereError,"* Read only %d bytes of image data err=%d\n",imageBytes,ferror(romFile));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
				if (!WriteToComPort(romdata,WRITE_BUFFER_SIZE,"image data"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
					Print(ESevereError,"* Wrote only %d bytes of image data err=%x\n",BytesWritten,GetLastError());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
			case 'S':	// request for the size of the image
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
				if (end-next>1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
					break;	// must be the last command in the buffer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
				if (next-cp==1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
					sprintf((char*)romdata,"%010d\n",ImageDataSize+KReproWrapperSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
					if (!WriteToComPort(romdata,strlen(romdata),NULL) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
							|| BytesWritten!=strlen(romdata))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
						Print(ESevereError,"* Failed to write file size\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
					expectedOffset=0;	// because we are starting again
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
					break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
				// otherwise fall through
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
			default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
				Print(EAlways,"\n* Unrecognised command >%s<\n", cp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
		if (cp<end)	// copy trailing characters back to the start of the buffer
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
			memmove(command,cp,end-cp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
		cp=command+(end-cp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
		length=command+READ_BUFFER_SIZE-cp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
	}