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