From 3b99d976eaa40c5ad7387fa9c3f243d41176373a Mon Sep 17 00:00:00 2001 From: Ingo Froehlich Date: Fri, 25 Jan 2019 13:20:50 +0100 Subject: [PATCH] added verify --- tools/spi_slave.pl | 89 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/tools/spi_slave.pl b/tools/spi_slave.pl index 38c7114..985a037 100755 --- a/tools/spi_slave.pl +++ b/tools/spi_slave.pl @@ -35,6 +35,8 @@ my $enablecfgflash; my $dumpcfgflash; my $erasecfgflash; my $writecfgflash; +my $verifycfgflash; +my $verify; my $dumpuserflash; my $writeuserflash; my $rr; @@ -68,6 +70,8 @@ my $result = GetOptions ( "dumpcfgflash" => \$dumpcfgflash, "erasecfgflash" => \$erasecfgflash, "writecfgflash" => \$writecfgflash, + "verifycfgflash" => \$verifycfgflash, + "verifypage" => \$verify, "dumpuserflash:s" => \$dumpuserflash, "writeuserflash:s" => \$writeuserflash, "eraseuserflash" => \$eraseuserflash, @@ -473,12 +477,31 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) { while (my $s = ) { my @t = split(' ',$s); my @a; - for (my $i=0;$i<16;$i++) { - push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff)); - } - sendcmd16(@a); - sendcmd(0x51<<$REGNR | $WRITE | 0x4); - sendcmd(0x50<<$REGNR | $WRITE | $p); + my $ok = 0; + while ($ok eq 0) { + for (my $i=0;$i<16;$i++) { + push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff)); + } + sendcmd16(@a); + + $ok = 1; + #page verify + if (defined($verify)) { + for (my $i=0;$i<16;$i++) { + my $b = sendcmd( (0x40+$i)<<$REGNR | $READ ); + foreach my $e (sort keys %$b) { + if (($b->{$e} & 0xff) ne (hex($t[$i+1]) & 0xff)) { + printf("\nByte %i differs in page %x: %02x %02x -> REDO page\n", $i, $p, $b->{$e}&0xff, hex($t[$i+1]) & 0xff); + $ok = 0; + } + } + } + } + } + + #flash only if RAM ok + sendcmd(0x51<<$REGNR | $WRITE | 0x4); + sendcmd(0x50<<$REGNR | $WRITE | $p); $p++; printf(STDERR "\r%d ",$p) if(!($p%10)); @@ -501,6 +524,60 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) { } } +if ($execute eq "verifycfgflash" | defined $verifycfgflash) { + printf("Verify with file: %s \n", $filename); + if (!defined($filename)) {$filename=$verifycfgflash;} + if (!defined $filename) { + die "for the command verifycfgflash an option or --filename is missing.\n"; + } + if (length($filename)==0) { + die "for the command verifycfgflash an option or --filename is missing.\n"; + } + open(INF, $filename) or die "verifycfgflash: Couldn't read file : $filename\n"; + my $b = sendcmd(0xFF<<$REGNR | $READ); + my $version = $b->{$endpoint}; + if (($version & 0xFF00) eq 0x100) { + printf("Dirich2 threshold FGPA detected.\n"); + } elsif (($version & 0xFF00) eq 0x200) { + printf("Padiwa amps2 detected.\n"); + } else { + die "No valid SPI slave detected"; + } + + my $p = 0; + my $ok = 1; + while (my $s = ) { + my @t = split(' ',$s); + + sendcmd(0x51<<$REGNR | $WRITE | 0x0); + sendcmd(0x50<<$REGNR | $WRITE | $p); # read page $p +# printf("0x%04x:\t",$p); + for (my $i=0;$i<16;$i++) { + my $b = sendcmd( (0x40+$i)<<$REGNR | $READ ); + foreach my $e (sort keys %$b) { + if (($b->{$e} & 0xff) ne (hex($t[$i+1]) & 0xff)) { + printf("\nByte %i differs in page %x: flash: %02x file: %02x\n", $i, $p, $b->{$e}&0xff, hex($t[$i+1]) & 0xff); + $ok = 0; + } + } + } +# printf("\n"); + printf(STDERR "\r%d",$p) if(!($p%10)); + +# my @a;# +# for (my $i=0;$i<16;$i++) { +# push(@a,0x40<<$REGNR | $i << $REGNR | $WRITE | (hex($t[$i+1]) & 0xff)); +# } + + $p++; + } + if ($ok eq 0) { + printf("\nVerification failed!!!\n"); + } else { + printf("\nVerification OK\n"); + } +} + ############################################################################### sub eraseuserflash { -- 2.43.0