@@ -18,9 +18,9 @@ use opentitanlib::io::spi::Target;
1818use opentitanlib:: io:: uart:: flow:: SoftwareFlowControl ;
1919use opentitanlib:: io:: uart:: serial:: SerialPortUart ;
2020use opentitanlib:: io:: uart:: { Uart , UartError } ;
21- use opentitanlib:: transport:: common:: fpga:: { ClearBitstream , FpgaProgram } ;
2221use opentitanlib:: transport:: {
23- Capabilities , Capability , Transport , TransportError , TransportInterfaceType ,
22+ Capabilities , Capability , FpgaOps , ProgressIndicator , Transport , TransportError ,
23+ TransportInterfaceType ,
2424} ;
2525use opentitanlib:: util:: fs:: builtin_file;
2626use opentitanlib:: util:: parse_int:: ParseInt ;
@@ -100,22 +100,6 @@ impl<B: Board> ChipWhisperer<B> {
100100 ) ?) )
101101 }
102102 }
103-
104- pub fn load_bitstream ( & self , fpga_program : & FpgaProgram ) -> Result < ( ) > {
105- // Program the FPGA bitstream.
106- log:: info!( "Programming the FPGA bitstream." ) ;
107- let usb = self . device . borrow ( ) ;
108- usb. spi1_enable ( false ) ?;
109- usb. fpga_program ( & fpga_program. bitstream , fpga_program. progress . as_ref ( ) ) ?;
110- Ok ( ( ) )
111- }
112-
113- pub fn clear_bitstream ( & self ) -> Result < ( ) > {
114- let usb = self . device . borrow ( ) ;
115- usb. spi1_enable ( false ) ?;
116- usb. clear_bitstream ( ) ?;
117- Ok ( ( ) )
118- }
119103}
120104
121105impl < B : Board + ' static > Transport for ChipWhisperer < B > {
@@ -162,11 +146,12 @@ impl<B: Board + 'static> Transport for ChipWhisperer<B> {
162146 Ok ( inner. spi . as_ref ( ) . unwrap ( ) . clone ( ) )
163147 }
164148
149+ fn fpga_ops ( & self ) -> Result < & dyn FpgaOps > {
150+ Ok ( self )
151+ }
152+
165153 fn dispatch ( & self , action : & dyn Any ) -> Result < Option < Box < dyn erased_serde:: Serialize > > > {
166- if let Some ( fpga_program) = action. downcast_ref :: < FpgaProgram > ( ) {
167- self . load_bitstream ( fpga_program) ?;
168- Ok ( None )
169- } else if action. downcast_ref :: < ResetSam3x > ( ) . is_some ( ) {
154+ if action. downcast_ref :: < ResetSam3x > ( ) . is_some ( ) {
170155 self . device . borrow ( ) . reset_sam3x ( ) ?;
171156 Ok ( None )
172157 } else if action. downcast_ref :: < SetPll > ( ) . is_some ( ) {
@@ -180,9 +165,6 @@ impl<B: Board + 'static> Transport for ChipWhisperer<B> {
180165 usb. pll_out_enable ( 2 , false ) ?;
181166 usb. pll_write_defaults ( ) ?;
182167 Ok ( None )
183- } else if action. downcast_ref :: < ClearBitstream > ( ) . is_some ( ) {
184- self . clear_bitstream ( ) ?;
185- Ok ( None )
186168 } else if action. downcast_ref :: < GetSam3xFwVersion > ( ) . is_some ( ) {
187169 let usb = self . device . borrow ( ) ;
188170 Ok ( Some ( Box :: new ( usb. get_firmware_version ( ) ?) ) )
@@ -192,6 +174,23 @@ impl<B: Board + 'static> Transport for ChipWhisperer<B> {
192174 }
193175}
194176
177+ impl < B : Board > FpgaOps for ChipWhisperer < B > {
178+ fn load_bitstream ( & self , bitstream : & [ u8 ] , progress : & dyn ProgressIndicator ) -> Result < ( ) > {
179+ // Program the FPGA bitstream.
180+ log:: info!( "Programming the FPGA bitstream." ) ;
181+ let usb = self . device . borrow ( ) ;
182+ usb. spi1_enable ( false ) ?;
183+ usb. fpga_program ( bitstream, progress) ?;
184+ Ok ( ( ) )
185+ }
186+
187+ fn clear_bitstream ( & self ) -> Result < ( ) > {
188+ let usb = self . device . borrow ( ) ;
189+ usb. spi1_enable ( false ) ?;
190+ usb. clear_bitstream ( ) ?;
191+ Ok ( ( ) )
192+ }
193+ }
195194/// Command for Transport::dispatch().
196195pub struct SetPll { }
197196
0 commit comments