/[mdap]/bin/fw-info.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/fw-info.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

fw-info.pl revision 21 by dpavlin, Mon Apr 23 20:49:47 2007 UTC bin/fw-info.pl revision 87 by dpavlin, Wed Dec 5 23:21:04 2007 UTC
# Line 6  Line 6 
6    
7  use strict;  use strict;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    use File::Find;
10    
11  my $path = shift @ARGV || '/srv/tftp/BANT-R'; # die "Usage: $0 firmware.bin\n";  my $debug = 0;
12    
13  my $magic = 'BLI223QH0';  my @images = @ARGV;
14    push @images, '/srv/tftp/BANT-R' unless @images;
15    
16  open(my $fh, $path) || die "Can't open $path: $!";  my $magic = 'BLI223Q';
 my $b;  
 read($fh, $b, length($magic));  
 die "# $path not a firmware image\n" unless ($b eq $magic);  
 seek($fh, 32, 0) || die "can't seek to 32: $!";  
 read($fh, $b, 4);  
 printf("%8s %s\n", join('.',unpack('CCCC', $b)), $path);  
17    
18    sub get_from {
19            my ($fh,$seek,$len) = @_;
20            my $b;
21            seek($fh, $seek, 0) || die "can't seek to $seek: $!";
22            read($fh, $b, $len) || die "can't read $len bytes: $!";
23            return $b;
24    }
25    
26    sub firmware {
27            my $path = shift;
28            open(my $fh, $path) || die "Can't open $path: $!";
29            my $b;
30            read($fh, $b, length($magic));
31            if ($b ne $magic) {
32                    warn "# $path not a firmware image\n";
33                    return;
34            }
35            my $version     = get_from($fh, 32, 4);
36            my $board       = get_from($fh, 0x136, 6);
37            my $name        = get_from($fh, 0x144, 15);
38            chomp($name);
39            $name =~ s/\W+/ /gs;
40            $version = join('.',unpack('CCCC', $version));
41            printf("%-8s %6s %-16s %s\n", $version, $board, $name, $path);
42    }
43    
44    for my $path ( @images ) {
45            warn "# ? $path\n" if $debug;
46            if ( -d $path ) {
47                    find( sub {
48                            my $path = $File::Find::name;
49                            warn "# ?? $path\n" if $debug;
50                            firmware( $path ) if -f $path;
51                    }, $path );
52            } elsif ( -f $path ) {
53                    firmware( $path );
54            } else {
55                    warn "# unknown: $path\n";
56            }
57    }

Legend:
Removed from v.21  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.26