mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge branch 'main' of github.com:betrusted-io/xous-core into main
This commit is contained in:
commit
0425f3c9b7
3 changed files with 838 additions and 286 deletions
|
|
@ -92,7 +92,15 @@ pub(crate) enum Opcode {
|
|||
/// =======|=========
|
||||
/// 0 | port number, low byte
|
||||
/// 1 | port number, high byte
|
||||
/// 2 | address type -- 4 = ipv4, 6 = ipv6
|
||||
/// 2 | timeout, msecs, low byte
|
||||
/// 3 | timeout
|
||||
/// 4 | timeout
|
||||
/// 5 | timeout
|
||||
/// 6 | timeout
|
||||
/// 7 | timeout
|
||||
/// 8 | timeout
|
||||
/// 9 | timeout, high byte
|
||||
/// 10 | address type -- 4 = ipv4, 6 = ipv6
|
||||
/// ... | remaining bytes are the address
|
||||
///
|
||||
/// # Returns
|
||||
|
|
@ -138,15 +146,35 @@ pub(crate) enum Opcode {
|
|||
///
|
||||
StdTcpTx = 31,
|
||||
|
||||
/// Receives data from the specified TCP Connection. The TCP connection number is
|
||||
/// passed in the upper 16 bits of the opcode, and the number of received bytes
|
||||
/// is returned as part of the `Valid` parameter. This is not blocking.
|
||||
StdTcpPeek = 32,
|
||||
|
||||
/// Receives data from the specified TCP Connection. The TCP connection number is
|
||||
/// passed in the upper 16 bits of the opcode, and the number of received bytes
|
||||
/// is returned as part of the `Valid` parameter.
|
||||
StdTcpRx = 32,
|
||||
StdTcpRx = 33,
|
||||
|
||||
/// Close the TCP connection. The connection ID is specified in the upper 16 bits
|
||||
/// of the opcode. This may be any kind of message (scalar, blockingscalar, memory,
|
||||
/// etc.)
|
||||
StdTcpClose = 33,
|
||||
StdTcpClose = 34,
|
||||
|
||||
/// Get the current IP address
|
||||
StdGetAddress = 35,
|
||||
|
||||
/// BlockingScalar call to get the current hop count of this connection
|
||||
StdGetTtl = 36,
|
||||
|
||||
/// BlockingScalar call to set the maximum hop count of this connection
|
||||
StdSetTtl = 37,
|
||||
|
||||
/// BlockingScalar call to get the NODELAY / "Nagle" value of this connection
|
||||
StdGetNodelay = 38,
|
||||
|
||||
/// BlockingScalar call to set the NODELAY / "Nagle" value of this connection
|
||||
StdSetNodelay = 39,
|
||||
}
|
||||
|
||||
#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone, Default)]
|
||||
|
|
@ -211,14 +239,15 @@ pub(crate) enum NetMemResponse {
|
|||
|
||||
#[repr(C)]
|
||||
pub enum NetError {
|
||||
Ok = 0,
|
||||
OutOfMemory = 1,
|
||||
// Ok = 0,
|
||||
// OutOfMemory = 1,
|
||||
SocketInUse = 2,
|
||||
AccessDenied = 3,
|
||||
// AccessDenied = 3,
|
||||
Invalid = 4,
|
||||
Finished = 5,
|
||||
// Finished = 5,
|
||||
LibraryError = 6,
|
||||
AlreadyUsed = 7,
|
||||
// AlreadyUsed = 7,
|
||||
TimedOut = 8,
|
||||
}
|
||||
|
||||
/////// a bunch of structures are re-derived here so we can infer `rkyv` traits on them
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ mod api;
|
|||
use api::*;
|
||||
use com::api::{ComIntSources, Ipv4Conf, NET_MTU};
|
||||
use num_traits::*;
|
||||
use ticktimer_server::Ticktimer;
|
||||
|
||||
mod connection_manager;
|
||||
mod device;
|
||||
|
|
@ -21,6 +22,7 @@ use smoltcp::socket::{IcmpEndpoint, IcmpPacketMetadata, IcmpSocket, IcmpSocketBu
|
|||
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address, Ipv4Cidr};
|
||||
use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, Icmpv6Packet, Icmpv6Repr};
|
||||
|
||||
use core::num::NonZeroU64;
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use smoltcp::socket::{
|
||||
SocketHandle, TcpSocket, TcpSocketBuffer, UdpPacketMetadata, UdpSocket, UdpSocketBuffer,
|
||||
|
|
@ -92,6 +94,12 @@ pub struct TcpState {
|
|||
shutdown_rx: bool,
|
||||
}
|
||||
|
||||
struct WaitingSocket {
|
||||
env: xous::MessageEnvelope,
|
||||
handle: SocketHandle,
|
||||
expiry: Option<NonZeroU64>,
|
||||
}
|
||||
|
||||
fn set_com_ints(com_int_list: &mut Vec<ComIntSources>) {
|
||||
com_int_list.clear();
|
||||
com_int_list.push(ComIntSources::WlanIpConfigUpdate);
|
||||
|
|
@ -125,6 +133,30 @@ fn parse_address(data: &[u8]) -> Option<smoltcp::wire::IpAddress> {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_address(address: IpAddress, data: &mut [u8]) -> Option<usize> {
|
||||
let mut i = data.iter_mut();
|
||||
match address {
|
||||
IpAddress::Ipv4(a) => {
|
||||
*i.next()? = 4;
|
||||
for (dest, src) in i.zip(a.as_bytes().iter()) {
|
||||
*dest = *src;
|
||||
}
|
||||
Some(5)
|
||||
}
|
||||
IpAddress::Ipv6(a) => {
|
||||
*i.next()? = 6;
|
||||
for (dest, src) in i.zip(a.as_bytes().iter()) {
|
||||
*dest = *src;
|
||||
}
|
||||
Some(16)
|
||||
}
|
||||
_ => {
|
||||
*i.next()? = 0;
|
||||
Some(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn respond_with_error(mut env: xous::MessageEnvelope, code: NetError) -> Option<()> {
|
||||
// If it's not a memory message, don't fill in the return information.
|
||||
let body = match env.body.memory_message_mut() {
|
||||
|
|
@ -138,6 +170,7 @@ fn respond_with_error(mut env: xous::MessageEnvelope, code: NetError) -> Option<
|
|||
Some(b) => b,
|
||||
};
|
||||
|
||||
body.valid = None;
|
||||
let s: &mut [u8] = body.buf.as_slice_mut();
|
||||
let mut i = s.iter_mut();
|
||||
|
||||
|
|
@ -150,10 +183,48 @@ fn respond_with_error(mut env: xous::MessageEnvelope, code: NetError) -> Option<
|
|||
None
|
||||
}
|
||||
|
||||
fn respond_with_connected(
|
||||
mut env: xous::MessageEnvelope,
|
||||
idx: u16,
|
||||
local_port: u16,
|
||||
remote_port: u16,
|
||||
) {
|
||||
let body = env.body.memory_message_mut().unwrap();
|
||||
let bfr = body.buf.as_slice_mut::<u16>();
|
||||
|
||||
log::trace!("successfully connected: {}", idx);
|
||||
bfr[0] = 0;
|
||||
bfr[1] = idx;
|
||||
bfr[2] = local_port;
|
||||
bfr[3] = remote_port;
|
||||
}
|
||||
|
||||
/// Insert `Some(value)` into the first slot in the Vec that is `None`,
|
||||
/// or append it to the end if there is no free slot
|
||||
fn insert_or_append<T>(arr: &mut Vec<Option<T>>, val: T) -> usize {
|
||||
// Look for a free index, or add it onto the end.
|
||||
let mut idx = None;
|
||||
for (i, elem) in arr.iter_mut().enumerate() {
|
||||
if elem.is_none() {
|
||||
idx = Some(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(idx) = idx {
|
||||
arr[idx] = Some(val);
|
||||
idx
|
||||
} else {
|
||||
let idx = arr.len();
|
||||
arr.push(Some(val));
|
||||
idx
|
||||
}
|
||||
}
|
||||
|
||||
fn std_tcp_connect(
|
||||
mut msg: xous::MessageEnvelope,
|
||||
local_port: u16,
|
||||
sockets: &mut SocketSet,
|
||||
tcp_connect_waiting: &mut Vec<Option<(xous::MessageEnvelope, SocketHandle, u16, u16, u16)>>,
|
||||
our_sockets: &mut Vec<Option<SocketHandle>>,
|
||||
) {
|
||||
// Ignore nonblocking and scalar messages
|
||||
|
|
@ -168,7 +239,8 @@ fn std_tcp_connect(
|
|||
|
||||
let bytes = body.buf.as_slice::<u8>();
|
||||
let remote_port = u16::from_le_bytes([bytes[0], bytes[1]]);
|
||||
let address = match parse_address(&bytes[2..]) {
|
||||
let timeout_ms = NonZeroU64::new(u64::from_le_bytes(bytes[2..10].try_into().unwrap()));
|
||||
let address = match parse_address(&bytes[10..]) {
|
||||
Some(addr) => addr,
|
||||
None => {
|
||||
log::trace!("couldn't parse address");
|
||||
|
|
@ -198,37 +270,24 @@ fn std_tcp_connect(
|
|||
return;
|
||||
}
|
||||
|
||||
tcp_socket.set_timeout(timeout_ms.map(|t| Duration::from_millis(t.get())));
|
||||
|
||||
let handle = sockets.add(tcp_socket);
|
||||
|
||||
// Look for a free index, or add it onto the end.
|
||||
let mut idx = None;
|
||||
for (i, elem) in our_sockets.iter_mut().enumerate() {
|
||||
if elem.is_none() {
|
||||
idx = Some(i);
|
||||
*elem = Some(handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if idx.is_none() {
|
||||
idx = Some(our_sockets.len());
|
||||
our_sockets.push(Some(handle));
|
||||
}
|
||||
|
||||
// We're done with the `bytes` array now as we've extracted all the data from it.
|
||||
drop(bytes);
|
||||
let bfr = body.buf.as_slice_mut::<u16>();
|
||||
|
||||
log::trace!("successfully connected: {}", idx.unwrap_or_default());
|
||||
bfr[0] = 0;
|
||||
bfr[1] = idx.unwrap_or_default() as u16;
|
||||
bfr[2] = local_port as u16;
|
||||
bfr[3] = remote_port as u16;
|
||||
// Add the socket onto the list of sockets waiting to connect, since the connection will
|
||||
// take time.
|
||||
let idx = insert_or_append(our_sockets, handle) as u16;
|
||||
insert_or_append(
|
||||
tcp_connect_waiting,
|
||||
(msg, handle, idx, local_port, remote_port),
|
||||
);
|
||||
}
|
||||
|
||||
fn std_tcp_tx(
|
||||
mut msg: xous::MessageEnvelope,
|
||||
timer: &Ticktimer,
|
||||
sockets: &mut SocketSet,
|
||||
tcp_tx_waiting: &mut Vec<Option<(xous::MessageEnvelope, SocketHandle)>>,
|
||||
tcp_tx_waiting: &mut Vec<Option<WaitingSocket>>,
|
||||
our_sockets: &Vec<Option<SocketHandle>>,
|
||||
) {
|
||||
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
||||
|
|
@ -251,20 +310,19 @@ fn std_tcp_tx(
|
|||
let mut socket = sockets.get::<TcpSocket>(*handle);
|
||||
if !socket.may_send() {
|
||||
log::trace!("tx can't send, will retry");
|
||||
let expiry = body
|
||||
.offset
|
||||
.map(|x| unsafe { NonZeroU64::new_unchecked(x.get() as u64 + timer.elapsed_ms()) });
|
||||
// Add the message to the TcpRxWaiting list, which will prevent it from getting
|
||||
// responded to right away.
|
||||
let mut idx = None;
|
||||
for (i, elem) in tcp_tx_waiting.iter_mut().enumerate() {
|
||||
if elem.is_none() {
|
||||
idx = Some(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(idx) = idx {
|
||||
tcp_tx_waiting[idx] = Some((msg, *handle));
|
||||
} else {
|
||||
tcp_tx_waiting.push(Some((msg, *handle)));
|
||||
}
|
||||
insert_or_append(
|
||||
tcp_tx_waiting,
|
||||
WaitingSocket {
|
||||
env: msg,
|
||||
handle: *handle,
|
||||
expiry,
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -300,8 +358,9 @@ fn std_tcp_tx(
|
|||
|
||||
fn std_tcp_rx(
|
||||
mut msg: xous::MessageEnvelope,
|
||||
timer: &Ticktimer,
|
||||
sockets: &mut SocketSet,
|
||||
tcp_rx_waiting: &mut Vec<Option<(xous::MessageEnvelope, SocketHandle)>>,
|
||||
tcp_rx_waiting: &mut Vec<Option<WaitingSocket>>,
|
||||
our_sockets: &Vec<Option<SocketHandle>>,
|
||||
) {
|
||||
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
||||
|
|
@ -344,24 +403,69 @@ fn std_tcp_rx(
|
|||
|
||||
// Add the message to the TcpRxWaiting list, which will prevent it from getting
|
||||
// responded to right away.
|
||||
let mut idx = None;
|
||||
for (i, elem) in tcp_rx_waiting.iter_mut().enumerate() {
|
||||
if elem.is_none() {
|
||||
idx = Some(i);
|
||||
break;
|
||||
let expiry = body
|
||||
.offset
|
||||
.map(|x| unsafe { NonZeroU64::new_unchecked(x.get() as u64 + timer.elapsed_ms()) });
|
||||
insert_or_append(
|
||||
tcp_rx_waiting,
|
||||
WaitingSocket {
|
||||
env: msg,
|
||||
handle: *handle,
|
||||
expiry,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn std_tcp_peek(
|
||||
mut msg: xous::MessageEnvelope,
|
||||
sockets: &mut SocketSet,
|
||||
our_sockets: &Vec<Option<SocketHandle>>,
|
||||
) {
|
||||
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
||||
let body = match msg.body.memory_message_mut() {
|
||||
Some(body) => body,
|
||||
None => {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Default to having no valid data upon return, indicating an error
|
||||
body.valid = None;
|
||||
|
||||
let handle = match our_sockets.get(connection_handle_index) {
|
||||
Some(Some(val)) => val,
|
||||
_ => {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut socket = sockets.get::<TcpSocket>(*handle);
|
||||
if socket.can_recv() {
|
||||
log::trace!("receiving data right away");
|
||||
match socket.peek_slice(body.buf.as_slice_mut()) {
|
||||
Ok(bytes) => {
|
||||
body.valid = xous::MemorySize::new(bytes);
|
||||
log::trace!("set body.valid = {:?}", body.valid);
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("unable to receive: {:?}", e);
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(idx) = idx {
|
||||
tcp_rx_waiting[idx] = Some((msg, *handle));
|
||||
} else {
|
||||
tcp_rx_waiting.push(Some((msg, *handle)));
|
||||
// No data available, so indicate `None`
|
||||
body.valid = None;
|
||||
// Also indicate no error
|
||||
body.buf.as_slice_mut::<u32>()[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -406,11 +510,23 @@ fn xmain() -> ! {
|
|||
|
||||
// When a client issues a Receive request, it will get placed here while the packet data
|
||||
// is being accumulated.
|
||||
let mut tcp_rx_waiting: Vec<Option<(xous::MessageEnvelope, SocketHandle)>> = Vec::new();
|
||||
let mut tcp_rx_waiting: Vec<Option<WaitingSocket>> = Vec::new();
|
||||
|
||||
// When a client issues a Send request, it will get placed here while the packet data
|
||||
// is being accumulated.
|
||||
let mut tcp_tx_waiting: Vec<Option<(xous::MessageEnvelope, SocketHandle)>> = Vec::new();
|
||||
let mut tcp_tx_waiting: Vec<Option<WaitingSocket>> = Vec::new();
|
||||
|
||||
// When a client issues a Connect request, it will get placed here while the connection is
|
||||
// being established.
|
||||
let mut tcp_connect_waiting: Vec<
|
||||
Option<(
|
||||
xous::MessageEnvelope,
|
||||
SocketHandle,
|
||||
u16, /* fd */
|
||||
u16, /* local_port */
|
||||
u16, /* remote_port */
|
||||
)>,
|
||||
> = Vec::new();
|
||||
|
||||
// ping storage
|
||||
// up to four concurrent pings in the queue
|
||||
|
|
@ -710,6 +826,7 @@ fn xmain() -> ! {
|
|||
msg,
|
||||
local_port,
|
||||
&mut sockets,
|
||||
&mut tcp_connect_waiting,
|
||||
process_sockets.entry(pid).or_default(),
|
||||
);
|
||||
}
|
||||
|
|
@ -718,16 +835,23 @@ fn xmain() -> ! {
|
|||
let pid = msg.sender.pid();
|
||||
std_tcp_tx(
|
||||
msg,
|
||||
&timer,
|
||||
&mut sockets,
|
||||
&mut tcp_tx_waiting,
|
||||
process_sockets.entry(pid).or_default(),
|
||||
);
|
||||
}
|
||||
|
||||
Some(Opcode::StdTcpPeek) => {
|
||||
let pid = msg.sender.pid();
|
||||
std_tcp_peek(msg, &mut sockets, process_sockets.entry(pid).or_default());
|
||||
}
|
||||
|
||||
Some(Opcode::StdTcpRx) => {
|
||||
let pid = msg.sender.pid();
|
||||
std_tcp_rx(
|
||||
msg,
|
||||
&timer,
|
||||
&mut sockets,
|
||||
&mut tcp_rx_waiting,
|
||||
process_sockets.entry(pid).or_default(),
|
||||
|
|
@ -761,6 +885,177 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
Some(Opcode::StdGetAddress) => {
|
||||
let pid = msg.sender.pid();
|
||||
let connection_idx = msg.body.id() >> 16;
|
||||
|
||||
let handle = if let Some(connection) = process_sockets
|
||||
.entry(pid)
|
||||
.or_default()
|
||||
.get_mut(connection_idx)
|
||||
{
|
||||
if let Some(connection) = connection.take() {
|
||||
connection
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
};
|
||||
|
||||
let body = match msg.body.memory_message_mut() {
|
||||
Some(body) => body,
|
||||
None => {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let socket = sockets.get::<TcpSocket>(handle);
|
||||
body.valid = xous::MemorySize::new(
|
||||
write_address(socket.local_endpoint().addr, body.buf.as_slice_mut())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
|
||||
Some(Opcode::StdGetTtl) => {
|
||||
let pid = msg.sender.pid();
|
||||
let connection_idx = msg.body.id() >> 16;
|
||||
// Only work with blockingscalar messages
|
||||
if !msg.body.is_blocking() || msg.body.has_memory() {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
continue;
|
||||
}
|
||||
|
||||
let handle = if let Some(connection) = process_sockets
|
||||
.entry(pid)
|
||||
.or_default()
|
||||
.get_mut(connection_idx)
|
||||
{
|
||||
if let Some(connection) = connection.take() {
|
||||
connection
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
};
|
||||
|
||||
let socket = sockets.get::<TcpSocket>(handle);
|
||||
xous::return_scalar(msg.sender, socket.hop_limit().unwrap_or_default() as usize)
|
||||
.ok();
|
||||
}
|
||||
|
||||
Some(Opcode::StdSetTtl) => {
|
||||
let pid = msg.sender.pid();
|
||||
let connection_idx = msg.body.id() >> 16;
|
||||
// Only work with blockingscalar messages
|
||||
if !msg.body.is_blocking() || msg.body.has_memory() {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
continue;
|
||||
}
|
||||
|
||||
let handle = if let Some(connection) = process_sockets
|
||||
.entry(pid)
|
||||
.or_default()
|
||||
.get_mut(connection_idx)
|
||||
{
|
||||
if let Some(connection) = connection.take() {
|
||||
connection
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
};
|
||||
|
||||
let args = msg.body.scalar_message().unwrap();
|
||||
|
||||
let mut socket = sockets.get::<TcpSocket>(handle);
|
||||
let hop_limit = if args.arg1 == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(args.arg1 as u8)
|
||||
};
|
||||
socket.set_hop_limit(hop_limit);
|
||||
xous::return_scalar(msg.sender, 0).ok();
|
||||
}
|
||||
|
||||
Some(Opcode::StdGetNodelay) => {
|
||||
let pid = msg.sender.pid();
|
||||
let connection_idx = msg.body.id() >> 16;
|
||||
// Only work with blockingscalar messages
|
||||
if !msg.body.is_blocking() || msg.body.has_memory() {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
continue;
|
||||
}
|
||||
|
||||
let handle = if let Some(connection) = process_sockets
|
||||
.entry(pid)
|
||||
.or_default()
|
||||
.get_mut(connection_idx)
|
||||
{
|
||||
if let Some(connection) = connection.take() {
|
||||
connection
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
};
|
||||
|
||||
let socket = sockets.get::<TcpSocket>(handle);
|
||||
xous::return_scalar(
|
||||
msg.sender,
|
||||
if socket.nagle_enabled().is_some() {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
},
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
|
||||
Some(Opcode::StdSetNodelay) => {
|
||||
let pid = msg.sender.pid();
|
||||
let connection_idx = msg.body.id() >> 16;
|
||||
// Only work with blockingscalar messages
|
||||
if !msg.body.is_blocking() || msg.body.has_memory() {
|
||||
respond_with_error(msg, NetError::LibraryError);
|
||||
continue;
|
||||
}
|
||||
|
||||
let handle = if let Some(connection) = process_sockets
|
||||
.entry(pid)
|
||||
.or_default()
|
||||
.get_mut(connection_idx)
|
||||
{
|
||||
if let Some(connection) = connection.take() {
|
||||
connection
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
respond_with_error(msg, NetError::Invalid);
|
||||
continue;
|
||||
};
|
||||
|
||||
let args = msg.body.scalar_message().unwrap();
|
||||
|
||||
let mut socket = sockets.get::<TcpSocket>(handle);
|
||||
socket.set_nagle_enabled(args.arg1 != 0);
|
||||
xous::return_scalar(msg.sender, 0).ok();
|
||||
}
|
||||
|
||||
Some(Opcode::TcpConnect) => {
|
||||
let mut buf = unsafe {
|
||||
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
|
||||
|
|
@ -1431,7 +1726,8 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
Some(Opcode::NetPump) => {
|
||||
let timestamp = Instant::from_millis(timer.elapsed_ms() as i64);
|
||||
let now = timer.elapsed_ms();
|
||||
let timestamp = Instant::from_millis(now as i64);
|
||||
match iface.poll(&mut sockets, timestamp) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
|
|
@ -1480,14 +1776,67 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
// Connect calls take time to establish. This block checks to see if connections
|
||||
// have been made and issues callbacks as necessary.
|
||||
for connection in tcp_connect_waiting.iter_mut() {
|
||||
use smoltcp::socket::TcpState;
|
||||
let socket;
|
||||
let (env, _handle, fd, local_port, remote_port) = {
|
||||
// If the connection is blank, or if it's still waiting to get
|
||||
// connected, don't do anything.
|
||||
match connection {
|
||||
&mut None => continue,
|
||||
Some(s) => {
|
||||
socket = sockets.get::<TcpSocket>(s.1);
|
||||
if socket.state() == TcpState::SynSent
|
||||
|| socket.state() == TcpState::SynReceived
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
connection.take().unwrap()
|
||||
};
|
||||
|
||||
log::trace!("tcp state is {:?}", socket.state());
|
||||
if socket.state() == TcpState::Established {
|
||||
respond_with_connected(env, fd, local_port, remote_port);
|
||||
} else {
|
||||
respond_with_error(env, NetError::TimedOut);
|
||||
}
|
||||
}
|
||||
|
||||
// This block handles TCP Rx for libstd callers
|
||||
for connection in tcp_rx_waiting.iter_mut() {
|
||||
let (env, handle) = match connection {
|
||||
&mut None => continue,
|
||||
Some(s) => s,
|
||||
let mut socket;
|
||||
let WaitingSocket {
|
||||
mut env,
|
||||
handle: _,
|
||||
expiry: _,
|
||||
} = {
|
||||
match connection {
|
||||
&mut None => continue,
|
||||
Some(s) => {
|
||||
socket = sockets.get::<TcpSocket>(s.handle);
|
||||
if !socket.can_recv() {
|
||||
if let Some(trigger) = s.expiry {
|
||||
if trigger.get() < now {
|
||||
// timer expired
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
connection.take().unwrap()
|
||||
};
|
||||
let mut socket = sockets.get::<TcpSocket>(*handle);
|
||||
|
||||
// If it can't receive, then the only explanation was that it timed out
|
||||
if !socket.can_recv() {
|
||||
respond_with_error(env, NetError::TimedOut);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1501,23 +1850,40 @@ fn xmain() -> ! {
|
|||
body.valid = None;
|
||||
}
|
||||
}
|
||||
|
||||
*connection = None;
|
||||
}
|
||||
|
||||
// This block handles TCP Tx for libstd callers
|
||||
for connection in tcp_tx_waiting.iter_mut() {
|
||||
match connection {
|
||||
&mut None => continue,
|
||||
Some(s) => {
|
||||
let socket = sockets.get::<TcpSocket>(s.1);
|
||||
if !socket.can_send() {
|
||||
continue;
|
||||
let mut socket;
|
||||
let WaitingSocket {
|
||||
mut env,
|
||||
handle: _,
|
||||
expiry: _,
|
||||
} = {
|
||||
match connection {
|
||||
&mut None => continue,
|
||||
Some(s) => {
|
||||
socket = sockets.get::<TcpSocket>(s.handle);
|
||||
if !socket.can_send() {
|
||||
if let Some(trigger) = s.expiry {
|
||||
if trigger.get() < now {
|
||||
// timer expired
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
connection.take().unwrap()
|
||||
};
|
||||
let (mut env, handle) = connection.take().unwrap();
|
||||
let mut socket = sockets.get::<TcpSocket>(handle);
|
||||
|
||||
if !socket.can_send() {
|
||||
respond_with_error(env, NetError::TimedOut);
|
||||
continue;
|
||||
}
|
||||
|
||||
let body = env.body.memory_message_mut().unwrap();
|
||||
// Perform the transfer
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
use chrono::Local;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt::Write as StdWrite;
|
||||
use std::fs::OpenOptions;
|
||||
use std::{
|
||||
env,
|
||||
fs::File,
|
||||
|
|
@ -5,10 +9,6 @@ use std::{
|
|||
path::{Path, PathBuf, MAIN_SEPARATOR},
|
||||
process::Command,
|
||||
};
|
||||
use std::fs::OpenOptions;
|
||||
use chrono::Local;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::fmt::Write as StdWrite;
|
||||
|
||||
type DynError = Box<dyn std::error::Error>;
|
||||
|
||||
|
|
@ -69,8 +69,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
];
|
||||
let app_pkgs = [
|
||||
// "standard" demo apps
|
||||
"ball",
|
||||
"repl",
|
||||
"ball", "repl",
|
||||
];
|
||||
let benchmark_pkgs = [
|
||||
"benchmark",
|
||||
|
|
@ -124,7 +123,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
"com",
|
||||
"susres",
|
||||
];
|
||||
let pddb_dev_pkgs = [ // just for checking compilation
|
||||
let pddb_dev_pkgs = [
|
||||
// just for checking compilation
|
||||
"ticktimer-server",
|
||||
"log-server",
|
||||
"susres",
|
||||
|
|
@ -170,7 +170,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
args.nth(1);
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let mut apps: Vec<String> = args.collect();
|
||||
if apps.len() == 0 { // add the standard demo apps if none are specified
|
||||
if apps.len() == 0 {
|
||||
// add the standard demo apps if none are specified
|
||||
println!("No apps specified, adding default apps...");
|
||||
apps.push("ball".to_string());
|
||||
apps.push("repl".to_string());
|
||||
|
|
@ -179,15 +180,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pkgs.push(app);
|
||||
}
|
||||
generate_app_menus(&apps);
|
||||
renode_image(false, &hw_pkgs, &[],
|
||||
None, Some(&["--features", "renode-bypass"]))?
|
||||
},
|
||||
renode_image(
|
||||
false,
|
||||
&hw_pkgs,
|
||||
&[],
|
||||
None,
|
||||
Some(&["--features", "renode-bypass"]),
|
||||
)?
|
||||
}
|
||||
Some("renode-test") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let mut apps: Vec<String> = args.collect();
|
||||
if apps.len() == 0 { // add the standard demo apps if none are specified
|
||||
if apps.len() == 0 {
|
||||
// add the standard demo apps if none are specified
|
||||
println!("No apps specified, adding default apps...");
|
||||
apps.push("ball".to_string());
|
||||
apps.push("repl".to_string());
|
||||
|
|
@ -197,37 +204,52 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
generate_app_menus(&apps);
|
||||
renode_image(false, &cbtest_pkgs, &[], None, None)?
|
||||
},
|
||||
}
|
||||
Some("tts") => {
|
||||
let tmp_dir = tempfile::Builder::new().prefix("bins").tempdir()?;
|
||||
let tts_exec_string = if true {
|
||||
println!("Fetching tts executable from build server...");
|
||||
let tts_exec_name = tmp_dir.path().join("espeak-embedded");
|
||||
let tts_exec_string = tts_exec_name.clone().into_os_string().into_string().unwrap();
|
||||
let tts_exec_string = tts_exec_name
|
||||
.clone()
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap();
|
||||
let mut tts_exec_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(tts_exec_name).expect("Can't open our version file for writing");
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(tts_exec_name)
|
||||
.expect("Can't open our version file for writing");
|
||||
let mut freader = ureq::get("https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded")
|
||||
.call()?
|
||||
.into_reader();
|
||||
std::io::copy(&mut freader, &mut tts_exec_file)?;
|
||||
println!("TTS exec is {} bytes", tts_exec_file.metadata().unwrap().len());
|
||||
println!(
|
||||
"TTS exec is {} bytes",
|
||||
tts_exec_file.metadata().unwrap().len()
|
||||
);
|
||||
tts_exec_string
|
||||
} else {
|
||||
println!("****** WARNING: using local dev image. Do not check this configuration in! ******");
|
||||
"../espeak-embedded/target/riscv32imac-unknown-xous-elf/release/espeak-embedded".to_string()
|
||||
"../espeak-embedded/target/riscv32imac-unknown-xous-elf/release/espeak-embedded"
|
||||
.to_string()
|
||||
};
|
||||
|
||||
let mut locale_override = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("xous-rs/src/locale.rs").expect("Can't open locale for modification");
|
||||
write!(locale_override, "{}", "pub const LANG: &str = \"en-tts\";\n").unwrap();
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("xous-rs/src/locale.rs")
|
||||
.expect("Can't open locale for modification");
|
||||
write!(
|
||||
locale_override,
|
||||
"{}",
|
||||
"pub const LANG: &str = \"en-tts\";\n"
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
|
|
@ -241,18 +263,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pkgs.push("ime-plugin-tts");
|
||||
pkgs.retain(|&pkg| pkg != "ime-plugin-shell");
|
||||
generate_app_menus(&apps);
|
||||
build_hw_image(false,
|
||||
build_hw_image(
|
||||
false,
|
||||
Some("./precursors/soc.svd".to_string()),
|
||||
&pkgs,
|
||||
None, None,
|
||||
Some(&["--features", "tts", "--features", "braille",]),
|
||||
&[&tts_exec_string], None)?;
|
||||
None,
|
||||
None,
|
||||
Some(&["--features", "tts", "--features", "braille"]),
|
||||
&[&tts_exec_string],
|
||||
None,
|
||||
)?;
|
||||
let mut locale_revert = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("xous-rs/src/locale.rs").expect("Can't open locale for modification");
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("xous-rs/src/locale.rs")
|
||||
.expect("Can't open locale for modification");
|
||||
write!(locale_revert, "{}", "pub const LANG: &str = \"en\";\n").unwrap();
|
||||
}
|
||||
Some("libstd-test") => {
|
||||
|
|
@ -264,8 +291,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
for program in &args {
|
||||
extra_packages.push(program.as_str());
|
||||
}
|
||||
renode_image(false, &pkgs, extra_packages.as_slice(),
|
||||
None, Some(&["--features", "renode-bypass"]))?;
|
||||
renode_image(
|
||||
false,
|
||||
&pkgs,
|
||||
extra_packages.as_slice(),
|
||||
None,
|
||||
Some(&["--features", "renode-bypass"]),
|
||||
)?;
|
||||
}
|
||||
Some("ffi-test") => {
|
||||
let mut args = env::args();
|
||||
|
|
@ -278,8 +310,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
for program in &args {
|
||||
extra_packages.push(program.as_str());
|
||||
}
|
||||
build_hw_image(false, Some("./precursors/soc.svd".to_string()),
|
||||
&pkgs, None, None, None, &[], Some(&["--features", "renode-bypass"]))?
|
||||
build_hw_image(
|
||||
false,
|
||||
Some("./precursors/soc.svd".to_string()),
|
||||
&pkgs,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&[],
|
||||
Some(&["--features", "renode-bypass"]),
|
||||
)?
|
||||
//renode_image(false, &pkgs, extra_packages.as_slice(),
|
||||
//None, Some(&["--features", "renode-bypass"]))?;
|
||||
}
|
||||
|
|
@ -291,37 +331,43 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pkgs.push("com");
|
||||
pkgs.push("llio");
|
||||
pkgs.push("dns");
|
||||
pkgs.push("libstd-test");
|
||||
let args: Vec<String> = args.collect();
|
||||
let mut extra_packages = vec![];
|
||||
for program in &args {
|
||||
extra_packages.push(program.as_str());
|
||||
}
|
||||
renode_image(false, &pkgs, extra_packages.as_slice(),
|
||||
Some(&["--features", "renode-minimal"]),
|
||||
Some(&["--features", "renode-bypass"]))?;
|
||||
renode_image(
|
||||
false,
|
||||
&pkgs,
|
||||
extra_packages.as_slice(),
|
||||
Some(&["--features", "renode-minimal"]),
|
||||
Some(&["--features", "renode-bypass"]),
|
||||
)?;
|
||||
}
|
||||
Some("renode-aes-test") => {
|
||||
generate_app_menus(&Vec::<String>::new());
|
||||
renode_image(false, &aestest_pkgs, &[], None, None)?
|
||||
},
|
||||
}
|
||||
Some("renode-image-debug") => {
|
||||
generate_app_menus(&vec!["ball".to_string()]);
|
||||
renode_image(true, &hw_pkgs, &[], None, None)?
|
||||
},
|
||||
}
|
||||
Some("pddb-ci") => {
|
||||
generate_app_menus(&Vec::<String>::new());
|
||||
run(false, &hw_pkgs, Some(
|
||||
&["--features", "pddb/ci", "--features", "pddb/deterministic"],
|
||||
),
|
||||
false,
|
||||
)?},
|
||||
run(
|
||||
false,
|
||||
&hw_pkgs,
|
||||
Some(&["--features", "pddb/ci", "--features", "pddb/deterministic"]),
|
||||
false,
|
||||
)?
|
||||
}
|
||||
Some("run") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let mut apps: Vec<String> = args.collect();
|
||||
if apps.len() == 0 { // add the standard demo apps if none are specified
|
||||
if apps.len() == 0 {
|
||||
// add the standard demo apps if none are specified
|
||||
println!("No apps specified, adding default apps...");
|
||||
apps.push("ball".to_string());
|
||||
apps.push("repl".to_string());
|
||||
|
|
@ -331,7 +377,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
generate_app_menus(&apps);
|
||||
run(false, &pkgs, None, false)?
|
||||
},
|
||||
}
|
||||
Some("hosted-ci") => {
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let mut apps: Vec<String> = args.collect();
|
||||
|
|
@ -342,13 +388,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
generate_app_menus(&apps);
|
||||
run(false, &pkgs, None, true)?
|
||||
},
|
||||
}
|
||||
Some("debug") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
let mut pkgs = hw_pkgs.to_vec();
|
||||
let mut apps: Vec<String> = args.collect();
|
||||
if apps.len() == 0 { // add the standard demo apps if none are specified
|
||||
if apps.len() == 0 {
|
||||
// add the standard demo apps if none are specified
|
||||
println!("No apps specified, adding default apps...");
|
||||
apps.push("ball".to_string());
|
||||
apps.push("repl".to_string());
|
||||
|
|
@ -358,7 +405,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
generate_app_menus(&apps);
|
||||
run(true, &pkgs, None, false)?
|
||||
},
|
||||
}
|
||||
Some("app-image") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
|
|
@ -368,10 +415,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pkgs.push(app);
|
||||
}
|
||||
generate_app_menus(&apps);
|
||||
build_hw_image(false,
|
||||
build_hw_image(
|
||||
false,
|
||||
Some("./precursors/soc.svd".to_string()),
|
||||
&pkgs,
|
||||
lkey, kkey, None, &[], None)?
|
||||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[],
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("hw-image") => {
|
||||
let mut pkgs = vec![];
|
||||
|
|
@ -386,12 +439,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
app_strs.push(app.to_string());
|
||||
}
|
||||
generate_app_menus(&app_strs);
|
||||
build_hw_image(false, env::args().nth(2),
|
||||
&pkgs, lkey, kkey, None, &[], None)?
|
||||
}
|
||||
Some("gfx-dev") => {
|
||||
run(true, &gfx_dev_pkgs, Some(&["--features", "graphics-server/testing"]), false)?
|
||||
build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[],
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("gfx-dev") => run(
|
||||
true,
|
||||
&gfx_dev_pkgs,
|
||||
Some(&["--features", "graphics-server/testing"]),
|
||||
false,
|
||||
)?,
|
||||
Some("pddb-dev") => build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
|
|
@ -399,7 +463,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[], None,
|
||||
&[],
|
||||
None,
|
||||
)?,
|
||||
Some("pddb-hosted") => run(false, &pddb_dev_pkgs, None, false)?,
|
||||
Some("benchmark") => build_hw_image(
|
||||
|
|
@ -409,7 +474,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[], None,
|
||||
&[],
|
||||
None,
|
||||
)?,
|
||||
Some("minimal") => build_hw_image(
|
||||
false,
|
||||
|
|
@ -418,7 +484,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[], None,
|
||||
&[],
|
||||
None,
|
||||
)?,
|
||||
Some("cbtest") => build_hw_image(
|
||||
false,
|
||||
|
|
@ -427,45 +494,58 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
lkey,
|
||||
kkey,
|
||||
None,
|
||||
&[], None,
|
||||
&[],
|
||||
None,
|
||||
)?,
|
||||
Some("trng-test") => {
|
||||
generate_app_menus(&Vec::<String>::new());
|
||||
build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "urandomtest"]),
|
||||
&[], None,
|
||||
)?},
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "urandomtest"]),
|
||||
&[],
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("ro-test") => {
|
||||
generate_app_menus(&Vec::<String>::new());
|
||||
build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "ringosctest"]),
|
||||
&[], None,
|
||||
)?},
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "ringosctest"]),
|
||||
&[],
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("av-test") => {
|
||||
generate_app_menus(&Vec::<String>::new());
|
||||
build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "avalanchetest"]),
|
||||
&[],
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("sr-test") => build_hw_image(
|
||||
false,
|
||||
env::args().nth(2),
|
||||
&hw_pkgs,
|
||||
&sr_pkgs,
|
||||
lkey,
|
||||
kkey,
|
||||
Some(&["--features", "avalanchetest"]),
|
||||
&[], None,
|
||||
)?},
|
||||
Some("sr-test") => {
|
||||
build_hw_image(false, env::args().nth(2),
|
||||
&sr_pkgs, lkey, kkey, None, &[], None)?
|
||||
}
|
||||
None,
|
||||
&[],
|
||||
None,
|
||||
)?,
|
||||
Some("burn-kernel") => update_usb(true, false, false, false)?,
|
||||
Some("burn-loader") => update_usb(false, true, false, false)?,
|
||||
Some("nuke-soc") => update_usb(false, false, true, false)?,
|
||||
|
|
@ -539,21 +619,26 @@ fn update_usb(
|
|||
println!("Burning kernel. After this is done, you must select 'Sign xous update' to self-sign the image.");
|
||||
let stdout = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", "python",
|
||||
"tools/usb_update.py", "-k", "target/riscv32imac-unknown-xous-elf/release/xous.img"])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.args([
|
||||
"/C",
|
||||
"python",
|
||||
"tools/usb_update.py",
|
||||
"-k",
|
||||
"target/riscv32imac-unknown-xous-elf/release/xous.img",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
} else {
|
||||
Command::new("python3")
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-k")
|
||||
.arg("target/riscv32imac-unknown-xous-elf/release/xous.img")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-k")
|
||||
.arg("target/riscv32imac-unknown-xous-elf/release/xous.img")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
};
|
||||
|
||||
let reader = BufReader::new(stdout);
|
||||
|
|
@ -565,21 +650,26 @@ fn update_usb(
|
|||
println!("Burning loader. After this is done, you must select 'Sign xous update' to self-sign the image.");
|
||||
let stdout = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", "python", "tools/usb_update.py",
|
||||
"-l", "target/riscv32imac-unknown-xous-elf/release/loader.bin"])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.args([
|
||||
"/C",
|
||||
"python",
|
||||
"tools/usb_update.py",
|
||||
"-l",
|
||||
"target/riscv32imac-unknown-xous-elf/release/loader.bin",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
} else {
|
||||
Command::new("python3")
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-l")
|
||||
.arg("target/riscv32imac-unknown-xous-elf/release/loader.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-l")
|
||||
.arg("target/riscv32imac-unknown-xous-elf/release/loader.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
};
|
||||
|
||||
let reader = BufReader::new(stdout);
|
||||
|
|
@ -591,21 +681,26 @@ fn update_usb(
|
|||
println!("Staging SoC gateware. After this is done, you must select 'Install Gateware Update' from the root menu of your Precursor device.");
|
||||
let stdout = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", "python", "tools/usb_update.py",
|
||||
"-s", "precursors/soc_csr.bin"])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.args([
|
||||
"/C",
|
||||
"python",
|
||||
"tools/usb_update.py",
|
||||
"-s",
|
||||
"precursors/soc_csr.bin",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
} else {
|
||||
Command::new("python3")
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-s")
|
||||
.arg("precursors/soc_csr.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("-s")
|
||||
.arg("precursors/soc_csr.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
};
|
||||
|
||||
let reader = BufReader::new(stdout);
|
||||
|
|
@ -617,21 +712,26 @@ fn update_usb(
|
|||
println!("Installing factory-reset SoC gateware (secrets will be lost)!");
|
||||
let stdout = if cfg!(traget_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", "python", "tools/usb_update.py",
|
||||
"--soc", "precursors/soc_csr.bin"])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.args([
|
||||
"/C",
|
||||
"python",
|
||||
"tools/usb_update.py",
|
||||
"--soc",
|
||||
"precursors/soc_csr.bin",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
} else {
|
||||
Command::new("python3")
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("--soc")
|
||||
.arg("precursors/soc_csr.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
.arg("tools/usb_update.py")
|
||||
.arg("--soc")
|
||||
.arg("precursors/soc_csr.bin")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "Could not capture output"))?
|
||||
};
|
||||
let reader = BufReader::new(stdout);
|
||||
reader
|
||||
|
|
@ -673,7 +773,14 @@ fn build_hw_image(
|
|||
|
||||
let kernel = build_kernel(debug)?;
|
||||
let mut init = vec![];
|
||||
let base_path = build(packages, debug, Some(PROGRAM_TARGET), None, extra_args, None)?;
|
||||
let base_path = build(
|
||||
packages,
|
||||
debug,
|
||||
Some(PROGRAM_TARGET),
|
||||
None,
|
||||
extra_args,
|
||||
None,
|
||||
)?;
|
||||
for pkg in packages {
|
||||
let mut pkg_path = base_path.clone();
|
||||
// some packages may have a colon-delimited version after it to clarify crates.io patches.
|
||||
|
|
@ -697,7 +804,8 @@ fn build_hw_image(
|
|||
debug,
|
||||
Some(KERNEL_TARGET),
|
||||
Some("loader".into()),
|
||||
None, loader_features,
|
||||
None,
|
||||
loader_features,
|
||||
)?;
|
||||
loader.push(PathBuf::from("loader"));
|
||||
|
||||
|
|
@ -842,7 +950,12 @@ fn renode_image(
|
|||
)
|
||||
}
|
||||
|
||||
fn run(debug: bool, init: &[&str], features: Option<&[&str]>, dry_run: bool) -> Result<(), DynError> {
|
||||
fn run(
|
||||
debug: bool,
|
||||
init: &[&str],
|
||||
features: Option<&[&str]>,
|
||||
dry_run: bool,
|
||||
) -> Result<(), DynError> {
|
||||
let stream = if debug { "debug" } else { "release" };
|
||||
|
||||
build(init, debug, None, None, None, features)?;
|
||||
|
|
@ -888,13 +1001,7 @@ fn run(debug: bool, init: &[&str], features: Option<&[&str]>, dry_run: bool) ->
|
|||
}
|
||||
|
||||
fn build_kernel(debug: bool) -> Result<PathBuf, DynError> {
|
||||
let mut path = build(
|
||||
&["kernel"],
|
||||
debug,
|
||||
Some(KERNEL_TARGET),
|
||||
None,
|
||||
None, None,
|
||||
)?;
|
||||
let mut path = build(&["kernel"], debug, Some(KERNEL_TARGET), None, None, None)?;
|
||||
path.push("kernel");
|
||||
Ok(path)
|
||||
}
|
||||
|
|
@ -1266,14 +1373,13 @@ fn generate_locales() -> Result<(), std::io::Error> {
|
|||
path.push("locales");
|
||||
let status = Command::new(cargo())
|
||||
.current_dir(path)
|
||||
.args(&[
|
||||
"build",
|
||||
"--package",
|
||||
"locales",
|
||||
])
|
||||
.args(&["build", "--package", "locales"])
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Couldn't generate the locales"));
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Couldn't generate the locales",
|
||||
));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -1306,15 +1412,15 @@ fn whycheproof_import() -> Result<(), DynError> {
|
|||
fn generate_version() {
|
||||
let output = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", "git describe --tags"])
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
.args(["/C", "git describe --tags"])
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
} else {
|
||||
Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg("git describe --tags")
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
.arg("-c")
|
||||
.arg("git describe --tags")
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
};
|
||||
let gitver = output.stdout;
|
||||
let semver = String::from_utf8_lossy(&gitver);
|
||||
|
|
@ -1324,18 +1430,27 @@ fn generate_version() {
|
|||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open("services/ticktimer-server/src/version.rs").expect("Can't open our version file for writing");
|
||||
.open("services/ticktimer-server/src/version.rs")
|
||||
.expect("Can't open our version file for writing");
|
||||
print_header(&mut vfile);
|
||||
#[cfg(not(feature="no-timestamp"))]
|
||||
#[cfg(not(feature = "no-timestamp"))]
|
||||
let now = Local::now();
|
||||
#[cfg(not(feature="no-timestamp"))]
|
||||
write!(vfile, "#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"{}\";\n", now.to_rfc2822()).expect("couldn't add our timestamp");
|
||||
write!(vfile, "pub const SEMVER: &'static str = \"{}\";\n",
|
||||
#[cfg(not(feature = "no-timestamp"))]
|
||||
write!(
|
||||
vfile,
|
||||
"#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"{}\";\n",
|
||||
now.to_rfc2822()
|
||||
)
|
||||
.expect("couldn't add our timestamp");
|
||||
write!(
|
||||
vfile,
|
||||
"pub const SEMVER: &'static str = \"{}\";\n",
|
||||
semver
|
||||
.strip_suffix("\r\n")
|
||||
.or(semver.strip_suffix("\n"))
|
||||
.unwrap_or(&semver)
|
||||
).expect("couldn't add our semver");
|
||||
.strip_suffix("\r\n")
|
||||
.or(semver.strip_suffix("\n"))
|
||||
.unwrap_or(&semver)
|
||||
)
|
||||
.expect("couldn't add our semver");
|
||||
}
|
||||
|
||||
fn print_header<U: Write>(out: &mut U) {
|
||||
|
|
@ -1355,7 +1470,8 @@ pub(crate) fn get_version() -> crate::api::VersionString {
|
|||
v
|
||||
}
|
||||
"####;
|
||||
out.write_all(s.as_bytes()).expect("couldn't write our version template header");
|
||||
out.write_all(s.as_bytes())
|
||||
.expect("couldn't write our version template header");
|
||||
}
|
||||
|
||||
////////////////////////// App manifest infrastructure
|
||||
|
|
@ -1371,7 +1487,7 @@ struct Locales {
|
|||
locales: HashMap<String, HashMap<String, String>>,
|
||||
}
|
||||
|
||||
fn generate_app_menus(apps: &Vec::<String>) {
|
||||
fn generate_app_menus(apps: &Vec<String>) {
|
||||
let file = File::open("apps/manifest.json").expect("Failed to open the manifest file");
|
||||
let mut reader = std::io::BufReader::new(file);
|
||||
let mut content = String::new();
|
||||
|
|
@ -1384,7 +1500,7 @@ fn generate_app_menus(apps: &Vec::<String>) {
|
|||
// localization file
|
||||
// inject all the localization strings into the i18n file, which in theory reduces the churn on other crates that depend
|
||||
// on the global i18n file between build variants
|
||||
let mut l = BTreeMap::<String, BTreeMap::<String, String>>::new();
|
||||
let mut l = BTreeMap::<String, BTreeMap<String, String>>::new();
|
||||
for (_app, manifest) in manifest.iter() {
|
||||
for (name, translations) in &manifest.menu_name {
|
||||
let mut map = BTreeMap::<String, String>::new();
|
||||
|
|
@ -1409,25 +1525,38 @@ fn generate_app_menus(apps: &Vec::<String>) {
|
|||
|
||||
// construct the gam_tokens
|
||||
let mut gam_tokens = String::new();
|
||||
writeln!(gam_tokens, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
|
||||
writeln!(
|
||||
gam_tokens,
|
||||
"// This file is auto-generated by xtask/main.rs generate_app_menus()"
|
||||
)
|
||||
.unwrap();
|
||||
for (app_name, manifest) in working_set.iter() {
|
||||
writeln!(gam_tokens, "pub const APP_NAME_{}: &'static str = \"{}\";",
|
||||
writeln!(
|
||||
gam_tokens,
|
||||
"pub const APP_NAME_{}: &'static str = \"{}\";",
|
||||
app_name.to_uppercase(),
|
||||
manifest.context_name,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
writeln!(gam_tokens, "\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &[").unwrap();
|
||||
writeln!(
|
||||
gam_tokens,
|
||||
"\npub const EXPECTED_APP_CONTEXTS: &[&'static str] = &["
|
||||
)
|
||||
.unwrap();
|
||||
for (app_name, _manifest) in working_set.iter() {
|
||||
writeln!(gam_tokens, " APP_NAME_{},",
|
||||
app_name.to_uppercase(),
|
||||
).unwrap();
|
||||
writeln!(gam_tokens, " APP_NAME_{},", app_name.to_uppercase(),).unwrap();
|
||||
}
|
||||
writeln!(gam_tokens, "];").unwrap();
|
||||
overwrite_if_changed(&gam_tokens, "services/gam/src/apps.rs");
|
||||
|
||||
// construct the app menu
|
||||
let mut menu = String::new();
|
||||
writeln!(menu, "// This file is auto-generated by xtask/main.rs generate_app_menus()").unwrap();
|
||||
writeln!(
|
||||
menu,
|
||||
"// This file is auto-generated by xtask/main.rs generate_app_menus()"
|
||||
)
|
||||
.unwrap();
|
||||
if apps.len() == 0 {
|
||||
writeln!(menu, "// NO APPS SELECTED: suppressing warning messages!").unwrap();
|
||||
writeln!(menu, "#![allow(dead_code)]").unwrap();
|
||||
|
|
@ -1458,44 +1587,73 @@ impl fmt::Display for AppDispatchError {{
|
|||
pub(crate) fn app_dispatch(gam: &gam::Gam, token: [u32; 4], index: usize) -> Result<(), AppDispatchError> {{
|
||||
match index {{"####).unwrap();
|
||||
for (index, (app_name, _manifest)) in working_set.iter().enumerate() {
|
||||
writeln!(menu, " {} => {{
|
||||
writeln!(
|
||||
menu,
|
||||
" {} => {{
|
||||
gam.switch_to_app(gam::APP_NAME_{}, token).expect(\"couldn't raise app\");
|
||||
Ok(())
|
||||
}},",
|
||||
index,
|
||||
app_name.to_uppercase()
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
writeln!(menu, r####" _ => Err(AppDispatchError::IndexNotFound(index)),
|
||||
writeln!(
|
||||
menu,
|
||||
r####" _ => Err(AppDispatchError::IndexNotFound(index)),
|
||||
}}
|
||||
}}
|
||||
|
||||
pub(crate) fn app_index_to_name(index: usize) -> Result<&'static str, AppDispatchError> {{
|
||||
match index {{"####).unwrap();
|
||||
match index {{"####
|
||||
)
|
||||
.unwrap();
|
||||
for (index, (_, _manifest)) in working_set.iter().enumerate() {
|
||||
for name in _manifest.menu_name.keys() {
|
||||
writeln!(menu, " {} => Ok(t!(\"{}\", xous::LANG)),",
|
||||
index,
|
||||
name,
|
||||
).unwrap();
|
||||
writeln!(
|
||||
menu,
|
||||
" {} => Ok(t!(\"{}\", xous::LANG)),",
|
||||
index, name,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
writeln!(menu, r####" _ => Err(AppDispatchError::IndexNotFound(index)),
|
||||
writeln!(
|
||||
menu,
|
||||
r####" _ => Err(AppDispatchError::IndexNotFound(index)),
|
||||
}}
|
||||
}}
|
||||
|
||||
pub(crate) fn app_menu_items(menu_items: &mut Vec::<MenuItem>, status_conn: u32) {{
|
||||
"####).unwrap();
|
||||
"####
|
||||
)
|
||||
.unwrap();
|
||||
for (index, (_app_name, manifest)) in working_set.iter().enumerate() {
|
||||
writeln!(menu, " menu_items.push(MenuItem {{",).unwrap();
|
||||
assert!(manifest.menu_name.len() == 1, "Improper menu name record entry");
|
||||
assert!(
|
||||
manifest.menu_name.len() == 1,
|
||||
"Improper menu name record entry"
|
||||
);
|
||||
for name in manifest.menu_name.keys() {
|
||||
writeln!(menu, " name: xous_ipc::String::from_str(t!(\"{}\", xous::LANG)),",
|
||||
name).unwrap();
|
||||
writeln!(
|
||||
menu,
|
||||
" name: xous_ipc::String::from_str(t!(\"{}\", xous::LANG)),",
|
||||
name
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
writeln!(menu, " action_conn: Some(status_conn),",).unwrap();
|
||||
writeln!(menu, " action_opcode: StatusOpcode::SwitchToApp.to_u32().unwrap(),",).unwrap();
|
||||
writeln!(menu, " action_payload: MenuPayload::Scalar([{}, 0, 0, 0]),", index).unwrap();
|
||||
writeln!(
|
||||
menu,
|
||||
" action_opcode: StatusOpcode::SwitchToApp.to_u32().unwrap(),",
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(
|
||||
menu,
|
||||
" action_payload: MenuPayload::Scalar([{}, 0, 0, 0]),",
|
||||
index
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(menu, " close_on_select: true,",).unwrap();
|
||||
writeln!(menu, " }});\n",).unwrap();
|
||||
}
|
||||
|
|
@ -1504,25 +1662,24 @@ pub(crate) fn app_menu_items(menu_items: &mut Vec::<MenuItem>, status_conn: u32)
|
|||
}
|
||||
|
||||
fn overwrite_if_changed(new_string: &String, old_file: &str) {
|
||||
let original = match OpenOptions::new()
|
||||
.read(true)
|
||||
.open(old_file) {
|
||||
let original = match OpenOptions::new().read(true).open(old_file) {
|
||||
Ok(mut ref_file) => {
|
||||
let mut buf = String::new();
|
||||
ref_file.read_to_string(&mut buf).expect("UTF-8 error in previous localization file");
|
||||
ref_file
|
||||
.read_to_string(&mut buf)
|
||||
.expect("UTF-8 error in previous localization file");
|
||||
buf
|
||||
}
|
||||
_ => {
|
||||
String::new()
|
||||
}
|
||||
_ => String::new(),
|
||||
};
|
||||
if &original != new_string {
|
||||
let mut new_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(old_file).expect("Can't open our gam manifest for writing");
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(old_file)
|
||||
.expect("Can't open our gam manifest for writing");
|
||||
write!(new_file, "{}", new_string).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue