SD AMSv2: fix r29169
[maemo-rb.git] / tools / ovl_offset.pl
blob89c346855605b9e74544e4e5af87d16725744567
1 #!/usr/bin/perl
3 # Calculate the highest possible location for an overlay based
4 # on a reference map file (.refmap)
6 sub map_scan {
7 my ($map) = @_;
8 my $ramstart = -1, $ramsize = -1, $startaddr = -1, $endaddr = -1;
9 open (MAP, "<$map");
10 while (<MAP>) {
11 if ($_ =~ /^PLUGIN_RAM +0x([0-9a-f]+) +0x([0-9a-f]+)$/) {
12 $ramstart = hex($1);
13 $ramsize = hex($2);
15 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_start_addr = ./) {
16 $startaddr = hex($1);
18 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_end_addr = ./) {
19 $endaddr = hex($1);
22 close (MAP);
23 if ($ramstart < 0 || $ramsize < 0 || $startaddr < 0 || $endaddr < 0
24 || $ramstart != $startaddr) {
25 printf "Could not analyze map file.\n";
26 exit 1;
28 return $ramstart + $ramsize - $endaddr;
31 printf map_scan($ARGV[0]) & ~0xf;