--- fw-info.pl 2007/04/23 18:04:04 18 +++ fw-info.pl 2007/11/16 23:44:29 59 @@ -7,15 +7,29 @@ use strict; use Data::Dump qw/dump/; -my $path = shift @ARGV || '/srv/tftp/BANT-R'; # die "Usage: $0 firmware.bin\n"; +my @images = @ARGV; +push @images, '/srv/tftp/BANT-R' unless @images; my $magic = 'BLI223QH0'; -open(my $fh, $path) || die "Can't open $path: $!"; -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); -print join('.',unpack('CCCC', $b)),"\t$path\n"; +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; +} +for my $path ( @images ) { + next unless -f $path; + open(my $fh, $path) || die "Can't open $path: $!"; + my $b; + read($fh, $b, length($magic)); + warn "# $path not a firmware image\n" unless ($b eq $magic); + my $version = get_from($fh, 32, 4); + my $board = get_from($fh, 0x136, 6); + my $name = get_from($fh, 0x144, 15); + chomp($name); + + printf("%8s %6s %s\t%s\n", join('.',unpack('CCCC', $version)), $board, $name, $path); +}