]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
made script more save
authorIngo Froehlich <ingo@nomail.fake>
Wed, 8 May 2019 15:44:32 +0000 (17:44 +0200)
committerIngo Froehlich <ingo@nomail.fake>
Wed, 8 May 2019 15:44:32 +0000 (17:44 +0200)
tools/spi_slave.pl

index 985a037637a3be83e56feb1bbb7b643d52e9e09f..7aa866adcf80700b0beeea229dad4a82e50a3145 100755 (executable)
@@ -112,15 +112,15 @@ sub conv_input_string_to_number {
 
 sub usage {
   print <<EOF;
-usage: spi_flash16bit_slaves.pl <--endpoint|e=0xYYYY> <--chain|c=N> [--register=number] [--data=number]
-
-examples: spi_flash16bit_slaves.pl -e 0x1212 -c 0 -x time                       # reads the compile time of 0x1212, chain 0
-          spi_flash16bit_slaves.pl -e 0x1212 -c 0 -x pwm --channel=1            # reads the threshold setting of channel 1
-          spi_flash16bit_slaves.pl -e=0x1212 -c=0 -x=inputenable --data=0xa55a  # disables some channels
-          spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert -d 0xff # sets the dischargedelayinvert bits
-          spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert         # reads the dischargedelayinvert register
-          spi_flash16bit_slaves.pl -e 0x1212 -c 0 --enablecfgflash=1            # enables the access to the config-flash
-          spi_flash16bit_slaves.pl --endpoint=0x1212 --chain=0 --dumpcfgflash > flash_dump.txt
+usage: spi_slave.pl <--endpoint|e=0xYYYY> <--chain|c=N> [--register=number] [--data=number]
+
+examples: spi_slave.pl -e 0x1212 -c 0 -x time                       # reads the compile time of 0x1212, chain 0
+          spi_slave.pl -e 0x1212 -c 0 -x pwm --channel=1            # reads the threshold setting of channel 1
+          spi_slave.pl -e=0x1212 -c=0 -x=inputenable --data=0xa55a  # disables some channels
+          spi_slave.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert -d 0xff # sets the dischargedelayinvert bits
+          spi_slave.pl --endpoint=0x1212 --chain=0 -x dischargedelayinvert         # reads the dischargedelayinvert register
+          spi_slave.pl -e 0x1212 -c 0 --enablecfgflash=1            # enables the access to the config-flash
+          spi_slave.pl --endpoint=0x1212 --chain=0 --dumpcfgflash > flash_dump.txt
           
           Some of the commands can also be used directly, i.e. '-rr=0x12' instead of '-x=rr -register=0x12'
 
@@ -171,6 +171,10 @@ if ($help || !defined $endpoint || !defined $chain) {
   usage();
 }
 
+if (defined $enablecfgflash and (defined $erasecfgflash or defined $dumpcfgflash or defined $writecfgflash or defined $verifycfgflash)) {
+    die("for security reasons is not allowed to enable cfg flash and to use it in one single command");
+}
+
 $endpoint       = &conv_input_string_to_number($endpoint,       "endpoint", "hex");
 $chain          = &conv_input_string_to_number($chain,          "chain");
 $register       = &conv_input_string_to_number($register,       "register")       if (defined $register);
@@ -386,11 +390,27 @@ if (defined $flashcmd) {
 
 ###############################################################################
 
+sub checkcfgflash {
+    my $b = sendcmd(0x5C<<$REGNR | $READ);
+    foreach my $e (sort keys %$b) {
+       printf(" %x ",$b->{$e}&0xfff);
+       if (($b->{$e}&0xfff) ne 0x101) {
+           die "config flash not enabled";
+       }
+    }
+}
+
 sub enableccfgflash {
+    sendcmd(0x51<<$REGNR | $WRITE | 0x8);
+    sendcmd(0x50<<$REGNR | $WRITE | 0x0);
+    sendcmd(0x5C<<$REGNR | $WRITE | 0x103);
+    sendcmd(0x5C<<$REGNR | $WRITE | 0x105);
     sendcmd(0x5C<<$REGNR | $WRITE | 0x101);
 }
 
 sub enableuserflash {
+    sendcmd(0x51<<$REGNR | $WRITE | 0x8);
+    sendcmd(0x50<<$REGNR | $WRITE | 0x0);
     sendcmd(0x5C<<$REGNR | $WRITE | 0x100);
 }
 
@@ -408,7 +428,8 @@ if ($execute eq "enableccfgflash" | defined $enablecfgflash) {
 ###############################################################################
 
 if ($execute eq "dumpcfgflash" | defined $dumpcfgflash) {
-    enableccfgflash();
+    #enableccfgflash();
+    checkcfgflash();
     my $b = sendcmd(0xFF<<$REGNR | $READ);
     my $version = $b->{$endpoint};
     my $max = 0x23ff;
@@ -435,7 +456,8 @@ if ($execute eq "dumpcfgflash" | defined $dumpcfgflash) {
 }
 
 sub erasecfgflash {
-    enableccfgflash();
+    #enableccfgflash();
+    checkcfgflash();
     while (flash_is_busy()) {
        printf(" busy - try again\n");
        usleep(300000);
@@ -450,6 +472,7 @@ if ($execute eq "erasecfgflash" | defined $erasecfgflash) {
 }
 
 if ($execute eq "writecfgflash" | defined $writecfgflash) {
+    checkcfgflash();
     if (!defined($filename)) {$filename=$writecfgflash;}
     if (!defined $filename) {
         die "for the command writecfgflash an option or --filename is missing.\n";
@@ -525,6 +548,7 @@ if ($execute eq "writecfgflash" | defined $writecfgflash) {
 }
 
 if ($execute eq "verifycfgflash" | defined $verifycfgflash) {
+    checkcfgflash();
     printf("Verify with file: %s \n", $filename);
     if (!defined($filename)) {$filename=$verifycfgflash;}
     if (!defined $filename) {