imgtools/buildrom/tools/featuresutil.pm
author jjkang
Tue, 29 Jun 2010 14:52:54 +0800
changeset 606 30b30f9da0b7
parent 0 044383f39525
permissions -rw-r--r--
Add ..\dev\.. to path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     1
#
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     2
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     3
# All rights reserved.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     8
#
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
     9
# Initial Contributors:
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    10
# Nokia Corporation - initial contribution.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    11
#
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    12
# Contributors:
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    13
#
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    14
# Description: 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    15
#
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    16
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    17
package featuresutil;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    18
        
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    19
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    20
require Exporter;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    21
@ISA = qw(Exporter);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    22
@EXPORT = qw(
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    23
	parseXMLDatabase
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    24
	createFeatureFile
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    25
	convert_FeatRegToFeatMgr
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    26
);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    27
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    28
use strict;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    29
use XML::Handler::XMLWriter;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    30
#use IO;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    31
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    32
use featureparser;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    33
use featuremanager;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    34
use featureregistry;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    35
use featuresdat;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    36
use featurecfg;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    37
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    38
my $xmlDBHandle = undef; #Object of feature parser
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    39
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    40
my @includeFeatureList;	#List of included features. The included feature in this list is a hash table giving the 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    41
			#Uid or the name. These features are collected from the iby/obey files.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    42
my @excludeFeatureList;	#List of excluded features.The excluded feature in this list is a hash table giving the 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    43
			#Uid or the name. These features are collected from the iby/obey files.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    44
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    45
my $verboseFlg = 0; # verbose mode flag
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    46
my $strictFlg = 1; # strict mode flag
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    47
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    48
# Subroutine to generate warning messages.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    49
sub WARN 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    50
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    51
	print "WARNING: ".$_[0]."\n"; 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    52
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    53
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    54
# Subroutine to generate error messages.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    55
sub ERROR 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    56
{ 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    57
	print "ERROR: ".$_[0]."\n"; 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    58
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    59
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    60
# Verbose mode output routine
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    61
sub MSG 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    62
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    63
	if($verboseFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    64
		print "**".$_[0]."...\n";
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    65
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    66
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    67
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    68
# Subroutine to parse feature list XML database file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    69
# @param dbfileList					- List of XML database file names seperated by commas.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    70
# @param fmFlag						- Flag to generate features data file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    71
# @param strictFlg					- Flag to enable strict mode (optional).
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    72
# @param verboseFlg                 - Flag to enable verbose mode (optional).
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    73
sub parseXMLDatabase
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    74
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    75
	my $dbfileList = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    76
	my $fmFlag = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    77
	$strictFlg = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    78
	$verboseFlg = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    79
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    80
	# list of xml databases
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    81
	my @filelist = split(/,/,$dbfileList);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    82
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    83
	# return status
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    84
	my $retStatus = 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    85
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    86
	# default mode is strict
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    87
	$strictFlg=0 if(!defined $strictFlg);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    88
	# default mode is nonverbose
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    89
	$verboseFlg=0 if(!defined $verboseFlg);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    90
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    91
	# multiple file support is not applicable for feature registry option
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    92
	if( (@filelist > 1) && (!$fmFlag) ) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    93
		&ERROR("Multiple XML database file support is not applicable for featureregistry option");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    94
		return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    95
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    96
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    97
	if($fmFlag) # Feature manager option handling
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    98
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
    99
		# create the object of feature manager class
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   100
		$xmlDBHandle = new featuremanager;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   101
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   102
		if($xmlDBHandle) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   103
			foreach my $file (@filelist) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   104
			{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   105
				my $status = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   106
				if(-e $file) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   107
					
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   108
					&MSG("Parsing $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   109
					
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   110
					# parse the feature manager xml file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   111
					$status = $xmlDBHandle->parseXMLFile($file);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   112
					if(! $status) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   113
					
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   114
						# create the object of feature registry class
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   115
						my $registryObj = new featureregistry;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   116
						# parse the feature registry xml file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   117
						$status = $registryObj->parseXMLFile($file);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   118
						if($status < 0) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   119
							if($strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   120
								&ERROR("Invalid features database $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   121
								$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   122
								return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   123
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   124
							else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   125
								&WARN("Invalid features database $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   126
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   127
						}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   128
						elsif(! $status) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   129
							# if the xml file is not valid feature list xml file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   130
							if($strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   131
								&ERROR("Error in reading features database file \"$file\"");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   132
								$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   133
								return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   134
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   135
							else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   136
								&WARN("Error in reading features database file \"$file\"");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   137
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   138
						}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   139
						else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   140
							MSG("Converting featureregistry database to featuremanager");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   141
							
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   142
							# add the feature registry file object to the feature manager file object
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   143
							if(! $xmlDBHandle->addFeatureRegistry($registryObj)) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   144
								if($strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   145
									MSG("Error in reading features database file \"$file\"");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   146
									$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   147
									return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   148
								}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   149
								else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   150
									&WARN("Error in reading features database file \"$file\"");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   151
								}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   152
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   153
							else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   154
								# parsing feature registry database success
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   155
								$retStatus = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   156
							}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   157
						}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   158
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   159
					elsif( $status < 0 ) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   160
						if($strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   161
							&ERROR("Invalid features database $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   162
							$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   163
							return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   164
						}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   165
						else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   166
							&WARN("Invalid features database $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   167
						}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   168
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   169
					else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   170
						# parsing feature manager database success
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   171
						$retStatus = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   172
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   173
				}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   174
				else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   175
					if(!$strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   176
						&WARN($file." doesn\'t exist");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   177
						next;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   178
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   179
					else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   180
						&ERROR($file." doesn\'t exist");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   181
						$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   182
						return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   183
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   184
				}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   185
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   186
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   187
		else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   188
			&ERROR("Couldn't create feature parser object");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   189
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   190
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   191
	else # Feature registry file handling
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   192
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   193
		if(@filelist) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   194
			my $file = $filelist[0];
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   195
			$xmlDBHandle = new featureregistry;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   196
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   197
			if($xmlDBHandle) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   198
				if(-e $file) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   199
				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   200
					MSG("Parsing $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   201
					
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   202
					my $status = $xmlDBHandle->parseXMLFile($file);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   203
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   204
					if($status < 0) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   205
						&ERROR($file." is invalid feature registry file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   206
						$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   207
						return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   208
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   209
					elsif(!$status) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   210
						&ERROR("Error in reading feature registry file ".$file);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   211
						$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   212
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   213
					else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   214
						# parsing feature registry database success
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   215
						$retStatus = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   216
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   217
				}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   218
				else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   219
					if(!$strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   220
						&WARN($file." doesn\'t exist -- ");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   221
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   222
					else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   223
						&ERROR($file." doesn\'t exist -- ");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   224
					}				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   225
					$xmlDBHandle = undef;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   226
				}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   227
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   228
			else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   229
				&ERROR("Couldn't create feature parser object");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   230
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   231
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   232
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   233
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   234
	if($retStatus) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   235
		return $xmlDBHandle
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   236
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   237
	else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   238
		return $retStatus;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   239
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   240
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   241
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   242
# Subroutine to generate feature manager database file from the given feature registry database
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   243
# @param strictFlg - strict mode flag
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   244
# @param verboseFlg - verbose mode flag
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   245
# @param outpath - destination path for the converted database file(s)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   246
# @param dblist - list of xml file names
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   247
sub convert_FeatRegToFeatMgr
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   248
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   249
	$strictFlg = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   250
	$verboseFlg = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   251
	my $outpath = shift;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   252
	my @dblist = @_;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   253
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   254
	# default mode is strict
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   255
	$strictFlg=0 if(!defined $strictFlg);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   256
	# default mode is nonverbose
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   257
	$verboseFlg=0 if(!defined $verboseFlg);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   258
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   259
	foreach my $file (@dblist)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   260
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   261
		# Create the object of feature registry
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   262
		my $fileHandle = new featureregistry;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   263
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   264
		if(-e $file) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   265
			# Parse the database
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   266
			if($fileHandle->parseXMLFile($file) > 0) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   267
				MSG("Converting Feature Registry database $file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   268
				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   269
				# Create directory if it doesn't exists
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   270
				if(!(-e $outpath)) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   271
					if(!mkdir($outpath)) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   272
						&ERROR("Failed to create $outpath folder");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   273
						return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   274
					}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   275
				}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   276
				# Emit the contents of feature registry object into an feature manager database file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   277
				&generateXML($fileHandle, $outpath);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   278
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   279
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   280
		else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   281
			if(!$strictFlg) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   282
				&WARN($file." doesn\'t exist -- ");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   283
				next;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   284
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   285
			else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   286
				&ERROR($file." doesn\'t exist -- ");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   287
				return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   288
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   289
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   290
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   291
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   292
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   293
# Subroutine to emit XML output for the given featureregistry object
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   294
# @param frObject - object of feature registry database
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   295
# @param outPath - destination path for the converted database file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   296
sub generateXML
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   297
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   298
	my ($frObject, $outPath) = @_;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   299
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   300
	my $outputFile = $frObject->fileName();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   301
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   302
	# Extract absolute file name
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   303
	if( $outputFile =~ /[\\\/]/) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   304
		$outputFile =~ /.*[\\\/](.+)\z/;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   305
		$outputFile = $1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   306
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   307
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   308
	# Add suffix _converted
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   309
	$outputFile =~ s/(.*)([\.].+)\z/$1_converted$2/;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   310
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   311
	my $fileHandle = new IO::File(">$outPath$outputFile");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   312
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   313
	if($fileHandle) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   314
		my $writer = XML::Handler::XMLWriter->new(Output => $fileHandle);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   315
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   316
		# Header
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   317
		$writer->start_document();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   318
		$writer->print("<!--Converted from the feature registry ".$frObject->fileName()."-->\n\n");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   319
		# DOCTYPE
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   320
		$writer->print("<!DOCTYPE featuredatabase SYSTEM \"featuredatabase.dtd\">\n\n");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   321
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   322
		# Root element begin
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   323
		$writer->start_element({Name => 'featuredatabase', Attributes => {}});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   324
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   325
		# FeatureSet element
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   326
		$writer->print("\n\t");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   327
		$writer->start_element({Name => 'featureset', Attributes => {}});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   328
		my $nameuidmap = $frObject->featureNameUidMap();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   329
		foreach my $uid (sort(values %$nameuidmap)) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   330
			my $featinfo = $frObject->getFeatureInfo($uid);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   331
			my %attributes = ();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   332
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   333
			$attributes{uid} = sprintf("0x%08X",$uid);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   334
			$attributes{statusflags} = "0x00000001";
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   335
			$attributes{name} = $featinfo->{name};
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   336
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   337
			$writer->print("\n\t\t");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   338
			$writer->start_element({Name => 'feature', Attributes => \%attributes});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   339
			$writer->end_element({Name => 'feature'});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   340
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   341
		$writer->print("\n\t");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   342
		$writer->end_element({Name => 'featureset'});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   343
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   344
		# defaultfeaturerange element
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   345
		my $rangeList = $frObject->defaultRangeList();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   346
		foreach my $range (@$rangeList) {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   347
			my %attributes = ();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   348
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   349
			next if(lc($range->{support}) eq "exclude");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   350
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   351
			$attributes{higheruid} = sprintf("0x%08X",$range->{max});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   352
			$attributes{loweruid} = sprintf("0x%08X",$range->{min});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   353
			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   354
			$writer->print("\n\t");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   355
			$writer->start_element({Name => 'defaultfeaturerange', Attributes => \%attributes});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   356
			$writer->end_element({Name => 'defaultfeaturerange'});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   357
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   358
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   359
		# Root element close
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   360
		$writer->print("\n");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   361
		$writer->end_element({Name => 'featuredatabase'});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   362
		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   363
		# Footer
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   364
		$writer->end_document();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   365
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   366
	else {
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   367
		&ERROR("Failed to create $outPath$outputFile file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   368
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   369
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   370
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   371
# Subroutine to create Feature Registry/Features Data file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   372
# @param romimage				 - Rom image number.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   373
# @param featurefile			 - Feature file number.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   374
# @param featurefilename		 - Name of the feature file to be generated.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   375
# @param featureslist			 - Reference to array of hashes containing features to included/excluded.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   376
# @param featuremanager			 - Flag to generate features data file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   377
# @param singleDATfile           - Flag to generate single features.dat file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   378
sub createFeatureFile
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   379
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   380
	if(!defined ($xmlDBHandle)) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   381
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   382
		ERROR("No XML Database opened");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   383
		return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   384
	}	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   385
	my ($romimage,$featurefile,$featurefilename,$featureslist,$featuremanager,$singleDATfile) = @_;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   386
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   387
	# Default setting for singleDATfile flag
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   388
	$singleDATfile = 0 if(!defined $singleDATfile);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   389
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   390
	# Clear the global include/exclude feature list.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   391
	@includeFeatureList = (); 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   392
	@excludeFeatureList = ();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   393
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   394
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   395
	for(my $k=0;$k<scalar @$featureslist;$k++)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   396
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   397
		if(($singleDATfile) || ($featureslist->[$k]{rom}==$romimage && $featureslist->[$k]{cfgfile} == $featurefile))
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   398
		{			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   399
			AddToFeatureList($featureslist->[$k],$featuremanager);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   400
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   401
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   402
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   403
	my $features = &featureparser::getFeatures(\@includeFeatureList, \@excludeFeatureList);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   404
	if (!$features)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   405
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   406
		ERROR("No feature file generated for ROM_IMAGE[".$romimage."]");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   407
		return 0;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   408
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   409
	else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   410
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   411
		my $object;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   412
		if ($featuremanager) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   413
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   414
			$object = new featuresdat($xmlDBHandle);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   415
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   416
		else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   417
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   418
			$object = new featurecfg($xmlDBHandle);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   419
		}		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   420
		return $object->createFile($featurefilename, $features , $featuremanager);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   421
	}	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   422
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   423
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   424
# Subroutine to add the feature specified to the included/excluded feature list
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   425
# @param featureData				 - Reference to hash containing feature information (i.e. name/uid,
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   426
# 									   included/excluded,SF and UD).  
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   427
# @param featuremanager				 - Flag to generate features data file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   428
sub AddToFeatureList
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   429
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   430
	my ($featureData, $featuremanager) = @_; 	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   431
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   432
	my %feat = ();
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   433
	my $feature = $featureData->{feature};		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   434
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   435
#	Check if the given value is a feature name.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   436
	my $value = $xmlDBHandle->getFeatureUID($feature);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   437
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   438
#	If not a feature, then may be uid value
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   439
	if(!defined $value)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   440
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   441
		if (!featureparser::IsValidNum($feature)) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   442
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   443
			ERROR("Feature \"".$feature."\" not found in feature list XML");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   444
			return;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   445
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   446
		if (&featureparser::ValidateUIDValue($feature))
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   447
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   448
			my $featureUid = $feature;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   449
			$feature = &featureparser::ConvertHexToDecimal($feature);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   450
			my $featureInfo = $xmlDBHandle->getFeatureInfo($feature);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   451
			if (!$featureInfo)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   452
			{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   453
				ERROR("Feature \"".$featureUid."\" not found in feature list XML");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   454
				return;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   455
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   456
			else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   457
			{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   458
				$feat{uid} = $feature;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   459
				$feat{name} = $featureInfo->{name};				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   460
			}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   461
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   462
		else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   463
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   464
			return;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   465
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   466
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   467
	else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   468
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   469
		$feat{name} = $feature;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   470
		$feat{uid} = $value;		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   471
	}		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   472
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   473
	# Set the values of "SF" and "UD" for feature manager.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   474
	if ($featuremanager) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   475
	{		
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   476
		&setFeatureArguments(\%feat,$featureData->{SF},$featureData->{UD});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   477
	}	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   478
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   479
	if($featureData->{include} == 1)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   480
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   481
		$feat{include} = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   482
		push @includeFeatureList, \%feat;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   483
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   484
	else
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   485
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   486
		$feat{exclude} = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   487
		push @excludeFeatureList, \%feat;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   488
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   489
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   490
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   491
# Subroutine to set the values of "SF" and "UD" for the specified feature
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   492
# @param feat						- Reference to hash containing information(i.e. name and uid) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   493
#									  of the specified feature.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   494
# @param SF							- Value of "SF" provided in the iby/oby file. 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   495
# @param UD							- Value of "UD" provided in the iby/oby file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   496
sub setFeatureArguments
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   497
{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   498
	my($feat,$SF,$UD)= @_;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   499
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   500
	my $featureInfo = $xmlDBHandle->getFeatureInfo($feat->{uid});
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   501
	
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   502
	# If the values of 'SF' and 'UD' are not provided in the iby/oby file, then take the values
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   503
	# from Feature Database XML file.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   504
	if ($SF && featureparser::IsValidNum($SF))  
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   505
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   506
		$feat->{SF} = &featureparser::ConvertHexToDecimal($SF);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   507
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   508
	else 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   509
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   510
		# Generate warning if the value of "SF" provided for the feature in iby/oby file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   511
		# is invalid.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   512
		if ($SF) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   513
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   514
			WARN("Invalid SF value \"$SF\" provided for feature \"$feat->{name}\". Defaulting to value provided in XML file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   515
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   516
		$feat->{SF} = &featureparser::ConvertHexToDecimal($featureInfo->{statusflags});			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   517
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   518
	if ($UD && featureparser::IsValidNum($UD))  					
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   519
	{			
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   520
		$feat->{UD} = &featureparser::ConvertHexToDecimal($UD);						
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   521
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   522
	else 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   523
	{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   524
		# Generate warning if the value of "UD" provided for the feature in iby/oby file
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   525
		# is invalid.
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   526
		if ($UD) 
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   527
		{
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   528
			WARN("Invalid UD value \"$UD\" provided for feature \"$feat->{name}\". Defaulting to value provided in XML file");
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   529
		}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   530
		$feat->{UD} = &featureparser::ConvertHexToDecimal($featureInfo->{userdata});				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   531
	}				
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   532
}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   533
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 0
diff changeset
   534
1;