Skip to content

Commit

Permalink
Merge pull request #28 from collabora/nusb
Browse files Browse the repository at this point in the history
Nusb support
  • Loading branch information
sjoerdsimons authored Oct 19, 2024
2 parents bd76dff + 305a92c commit e5f3c03
Show file tree
Hide file tree
Showing 12 changed files with 1,037 additions and 46 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
# Not yet supported. See <https://github.com/dependabot/dependabot-core/issues/4009>.
# versioning-strategy: "increase-if-necessary"
ignore:
- dependency-name: "tokio"
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.70.0
- uses: dtolnay/rust-toolchain@1.81
- run: cargo test --all-targets --all-features
- run: cargo test --doc --all-features

fmt:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.70.0
- uses: dtolnay/rust-toolchain@1.81
with:
components: rustfmt
- run: cargo fmt --all --check
Expand All @@ -30,10 +31,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.70.0
- uses: dtolnay/rust-toolchain@1.81
with:
components: clippy
- run: cargo clippy --all-targets -- -D warnings
- run: cargo clippy --all-targets --all-features -- -D warnings

allgreen:
if: always()
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"rockfile",
"rockusb"
Expand Down
3 changes: 1 addition & 2 deletions rockfile/examples/rockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ fn parse_entry(header: RkBootHeaderEntry, name: &str, file: &mut File) -> Result
println!("Name: {}", String::from_utf16(entry.name.as_slice())?);
println!("Raw: {:?}", entry);

let mut data = Vec::new();
data.resize(entry.data_size as usize, 0);
let mut data = vec![0; entry.data_size as usize];
file.seek(SeekFrom::Start(entry.data_offset as u64))?;
file.read_exact(&mut data)?;

Expand Down
26 changes: 20 additions & 6 deletions rockusb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,41 @@ readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["libusb"]
libusb = ["dep:rusb"]
nusb = ["dep:nusb", "dep:futures"]

[dependencies]
bytes = "1.4.0"
crc = "3.0.1"
fastrand = "1.9.0"
num_enum = "0.5.9"
fastrand = "2"
num_enum = "0.7"
thiserror = "1.0.38"
rusb = { version = "0.9.1", optional = true }
rusb = { version = "0.9.4", optional = true }
nusb = { version = "0.1.10", optional = true }
futures = { version = "0.3.31", optional = true }

[dev-dependencies]
anyhow = "1.0.69"
bmap-parser = "0.1.0"
bmap-parser = "0.2.0"
clap = { version = "4.2", features = ["derive"] }
clap-num = "1.0"
flate2 = "1.0.25"
nbd = "0.2.3"
nbd = "0.3"
rockfile = { path = "../rockfile", version = "0.1.1" }
rusb = "0.9.1"
tokio = { version = "1.40.0", features = ["full"] }
futures = { version = "0.3.31", features = ["compat", "io-compat"]}
tokio-util = { version = "0.7.12", features = ["compat"] }
async-compression = { version = "0.4.5", features = ["gzip", "futures-io"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[[example]]
name="rockusb"
required-features = ["libusb"]

[[example]]
name="rockusb-nusb"
required-features = ["nusb"]
32 changes: 23 additions & 9 deletions rockusb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

Rockchip bootroms and early loaders implement an USB protocol to help loader
early firmware, flashing persistant storage etc. This crate contains a sans-io
implementation of that protocol as well as an optional (enabled by default)
implementation of IO using libusb
implementation of that protocol as well as an optional implementations of IO
using libusb or nusb.

Printing chip info using libusb backend:
```rust,no_run
fn main() -> anyhow::Result<()> {
let devices = rockusb::libusb::Devices::new()?;
let mut transport = devices.iter().next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))??;
println!("Chip Info: {:0x?}", transport.chip_info()?);
Ok(())
}
# fn main() -> anyhow::Result<()> {
let devices = rockusb::libusb::Devices::new()?;
let mut transport = devices.iter().next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))??;
println!("Chip Info: {:0x?}", transport.chip_info()?);
Ok(())
# }
```

Printing chip info using nusb backend:
```rust,no_run
# #[tokio::main]
# async fn main() -> anyhow::Result<()> {
let mut devices = rockusb::nusb::devices()?;
let info = devices.next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))?;
let mut transport = rockusb::nusb::Transport::from_usb_device_info(info)?;
println!("Chip Info: {:0x?}", transport.chip_info().await?);
Ok(())
# }
```
Loading

0 comments on commit e5f3c03

Please sign in to comment.