blob: 06ff16777787e460e28d158d1703908d91a5284b [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2005
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#
36#*****************************************************************************
37#
38# Filename:
39# ---------
40# mmi_mem_cfg.pl
41#
42# Description:
43# ------------
44# XXX.
45#
46# Auther:
47# -------
48# Shinn Lin
49#
50# Note:
51# -----
52# valid dependency :
53# base = 10 + base(cui)
54# fg = 100 + fg(cui)
55# fg = 100 + base(cui) + fg(cui)
56#
57# Log:
58# -----
59# 2010/07/27 Create.
60#
61
62#BEGIN { push @INC, "pcore/" , 'U:\\00MyPerlLib'} # add additional library path
63#package XXX; # declare package library
64use strict;
65use Text::Balanced qw(extract_bracketed);
66
67#******************************************************************************
68# Global Data
69#******************************************************************************
70my $g_memCfgFile = "";
71my $g_outputPathC = ".\\";
72my $g_outputPathH = ".\\";
73my $g_opAppDataH = "mmi_rp_app_data.h";
74my $g_opAppDataDefH = "mmi_rp_app_data_def.h";
75my $g_opAppDataC = "mmi_rp_app_data.c";
76my $g_opAppMemCfgH = "mmi_rp_app_mem_config.h";
77
78my @g_appDataHDefaultInc = ("MMI_features.h", "MMIDataType.h", "vfx_sys_config.h");
79
80my %g_reserveWord = ("max" => 1, "min" => 1);
81
82my $g_tagFg = "fg";
83my $g_tagBase = "base";
84my $g_tagHeap = "heap";
85my $g_tagHeapShrink = "heap_shrink";
86my $g_tagHeapSource = "heap_source";
87my $g_tagExtraBase = "extra_base";
88my $g_tagCui = "cui";
89my $g_tagId = "id";
90my $g_tagStr = "str";
91my $g_tagInc = "inc";
92my $g_tagConc = "concurrent";
93my $g_tagConcWOrder = "concurrent_w_order";
94
95my $g_tagAppFg = "app_fg";
96my $g_tagCuiBase = "cui_base";
97my $g_tagCuiFg = "cui_fg";
98my $g_tagTotal = "total";
99
100# used to distinguish non-ordered concurrent or concurrent w/ order
101my %g_concValue = ($g_tagConc => 1, $g_tagConcWOrder => 2);
102
103# vrt memory
104my $g_tagAppType = "app_type";
105my $g_tagVrtMemFactor = "vrt_mem_factor";
106my $g_vrtMemUnitSize = "VRT_MEM_UNIT_SIZE"; # provided by Jimmy later
107my $g_vrtMemFactorDefault = "0";
108
109my %g_prefix = ("base" => "ASM_BASE_SIZE_",
110 "extra_base" => "ASM_EXTRA_BASE_SIZE_",
111 "fg" => "ASM_FG_SIZE_",
112 "heap" => "ASM_HEAP_SIZE_",
113 "heap_shrink" => "ASM_HEAP_SHRINK_SIZE_",
114 "total" => "ASM_TOTAL_SIZE_",
115 "app_fg" => "ASM_APP_FG_SIZE_",
116 "cui_base" => "ASM_CUI_BASE_SIZE_",
117 "cui_fg" => "ASM_CUI_FG_SIZE_",
118 "totalNum" => "ASM_TOTAL_NUM_",
119 "concBase" => "ASM_CONC_BASE_SIZE_",
120 "concFg" => "ASM_CONC_FG_SIZE_",
121 "concTotal" => "ASM_CONC_TOTAL_SIZE_",
122 "resBase" => "RESOURCE_BASE_",
123 "resEnd" => "RESOURCE_BASE_",
124 );
125my %g_postfix = ("resEnd" => "_END");
126
127my $g_mcuPath = ".\\";
128
129my $g_errorFlag = 0;
130my $g_errorData = "";
131
132#******************************************************************************
133# Export Function
134#******************************************************************************
135
136#******************************************************************************
137# Internal Data
138#******************************************************************************
139my %memInfo = ();
140my %concInfo = ();
141my %undefInfo = ();
142
143#******************************************************************************
144# Program Start
145#******************************************************************************
146
147die getHelp() if (@ARGV == 0);
148{
149 my $pathC;
150 my $pathH;
151 my $mcuPath;
152 ($g_memCfgFile, $mcuPath, $pathC, $pathH) = @ARGV;
153 $g_mcuPath = $mcuPath;
154 $g_outputPathC = $pathC if ($pathC ne "");
155 $g_outputPathH = $pathH if ($pathH ne "");
156
157 # make sure path ends with "\\"
158 $g_mcuPath = $g_mcuPath."\\" if ($g_mcuPath !~ /\\$/);
159 $g_outputPathC = $g_outputPathC."\\" if ($g_outputPathC !~ /\\$/);
160 $g_outputPathH = $g_outputPathH."\\" if ($g_outputPathH !~ /\\$/);
161}
162
163&readCfgFile($g_memCfgFile, \%memInfo, \%concInfo);
164&processDependency(\%memInfo, \%concInfo, \%undefInfo);
165
166&genAppMemCfgH(\%memInfo, \%concInfo, "$g_outputPathH$g_opAppMemCfgH");
167&genAppDataC(\%memInfo, \%concInfo, "$g_outputPathC$g_opAppDataC");
168&genAppDataH(\%memInfo, \%concInfo, \%undefInfo, "$g_outputPathH$g_opAppDataH", "$g_outputPathH$g_opAppDataDefH");
169
1700;
171#******************************************************************************
172# Internal Function
173#******************************************************************************
174
175#******************************************************************************
176# FUNCTION
177# xxx
178# DESCRIPTION
179# xxx
180# PARAMETERS
181# xxx
182# RETURNS
183# xxx
184#******************************************************************************
185
186sub genAppMemCfgH()
187{
188 my ($memInfo_href, $concInfo_href, $file) = @_;
189
190 open(hFile, ">$file") or die "can't open $file\n";
191 print hFile getFileHeaderStr(splitPathName($file));
192
193 my $hMacro = uc "__".splitPathName($file)."__";
194 $hMacro =~ s/\./_/;
195 print hFile "#ifndef $hMacro\n".
196 "#define $hMacro\n\n\n";
197
198 my @sortedID = sort keys(%{$memInfo_href});
199
200 my @tagList = ($g_tagHeap, $g_tagHeapShrink, $g_tagExtraBase, $g_tagBase, $g_tagFg, $g_tagTotal, $g_tagAppFg, $g_tagCuiFg, $g_tagCuiBase);
201 foreach my $tag (@tagList)
202 {
203 print hFile "/* $tag */\n";
204 print hFile "typedef union {\n";
205 foreach my $id (@sortedID)
206 {
207 print hFile " kal_uint8 ".$id."[".$g_prefix{$tag}.$id." + 4];\n" if (defined ${$memInfo_href}{$id}{$tag});
208 }
209 print hFile " kal_uint8 dummy;\n";
210 print hFile "} app_asm_pool_".$tag."_union;\n\n";
211 }
212
213 # << app_asm_pool_sub_union >>
214 print hFile "typedef union {\n";
215
216 # for each ap
217 foreach my $id (@sortedID)
218 {
219 my $value;
220 next if ($id =~ /^(((SRV|CUI|VCUI)_)|(\s*$))/);
221
222 $value = $g_prefix{"total"}.$id;
223 print hFile " kal_uint8 ".$id."[APPLIB_MEM_AP_POOL_SIZE_CONFIG(".$value.")];\n";
224 }
225 # app concurrent
226 foreach my $conc (sort keys (%{$concInfo_href}))
227 {
228 my $concStr = join('_', split(',', $conc));
229 my $concTotal = $g_prefix{"concTotal"}.$concStr;
230 print hFile " kal_uint8 CONC_".$concStr."[APPLIB_MEM_AP_POOL_SIZE_CONFIG(".$concTotal.")];\n";
231 }
232
233 print hFile " kal_uint8 DEFAULT_POOL[APPLIB_MEM_AP_POOL_SIZE_CONFIG(APPLIB_MEM_AP_POOL_DEFAULT_SIZE)];\n".
234 "} app_asm_pool_sub_union;\n\n";
235
236 # << app_asm_pool_global_union >>
237 print hFile "typedef union {\n";
238 my $totalStr = "";
239 foreach my $id (@sortedID)
240 {
241 next if (${$memInfo_href}{$id}{$g_tagHeapSource} ne "global");
242 $totalStr .= "+" if $totalStr ne "";
243 $totalStr .= "APPLIB_MEM_AP_POOL_SIZE_CONFIG(".$g_prefix{"heap_shrink"}.$id.")";
244 print hFile " kal_uint8 ".$id."[APPLIB_MEM_AP_POOL_SIZE_CONFIG(".$g_prefix{"heap_shrink"}.$id.")];\n";
245 }
246 print hFile " kal_uint8 sum_total[".$totalStr."];\n" if($totalStr ne "");
247 print hFile " kal_uint8 dummy;\n".
248 "} app_asm_pool_global_union;\n\n";
249
250 print hFile "#endif /* $hMacro */\n\n";
251 close(hFile);
252}
253
254sub genAppDataC()
255{
256 my ($memInfo_href, $concInfo_href, $file) = @_;
257
258 open(hFile, ">$file") or die "can't open $file\n";
259 print hFile getFileHeaderStr(splitPathName($file));
260 print hFile getAppDataCHead();
261
262 # mmi_app_info
263 print hFile "const mmi_app_info_struct mmi_app_info[] = {\n";
264 foreach my $id (sort keys(%{$memInfo_href}))
265 {
266 my $resBase = $g_prefix{"resBase"}."$id";
267 my $resEnd = $g_prefix{"resEnd"}."$id".$g_postfix{"resEnd"};
268 my $strId = ${$memInfo_href}{$id}{$g_tagStr};
269 my $baseSize = $g_prefix{"base"}.$id;
270 my $fgSize = $g_prefix{"fg"}.$id;
271 my $heapSize = $g_prefix{"heap"}.$id;
272 my $heapShrinkSize = "0";
273 my $vrtMemFactor = ${$memInfo_href}{$id}{$g_tagVrtMemFactor};
274 $heapShrinkSize = $g_prefix{"heap_shrink"}.$id if (defined ${$memInfo_href}{$id}{$g_tagHeapShrink});
275 $baseSize .= "+".$g_prefix{"heap_shrink"}.$id if (defined ${$memInfo_href}{$id}{$g_tagHeapShrink});
276 print hFile "\t{$resBase,\t$resEnd,\t$strId,\t$baseSize,\t$fgSize,\t$heapSize,\t$heapShrinkSize,\t$vrtMemFactor},\n";
277 }
278 print hFile "0" if (scalar(keys(%{$memInfo_href})) == 0); # if no APP declared, give empty struct
279 print hFile "};\n\n";
280
281 print hFile getAppDataCTail();
282 close(hFile);
283}
284
285
286sub printAppDataEnum
287{
288 my ($tagStr, $dataStr, $memInfo_href, $concInfo_href, $undefInfo_href, $hFile, $hashPrinted) = @_;
289
290 #check if already printed
291 if (defined $hashPrinted->{$tagStr})
292 {
293 return;
294 }
295
296 # search dataStr for possible tags, and print them recursively
297 my @tagFound = $dataStr =~ m{ ASM_(HEAP|HEAP_SHRINK|BASE|FG|TOTAL|EXTRA_BASE|APP_FG|CUI_BASE|CUI_FG)_SIZE_(\w+) }gx;
298
299 for(my $i=0; $i<=$#tagFound; $i+=2)
300 {
301 my $loopId = $tagFound[$i+1];
302 my $loopType = lc $tagFound[$i];
303
304 my $loopValue = &removeMacroSign(${$memInfo_href}{$loopId}{$loopType});
305
306 printAppDataEnum($g_prefix{$loopType}.$loopId, $loopValue, $memInfo_href, $concInfo_href, $undefInfo_href, $hFile, $hashPrinted);
307 }
308
309 # after all refered tag are print, print this one, and add into hash
310 $hashPrinted->{$tagStr} = 1;
311
312 print hFile " $tagStr = ($dataStr),\n";
313}
314
315
316sub genAppDataH()
317{
318 my ($memInfo_href, $concInfo_href, $undefInfo_href, $file, $fileDef) = @_;
319
320 open(hFile, ">$file") or die "can't open $file\n";
321 print hFile getFileHeaderStr(splitPathName($file));
322
323 my $hMacro = uc "__".splitPathName($file)."__";
324 $hMacro =~ s/\./_/;
325 print hFile "#ifndef $hMacro\n";
326 print hFile "#define $hMacro\n\n";
327
328 # add inc header
329 my @incArray = @g_appDataHDefaultInc;
330 my %incHash = ();
331 $incHash{$_} = 1 foreach (@incArray);
332
333 # each inc will be included orderly only once
334 foreach my $id (sort keys(%{$memInfo_href}))
335 {
336 if (${$memInfo_href}{$id}{$g_tagInc} ne "")
337 {
338 ${$memInfo_href}{$id}{$g_tagInc} =~ s/[\s]+//g; # remove space
339 my @incArrayTmp = split(',', ${$memInfo_href}{$id}{$g_tagInc});
340 foreach my $inc (@incArrayTmp)
341 {
342 if (!defined $incHash{$inc})
343 {
344 push @incArray, $inc;
345 $incHash{$inc} = 1;
346 }
347 }
348 }
349 }
350 print hFile "#include \"".$_."\"\n" foreach @incArray;
351 print hFile "\n";
352
353 # macro for max(a, b) and min(a, b)
354 print hFile "#undef max\n".
355 "#undef min\n\n".
356 "/* __SKIP_MACRO_EXPANSION__ is used in objcheck.pl to get more readable output */\n".
357 "#ifdef __SKIP_MACRO_EXPANSION__\n".
358 "// undef macro to skip here\n".
359 "#else\n".
360 "#define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))\n".
361 "#define max1(_1) (_1)\n".
362 "#define max3(_1, _2, _3) max(_1, max(_2, _3))\n".
363 "#define max4(_1, _2, _3, _4) max(_1, max3(_2, _3, _4))\n".
364 "#define max5(_1, _2, _3, _4, _5) max(_1, max4(_2, _3, _4, _5))\n".
365 "#define max6(_1, _2, _3, _4, _5, _6) max(_1, max5(_2, _3, _4, _5, _6))\n".
366 "#define max7(_1, _2, _3, _4, _5, _6, _7) max(_1, max6(_2, _3, _4, _5, _6, _7))\n".
367 "#define max8(_1, _2, _3, _4, _5, _6, _7, _8) max(_1, max7(_2, _3, _4, _5, _6, _7, _8))\n".
368 "#define max9(_1, _2, _3, _4, _5, _6, _7, _8, _9) max(_1, max8(_2, _3, _4, _5, _6, _7, _8, _9))\n".
369 "#define min(_a, _b) (((_a) > (_b)) ? (_b) : (_a))\n".
370 "#define ASM_FG_EXTRA(_vrt_mem_factor)\t((U32)(((_vrt_mem_factor)*".$g_vrtMemUnitSize.")+0.5))\n".
371 "#endif /* __SKIP_MACRO_EXPANSION__ */\n\n";
372
373 print hFile "enum {\n";
374
375 my %printedHash = ();
376
377 # undefined features
378 print hFile " /* undefined features */\n";
379 foreach my $id (sort keys(%{$undefInfo_href}))
380 {
381 my @tagList = ($g_tagBase, $g_tagFg, "total");
382 foreach my $tag (@tagList)
383 {
384 print hFile " ".$g_prefix{$tag}."$id = (0),\n";
385 $printedHash{$g_prefix{$tag}.$id} = 1;
386 }
387 print hFile "\n";
388 }
389
390 # each app
391 foreach my $id (sort keys(%{$memInfo_href}))
392 {
393 print hFile " /* $id */\n";
394
395 # << heap/extra_base/base/fg/total memory size >>
396 my @tagList = ($g_tagHeap, $g_tagHeapShrink, $g_tagExtraBase, $g_tagBase, $g_tagAppFg, $g_tagCuiFg, $g_tagCuiBase, $g_tagTotal, $g_tagFg);
397 foreach my $tag (@tagList)
398 {
399 if (defined ${$memInfo_href}{$id}{$tag})
400 {
401 my $dataStr = &removeMacroSign(${$memInfo_href}{$id}{$tag});
402 printAppDataEnum($g_prefix{$tag}.$id, $dataStr, $memInfo_href, $concInfo_href, $undefInfo_href, \*hFile, \%printedHash);
403 }
404 }
405 print hFile "\n";
406 }
407
408 # total number of APP declared
409 print hFile " /* total number of APP declared */\n".
410 " ".$g_prefix{"totalNum"}."APP = (".scalar(keys(%{$memInfo_href}))."),\n\n";
411
412 # concurrent info
413 print hFile " /* concurrent info */\n";
414 foreach my $conc (sort keys (%{$concInfo_href}))
415 {
416 my $concNameBase = $g_prefix{"concBase"}.join('_', split(',', $conc));
417 my $concNameFg = $g_prefix{"concFg"}.join('_', split(',', $conc));
418 my $concNameTotal = $g_prefix{"concTotal"}.join('_', split(',', $conc));
419 my $concType = ${$concInfo_href}{$conc};
420
421 $conc = &removeMacroSign($conc);
422 if ($concType eq $g_concValue{$g_tagConc})
423 {
424 # concurrent w/o order
425 my $valueBase;
426 my $valueFg;
427 $valueBase = join(' + ', map {$g_prefix{"base"}."$_"} split(',', $conc));
428 my @tmp = map {$g_prefix{"fg"}."$_"} split(',', $conc);
429 $valueFg = &xferToPair("max", \@tmp);
430
431 print hFile " ".$concNameBase." = (".$valueBase."),\n";
432 print hFile " ".$concNameFg." = (".$valueFg."),\n";
433 print hFile " ".$concNameTotal." = (".$valueBase." + ".$valueFg."),\n\n";
434 }
435 # concurrent w/ order
436 else
437 {
438 my $valueWOrder;
439 my @valueArray = ();
440 my @concArray = split(',', $conc);
441 my $baseStr = $g_prefix{"base"}.$concArray[0];
442 push @valueArray, $baseStr." + ".$g_prefix{"fg"}.$concArray[0];
443 for (my $i=1; $i<scalar(@concArray); $i++)
444 {
445 $baseStr .= " + ".$g_prefix{"base"}.$concArray[$i];
446 push @valueArray, $baseStr." + ".$g_prefix{"fg"}.$concArray[$i];
447 }
448 $valueWOrder = &xferToPair("max", \@valueArray);
449 print hFile " ".$concNameTotal." = (".$valueWOrder."),\n\n";
450 }
451 }
452 print hFile " ASM_SIZE_ENUM_MAX\n";
453 print hFile "};\n";
454 print hFile "\n";
455 print hFile "#include \"".splitPathName($fileDef)."\"\n";
456 print hFile "#endif /* $hMacro */\n\n";
457 close(hFile);
458
459 open(hFile, ">$fileDef") or die "can't open $fileDef\n";
460 print hFile getFileHeaderStr(splitPathName($fileDef));
461
462 $hMacro = uc "__".splitPathName($fileDef)."__";
463 $hMacro =~ s/\./_/;
464 print hFile "#ifndef $hMacro\n";
465 print hFile "#define $hMacro\n\n";
466
467 print hFile getAppDataHTail();
468
469 print hFile "#endif /* $hMacro */\n\n";
470 close(hFile);
471}
472
473
474sub xferToPair()
475{
476 my ($prefix, $in_aref) = @_;
477 my $outStr = "";
478
479 if ((scalar @{$in_aref}) <= 1)
480 {
481 $outStr = join('', @{$in_aref});
482 }
483 else
484 {
485 my @tmp = @{$in_aref};
486 $outStr = ", ".pop(@tmp).")";
487 $outStr = $prefix."(".pop(@tmp).$outStr;
488 while (scalar @tmp)
489 {
490 $outStr = $prefix."(".pop(@tmp).", $outStr)";
491 }
492 }
493 #print "[xferToPair] $outStr\n";
494 return $outStr;
495}
496
497sub removeMacroSign()
498{
499 my ($str) = @_;
500
501 $str =~ s/\$\((.+?)\)/$1/g;
502
503 return $str;
504}
505
506
507sub readCfgFile()
508{
509 my ($file, $memInfo_href, $concInfo_href) = @_;
510
511 open(hFile, "<$file") or die "can't open $file\n";
512 foreach my $line (<hFile>)
513 {
514 my $id = "";
515 while ($line =~ /\[([\w]+)\]([^\[]+)/g)
516 {
517 my $attr = lc $1;
518 my $val = &trim($2);
519 #print "[attr] $attr\t[val] $val\n";
520
521 if ($memInfo_href)
522 {
523 if ($attr eq $g_tagId)
524 {
525 $id = $val;
526 }
527 elsif (($attr eq $g_tagConc) || ( $attr eq $g_tagConcWOrder))
528 {
529 my $conc = $val;
530 my @concArray = ();
531 $conc =~ s/[\s]+//g; # remove space first to prevent from wrong sort result
532
533 # sort in order to filter same concurrent situation
534 if ($attr eq $g_tagConc)
535 {
536 @concArray = sort split(',', $conc);
537 $conc = join(',', @concArray);
538 }
539 if ($concInfo_href)
540 {
541 ${$concInfo_href}{$conc} = $g_concValue{$attr};
542 }
543 }
544 else
545 {
546 # id is always 1st
547 ${$memInfo_href}{$id}{$attr} = $val if ($id ne "");
548 }
549 }
550 }
551
552 # assign default value
553 if ($id ne "")
554 {
555 # app type => "pluto"
556 if (!defined ${$memInfo_href}{$id}{$g_tagAppType})
557 {
558 ${$memInfo_href}{$id}{$g_tagAppType} = "pluto";
559 ${$memInfo_href}{$id}{$g_tagVrtMemFactor} = "0";
560 }
561 else
562 # vrt mem factor => "$g_vrtMemFactorDefault"
563 {
564 ${$memInfo_href}{$id}{$g_tagVrtMemFactor} = "$g_vrtMemFactorDefault" if (!defined ${$memInfo_href}{$id}{$g_tagVrtMemFactor});
565 }
566
567 # heap source/shrink value check
568 if (!defined ${$memInfo_href}{$id}{$g_tagHeapSource})
569 {
570 ${$memInfo_href}{$id}{$g_tagHeapSource} = "app";
571 }
572
573 if (${$memInfo_href}{$id}{$g_tagHeapSource} eq "global")
574 {
575 if (!defined ${$memInfo_href}{$id}{$g_tagHeapShrink})
576 {
577 $g_errorFlag = 1;
578 ${$memInfo_href}{$id}{$g_tagHeapSource} = "app";
579 }
580 }
581 else
582 {
583 if (defined ${$memInfo_href}{$id}{$g_tagHeapShrink})
584 {
585 $g_errorFlag = 1;
586 delete(${$memInfo_href}{$id}{$g_tagHeapShrink});
587 }
588 }
589 }
590 }
591 close(hFile);
592}
593
594
595sub processDependency()
596{
597 my ($memInfo_href, $concInfo_href, $undefInfo_href) = @_;
598
599 # get undefInfo for concInfo
600 foreach my $conc (sort keys(%{$concInfo_href}))
601 {
602 my $tmp = $conc;
603 $tmp =~ s/\$\(.+\)//g; # skip all $(...)
604 #while ($tmp =~ /(^?|\W)([a-z]\w*)($?|\W)/ig)
605 for my $symbol (split(/,/, $tmp))
606 {
607 #my $symbol = $2;
608 if (!defined $g_reserveWord{$symbol}) # skip reserve word
609 {
610 # add to undefInfo
611 ${$undefInfo_href}{$symbol} = 1 if (!defined ${$memInfo_href}{$symbol});
612 }
613 }
614 }
615
616 foreach my $id (sort keys(%{$memInfo_href}))
617 {
618 my $heapStr = "";
619 my $heapShrinkStr = "";
620 my $extraStr = "";
621 my $appFgStr = "";
622 my $cuiBaseStr = "";
623 my $cuiTotalStr = "";
624 my $cuiFgStr = "";
625 my @datas;
626
627 my $baseStr = "";
628 my $fgStr = "";
629 my $totalStr = "";
630
631 # collect all necessary information
632 $heapStr = $g_prefix{$g_tagHeap}.$id if (defined ${$memInfo_href}{$id}{$g_tagHeap});
633 $heapShrinkStr = $g_prefix{$g_tagHeapShrink}.$id if (defined ${$memInfo_href}{$id}{$g_tagHeapShrink});
634 $extraStr = $g_prefix{$g_tagExtraBase}.$id if (defined ${$memInfo_href}{$id}{$g_tagExtraBase});
635
636 $appFgStr = ${$memInfo_href}{$id}{$g_tagFg} if (defined ${$memInfo_href}{$id}{$g_tagFg});
637 if (${$memInfo_href}{$id}{$g_tagVrtMemFactor} ne "0")
638 {
639 $appFgStr .= " + " if ($appFgStr ne "");
640 $appFgStr .= "ASM_FG_EXTRA(".${$memInfo_href}{$id}{$g_tagVrtMemFactor}.")";
641 }
642
643 if (defined ${$memInfo_href}{$id}{$g_tagCui})
644 {
645 ($cuiBaseStr, $cuiFgStr, $cuiTotalStr) = &getTypeValue($memInfo_href, $undefInfo_href, ${$memInfo_href}{$id}{$g_tagCui}, "all");
646 if ($cuiTotalStr eq "")
647 {
648 $cuiTotalStr = "$g_prefix{$g_tagCuiBase}$id + $g_prefix{$g_tagCuiFg}$id";
649 }
650 elsif ($cuiFgStr eq "")
651 {
652 $cuiFgStr = "max($cuiTotalStr, $g_prefix{$g_tagCuiBase}$id)-$g_prefix{$g_tagCuiBase}$id";
653 }
654 }
655
656 # ready to go
657
658 # << base memory size >>
659 if (!defined ${$memInfo_href}{$id}{$g_tagBase})
660 {
661 # << base memory size >> = heap + extra_base + base(cui)
662 @datas = ();
663 # if source != "global" add to base
664 if ($heapStr ne "")
665 {
666 if (${$memInfo_href}{$id}{$g_tagHeapSource} eq "global")
667 {
668 push(@datas, "(".$heapStr."-".$heapShrinkStr.")");
669 }
670 else
671 {
672 push(@datas, $heapStr);
673 }
674 }
675 push(@datas, $extraStr) if ($extraStr ne "");
676 push(@datas, $g_prefix{$g_tagCuiBase}.$id) if ($cuiBaseStr ne "");
677 $baseStr = join(" + ", @datas);
678 }
679 else
680 {
681 # << base memory size >> = base
682 $baseStr = ${$memInfo_href}{$id}{$g_tagBase};
683 }
684
685 # << fg memory size >> = max(fg-base(cui), fg(cui))
686 @datas = ();
687 if ($appFgStr ne "" && $cuiFgStr ne "")
688 {
689 push(@datas, "max(max($g_prefix{$g_tagAppFg}$id, $g_prefix{$g_tagCuiBase}$id) - $g_prefix{$g_tagCuiBase}$id, $g_prefix{$g_tagCuiFg}$id)");
690 }
691 elsif ($appFgStr ne "")
692 {
693 push(@datas, $g_prefix{$g_tagAppFg}.$id);
694 }
695 elsif ($cuiFgStr ne "")
696 {
697 push(@datas, $g_prefix{$g_tagCuiFg}.$id);
698 }
699 $fgStr = join(" + ", @datas);
700
701 # << total memory size >>= base + fg
702 $totalStr = $g_prefix{$g_tagBase}.$id." + ".$g_prefix{$g_tagFg}.$id;
703
704 #print "[$id]\nH $heapStr\nE $extraStr\nAF $appFgStr\nCB $cuiBaseStr\nCT $cuiTotalStr\nCF $cuiFgStr\n";
705 #print "B $baseStr\n";
706 #print "F $fgStr\n";
707 #print "T $totalStr\n";
708
709 $extraStr = ${$memInfo_href}{$id}{$g_tagExtraBase} if (defined ${$memInfo_href}{$id}{$g_tagExtraBase});
710
711 @datas = ($baseStr, $fgStr, $totalStr, $extraStr, $appFgStr, $cuiBaseStr, $cuiFgStr);
712 for(my $i=0; $i<=$#datas; $i++)
713 {
714 my $tempStr = $datas[$i];
715
716 # check for correctness of dependency ID
717 while ($tempStr =~ /(base|fg|total)\(([\w]+)\)/g)
718 {
719 my $depId = $2;
720 if (!defined ${$memInfo_href}{$depId})
721 {
722 # dependency ID not exists
723 ${$undefInfo_href}{$depId} = 1;
724 }
725 }
726 # replace dependency of base mem.
727 $tempStr =~ s/base\(([\w]+)\)/$g_prefix{"base"}$1/g;
728 $tempStr =~ s/fg\(([\w]+)\)/$g_prefix{"fg"}$1/g;
729 $tempStr =~ s/total\(([\w]+)\)/$g_prefix{"total"}$1/g;
730 $tempStr = "0" if ($tempStr eq "");
731
732 $datas[$i] = $tempStr;
733 }
734
735 ${$memInfo_href}{$id}{$g_tagBase} = $datas[0];
736 ${$memInfo_href}{$id}{$g_tagFg} = $datas[1];
737 ${$memInfo_href}{$id}{$g_tagTotal} = $datas[2];
738
739 ${$memInfo_href}{$id}{$g_tagHeap} = "0" if (!defined ${$memInfo_href}{$id}{$g_tagHeap});
740 ${$memInfo_href}{$id}{$g_tagExtraBase} = $datas[3] if (defined ${$memInfo_href}{$id}{$g_tagExtraBase});
741 ${$memInfo_href}{$id}{$g_tagAppFg} = $datas[4] if ($appFgStr ne "");
742 ${$memInfo_href}{$id}{$g_tagCuiBase} = $datas[5] if ($cuiBaseStr ne "");
743 ${$memInfo_href}{$id}{$g_tagCuiFg} = $datas[6] if ($cuiFgStr ne "");
744 }
745}
746
747sub splitStr()
748{
749 my ($string, $d) = @_;
750 my @params = ();
751 my $prevStr;
752
753 while ($string) {
754 $prevStr = $string;
755
756 if ($string =~ /^([^(]*?)\s*$d/) {
757 push @params, $1;
758 $string =~ s/^\Q$1\E\s*$d?\s*//;
759 } else {
760 my ($ext, $pre);
761 ($ext, $string, $pre) = extract_bracketed($string,'()','[^()]*');
762
763 #print "ext=$ext, s=$string, pre=$pre\n";
764
765 if ($ext eq "") {
766 push @params, $string;
767 $string = ""
768 } else {
769 push @params, "$pre$ext";
770 $string =~ s/^\s*$d\s*//;
771 }
772 }
773 }
774
775 return @params;
776}
777
778sub getTypeValue_r()
779{
780 my ($string, $type, $memInfo_href) = @_;
781
782 my $f;
783 my $delim;
784 my $content;
785 my $strlen = length($string);
786
787 my $retStr = "";
788
789 if ($string =~ /^([A-Z0-9\_]+$)/) {
790 if ($type eq "all") {
791 if (!defined ${$memInfo_href}{$string}) {
792 return ("0", "0", "0");
793 }
794 return ("$g_prefix{base}$string", "$g_prefix{fg}$string", "$g_prefix{total}$string");
795 } else {
796 if (!defined ${$memInfo_href}{$string}) {
797 return "0";
798 }
799 return "$g_prefix{$type}$string";
800 }
801 }
802
803 if ($string =~ /^\s*max\s*\(\s*(.+?)\s*\)\s*$/) {
804 $f = "or";
805 $delim = ",";
806 $content = $1;
807 } elsif ($string =~ /^\s*\(\s*(.+?)\s*\)\s*$/) {
808 $f = "and";
809 $delim = "\\+";
810 $content = $1;
811 } else {
812 $f = "and";
813 $delim = "\\+";
814 $content = $string;
815 }
816
817 my @list = &splitStr($content, $delim);
818 my $listLen = $#list+1;
819 my $maxStr;
820 if ($listLen==2) {
821 $maxStr = "max";
822 } else {
823 $maxStr = "max$listLen";
824 }
825
826 # for debug
827 if (0) {
828 print "\ng:$string,t=$type\n";
829 print "f=$f,d=$delim,c=$content\n";
830 my $sss;
831 for $sss (@list) {
832 print "d: $sss\n";
833 }
834 print "\n";
835 }
836
837 if ($f eq "or") {
838
839 if ($type eq "base") {
840 return "$maxStr(".join(",", map { getTypeValue_r($_, "base", $memInfo_href) } @list).")";
841 } elsif ($type eq "fg") {
842 my $strTotal = "$maxStr(".join(",", map { getTypeValue_r($_, "total", $memInfo_href) } @list).")";
843 my $strBase = "$maxStr(".join(",", map { getTypeValue_r($_, "base", $memInfo_href) } @list).")";
844 return "max(".$strBase.",".$strTotal.")-".$strBase;
845 } elsif ($type eq "total") {
846 return "$maxStr(".join(",", map { getTypeValue_r($_, "total", $memInfo_href) } @list).")";
847 } elsif ($type eq "all") {
848 my $strTotal = "$maxStr(".join(",", map { getTypeValue_r($_, "total", $memInfo_href) } @list).")";
849 my $strBase = "$maxStr(".join(",", map { getTypeValue_r($_, "base", $memInfo_href) } @list).")";
850 return ($strBase, "", $strTotal);
851 }
852
853 } elsif ($f eq "and") {
854
855 if ($type eq "base") {
856 return join("+", map { getTypeValue_r($_, "base", $memInfo_href) } @list);
857 } elsif ($type eq "fg") {
858 return "$maxStr(".join(",", map { getTypeValue_r($_, "fg", $memInfo_href) } @list).")";
859 } elsif ($type eq "total") {
860 my $strBase = join("+", map { getTypeValue_r($_, "base", $memInfo_href) } @list);
861 my $strFg = "$maxStr(".join(",", map { getTypeValue_r($_, "fg", $memInfo_href) } @list).")";
862 return $strBase."+".$strFg;
863 } elsif ($type eq "all") {
864 my $strBase = join("+", map { getTypeValue_r($_, "base", $memInfo_href) } @list);
865 my $strFg = "$maxStr(".join(",", map { getTypeValue_r($_, "fg", $memInfo_href) } @list).")";
866 return ($strBase, $strFg, "");
867 }
868 }
869
870 return "";
871}
872
873sub getTypeValue()
874{
875 my ($memInfo_href, $undefInfo_href, $str, $type) = @_;
876 my $outStr = $str;
877
878 #print "[$type] $str\n";
879 $str =~ s/\$\(.+\)//g; # skip all $(...)
880 # get all valid IDs
881 while ($str =~ /(^||\W)([a-z]\w*)($||\W)/ig)
882 {
883 my $id = "$2";
884 #print "[ID] $id\n";
885 if (!defined $g_reserveWord{$id})
886 {
887 #print "[ID] $id\n";
888
889 # log undefined ID
890 if (!defined ${$memInfo_href}{$id})
891 {
892 #print "[undef ID] $id\n";
893 ${$undefInfo_href}{$id} = 1;
894 }
895 }
896 }
897
898 return &getTypeValue_r($outStr, "all", $memInfo_href);
899}
900
901sub getAppDataCHead()
902{
903 my $str = << "__STR__";
904#include "MMIDataType.h"
905#include "mmi_rp_app_data.h"
906#include "mmi_rp_all_defs.h"
907
908
909__STR__
910 return $str;
911}
912
913sub getAppDataCTail()
914{
915 my $str = << "__STR__";
916
917/*****************************************************************************
918 * FUNCTION
919 * mmi_app_info_array_size
920 * DESCRIPTION
921 * Get size of mmi_app_info[] array
922 * PARAMETERS
923 * void
924 * RETURNS
925 * Number of elements
926 *****************************************************************************/
927U32 mmi_app_info_array_size(void)
928{
929 return sizeof(mmi_app_info)/sizeof(mmi_app_info_struct);
930}
931__STR__
932 return $str;
933}
934
935sub getAppDataHTail()
936{
937 my $str = << "__STR__";
938
939
940/* mmi_app_info_struct structure declaration */
941typedef struct {
942 U16 baseId;
943 U16 baseIdMax;
944 U16 name;
945 U32 base_size;
946 U32 fg_size;
947 U32 heap_size;
948 U32 heap_shrink_size;
949 FLOAT vrt_mem_factor;
950} mmi_app_info_struct;
951
952/* extern declaration to use the mmi_app_info array */
953extern const mmi_app_info_struct mmi_app_info[];
954
955/* extern declaration to use the mmi_app_info_array_size() function to get the number of elements */
956extern U32 mmi_app_info_array_size(void);
957
958__STR__
959 return $str;
960}
961
962sub getFileHeaderStr()
963{
964 my ($filename) = @_;
965 my $str = << "__STR__";
966/*****************************************************************************
967* Copyright Statement:
968* --------------------
969* This software is protected by Copyright and the information contained
970* herein is confidential. The software may not be copied and the information
971* contained herein may not be used or disclosed except with the written
972* permission of MediaTek Inc. (C) 2005
973*
974* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
975* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
976* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
977* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
978* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
979* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
980* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
981* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
982* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
983* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
984* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
985* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
986*
987* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
988* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
989* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
990* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
991* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
992*
993* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
994* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
995* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
996* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
997* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
998*
999*****************************************************************************/
1000
1001/*******************************************************************************
1002 * Filename:
1003 * ---------
1004 * $filename
1005 *
1006 * Project:
1007 * --------
1008 * MAUI
1009 *
1010 * Description:
1011 * ------------
1012 * Resource populate function generated by XML resgen
1013 *
1014 * Author:
1015 * -------
1016 * MTK resgenerator XML parser
1017 *
1018 *******************************************************************************/
1019__STR__
1020 return $str;
1021}
1022
1023
1024sub trim()
1025{
1026 my $str;
1027 ($str) = @_;
1028
1029 $str =~ s/(^\s*)|(\s*$)//g;
1030 return $str;
1031}
1032
1033
1034sub splitPathName()
1035{
1036 my $pathname;
1037 my $path_ref;
1038
1039 ($pathname, $path_ref) = @_;
1040
1041 if ($pathname =~ /(^.*)\\([^\\\/]+$)/)
1042 {
1043 #print "path [$1] filename[$2]\n";
1044 $$path_ref = $1 if ($path_ref != 0);
1045 return $2;
1046 }
1047 else
1048 {
1049 die "can't split path/name from $pathname\n";
1050 }
1051}
1052
1053sub getHelp()
1054{
1055 my $helpStr = << "__HELP_STR__";
1056
1057Usage:
1058 mmi_mem_cfg.pl <memory config file> <mcu path> <src output path> <header output path>
1059__HELP_STR__
1060
1061 return $helpStr;
1062}