Hello Andrew,

 

thank you very much!

That was the right hint.

 

I changed my code to use the FileDevicePath-function and it worked.

 

Regards,

Michael

 

Von: Andrew Fish [mailto:[email protected]] 
Gesendet: Montag, 15. Oktober 2012 15:42
An: [email protected]
Betreff: Re: [edk2] LoadImage() for Bootx64.efi from a specific partition
(DevicePath-problem)

 

Michael,

 

Be careful as Length is an array. Your hang is probably a bad length. I
would recommend using the lib function, FileDevicePath().

https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/MdePkg/Library/Uefi
DevicePathLib/UefiDevicePathLib.c

 

/**
  Allocates a device path for a file and appends it to an existing device
path.
 
  If Device is a valid device handle that contains a device path protocol,
then a device path for
  the file specified by FileName  is allocated and appended to the device
path associated with the
  handle Device.  The allocated device path is returned.  If Device is NULL
or Device is a handle
  that does not support the device path protocol, then a device path
containing a single device
  path node for the file specified by FileName is allocated and returned.
  The memory for the new device path is allocated from EFI boot services
memory. It is the responsibility
  of the caller to free the memory allocated.
  
  If FileName is NULL, then ASSERT().
  If FileName is not aligned on a 16-bit boundary, then ASSERT().
 
  @param  Device                     A pointer to a device handle.  This
parameter 
                                     is optional and may be NULL.
  @param  FileName                   A pointer to a Null-terminated Unicode
string.
 
  @return The allocated device path.
 
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
FileDevicePath (
  IN EFI_HANDLE                      Device,     OPTIONAL
  IN CONST CHAR16                    *FileName
  )

 

 

Andrew Fish

 

/**
  This protocol can be used on any device handle to obtain generic
path/location 
  information concerning the physical device or logical device. If the
handle does 
  not logically map to a physical device, the handle may not necessarily
support 
  the device path protocol. The device path describes the location of the
device 
  the handle is for. The size of the Device Path can be determined from the
structures 
  that make up the Device Path.
**/
typedef struct {
  UINT8 Type;       ///< 0x01 Hardware Device Path.
                    ///< 0x02 ACPI Device Path.
                    ///< 0x03 Messaging Device Path.
                    ///< 0x04 Media Device Path.
                    ///< 0x05 BIOS Boot Specification Device Path.
                    ///< 0x7F End of Hardware Device Path.
                    
  UINT8 SubType;    ///< Varies by Type
                    ///< 0xFF End Entire Device Path, or
                    ///< 0x01 End This Instance of a Device Path and start a
new
                    ///< Device Path.
                    
  UINT8 Length[2];  ///< Specific Device Path data. Type and Sub-Type define
                    ///< type of data. Size of data is included in Length.
                    
} EFI_DEVICE_PATH_PROTOCOL;

 

 

 

On Oct 15, 2012, at 6:25 AM, Michael Lorer wrote:





Hello,

 

I'm trinying to load a EFI\BOOT\Bootx64.efi-image from a specific partition
using the UEFI LoadImage() function.

But I think I have some difficulties to build a correct DevicePath to the
image.

Right now I do it the following way, but the LoadImage() function gets stuck
in a Deadloop:

 

struct {

EFI_DEVICE_PATH_PROTOCOL Header;

CHAR16 FileName[22];

EFI_DEVICE_PATH_PROTOCOL end;

} ApplicationFilePath = {

                {

                               MEDIA_DEVICE_PATH,

                               MEDIA_FILEPATH_DP,

                               46

                },

                { L"EFI\\BOOT\\BOOTx64.EFI"},

                {

                               END_DEVICE_PATH, END_ENTIRE_SUBTYPE,

                               sizeof(EFI_DEVICE_PATH_PROTOCOL)

                }                             

};

EFI_DEVICE_PATH_PROTOCOL *pApplicationFilePath = (EFI_DEVICE_PATH_PROTOCOL
*)&ApplicationFilePath;

 

// Get all BlockIO-Protocols

Status =
pBS->LocateHandleBuffer(ByProtocol,&gEfiBlockIoProtocolGuid,NULL,&Count,&Han
dle);

 

for( i=0; i<Count; i++ ){

                EFI_BLOCK_IO_PROTOCOL                        *BlockIo;

                EFI_DEVICE_PATH_PROTOCOL *PartitionDevicePath,
*TmpDevicePath;

                EFI_DEVICE_PATH_PROTOCOL *pApplicationPath = NULL;

               

                Status = pBS->HandleProtocol(Handle[i],
&gEfiDevicePathProtocolGuid, &PartitionDevicePath);

               

                // Get last node of the device path. It should be partition
node

                PartitionNode = (HARDDRIVE_DEVICE_PATH*)PartitionDevicePath;

               

                for( TmpDevicePath = PartitionDevicePath;

                                !EfiIsDevicePathEndType(TmpDevicePath);

                               TmpDevicePath =
EfiNextDevicePathNode(TmpDevicePath) )

                {

                               PartitionNode =
(HARDDRIVE_DEVICE_PATH*)TmpDevicePath;

                }

               

                // Here I'm looking for a specific partition and check some
Header-Parameter

                if (PartitionNode->Header.Type != MEDIA_DEVICE_PATH ||

                               PartitionNode->Header.SubType !=
MEDIA_HARDDRIVE_DP ||

                               PartitionNode->SignatureType != 0x02 ||

                               MemCmp(&PartitionNode->Signature,
gGuidOfASpecificPartition, sizeof(EFI_GUID)) != 0)

                                               continue;           

               

                Status =
pBS->LocateProtocol(&gEfiDevicePathUtilitiesProtocolGuid,
NULL,(VOID**)&pDevicePathUtils);

 

                // Build the whole DevicePath

                pApplicationPath =
pDevicePathUtils->AppendDevicePath(PartitionDevicePath,pApplicationFilePath)
;

               

                // Try to load the Image using the built DevicePath

                Status = pBS->LoadImage
(TRUE,ImageHandle,pApplicationPath,NULL,0,&Handle);

                // But it resaults in a deadloop

}

 

I would appreciate any hints on what I'm missing.

 

Thank you,

Michael

----------------------------------------------------------------------------
--
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev________________________________________
_______
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to