os/persistentdata/featuremgmt/featureregistry/tools/featregconfig/scripts/checkfeatregconfig.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/featuremgmt/featureregistry/tools/featregconfig/scripts/checkfeatregconfig.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,182 @@
     1.4 +# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +# All rights reserved.
     1.6 +# This component and the accompanying materials are made available
     1.7 +# under the terms of "Eclipse Public License v1.0"
     1.8 +# which accompanies this distribution, and is available
     1.9 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +#
    1.11 +# Initial Contributors:
    1.12 +# Nokia Corporation - initial contribution.
    1.13 +#
    1.14 +# Contributors:
    1.15 +#
    1.16 +# Description:
    1.17 +# Feature Registry Configuration File Lister/Checker
    1.18 +# 
    1.19 +#
    1.20 +
    1.21 +use strict;
    1.22 +
    1.23 +# Usage help text
    1.24 +my $usage = "Feature Registry Configuration File Lister/Checker\n" .
    1.25 +			"Copyright (c) 2005 Symbian Software Ltd. All rights reserved\n\n" .
    1.26 +			"Usage: perl $0 BINCONFIGFILE\n\n" .
    1.27 +			"Returns 0 if config file is valid, non-zero and reasons otherwise\n";
    1.28 +
    1.29 +# Process command line
    1.30 +if (1 != scalar(@ARGV))
    1.31 +	{
    1.32 +	print $usage;
    1.33 +	exit 1;
    1.34 +	}
    1.35 +my $binConfigFile = $ARGV[0];
    1.36 +
    1.37 +# open config file in binary mode
    1.38 +my $BINCONFIG;
    1.39 +if (!open ($BINCONFIG, $binConfigFile))
    1.40 +	{
    1.41 +	print "ERROR: Binary config file is missing or cannot be opened";
    1.42 +	exit 1;
    1.43 +	}
    1.44 +binmode $BINCONFIG;
    1.45 +
    1.46 +# Check file size
    1.47 +my ($dev, $ino, $mode, $nlink, $_uid, $_gid, $redv, $size, $atime, $mtime, $ctime, $blksize, $blocks)
    1.48 +	= stat $BINCONFIG;
    1.49 +my $headerSize = 16;
    1.50 +if ($size < $headerSize)
    1.51 +	{
    1.52 +	print "INVALID Feature Registry Config File: file is too small, must have at least 16 byte header";
    1.53 +	exit 1;
    1.54 +	}
    1.55 +my $KMaxLargePropertySize = 65535;
    1.56 +if ($size > $KMaxLargePropertySize)
    1.57 +	{
    1.58 +	print "INVALID Feature Registry Config File: File is larger than limit of 65535 bytes";
    1.59 +	exit 1;
    1.60 +	}
    1.61 +if ($size > 4096) # arbitrarily chosen; it may be sensible to change the way featreg works if config files become this big
    1.62 +	{
    1.63 +	print "WARNING: Large Feature Registry config file (", $ARGV[0], "); something may be wrong\n";
    1.64 +	}
    1.65 +
    1.66 +# Read and check header
    1.67 +my $packedHeader;
    1.68 +if (!read($BINCONFIG, $packedHeader, $headerSize) ||
    1.69 +	(length $packedHeader < 16))
    1.70 +	{
    1.71 +	print "INVALID Feature Registry Config File: Could not read 16-byte header";
    1.72 +	exit 1;
    1.73 +	}
    1.74 +my ($feat, $version, $entryCount, $rangeCount) = unpack 'a4I3', $packedHeader;
    1.75 +if ($feat ne 'feat')
    1.76 +	{
    1.77 +	print "INVALID Feature Registry Config File: First 4 bytes of header must be ASCII 'f' 'e' 'a' 't'";
    1.78 +	exit 1;
    1.79 +	}
    1.80 +if ($version != 0)
    1.81 +	{
    1.82 +	print "INVALID Feature Registry Config File: Second 32-bit word in header (version/flags) must be zero";
    1.83 +	exit 1;
    1.84 +	}
    1.85 +my $entrySize = 8;
    1.86 +my $rangeSize = 8;
    1.87 +my $expectedSize = $headerSize + $entryCount*$entrySize + $rangeCount*$rangeSize;
    1.88 +if ($expectedSize != $size)
    1.89 +	{
    1.90 +	print "INVALID Feature Registry Config File: Size of file ($size bytes) does not match size expected from header" .
    1.91 +		  " ($expectedSize bytes) for $entryCount feature entries and $rangeCount default ranges";
    1.92 +	exit 1;
    1.93 +	}
    1.94 +
    1.95 +# Write information from the header:
    1.96 +print "Feature Registry Configuration file '$binConfigFile'\n";
    1.97 +print "Contains $entryCount feature entries and $rangeCount default ranges\n";
    1.98 +
    1.99 +print "---\n";
   1.100 +
   1.101 +# Check individual feature entries are listed by increasing (and non-repeating) UID, and write them to STDOUT
   1.102 +my $lastFeatureUid = 0;
   1.103 +for (my $e = 0; $e < $entryCount; $e++)
   1.104 +	{
   1.105 +	my $packedEntry;
   1.106 +	if (!read($BINCONFIG, $packedEntry, $entrySize) ||
   1.107 +		(length $packedEntry < $entrySize))
   1.108 +		{
   1.109 +		print "INVALID Feature Registry Config File: Unable to read feature entry $e";
   1.110 +		exit 1;
   1.111 +		}
   1.112 +	my ($featureUid, $status) = unpack 'I2', $packedEntry;
   1.113 +	printf "Feature UID 0x%08X, status = 0x%08X (%s)\n", $featureUid, $status, ($status & 1) ? 'supported' : 'not supported';
   1.114 +	if (($e > 0) && ($featureUid <= $lastFeatureUid))
   1.115 +		{
   1.116 +		print "INVALID Feature Registry Config File: Feature entries not listed by increasing (and non-repeating) UID";
   1.117 +		exit 1;
   1.118 +		}
   1.119 +	if ($status & ~3)
   1.120 +		{
   1.121 +		print "WARNING Feature Registry Config File: Feature entry status bits 2-31 should be zero\n";
   1.122 +		}
   1.123 +	$lastFeatureUid = $featureUid;
   1.124 +	}
   1.125 +
   1.126 +print "---\n";
   1.127 +
   1.128 +# Check default supported ranges are in low-UID / high-UID pairs
   1.129 +# AND that the Symbian Essential default range is covered:
   1.130 +my $EssentialDefaultSupportedRangeLowUid = 271030278;
   1.131 +my $EssentialDefaultSupportedRangeHighUid = 271063045;
   1.132 +if (($EssentialDefaultSupportedRangeLowUid != 0x10279806) ||
   1.133 +	($EssentialDefaultSupportedRangeHighUid != 0x10281805))
   1.134 +	{
   1.135 +	print "ERROR Mismatch on Feature Registry Symbian essential default-supported range";
   1.136 +	exit 1;
   1.137 +	}
   1.138 +my $haveEssentialRange;
   1.139 +for (my $r = 0; $r < $rangeCount; $r++)
   1.140 +	{
   1.141 +	my $packedRange;
   1.142 +	if (!read($BINCONFIG, $packedRange, $entrySize) ||
   1.143 +		(length $packedRange < $rangeSize))
   1.144 +		{
   1.145 +		print "INVALID Feature Registry Config File: Unable to read default-supported range $r";
   1.146 +		exit 1;
   1.147 +		}
   1.148 +	my ($lowUid, $highUid) = unpack 'I2', $packedRange;
   1.149 +	printf "Feature UID range 0x%08X to 0x%08X supported by default\n", $lowUid, $highUid;
   1.150 +	if (($lowUid <= $EssentialDefaultSupportedRangeLowUid) &&
   1.151 +		($highUid >= $EssentialDefaultSupportedRangeHighUid))
   1.152 +		{
   1.153 +		$haveEssentialRange = 1;
   1.154 +		}
   1.155 +	if ($lowUid > $highUid)
   1.156 +		{
   1.157 +		print "INVALID Feature Registry Config File: Default-supported range is not listed in order Low-UID High-Uid";
   1.158 +		exit 1;
   1.159 +		}
   1.160 +	}
   1.161 +
   1.162 +if (!$haveEssentialRange)
   1.163 +	{
   1.164 +	printf "INVALID Feature Registry Config File: Symbian essential default-supported UID range 0x%08X to 0x%08X is not present\n",
   1.165 +		$EssentialDefaultSupportedRangeLowUid, $EssentialDefaultSupportedRangeHighUid;
   1.166 +	exit 1;
   1.167 +	}
   1.168 +
   1.169 +# Confirm there's nothing more to read
   1.170 +my $junk;
   1.171 +if (read $BINCONFIG, $junk, 1)
   1.172 +	{
   1.173 +	printf "INVALID Feature Registry Config File: Unexpected data at end of binary configuration file";
   1.174 +	exit 1;
   1.175 +	}
   1.176 +
   1.177 +# Warn if the filename is not 'featreg.cfg' (case insensitive)
   1.178 +if ($binConfigFile !~ m/[Ff][Ee][Aa][Tt][Rr][Ee][Gg]\.[Cc][Ff][Gg]$/)
   1.179 +	{
   1.180 +	printf "WARNING Feature Registry Config File must be called 'featreg.cfg'";
   1.181 +	}
   1.182 +
   1.183 +# Success - a valid configuration file (but it's up to you to guarantee the entries and ranges are correct,
   1.184 +# and to put the file in the correct location
   1.185 +exit 0;