File tree 2 files changed +28
-18
lines changed
2 files changed +28
-18
lines changed Original file line number Diff line number Diff line change @@ -25,31 +25,40 @@ lazy_static! {
25
25
static ref DEVICE : Arc <Mutex <Option <DevHandle >>> = Arc :: new( Mutex :: new( None ) ) ;
26
26
}
27
27
28
- fn init ( ) {
28
+ fn init ( ) -> bool {
29
29
let mut device = DEVICE . lock ( ) . unwrap ( ) ;
30
30
if ( * device) . is_some ( ) {
31
- return ;
31
+ return true ;
32
32
}
33
33
34
34
let path = w ! ( r"\\.\GLOBALROOT\Device\CrosEC" ) ;
35
- unsafe {
36
- * device = Some ( DevHandle (
37
- CreateFileW (
38
- path,
39
- FILE_GENERIC_READ . 0 | FILE_GENERIC_WRITE . 0 ,
40
- FILE_SHARE_READ | FILE_SHARE_WRITE ,
41
- None ,
42
- OPEN_EXISTING ,
43
- FILE_FLAGS_AND_ATTRIBUTES ( 0 ) ,
44
- None ,
45
- )
46
- . unwrap ( ) ,
47
- ) ) ;
48
- }
35
+ let res = unsafe {
36
+ CreateFileW (
37
+ path,
38
+ FILE_GENERIC_READ . 0 | FILE_GENERIC_WRITE . 0 ,
39
+ FILE_SHARE_READ | FILE_SHARE_WRITE ,
40
+ None ,
41
+ OPEN_EXISTING ,
42
+ FILE_FLAGS_AND_ATTRIBUTES ( 0 ) ,
43
+ None ,
44
+ )
45
+ } ;
46
+ let handle = match res {
47
+ Ok ( h) => h,
48
+ Err ( err) => {
49
+ error ! ( "Failed to find Windows driver. {:?}" , err) ;
50
+ return false ;
51
+ }
52
+ } ;
53
+
54
+ * device = Some ( DevHandle ( handle) ) ;
55
+ true
49
56
}
50
57
51
58
pub fn read_memory ( offset : u16 , length : u16 ) -> EcResult < Vec < u8 > > {
52
- init ( ) ;
59
+ if !init ( ) {
60
+ return Err ( EcError :: DeviceError ( "Failed to initialize" . to_string ( ) ) ) ;
61
+ }
53
62
let mut rm = CrosEcReadMem {
54
63
offset : offset as u32 ,
55
64
bytes : length as u32 ,
Original file line number Diff line number Diff line change @@ -1111,7 +1111,8 @@ fn selftest(ec: &CrosEc) -> Option<()> {
1111
1111
if let Some ( mem) = ec. dump_mem_region ( ) {
1112
1112
util:: print_multiline_buffer ( & mem, 0 ) ;
1113
1113
} else {
1114
- println ! ( " Failed to read EC memory region" )
1114
+ println ! ( " Failed to read EC memory region" ) ;
1115
+ return None ;
1115
1116
}
1116
1117
1117
1118
println ! ( " Checking EC memory mapped magic bytes" ) ;
You can’t perform that action at this time.
0 commit comments