Commit 9aae160ad1d86dd101898ba956fde58c5b77b20f

Authored by Brice Colombier
1 parent 1aaf7d0ed1
Exists in master

Application working

Showing 20 changed files with 102 additions and 1997 deletions

... ... @@ -13,4 +13,8 @@
13 13 wrapper/ref_working/work/
14 14 *.wlf
15 15 *.ini
  16 +*.spec
  17 +dist/
  18 +build/
  19 +wrapper/*.vhd
AW_decoder/AW_decoder.vhd View file @ 9aae160
... ... @@ -4,7 +4,7 @@
4 4 ENTITY AW_decoder IS
5 5  
6 6 PORT (
7   - formatted_AW : IN STD_LOGIC_VECTOR(0 TO 3);
  7 + formatted_AW : IN STD_LOGIC_VECTOR(0 TO 15);
8 8 AW : OUT STD_LOGIC_VECTOR(0 TO 7));
9 9  
10 10 END ENTITY AW_decoder;
11 11  
12 12  
... ... @@ -13,20 +13,20 @@
13 13  
14 14 BEGIN
15 15  
16   - -- Formatted AW: 1011
  16 + -- Formatted AW: 0111001101010110
17 17 -- AW: 10100011
18 18  
19 19 -- Mask ORs
20   - AW(1) <= formatted_AW(1);
21   - AW(3) <= formatted_AW(1);
22   - AW(4) <= formatted_AW(1);
23   - AW(5) <= formatted_AW(1);
  20 + AW(1) <= formatted_AW(15) OR formatted_AW(5);
  21 + AW(3) <= formatted_AW(10) OR formatted_AW(8);
  22 + AW(4) <= formatted_AW(4) OR formatted_AW(12);
  23 + AW(5) <= formatted_AW(0);
24 24  
25 25 -- Mask ANDs
26   - AW(0) <= formatted_AW(0);
27   - AW(2) <= formatted_AW(2);
28   - AW(6) <= formatted_AW(3);
29   - AW(7) <= formatted_AW(0);
  26 + AW(0) <= formatted_AW(9) AND formatted_AW(13) AND formatted_AW(14);
  27 + AW(2) <= formatted_AW(3) AND formatted_AW(11);
  28 + AW(6) <= formatted_AW(1) AND formatted_AW(6);
  29 + AW(7) <= formatted_AW(7) AND formatted_AW(2);
30 30  
31 31 END ARCHITECTURE rtl;
AW_decoder/gen_AW_decoder.py View file @ 9aae160
... ... @@ -115,7 +115,7 @@
115 115 """
116 116  
117 117 path = "./user_space/"
118   -
  118 + # path = "./"
119 119 locking_word = ""
120 120 masking_word = ""
121 121 if locking:
122 122  
... ... @@ -234,11 +234,11 @@
234 234 if __name__ == "__main__":
235 235 # print gen_AW_decoder("0101 1100", 16, locking=True, masking=True)
236 236 # print gen_AW_decoder("01011100", 16, locking=True, masking=False)
237   - # print gen_AW_decoder("01011100", 16, locking=False, masking=True)
  237 + print gen_AW_decoder("01011100", 16, locking=False, masking=True)
238 238 # print gen_AW_decoder("0101 1100", 8, locking=True, masking=True)
239 239 # print gen_AW_decoder("01011100", 8, locking=True, masking=False)
240 240 # print gen_AW_decoder("01011100", 8, locking=False, masking=True)
241 241 # print gen_AW_decoder("0101 1100", 4, locking=True, masking=True)
242 242 # print gen_AW_decoder("01011100", 4, locking=True, masking=False)
243   - print gen_AW_decoder("01011100", 4, locking=False, masking=True)
  243 + # print gen_AW_decoder("01011100", 4, locking=False, masking=True)
CASCADE/cascade.py View file @ 9aae160
... ... @@ -69,6 +69,7 @@
69 69 else:
70 70 if passe > 0:
71 71 even_parity_blocks.append(indices[block_index])
  72 + print "Blocks to correct", blocks_to_correct
72 73 if blocks_to_correct:
73 74 while len(blocks_to_correct[0]) > 2:
74 75 reference_response_to_correct, blocks_to_correct = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager, len(reference_response)*4)
... ... @@ -82,6 +83,7 @@
82 83 even_parity_blocks.extend(indices)
83 84 indices = fl.flatten(indices)
84 85 reference_response = fl.flatten(reference_response)
  86 + print "Indices to flip", indices_to_flip
85 87 if blocks_to_correct:
86 88 # Error correction step
87 89 fb.flip_bits(reference_response, indices_to_flip, indices)
... ... @@ -12,6 +12,11 @@
12 12 return ciphertext
13 13  
14 14 if __name__ == "__main__":
15   - print otp("0000000000000000", "0000000001111111")
  15 + plaintext = bin(int("CEDBCE851A6BFC6E19711E8B17C1B47C", 16))[2:].zfill(128)
  16 + key = bin(int("44444444444444444444444444444444", 16))[2:].zfill(128)
  17 + print plaintext
  18 + print key
  19 + print hex(int(otp(plaintext, key), 2)).upper()[2:-1]
  20 + print otp(plaintext, key)
16 21  
add_frame_elements.py View file @ 9aae160
... ... @@ -372,9 +372,11 @@
372 372 command=self.open_activation_word)
373 373 self.search_activation_word_button.grid(row=0, column=2)
374 374 self.encrypt_activation_word_button = Button(self.activation_word_encryption_frame,
375   - text="Encrypt Activation word")
  375 + text="Encrypt Activation word",
  376 + command = self.encrypt_activation_word)
376 377 self.encrypt_activation_word_button.grid(row=1)
377 378 self.start_activation_process_button = Button(self.activation_process_frame,
378   - text="Start activation process")
  379 + text="Start activation process",
  380 + command=self.start_activation_process)
379 381 self.start_activation_process_button.pack(side=LEFT)
... ... @@ -8,6 +8,8 @@
8 8 # File: app.py
9 9 # Date: 2016-10-13
10 10  
  11 +import igraph.vendor.texttable
  12 +
11 13 import random
12 14  
13 15 import tkFileDialog
... ... @@ -51,6 +53,8 @@
51 53  
52 54 from activable_design.generate_activable_design import generate_activable_design
53 55  
  56 +from OTP.otp import otp
  57 +
54 58 class App:
55 59  
56 60 """Main class for the demonstrator GUI app"""
... ... @@ -94,8 +98,8 @@
94 98 # Activation frame
95 99 self.setState(self.CASCADE_frame, state = "disabled")
96 100 self.setState(self.key_derivation_frame, state = "disabled")
97   - self.setState(self.activation_word_encryption_frame, state = "disabled")
98   - self.setState(self.activation_process_frame, state = "disabled")
  101 + # self.setState(self.activation_word_encryption_frame, state = "disabled")
  102 + # self.setState(self.activation_process_frame, state = "disabled")
99 103 # Enrolment frame
100 104 self.setState(self.get_PUF_response_frame, state = "disabled")
101 105  
... ... @@ -187,7 +191,7 @@
187 191 else:
188 192 self.server_reference_response = str(line[20:])
189 193 self.server_reference_response_displayed.set(self.server_reference_response)
190   - self.server_reference_response = response_converter_to_bin_list(self.server_reference_response)[::-1]
  194 + self.server_reference_response = response_converter_to_bin_list(self.server_reference_response)#[::-1]
191 195 self.update_status("")
192 196 if self.connected.get() == True:
193 197 self.setState(self.CASCADE_frame, state = "normal")
... ... @@ -204,7 +208,6 @@
204 208 self.update_status("The file could not be parsed as an Activation Word file")
205 209 else:
206 210 self.activation_word.set(line)
207   - print self.activation_word.get()
208 211  
209 212 def open_associated_activation_word(self):
210 213 self.update_status("")
... ... @@ -297,6 +300,7 @@
297 300 self.connected.set(False)
298 301 else: # Connection successful
299 302 self.com_port_button_connect.configure(state="disabled")
  303 + self.com_port_button_reset.configure(state="normal")
300 304 self.com_port_button_disconnect.configure(state="normal")
301 305 self.connected.set(True)
302 306 self.board_status.set("Board Connected")
... ... @@ -309,6 +313,7 @@
309 313 try:
310 314 self.tcl_obj.eval(self.board_manager.disconnect())
311 315 self.com_port_button_disconnect.configure(state="disabled")
  316 + self.com_port_button_reset.configure(state="disabled")
312 317 self.com_port_button_connect.configure(state="normal")
313 318 self.connected.set(False)
314 319 self.board_status.set("Board not connected")
... ... @@ -362,8 +367,8 @@
362 367 self.master.config(cursor="")
363 368 self.master.update()
364 369  
365   - print self.locking_inputs
366   - print self.masking_inputs
  370 + # print self.locking_inputs
  371 + # print self.masking_inputs
367 372  
368 373 def derive_key_from_response(self):
369 374 self.update_status("")
... ... @@ -421,7 +426,7 @@
421 426 filename[1] = "txt"
422 427 filename = ".".join(filename)
423 428 filename = "/".join(self.modified_design_to_wrap.get().split("/")[:-1])+"/"+filename
424   - print filename
  429 + # print filename
425 430 with open(filename, "w") as aw_file:
426 431 aw_file.write("Formatted Activation Word\n"+self.formatted_AW)
427 432 self.update_status(str("Formatted activation word saved under "+filename))
... ... @@ -472,7 +477,7 @@
472 477 def perform_reconciliation(self):
473 478 self.update_status("")
474 479 self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
475   - self.tcl_obj.eval(self.board_manager.generate_response())
  480 + print self.tcl_obj.eval(self.board_manager.generate_response())
476 481 server_before = self.server_reference_response
477 482 self.server_reference_response = cascade(self.server_reference_response,
478 483 0.02,
... ... @@ -481,10 +486,22 @@
481 486 self.board_manager,
482 487 int(self.reconciliation_parameter_initial_block_size_spinbox.get()))
483 488 server_after = self.server_reference_response
484   - print "Befor :", server_before
485   - print "After :", server_after
486   - print "Diffs :", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
487   - print ("Reconciliation done")
  489 + print "Errors corrected :", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
  490 + self.status.set("Reconciliation done")
  491 +
  492 + def encrypt_activation_word(self):
  493 + ref_rep = "".join([str(i) for i in self.server_reference_response])[::-1]
  494 + self.encrypted_AW = otp(self.activation_word.get(), ref_rep) #binary
  495 + self.encrypted_AW = hex(int(self.encrypted_AW, 2))[2:-1].upper()
  496 + encrypted_AW_file_name = self.activation_word_file.replace("formatted", "encrypted")
  497 + with open(encrypted_AW_file_name, "w") as encrypted_AW_file:
  498 + encrypted_AW_file.write(self.encrypted_AW)
  499 + self.status.set("Encrypted AW saved under "+encrypted_AW_file_name)
  500 +
  501 + def start_activation_process(self):
  502 + print self.encrypted_AW
  503 + print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
  504 + self.status.set("Activation done")
488 505  
489 506 def update_status(self, text):
490 507 self.status.set(text)
boards_management/board_commands.py View file @ 9aae160
... ... @@ -85,7 +85,19 @@
85 85 command+="return [string reverse [string range [string reverse $par] 0 "+str(int(math.ceil((nb_blocks-1)/4)))+"]]"
86 86 return command
87 87  
  88 + def activate_design(self, encrypted_AW):
  89 + command = "set puf_mode 4\n"
  90 + command+="set mb2db_words 2\n"
  91 + command+="set db2mb_words 0\n"
88 92  
  93 + command+="set data \"[fromHEX {"+encrypted_AW[:len(encrypted_AW)/2]+"}]\n"
  94 + command+="[fromHEX {"+encrypted_AW[len(encrypted_AW)/2:]+"}]\"\n"
  95 +
  96 + command+="set ret [sendPufData $dev $puf_mode $mb2db_words $db2mb_words $data 0]\n"
  97 + command+="set status [lindex $ret 0]\n"
  98 + command+="return $status"
  99 +
  100 + return command
89 101  
90 102 def disconnect(self):
91 103 command = "disconnect $dev\n"
boards_management_back/HECTOR_data_acq.tcl View file @ 9aae160
1   -##############################################################################
2   -#
3   -# Design unit: HECTOR TCL language extension
4   -#
5   -# File name: HECTOR_data_acq.tcl
6   -#
7   -# Description: TCL language extension providing high-level access to
8   -# communication interface with HECTOR evaluation boards.
9   -#
10   -# System: TCL v. 8.5 and higher
11   -#
12   -# Author: O. Petura - Hubert Curien Laboratory
13   -#
14   -# Copyright: Hubert Curien Laboratory, 2016
15   -#
16   -# Revision: Version 1.00, April 2016
17   -#
18   -##############################################################################
19   -
20   -
21   -# Timeout for the UART response in seconds
22   -set UART_timeout 5
23   -
24   -# Timeout between two consequent checks of UART input buffer
25   -set uart_check_timeout 100
26   -
27   -# Opens a connection to HECTOR evaluation board
28   -proc openDevice {dev {baudrate 460800} {verbose 0}} {
29   -
30   - global tcl_platform
31   -
32   -# Append \\.\ to serial port number when we are running on Windows
33   - if {[string first "Win" $tcl_platform(os)] != -1} {
34   - set dev "\\\\.\\$dev"
35   - }
36   -
37   -# Open the serial device
38   - if { [catch { open $dev "r+" } fd ] } {
39   - if {$verbose != 0} {
40   - puts "Error opening device '$dev'\n Error description: $::errorInfo"
41   - }
42   - puts "Error opening device '$dev'"
43   - set ret -1
44   - } else {
45   -# Configure communication parameters
46   - fconfigure $fd -blocking 0 -buffering none -mode "$baudrate,n,8,1" -translation binary -eofchar {}
47   -
48   -# Update the application status
49   - puts "Connection to '$dev' opened"
50   -
51   -# Create device handle
52   - set ret [list $dev $fd]
53   -
54   - }
55   -
56   - return $ret
57   -
58   -}
59   -
60   -# Disconnect from the HECTOR evaluation board
61   -proc disconnect {device} {
62   -
63   -# Close the connection to the serial device
64   - close [lindex $device 1]
65   -
66   -# Update the application status
67   - puts "Connection to '[lindex $device 0]' closed"
68   -}
69   -
70   -# Poll the serial device for input data
71   -proc pollDevice {device {verbose 0}} {
72   -
73   -# Read the input serial buffer
74   - set data [read [lindex $device 1]]
75   -
76   -# If there is something, process it
77   - if {[string length $data] != 0} {
78   - if {$verbose != 0} {
79   - puts "Received data: [binToHEX $data]"
80   - }
81   -
82   -# Get the MSS status packet header offset
83   - set offset [string first "\x13\x57\x00\x00" $data]
84   - if {$offset != -1} {
85   -# Get the status fields
86   - set response [string range $data [expr $offset + 11] [expr $offset + 11]]
87   - set progress [string range $data [expr $offset + 8] [expr $offset + 8]]
88   - set aq_state [string range $data [expr $offset + 9] [expr $offset + 9]]
89   - set gpio [string range $data [expr $offset + 10] [expr $offset + 10]]
90   -
91   - binary scan $response c1 ret(response)
92   - binary scan $progress c1 ret(progress)
93   - binary scan $aq_state c1 ret(aq_state)
94   - set ret(gpio) [binToHEX $gpio]
95   - return [list $ret(response) $ret(progress) $ret(aq_state) $ret(gpio)]
96   - } else {
97   -
98   -# Get the FPGA status packet header offset
99   - set offset [string first "\x13\xF5\x00\x00" $data]
100   - if {$offset != -1} {
101   -# Get the status fields
102   - set fpga_data [string range $data [expr $offset + 4] [expr $offset + 7]]
103   - set fpga_status [string range $data [expr $offset + 8] [expr $offset + 11]]
104   -
105   - set ret(fpga_data) [binToHEX $fpga_data]
106   - set ret(fpga_status) [binToHEX $fpga_status]
107   - return [list $ret(fpga_status) $ret(fpga_data)]
108   - }
109   - }
110   - } else {
111   - set ret(response) -1
112   - set ret(appError) 1
113   - return [list $ret(response) $ret(appError)]
114   - }
115   -
116   -}
117   -
118   -# Wait for a specified time
119   -proc wait_ms {ms} {
120   -
121   -# Create a variable name
122   - set varName finished_[clock clicks]
123   - global $varName
124   -
125   -# Set the variable after a specified timeout
126   - after $ms set $varName 1
127   -
128   -# Wait for the variable to be set
129   - vwait $varName
130   -
131   -# Clear the variable from memory
132   - unset $varName
133   -}
134   -
135   -# Convert a binary string to HEX
136   -proc binToHEX {in} {
137   - set ret ""
138   - for {set i 0} {$i < [string length $in]} {incr i} {
139   - binary scan [string index $in $i] c1 byte
140   - if {$byte < 0} {set byte [expr 256 + $byte]}
141   - set HI [expr $byte >> 4]
142   - set LO [expr $byte & 15]
143   - switch $HI {
144   - 0 {append ret "0"}
145   - 1 {append ret "1"}
146   - 2 {append ret "2"}
147   - 3 {append ret "3"}
148   - 4 {append ret "4"}
149   - 5 {append ret "5"}
150   - 6 {append ret "6"}
151   - 7 {append ret "7"}
152   - 8 {append ret "8"}
153   - 9 {append ret "9"}
154   - 10 {append ret "A"}
155   - 11 {append ret "B"}
156   - 12 {append ret "C"}
157   - 13 {append ret "D"}
158   - 14 {append ret "E"}
159   - 15 {append ret "F"}
160   - }
161   - switch $LO {
162   - 0 {append ret "0"}
163   - 1 {append ret "1"}
164   - 2 {append ret "2"}
165   - 3 {append ret "3"}
166   - 4 {append ret "4"}
167   - 5 {append ret "5"}
168   - 6 {append ret "6"}
169   - 7 {append ret "7"}
170   - 8 {append ret "8"}
171   - 9 {append ret "9"}
172   - 10 {append ret "A"}
173   - 11 {append ret "B"}
174   - 12 {append ret "C"}
175   - 13 {append ret "D"}
176   - 14 {append ret "E"}
177   - 15 {append ret "F"}
178   - }
179   - }
180   - return $ret
181   -}
182   -
183   -# Convert DEC to HEX
184   -proc toHEX {in} {
185   - set ret ""
186   - set dec $in
187   - while { $dec > 0 } {
188   - set rest [expr $dec % 16]
189   - switch $rest {
190   - 0 {set ret "0$ret"}
191   - 1 {set ret "1$ret"}
192   - 2 {set ret "2$ret"}
193   - 3 {set ret "3$ret"}
194   - 4 {set ret "4$ret"}
195   - 5 {set ret "5$ret"}
196   - 6 {set ret "6$ret"}
197   - 7 {set ret "7$ret"}
198   - 8 {set ret "8$ret"}
199   - 9 {set ret "9$ret"}
200   - 10 {set ret "A$ret"}
201   - 11 {set ret "B$ret"}
202   - 12 {set ret "C$ret"}
203   - 13 {set ret "D$ret"}
204   - 14 {set ret "E$ret"}
205   - 15 {set ret "F$ret"}
206   - }
207   - set dec [expr $dec / 16]
208   - }
209   - return $ret
210   -}
211   -
212   -# Function to convert HEX to DEC
213   -proc fromHEX {in} {
214   - set in_end [expr [string length $in] - 1]
215   - set ret 0
216   - for {set i $in_end} {$i >= 0} {incr i -1} {
217   - switch [string index $in $i] {
218   - "0" {set val 0}
219   - "1" {set val 1}
220   - "2" {set val 2}
221   - "3" {set val 3}
222   - "4" {set val 4}
223   - "5" {set val 5}
224   - "6" {set val 6}
225   - "7" {set val 7}
226   - "8" {set val 8}
227   - "9" {set val 9}
228   - "A" {set val 10}
229   - "B" {set val 11}
230   - "C" {set val 12}
231   - "D" {set val 13}
232   - "E" {set val 14}
233   - "F" {set val 15}
234   - }
235   - set ret [expr $ret + ($val * (16**($in_end - $i)))]
236   - }
237   - return $ret
238   -}
239   -
240   -# Function to read bit value from a specific bit field in decimal value
241   -proc getBitValue {decNumber bitFieldIndex} {
242   - return [expr ( $decNumber & (2**$bitFieldIndex) ) >> $bitFieldIndex]
243   -}
244   -
245   -##############
246   -## COMMANDS ##
247   -##############
248   -
249   -proc getStatus {device {verbose 0}} {
250   - global UART_timeout
251   - global uart_check_timeout
252   -
253   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07"
254   - puts -nonewline [lindex $device 1] $data
255   - if {$verbose != 0} {
256   - puts "Sending: [binToHEX $data]"
257   - }
258   -
259   - set resp "-1 1"
260   - set start [clock seconds]
261   - while { [string match $resp "-1 1"] } {
262   - set resp [pollDevice $device $verbose]
263   - if { [clock seconds] > [expr $start + $UART_timeout] } {
264   - break
265   - }
266   - wait_ms $uart_check_timeout
267   - }
268   - set st1 $resp
269   -
270   - set data "\x13\xFB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
271   - puts -nonewline [lindex $device 1] $data
272   - if {$verbose != 0} {
273   - puts "Sending: [binToHEX $data]"
274   - }
275   -# Return the response of the command
276   - set resp "-1 1"
277   - set start [clock seconds]
278   - while { [string match $resp "-1 1"] } {
279   - set resp [pollDevice $device $verbose]
280   - if { [clock seconds] > [expr $start + $UART_timeout] } {
281   - break
282   - }
283   - wait_ms $uart_check_timeout
284   - }
285   - set st2 $resp
286   -
287   - set status [list [lindex $st1 0] [lindex $st1 1] [lindex $st1 2] [lindex $st1 3] [lindex $st2 0] [lindex $st2 1]]
288   -
289   - return $status
290   -}
291   -
292   -proc sendFabricCommand {device command data {verbose 0}} {
293   - global UART_timeout
294   - global uart_check_timeout
295   -
296   - set data "\x13\xFB\x00\x00[binary format I1 $data][binary format I1 $command]"
297   - puts -nonewline [lindex $device 1] $data
298   - if {$verbose != 0} {
299   - puts "Sending: [binToHEX $data]"
300   - }
301   -# Return the response of the command
302   - set resp "-1 1"
303   - set start [clock seconds]
304   - while { [string match $resp "-1 1"] } {
305   - set resp [pollDevice $device $verbose]
306   - if { [clock seconds] > [expr $start + $UART_timeout] } {
307   - break
308   - }
309   - wait_ms $uart_check_timeout
310   - }
311   - return $resp
312   -}
313   -
314   -proc sendFabricReset {device {verbose 0}} {
315   - global UART_timeout
316   - global uart_check_timeout
317   -
318   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"
319   - puts -nonewline [lindex $device 1] $data
320   - if {$verbose != 0} {
321   - puts "Sending: [binToHEX $data]"
322   - }
323   -# Return the response of the command
324   - set resp "-1 1"
325   - set start [clock seconds]
326   - while { [string match $resp "-1 1"] } {
327   - set resp [pollDevice $device $verbose]
328   - if { [clock seconds] > [expr $start + $UART_timeout] } {
329   - break
330   - }
331   - wait_ms $uart_check_timeout
332   - }
333   - return $resp
334   -}
335   -
336   -proc sendDaughterReset {device {verbose 0}} {
337   - global UART_timeout
338   - global uart_check_timeout
339   -
340   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05"
341   - puts -nonewline [lindex $device 1] $data
342   - if {$verbose != 0} {
343   - puts "Sending: [binToHEX $data]"
344   - }
345   -# Return the response of the command
346   - set resp "-1 1"
347   - set start [clock seconds]
348   - while { [string match $resp "-1 1"] } {
349   - set resp [pollDevice $device $verbose]
350   - if { [clock seconds] > [expr $start + $UART_timeout] } {
351   - break
352   - }
353   - wait_ms $uart_check_timeout
354   - }
355   - return $resp
356   -}
357   -
358   -proc mountDisk {device {verbose 0}} {
359   - global UART_timeout
360   - global uart_check_timeout
361   -
362   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06"
363   - puts -nonewline [lindex $device 1] $data
364   - if {$verbose != 0} {
365   - puts "Sending: [binToHEX $data]"
366   - }
367   -# Return the response of the command
368   - set resp "-1 1"
369   - set start [clock seconds]
370   - while { [string match $resp "-1 1"] } {
371   - set resp [pollDevice $device $verbose]
372   - if { [clock seconds] > [expr $start + $UART_timeout] } {
373   - break
374   - }
375   - wait_ms $uart_check_timeout
376   - }
377   - return $resp
378   -}
379   -
380   -proc createFileSystem {device {verbose 0}} {
381   - global UART_timeout
382   - global uart_check_timeout
383   -
384   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08"
385   - puts -nonewline [lindex $device 1] $data
386   - if {$verbose != 0} {
387   - puts "Sending: [binToHEX $data]"
388   - }
389   -# Return the response of the command
390   - set resp "-1 1"
391   - set start [clock seconds]
392   - while { [string match $resp "-1 1"] } {
393   - set resp [pollDevice $device $verbose]
394   - if { [clock seconds] > [expr $start + $UART_timeout] } {
395   - break
396   - }
397   - wait_ms $uart_check_timeout
398   - }
399   - return $resp
400   -}
401   -
402   -proc beginAcquisition {device filename size {verbose 0}} {
403   - global UART_timeout
404   - global uart_check_timeout
405   -
406   - set data "\x13\xFD\x00\x00$filename [binary format I1 $size]"
407   - puts -nonewline [lindex $device 1] $data
408   - if {$verbose != 0} {
409   - puts "Sending command: [binToHEX $data]"
410   - }
411   -# Return the response of the command
412   - set resp "-1 1"
413   - set start [clock seconds]
414   - while { [string match $resp "-1 1"] } {
415   - set resp [pollDevice $device $verbose]
416   - if { [clock seconds] > [expr $start + $UART_timeout] } {
417   - break
418   - }
419   - wait_ms $uart_check_timeout
420   - }
421   - return $resp
422   -}
423   -
424   -proc loadInputFile {device filename size {verbose 0}} {
425   - global UART_timeout
426   - global uart_check_timeout
427   -
428   - set data "\x13\x3D\x00\x00$filename [binary format I1 $size]"
429   - puts -nonewline [lindex $device 1] $data
430   - if {$verbose != 0} {
431   - puts "Sending command: [binToHEX $data]"
432   - }
433   -# Return the response of the command
434   - set resp "-1 1"
435   - set start [clock seconds]
436   - while { [string match $resp "-1 1"] } {
437   - set resp [pollDevice $device $verbose]
438   - if { [clock seconds] > [expr $start + $UART_timeout] } {
439   - break
440   - }
441   - wait_ms $uart_check_timeout
442   - }
443   - return $resp
444   -}
445   -
446   -proc configureGPIO {device GPIO {verbose 0}} {
447   - global UART_timeout
448   - global uart_check_timeout
449   -
450   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x09"
451   - puts -nonewline [lindex $device 1] $data
452   - if {$verbose != 0} {
453   - puts "Sending command: [binToHEX $data]"
454   - }
455   -# Return the response of the command
456   - set resp "-1 1"
457   - set start [clock seconds]
458   - while { [string match $resp "-1 1"] } {
459   - set resp [pollDevice $device $verbose]
460   - if { [clock seconds] > [expr $start + $UART_timeout] } {
461   - break
462   - }
463   - wait_ms $uart_check_timeout
464   - }
465   - return $resp
466   -}
467   -
468   -proc setGPIO {device GPIO {verbose 0}} {
469   - global UART_timeout
470   - global uart_check_timeout
471   -
472   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x0A"
473   - puts -nonewline [lindex $device 1] $data
474   - if {$verbose != 0} {
475   - puts "Sending command: [binToHEX $data]"
476   - }
477   -# Return the response of the command
478   - set resp "-1 1"
479   - set start [clock seconds]
480   - while { [string match $resp "-1 1"] } {
481   - set resp [pollDevice $device $verbose]
482   - if { [clock seconds] > [expr $start + $UART_timeout] } {
483   - break
484   - }
485   - wait_ms $uart_check_timeout
486   - }
487   - return $resp
488   -}
489   -
490   -proc softReset {device {verbose 0}} {
491   - global UART_timeout
492   - global uart_check_timeout
493   -
494   - set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0B"
495   - puts -nonewline [lindex $device 1] $data
496   - if {$verbose != 0} {
497   - puts "Sending command: [binToHEX $data]"
498   - }
499   -# Return the response of the command
500   - set resp "-1 1"
501   - set start [clock seconds]
502   - while { [string match $resp "-1 1"] } {
503   - set resp [pollDevice $device $verbose]
504   - if { [clock seconds] > [expr $start + $UART_timeout] } {
505   - break
506   - }
507   - wait_ms $uart_check_timeout
508   - }
509   - return $resp
510   -}
511   -
512   -# board =
513   -# 1 - HDMI
514   -# 2 - SATA
515   -proc selectDaughterBoard {device board {verbose 0}} {
516   - global UART_timeout
517   - global uart_check_timeout
518   -
519   - if { $board == 1 } {
520   - set command 2
521   - } elseif { $board == 2 } {
522   - set command 3
523   - } else {
524   - set command 0
525   - }
526   - set data "\x13\xFB\x00\x00\x00\x00\x00\x00[binary format I1 $command]"
527   - puts -nonewline [lindex $device 1] $data
528   - if {$verbose != 0} {
529   - puts "Sending command: [binToHEX $data]"
530   - }
531   -# Return the response of the command
532   - set resp "-1 1"
533   - set start [clock seconds]
534   - while { [string match $resp "-1 1"] } {
535   - set resp [pollDevice $device $verbose]
536   - if { [clock seconds] > [expr $start + $UART_timeout] } {
537   - break
538   - }
539   - wait_ms $uart_check_timeout
540   - }
541   - return $resp
542   -}
543   -
544   -###########################
545   -## Application functions ##
546   -###########################
547   -
548   -# Find the connected disk drives
549   -proc findDiskDrives {} {
550   - global tcl_platform
551   -
552   - set drives ""
553   -
554   - if {[string match $tcl_platform(os) "Linux"]} {
555   - if { [catch {exec blkid} disks] } {
556   - puts "blkid is not available. Automatic disk recognition is impossible."
557   - return -1
558   - } else {
559   - set disks [split $disks "\n"]
560   - foreach disk $disks {
561   - set uuid_offset [string first "UUID=" $disk]
562   - set device [string range $disk 0 [expr [string first ":" $disk] - 1]]
563   -# Get the mountpoint
564   - set mountpoint ""
565   - set f [open "/proc/mounts" "r"]
566   - while { [gets $f line] >= 0} {
567   - if {[string first $device $line] != -1} {
568   - set mountpoint [lindex $line 1]
569   - break
570   - }
571   - }
572   - close $f
573   -
574   - if { $uuid_offset != -1 } {
575   - set uuidStart [expr $uuid_offset + 5]
576   - set uuidEnd [string first "\"" $disk [expr $uuidStart + 1]]
577   - set uuidString [string range $disk [expr $uuidStart + 1] [expr $uuidEnd - 1]]
578   - lappend drives [list $device $uuidString $mountpoint]
579   - }
580   - }
581   - }
582   - } elseif {[string first "Win" $tcl_platform(os)] != -1} {
583   - set disks [file volumes]
584   - foreach disk $disks {
585   - set disk [string range $disk 0 end-1]
586   - if {[catch {exec cmd /c vol $disk} resp]} {
587   - continue
588   - } else {
589   - set disk [string range $disk 0 end-1]
590   - set uuidString [string range $resp end-8 end]
591   - lappend drives [list $disk $uuidString "$disk:/"]
592   - }
593   - }
594   - } else {
595   - puts "Only linux and windows platforms are supported for the moment"
596   - return -1
597   - }
598   -
599   - return $drives
600   -}
601   -
602   -# Find HECTOR disk
603   -proc findHECTOR {{timeout 5}} {
604   - set start [clock seconds]
605   - set hectorDrive 0
606   -
607   - while { $hectorDrive == 0 && [expr [clock seconds] - $start] < $timeout} {
608   - set disks [findDiskDrives]
609   - foreach disk $disks {
610   - if { [string match "48A1-0000" [lindex $disk 1]] } {
611   - set hectorDrive $disk
612   - break
613   - }
614   - }
615   - wait_ms 100
616   - }
617   - return $hectorDrive
618   -}
619   -
620   -# Sync filesystem
621   -proc syncDrives {} {
622   - global tcl_platform
623   -
624   - if {[string match $tcl_platform(os) "Linux"]} {
625   - if { [catch {exec sync} ret] } {
626   - puts "Disk sync failed."
627   - return -1
628   - } else {
629   - return 0
630   - }
631   - } elseif {[string first "Win" $tcl_platform(os)] != -1} {
632   - if { [catch {exec "sync.exe"} ret] } {
633   - puts "Disk sync failed."
634   - return -1
635   - } else {
636   - return 0
637   - }
638   - } else {
639   - puts "Only linux and windows platforms are supported for the moment"
640   - return -1
641   - }
642   -}
643   -
644   -proc acquireData {device filename filesize {interface 0} {debug 0}} {
645   - global tcl_platform
646   -
647   -
648   -# Reset the FPGA controller
649   - set err [softReset $device $debug]
650   - if {[lindex $err 0] != 0} {
651   - puts "Soft reset failed with code $err"
652   - return $err
653   - }
654   -
655   -# Set the right interface
656   -# 0 = SATA
657   -# 1 = HDMI
658   - if { $interface == 0 } {
659   - set err [sendFabricCommand $device 3]
660   - if { [lindex $err 0] != 0 } {
661   - puts "Interface set error. Code: $err"
662   - }
663   - } elseif { $interface == 1 } {
664   - set err [sendFabricCommand $device 4]
665   - if { [lindex $err 0] != 0 } {
666   - puts "Interface set error. Code: $err"
667   - }
668   - }
669   -
670   -# Reset the daugther module
671   - set err [sendDaughterReset $device $debug]
672   - if {[lindex $err 0] != 0} {
673   - puts "Daughter reset failed with code $err"
674   - return $err
675   - }
676   -
677   -# Create filesystem
678   - set err [createFileSystem $device $debug]
679   - if {[lindex $err 0] != 0 } {
680   - puts "Filesystem creation failed with code $err"
681   - return $err
682   - }
683   -
684   -## Create a progressbar
685   -# set progressbar {[=====|=====|=====|=====]}
686   -# puts $progressbar
687   -# set progressStep [expr 100.0 / ([string length $progressbar] - 2)]
688   -
689   -# Start the measurement
690   - set err [beginAcquisition $device ACQ $filesize]
691   - if {[lindex $err 0] != 0 } {
692   - puts "Acquisition failed to start. Error code: $err"
693   - return $err
694   - }
695   -
696   -# set progress 0
697   -# puts -nonewline {[}
698   -# flush stdout
699   - while {[lindex $err 2] != 0} {
700   - set err [getStatus $device $debug]
701   - if {[lindex $err 0] != 0 } {
702   - puts "An error occured during data acquisition. Error code: $err"
703   - return $err
704   - } else {
705   - puts -nonewline "[lindex $err 1] %\r"
706   - flush stdout
707   - #if { [lindex $err 1] > $progress } {
708   - # set steps [expr ([lindex $err 1] - $progress) / $progressStep]
709   - # if { $steps >= 1 } {
710   - # set progress [expr $progress + ( floor($steps) * $progressStep)]
711   - # #puts "$progress - $steps"
712   - # for {set i 0} {$i < [expr floor($steps)]} {incr i} {
713   - # puts -nonewline "#"
714   - # flush stdout
715   - # }
716   - # }
717   - #}
718   - }
719   - }
720   - puts {}
721   - flush stdout
722   -
723   -# Mount the disk
724   - set err [mountDisk $device $debug]
725   - if {[lindex $err 0] != 0} {
726   - puts "Mounting disk failed with error code $err"
727   - return $err
728   - }
729   -
730   -# Search for the hector disk
731   - set hectorDrive [findHECTOR 5]
732   -
733   - if { $hectorDrive == 0 } {
734   - puts "Hector disk drive not found. You will have to search for it manually."
735   - return 1
736   - }
737   -
738   -# Check for the mountpoint
739   - if { [string length [lindex $hectorDrive 2]] == 0 } {
740   - puts "Hector disk drive is not mounted. Please mount the device [lindex $hectorDrive 0]."
741   - return 1
742   - }
743   -
744   -# Copy the file from hector disk to the PC
745   - if { [string match $tcl_platform(os) "Linux"] } {
746   - puts [lindex $hectorDrive 2]/ACQ
747   - file copy -force [lindex $hectorDrive 2]/ACQ $filename
748   - } elseif { [string first $tcl_platform(os) "Win"] != -1 } {
749   - file copy -force {"[lindex $hectorDrive 2]/ACQ"} $filename
750   - }
751   -
752   - puts "Acquired data are available in the file $filename"
753   -
754   - return 0
755   -}
756   -
757   -proc hex2bin {hexIn {spaceSeparated 0}} {
758   - set outStr ""
759   -
760   - for {set i 0} {$i < [string length $hexIn]} {incr i} {
761   - set char [string index $hexIn $i]
762   - switch -glob $char {
763   - "0" {set outStr "$outStr 0000"}
764   - "1" {set outStr "$outStr 0001"}
765   - "2" {set outStr "$outStr 0010"}
766   - "3" {set outStr "$outStr 0011"}
767   - "4" {set outStr "$outStr 0100"}
768   - "5" {set outStr "$outStr 0101"}
769   - "6" {set outStr "$outStr 0110"}
770   - "7" {set outStr "$outStr 0111"}
771   - "8" {set outStr "$outStr 1000"}
772   - "9" {set outStr "$outStr 1001"}
773   - "A" {set outStr "$outStr 1010"}
774   - "a" {set outStr "$outStr 1010"}
775   - "B" {set outStr "$outStr 1011"}
776   - "b" {set outStr "$outStr 1011"}
777   - "C" {set outStr "$outStr 1100"}
778   - "c" {set outStr "$outStr 1100"}
779   - "D" {set outStr "$outStr 1101"}
780   - "d" {set outStr "$outStr 1101"}
781   - "E" {set outStr "$outStr 1110"}
782   - "e" {set outStr "$outStr 1110"}
783   - "F" {set outStr "$outStr 1111"}
784   - "f" {set outStr "$outStr 1111"}
785   - default {}
786   - }
787   - }
788   -
789   - if { $spaceSeparated == 0 } {
790   - set outStr [string map {" " {}} $outStr]
791   - }
792   -
793   - return $outStr
794   -}
795   -
796   -proc bin2hex {binIn} {
797   - set outStr ""
798   -
799   - for {set i 0} {$i < [string length $binIn]} {set i [expr $i+4]} {
800   - set char4 [string range $binIn [expr $i] [expr $i+3] ]
801   - switch -glob $char4 {
802   - "0000" {set outStr "$outStr 0"}
803   - "0001" {set outStr "$outStr 1"}
804   - "0010" {set outStr "$outStr 2"}
805   - "0011" {set outStr "$outStr 3"}
806   - "0100" {set outStr "$outStr 4"}
807   - "0101" {set outStr "$outStr 5"}
808   - "0110" {set outStr "$outStr 6"}
809   - "0111" {set outStr "$outStr 7"}
810   - "1000" {set outStr "$outStr 8"}
811   - "1001" {set outStr "$outStr 9"}
812   - "1010" {set outStr "$outStr A"}
813   - "1011" {set outStr "$outStr B"}
814   - "1100" {set outStr "$outStr C"}
815   - "1101" {set outStr "$outStr D"}
816   - "1110" {set outStr "$outStr E"}
817   - "1111" {set outStr "$outStr F"}
818   - default {}
819   - }
820   - }
821   -
822   - set outStr [string map {" " {}} $outStr]
823   -
824   - return $outStr
825   -}
boards_management_back/board_commands.py View file @ 9aae160
1   -# Author: Brice Colombier
2   -# Laboratoire Hubert Curien
3