30 const TInt KRomLoaderHeaderNone=0; |
30 const TInt KRomLoaderHeaderNone=0; |
31 const TInt KRomLoaderHeaderEPOC=1; |
31 const TInt KRomLoaderHeaderEPOC=1; |
32 const TInt KRomLoaderHeaderCOFF=2; |
32 const TInt KRomLoaderHeaderCOFF=2; |
33 |
33 |
34 static const TInt RombuildMajorVersion=2; |
34 static const TInt RombuildMajorVersion=2; |
35 static const TInt RombuildMinorVersion=14; |
35 static const TInt RombuildMinorVersion=17; |
36 static const TInt RombuildPatchVersion=0; |
36 static const TInt RombuildPatchVersion=3; |
37 static TBool SizeSummary=EFalse; |
37 static TBool SizeSummary=EFalse; |
38 static TPrintType SizeWhere=EAlways; |
38 static TPrintType SizeWhere=EAlways; |
39 static char *CompareRom=NULL; |
39 static string compareROMName = ""; |
40 static TInt MAXIMUM_THREADS = 128; |
40 static TInt MAXIMUM_THREADS = 128; |
41 static TInt DEFAULT_THREADS = 8; |
41 static TInt DEFAULT_THREADS = 8; |
42 |
42 |
43 string filename; // to store oby filename passed to Rombuild. |
43 string filename; // to store oby filename passed to Rombuild. |
44 TBool reallyHelp=EFalse; |
44 TBool reallyHelp=EFalse; |
45 TInt gCPUNum = 0; |
45 TInt gCPUNum = 0; |
46 TInt gThreadNum = 0; |
46 TInt gThreadNum = 0; |
47 char* g_pCharCPUNum = NULL; |
47 char* g_pCharCPUNum = NULL; |
48 TBool gGenDepGraph = EFalse; |
48 TBool gGenDepGraph = EFalse; |
49 char* gDepInfoFile = NULL; |
49 string gDepInfoFile = ""; |
50 |
50 TBool gGenSymbols = EFalse ; |
51 void PrintVersion() |
51 void PrintVersion() { |
52 { |
52 Print(EAlways,"\nROMBUILD - Rom builder"); |
53 Print(EAlways,"\nROMBUILD - Rom builder"); |
|
54 Print(EAlways, " V%d.%d.%d\n", RombuildMajorVersion, RombuildMinorVersion, RombuildPatchVersion); |
53 Print(EAlways, " V%d.%d.%d\n", RombuildMajorVersion, RombuildMinorVersion, RombuildPatchVersion); |
55 Print(EAlways,Copyright); |
54 Print(EAlways,Copyright); |
56 } |
55 } |
57 |
56 |
58 char HelpText[] = |
57 char HelpText[] = |
64 " -no-header suppress the image loader header\n" |
63 " -no-header suppress the image loader header\n" |
65 " -gendep generate the dependence graph for paged part\n" |
64 " -gendep generate the dependence graph for paged part\n" |
66 " -coff-header use a PE-COFF header rather than an EPOC header\n" |
65 " -coff-header use a PE-COFF header rather than an EPOC header\n" |
67 " -d<bitmask> set trace mask (DEB build only)\n" |
66 " -d<bitmask> set trace mask (DEB build only)\n" |
68 " -compress[[=]paged|unpaged] compress the ROM Image\n" |
67 " -compress[[=]paged|unpaged] compress the ROM Image\n" |
69 " without any argumentum compress both sections\n" |
68 " without any argumentum compress both sections\n" |
70 " paged compress paged section only\n" |
69 " paged compress paged section only\n" |
71 " unpaged compress unpaged section only\n" |
70 " unpaged compress unpaged section only\n\n" |
72 " -fastcompress compress files with faster bytepair and tradeoff of compress ratio\n" |
71 " -j<digit> do the main job with <digit> threads\n" |
73 " -j<digit> do the main job with <digit> threads\n" |
72 " -symbols generate symbol file\n" |
74 " -compressionmethod <method> method one of none|inflate|bytepair to set the compression\n" |
73 " -compressionmethod <method> method one of none|inflate|bytepair to set the compression\n" |
75 " -no-sorted-romfs do not add sorted entries arrays (6.1 compatible)\n" |
74 " -no-sorted-romfs do not add sorted entries arrays (6.1 compatible)\n" |
76 " -geninc to generate include file for licensee tools to use\n" // DEF095619 |
75 " -geninc to generate include file for licensee tools to use\n" // DEF095619 |
77 " -loglevel<level> level of information to log (valid levels are 0,1,2,3,4).\n" //Tools like Visual ROM builder need the host/ROM filenames, size & if the file is hidden. |
76 " -loglevel<level> level of information to log (valid levels are 0,1,2,3,4).\n" //Tools like Visual ROM builder need the host/ROM filenames, size & if the file is hidden. |
78 " -wstdpath warn if destination path provided for a file is not a standard path\n" |
77 " -wstdpath warn if destination path provided for a file is not a standard path\n" |
79 " -argfile=<fileName> specify argument-file name containing list of command-line arguments to rombuild\n" |
78 " -argfile=<fileName> specify argument-file name containing list of command-line arguments to rombuild\n" |
80 " -lowmem use memory-mapped file for image build to reduce physical memory consumption\n" |
79 " -lowmem use memory-mapped file for image build to reduce physical memory consumption\n" |
81 " -coreimage=<core image file> to pass the core image as input for extension ROM image generation\n"; |
80 " -coreimage=<core image file> to pass the core image as input for extension ROM image generation\n" |
|
81 " -k to enable keepgoing when duplicate files exist in oby\n"; |
82 |
82 |
83 |
83 |
84 char ReallyHelpText[] = |
84 char ReallyHelpText[] = |
85 "Priorities:\n" |
85 "Priorities:\n" |
86 " low background foreground high windowserver\n" |
86 " low background foreground high windowserver\n" |
97 "Log Level:\n" |
97 "Log Level:\n" |
98 " 0 produce the default logs\n" |
98 " 0 produce the default logs\n" |
99 " 1 produce file detail logs in addition to the default logs\n" |
99 " 1 produce file detail logs in addition to the default logs\n" |
100 " 2 logs e32 header attributes(same as default log) in addition to the level 1 details\n"; |
100 " 2 logs e32 header attributes(same as default log) in addition to the level 1 details\n"; |
101 |
101 |
102 void processParamfile(string aFileName); |
102 void processParamfile(const string& aFileName); |
103 |
|
104 void processCommandLine(int argc, char *argv[], TBool paramFileFlag=EFalse) |
|
105 // |
103 // |
106 // Process the command line arguments, printing a helpful message if none are supplied |
104 // Process the command line arguments, printing a helpful message if none are supplied |
107 // |
105 // |
108 { |
106 void processCommandLine(int argc, char *argv[], TBool paramFileFlag=EFalse) { |
109 |
107 |
110 // If "-argfile" option is passed to Rombuild, then process the parameters |
108 // If "-argfile" option is passed to Rombuild, then process the parameters |
111 // specified in parameter-file first and then the options passed from the |
109 // specified in parameter-file first and then the options passed from the |
112 // command-line. |
110 // command-line. |
113 string ParamFileArg("-ARGFILE="); |
111 string ParamFileArg("-argfile="); |
114 if(paramFileFlag == EFalse) |
112 if(paramFileFlag == EFalse) { |
115 { |
113 for (int count=1; count<argc; count++) { |
116 for (int count=1; count<argc; count++) |
114 string paramFile; |
117 { |
115 if(strnicmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length())==0) { |
118 string paramFile; |
116 paramFile.assign(&argv[count][ParamFileArg.length()]); |
119 strupr(argv[count]); |
|
120 if(strncmp(argv[count],ParamFileArg.c_str(),ParamFileArg.length())==0) |
|
121 { |
|
122 paramFile.assign(&argv[count][ParamFileArg.length()]); |
|
123 processParamfile(paramFile); |
117 processParamfile(paramFile); |
124 } |
118 } |
125 } |
119 } |
126 } |
120 } |
127 |
121 |
128 for (int i=1; i<argc; i++) |
122 for (int i=1; i<argc; i++) { |
129 { |
123 #ifdef __LINUX__ |
130 strupr(argv[i]); |
124 if (argv[i][0] == '-') |
|
125 #else |
131 if ((argv[i][0] == '-') || (argv[i][0] == '/')) |
126 if ((argv[i][0] == '-') || (argv[i][0] == '/')) |
132 { // switch |
127 #endif |
133 if (argv[i][1] == 'V') |
128 { // switch |
|
129 char* arg = argv[i] + 1; |
|
130 if (stricmp(arg, "symbols") == 0) |
|
131 gGenSymbols = ETrue; |
|
132 else if (stricmp(arg, "v") == 0) |
134 H.iVerbose = ETrue; |
133 H.iVerbose = ETrue; |
135 else if (argv[i][1] == 'S') |
134 else if (stricmp(arg, "sl") == 0 || stricmp(arg, "slog") == 0) { |
136 { |
135 SizeSummary = ETrue; |
137 SizeSummary=ETrue; |
136 SizeWhere = ELog; |
138 if (argv[i][2] == 'L') |
137 } |
139 SizeWhere=ELog; |
138 else if (stricmp(arg, "ss") == 0 || stricmp(arg, "sscreen") == 0) { |
140 if (argv[i][2] == 'S') |
139 SizeSummary = ETrue; |
141 SizeWhere=EScreen; |
140 SizeWhere = EScreen; |
142 } |
141 } |
143 else if (strcmp(argv[i], "-FASTCOMPRESS")==0) |
142 else if(stricmp(arg, "sb") == 0 || stricmp(arg, "sboth") == 0) { |
144 gFastCompress = ETrue; |
143 SizeSummary = ETrue; |
145 else if (strcmp(argv[i], "-GENDEP")==0) |
144 SizeWhere = EAlways; |
|
145 } |
|
146 else if (stricmp(arg, "gendep")==0) |
146 gGenDepGraph = ETrue; |
147 gGenDepGraph = ETrue; |
147 else if (strncmp(argv[i], "-J", 2)==0) |
148 else if (stricmp(arg, "k")==0) |
148 { |
149 gKeepGoing = ETrue; |
149 if(argv[i][2]) |
150 else if ('j' == *arg || 'J' == *arg) { |
150 gThreadNum = atoi(&argv[i][2]); |
151 if(arg[1]) |
151 else |
152 gThreadNum = atoi(arg + 1); |
152 { |
153 else { |
153 Print(EWarning, "The option should be like '-j4'.\n"); |
154 Print(EWarning, "The option should be like '-j4'.\n"); |
154 gThreadNum = 0; |
155 gThreadNum = 0; |
155 } |
156 } |
156 if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS) |
157 if(gThreadNum <= 0 || gThreadNum > MAXIMUM_THREADS) { |
157 { |
158 if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS) { |
158 if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS) |
159 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the number of processors %d will be used as the number of concurrent jobs.\n", gCPUNum); |
159 { |
160 gThreadNum = gCPUNum; |
160 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the number of processors %d will be used as the number of concurrent jobs.\n", gCPUNum); |
161 } |
161 gThreadNum = gCPUNum; |
162 else if(g_pCharCPUNum) { |
162 } |
163 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is invalid, so the default value %d will be used.\n", DEFAULT_THREADS); |
163 else if(g_pCharCPUNum) |
164 gThreadNum = DEFAULT_THREADS; |
164 { |
165 } |
165 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is invalid, so the default value %d will be used.\n", DEFAULT_THREADS); |
166 else { |
166 gThreadNum = DEFAULT_THREADS; |
167 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is not available, so the default value %d will be used.\n", DEFAULT_THREADS); |
167 } |
168 gThreadNum = DEFAULT_THREADS; |
168 else |
169 } |
169 { |
170 } |
170 Print(EWarning, "The number of concurrent jobs set by -j should be between 1 and 128. And the NUMBER_OF_PROCESSORS is not available, so the default value %d will be used.\n", DEFAULT_THREADS); |
171 } |
171 gThreadNum = DEFAULT_THREADS; |
172 else if (strnicmp(argv[i],ParamFileArg.c_str(),ParamFileArg.length())==0) { |
172 } |
173 // If "-argfile" option is specified within parameter-file then process it |
173 } |
|
174 } |
|
175 else if (strncmp(argv[i],ParamFileArg.c_str(),ParamFileArg.length())==0) |
|
176 { |
|
177 // If "-argfile" option is specified within parameter-file then process it |
|
178 // otherwise ignore the option. |
174 // otherwise ignore the option. |
179 if (paramFileFlag) |
175 if (paramFileFlag) { |
180 { |
176 string paramFile; |
181 String paramFile; |
|
182 paramFile.assign(&argv[i][ParamFileArg.length()]); |
177 paramFile.assign(&argv[i][ParamFileArg.length()]); |
183 processParamfile(paramFile); |
178 processParamfile(paramFile); |
184 } |
179 } |
185 else |
180 else { |
186 { |
181 continue; |
187 continue; |
|
188 } |
182 } |
189 } |
183 } |
190 else if (argv[i][1] == 'T') |
184 else if ('t' == *arg || 'T' == *arg) |
191 TypeSafeLink=ETrue; |
185 TypeSafeLink=ETrue; |
192 else if (argv[i][1] == '?') |
186 else if (*arg == '?') |
193 reallyHelp=ETrue; |
187 reallyHelp=ETrue; |
194 else if (argv[i][1] == 'R') |
188 else if ('r' == *arg || 'R' == *arg) |
195 CompareRom=strdup(&argv[i][2]); |
189 compareROMName.assign(arg + 1); |
196 else if (strcmp(argv[i], "-NO-HEADER")==0) |
190 else if (stricmp(arg, "no-header")==0) |
197 gHeaderType=KRomLoaderHeaderNone; |
191 gHeaderType=KRomLoaderHeaderNone; |
198 else if (strcmp(argv[i], "-EPOC-HEADER")==0) |
192 else if (stricmp(arg, "epoc-header")==0) |
199 gHeaderType=KRomLoaderHeaderEPOC; |
193 gHeaderType=KRomLoaderHeaderEPOC; |
200 else if (strcmp(argv[i], "-COFF-HEADER")==0) |
194 else if (stricmp(arg, "coff-header")==0) |
201 gHeaderType=KRomLoaderHeaderCOFF; |
195 gHeaderType=KRomLoaderHeaderCOFF; |
202 else if (strcmp(argv[i], "-COMPRESS")==0) |
196 else if ((stricmp(arg, "compress")==0) || (strnicmp(arg, "compress=", 9)==0)) |
203 { |
197 { |
204 if( (i+1) >= argc || argv[i+1][0] == '-') |
198 if((stricmp(arg, "compress")==0) && ((i+1) >= argc || argv[i+1][0] == '-')) |
205 { |
199 { |
206 // No argument, compress both parts with default compression method |
200 // No argument, compress both parts with default compression method |
207 // un-paged part compressed by Deflate |
201 // un-paged part compressed by Deflate |
208 gCompressUnpaged = ETrue; |
202 gCompressUnpaged = ETrue; |
209 gCompressUnpagedMethod = KUidCompressionDeflate; |
203 gCompressUnpagedMethod = KUidCompressionDeflate; |
211 gEnableCompress=ETrue; |
205 gEnableCompress=ETrue; |
212 gCompressionMethod = KUidCompressionBytePair; |
206 gCompressionMethod = KUidCompressionBytePair; |
213 } |
207 } |
214 else |
208 else |
215 { |
209 { |
216 // An argument exists |
210 const int paraMaxLen = 20; |
217 i++; |
211 char* parameter = new char[paraMaxLen]; |
218 strupr(argv[i]); |
212 memset(parameter, 0, paraMaxLen); |
219 if( strcmp(argv[i], "PAGED") == 0) |
213 |
|
214 if(strncmp(arg, "compress=", 9)==0) |
|
215 { |
|
216 int paraLen = strlen(arg + 9); |
|
217 if (paraLen > paraMaxLen - 1) |
|
218 { |
|
219 delete[] parameter; |
|
220 parameter = new char[paraLen + 1]; |
|
221 memset(parameter, 0, paraLen + 1); |
|
222 } |
|
223 |
|
224 memcpy(parameter, arg + 9, paraLen); |
|
225 } |
|
226 else |
|
227 { |
|
228 int paraLen = strlen(argv[++i]); |
|
229 if (paraLen > paraMaxLen - 1) |
|
230 { |
|
231 delete[] parameter; |
|
232 parameter = new char[paraLen + 1]; |
|
233 memset(parameter, 0, paraLen + 1); |
|
234 } |
|
235 memcpy(parameter, argv[i], paraLen); |
|
236 } |
|
237 // An argument exists |
|
238 if( stricmp(parameter, "paged") == 0) |
220 { |
239 { |
221 gEnableCompress=ETrue; |
240 gEnableCompress=ETrue; |
222 gCompressionMethod = KUidCompressionBytePair; |
241 gCompressionMethod = KUidCompressionBytePair; |
223 } |
242 } |
224 else if( strcmp(argv[i], "UNPAGED") == 0) |
243 else if( stricmp(parameter, "unpaged") == 0) |
225 { |
244 { |
226 gCompressUnpaged=ETrue; |
245 gCompressUnpaged=ETrue; |
227 gCompressUnpagedMethod = KUidCompressionDeflate; |
246 gCompressUnpagedMethod = KUidCompressionDeflate; |
228 } |
247 } |
229 else |
248 else { |
230 { |
249 Print (EError, "Unknown -compression argument! Set it to default (no compression)!"); |
231 Print (EError, "Unknown -compression argument! Set it to default (no compression)!"); |
|
232 gEnableCompress=EFalse; |
250 gEnableCompress=EFalse; |
233 gCompressionMethod = 0; |
251 gCompressionMethod = 0; |
234 gCompressUnpaged = EFalse; |
252 gCompressUnpaged = EFalse; |
235 gCompressUnpagedMethod = 0; |
253 gCompressUnpagedMethod = 0; |
236 } |
254 } |
|
255 |
|
256 delete[] parameter; |
237 } |
257 } |
238 } |
258 } |
239 else if( strcmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) |
259 else if( stricmp(arg, "compressionmethod") == 0 ) { |
240 { |
260 // next argument should be a method |
241 // next argument should be a method |
261 if( (i+1) >= argc || argv[i+1][0] == '-') { |
242 if( (i+1) >= argc || argv[i+1][0] == '-') |
262 Print (EError, "Missing compression method! Set it to default (no compression)!"); |
243 { |
|
244 Print (EError, "Missing compression method! Set it to default (no compression)!"); |
|
245 gEnableCompress=EFalse; |
263 gEnableCompress=EFalse; |
246 gCompressionMethod = 0; |
264 gCompressionMethod = 0; |
247 } |
265 } |
248 else |
266 else { |
249 { |
267 i++; |
250 i++; |
268 if( stricmp(argv[i], "inflate") == 0) { |
251 strupr(argv[i]); |
269 gEnableCompress=ETrue; |
252 if( strcmp(argv[i], "INFLATE") == 0) |
|
253 { |
|
254 gEnableCompress=ETrue; |
|
255 gCompressionMethod = KUidCompressionDeflate; |
270 gCompressionMethod = KUidCompressionDeflate; |
256 } |
271 } |
257 else if( strcmp(argv[i], "BYTEPAIR") == 0) |
272 else if( stricmp(argv[i], "bytepair") == 0) { |
258 { |
273 gEnableCompress=ETrue; |
259 gEnableCompress=ETrue; |
|
260 gCompressionMethod = KUidCompressionBytePair; |
274 gCompressionMethod = KUidCompressionBytePair; |
261 } |
275 } |
262 else |
276 else { |
263 { |
277 if( stricmp(argv[i], "none") != 0) { |
264 if( strcmp(argv[i], "NONE") != 0) |
278 Print (EError, "Unknown compression method! Set it to default (no compression)!"); |
265 { |
|
266 Print (EError, "Unknown compression method! Set it to default (no compression)!"); |
|
267 } |
279 } |
268 gEnableCompress=EFalse; |
280 gEnableCompress=EFalse; |
269 gCompressionMethod = 0; |
281 gCompressionMethod = 0; |
270 } |
282 } |
271 } |
283 } |
272 |
284 |
273 } |
285 } |
274 else if (strcmp(argv[i], "-NO-SORTED-ROMFS")==0) |
286 else if (stricmp(arg, "no-sorted-romfs")==0) |
275 gSortedRomFs=EFalse; |
287 gSortedRomFs=EFalse; |
276 else if (strcmp(argv[i], "-GENINC")==0) // DEF095619 |
288 else if (stricmp(arg, "geninc")==0) // DEF095619 |
277 gGenInc=ETrue; |
289 gGenInc=ETrue; |
278 else if (strcmp(argv[i], "-WSTDPATH")==0) // Warn if destination path provided for a file |
290 else if (stricmp(arg, "wstdpath")==0) // Warn if destination path provided for a file |
279 gEnableStdPathWarning=ETrue; // is not a standard path as per platsec |
291 gEnableStdPathWarning=ETrue; // is not a standard path as per platsec |
280 else if( strcmp(argv[i], "-LOGLEVEL") == 0) |
292 else if( stricmp(arg, "loglevel") == 0) { |
281 { |
293 // next argument should a be loglevel |
282 // next argument should a be loglevel |
294 if( (i+1) >= argc || argv[i+1][0] == '-') { |
283 if( (i+1) >= argc || argv[i+1][0] == '-') |
295 Print (EError, "Missing loglevel!"); |
284 { |
|
285 Print (EError, "Missing loglevel!"); |
|
286 gLogLevel = DEFAULT_LOG_LEVEL; |
296 gLogLevel = DEFAULT_LOG_LEVEL; |
287 } |
297 } |
288 else |
298 else { |
289 { |
299 i++; |
290 i++; |
300 if (stricmp(argv[i], "4") == 0) |
291 if (strcmp(argv[i], "4") == 0) |
|
292 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO); |
301 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO); |
293 else if (strcmp(argv[i], "3") == 0) |
302 else if (stricmp(argv[i], "3") == 0) |
294 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO); |
303 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO); |
295 else if (strcmp(argv[i], "2") == 0) |
304 else if (stricmp(argv[i], "2") == 0) |
296 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES); |
305 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES); |
297 else if (strcmp(argv[i], "1") == 0) |
306 else if (stricmp(argv[i], "1") == 0) |
298 gLogLevel = LOG_LEVEL_FILE_DETAILS; |
307 gLogLevel = LOG_LEVEL_FILE_DETAILS; |
299 else if (strcmp(argv[i], "0") == 0) |
308 else if (stricmp(argv[i], "0") == 0) |
300 gLogLevel = DEFAULT_LOG_LEVEL; |
309 gLogLevel = DEFAULT_LOG_LEVEL; |
301 else |
310 else |
302 Print(EError, "Only loglevel 0, 1, 2, 3 or 4 is allowed!"); |
311 Print(EError, "Only loglevel 0, 1, 2, 3 or 4 is allowed!"); |
303 } |
312 } |
304 } |
313 } |
305 else if( strcmp(argv[i], "-LOGLEVEL4") == 0) |
314 else if( stricmp(arg, "loglevel4") == 0) |
306 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO); |
315 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO | LOG_LEVEL_SMP_INFO); |
307 else if( strcmp(argv[i], "-LOGLEVEL3") == 0) |
316 else if( stricmp(arg, "loglevel3") == 0) |
308 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO); |
317 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES | LOG_LEVEL_COMPRESSION_INFO); |
309 else if( strcmp(argv[i], "-LOGLEVEL2") == 0) |
318 else if( stricmp(arg, "loglevel2") == 0) |
310 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES); |
319 gLogLevel = (LOG_LEVEL_FILE_DETAILS | LOG_LEVEL_FILE_ATTRIBUTES); |
311 else if( strcmp(argv[i], "-LOGLEVEL1") == 0) |
320 else if( stricmp(arg, "loglevel1") == 0) |
312 gLogLevel = LOG_LEVEL_FILE_DETAILS; |
321 gLogLevel = LOG_LEVEL_FILE_DETAILS; |
313 else if( strcmp(argv[i], "-LOGLEVEL0") == 0) |
322 else if( stricmp(arg, "loglevel0") == 0) |
314 gLogLevel = DEFAULT_LOG_LEVEL; |
323 gLogLevel = DEFAULT_LOG_LEVEL; |
315 else if (argv[i][1] == 'D') |
324 else if ('d' == *arg || 'D' == *arg) { |
316 { |
325 TraceMask=strtoul(arg+1, 0, 0); |
317 TraceMask=strtoul(argv[i]+2, 0, 0); |
326 } |
318 } |
327 else if (stricmp(arg, "lowmem") == 0) |
319 else if (strcmp(argv[i], "-LOWMEM") == 0) |
|
320 gLowMem = ETrue; |
328 gLowMem = ETrue; |
321 else if (strncmp(argv[i], "-COREIMAGE=",11) ==0) |
329 else if (strnicmp(arg, "coreimage=",10) ==0) { |
322 { |
330 if(argv[i][11]) { |
323 if(argv[i][11]) |
331 gUseCoreImage = ETrue; |
324 { |
332 gImageFilename.assign(arg + 10); |
325 gUseCoreImage = ETrue; |
333 } |
326 gImageFilename = (TText*)strdup(&argv[i][11]); |
334 else { |
327 } |
335 Print (EError, "Core ROM image file is missing\n"); |
328 else |
|
329 { |
|
330 Print (EError, "Core ROM image file is missing\n"); |
|
331 } |
336 } |
332 } |
337 } |
333 else |
338 else |
|
339 #ifdef WIN32 |
334 cout << "Unrecognised option " << argv[i] << "\n"; |
340 cout << "Unrecognised option " << argv[i] << "\n"; |
|
341 #else |
|
342 if(0 == access(argv[i],R_OK)){ |
|
343 filename.assign(argv[i]); |
|
344 } |
|
345 else { |
|
346 cout << "Unrecognised option " << argv[i] << "\n"; |
|
347 } |
|
348 #endif |
335 } |
349 } |
336 else // Must be the obey filename |
350 else // Must be the obey filename |
337 filename=argv[i]; |
351 filename.assign(argv[i]); |
338 } |
352 } |
339 if (paramFileFlag) |
353 if (paramFileFlag) |
340 return; |
354 return; |
341 if (filename.empty()) |
355 if (filename.empty()) { |
342 { |
356 PrintVersion(); |
343 PrintVersion(); |
|
344 cout << HelpText; |
357 cout << HelpText; |
345 if (reallyHelp) |
358 if (reallyHelp) { |
346 { |
359 ObeyFileReader::KeywordHelp(); |
347 ObeyFileReader::KeywordHelp(); |
|
348 cout << ReallyHelpText; |
360 cout << ReallyHelpText; |
349 } |
361 } |
350 else |
362 else |
351 Print(EError, "Obey filename is missing\n"); |
363 Print(EError, "Obey filename is missing\n"); |
352 } |
364 } |
355 /** |
367 /** |
356 Function to process parameter-file. |
368 Function to process parameter-file. |
357 |
369 |
358 @param aFileName parameter-file name. |
370 @param aFileName parameter-file name. |
359 */ |
371 */ |
360 void processParamfile(string aFileName) |
372 void processParamfile(const string& aFileName) { |
361 { |
373 CParameterFileProcessor parameterFile(aFileName); |
362 CParameterFileProcessor parameterFile(aFileName); |
|
363 |
374 |
364 // Invoke fuction "ParameterFileProcessor" to process parameter-file. |
375 // Invoke fuction "ParameterFileProcessor" to process parameter-file. |
365 if(parameterFile.ParameterFileProcessor()) |
376 if(parameterFile.ParameterFileProcessor()) { |
366 { |
377 TUint noOfParameters = parameterFile.GetNoOfArguments(); |
367 TUint noOfParameters = parameterFile.GetNoOfArguments(); |
|
368 char** parameters = parameterFile.GetParameters(); |
378 char** parameters = parameterFile.GetParameters(); |
369 TBool paramFileFlag=ETrue; |
379 TBool paramFileFlag=ETrue; |
370 |
380 |
371 // Invoke function "processCommandLine" to process parameters read from parameter-file. |
381 // Invoke function "processCommandLine" to process parameters read from parameter-file. |
372 processCommandLine(noOfParameters, parameters, paramFileFlag); |
382 processCommandLine(noOfParameters, parameters, paramFileFlag); |
373 } |
383 } |
374 } |
384 } |
375 |
385 |
376 void GenerateIncludeFile(char* aRomName, TInt aUnpagedSize, TInt aPagedSize ) |
386 void GenerateIncludeFile(const char* aRomName, TInt aUnpagedSize, TInt aPagedSize ) { |
377 { |
387 |
|
388 |
|
389 string incFileName(aRomName); |
|
390 int pos = -1 ; |
|
391 for(int i = incFileName.length() - 1 ; i >= 0 ; i--){ |
|
392 char ch = incFileName[i]; |
|
393 if(ch == '/' || ch == '\\') |
|
394 break ; |
|
395 else if(ch == '.'){ |
|
396 pos = i ; |
|
397 break ; |
|
398 } |
|
399 } |
|
400 if(pos > 0) |
|
401 incFileName.erase(pos,incFileName.length() - pos); |
|
402 incFileName += ".inc"; |
378 |
403 |
379 const char * incFileNameExt = ".inc"; |
404 ofstream incFile(incFileName.c_str(),ios_base::trunc + ios_base::out); |
380 |
405 if(!incFile.is_open()) { |
381 TText* incFileName; |
406 Print(EError,"Cannot open include file %s for output\n", incFileName.c_str()); |
382 incFileName=new TText[strlen(aRomName) + strlen(incFileNameExt) + 1]; // Place for include file name and ".inc" extension and '\0' |
407 } |
383 strcpy((char *)incFileName, aRomName); |
408 else { |
384 |
409 const char incContent[] = |
385 char *p = (char*)strrchr((const char *)incFileName, '.'); |
|
386 if( NULL != p) |
|
387 { |
|
388 strncpy(p, incFileNameExt, strlen(incFileNameExt) + 1); // copy extension and the '\0' |
|
389 } |
|
390 else |
|
391 { |
|
392 strcat((char *)incFileName, incFileNameExt); //Doesn't cotains extension, add to it. |
|
393 } |
|
394 |
|
395 Print(EAlways," (%s)\n", (const char *)incFileName); |
|
396 |
|
397 ofstream incFile((const char*)incFileName, ios::out); |
|
398 if(!incFile) |
|
399 { |
|
400 Print(EError,"Cannot open include file %s for output\n",(const char *)incFileName); |
|
401 } |
|
402 else |
|
403 { |
|
404 const char * incContent = |
|
405 "/** Size of the unpaged part of ROM.\n" |
410 "/** Size of the unpaged part of ROM.\n" |
406 "This part is at the start of the ROM image. */\n" |
411 "This part is at the start of the ROM image. */\n" |
407 "#define SYMBIAN_ROM_UNPAGED_SIZE 0x%08x\n" |
412 "#define SYMBIAN_ROM_UNPAGED_SIZE 0x%08x\n" |
408 "\n" |
413 "\n" |
409 "/** Size of the demand paged part of ROM.\n" |
414 "/** Size of the demand paged part of ROM.\n" |
410 "This part is stored immediately after the unpaged part in the ROM image. */\n" |
415 "This part is stored immediately after the unpaged part in the ROM image. */\n" |
411 "#define SYMBIAN_ROM_PAGED_SIZE 0x%08x\n"; |
416 "#define SYMBIAN_ROM_PAGED_SIZE 0x%08x\n"; |
412 |
417 // for place of two hex representated values and '\0' |
413 TText* temp = new TText[strlen(incContent)+ 2 * 8 + 1]; // for place of two hex representated values and '\0' |
418 char* temp = new char[sizeof(incContent)+ 20]; |
414 |
419 size_t len = sprintf(temp,incContent, aUnpagedSize, aPagedSize); |
415 sprintf((char *)temp,incContent, aUnpagedSize, aPagedSize); |
420 incFile.write(temp, len); |
416 incFile.write((const char *)temp, strlen((const char *)temp)); |
|
417 |
|
418 incFile.close(); |
421 incFile.close(); |
419 delete[] temp; |
422 delete[] temp; |
420 } |
423 } |
421 delete[] incFileName; |
424 } |
422 |
425 |
423 } |
426 int main(int argc, char *argv[]) { |
424 |
427 H.SetLogFile("ROMBUILD.LOG"); |
425 int main(int argc, char *argv[]) |
|
426 { |
|
427 H.SetLogFile((unsigned char *)"ROMBUILD.LOG"); |
|
428 TInt r = 0; |
428 TInt r = 0; |
|
429 #ifdef __LINUX__ |
|
430 gCPUNum = sysconf(_SC_NPROCESSORS_CONF); |
|
431 #else |
429 g_pCharCPUNum = getenv("NUMBER_OF_PROCESSORS"); |
432 g_pCharCPUNum = getenv("NUMBER_OF_PROCESSORS"); |
430 if(g_pCharCPUNum != NULL) |
433 if(g_pCharCPUNum != NULL) |
431 gCPUNum = atoi(g_pCharCPUNum); |
434 gCPUNum = atoi(g_pCharCPUNum); |
432 |
435 #endif |
433 // initialise set of all capabilities |
436 // initialise set of all capabilities |
434 ParseCapabilitiesArg(gPlatSecAllCaps, "all"); |
437 ParseCapabilitiesArg(gPlatSecAllCaps, "all"); |
435 |
438 |
436 processCommandLine(argc, argv); |
439 processCommandLine(argc, argv); |
437 if(filename.empty()) |
440 if(filename.empty()) |
438 return KErrGeneral; |
441 return KErrGeneral; |
439 |
442 |
440 if(gThreadNum == 0) |
443 if(gThreadNum == 0) { |
441 { |
444 if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS) { |
442 if(gCPUNum > 0 && gCPUNum <= MAXIMUM_THREADS) |
445 Print(EAlways, "The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum); |
443 { |
|
444 Print(EAlways, "The number of processors (%d) is used as the number of concurrent jobs.\n", gCPUNum); |
|
445 gThreadNum = gCPUNum; |
446 gThreadNum = gCPUNum; |
446 } |
447 } |
447 else if(g_pCharCPUNum) |
448 else if(g_pCharCPUNum) { |
448 { |
449 Print(EWarning, "The NUMBER_OF_PROCESSORS is invalid, and the default value %d will be used.\n", DEFAULT_THREADS); |
449 Print(EWarning, "The NUMBER_OF_PROCESSORS is invalid, and the default value %d will be used.\n", DEFAULT_THREADS); |
|
450 gThreadNum = DEFAULT_THREADS; |
450 gThreadNum = DEFAULT_THREADS; |
451 } |
451 } |
452 else |
452 else { |
453 { |
453 Print(EWarning, "The NUMBER_OF_PROCESSORS is not available, and the default value %d will be used.\n", DEFAULT_THREADS); |
454 Print(EWarning, "The NUMBER_OF_PROCESSORS is not available, and the default value %d will be used.\n", DEFAULT_THREADS); |
|
455 gThreadNum = DEFAULT_THREADS; |
454 gThreadNum = DEFAULT_THREADS; |
456 } |
455 } |
457 } |
456 } |
458 TText *obeyFileName= (TText*)filename.c_str(); |
|
459 |
|
460 PrintVersion(); |
457 PrintVersion(); |
461 |
458 |
462 ObeyFileReader *reader=new ObeyFileReader(obeyFileName); |
459 ObeyFileReader *reader=new ObeyFileReader(filename.c_str()); |
463 if (!reader->Open()) |
460 if (!reader->Open()) { |
464 { |
461 delete reader; |
465 delete reader; |
|
466 return KErrGeneral; |
462 return KErrGeneral; |
467 } |
463 } |
468 |
464 |
469 E32Rom* kernelRom=0; // for image from obey file |
465 E32Rom* kernelRom=0; // for image from obey file |
470 CoreRomImage *core= 0; // for image from core image file |
466 CoreRomImage *core= 0; // for image from core image file |
471 MRomImage* imageInfo=0; |
467 MRomImage* imageInfo=0; |
472 CObeyFile *mainObeyFile=new CObeyFile(*reader); |
468 CObeyFile *mainObeyFile=new CObeyFile(*reader); |
473 |
469 |
474 // need check if obey file has coreimage keyword |
470 // need check if obey file has coreimage keyword |
475 TText *file = mainObeyFile->ProcessCoreImage(); |
471 char* file = mainObeyFile->ProcessCoreImage(); |
476 if (file) |
472 if (file) { |
477 { |
473 // hase coreimage keyword but only use if command line option |
478 // hase coreimage keyword but only use if command line option |
|
479 // for coreimage not already selected |
474 // for coreimage not already selected |
480 if (!gUseCoreImage) |
475 if (!gUseCoreImage) { |
481 { |
476 gUseCoreImage = ETrue; |
482 gUseCoreImage = ETrue; |
|
483 gImageFilename = file; |
477 gImageFilename = file; |
484 } |
478 } |
485 } |
479 delete []file ; |
486 |
480 } |
487 if (!gUseCoreImage) |
481 |
488 { |
482 if (!gUseCoreImage) { |
489 r=mainObeyFile->ProcessKernelRom(); |
483 r=mainObeyFile->ProcessKernelRom(); |
490 if (r==KErrNone) |
484 if (r==KErrNone) { |
491 { |
485 // Build a kernel ROM using the description compiled into the |
492 // Build a kernel ROM using the description compiled into the |
|
493 // CObeyFile object |
486 // CObeyFile object |
494 |
487 |
495 kernelRom = new E32Rom(mainObeyFile); |
488 kernelRom = new E32Rom(mainObeyFile); |
496 if (kernelRom == 0 || kernelRom->iData == 0) |
489 if (kernelRom == 0 || kernelRom->iData == 0) |
497 return KErrNoMemory; |
490 return KErrNoMemory; |
498 |
491 |
499 r=kernelRom->Create(); |
492 r=kernelRom->Create(); |
500 if (r!=KErrNone) |
493 if (r!=KErrNone) { |
501 { |
494 delete kernelRom; |
502 delete kernelRom; |
|
503 delete mainObeyFile; |
495 delete mainObeyFile; |
504 return r; |
496 return r; |
505 } |
497 } |
506 if (SizeSummary) |
498 if (SizeSummary) |
507 kernelRom->DisplaySizes(SizeWhere); |
499 kernelRom->DisplaySizes(SizeWhere); |
508 |
500 |
509 r=kernelRom->WriteImages(gHeaderType); |
501 r=kernelRom->WriteImages(gHeaderType); |
510 if (r!=KErrNone) |
502 if (r!=KErrNone) { |
511 { |
503 delete kernelRom; |
512 delete kernelRom; |
|
513 delete mainObeyFile; |
504 delete mainObeyFile; |
514 return r; |
505 return r; |
515 } |
506 } |
516 |
507 |
517 if (CompareRom) |
508 if (compareROMName.length() > 0 ) { |
518 { |
509 r=kernelRom->Compare(compareROMName.c_str(), gHeaderType); |
519 r=kernelRom->Compare(CompareRom, gHeaderType); |
510 if (r!=KErrNone) { |
520 if (r!=KErrNone) |
511 delete kernelRom; |
521 { |
|
522 delete kernelRom; |
|
523 delete mainObeyFile; |
512 delete mainObeyFile; |
524 return r; |
513 return r; |
525 } |
514 } |
526 } |
515 } |
527 imageInfo = kernelRom; |
516 imageInfo = kernelRom; |
528 mainObeyFile->Release(); |
517 mainObeyFile->Release(); |
529 } |
518 } |
530 else if (r!=KErrNotFound) |
519 else if (r!=KErrNotFound) |
531 return r; |
520 return r; |
532 } |
521 } |
533 else |
522 else { |
534 { |
523 // need to use core image |
535 // need to use core image |
524 core = new CoreRomImage(gImageFilename.c_str()); |
536 core = new CoreRomImage((char*)gImageFilename); |
525 if (!core) { |
537 if (!core) |
526 return KErrNoMemory; |
538 { |
527 } |
539 return KErrNoMemory; |
528 if (!core->ProcessImage(gLowMem)) { |
540 } |
529 delete core; |
541 if (!core->ProcessImage(gLowMem)) |
|
542 { |
|
543 delete core; |
|
544 delete mainObeyFile; |
530 delete mainObeyFile; |
545 return KErrGeneral; |
531 return KErrGeneral; |
546 } |
532 } |
547 |
533 |
548 NumberOfVariants = core->VariantCount(); |
534 NumberOfVariants = core->VariantCount(); |
551 |
537 |
552 core->SetRomAlign(mainObeyFile->iRomAlign); |
538 core->SetRomAlign(mainObeyFile->iRomAlign); |
553 core->SetDataRunAddress(mainObeyFile->iDataRunAddress); |
539 core->SetDataRunAddress(mainObeyFile->iDataRunAddress); |
554 |
540 |
555 gCompressionMethod = core->CompressionType(); |
541 gCompressionMethod = core->CompressionType(); |
556 if(gCompressionMethod) |
542 if(gCompressionMethod) { |
557 { |
543 gEnableCompress = ETrue; |
558 gEnableCompress = ETrue; |
|
559 } |
544 } |
560 |
545 |
561 imageInfo = core; |
546 imageInfo = core; |
562 if(!mainObeyFile->SkipToExtension()) |
547 if(!mainObeyFile->SkipToExtension()) { |
563 { |
548 delete core; |
564 delete core; |
|
565 delete mainObeyFile; |
549 delete mainObeyFile; |
566 return KErrGeneral; |
550 return KErrGeneral; |
567 } |
551 } |
568 } |
552 } |
569 |
553 |
570 if(gGenInc) |
554 if(gGenInc) { |
571 { |
555 Print(EAlways,"Generating include file for ROM image post-processors "); |
572 Print(EAlways,"Generating include file for ROM image post-processors "); |
556 if( gPagedRom ) { |
573 if( gPagedRom ) |
557 Print(EAlways,"Paged ROM"); |
574 { |
|
575 Print(EAlways,"Paged ROM"); |
|
576 GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iPageableRomStart, kernelRom->iHeader->iPageableRomSize); |
558 GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iPageableRomStart, kernelRom->iHeader->iPageableRomSize); |
577 } |
559 } |
578 else |
560 else { |
579 { |
561 Print(EAlways,"Unpaged ROM"); |
580 Print(EAlways,"Unpaged ROM"); |
|
581 int headersize=(kernelRom->iExtensionRomHeader ? sizeof(TExtensionRomHeader) : sizeof(TRomHeader)) - sizeof(TRomLoaderHeader); |
562 int headersize=(kernelRom->iExtensionRomHeader ? sizeof(TExtensionRomHeader) : sizeof(TRomHeader)) - sizeof(TRomLoaderHeader); |
582 GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iCompressedSize + headersize, kernelRom->iHeader->iPageableRomSize); |
563 GenerateIncludeFile((char*)mainObeyFile->iRomFileName, kernelRom->iHeader->iCompressedSize + headersize, kernelRom->iHeader->iPageableRomSize); |
583 } |
564 } |
584 } |
565 } |
585 |
566 |
586 do |
567 do { |
587 { |
568 CObeyFile* extensionObeyFile = 0; |
588 CObeyFile* extensionObeyFile = 0; |
|
589 E32Rom* extensionRom = 0; |
569 E32Rom* extensionRom = 0; |
590 |
570 |
591 extensionObeyFile = new CObeyFile(*reader); |
571 extensionObeyFile = new CObeyFile(*reader); |
592 r = extensionObeyFile->ProcessExtensionRom(imageInfo); |
572 r = extensionObeyFile->ProcessExtensionRom(imageInfo); |
593 if (r==KErrEof) |
573 if (r==KErrEof) { |
594 { |
574 delete imageInfo; |
595 delete imageInfo; |
|
596 delete mainObeyFile; |
575 delete mainObeyFile; |
597 delete extensionObeyFile; |
576 delete extensionObeyFile; |
598 return KErrNone; |
577 return KErrNone; |
599 } |
578 } |
600 if (r!=KErrNone) |
579 if (r!=KErrNone) { |
601 { |
580 delete extensionObeyFile; |
|
581 break; |
|
582 } |
|
583 |
|
584 extensionRom = new E32Rom(extensionObeyFile); |
|
585 r=extensionRom->CreateExtension(imageInfo); |
|
586 if (r!=KErrNone) { |
|
587 delete extensionRom; |
602 delete extensionObeyFile; |
588 delete extensionObeyFile; |
603 break; |
589 break; |
604 } |
590 } |
605 |
|
606 extensionRom = new E32Rom(extensionObeyFile); |
|
607 r=extensionRom->CreateExtension(imageInfo); |
|
608 if (r!=KErrNone) |
|
609 { |
|
610 delete extensionRom; |
|
611 delete extensionObeyFile; |
|
612 break; |
|
613 } |
|
614 if (SizeSummary) |
591 if (SizeSummary) |
615 extensionRom->DisplaySizes(SizeWhere); |
592 extensionRom->DisplaySizes(SizeWhere); |
616 |
593 |
617 r=extensionRom->WriteImages(0); // always a raw image |
594 r=extensionRom->WriteImages(0); // always a raw image |
618 |
595 |