|
1 # |
|
2 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Perl script to dump the ROM root directory |
|
16 # |
|
17 |
|
18 my $imagefile="ba_001.engbuild.img"; |
|
19 my $imageoffset=0; |
|
20 |
|
21 die "Usage: checkstubs [imagefile]\n" if (@ARGV>1); |
|
22 if (@ARGV==1) |
|
23 { |
|
24 $imagefile = @ARGV[0]; |
|
25 $symbolfile = $imagefile; |
|
26 } |
|
27 |
|
28 # 1. Read the root directory list |
|
29 # |
|
30 |
|
31 open IMAGE, "<$imagefile" or die "Cannot open $imagefile"; |
|
32 binmode IMAGE; |
|
33 |
|
34 my $imagedata; |
|
35 my $errors=0; |
|
36 my $romrootdirectory; |
|
37 |
|
38 read IMAGE, $imagedata, 20; |
|
39 if ($imagedata =~ /^EPOC....ROM/) |
|
40 { |
|
41 $imageoffset -= 256; # compensate for REPRO header |
|
42 } |
|
43 |
|
44 sub readimage |
|
45 { |
|
46 my ($length, $linaddr) = @_; |
|
47 my $imagedata; |
|
48 if ($linaddr != 0) # read from next address |
|
49 { |
|
50 if (!seek(IMAGE, $linaddr-$imageoffset, 0)) |
|
51 { |
|
52 printf "Can't seek to address 0x%x\n", $linaddr; |
|
53 $errors++; |
|
54 return ""; |
|
55 } |
|
56 } |
|
57 read IMAGE, $imagedata, $length; |
|
58 return $imagedata; |
|
59 } |
|
60 |
|
61 sub readword |
|
62 { |
|
63 my ($linaddr) = @_; |
|
64 return unpack "V", readimage(4, $linaddr); |
|
65 } |
|
66 |
|
67 # really want read from address 0, but readword does not allow it |
|
68 # so need to read from word 1 and mask out extra byte read |
|
69 if ((readword(1) & 0x00ffffff) == 0x00EA0000) |
|
70 { |
|
71 printf "Kernel ROM image: %s\n\n", $imagefile; |
|
72 $imageoffset += readword(0x8c); |
|
73 readword(); # image size |
|
74 $romrootdirectory = readword(); |
|
75 } |
|
76 else |
|
77 { |
|
78 printf "Extension ROM image: %s\n\n", $imagefile; |
|
79 $imageoffset += readword(0x0c); |
|
80 readword(); # image size |
|
81 $romrootdirectory = readword(); |
|
82 } |
|
83 |
|
84 my $numroots = readword($romrootdirectory); |
|
85 printf "Rom Root Directory List at 0x%08x - %d entries\n", $romrootdirectory, $numroots; |
|
86 |
|
87 my @directories; |
|
88 my $root; |
|
89 while ($numroots) |
|
90 { |
|
91 my $variant = readword(); |
|
92 $root = readword(); |
|
93 $numroots -= 1; |
|
94 printf "Variant 0x%08x @ 0x%08x\n", $variant, $root; |
|
95 push @directories, $root; |
|
96 } |
|
97 |
|
98 foreach $root (@directories) |
|
99 { |
|
100 printf "\nDirectory @ 0x%08x:\n", $root; |
|
101 print_directory($root, ""); |
|
102 } |
|
103 |
|
104 my %seen_before; |
|
105 |
|
106 sub print_directory |
|
107 { |
|
108 my ($dir, $prefix) = @_; |
|
109 if ($seen_before{$dir} == 1) |
|
110 { |
|
111 printf "%s ...\n", $prefix; |
|
112 return; |
|
113 } |
|
114 $seen_before{$dir} = 1; |
|
115 my $entry = $dir+4; |
|
116 my $end = $entry+readword($dir); |
|
117 |
|
118 while ($entry < $end) |
|
119 { |
|
120 my $size = readword($entry); |
|
121 my $linaddr = readword(); |
|
122 my $attributes = unpack "C", readimage(1); |
|
123 my $namelen = unpack "C", readimage(1); |
|
124 my $name = readimage($namelen*2); |
|
125 $name =~ s/(.)./$1/g; # drop high byte of Unicode characters |
|
126 |
|
127 if ($attributes & 0x10) |
|
128 { |
|
129 printf "%s %08x %02x %s\\\n", $prefix, $linaddr, $attributes, $name; |
|
130 print_directory($linaddr, "$prefix |"); |
|
131 } |
|
132 else |
|
133 { |
|
134 printf "%s %08x %02x %6d %s%s\n", $prefix, $linaddr, $attributes, $size, |
|
135 ($seen_before{$linaddr}==1?" *":""), $name; |
|
136 $seen_before{$linaddr} = 1; |
|
137 } |
|
138 $entry += 10 + $namelen*2; |
|
139 $entry = ($entry+3)&~3; |
|
140 } |
|
141 } |