/[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

revision 73 by dpavlin, Sun Nov 18 14:17:54 2007 UTC revision 74 by dpavlin, Sun Nov 18 14:50:21 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 $debug = 0;
12    
13  my @images = @ARGV;  my @images = @ARGV;
14  push @images, '/srv/tftp/BANT-R' unless @images;  push @images, '/srv/tftp/BANT-R' unless @images;
# Line 20  sub get_from { Line 23  sub get_from {
23          return $b;          return $b;
24  }  }
25    
26  for my $path ( @images ) {  sub firmware {
27          next unless -f $path;          my $path = shift;
28          open(my $fh, $path) || die "Can't open $path: $!";          open(my $fh, $path) || die "Can't open $path: $!";
29          my $b;          my $b;
30          read($fh, $b, length($magic));          read($fh, $b, length($magic));
31          warn "# $path not a firmware image\n" unless ($b eq $magic);          if ($b ne $magic) {
32                    warn "# $path not a firmware image\n";
33                    return;
34            }
35          my $version     = get_from($fh, 32, 4);          my $version     = get_from($fh, 32, 4);
36          my $board       = get_from($fh, 0x136, 6);          my $board       = get_from($fh, 0x136, 6);
37          my $name        = get_from($fh, 0x144, 15);          my $name        = get_from($fh, 0x144, 15);
38          chomp($name);          chomp($name);
39            $version = join('.',unpack('CCCC', $version));
40            printf("%8s %6s %s\t%s\n", $version, $board, $name, $path);
41    }
42    
43          printf("%8s %6s %s\t%s\n", join('.',unpack('CCCC', $version)), $board, $name, $path);  for my $path ( @images ) {
44            warn "# ? $path\n" if $debug;
45            if ( -d $path ) {
46                    find( sub {
47                            my $path = $File::Find::name;
48                            warn "# ?? $path\n" if $debug;
49                            firmware( $path ) if -f $path;
50                    }, $path );
51            } elsif ( -f $path ) {
52                    firmware( $path );
53            } else {
54                    warn "# unknown: $path\n";
55            }
56  }  }

Legend:
Removed from v.73  
changed lines
  Added in v.74

  ViewVC Help
Powered by ViewVC 1.1.26