coremgmt: fix import/uses

This commit is contained in:
occheung 2024-09-05 12:16:57 +08:00
parent 47d418c69e
commit 7da5061f7e
2 changed files with 37 additions and 40 deletions

View File

@ -3,19 +3,18 @@ use core::{cell::RefCell, ops::Deref};
use futures::{future::poll_fn, task::Poll}; use futures::{future::poll_fn, task::Poll};
use libasync::{smoltcp::TcpStream, task}; use libasync::{smoltcp::TcpStream, task};
use libboard_artiq::{drtio_routing, use libboard_artiq::{drtio_routing::RoutingTable,
drtio_routing::RoutingTable,
logger::{BufferLogger, LogBufferRef}}; logger::{BufferLogger, LogBufferRef}};
use libboard_zynq::{slcr, smoltcp, timer::GlobalTimer}; use libboard_zynq::{smoltcp, timer::GlobalTimer};
use libconfig::Config; use libconfig::Config;
use libcortex_a9::{mutex::Mute, semaphore::Semaphore}; use libcortex_a9::{mutex::Mutex, semaphore::Semaphore};
use log::{self, debug, error, info, warn, LevelFilter}; use log::{self, debug, error, info, warn};
use num_derive::FromPrimitive; use num_derive::FromPrimitive;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use crate::proto_async::*; use crate::proto_async::*;
#[cfg(has_drtio)] #[cfg(has_drtio)]
use crate::rtio_mgt::*; use crate::rtio_mgt::drtio;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error { pub enum Error {
@ -140,12 +139,11 @@ mod remote_coremgmt {
drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE}}; drtioaux_proto::{Packet, MASTER_PAYLOAD_MAX_SIZE}};
use super::*; use super::*;
use crate::rtio_mgt::drtio;
pub async fn get_log( pub async fn get_log(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -190,7 +188,7 @@ mod remote_coremgmt {
pub async fn clear_log( pub async fn clear_log(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -225,7 +223,7 @@ mod remote_coremgmt {
pub async fn pull_log( pub async fn pull_log(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -276,11 +274,11 @@ mod remote_coremgmt {
pub async fn set_log_filter( pub async fn set_log_filter(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
level: LevelFilter, level: log::LevelFilter,
) -> Result<()> { ) -> Result<()> {
let reply = drtio::aux_transact( let reply = drtio::aux_transact(
aux_mutex, aux_mutex,
@ -315,11 +313,11 @@ mod remote_coremgmt {
pub async fn set_uart_log_filter( pub async fn set_uart_log_filter(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
level: LevelFilter, level: log::LevelFilter,
) -> Result<()> { ) -> Result<()> {
let reply = drtio::aux_transact( let reply = drtio::aux_transact(
aux_mutex, aux_mutex,
@ -354,7 +352,7 @@ mod remote_coremgmt {
pub async fn config_read( pub async fn config_read(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -418,7 +416,7 @@ mod remote_coremgmt {
pub async fn config_write( pub async fn config_write(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -468,7 +466,7 @@ mod remote_coremgmt {
pub async fn config_remove( pub async fn config_remove(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -514,7 +512,7 @@ mod remote_coremgmt {
pub async fn config_erase( pub async fn config_erase(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -551,7 +549,7 @@ mod remote_coremgmt {
pub async fn reboot( pub async fn reboot(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -589,7 +587,7 @@ mod remote_coremgmt {
pub async fn debug_allocator( pub async fn debug_allocator(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -624,7 +622,7 @@ mod remote_coremgmt {
pub async fn image_write( pub async fn image_write(
stream: &mut TcpStream, stream: &mut TcpStream,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &drtio_routing::RoutingTable, routing_table: &RoutingTable,
timer: GlobalTimer, timer: GlobalTimer,
linkno: u8, linkno: u8,
destination: u8, destination: u8,
@ -681,6 +679,8 @@ mod remote_coremgmt {
} }
mod local_coremgmt { mod local_coremgmt {
use libboard_zynq::slcr;
use super::*; use super::*;
pub async fn get_log(stream: &mut TcpStream) -> Result<()> { pub async fn get_log(stream: &mut TcpStream) -> Result<()> {
@ -714,25 +714,25 @@ mod local_coremgmt {
buffer.clear(); buffer.clear();
core::mem::drop(buffer); core::mem::drop(buffer);
write_chunk(stream, &bytes).await?; write_chunk(stream, &bytes).await?;
if log::max_level() == LevelFilter::Trace { if log::max_level() == log::LevelFilter::Trace {
// temporarily discard all trace level log // temporarily discard all trace level log
let logger = unsafe { BufferLogger::get_logger().as_mut().unwrap() }; let logger = unsafe { BufferLogger::get_logger().as_mut().unwrap() };
logger.set_buffer_log_level(LevelFilter::Debug); logger.set_buffer_log_level(log::LevelFilter::Debug);
stream.flush().await?; stream.flush().await?;
logger.set_buffer_log_level(LevelFilter::Trace); logger.set_buffer_log_level(log::LevelFilter::Trace);
} }
} }
Ok(()) Ok(())
} }
pub async fn set_log_filter(stream: &mut TcpStream, lvl: LevelFilter) -> Result<()> { pub async fn set_log_filter(stream: &mut TcpStream, lvl: log::LevelFilter) -> Result<()> {
info!("Changing log level to {}", lvl); info!("Changing log level to {}", lvl);
log::set_max_level(lvl); log::set_max_level(lvl);
write_i8(stream, Reply::Success as i8).await?; write_i8(stream, Reply::Success as i8).await?;
Ok(()) Ok(())
} }
pub async fn set_uart_log_filter(stream: &mut TcpStream, lvl: LevelFilter) -> Result<()> { pub async fn set_uart_log_filter(stream: &mut TcpStream, lvl: log::LevelFilter) -> Result<()> {
info!("Changing UART log level to {}", lvl); info!("Changing UART log level to {}", lvl);
unsafe { unsafe {
BufferLogger::get_logger().as_ref().unwrap().set_uart_log_level(lvl); BufferLogger::get_logger().as_ref().unwrap().set_uart_log_level(lvl);
@ -920,11 +920,7 @@ async fn handle_connection(
} }
} }
pub fn start( pub fn start(cfg: Config, restart_idle: Rc<Semaphore>, drtio_tuple: Option<(&Rc<Mutex<bool>>, &Rc<RefCell<RoutingTable>>, GlobalTimer)>) {
cfg: Rc<Config>,
restart_idle: Rc<Semaphore>,
drtio_tuple: Option<(&Rc<Mutex<bool>>, &Rc<RefCell<drtio_routing::RoutingTable>>, GlobalTimer)>,
) {
let drtio_tuple = let drtio_tuple =
drtio_tuple.map(|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer)); drtio_tuple.map(|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer));
task::spawn(async move { task::spawn(async move {

View File

@ -2,24 +2,24 @@ use alloc::vec::Vec;
use byteorder::{ByteOrder, NativeEndian}; use byteorder::{ByteOrder, NativeEndian};
use crc::crc32; use crc::crc32;
use io::{Cursor, ProtoRead, ProtoWrite}; use io::{ProtoRead, ProtoWrite};
use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE, use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE,
logger::{BufferLogger, LogBufferRef}}; logger::{BufferLogger, LogBufferRef}};
use libconfig::Config; use libconfig::Config;
use log::{self, debug, error, info, warn, LevelFilter}; use log::{debug, error, info, warn, LevelFilter};
use crate::routing::{SliceMeta, Sliceable}; use crate::routing::{SliceMeta, Sliceable};
type Result<T> = core::result::Result<T, ()>; type Result<T> = core::result::Result<T, ()>;
pub fn byte_to_level_filter(level_byte: u8) -> Result<log::LevelFilter> { pub fn byte_to_level_filter(level_byte: u8) -> Result<LevelFilter> {
Ok(match level_byte { Ok(match level_byte {
0 => log::LevelFilter::Off, 0 => LevelFilter::Off,
1 => log::LevelFilter::Error, 1 => LevelFilter::Error,
2 => log::LevelFilter::Warn, 2 => LevelFilter::Warn,
3 => log::LevelFilter::Info, 3 => LevelFilter::Info,
4 => log::LevelFilter::Debug, 4 => LevelFilter::Debug,
5 => log::LevelFilter::Trace, 5 => LevelFilter::Trace,
lv => { lv => {
error!("unknown log level: {}", lv); error!("unknown log level: {}", lv);
return Err(()); return Err(());
@ -132,6 +132,7 @@ impl<'a> Manager<'_> {
let actual_crc = crc32::checksum_ieee(image_ref); let actual_crc = crc32::checksum_ieee(image_ref);
if actual_crc == expected_crc { if actual_crc == expected_crc {
info!("CRC passed. Writing boot image to SD card...");
image.truncate(bin_len); image.truncate(bin_len);
self.cfg.write("boot", image).expect("failed to write boot image"); self.cfg.write("boot", image).expect("failed to write boot image");
} else { } else {