Skip to content

Commit

Permalink
rockusb_fwudate: Update bootmode detection
Browse files Browse the repository at this point in the history
After discussion with the maintainers, decided is to keep the Bootmode
detection logic local to this project. There is no generic solution
possible that works for all rockusb devices. Detection is based on
behavior of the loader that is installed on the rockchip device, no
spec exists that guarantees a certain behavior of this loader.
see collabora/rockchiprs#22

Updated the rockusb dependency to the main branch, as one of the latest
patches are required.
  • Loading branch information
svenrademakers committed Sep 8, 2023
1 parent 8e6c5a4 commit a7bcad4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tpi_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ evdev = { version = "0.12.1", features = ["tokio"] }
gpiod = { version = "0.2.3", default-features = false }
once_cell = "1.18.0"
rockfile = { version = "0.1.0"}
rockusb = { git = "https://github.com/svenrademakers/rockchiprs.git", branch="main"}
rockusb = { version = "0.1.0" }
rusb = "0.9.2"
rustpiboot = { git = "https://github.com/ruslashev/rustpiboot.git", rev="89e6497"}
serde = { version = "1.0.183", features = ["derive"] }
Expand All @@ -30,3 +30,6 @@ simple_logger.workspace = true
tokio.workspace = true
tokio-util.workspace = true
futures.workspace = true

[patch.crates-io]
rockusb = { git= "https://github.com/collabora/rockchiprs", rev = "dc90ab5" }
22 changes: 19 additions & 3 deletions tpi_rs/src/middleware/firmware_update/rockusb_fwudate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -7,7 +8,6 @@ use log::info;
use rockfile::boot::{
RkBootEntry, RkBootEntryBytes, RkBootHeader, RkBootHeaderBytes, RkBootHeaderEntry,
};
use rockusb::libusb::BootMode;
use rockusb::libusb::{Transport, TransportIO};
use rusb::GlobalContext;
use std::{mem::size_of, ops::Range, time::Duration};
Expand All @@ -23,8 +23,8 @@ 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 let Ok(BootMode::MaskedRom) = transport.boot_mode() {
info!("MaskedRom mode detected. loading usb-plug..");
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
.try_send(FlashProgress {
Expand Down Expand Up @@ -132,3 +132,19 @@ async fn load_boot_entries(
log::debug!("written {} bytes", size);
Ok(())
}

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

impl From<DeviceDescriptor> for BootMode {
fn from(dd: DeviceDescriptor) -> BootMode {
match dd.usb_version().sub_minor() & 0x1 {
0 => BootMode::Maskrom,
1 => BootMode::Loader,
_ => unreachable!(),
}
}
}

0 comments on commit a7bcad4

Please sign in to comment.