summaryrefslogtreecommitdiff
path: root/tools/ovl_offset.pl
blob: 89c346855605b9e74544e4e5af87d16725744567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl

# Calculate the highest possible location for an overlay based
# on a reference map file (.refmap)

sub map_scan {
    my ($map) = @_;
    my $ramstart = -1, $ramsize = -1, $startaddr = -1, $endaddr = -1;
    open (MAP, "<$map");
    while (<MAP>) {
        if ($_ =~ /^PLUGIN_RAM +0x([0-9a-f]+) +0x([0-9a-f]+)$/) {
            $ramstart = hex($1);
            $ramsize = hex($2);
        }
        elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_start_addr = ./) {
            $startaddr = hex($1);
        }
        elsif ($_ =~ / +0x([0-9a-f]+) +_?plugin_end_addr = ./) {
            $endaddr = hex($1);
        }
    }
    close (MAP);
    if ($ramstart < 0 || $ramsize < 0 || $startaddr < 0 || $endaddr < 0
        || $ramstart != $startaddr) {
        printf "Could not analyze map file.\n";
        exit 1;
    }
    return $ramstart + $ramsize - $endaddr;
}

printf map_scan($ARGV[0]) & ~0xf;