Skip to content

Commit

Permalink
run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslashev committed Sep 25, 2023
1 parent 8130d60 commit dbcbb98
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
16 changes: 10 additions & 6 deletions bmcd/src/into_legacy_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,18 @@ pub type LegacyResult<T> = Result<T, LegacyResponse>;
impl From<LegacyResponse> for HttpResponse {
fn from(value: LegacyResponse) -> Self {
let (response, result, is_uart) = match value {
LegacyResponse::Success(None) => {
(StatusCode::OK, serde_json::Value::String("ok".to_string()), false)
}
LegacyResponse::Success(None) => (
StatusCode::OK,
serde_json::Value::String("ok".to_string()),
false,
),
LegacyResponse::Success(Some(body)) => (StatusCode::OK, body, false),
LegacyResponse::UartData(d) => (StatusCode::OK, serde_json::Value::String(d), true),
LegacyResponse::Error(status_code, msg) => {
(status_code, serde_json::Value::String(msg.into_owned()), false)
}
LegacyResponse::Error(status_code, msg) => (
status_code,
serde_json::Value::String(msg.into_owned()),
false,
),
};

let msg = if is_uart {
Expand Down
12 changes: 8 additions & 4 deletions bmcd/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn api_entry(bmc: web::Data<BmcApplication>, query: Query) -> impl Respond
};

let Some(ty) = query.get("type") else {
return LegacyResponse::bad_request("Missing `type` parameter")
return LegacyResponse::bad_request("Missing `type` parameter");
};

let bmc = bmc.as_ref();
Expand Down Expand Up @@ -144,11 +144,15 @@ fn get_node_param(query: &Query) -> LegacyResult<NodeId> {
};

let Ok(node_num) = i32::from_str(node_str) else {
return Err(LegacyResponse::bad_request("Parameter `node` is not a number"));
return Err(LegacyResponse::bad_request(
"Parameter `node` is not a number",
));
};

let Ok(node) = node_num.try_into() else {
return Err(LegacyResponse::bad_request("Parameter `node` is out of range 0..3 of node IDs"));
return Err(LegacyResponse::bad_request(
"Parameter `node` is out of range 0..3 of node IDs",
));
};

Ok(node)
Expand Down Expand Up @@ -286,7 +290,7 @@ fn get_sdcard_fs_stat() -> anyhow::Result<(u64, u64)> {
async fn write_to_uart(bmc: &BmcApplication, query: Query) -> LegacyResult<()> {
let node = get_node_param(&query)?;
let Some(cmd) = query.get("cmd") else {
return Err(LegacyResponse::bad_request("Missing `cmd` parameter"));
return Err(LegacyResponse::bad_request("Missing `cmd` parameter"));
};
let mut data = cmd.clone();

Expand Down
4 changes: 2 additions & 2 deletions tpi_rs/src/c_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub extern "C" fn tpi_get_node_power(node: c_int) -> c_int {
#[no_mangle]
pub extern "C" fn tpi_reset_node(node: c_int) {
let Ok(node_id) = node.try_into().map_err(|e| log::error!("{}", e)) else {
return ;
return;
};
execute_routine(|bmc| Box::pin(bmc.reset_node(node_id)));
}
Expand Down Expand Up @@ -211,7 +211,7 @@ pub unsafe extern "C" fn tpi_flash_node(node: c_int, image_path: *const c_char)
let node_image = PathBuf::from(bstr);

let Ok(node_id) = node.try_into() else {
return FlashingResult::InvalidArgs
return FlashingResult::InvalidArgs;
};

RUNTIME.block_on(async move {
Expand Down
19 changes: 12 additions & 7 deletions tpi_rs/src/middleware/firmware_update/rockusb_fwudate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::transport::{StdFwUpdateTransport, StdTransportWrapper};
use rusb::DeviceDescriptor;
use super::{FlashProgress, FlashingError, FlashingErrorExt};
use crate::middleware::firmware_update::FlashStatus;
use crate::middleware::usbboot;
Expand All @@ -9,6 +8,7 @@ use rockfile::boot::{
RkBootEntry, RkBootEntryBytes, RkBootHeader, RkBootHeaderBytes, RkBootHeaderEntry,
};
use rockusb::libusb::{Transport, TransportIO};
use rusb::DeviceDescriptor;
use rusb::GlobalContext;
use std::{mem::size_of, ops::Range, time::Duration};
use tokio::sync::mpsc::Sender;
Expand All @@ -23,7 +23,12 @@ pub async fn new_rockusb_transport(
let mut transport = Transport::from_usb_device(device.open().map_err_into_logged_usb(logging)?)
.map_err(|_| FlashingError::UsbError)?;

if BootMode::Maskrom == device.device_descriptor().map_err_into_logged_usb(logging)?.into() {
if BootMode::Maskrom
== device
.device_descriptor()
.map_err_into_logged_usb(logging)?
.into()
{
info!("Maskrom mode detected. loading usb-plug..");
transport = download_boot(&mut transport, logging).await?;
logging
Expand Down Expand Up @@ -134,10 +139,10 @@ async fn load_boot_entries(
}

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum BootMode {
pub enum BootMode {
Maskrom = 0,
Loader = 1,
}
Loader = 1,
}

impl From<DeviceDescriptor> for BootMode {
fn from(dd: DeviceDescriptor) -> BootMode {
Expand All @@ -146,5 +151,5 @@ impl From<DeviceDescriptor> for BootMode {
1 => BootMode::Loader,
_ => unreachable!(),
}
}
}
}
}

0 comments on commit dbcbb98

Please sign in to comment.