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; |
15 |
|
|
16 |
my $magic = 'BLI223QH0'; |
my $magic = 'BLI223Q'; |
17 |
|
|
18 |
sub get_from { |
sub get_from { |
19 |
my ($fh,$seek,$len) = @_; |
my ($fh,$seek,$len) = @_; |
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 |
} |
} |