imgtools/romtools/rofsbuild/r_obey.h
changeset 0 044383f39525
child 590 360bd6b35136
child 606 30b30f9da0b7
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * @internalComponent * @released
       
    16 * OBY file reader and processing class Definition.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef __R_OBEY_H__
       
    22 #define __R_OBEY_H__
       
    23 
       
    24 #define __REFERENCE_CAPABILITY_NAMES__
       
    25 
       
    26 #ifdef _MSC_VER
       
    27 #pragma warning(disable:4503)
       
    28 #endif
       
    29 
       
    30 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    31 #include <fstream>
       
    32 #else
       
    33 #include <fstream.h>
       
    34 #endif
       
    35 
       
    36 #include <stdio.h>
       
    37 #include <e32capability.h>
       
    38 
       
    39 #ifdef _L
       
    40 #undef _L
       
    41 #endif
       
    42 
       
    43 #include <vector>
       
    44 #include <map>
       
    45 #include <kernel/kernboot.h>
       
    46 
       
    47 //
       
    48 const TUint32 KNumWords=16;
       
    49 //
       
    50 const TInt KDefaultRomSize=0x400000;
       
    51 const TInt KDefaultRomAlign=0x10;
       
    52 //
       
    53 
       
    54 typedef std::string String;
       
    55 typedef std::vector<String> StringVector;
       
    56 typedef std::map<String, StringVector> KeywordMap;
       
    57 
       
    58 enum EKeyword
       
    59 {
       
    60 	EKeywordNone=0,	// backwards compatibility, but now ignored
       
    61 	EKeywordFile,
       
    62 	EKeywordData,
       
    63 	EKeywordRofsName,
       
    64 	EKeywordExtensionRofs, 
       
    65 	EKeywordCoreRofsName,
       
    66 	EKeywordRomSize,
       
    67 	EKeywordAlias,
       
    68 	EKeywordHide,
       
    69 	EKeywordRename,
       
    70 	EKeywordRofsSize,
       
    71 	EKeywordRofsChecksum,
       
    72 	EKeywordVersion,
       
    73 	EKeywordTime,
       
    74 	EKeywordRomChecksum,
       
    75 	EKeywordTrace,
       
    76 	EKeywordCoreImage,
       
    77 	EKeywordRofsAutoSize,
       
    78 	EKeywordFileCompress,
       
    79 	EKeywordFileUncompress,
       
    80 	EKeywordHideV2,
       
    81 	EKeywordPatchDllData,
       
    82 	EKeywordPagingOverride,
       
    83 	EKeywordCodePagingOverride,
       
    84 	EKeywordDataPagingOverride,
       
    85 	// Added to support data drive images.
       
    86 	EKeywordDataImageName,    
       
    87 	EKeywordDataImageFileSystem, 
       
    88 	EKeywordDataImageSize,
       
    89 	EKeywordDataImageVolume,
       
    90 	EKeywordDataImageSectorSize,
       
    91 	EKeywordDataImageNoOfFats,
       
    92 	EKeywordSmrImageName,
       
    93 	EKeywordSmrFileData,
       
    94 	EKeywordSmrFormatVersion,
       
    95 	EKeywordSmrFlags,
       
    96 	EKeywordSmrUID
       
    97 
       
    98 };
       
    99 
       
   100 enum EFileAttribute {
       
   101 	EAttributeAtt,
       
   102 	EAttributeAttExtra,
       
   103 //	EAttributeCompress,
       
   104 	EAttributeStack,
       
   105 	EAttributeFixed,
       
   106 	EAttributePriority,
       
   107 	EAttributeUid1,
       
   108 	EAttributeUid2,
       
   109 	EAttributeUid3,
       
   110 	EAttributeHeapMin,
       
   111 	EAttributeHeapMax,
       
   112 	EAttributeCapability,
       
   113 	EAttributeUnpaged,
       
   114 	EAttributePaged,
       
   115 	EAttributeUnpagedCode,
       
   116 	EAttributePagedCode,
       
   117 	EAttributeUnpagedData,
       
   118 	EAttributePagedData,
       
   119 	};
       
   120 
       
   121 #include "r_romnode.h"
       
   122 #include "r_rofs.h"
       
   123 
       
   124 class MRofsImage;
       
   125 
       
   126 struct ObeyFileKeyword
       
   127 	{
       
   128 	const char* iKeyword;
       
   129 	size_t iKeywordLength;
       
   130 	TInt iPass;
       
   131 	TInt iNumArgs;		// -ve means >= number
       
   132 	enum EKeyword iKeywordEnum;
       
   133 	const char* iHelpText;
       
   134 	};
       
   135 
       
   136 struct FileAttributeKeyword
       
   137 	{
       
   138 	const char* iKeyword;
       
   139 	size_t iKeywordLength;
       
   140 	TInt iIsFileAttribute;
       
   141 	TInt iNumArgs;
       
   142 	enum EFileAttribute iAttributeEnum;
       
   143 	const char* iHelpText;
       
   144 	};
       
   145 
       
   146 class ObeyFileReader
       
   147 	{
       
   148 public:
       
   149 	ObeyFileReader(TText *aFileName);
       
   150 	~ObeyFileReader();
       
   151 
       
   152 	static void KeywordHelp();
       
   153 
       
   154 	TBool Open();
       
   155 	void Mark();
       
   156 	void MarkNext();
       
   157 	void Rewind();
       
   158 
       
   159 	TInt NextLine(TInt aPass, enum EKeyword& aKeyword);
       
   160 	TInt NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, TText*& aArg);
       
   161 
       
   162 	void CopyWord(TInt aIndex, TText*& aString);				// allocate copy of nth word
       
   163 	TInt Count() { return iNumWords;}				// number of words on current line
       
   164 	char* Word(TInt aIndex) { return (char*)iWord[aIndex]; }	// return nth word as char*
       
   165 	TText* Text(TInt aIndex) { return iWord[aIndex]; }			// return nth word as TText*
       
   166 	char* Suffix() { return (char*)iSuffix; }			// return unmatched suffix of word[0]
       
   167 	TInt CurrentLine() { return iCurrentLine;}				// number of words on current line
       
   168 	TText* GetCurrentObeyStatement() const;						// return current obey statement
       
   169 
       
   170 	void ProcessTime(TInt64& aTime);
       
   171 
       
   172 	static void TimeNow(TInt64& aTime);
       
   173 private:
       
   174 	TInt ReadAndParseLine();
       
   175 	TInt SetLineLengthBuffer();
       
   176 	TInt Parse();
       
   177 	inline TBool IsGap(char ch);
       
   178 
       
   179 	static const ObeyFileKeyword iKeywords[];
       
   180 	static const FileAttributeKeyword iAttributeKeywords[];
       
   181 	static TInt64 iTimeNow;
       
   182 
       
   183 private:
       
   184 	FILE* iObeyFile;
       
   185 	long iMark;
       
   186 	TInt iMarkLine;
       
   187 	long iCurrentMark;
       
   188 	TInt iCurrentLine;
       
   189 	TInt imaxLength;
       
   190 	TText* iFileName;
       
   191 	TInt iNumWords;
       
   192 	TText* iWord[KNumWords];
       
   193 	TText* iSuffix;
       
   194 	TText* iLine;
       
   195 	TText* iCurrentObeyStatement;
       
   196 	};
       
   197 
       
   198 class CPatchDataProcessor;
       
   199 struct ConfigurableFatAttributes;
       
   200 
       
   201 class CObeyFile
       
   202 	{
       
   203 public:
       
   204 	TText *iRomFileName;
       
   205 	TText *iExtensionRofsName;
       
   206 	TText *iKernelRofsName;
       
   207 	TInt iRomSize;
       
   208 	TVersion iVersion;
       
   209 	TUint32 iCheckSum;
       
   210 	TInt iNumberOfFiles;
       
   211 	TInt64 iTime;
       
   212 	TRomNode* iRootDirectory;
       
   213 	TInt iNumberOfDataFiles;
       
   214 	// Added to support Data Drive Images.
       
   215 	TText* iDriveFileName;
       
   216 	TInt64 iDataSize;
       
   217 	TText* iDriveFileFormat;
       
   218 	ConfigurableFatAttributes* iConfigurableFatAttributes;
       
   219 
       
   220 private:
       
   221 	ObeyFileReader& iReader;
       
   222 	TInt iMissingFiles;
       
   223 	TRomNode* iLastExecutable;
       
   224 
       
   225 	TRomBuilderEntry* iFirstFile;
       
   226 	TRomBuilderEntry** iNextFilePtrPtr;
       
   227 	TRomBuilderEntry* iCurrentFile;
       
   228 	KeywordMap iKeyValues;
       
   229 
       
   230 public:
       
   231 	CObeyFile(ObeyFileReader& aReader);
       
   232 	~CObeyFile();
       
   233 	void Release();
       
   234 	TInt ProcessRofs();
       
   235 	TInt ProcessExtensionRofs(MRofsImage* info);
       
   236 	TInt ProcessDataDrive();		//	Process the data drive obey file.
       
   237 	TRomBuilderEntry *FirstFile();
       
   238 	TRomBuilderEntry *NextFile();
       
   239 	TText* ProcessCoreImage();
       
   240 	void SkipToExtension();
       
   241 	TBool AutoSize();
       
   242 	TUint32 AutoPageSize();
       
   243 	TBool Process();
       
   244 	StringVector getValues(const String& aKey);
       
   245 
       
   246 private:
       
   247 	TBool ProcessFile(TInt aAlign, enum EKeyword aKeyword);
       
   248 	TBool ProcessDriveFile(enum EKeyword aKeyword);               
       
   249 	TBool ProcessRenaming(enum EKeyword aKeyword);
       
   250 	TBool ProcessKeyword(enum EKeyword aKeyword);
       
   251 	TBool ProcessDriveKeyword(enum EKeyword aKeyword);
       
   252 	void ProcessExtensionKeyword(enum EKeyword aKeyword);
       
   253 	TInt ParseFileAttributes(TRomNode* aNode, TRomBuilderEntry* aFile, enum EKeyword aKeyword);
       
   254 	TInt ParseSection();
       
   255 	TBool ParsePatchDllData();
       
   256 	TBool GotKeyVariables();
       
   257 	TBool GotKeyDriveVariables();			// To check the data drive mandatory variables. 
       
   258 	TBool GotExtensionVariables(MRofsImage* aRom);
       
   259 	TBool GetNextBitOfFileName(TText **epocEndPtr);
       
   260 	TText *IsValidFilePath(TText *aPath);
       
   261 	void AddFile(TRomBuilderEntry* aFile);
       
   262 
       
   263 	TInt SetStackSize(TRomNode* aNode, TText *aStr);
       
   264 	TInt SetHeapSizeMin(TRomNode* aNode, TText *aStr);
       
   265 	TInt SetHeapSizeMax(TRomNode* aNode, TText *aStr);
       
   266 	TInt SetCapability(TRomNode* aNode, TText *aStr);
       
   267 	TInt SetUid1(TRomNode* aNode, TText *aStr);
       
   268 	TInt SetUid2(TRomNode* aNode, TText *aStr);
       
   269 	TInt SetUid3(TRomNode* aNode, TText *aStr);
       
   270 	TInt SetPriority(TRomNode* aNode, TText *aStr);
       
   271 
       
   272 	TBool iAutoSize;
       
   273 	TUint32 iAutoPageSize;
       
   274 	TBool iPagingOverrideParsed;
       
   275 	TBool iCodePagingOverrideParsed;
       
   276 	TBool iDataPagingOverrideParsed;
       
   277 
       
   278 public:
       
   279 	CPatchDataProcessor* iPatchData;	
       
   280 	void SplitPatchDataStatement(StringVector& aPatchDataTokens);	
       
   281 	};
       
   282 
       
   283 
       
   284 #endif