Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions cmd/qspi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ edition.workspace = true
description = "QSPI status, reading and writing"

[dependencies]
hif.workspace = true
clap.workspace = true
anyhow.workspace = true
parse_int.workspace = true
clap.workspace = true
hif.workspace = true
indicatif.workspace = true
log.workspace = true
parse_int.workspace = true
sha2.workspace = true
zerocopy.workspace = true

humility.workspace = true
humility-cli.workspace = true
Expand Down
13 changes: 6 additions & 7 deletions cmd/qspi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ use std::time::Instant;
use anyhow::{Result, anyhow, bail};
use clap::{ArgGroup, Parser};
use hif::*;
use zerocopy::{FromBytes, Immutable, KnownLayout};

use indicatif::{HumanBytes, HumanDuration};
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -225,9 +226,8 @@ fn optional_nbytes<'a>(
Ok(results) => match &results[0] {
Ok(buf) => {
if mem::size_of::<DeviceIdData>() == buf.len() {
let did: DeviceIdData = unsafe {
std::ptr::read(buf.as_ptr() as *const _)
};
let did =
DeviceIdData::ref_from_bytes(buf).unwrap();
Ok(did.size()? as u32)
} else {
Err(anyhow!(
Expand Down Expand Up @@ -1059,8 +1059,7 @@ fn qspi(subargs: QspiArgs, context: &mut ExecutionContext) -> Result<()> {
// If the response is well formatted, print it out in addition to raw hex.
if let Ok(results) = &results[0] {
if mem::size_of::<DeviceIdData>() == results.len() {
let did: DeviceIdData =
unsafe { std::ptr::read(results.as_ptr() as *const _) };
let did = DeviceIdData::ref_from_bytes(results).unwrap();
println!("{}", did);
} else {
println!(
Expand Down Expand Up @@ -1090,8 +1089,8 @@ fn qspi(subargs: QspiArgs, context: &mut ExecutionContext) -> Result<()> {
/// Micron's Device ID Data
// Responses to the Read ID family of instructions can be more flexible than
// the struct below, but until we need support beyond Micron MT25Q, this will do.
#[derive(Debug, Copy, Clone)]
#[repr(C, packed)]
#[derive(Debug, Copy, Clone, FromBytes, KnownLayout, Immutable)]
#[repr(C)]
struct DeviceIdData {
manufacturer_id: u8,
memory_type: u8,
Expand Down
Loading