File tree 4 files changed +71
-0
lines changed
uefi-test-runner/src/proto
4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ pub fn test() {
24
24
rng:: test ( ) ;
25
25
shell_params:: test ( ) ;
26
26
string:: test ( ) ;
27
+ usb:: test ( ) ;
27
28
misc:: test ( ) ;
28
29
29
30
// disable the ATA test on aarch64 for now. The aarch64 UEFI Firmware does not yet seem
@@ -96,3 +97,4 @@ mod shell_params;
96
97
mod shim;
97
98
mod string;
98
99
mod tcg;
100
+ mod usb;
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+
3
+ use core:: mem;
4
+ use uefi:: proto:: usb:: DeviceDescriptor ;
5
+ use uefi:: proto:: usb:: io:: { ControlTransfer , UsbIo } ;
6
+ use uefi:: { Status , boot} ;
7
+
8
+ pub fn test ( ) {
9
+ info ! ( "Testing USB I/O protocol" ) ;
10
+
11
+ let handles = boot:: locate_handle_buffer ( boot:: SearchType :: from_proto :: < UsbIo > ( ) )
12
+ . expect ( "failed to acquire USB I/O handles" ) ;
13
+
14
+ for handle in handles. iter ( ) . copied ( ) {
15
+ let mut io = boot:: open_protocol_exclusive :: < UsbIo > ( handle)
16
+ . expect ( "failed to open USB I/O protocol" ) ;
17
+
18
+ let device = io
19
+ . device_descriptor ( )
20
+ . expect ( "failed to acquire USB device descriptor" ) ;
21
+ io. config_descriptor ( )
22
+ . expect ( "failed to acquire USB config descriptor" ) ;
23
+ io. interface_descriptor ( )
24
+ . expect ( "failed to acquire USB interface descriptor" ) ;
25
+ for endpoint_index in 0 ..16 {
26
+ let result = io. endpoint_descriptor ( endpoint_index) ;
27
+ if result
28
+ . as_ref ( )
29
+ . is_err_and ( |error| error. status ( ) == Status :: NOT_FOUND )
30
+ {
31
+ continue ;
32
+ }
33
+
34
+ result. expect ( "failed to acquire USB endpoint descriptor" ) ;
35
+ }
36
+
37
+ let mut buffer = [ 0u8 ; mem:: size_of :: < DeviceDescriptor > ( ) ] ;
38
+
39
+ io. control_transfer (
40
+ 0b1000_0000 ,
41
+ 6 ,
42
+ 1u16 << 8 ,
43
+ 0 ,
44
+ ControlTransfer :: DataIn ( & mut buffer[ ..mem:: size_of :: < DeviceDescriptor > ( ) ] ) ,
45
+ 0 ,
46
+ )
47
+ . expect ( "failed control transfer" ) ;
48
+ unsafe {
49
+ assert_eq ! (
50
+ device,
51
+ buffer. as_ptr( ) . cast:: <DeviceDescriptor >( ) . read_unaligned( )
52
+ )
53
+ }
54
+ }
55
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+
3
+ pub fn test ( ) {
4
+ info ! ( "Testing USB protocols" ) ;
5
+
6
+ io:: test ( ) ;
7
+ }
8
+
9
+ mod io;
Original file line number Diff line number Diff line change @@ -438,6 +438,11 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
438
438
cmd. args ( [ "-display" , "none" ] ) ;
439
439
}
440
440
441
+ // Configure USB
442
+ cmd. args ( [ "-device" , "qemu-xhci" ] ) ;
443
+
444
+ cmd. args ( [ "-device" , "usb-net" ] ) ;
445
+
441
446
// Second (FAT) disk
442
447
let test_disk = tmp_dir. join ( "test_disk.fat.img" ) ;
443
448
create_mbr_test_disk ( & test_disk) ?;
You can’t perform that action at this time.
0 commit comments