-
-
Notifications
You must be signed in to change notification settings - Fork 170
uefi: Add safe protocol wrapper for EFI_ATA_PASS_THRU_PROTOCOL #1595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
mod pass_thru; | ||
|
||
pub fn test() { | ||
pass_thru::test(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use uefi::boot; | ||
use uefi::boot::{OpenProtocolAttributes, OpenProtocolParams}; | ||
use uefi::proto::ata::pass_thru::AtaPassThru; | ||
use uefi::proto::ata::AtaRequestBuilder; | ||
|
||
pub fn test() { | ||
info!("Running ATA PassThru tests"); | ||
|
||
assert!(is_testdrive_present()); | ||
} | ||
|
||
const ATACMD_IDENTIFY: u8 = 0xEC; | ||
|
||
fn is_testdrive_present() -> bool { | ||
let ata_ctrl_handles = boot::find_handles::<AtaPassThru>().unwrap(); | ||
assert_eq!(ata_ctrl_handles.len(), 1); | ||
|
||
for handle in ata_ctrl_handles { | ||
let params = OpenProtocolParams { | ||
handle, | ||
agent: boot::image_handle(), | ||
controller: None, | ||
}; | ||
let ata_pt = unsafe { | ||
// don't open exclusive! That would break other tests | ||
boot::open_protocol::<AtaPassThru>(params, OpenProtocolAttributes::GetProtocol).unwrap() | ||
seijikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
for mut device in ata_pt.iter_devices() { | ||
// ATA IDENTIFY command | ||
let request = AtaRequestBuilder::read_udma(ata_pt.io_align(), ATACMD_IDENTIFY) | ||
.unwrap() | ||
.with_timeout(core::time::Duration::from_millis(500)) | ||
.with_read_buffer(255) | ||
.unwrap() | ||
.build(); | ||
if let Ok(result) = device.execute_command(request) { | ||
let bfr = result.read_buffer().unwrap(); | ||
// ATA uses wchar16 big endian strings for serial numbers | ||
let mut serial_bfr = [0u8; 20]; | ||
bfr[20..40] | ||
.chunks_exact(2) | ||
.zip(serial_bfr.chunks_exact_mut(2)) | ||
.for_each(|(src, dst)| { | ||
dst[0] = src[1]; | ||
dst[1] = src[0]; | ||
}); | ||
let serial = core::str::from_utf8(&serial_bfr).unwrap().trim(); | ||
if serial == "AtaPassThru" { | ||
info!("Found Testdisk at handle: {:?}", handle); | ||
return true; // found our testdrive! | ||
} | ||
} | ||
} | ||
} | ||
|
||
false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.