Prepare new maemo release
[maemo-rb.git] / tools / ovl_offset.pl
blob10419999d6c794e5afbab9534cbf347ceb96b5f4
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 # The buflib handle table is a few hundred bytes, just before
8 # the plugin buffer. We assume it's never more than 1024 bytes.
9 # If this assumption is wrong, overlay loading will fail.
10 my $max_handle_table_size = 1024;
11 my ($map) = @_;
12 my $ramstart = -1, $ramsize = -1, $startaddr = -1, $endaddr = -1;
13 open (MAP, "<$map");
14 while (<MAP>) {
15 if ($_ =~ /^PLUGIN_RAM +0x([0-9a-f]+) +0x([0-9a-f]+)$/) {
16 $ramstart = hex($1);
17 $ramsize = hex($2);
19 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_start_addr = ./) {
20 $startaddr = hex($1);
22 elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_end_addr = ./) {
23 $endaddr = hex($1);
26 close (MAP);
27 if ($ramstart < 0 || $ramsize < 0 || $startaddr < 0 || $endaddr < 0
28 || $ramstart != $startaddr) {
29 printf "Could not analyze map file.\n";
30 exit 1;
32 return $ramstart + $ramsize - $endaddr - $max_handle_table_size;
35 printf map_scan($ARGV[0]) & ~0xf;