Skip to content

Commit 1ac1583

Browse files
committed
[opentitanproxy] support bitstream programming over proxy
Signed-off-by: Gary Guo <[email protected]>
1 parent 1c9ce6b commit 1ac1583

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

sw/host/ot_proxy/proto/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum Request {
4040
Spi { id: String, command: SpiRequest },
4141
I2c { id: String, command: I2cRequest },
4242
Emu { command: EmuRequest },
43+
Fpga(FpgaRequest),
4344
Proxy(ProxyRequest),
4445
}
4546

@@ -55,6 +56,7 @@ pub enum Response {
5556
Spi(SpiResponse),
5657
I2c(I2cResponse),
5758
Emu(EmuResponse),
59+
Fpga(FgpaResponse),
5860
Proxy(ProxyResponse),
5961
}
6062

@@ -376,6 +378,18 @@ pub enum EmuResponse {
376378
Stop,
377379
}
378380

381+
#[derive(Serialize, Deserialize)]
382+
pub enum FpgaRequest {
383+
LoadBitstream { bitstream: Vec<u8> },
384+
ClearBitstream,
385+
}
386+
387+
#[derive(Serialize, Deserialize)]
388+
pub enum FgpaResponse {
389+
LoadBitstream,
390+
ClearBitstream,
391+
}
392+
379393
#[derive(Serialize, Deserialize)]
380394
pub enum ProxyRequest {
381395
Provides,

sw/host/ot_proxy/server/src/handler.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::sync::Arc;
1212
use std::task::{Context, Poll};
1313
use std::time::Duration;
1414

15-
use opentitanlib::app::TransportWrapper;
15+
use opentitanlib::app::{NoProgressBar, TransportWrapper};
1616
use opentitanlib::bootstrap::Bootstrap;
1717
use opentitanlib::io::console::broadcast::WeakBroadcaster;
1818
use opentitanlib::io::console::{Broadcaster, ConsoleDevice};
@@ -25,10 +25,11 @@ use opentitanlib::transport::TransportError;
2525
use opentitanlib::util::serializable_error::SerializedError;
2626
use ot_proxy_proto::{
2727
BitbangEntryRequest, BitbangEntryResponse, DacBangEntryRequest, EmuRequest, EmuResponse,
28-
GpioBitRequest, GpioBitResponse, GpioDacRequest, GpioDacResponse, GpioMonRequest,
29-
GpioMonResponse, GpioRequest, GpioResponse, I2cRequest, I2cResponse, I2cTransferRequest,
30-
I2cTransferResponse, Message, ProxyRequest, ProxyResponse, Request, Response, SpiRequest,
31-
SpiResponse, SpiTransferRequest, SpiTransferResponse, UartRequest, UartResponse,
28+
FgpaResponse, FpgaRequest, GpioBitRequest, GpioBitResponse, GpioDacRequest, GpioDacResponse,
29+
GpioMonRequest, GpioMonResponse, GpioRequest, GpioResponse, I2cRequest, I2cResponse,
30+
I2cTransferRequest, I2cTransferResponse, Message, ProxyRequest, ProxyResponse, Request,
31+
Response, SpiRequest, SpiResponse, SpiTransferRequest, SpiTransferResponse, UartRequest,
32+
UartResponse,
3233
};
3334

3435
use super::{CommandHandler, Connection};
@@ -588,6 +589,18 @@ impl TransportCommandHandler {
588589
}
589590
}
590591
}
592+
Request::Fpga(request) => match request {
593+
FpgaRequest::LoadBitstream { bitstream } => {
594+
self.transport
595+
.fpga_ops()?
596+
.load_bitstream(bitstream, &NoProgressBar)?;
597+
Ok(Response::Fpga(FgpaResponse::LoadBitstream))
598+
}
599+
FpgaRequest::ClearBitstream => {
600+
self.transport.fpga_ops()?.clear_bitstream()?;
601+
Ok(Response::Fpga(FgpaResponse::ClearBitstream))
602+
}
603+
},
591604
Request::Proxy(command) => match command {
592605
ProxyRequest::Provides => {
593606
let provides_map = self.transport.provides_map()?.clone();

sw/host/ot_transports/proxy/src/lib.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ use opentitanlib::io::gpio::{GpioBitbanging, GpioMonitoring, GpioPin};
2929
use opentitanlib::io::i2c::Bus;
3030
use opentitanlib::io::spi::Target;
3131
use opentitanlib::io::uart::Uart;
32-
use opentitanlib::transport::{Capabilities, Capability, ProxyOps, Transport, TransportError};
32+
use opentitanlib::transport::{
33+
Capabilities, Capability, FpgaOps, ProgressIndicator, ProxyOps, Transport, TransportError,
34+
};
3335
use opentitanlib::util::serializable_error::SerializedError;
3436
use ot_proxy_proto::{
35-
Message, ProxyRequest, ProxyResponse, Request, Response, UartRequest, UartResponse,
37+
FgpaResponse, FpgaRequest, Message, ProxyRequest, ProxyResponse, Request, Response,
38+
UartRequest, UartResponse,
3639
};
3740

3841
mod emu;
@@ -210,6 +213,29 @@ impl Inner {
210213
}
211214
}
212215

216+
impl FpgaOps for Proxy {
217+
fn load_bitstream(&self, bitstream: &[u8], _progress: &dyn ProgressIndicator) -> Result<()> {
218+
match self
219+
.inner
220+
.execute_command(Request::Fpga(FpgaRequest::LoadBitstream {
221+
bitstream: bitstream.to_owned(),
222+
}))? {
223+
Response::Fpga(FgpaResponse::LoadBitstream) => Ok(()),
224+
_ => bail!(ProxyError::UnexpectedReply()),
225+
}
226+
}
227+
228+
fn clear_bitstream(&self) -> Result<()> {
229+
match self
230+
.inner
231+
.execute_command(Request::Fpga(FpgaRequest::ClearBitstream))?
232+
{
233+
Response::Fpga(FgpaResponse::ClearBitstream) => Ok(()),
234+
_ => bail!(ProxyError::UnexpectedReply()),
235+
}
236+
}
237+
}
238+
213239
impl ProxyOps for Proxy {
214240
fn provides_map(&self) -> Result<HashMap<String, String>> {
215241
match self
@@ -339,6 +365,10 @@ impl Transport for Proxy {
339365
Ok(self)
340366
}
341367

368+
fn fpga_ops(&self) -> Result<&dyn FpgaOps> {
369+
Ok(self)
370+
}
371+
342372
// Create ProxyOps instance.
343373
fn proxy_ops(&self) -> Result<&dyn ProxyOps> {
344374
Ok(self)

0 commit comments

Comments
 (0)