2

i am trying to load an efi application from another efi application using loadimage and startimage protocols. but loadimage is getting succeeded,startimage failing with return value -1/0xffffffff. it would be very helpful if any one suggest some ideas, why it is failing. if there is any mistake in code please correct it.

EFI_STATUS LoadPythonBinary()
{
    EFI_STATUS Status;
    UINTN NumberOfFSHandles;
    EFI_HANDLE *FSHandles;
    EFI_GUID SimpleFileSystemGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
    UINTN  Index = 0;
    EFI_BLOCK_IO  *BlkIo;
    EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSysProtocol =  NULL;
    EFI_DEVICE_PATH_PROTOCOL        *FilePath;
    EFI_HANDLE                      ImageHandle2 = NULL;
//    EFI_DEVICE_PATH_PROTOCOL        *DevicePath;
//    EFI_HANDLE                      DeviceHandle;
    EFI_HANDLE          Controller=NULL;
    EFI_LOADED_IMAGE_PROTOCOL  *ImageInfo;
    EFI_GUID EfiDevicePathProtocolGuid = EFI_DEVICE_PATH_PROTOCOL_GUID;
    EFI_GUID EfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID;
    const CHAR16   *FileName = L"Python.efi";
    EFI_GUID EfiLoadedImageProtocol = EFI_LOADED_IMAGE_PROTOCOL_GUID;
//    EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
    char temp[MAX_PATH];
    CHAR16 CmdLineParams[MAX_PATH] = L"fs0:\\GK\\Temp\\UnzipBuildTools.py fs0:\\GK\\Temp\\EFI.zip fs0:\\Test";
    strcpy(temp,(const char *)StrDup16to8(CmdLineParams));

    Status = gBS->LocateHandleBuffer(ByProtocol, &SimpleFileSystemGuid,NULL, &NumberOfFSHandles, &FSHandles);
    if(!EFI_ERROR(Status))
    {
        for(Index = 0; Index < NumberOfFSHandles; Index++)
        {
            Status = gBS->HandleProtocol(FSHandles[Index], &SimpleFileSystemGuid, &BlkIo);
            if(!EFI_ERROR(Status))
            {
                    FilePath = FileDevicePath(FSHandles[Index],FileName);
                    Status = gBS->LoadImage(TRUE, gImageHandle, FilePath, NULL, 0, &ImageHandle2);
                    printf("Load Image Status = %x", Status);
                    if(!EFI_ERROR(Status))
                    {
                        printf("Image Loaded Successfully\n");
                        Status = gBS->HandleProtocol(ImageHandle2, &EfiLoadedImageProtocol,(VOID**)&ImageInfo);
                        if(!EFI_ERROR(Status))
                        {
                            if(ImageInfo->ImageCodeType == EfiLoaderCode) 
                            {
                                 gBS->FreePool(FilePath);
                            }
                            printf("Options :%s\n",temp);
                            printf("LoadedImage->ImageSize = %x", ImageInfo->ImageSize);
                            ImageInfo->LoadOptions = CmdLineParams;
                            ImageInfo->LoadOptionsSize = (UINT32)(wcslen(CmdLineParams));
                            ImageInfo->DeviceHandle = gImageHandle;
                        }
                    }

                    printf("About to start image\n");
                    Status = gBS->StartImage(ImageHandle2, NULL, NULL);
                    printf("StartImage Status = %x", Status);
                    if(!EFI_ERROR(Status))
                    {
                        printf("StartImage success\n");
                        break;
                    }
            }
        }
    }

return Status;
}
gkreddy
  • 23
  • 5

2 Answers2

2

Possible problem: Probably your target image (Python.efi) is not a valid UEFI application and can't be loaded by EFI_BOOT_SERVICES.StartImage() interface. For more information please consult the valid types of UEFI images loadable by UEFI boot service, check the session 7.4 in UEFI Spec 2.7.

Solution: Make sure that in the target application .inf file, the field MODULE_TYPE is configured with UEFI_APPLICATION and its .c file has the entry point signature to an UEFI application similar to:

EFI_STATUS
EFIAPI
MyEntryPointName (
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
    )
{
 ...
}

A functional code example can be consulted in LoadImageApp. This application load and start a target application named HelloImageEntryPoint.efi with success.

Manoel Rui
  • 101
  • 5
0

-1 is not a valid EFI_STATUS if you are on a 64-bit system EFI_STATUS is 64-bit. Also if you use Print() %r will print out a string for EFI_STATUS.

The EFI_STATUS values returned from EFI services are define in the EFI Spec: EFI_INVALID_PARAMETER - ImageHandle is either an invalid image handle or the image has already been initialized with StartImage

EFI_SECURITY_VIOLATION - The current platform policy specifies that the image should not be started.

Exit code from image - Exit code from image.

So did the code you loaded return an error back to you?