Skip to content

Commit 13c4d5e

Browse files
committed
Replace deprecated handle_protocol calls with open_protocol
1 parent 47256d8 commit 13c4d5e

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

uefi/src/main.rs

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bootloader_api::{info::FrameBufferInfo, BootloaderConfig};
88
use bootloader_x86_64_common::{legacy_memory_region::LegacyFrameAllocator, Kernel, SystemInfo};
99
use core::{arch::asm, cell::UnsafeCell, fmt::Write, mem, panic::PanicInfo, ptr, slice};
1010
use uefi::{
11-
prelude::{entry, Boot, Handle, ResultExt, Status, SystemTable},
11+
prelude::{entry, Boot, Handle, Status, SystemTable},
1212
proto::{
1313
console::gop::{GraphicsOutput, PixelFormat},
1414
device_path::DevicePath,
@@ -22,7 +22,9 @@ use uefi::{
2222
IpAddress,
2323
},
2424
},
25-
table::boot::{AllocateType, MemoryDescriptor, MemoryType},
25+
table::boot::{
26+
AllocateType, MemoryDescriptor, MemoryType, OpenProtocolAttributes, OpenProtocolParams,
27+
},
2628
CStr16, CStr8,
2729
};
2830
use x86_64::{
@@ -140,25 +142,46 @@ fn load_kernel_file_from_disk(image: Handle, st: &SystemTable<Boot>) -> Option<&
140142
let file_system_raw = {
141143
let ref this = st.boot_services();
142144
let loaded_image = this
143-
.handle_protocol::<LoadedImage>(image)
145+
.open_protocol::<LoadedImage>(
146+
OpenProtocolParams {
147+
handle: image,
148+
agent: image,
149+
controller: None,
150+
},
151+
OpenProtocolAttributes::Exclusive,
152+
)
144153
.expect("Failed to retrieve `LoadedImage` protocol from handle");
145-
let loaded_image = unsafe { &*loaded_image.get() };
154+
let loaded_image = unsafe { &*loaded_image.interface.get() };
146155

147156
let device_handle = loaded_image.device();
148157

149158
let device_path = this
150-
.handle_protocol::<DevicePath>(device_handle)
159+
.open_protocol::<DevicePath>(
160+
OpenProtocolParams {
161+
handle: device_handle,
162+
agent: image,
163+
controller: None,
164+
},
165+
OpenProtocolAttributes::Exclusive,
166+
)
151167
.expect("Failed to retrieve `DevicePath` protocol from image's device handle");
152-
let mut device_path = unsafe { &*device_path.get() };
168+
let mut device_path = unsafe { &*device_path.interface.get() };
153169

154-
let device_handle = this
170+
let fs_handle = this
155171
.locate_device_path::<SimpleFileSystem>(&mut device_path)
156172
.ok()?;
157173

158-
this.handle_protocol::<SimpleFileSystem>(device_handle)
174+
this.open_protocol::<SimpleFileSystem>(
175+
OpenProtocolParams {
176+
handle: fs_handle,
177+
agent: image,
178+
controller: None,
179+
},
180+
OpenProtocolAttributes::Exclusive,
181+
)
159182
}
160183
.unwrap();
161-
let file_system = unsafe { &mut *file_system_raw.get() };
184+
let file_system = unsafe { &mut *file_system_raw.interface.get() };
162185

163186
let mut root = file_system.open_volume().unwrap();
164187
let mut buf = [0; 14 * 2];
@@ -200,21 +223,44 @@ fn load_kernel_file_from_tftp_boot_server(
200223
// Try to locate a `BaseCode` protocol on the boot device.
201224

202225
let loaded_image = this
203-
.handle_protocol::<LoadedImage>(image)
226+
.open_protocol::<LoadedImage>(
227+
OpenProtocolParams {
228+
handle: image,
229+
agent: image,
230+
controller: None,
231+
},
232+
OpenProtocolAttributes::Exclusive,
233+
)
204234
.expect("Failed to retrieve `LoadedImage` protocol from handle");
205-
let loaded_image = unsafe { &*loaded_image.get() };
235+
let loaded_image = unsafe { &*loaded_image.interface.get() };
206236

207237
let device_handle = loaded_image.device();
208238

209239
let device_path = this
210-
.handle_protocol::<DevicePath>(device_handle)
240+
.open_protocol::<DevicePath>(
241+
OpenProtocolParams {
242+
handle: device_handle,
243+
agent: image,
244+
controller: None,
245+
},
246+
OpenProtocolAttributes::Exclusive,
247+
)
211248
.expect("Failed to retrieve `DevicePath` protocol from image's device handle");
212-
let mut device_path = unsafe { &*device_path.get() };
213-
214-
let device_handle = this.locate_device_path::<BaseCode>(&mut device_path).ok()?;
215-
216-
let base_code_raw = this.handle_protocol::<BaseCode>(device_handle).unwrap();
217-
let base_code = unsafe { &mut *base_code_raw.get() };
249+
let mut device_path = unsafe { &*device_path.interface.get() };
250+
251+
let base_code_handle = this.locate_device_path::<BaseCode>(&mut device_path).ok()?;
252+
253+
let base_code_raw = this
254+
.open_protocol::<BaseCode>(
255+
OpenProtocolParams {
256+
handle: base_code_handle,
257+
agent: image,
258+
controller: None,
259+
},
260+
OpenProtocolAttributes::Exclusive,
261+
)
262+
.unwrap();
263+
let base_code = unsafe { &mut *base_code_raw.interface.get() };
218264

219265
// Find the TFTP boot server.
220266
let mode = base_code.mode();

0 commit comments

Comments
 (0)