deprecated/rommask/rommask.cpp
author srilekhas <srilekhas@symbian.org>
Wed, 18 Aug 2010 11:18:38 +0100
changeset 627 cb3264f4c6e6
parent 600 6d08f4a05d93
permissions -rw-r--r--
Merge : re-applies missing part of fix for Bug 2901,Add export for s60ibymacros.pm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (c) 1996-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
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <io.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <iomanip>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#else //!__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include <iomanip.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#endif //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#include "h_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include "h_ver.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
// ROMMASK.EXE cl parameters
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
char *gRomImage=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
char *gOutputRom=NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
int	gRomSize=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
char gFormat='P';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
const int KMaxSections=8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
int gNumberOfSections=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
int gSectionSize[KMaxSections];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
int gHeader=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
int gVerbose=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
TInt MaskPlain(TInt aRomSize,ifstream& aPsionImageFile,ofstream& aMaskRomImageFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
// Create a plain mask rom image file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	const char KMaskRomFillCharacter='\377';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	const TInt KBufferSize=1024;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
	char empty[KBufferSize];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
	for (TInt y=0;y<KBufferSize;y++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
		empty[y]=KMaskRomFillCharacter;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	char buffer[KBufferSize];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	TUint checksum32=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	TUint checksum8=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
	for (TInt x=0;x<aRomSize;x+=KBufferSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
		memcpy(buffer,empty,KBufferSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
		aPsionImageFile.read(buffer,KBufferSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
		aMaskRomImageFile.write(buffer,KBufferSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
		TInt z;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
		for (z=0;z<KBufferSize;z+=4)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
			checksum32+=*(TUint32*)&buffer[z];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
		for (z=0;z<KBufferSize;z++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
			checksum8+=(TUint8)buffer[z];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	if (gVerbose)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		cout << dec;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		cout << aRomSize << " byte PLAIN\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
		cout << "32 bit checksum 0x";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
		cout << setw(8);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
		cout << hex;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
		cout << setfill('0');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
		cout << checksum32 << "\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		cout << " 8 bit checksum 0x";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
		cout << setw(8);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		cout << hex;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		cout << setfill('0');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		cout << checksum8 << "\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	return(KErrNone);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
TInt MaskMotorola(TInt /*aRomSize*/,ifstream& /*aPsionImageFile*/,ofstream& /*aMaskRomImageFile*/)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
// Create a motorola s-record mask rom image file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	return(KErrNone);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
TInt MaskRom(TInt aRomSize,ifstream& aPsionImageFile,const char* aMaskRomImageFileName,const char* aMaskRomFormat)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
	ofstream MaskRomImageFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
	TInt r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
	if (!MaskRomImageFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
		cout << "Error:  Cannot create mask rom image file (" << aMaskRomImageFileName << ")\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
		r=KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		if (gVerbose)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
			cout << "\r\nMask ROM image file: ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
			cout << aMaskRomImageFileName << "\r\n"; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
		switch (aMaskRomFormat[0])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
		case 'P':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
			MaskRomImageFile.open(aMaskRomImageFileName, ios::in | ios::binary);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
			r=MaskPlain(aRomSize,aPsionImageFile,MaskRomImageFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
		case 'M':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
			MaskRomImageFile.open(aMaskRomImageFileName, ios::in);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
			r=MaskMotorola(aRomSize,aPsionImageFile,MaskRomImageFile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
			cerr << "Error:  Rom format not recognised\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
			r=KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
		MaskRomImageFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
	return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
TInt getIntegerArg(int argc, char *argv[], int param)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
	int error=KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
	if (param>=argc)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
		error=KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
	if (error==KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
		int val;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
//		if (!isNumber(argv[param]))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
//			return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
#ifdef __TOOLS2__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
istringstream s(argv[param]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
istrstream s(argv[param], strlen(argv[param]));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
		s >> setbase(0);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
#endif //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
		s>>val;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
		if (!s.fail())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
			return val;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
	cerr << "Error:  Integer argument required for ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
	cerr << argv[param-1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
	cerr << "\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	return -1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
char *getStringArg(int argc, char *argv[], int param)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	if (param>=argc)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
		cerr << "Error:  String argument required for ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
		cerr << argv[param-1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
		cerr << "\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
		return NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
	return argv[param];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
char getCharArg(int argc, char *argv[], int param)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
	char *p=getStringArg(argc,argv,param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
	if (p!=NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
		return p[0];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	return '\000';
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
TInt processCommandLine(int argc, char *argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
	if (argc==1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
		return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	int param=1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
	while (param<argc)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
		switch (argv[param][1])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
		case 'r':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
		case 'R':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
			// rom name
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
			param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
			gRomImage=getStringArg(argc, argv, param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
			break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
		case 's':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
		case 'S':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
			if (argv[param][2]=='i')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
				// rom size
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
				param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
				gRomSize=getIntegerArg(argc, argv, param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
				if (gRomSize==-1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
					return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
			else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
				{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
				// section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
				if (gNumberOfSections>=KMaxSections)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
					cerr << "Error:  Too many sections\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
					return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
				param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
				gSectionSize[gNumberOfSections]=getIntegerArg(argc, argv, param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
				if (gSectionSize[gNumberOfSections]==-1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
					return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
				if (gSectionSize[gNumberOfSections]==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
					cerr << "Error:  Section is zero bytes long\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
					return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
				if (gSectionSize[gNumberOfSections]>64)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
					{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
					cerr << "Error: Section too big\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
					return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
					}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
				gNumberOfSections++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
			case 'f':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
			case 'F':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
				param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
				gRomSize=getCharArg(argc, argv, param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
			case 'l':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
			case 'L':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
				cerr << "Error:  Use -verbose instead of -log";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
			case 'v':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
			case 'V':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
				gVerbose=ETrue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
			case 'o':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
			case 'O':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
				param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
				gOutputRom=getStringArg(argc, argv, param);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
			case 'n':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
			case 'N':
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
				// -no-header
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
				gHeader=EFalse;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
				break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
			default:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
				cout << "Error:  Unrecognised switch '"<<argv[param]<<"'\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
				return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
		param++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
	if (gRomImage==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
		cerr << "Error:  No rom image specified\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
		return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
	if (gOutputRom==NULL)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
		cerr << "Error:  No output rom file specified\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
		return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
	if (gRomSize>64)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
		cerr << "Error:  Rom too big\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
	if (gRomSize==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
		cerr << "Error: No rom size specified\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
		return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
	if (gFormat!='P' && gFormat!='M')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
		cerr << "Error:  Invalid mask rom format specified\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
		return KErrArgument;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
	return KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
TInt Align1M(TInt aVal)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
	return (aVal+0xfffff) & 0x7ff00000;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
TInt main(int argc, char *argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
	const TInt KPsionImageFileHeaderSize=0x100;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
	cout << "\r\nROMMASK - Rom masker V" << MajorVersion << "." << MinorVersion << "(Build " << Build << ")\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
	cout << Copyright;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
	char HelpText[] = 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
		"Syntax: ROMMASK -romimage <psion img file> -output <rom img name>\r\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
		"                [-verbose] [-size <total rom size>]\r\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
		"                [-no-header] [-format <format>] [-section <size>]*\r\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
		"Format: MOTOROLA (ascii s-record format)\r\n"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
		"        PLAIN (plain binary format) default\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
	int r=processCommandLine(argc, argv);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
	if (r==KErrArgument)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
		cout << HelpText;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
		return(KErrArgument);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
// Open the psion image file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
	ifstream PsionImageFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
	char*& PsionImageFileName=gRomImage;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
	PsionImageFile.open(PsionImageFileName, ios::in | ios::binary);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
#else //!__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
	PsionImageFile.open(PsionImageFileName, ios::nocreate | ios::binary);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
#endif //__MSVCDOTNET__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
	if (!PsionImageFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
		cerr << "Error:  Cannot open psion image file (" << PsionImageFileName << ")\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
		return(KErrArgument);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
	gRomSize*=1024*1024; // in Mb
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
	// resolve sections to cover whole rom
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
	int size=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
	int i;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
	for (i=0; i<gNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
		gSectionSize[i]*=1024*1024; // in Mb
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
		size+=gSectionSize[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
	if (size<gRomSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
		gSectionSize[gNumberOfSections++]=gRomSize-size;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
	if (size>gRomSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
		cerr << "Error:  Sections too big for rom";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
		return KErrGeneral;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
// Create the mask rom image file
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
	ofstream MaskRomImageFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
	char*& MaskRomImageFileName=gOutputRom;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
 	MaskRomImageFile.open(MaskRomImageFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
	if (!MaskRomImageFile)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
		cerr << "Error:  Cannot create mask rom image file (" << MaskRomImageFileName << ")\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
		PsionImageFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
		return(KErrArgument);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
	if (gHeader)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
		PsionImageFile.ignore(KPsionImageFileHeaderSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
		int count=PsionImageFile.gcount();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
		if (count!=KPsionImageFileHeaderSize)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
			cerr << "Error:  Corrupt Psion image file\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
			return(KErrGeneral);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
	r=KErrNone;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
	for (i=0; i<gNumberOfSections; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
		r=MaskRom(gSectionSize[i],PsionImageFile,MaskRomImageFileName,&gFormat);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
		if (r!=KErrNone)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
			cerr << "Error:  An error occured while processing Rom image\r\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
			return r;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
		// next section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
		char* ptr=MaskRomImageFileName;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
		while (*++ptr!=0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
			;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
		*--ptr=(char)(i+'2');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
	PsionImageFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
	return(r);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
	}