Reputation: 61
I have a problem Loading and starting image from memory. This is the code:
UINT8 *Buffer;
typedef struct
{
MEMMAP_DEVICE_PATH Node1;
EFI_DEVICE_PATH_PROTOCOL End;
} MEMORY_DEVICE_PATH;
STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplate =
{
{
{
HARDWARE_DEVICE_PATH,
HW_MEMMAP_DP,
{
(UINT8)(sizeof(MEMMAP_DEVICE_PATH)),
(UINT8)((sizeof(MEMMAP_DEVICE_PATH)) >> 8),
},
}, // Header
0, // StartingAddress (set at runtime)
0 // EndingAddress (set at runtime)
}, // Node1
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{sizeof(EFI_DEVICE_PATH_PROTOCOL), 0}} // End
};
MEMORY_DEVICE_PATH BufferDevicePath = mMemoryDevicePathTemplate;
BufferDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
BufferDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer + BufferSize;
Prnt("Loading Image...");
Status = gBS->LoadImage(
TRUE,
gImageHandle,
(EFI_DEVICE_PATH *)&BufferDevicePath,
Buffer,
BufferSize,
&ImageHandle);
if (!EFI_ERROR(Status))
{
Status = gBS->StartImage (ImageHandle, NULL, NULL);
if (EFI_ERROR(Status))
{
Prnt("Error Starting image ... Status=%08x", Status);
}
}
else {
Prnt("Error Loading image ... Status=%08x", Status);
}
The image verified to be fine by loading it (not from memory) with UEFI Shell using load
.
However in this case there are no errors, The image seems to be started but the machine is stuck, there is black screen with white cursor on the upper left screen.
Upvotes: 0
Views: 291
Reputation: 1538
You forgot the MemoryType field in the MEMMAP_DEVICE_PATH structure.
///
/// Memory Mapped Device Path.
///
typedef struct {
EFI_DEVICE_PATH_PROTOCOL Header;
///
/// EFI_MEMORY_TYPE
///
UINT32 MemoryType;
///
/// Starting Memory Address.
///
EFI_PHYSICAL_ADDRESS StartingAddress;
///
/// Ending Memory Address.
///
EFI_PHYSICAL_ADDRESS EndingAddress;
} MEMMAP_DEVICE_PATH;
With your code it is set to 0 (EfiReservedMemoryType), set it to 1 (EfiLoaderCode).
By the way there was a similar question, maybe the solution there can help you too.
Upvotes: 3