Skip to content

Commit

Permalink
merge Recovery to USB options
Browse files Browse the repository at this point in the history
  • Loading branch information
svenrademakers committed Nov 23, 2023
1 parent 748b6a1 commit 2b0106c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
9 changes: 5 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@ pub enum ModeCmd {
/// reboots supported compute modules and expose its eMMC storage as a mass
/// storage device
Msd,
/// Setting the recovery pin high will cause the module to halt after its
/// respective bootROM code. A manual restart is required.
Recovery,
}

#[derive(ValueEnum, Clone, PartialEq, Eq)]
pub enum UsbCmd {
/// Configure the specified node as USB device. The `BMC` itself or USB-A port is USB host
/// Configure the specified node as USB device. The `BMC` itself or USB-A
/// port is USB host
Device,
/// Configure the specified node as USB Host. USB devices can be attached to
/// the USB-A port on the board.
Host,
/// Turns the module into flashing mode and sets the USB_OTG into device
/// mode - use to flash the module using USB_OTG port
Flash,
Status,
}

Expand Down
31 changes: 8 additions & 23 deletions src/legacy_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,14 @@ impl LegacyHandler {
.append_pair("type", "usb")
.append_pair("node", &(node - 1).to_string());

let mut mode = if args.mode == UsbCmd::Host { 0 } else { 1 };
mode |= u8::from(args.bmc) << 1;
let mut mode = match args.mode {
UsbCmd::Host => 0,
UsbCmd::Device => 1,
UsbCmd::Flash => 2,
UsbCmd::Status => panic!("cannot reach here"),
};

mode |= u8::from(args.bmc) << 2;
serializer.append_pair("mode", &mode.to_string());

self.response_printer = Some(result_printer);
Expand Down Expand Up @@ -546,27 +552,6 @@ impl LegacyHandler {
.append_pair("type", "node_to_msd")
.append_pair("node", &(args.node - 1).to_string());
}
crate::cli::ModeCmd::Recovery => {
self.request
.url_mut()
.query_pairs_mut()
.append_pair("opt", "set")
.append_pair("type", "usb_boot")
.append_pair("node", &(args.node - 1).to_string());
let response = self.request.clone().send(self.client.clone()).await?;

if !response.status().is_success() {
bail!(
"could not execute Recovery mode: {}",
response.text().await?
);
}

return self.handle_power_nodes(&PowerArgs {
cmd: PowerCmd::Reset,
node: Some(args.node),
});
}
}
self.response_printer = Some(result_printer);

Expand Down

0 comments on commit 2b0106c

Please sign in to comment.