forked from M-Labs/artiq-zynq
Compare commits
No commits in common. "abe0d6ff794186f70a3fdaaaac826b39bf811a9b" and "5f5b7148382b06be01ecbc57325b07e1b61c94e7" have entirely different histories.
abe0d6ff79
...
5f5b714838
|
@ -501,9 +501,7 @@ name = "satman"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"build_zynq",
|
||||
"byteorder",
|
||||
"core_io",
|
||||
"crc",
|
||||
"cslice",
|
||||
"embedded-hal",
|
||||
"io",
|
||||
|
|
|
@ -331,16 +331,6 @@ pub enum Packet {
|
|||
CoreMgmtAllocatorDebugRequest {
|
||||
destination: u8,
|
||||
},
|
||||
CoreMgmtFlashRequest {
|
||||
destination: u8,
|
||||
last: bool,
|
||||
length: u16,
|
||||
data: [u8; MASTER_PAYLOAD_MAX_SIZE],
|
||||
},
|
||||
CoreMgmtDropLinkAck {
|
||||
destination: u8,
|
||||
},
|
||||
CoreMgmtDropLink,
|
||||
CoreMgmtGetLogReply {
|
||||
last: bool,
|
||||
length: u16,
|
||||
|
@ -351,9 +341,8 @@ pub enum Packet {
|
|||
length: u16,
|
||||
value: [u8; SAT_PAYLOAD_MAX_SIZE],
|
||||
},
|
||||
CoreMgmtReply {
|
||||
succeeded: bool,
|
||||
},
|
||||
CoreMgmtAck,
|
||||
CoreMgmtNack,
|
||||
}
|
||||
|
||||
impl Packet {
|
||||
|
@ -693,23 +682,6 @@ impl Packet {
|
|||
destination: reader.read_u8()?,
|
||||
},
|
||||
0xdb => {
|
||||
let destination = reader.read_u8()?;
|
||||
let last = reader.read_bool()?;
|
||||
let length = reader.read_u16()?;
|
||||
let mut data: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
|
||||
reader.read_exact(&mut data[0..length as usize])?;
|
||||
Packet::CoreMgmtFlashRequest {
|
||||
destination: destination,
|
||||
last: last,
|
||||
length: length,
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
0xdc => Packet::CoreMgmtDropLinkAck {
|
||||
destination: reader.read_u8()?,
|
||||
},
|
||||
0xdd => Packet::CoreMgmtDropLink,
|
||||
0xde => {
|
||||
let last = reader.read_bool()?;
|
||||
let length = reader.read_u16()?;
|
||||
let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
|
||||
|
@ -720,7 +692,7 @@ impl Packet {
|
|||
data: data,
|
||||
}
|
||||
}
|
||||
0xdf => {
|
||||
0xdc => {
|
||||
let last = reader.read_bool()?;
|
||||
let length = reader.read_u16()?;
|
||||
let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
|
||||
|
@ -731,9 +703,8 @@ impl Packet {
|
|||
value: value,
|
||||
}
|
||||
}
|
||||
0xe0 => Packet::CoreMgmtReply {
|
||||
succeeded: reader.read_bool()?,
|
||||
},
|
||||
0xdd => Packet::CoreMgmtAck,
|
||||
0xde => Packet::CoreMgmtNack,
|
||||
|
||||
ty => return Err(Error::UnknownPacket(ty)),
|
||||
})
|
||||
|
@ -1178,39 +1149,20 @@ impl Packet {
|
|||
writer.write_u8(0xda)?;
|
||||
writer.write_u8(destination)?;
|
||||
}
|
||||
Packet::CoreMgmtFlashRequest {
|
||||
destination,
|
||||
last,
|
||||
length,
|
||||
data,
|
||||
} => {
|
||||
writer.write_u8(0xdb)?;
|
||||
writer.write_u8(destination)?;
|
||||
writer.write_bool(last)?;
|
||||
writer.write_u16(length)?;
|
||||
writer.write_all(&data[..length as usize])?;
|
||||
}
|
||||
Packet::CoreMgmtDropLinkAck { destination } => {
|
||||
writer.write_u8(0xdc)?;
|
||||
writer.write_u8(destination)?;
|
||||
}
|
||||
Packet::CoreMgmtDropLink => writer.write_u8(0xdd)?,
|
||||
Packet::CoreMgmtGetLogReply { last, length, data } => {
|
||||
writer.write_u8(0xde)?;
|
||||
writer.write_u8(0xdb)?;
|
||||
writer.write_bool(last)?;
|
||||
writer.write_u16(length)?;
|
||||
writer.write_all(&data[0..length as usize])?;
|
||||
}
|
||||
Packet::CoreMgmtConfigReadReply { last, length, value } => {
|
||||
writer.write_u8(0xdf)?;
|
||||
writer.write_u8(0xdc)?;
|
||||
writer.write_bool(last)?;
|
||||
writer.write_u16(length)?;
|
||||
writer.write_all(&value[0..length as usize])?;
|
||||
}
|
||||
Packet::CoreMgmtReply { succeeded } => {
|
||||
writer.write_u8(0xe0)?;
|
||||
writer.write_bool(succeeded)?;
|
||||
}
|
||||
Packet::CoreMgmtAck => writer.write_u8(0xdd)?,
|
||||
Packet::CoreMgmtNack => writer.write_u8(0xde)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@ use core::{cell::RefCell, ops::Deref};
|
|||
|
||||
use futures::{future::poll_fn, task::Poll};
|
||||
use libasync::{smoltcp::TcpStream, task};
|
||||
use libboard_artiq::{drtio_routing::RoutingTable,
|
||||
use libboard_artiq::{drtio_routing,
|
||||
drtio_routing::RoutingTable,
|
||||
logger::{BufferLogger, LogBufferRef}};
|
||||
use libboard_zynq::{smoltcp, timer::GlobalTimer};
|
||||
use libboard_zynq::{slcr, smoltcp, timer::GlobalTimer};
|
||||
use libconfig::Config;
|
||||
use libcortex_a9::mutex::Mutex;
|
||||
use log::{self, debug, error, info, warn};
|
||||
use log::{self, debug, error, info, warn, LevelFilter};
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use crate::proto_async::*;
|
||||
#[cfg(has_drtio)]
|
||||
use crate::rtio_mgt::drtio;
|
||||
use crate::rtio_mgt::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
|
@ -69,8 +70,6 @@ pub enum Request {
|
|||
ConfigErase = 15,
|
||||
|
||||
DebugAllocator = 8,
|
||||
|
||||
Flash = 9,
|
||||
}
|
||||
|
||||
#[repr(i8)]
|
||||
|
@ -133,17 +132,16 @@ async fn read_key(stream: &mut TcpStream) -> Result<String> {
|
|||
|
||||
#[cfg(has_drtio)]
|
||||
mod remote_coremgmt {
|
||||
use core_io::Read;
|
||||
use io::ProtoWrite;
|
||||
use libboard_artiq::{drtioaux_async,
|
||||
drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE}};
|
||||
use io::{Cursor, ProtoWrite};
|
||||
use libboard_artiq::drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE};
|
||||
|
||||
use super::*;
|
||||
use crate::rtio_mgt::drtio;
|
||||
|
||||
pub async fn get_log(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -188,7 +186,7 @@ mod remote_coremgmt {
|
|||
pub async fn clear_log(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -203,7 +201,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ mod remote_coremgmt {
|
|||
pub async fn pull_log(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -274,11 +272,11 @@ mod remote_coremgmt {
|
|||
pub async fn set_log_filter(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
level: log::LevelFilter,
|
||||
level: LevelFilter,
|
||||
) -> Result<()> {
|
||||
let reply = drtio::aux_transact(
|
||||
aux_mutex,
|
||||
|
@ -293,7 +291,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -313,11 +311,11 @@ mod remote_coremgmt {
|
|||
pub async fn set_uart_log_filter(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
level: log::LevelFilter,
|
||||
level: LevelFilter,
|
||||
) -> Result<()> {
|
||||
let reply = drtio::aux_transact(
|
||||
aux_mutex,
|
||||
|
@ -332,7 +330,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -352,7 +350,7 @@ mod remote_coremgmt {
|
|||
pub async fn config_read(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -416,7 +414,7 @@ mod remote_coremgmt {
|
|||
pub async fn config_write(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -424,7 +422,7 @@ mod remote_coremgmt {
|
|||
key: &String,
|
||||
value: Vec<u8>,
|
||||
) -> Result<()> {
|
||||
let mut message = Vec::with_capacity(key.len() + value.len() + 4 * 2);
|
||||
let mut message = Cursor::new(Vec::with_capacity(key.len() + value.len() + 4 * 2));
|
||||
message.write_string(key).unwrap();
|
||||
message.write_bytes(&value).unwrap();
|
||||
|
||||
|
@ -433,7 +431,7 @@ mod remote_coremgmt {
|
|||
aux_mutex,
|
||||
routing_table,
|
||||
timer,
|
||||
&message,
|
||||
message.get_ref(),
|
||||
|slice, status, len: usize| Packet::CoreMgmtConfigWriteRequest {
|
||||
destination: destination,
|
||||
last: status.is_last(),
|
||||
|
@ -441,7 +439,7 @@ mod remote_coremgmt {
|
|||
data: *slice,
|
||||
},
|
||||
|reply| match reply {
|
||||
Packet::CoreMgmtReply { succeeded: true } => Ok(()),
|
||||
Packet::CoreMgmtAck => Ok(()),
|
||||
packet => {
|
||||
error!("received unexpected aux packet: {:?}", packet);
|
||||
Err(drtio::Error::UnexpectedReply)
|
||||
|
@ -465,7 +463,7 @@ mod remote_coremgmt {
|
|||
pub async fn config_remove(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -490,7 +488,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -510,7 +508,7 @@ mod remote_coremgmt {
|
|||
pub async fn config_erase(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -527,7 +525,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -547,7 +545,7 @@ mod remote_coremgmt {
|
|||
pub async fn reboot(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -565,7 +563,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::RebootImminent as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -585,7 +583,7 @@ mod remote_coremgmt {
|
|||
pub async fn debug_allocator(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
routing_table: &drtio_routing::RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
|
@ -602,7 +600,7 @@ mod remote_coremgmt {
|
|||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) => {
|
||||
Ok(Packet::CoreMgmtAck) => {
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -616,69 +614,9 @@ mod remote_coremgmt {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn image_write(
|
||||
stream: &mut TcpStream,
|
||||
aux_mutex: &Rc<Mutex<bool>>,
|
||||
routing_table: &RoutingTable,
|
||||
timer: GlobalTimer,
|
||||
linkno: u8,
|
||||
destination: u8,
|
||||
_cfg: &Rc<Config>,
|
||||
image: Vec<u8>,
|
||||
) -> Result<()> {
|
||||
let mut image = &image[..];
|
||||
|
||||
while !image.is_empty() {
|
||||
let mut data = [0; MASTER_PAYLOAD_MAX_SIZE];
|
||||
let len = image.read(&mut data).unwrap();
|
||||
let last = image.is_empty();
|
||||
|
||||
let reply = drtio::aux_transact(
|
||||
aux_mutex,
|
||||
linkno,
|
||||
routing_table,
|
||||
&Packet::CoreMgmtFlashRequest {
|
||||
destination: destination,
|
||||
last: last,
|
||||
length: len as u16,
|
||||
data: data,
|
||||
},
|
||||
timer,
|
||||
)
|
||||
.await;
|
||||
|
||||
match reply {
|
||||
Ok(Packet::CoreMgmtReply { succeeded: true }) if !last => Ok(()),
|
||||
Ok(Packet::CoreMgmtDropLink) if last => drtioaux_async::send(
|
||||
linkno,
|
||||
&Packet::CoreMgmtDropLinkAck {
|
||||
destination: destination,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|_| drtio::Error::AuxError),
|
||||
Ok(packet) => {
|
||||
error!("received unexpected aux packet: {:?}", packet);
|
||||
write_i8(stream, Reply::Error as i8).await?;
|
||||
Err(drtio::Error::UnexpectedReply)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("aux packet error ({})", e);
|
||||
write_i8(stream, Reply::Error as i8).await?;
|
||||
Err(drtio::Error::AuxError)
|
||||
}
|
||||
}?;
|
||||
}
|
||||
|
||||
write_i8(stream, Reply::RebootImminent as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
mod local_coremgmt {
|
||||
use libboard_zynq::slcr;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub async fn get_log(stream: &mut TcpStream) -> Result<()> {
|
||||
|
@ -712,25 +650,25 @@ mod local_coremgmt {
|
|||
buffer.clear();
|
||||
core::mem::drop(buffer);
|
||||
write_chunk(stream, &bytes).await?;
|
||||
if log::max_level() == log::LevelFilter::Trace {
|
||||
if log::max_level() == LevelFilter::Trace {
|
||||
// temporarily discard all trace level log
|
||||
let logger = unsafe { BufferLogger::get_logger().as_mut().unwrap() };
|
||||
logger.set_buffer_log_level(log::LevelFilter::Debug);
|
||||
logger.set_buffer_log_level(LevelFilter::Debug);
|
||||
stream.flush().await?;
|
||||
logger.set_buffer_log_level(log::LevelFilter::Trace);
|
||||
logger.set_buffer_log_level(LevelFilter::Trace);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_log_filter(stream: &mut TcpStream, lvl: log::LevelFilter) -> Result<()> {
|
||||
pub async fn set_log_filter(stream: &mut TcpStream, lvl: LevelFilter) -> Result<()> {
|
||||
info!("Changing log level to {}", lvl);
|
||||
log::set_max_level(lvl);
|
||||
write_i8(stream, Reply::Success as i8).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_uart_log_filter(stream: &mut TcpStream, lvl: log::LevelFilter) -> Result<()> {
|
||||
pub async fn set_uart_log_filter(stream: &mut TcpStream, lvl: LevelFilter) -> Result<()> {
|
||||
info!("Changing UART log level to {}", lvl);
|
||||
unsafe {
|
||||
BufferLogger::get_logger().as_ref().unwrap().set_uart_log_level(lvl);
|
||||
|
@ -796,18 +734,6 @@ mod local_coremgmt {
|
|||
error!("zynq device does not support allocator debug print");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn image_write(stream: &mut TcpStream, cfg: &Rc<Config>, image: Vec<u8>) -> Result<()> {
|
||||
let value = cfg.write("boot", image);
|
||||
if value.is_ok() {
|
||||
reboot(stream).await?;
|
||||
} else {
|
||||
// this is an error because we do not expect write to fail
|
||||
error!("failed to write boot file: {:?}", value);
|
||||
write_i8(stream, Reply::Error as i8).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(has_drtio)]
|
||||
|
@ -855,18 +781,43 @@ async fn handle_connection(
|
|||
match msg {
|
||||
Request::GetLog => process!(stream, _drtio_tuple, _destination, get_log),
|
||||
Request::ClearLog => process!(stream, _drtio_tuple, _destination, clear_log),
|
||||
Request::PullLog => process!(stream, _drtio_tuple, _destination, pull_log, &pull_id),
|
||||
Request::PullLog => process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
pull_log,
|
||||
&pull_id
|
||||
),
|
||||
Request::SetLogFilter => {
|
||||
let lvl = read_log_level_filter(stream).await?;
|
||||
process!(stream, _drtio_tuple, _destination, set_log_filter, lvl)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
set_log_filter,
|
||||
lvl
|
||||
)
|
||||
}
|
||||
Request::SetUartLogFilter => {
|
||||
let lvl = read_log_level_filter(stream).await?;
|
||||
process!(stream, _drtio_tuple, _destination, set_uart_log_filter, lvl)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
set_uart_log_filter,
|
||||
lvl
|
||||
)
|
||||
}
|
||||
Request::ConfigRead => {
|
||||
let key = read_key(stream).await?;
|
||||
process!(stream, _drtio_tuple, _destination, config_read, &cfg, &key)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
config_read,
|
||||
&cfg,
|
||||
&key
|
||||
)
|
||||
}
|
||||
Request::ConfigWrite => {
|
||||
let key = read_key(stream).await?;
|
||||
|
@ -877,11 +828,26 @@ async fn handle_connection(
|
|||
buffer.set_len(len);
|
||||
}
|
||||
read_chunk(stream, &mut buffer).await?;
|
||||
process!(stream, _drtio_tuple, _destination, config_write, &cfg, &key, buffer)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
config_write,
|
||||
&cfg,
|
||||
&key,
|
||||
buffer
|
||||
)
|
||||
}
|
||||
Request::ConfigRemove => {
|
||||
let key = read_key(stream).await?;
|
||||
process!(stream, _drtio_tuple, _destination, config_remove, &cfg, &key)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
config_remove,
|
||||
&cfg,
|
||||
&key
|
||||
)
|
||||
}
|
||||
Request::Reboot => {
|
||||
process!(stream, _drtio_tuple, _destination, reboot)
|
||||
|
@ -890,28 +856,28 @@ async fn handle_connection(
|
|||
process!(stream, _drtio_tuple, _destination, config_erase)
|
||||
}
|
||||
Request::DebugAllocator => {
|
||||
process!(stream, _drtio_tuple, _destination, debug_allocator)
|
||||
}
|
||||
Request::Flash => {
|
||||
let len = read_i32(stream).await?;
|
||||
if len <= 0 {
|
||||
write_i8(stream, Reply::Error as i8).await?;
|
||||
return Err(Error::UnexpectedPattern);
|
||||
}
|
||||
let mut buffer = Vec::with_capacity(len as usize);
|
||||
unsafe {
|
||||
buffer.set_len(len as usize);
|
||||
}
|
||||
read_chunk(stream, &mut buffer).await?;
|
||||
process!(stream, _drtio_tuple, _destination, image_write, &cfg, buffer)
|
||||
process!(
|
||||
stream,
|
||||
_drtio_tuple,
|
||||
_destination,
|
||||
debug_allocator
|
||||
)
|
||||
}
|
||||
}?;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(cfg: Config, drtio_tuple: Option<(&Rc<Mutex<bool>>, &Rc<RefCell<RoutingTable>>, GlobalTimer)>) {
|
||||
let drtio_tuple =
|
||||
drtio_tuple.map(|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer));
|
||||
pub fn start(
|
||||
cfg: Config,
|
||||
drtio_tuple: Option<(
|
||||
&Rc<Mutex<bool>>,
|
||||
&Rc<RefCell<drtio_routing::RoutingTable>>,
|
||||
GlobalTimer,
|
||||
)>,
|
||||
) {
|
||||
let drtio_tuple = drtio_tuple.map(
|
||||
|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer)
|
||||
);
|
||||
task::spawn(async move {
|
||||
let pull_id = Rc::new(RefCell::new(0u32));
|
||||
let cfg = Rc::new(cfg);
|
||||
|
@ -925,12 +891,12 @@ pub fn start(cfg: Config, drtio_tuple: Option<(&Rc<Mutex<bool>>, &Rc<RefCell<Rou
|
|||
info!("received connection");
|
||||
// Avoid consuming the tuple
|
||||
// Keep the borrowed value on stack
|
||||
let drtio_tuple = drtio_tuple
|
||||
.as_ref()
|
||||
.map(|(aux_mutex, routing_table, timer)| (aux_mutex, routing_table.borrow(), *timer));
|
||||
let drtio_tuple = drtio_tuple
|
||||
.as_ref()
|
||||
.map(|(aux_mutex, routing_table, timer)| (*aux_mutex, routing_table.deref(), *timer));
|
||||
let drtio_tuple = drtio_tuple.as_ref().map(
|
||||
|(aux_mutex, routing_table, timer)| (aux_mutex, routing_table.borrow(), *timer)
|
||||
);
|
||||
let drtio_tuple = drtio_tuple.as_ref().map(
|
||||
|(aux_mutex, routing_table, timer)| (*aux_mutex, routing_table.deref(), *timer)
|
||||
);
|
||||
let _ = handle_connection(&mut stream, pull_id, cfg, drtio_tuple)
|
||||
.await
|
||||
.map_err(|e| warn!("connection terminated: {:?}", e));
|
||||
|
|
|
@ -15,9 +15,7 @@ build_zynq = { path = "../libbuild_zynq" }
|
|||
|
||||
[dependencies]
|
||||
log = { version = "0.4", default-features = false }
|
||||
byteorder = { version = "1.3", default-features = false }
|
||||
core_io = { version = "0.1", features = ["collections"] }
|
||||
crc = { version = "1.7", default-features = false }
|
||||
cslice = "0.3"
|
||||
embedded-hal = "0.2"
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate byteorder;
|
||||
extern crate core_io;
|
||||
extern crate crc;
|
||||
extern crate cslice;
|
||||
extern crate embedded_hal;
|
||||
|
||||
|
@ -1057,7 +1055,7 @@ fn process_aux_packet(
|
|||
timer
|
||||
);
|
||||
mgmt::clear_log();
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtSetLogLevelRequest {
|
||||
destination: _destination,
|
||||
|
@ -1077,9 +1075,9 @@ fn process_aux_packet(
|
|||
if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) {
|
||||
info!("Changing log level to {}", level_filter);
|
||||
log::set_max_level(level_filter);
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtSetUartLogLevelRequest {
|
||||
|
@ -1105,9 +1103,9 @@ fn process_aux_packet(
|
|||
.unwrap()
|
||||
.set_uart_log_level(level_filter);
|
||||
}
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtConfigReadRequest {
|
||||
|
@ -1131,7 +1129,7 @@ fn process_aux_packet(
|
|||
let key_slice = &key[..length as usize];
|
||||
if !key_slice.is_ascii() {
|
||||
error!("invalid key");
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
} else {
|
||||
let key = core::str::from_utf8(key_slice).unwrap();
|
||||
if core_manager.fetch_config_value(key).is_ok() {
|
||||
|
@ -1145,7 +1143,7 @@ fn process_aux_packet(
|
|||
},
|
||||
)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1191,15 +1189,19 @@ fn process_aux_packet(
|
|||
timer
|
||||
);
|
||||
|
||||
core_manager.add_config_data(&data, length as usize);
|
||||
core_manager.add_data(&data, length as usize);
|
||||
|
||||
let mut succeeded = true;
|
||||
if last {
|
||||
succeeded = core_manager.write_config().is_ok();
|
||||
core_manager.clear_config_data();
|
||||
core_manager.clear_data();
|
||||
}
|
||||
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
|
||||
if succeeded {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtConfigRemoveRequest {
|
||||
destination: _destination,
|
||||
|
@ -1220,11 +1222,14 @@ fn process_aux_packet(
|
|||
let key_slice = &key[..length as usize];
|
||||
if !key_slice.is_ascii() {
|
||||
error!("invalid key");
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
} else {
|
||||
let key = core::str::from_utf8(key_slice).unwrap();
|
||||
let succeeded = core_manager.remove_config(key).is_ok();
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded })
|
||||
if core_manager.remove_config(key).is_ok() {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
}
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtConfigEraseRequest {
|
||||
|
@ -1242,7 +1247,7 @@ fn process_aux_packet(
|
|||
);
|
||||
|
||||
error!("config erase not supported on zynq device");
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtRebootRequest {
|
||||
destination: _destination,
|
||||
|
@ -1259,11 +1264,10 @@ fn process_aux_packet(
|
|||
timer
|
||||
);
|
||||
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })?;
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?;
|
||||
info!("reboot imminent");
|
||||
slcr::reboot();
|
||||
|
||||
unreachable!();
|
||||
Ok(())
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtAllocatorDebugRequest {
|
||||
destination: _destination,
|
||||
|
@ -1280,54 +1284,7 @@ fn process_aux_packet(
|
|||
);
|
||||
|
||||
error!("debug allocator not supported on zynq device");
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false })
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtFlashRequest {
|
||||
destination: _destination,
|
||||
last,
|
||||
length,
|
||||
data,
|
||||
} => {
|
||||
forward!(
|
||||
router,
|
||||
_routing_table,
|
||||
_destination,
|
||||
*rank,
|
||||
*self_destination,
|
||||
_repeaters,
|
||||
&packet,
|
||||
timer
|
||||
);
|
||||
|
||||
core_manager.add_image_data(&data, length as usize);
|
||||
|
||||
if last {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtDropLink)
|
||||
} else {
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })
|
||||
}
|
||||
}
|
||||
drtioaux::Packet::CoreMgmtDropLinkAck {
|
||||
destination: _destination,
|
||||
} => {
|
||||
forward!(
|
||||
router,
|
||||
_routing_table,
|
||||
_destination,
|
||||
*rank,
|
||||
*self_destination,
|
||||
_repeaters,
|
||||
&packet,
|
||||
timer
|
||||
);
|
||||
|
||||
unsafe {
|
||||
csr::gt_drtio::txenable_write(0);
|
||||
}
|
||||
core_manager.write_image();
|
||||
info!("reboot imminent");
|
||||
slcr::reboot();
|
||||
Ok(())
|
||||
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
|
||||
}
|
||||
|
||||
p => {
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
use alloc::vec::Vec;
|
||||
|
||||
use byteorder::{ByteOrder, NativeEndian};
|
||||
use crc::crc32;
|
||||
use io::{ProtoRead, ProtoWrite};
|
||||
use io::{Cursor, ProtoRead, ProtoWrite};
|
||||
use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE,
|
||||
logger::{BufferLogger, LogBufferRef}};
|
||||
use libconfig::Config;
|
||||
use log::{debug, error, info, warn, LevelFilter};
|
||||
use log::{self, debug, error, info, warn, LevelFilter};
|
||||
|
||||
use crate::routing::{SliceMeta, Sliceable};
|
||||
|
||||
type Result<T> = core::result::Result<T, ()>;
|
||||
|
||||
pub fn byte_to_level_filter(level_byte: u8) -> Result<LevelFilter> {
|
||||
pub fn byte_to_level_filter(level_byte: u8) -> Result<log::LevelFilter> {
|
||||
Ok(match level_byte {
|
||||
0 => LevelFilter::Off,
|
||||
1 => LevelFilter::Error,
|
||||
2 => LevelFilter::Warn,
|
||||
3 => LevelFilter::Info,
|
||||
4 => LevelFilter::Debug,
|
||||
5 => LevelFilter::Trace,
|
||||
0 => log::LevelFilter::Off,
|
||||
1 => log::LevelFilter::Error,
|
||||
2 => log::LevelFilter::Warn,
|
||||
3 => log::LevelFilter::Info,
|
||||
4 => log::LevelFilter::Debug,
|
||||
5 => log::LevelFilter::Trace,
|
||||
lv => {
|
||||
error!("unknown log level: {}", lv);
|
||||
return Err(());
|
||||
|
@ -48,9 +46,8 @@ pub fn clear_log() {
|
|||
pub struct Manager<'a> {
|
||||
cfg: &'a mut Config,
|
||||
last_log: Sliceable,
|
||||
config_payload: Vec<u8>,
|
||||
current_payload: Cursor<Vec<u8>>,
|
||||
last_value: Sliceable,
|
||||
image_payload: Vec<u8>,
|
||||
}
|
||||
|
||||
impl<'a> Manager<'_> {
|
||||
|
@ -58,9 +55,8 @@ impl<'a> Manager<'_> {
|
|||
Manager {
|
||||
cfg: cfg,
|
||||
last_log: Sliceable::new(0, Vec::new()),
|
||||
config_payload: Vec::new(),
|
||||
current_payload: Cursor::new(Vec::new()),
|
||||
last_value: Sliceable::new(0, Vec::new()),
|
||||
image_payload: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,19 +83,22 @@ impl<'a> Manager<'_> {
|
|||
self.last_value.get_slice_satellite(data_slice)
|
||||
}
|
||||
|
||||
pub fn add_config_data(&mut self, data: &[u8], data_len: usize) {
|
||||
self.config_payload.write_all(&data[..data_len]).unwrap();
|
||||
pub fn add_data(&mut self, data: &[u8], data_len: usize) {
|
||||
self.current_payload.write_all(&data[..data_len]).unwrap();
|
||||
}
|
||||
|
||||
pub fn clear_config_data(&mut self) {
|
||||
self.config_payload.clear();
|
||||
pub fn clear_data(&mut self) {
|
||||
self.current_payload.get_mut().clear();
|
||||
self.current_payload.set_position(0);
|
||||
}
|
||||
|
||||
pub fn write_config(&mut self) -> Result<()> {
|
||||
let mut payload = &self.config_payload[..];
|
||||
let key = payload.read_string().map_err(|_err| error!("error on reading key"))?;
|
||||
let key = self
|
||||
.current_payload
|
||||
.read_string()
|
||||
.map_err(|_err| error!("error on reading key"))?;
|
||||
debug!("write key: {}", key);
|
||||
let value = payload.read_bytes().unwrap();
|
||||
let value = self.current_payload.read_bytes().unwrap();
|
||||
|
||||
self.cfg
|
||||
.write(&key, value)
|
||||
|
@ -114,32 +113,4 @@ impl<'a> Manager<'_> {
|
|||
.map(|()| debug!("erase success"))
|
||||
.map_err(|err| warn!("failed to erase: {:?}", err))
|
||||
}
|
||||
|
||||
pub fn add_image_data(&mut self, data: &[u8], data_len: usize) {
|
||||
self.image_payload.extend(&data[..data_len]);
|
||||
}
|
||||
|
||||
pub fn write_image(&self) {
|
||||
let mut image = self.image_payload.clone();
|
||||
let image_ref = &image[..];
|
||||
let bin_len = image.len() - 4;
|
||||
|
||||
let (image_ref, expected_crc) = {
|
||||
let (image_ref, crc_slice) = image_ref.split_at(bin_len);
|
||||
(image_ref, NativeEndian::read_u32(crc_slice))
|
||||
};
|
||||
|
||||
let actual_crc = crc32::checksum_ieee(image_ref);
|
||||
|
||||
if actual_crc == expected_crc {
|
||||
info!("CRC passed. Writing boot image to SD card...");
|
||||
image.truncate(bin_len);
|
||||
self.cfg.write("boot", image).expect("failed to write boot image");
|
||||
} else {
|
||||
panic!(
|
||||
"CRC failed in SDRAM (actual {:08x}, expected {:08x})",
|
||||
actual_crc, expected_crc
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue