--- fw-info.pl 2007/04/22 14:42:56 5 +++ bin/fw-info.pl 2007/11/18 14:54:00 75 @@ -6,12 +6,51 @@ use strict; use Data::Dump qw/dump/; +use File::Find; -my $path = shift @ARGV || die "Usage: $0 firmware.bin\n"; +my $debug = 0; -open(my $fh, $path) || die "Can't open $path: $!"; -my $ver; -seek($fh, 32, 0) || die "can't seek to 32: $!"; -read($fh, $ver, 5); -print dump( $ver ), dump( unpack 'CCCCC', $ver ),$/; +my @images = @ARGV; +push @images, '/srv/tftp/BANT-R' unless @images; +my $magic = 'BLI223Q'; + +sub get_from { + my ($fh,$seek,$len) = @_; + my $b; + seek($fh, $seek, 0) || die "can't seek to $seek: $!"; + read($fh, $b, $len) || die "can't read $len bytes: $!"; + return $b; +} + +sub firmware { + my $path = shift; + open(my $fh, $path) || die "Can't open $path: $!"; + my $b; + read($fh, $b, length($magic)); + if ($b ne $magic) { + warn "# $path not a firmware image\n"; + return; + } + my $version = get_from($fh, 32, 4); + my $board = get_from($fh, 0x136, 6); + my $name = get_from($fh, 0x144, 15); + chomp($name); + $version = join('.',unpack('CCCC', $version)); + printf("%8s %6s %s\t%s\n", $version, $board, $name, $path); +} + +for my $path ( @images ) { + warn "# ? $path\n" if $debug; + if ( -d $path ) { + find( sub { + my $path = $File::Find::name; + warn "# ?? $path\n" if $debug; + firmware( $path ) if -f $path; + }, $path ); + } elsif ( -f $path ) { + firmware( $path ); + } else { + warn "# unknown: $path\n"; + } +}