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

Contents of /bin/fw-info.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 87 - (show annotations)
Wed Dec 5 23:21:04 2007 UTC (15 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 1202 byte(s)
remove unprintable chars which confuse iselect (sigh!)
1 #!/usr/bin/perl -w
2
3 # fw-info.pl
4 #
5 # 04/22/07 16:33:13 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use strict;
8 use Data::Dump qw/dump/;
9 use File::Find;
10
11 my $debug = 0;
12
13 my @images = @ARGV;
14 push @images, '/srv/tftp/BANT-R' unless @images;
15
16 my $magic = 'BLI223Q';
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 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26