os/persistentdata/featuremgmt/featureregistry/tools/featregconfig/scripts/checkfeatregconfig.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 # All rights reserved.
     3 # This component and the accompanying materials are made available
     4 # under the terms of "Eclipse Public License v1.0"
     5 # which accompanies this distribution, and is available
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 #
     8 # Initial Contributors:
     9 # Nokia Corporation - initial contribution.
    10 #
    11 # Contributors:
    12 #
    13 # Description:
    14 # Feature Registry Configuration File Lister/Checker
    15 # 
    16 #
    17 
    18 use strict;
    19 
    20 # Usage help text
    21 my $usage = "Feature Registry Configuration File Lister/Checker\n" .
    22 			"Copyright (c) 2005 Symbian Software Ltd. All rights reserved\n\n" .
    23 			"Usage: perl $0 BINCONFIGFILE\n\n" .
    24 			"Returns 0 if config file is valid, non-zero and reasons otherwise\n";
    25 
    26 # Process command line
    27 if (1 != scalar(@ARGV))
    28 	{
    29 	print $usage;
    30 	exit 1;
    31 	}
    32 my $binConfigFile = $ARGV[0];
    33 
    34 # open config file in binary mode
    35 my $BINCONFIG;
    36 if (!open ($BINCONFIG, $binConfigFile))
    37 	{
    38 	print "ERROR: Binary config file is missing or cannot be opened";
    39 	exit 1;
    40 	}
    41 binmode $BINCONFIG;
    42 
    43 # Check file size
    44 my ($dev, $ino, $mode, $nlink, $_uid, $_gid, $redv, $size, $atime, $mtime, $ctime, $blksize, $blocks)
    45 	= stat $BINCONFIG;
    46 my $headerSize = 16;
    47 if ($size < $headerSize)
    48 	{
    49 	print "INVALID Feature Registry Config File: file is too small, must have at least 16 byte header";
    50 	exit 1;
    51 	}
    52 my $KMaxLargePropertySize = 65535;
    53 if ($size > $KMaxLargePropertySize)
    54 	{
    55 	print "INVALID Feature Registry Config File: File is larger than limit of 65535 bytes";
    56 	exit 1;
    57 	}
    58 if ($size > 4096) # arbitrarily chosen; it may be sensible to change the way featreg works if config files become this big
    59 	{
    60 	print "WARNING: Large Feature Registry config file (", $ARGV[0], "); something may be wrong\n";
    61 	}
    62 
    63 # Read and check header
    64 my $packedHeader;
    65 if (!read($BINCONFIG, $packedHeader, $headerSize) ||
    66 	(length $packedHeader < 16))
    67 	{
    68 	print "INVALID Feature Registry Config File: Could not read 16-byte header";
    69 	exit 1;
    70 	}
    71 my ($feat, $version, $entryCount, $rangeCount) = unpack 'a4I3', $packedHeader;
    72 if ($feat ne 'feat')
    73 	{
    74 	print "INVALID Feature Registry Config File: First 4 bytes of header must be ASCII 'f' 'e' 'a' 't'";
    75 	exit 1;
    76 	}
    77 if ($version != 0)
    78 	{
    79 	print "INVALID Feature Registry Config File: Second 32-bit word in header (version/flags) must be zero";
    80 	exit 1;
    81 	}
    82 my $entrySize = 8;
    83 my $rangeSize = 8;
    84 my $expectedSize = $headerSize + $entryCount*$entrySize + $rangeCount*$rangeSize;
    85 if ($expectedSize != $size)
    86 	{
    87 	print "INVALID Feature Registry Config File: Size of file ($size bytes) does not match size expected from header" .
    88 		  " ($expectedSize bytes) for $entryCount feature entries and $rangeCount default ranges";
    89 	exit 1;
    90 	}
    91 
    92 # Write information from the header:
    93 print "Feature Registry Configuration file '$binConfigFile'\n";
    94 print "Contains $entryCount feature entries and $rangeCount default ranges\n";
    95 
    96 print "---\n";
    97 
    98 # Check individual feature entries are listed by increasing (and non-repeating) UID, and write them to STDOUT
    99 my $lastFeatureUid = 0;
   100 for (my $e = 0; $e < $entryCount; $e++)
   101 	{
   102 	my $packedEntry;
   103 	if (!read($BINCONFIG, $packedEntry, $entrySize) ||
   104 		(length $packedEntry < $entrySize))
   105 		{
   106 		print "INVALID Feature Registry Config File: Unable to read feature entry $e";
   107 		exit 1;
   108 		}
   109 	my ($featureUid, $status) = unpack 'I2', $packedEntry;
   110 	printf "Feature UID 0x%08X, status = 0x%08X (%s)\n", $featureUid, $status, ($status & 1) ? 'supported' : 'not supported';
   111 	if (($e > 0) && ($featureUid <= $lastFeatureUid))
   112 		{
   113 		print "INVALID Feature Registry Config File: Feature entries not listed by increasing (and non-repeating) UID";
   114 		exit 1;
   115 		}
   116 	if ($status & ~3)
   117 		{
   118 		print "WARNING Feature Registry Config File: Feature entry status bits 2-31 should be zero\n";
   119 		}
   120 	$lastFeatureUid = $featureUid;
   121 	}
   122 
   123 print "---\n";
   124 
   125 # Check default supported ranges are in low-UID / high-UID pairs
   126 # AND that the Symbian Essential default range is covered:
   127 my $EssentialDefaultSupportedRangeLowUid = 271030278;
   128 my $EssentialDefaultSupportedRangeHighUid = 271063045;
   129 if (($EssentialDefaultSupportedRangeLowUid != 0x10279806) ||
   130 	($EssentialDefaultSupportedRangeHighUid != 0x10281805))
   131 	{
   132 	print "ERROR Mismatch on Feature Registry Symbian essential default-supported range";
   133 	exit 1;
   134 	}
   135 my $haveEssentialRange;
   136 for (my $r = 0; $r < $rangeCount; $r++)
   137 	{
   138 	my $packedRange;
   139 	if (!read($BINCONFIG, $packedRange, $entrySize) ||
   140 		(length $packedRange < $rangeSize))
   141 		{
   142 		print "INVALID Feature Registry Config File: Unable to read default-supported range $r";
   143 		exit 1;
   144 		}
   145 	my ($lowUid, $highUid) = unpack 'I2', $packedRange;
   146 	printf "Feature UID range 0x%08X to 0x%08X supported by default\n", $lowUid, $highUid;
   147 	if (($lowUid <= $EssentialDefaultSupportedRangeLowUid) &&
   148 		($highUid >= $EssentialDefaultSupportedRangeHighUid))
   149 		{
   150 		$haveEssentialRange = 1;
   151 		}
   152 	if ($lowUid > $highUid)
   153 		{
   154 		print "INVALID Feature Registry Config File: Default-supported range is not listed in order Low-UID High-Uid";
   155 		exit 1;
   156 		}
   157 	}
   158 
   159 if (!$haveEssentialRange)
   160 	{
   161 	printf "INVALID Feature Registry Config File: Symbian essential default-supported UID range 0x%08X to 0x%08X is not present\n",
   162 		$EssentialDefaultSupportedRangeLowUid, $EssentialDefaultSupportedRangeHighUid;
   163 	exit 1;
   164 	}
   165 
   166 # Confirm there's nothing more to read
   167 my $junk;
   168 if (read $BINCONFIG, $junk, 1)
   169 	{
   170 	printf "INVALID Feature Registry Config File: Unexpected data at end of binary configuration file";
   171 	exit 1;
   172 	}
   173 
   174 # Warn if the filename is not 'featreg.cfg' (case insensitive)
   175 if ($binConfigFile !~ m/[Ff][Ee][Aa][Tt][Rr][Ee][Gg]\.[Cc][Ff][Gg]$/)
   176 	{
   177 	printf "WARNING Feature Registry Config File must be called 'featreg.cfg'";
   178 	}
   179 
   180 # Success - a valid configuration file (but it's up to you to guarantee the entries and ranges are correct,
   181 # and to put the file in the correct location
   182 exit 0;