version 1.16, 2007/01/08 16:49:44 |
version 1.21, 2007/02/01 17:08:44 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: update_trango.pl,v 1.15 2005/12/30 20:26:41 andrew Exp $ |
# $RedRiver: update_trango.pl,v 1.20 2007/01/31 22:19:07 mike Exp $ |
######################################################################## |
######################################################################## |
# update_trango.pl *** Updates trango foxes with a new firmware |
# update_trango.pl *** Updates trango foxes with a new firmware |
# |
# |
|
|
use warnings; |
use warnings; |
|
|
use Net::TFTP; |
use Net::TFTP; |
use YAML; |
|
use lib '.'; |
use lib '.'; |
use Net::Telnet::Trango; |
use Net::Telnet::Trango; |
|
|
|
|
Timeout => 5, |
Timeout => 5, |
Errmode => 'return', |
Errmode => 'return', |
) or die "Couldn't make new connection: $!"; |
) or die "Couldn't make new connection: $!"; |
|
|
$l->p("Connecting to $fox"); |
$l->p("Connecting to $fox"); |
unless ( $t->open($fox) ) { |
unless ( $t->open($fox) ) { |
$l->sp("Error connecting: $!"); |
$l->sp("Error connecting: $!"); |
next; |
next; |
} |
} |
|
|
if ($t->host_type ne $conf->{'type'}) { |
my $host_type = $t->host_type; |
$l->sp("Wrong type of unit ('$t->host_type' should be '$conf->{'type'}')"); |
|
|
if (lc($conf->{'firmware_type'}) eq 'fpga') { |
|
$host_type =~ s/\s.*$//; |
|
} |
|
|
|
if ($host_type ne $conf->{'type'}) { |
|
$l->sp("Wrong type of unit ('" . $t->host_type . "' should be '$conf->{'type'}')"); |
$t->close; |
$t->close; |
next; |
next; |
} |
} |
|
|
if ($t->firmware_version eq $conf->{'ver'}) { |
if ($t->firmware_version eq $conf->{'ver'}) { |
$l->sp("Already up to date with firmware version '$t->firmware_version'"); |
$l->sp("Already up to date with firmware version '" . $t->firmware_version . "'"); |
$t->close; |
$t->close; |
next; |
next; |
} |
} |
|
|
|
|
$l->p("Sending commands"); |
$l->p("Sending commands"); |
## Send commands |
## Send commands |
#print Dump $t->login_banner; |
if ( upload($t, $conf->{'file_name'}) ) { |
#print Dump $t->sysinfo; |
$l->p("Rebooting"); |
#print Dump $t->last_lines; |
$t->reboot; |
#print Dump $t->ver(); |
} else { |
#print Dump $t->tftpd(); |
|
#print Dump $t->enable_tftpd(); |
|
#print Dump [ "Exit", $t->exit ]; |
|
#print Dump $t->tftpd(); |
|
#print Dump $t->disable_tftpd(); |
|
#print Dump $t->tftpd(); |
|
print Dump $t->sulog(args => 5); |
|
#if ( upload($t, $conf->{'file_name'}) ) { |
|
# $l->p("Rebooting"); |
|
# $t->reboot; |
|
#} else { |
|
$l->p("Exiting"); |
$l->p("Exiting"); |
$t->exit; |
$t->exit; |
#} |
} |
|
|
$l->sp(""); |
$l->sp(""); |
} |
} |
|
|
my $t = shift; |
my $t = shift; |
my $file = shift; |
my $file = shift; |
|
|
|
my $fw_type = 'Firmware'; |
|
if (uc($conf->{'firmware_type'}) eq 'FPGA') { |
|
$fw_type = 'FPGA'; |
|
} |
|
|
my $ver = $t->ver; |
my $ver = $t->ver; |
$l->p("Current version '$ver->{'Firmware Version'}'"); |
$l->p("Current version '" . $ver->{$fw_type . ' Version'} . "'"); |
|
|
if ( |
if ( |
$ver->{'Firmware Version'} eq $conf->{'ver'} && |
$ver->{$fw_type . ' Version'} eq $conf->{'ver'} && |
$ver->{'Firmware Checksum'} eq $conf->{'cksum'} |
$ver->{$fw_type . ' Checksum'} eq $conf->{'cksum'} |
) { |
) { |
$l->sp("Already updated!"); |
$l->sp("Already updated!"); |
return 1; |
return 0; |
} |
} |
|
|
my $try = 0; |
my $try = 0; |
|
|
# use tftp to push the file up |
# use tftp to push the file up |
my $tftp = Net::TFTP->new($t->Host, Mode => 'octet'); |
my $tftp = Net::TFTP->new($t->Host, Mode => 'octet'); |
|
|
$tftp->put($file, $file) |
unless ($tftp->put($file, $file)) { |
or die "Error uploading: " . $tftp->error; |
print "Error uploading: " . $tftp->error; |
|
next; |
|
} |
|
|
# waitfor some sort of output |
# waitfor some sort of output |
# make sure it says 'Success.' otherwise error |
# make sure it says 'Success.' otherwise error |
|
|
if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) { |
if ( $results->{'File Checksum'} ne $conf->{'file_cksum'}) { |
$l->sp( |
$l->sp( |
"File checksum '" . $results->{'File Checksum'} . |
"File checksum '" . $results->{'File Checksum'} . |
"does not match config file '" . $conf->{'file_cksum'} . "'!" |
" does not match config file '" . $conf->{'file_cksum'} . "'!" |
); |
); |
next; |
next; |
} |
} |
|
|
} |
} |
$l->p("File name matches . . . "); |
$l->p("File name matches . . . "); |
|
|
$l->p("Updating flash (new checksum '$conf->{'cksum'}')"); |
my $image_type = 'mainimage'; |
|
if ($fw_type eq 'FPGA') { |
|
$image_type = 'fpgaimage'; |
|
} |
|
$l->p("Updating $image_type (new checksum '$conf->{'cksum'}')"); |
unless ($results = $t->updateflash( |
unless ($results = $t->updateflash( |
args => 'mainimage ' . $ver->{'Firmware Checksum'} . |
args => $image_type . ' ' . $ver->{$fw_type . ' Checksum'} . |
' ' . $conf->{'cksum'}, |
' ' . $conf->{'cksum'}, |
Timeout => 90, |
Timeout => 90, |
) ) { |
) ) { |
|
|
defined $results->{'Checksum'} && |
defined $results->{'Checksum'} && |
$results->{'Checksum'} eq $conf->{'cksum'} |
$results->{'Checksum'} eq $conf->{'cksum'} |
) { |
) { |
$l->sp("Saved checksum does not match config file!"); |
$l->sp("Saved checksum " . $results->{'Checksum'} . " does not match config file " . $conf->{'cksum'} . "!"); |
next; |
next; |
} |
} |
$l->p("Uploaded checksum ($results->{'Checksum'}) " . |
$l->p("Uploaded checksum ($results->{'Checksum'}) " . |