11use crate :: context:: SproutContext ;
2+ use crate :: integrations:: shim:: { ShimInput , ShimSupport } ;
23use crate :: utils;
34use anyhow:: { Context , Result } ;
45use log:: info;
56use serde:: { Deserialize , Serialize } ;
67use std:: collections:: BTreeMap ;
78use std:: rc:: Rc ;
89use uefi:: boot:: SearchType ;
9- use uefi:: proto:: device_path:: LoadedImageDevicePath ;
1010
1111/// Declares a driver configuration.
1212/// Drivers allow extending the functionality of Sprout.
@@ -23,28 +23,17 @@ pub struct DriverDeclaration {
2323fn load_driver ( context : Rc < SproutContext > , driver : & DriverDeclaration ) -> Result < ( ) > {
2424 // Acquire the handle and device path of the loaded image.
2525 let sprout_image = uefi:: boot:: image_handle ( ) ;
26- let image_device_path_protocol =
27- uefi:: boot:: open_protocol_exclusive :: < LoadedImageDevicePath > ( sprout_image)
28- . context ( "unable to open loaded image device path protocol" ) ?;
2926
30- // Get the device path root of the sprout image.
31- let mut full_path = utils:: device_path_root ( & image_device_path_protocol) ?;
32-
33- // Push the path of the driver from the root.
34- full_path. push_str ( & context. stamp ( & driver. path ) ) ;
35-
36- // Convert the path to a device path.
37- let device_path = utils:: text_to_device_path ( & full_path) ?;
38-
39- // Load the driver image.
40- let image = uefi:: boot:: load_image (
41- sprout_image,
42- uefi:: boot:: LoadImageSource :: FromDevicePath {
43- device_path : & device_path,
44- boot_policy : uefi:: proto:: BootPolicy :: ExactMatch ,
45- } ,
27+ // Resolve the path to the driver image.
28+ let resolved = utils:: resolve_path (
29+ Some ( context. root ( ) . loaded_image_path ( ) ?) ,
30+ & context. stamp ( & driver. path ) ,
4631 )
47- . context ( "unable to load image" ) ?;
32+ . context ( "unable to resolve path to driver" ) ?;
33+
34+ // Load the driver image using the shim support integration.
35+ // It will determine if the image needs to be loaded via the shim or can be loaded directly.
36+ let image = ShimSupport :: load ( sprout_image, ShimInput :: ResolvedPath ( & resolved) ) ?;
4837
4938 // Start the driver image, this is expected to return control to sprout.
5039 // There is no guarantee that the driver will actually return control as it is
0 commit comments